/**
 * Copyright © 2016-2019 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
.tb-rulechain {
  .tb-fullscreen-button-style {
    z-index: 1;
  }

  section.tb-header-buttons.tb-library-open {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    pointer-events: none;

    .md-button.tb-btn-open-library {
      top: 0;
      left: 0;
      width: 36px;
      height: 36px;
      margin: 4px 0 0 4px;
      line-height: 36px;
      opacity: .5;
    }
  }

  .tb-rulechain-library {
    z-index: 1;
    width: 250px;
    min-width: 250px;

    md-toolbar {
      height: 48px;
      min-height: 48px;

      .md-toolbar-tools > .md-button:last-child {
        margin-right: 0;
      }

      .md-toolbar-tools {
        height: 48px;
        padding: 0 6px;
        font-size: 14px;

        .md-button.md-icon-button {
          margin: 0;

          &.tb-small {
            width: 32px;
            height: 32px;
            min-height: 32px;
            padding: 6px;
            line-height: 20px;

            md-icon {
              width: 20px;
              min-width: 20px;
              height: 20px;
              min-height: 20px;
              font-size: 20px;
              line-height: 20px;
            }
          }
        }
      }
    }

    .tb-rulechain-library-panel-group {
      overflow-x: hidden;
      overflow-y: auto;

      .tb-panel-title {
        min-width: 150px;
        user-select: none;
      }

      .fc-canvas {
        background: #f9f9f9;
      }

      md-icon.md-expansion-panel-icon {
        margin-right: 0;
      }

      md-expansion-panel-collapsed,
      .md-expansion-panel-header-container {
        position: static;
        background: #e6e6e6;
        border-color: #909090;
      }

      md-expansion-panel {
        &.md-open {
          margin-top: 0;
          margin-bottom: 0;
        }
      }

      md-expansion-panel-content {
        padding: 0;
      }
    }
  }

  .tb-rulechain-graph {
    z-index: 0;
    overflow: auto;
  }
}

#tb-rule-chain-context-menu {
  max-height: 404px;
  padding-top: 0;
  border-radius: 8px;

  .tb-context-menu-header {
    display: flex;
    flex-direction: row;
    height: 36px;
    min-height: 36px;
    padding: 8px 5px 5px;
    font-size: 14px;

    &.tb-rulechain {
      background-color: #aac7e4;
    }

    &.tb-link {
      background-color: #aac7e4;
    }

    md-icon {
      padding-right: 10px;
      padding-left: 2px;
    }

    .tb-context-menu-title {
      font-weight: 500;
    }

    .tb-context-menu-subtitle {
      font-size: 12px;
    }
  }
}

.fc-canvas {
  min-width: 100%;
  min-height: 100%;
  user-select: none;
  outline: none;
  -webkit-touch-callout: none;

  svg {
    display: block;
  }
}

.tb-rule-node,
#tb-rule-chain-context-menu .tb-context-menu-header {
  &.tb-filter-type {
    background-color: #f1e861;
  }

  &.tb-enrichment-type {
    background-color: #cdf14e;
  }

  &.tb-transformation-type {
    background-color: #79cef1;
  }

  &.tb-action-type {
    background-color: #f1928f;
  }

  &.tb-external-type {
    background-color: #fbc766;
  }

  &.tb-rule-chain-type {
    background-color: #d6c4f1;
  }

  &.tb-unknown-type {
    background-color: #f16c29;
  }
}

.tb-rule-node {
  display: flex;
  flex-direction: row;
  min-width: 150px;
  max-width: 150px;
  height: 32px;
  min-height: 32px;
  max-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
  line-height: 16px;
  color: #333;
  pointer-events: none;
  background-color: #f15b26;
  border: solid 1px #777;
  border-radius: 5px;

  &.tb-rule-node-highlighted:not(.tb-rule-node-invalid) {
    box-shadow: 0 0 10px 6px #51cbee;

    .tb-node-title {
      font-weight: 700;
      text-decoration: underline;
    }
  }

  &.tb-rule-node-invalid {
    box-shadow: 0 0 10px 6px #ff5c50;
  }

  &.tb-input-type {
    user-select: none;
    background-color: #a3eaa9;
  }

  md-icon {
    width: 20px;
    min-width: 20px;
    height: 20px;
    min-height: 20px;
    padding-right: 4px;
    font-size: 20px;
  }

  .tb-node-title {
    font-weight: 500;
  }

  .tb-node-type,
  .tb-node-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.fc-node {
  z-index: 1;
  border-radius: 8px;
  outline: none;

  &.fc-dragging {
    z-index: 10;
  }

  p {
    padding: 0 15px;
    text-align: center;
  }

  .fc-node-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    background-color: #000;
    border-radius: 5px;
    opacity: 0;
  }

  &.fc-hover {
    .fc-node-overlay {
      opacity: .25;
    }
  }

  &.fc-selected {
    .fc-node-overlay {
      opacity: .25;
    }

    &:not(.fc-edit) {
      margin: -3px;
      border: solid 3px #f00;
    }
  }
}

.fc-leftConnectors,
.fc-rightConnectors {
  position: absolute;
  top: 0;

  z-index: 0;

  display: flex;
  flex-direction: column;
  height: 100%;

  .fc-magnet {
    align-items: center;
  }
}

.fc-leftConnectors {
  left: -20px;
}

.fc-rightConnectors {
  right: -20px;
}

.fc-magnet {
  display: flex;
  flex-grow: 1;
  justify-content: center;
  height: 60px;
}

.fc-connector {
  width: 14px;
  height: 14px;
  margin: 10px;
  pointer-events: all;
  background-color: #ccc;
  border: 1px solid #333;
  border-radius: 5px;
}

.fc-connector.fc-hover {
  background-color: #000;
}

.fc-arrow-marker {
  polygon {
    fill: #808080;
    stroke: #808080;
  }
}

.fc-arrow-marker-selected {
  polygon {
    fill: #f00;
    stroke: #f00;
  }
}

.fc-edge {
  outline: none;
  transition: stroke-width .2s;
  fill: transparent;
  stroke: #808080;
  stroke-width: 4;

  &.fc-selected {
    fill: transparent;
    stroke: #f00;
    stroke-width: 4;
  }

  &.fc-active {
    animation: dash 3s linear infinite;
    stroke-dasharray: 20;
  }

  &.fc-hover {
    fill: transparent;
    stroke: #808080;
    stroke-width: 6;
  }

  &.fc-dragging {
    pointer-events: none;
  }
}

.edge-endpoint {
  fill: #808080;
}

.fc-nodedelete {
  display: none;
  font-size: 18px;
}

.fc-nodeedit {
  display: none;
  font-size: 15px;
}

.fc-edit {
  .fc-nodedelete,
  .fc-nodeedit {
    position: absolute;
    display: block;
    width: 22px;
    height: 20px;
    padding-top: 2px;
    font-weight: 600;
    line-height: 20px;
    color: #fff;
    text-align: center;
    vertical-align: bottom;
    cursor: pointer;
    background: #f83e05;
    border: solid 2px #fff;
    border-radius: 50%;
    outline: none;
  }

  .fc-nodeedit {
    top: -24px;
    right: 16px;
  }

  .fc-nodedelete {
    top: -24px;
    right: -13px;
  }
}

.fc-noselect {
  user-select: none;
}

.fc-edge-label {
  position: absolute;
  transition: transform .2s;
  //  opacity: 0.8;

  &.ng-leave {
    transition: 0s none;
  }

  &.fc-hover {
    transform: scale(1.25);
  }

  &.fc-selected {
    .fc-edge-label-text {
      span {
        font-weight: 600;
        color: #fff;
        background-color: #f00;
        border: solid #f00;
      }
    }
  }

  .fc-nodeedit {
    top: -30px;
    right: 14px;
  }

  .fc-nodedelete {
    top: -30px;
    right: -13px;
  }

  &:focus {
    outline: 0;
  }
}

.fc-edge-label-text {
  position: absolute;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  transform: translate(-50%, -50%);

  span {
    padding: 3px 5px;
    color: #003a79;
    cursor: default;
    background-color: #fff;
    border: solid 2px #003a79;
    border-radius: 10px;
  }
}

.fc-select-rectangle {
  position: absolute;
  z-index: 2;
  background: rgba(20, 125, 255, .1);
  border: 2px dashed #5262ff;
}

@keyframes dash {
  from {
    stroke-dashoffset: 500;
  }
}

.tb-rule-node-tooltip,
.tb-rule-node-help {
  color: #333;
}

.tb-rule-node-tooltip {
  max-width: 300px;
  font-size: 14px;

  &.tb-lib-tooltip {
    width: 300px;
  }
}

.tb-rule-node-help {
  font-size: 16px;
}

.tb-rule-node-error-tooltip {
  font-size: 16px;
  color: #ea0d0d;
}

.tb-rule-node-tooltip,
.tb-rule-node-error-tooltip,
.tb-rule-node-help {
  #tb-node-content {
    .tb-node-title {
      font-weight: 600;
    }

    .tb-node-description {
      font-style: italic;
      color: #555;
    }

    .tb-node-details {
      padding-top: 10px;
      padding-bottom: 10px;
    }

    code {
      padding: 0 3px 2px 3px;
      margin: 1px;
      font-size: 12px;
      color: #ad1625;
      white-space: nowrap;
      background-color: #f7f7f9;
      border: 1px solid #e1e1e8;
      border-radius: 2px;
    }
  }
}
