/**
 * @license
 * Copyright 2024 The Model Explorer Authors. All Rights Reserved.
 *
 * 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.
 * ==============================================================================
 */

@use 'variables';

:host {
  position: relative;
  width: 370px;
  min-width: 370px;
}

.container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  border-left: 1px solid #e1e3e1;
  background-color: white;
  font-size: 12px;
  overflow-y: auto;
  position: relative;

  .section {
    transition: max-height 150ms ease-out;
    padding-bottom: 8px;
    box-sizing: border-box;

    &.collapsed {
      /* stylelint-disable-next-line declaration-no-important -- override element style */
      max-height: 32px !important;
      overflow: hidden;
    }

    &.inputs {
      padding-bottom: 16px;
    }

    .flat-items-container {
      display: flex;
      flex-direction: column;
      margin-top: 10px;
      gap: 8px;
    }

    .flat-item {
      display: flex;
      flex-direction: column;
      padding: 0 2px 0 12px;
      font-size: 12px;

      .name-row {
        display: flex;
        align-items: center;

        &.search-match {
          background-color: variables.$search-match-color;
        }

        .index {
          color: #999;
          min-width: 14px;
          margin-right: 2px;
        }

        .name {
          color: #00639b;
          font-weight: 500;
          display: flex;
          align-items: center;

          &.locator {
            flex-grow: 1;
            display: flex;
            align-items: center;
            cursor: pointer;

            &:hover {
              background-color: #f6f6f6;

              .locator-icon-container {
                opacity: 0.8;
              }
            }
          }
        }
      }

      .target-op-container {
        display: flex;
        align-items: center;
        color: #999;
        font-weight: normal;

        mat-icon.arrow {
          font-size: 12px;
          height: 12px;
          width: 12px;
          margin: 0 4px;
        }
      }

      .source-op-node-label {
        color: #999;
        font-weight: normal;
        margin-left: 6px;
      }

      .metadata-table {
        margin-top: 3px;
        margin-left: 18px;
        margin-right: 0;
      }
    }

    .node-id-attribute {
      display: flex;
      cursor: pointer;
    }
  }

  .section:not(:first-child) {
    border-top: 1px solid #dadce0;
  }

  .filler {
    flex-grow: 1;
  }

  .header {
    display: flex;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 12px 0;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
    box-sizing: border-box;
    background-color: white;
    user-select: none;
    color: rgba(0, 0, 0, 0.87);

    &.input,
    &.output,
    &.identical-groups {
      justify-content: space-between;
    }

    .header-label-container {
      display: flex;
      align-items: center;
    }

    button.toggle {
      padding: 0;
      width: 24px;
      height: 24px;
      margin-left: -8px;
      margin-right: 2px;
      display: flex;
      align-items: center;
      justify-content: center;

      mat-icon {
        color: inherit;
        font-size: 20px;
        width: 20px;
        height: 20px;
      }

      ::ng-deep .mat-mdc-button-touch-target {
        display: none;
      }
    }
  }

  .output-item-container {
    font-family: Roboto, sans-serif;
  }

  .output-item-container:not(.last) {
    margin-top: 8px;
  }

  .output-item-label {
    font-size: 13px;
    padding: 4px 12px;
    color: #00639b;
    font-weight: 500;
  }

  .metadata-table {
    border-spacing: 0;
    border-collapse: collapse;
    font-size: 12px;
    margin: 0 12px;
    word-break: break-all;
    max-width: calc(100% - 28px);

    &.info-attrs {
      margin-left: 30px;
    }

    tr {
      vertical-align: text-top;

      &.search-match {
        background-color: variables.$search-match-color;
      }

      &:hover.has-hover-values {
        cursor: pointer;
        background-color: #f6f6f6;
      }

      mat-icon.bullet {
        flex-shrink: 0;
        font-size: 4px;
        width: 5px;
        height: 5px;
        color: #bbb;
        margin-right: 4px;
        margin-top: 6px;
      }
    }

    td.key {
      color: #999;
      padding-right: 6px;
      white-space: nowrap;
      min-width: 100px;
      width: 100px;
      max-width: 100px;
      overflow: hidden;
      text-overflow: ellipsis;
      position: relative;

      .key-container {
        display: flex;
        align-items: flex-start;
        overflow: hidden;
        position: absolute;
        inset: 0;
      }
    }

    td.value {
      max-width: 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &:has(expandable-info-text.expanded) {
        white-space: normal;
        max-width: inherit;
      }
    }

    .target-node-container {
      display: flex;
      align-items: center;
      cursor: pointer;

      &:hover .locator-icon-container {
        opacity: 0.8;
      }

      &.search-match {
        background-color: variables.$search-match-color;
      }
    }

    .values-hover-trigger {
      box-sizing: border-box;
      border-radius: 99px;
      display: flex;
      align-items: center;
      background-color: #d7f1ff;
      color: #00639b;
      width: fit-content;
      height: 16px;
      padding: 0 6px;
      font-size: 10px;
    }
  }

  .items-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
    margin-bottom: 6px;
  }

  .item-container {
    display: flex;
    flex-direction: column;
    padding: 0 12px;

    &.search-match {
      background-color: variables.$search-match-color;
    }

    .label-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .label {
      font-weight: 500;
      color: #aaa;
      font-size: 12px;
      margin-bottom: 1px;
    }

    .show-on-node-toggle {
      height: 16px;
      display: flex;
      font-size: 11px;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      cursor: pointer;
      user-select: none;
      transform: scale(0.7);
      margin-right: -6px;
      margin-top: -1px;
    }

    .value {
      font-size: 13px;
      word-break: break-word;

      &.big-text {
        font-size: 14px;
        font-weight: 500;
      }

      &.has-bg-color {
        padding: 2px 4px;
        border-radius: 4px;
        margin-top: 2px;
      }
    }
  }

  .locator-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    margin-left: 4px;

    &.left {
      margin-right: 4px;
      margin-left: 0;
      display: inline-block;

      mat-icon {
        margin-bottom: -2px;
      }
    }

    &:hover {
      opacity: 0.8;
    }

    mat-icon {
      color: #333;
      font-size: 12px;
      width: 12px;
      height: 12px;
    }
  }

  .visibility-icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    padding: 0 11px 0 20px;
    cursor: pointer;

    &:hover {
      opacity: 0.8;
    }

    mat-icon {
      color: #333;
      font-size: 14px;
      width: 14px;
      height: 14px;
    }

    &.input.visible {
      mat-icon {
        color: #009e73;
      }
    }

    &.output.visible {
      mat-icon {
        color: #d55e00;
      }
    }
  }
}

.resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  cursor: ew-resize;
  background-color: transparent;
  z-index: 200;

  &:hover,
  &.resizing {
    background-color: rgba(0, 0, 0, 0.04);
  }
}

.hide-toggle {
  position: absolute;
  right: 100%;
  bottom: 2px;
  width: 16px;
  height: 20px;
  border: 1px solid #ccc;
  border-right: none;
  box-sizing: border-box;
  border-radius: 99px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  cursor: pointer;
  background-color: white;

  &:hover {
    background-color: #eee;
  }

  mat-icon {
    width: 18px;
    height: 18px;
    font-size: 18px;
    color: #999;
  }
}

::ng-deep bubble-container:has(.model-explorer-const-values-popup) {
  width: 100%;
}

::ng-deep .model-explorer-const-values-popup {
  padding: 8px;
  line-height: 12px;
  background-color: white;

  .values-count-msg {
    margin-bottom: 8px;
    color: #999;
    font-size: 12px;
  }

  .content {
    font-size: 11px;
    white-space: pre-wrap;
    font-family: monospace;
  }

  .namespace-row {
    font-size: 12px;
    padding: 3px 0;
  }
}
