@import '../styles/themes/themes.less';
@import '../styles/mixins/animate.less';

.ellipsis() {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flex-center() {
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-text() {
  margin-left: 4px;
  line-height: 18px;
}

.input() {
  box-sizing: border-box;
  width: 100%;
  height: 32px;
  padding: 0 28px 0 10px;
  line-height: normal;
  color: @default-color;
  text-align: left;
  vertical-align: middle;
  cursor: pointer;
  resize: none;
  background-color: @white-color;
  border: 1px solid @light-gray;
  border-radius: 2px;
  outline: none;
  transition: all .1s;
  .ellipsis();

  &::placeholder {
    color: @light-gray;
  }
}

.@{bk-prefix}-select {
  .select-icon(@fontSize: 20px, @color: #979ba5) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: @fontSize;
    color: @color;
  }

  .fix-icon() {
    position: absolute;
    top: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }

  .mr(@marginRight) {
    margin-right: @marginRight;
  }

  .ml(@marginLeft) {
    margin-left: @marginLeft;
  }

  .active(@color: @primary-color) {
    border-color: @primary-color;
    outline: 0;
    box-shadow: 0 0 3px 0 @input-shadow-color;
  }

  .mr5 {
    .mr(5px)
  }

  .ml5 {
    .ml(5px)
  }

  ul {
    padding: 0;
    margin: 0;
    font-weight: normal;
    list-style: none;
  }

  &.large {
    .@{bk-prefix}-select-content-wrapper {
      font-size: 14px;
    }
  }

  &.is-focus:not(.is-disabled) {
    &.normal {
      .@{bk-prefix}-select-trigger .@{bk-prefix}-select-tag {
        border-color: @primary-color;
        box-shadow: 0px 0px 3px 0px #a3c5fd;
      }
    }

    &.simplicity {
      .@{bk-prefix}-select-trigger .@{bk-prefix}-select-tag {
        border-bottom-color: @primary-color;
      }
    }
  }

  &.is-focus .@{bk-prefix}-input {
    border-color: @primary-color;
    outline: 0;
    box-shadow: 0px 0px 3px 0px @input-shadow-color;

    &.is-simplicity {
      border-color: transparent;
      border-bottom-color: @primary-color;
      box-shadow: none;

      .@{bk-prefix}-input--text {
        background-color: @input-block-color;
      }
    }
  }

  &.popover-show {
    .@{bk-prefix}-select-trigger .angle-down {
      transform: rotate(180deg);
    }
  }

  &.is-disabled {
    .@{bk-prefix}-input--text {
      cursor: not-allowed;
      background-color: #fafbfd;
    }
  }

  .@{bk-prefix}-input {
    &.is-focused {
      .active();

      &.is-simplicity {
        border-color: transparent;
        border-bottom-color: @primary-color;
        box-shadow: none;
      }
    }
  }

  .@{bk-prefix}-input--text {
    .ellipsis();
    padding-right: 24px;
    cursor: pointer;
    background-color: @white-color;
  }

  .@{bk-prefix}-select-trigger {
    position: relative;

    .@{bk-prefix}-tag-input .@{bk-prefix}-tag-input-trigger .clear-icon {
      margin-right: 0;
    }

    .@{bk-prefix}-select-tag {
      .input();
      display: flex;
      align-items: center;
      width: auto;

      &.is-simplicity {
        background-color: transparent;
        border-color: transparent;
        border-bottom-color: @input-border-color;
    
        &:hover {
          background-color: @input-block-color;
          border-color: transparent;
          border-bottom-color: @light-gray;
          box-shadow: none;
        }
      }
      
      &.has-prefix {
        padding-left: 0;
      }

      &-wrapper {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        align-items: center;
        padding: 4px 0;
        overflow: hidden;
      }

      &.collapse-tag .@{bk-prefix}-select-tag-wrapper {
        height: 30px;
      }

      &:not(.collapse-tag) {
        position: relative;
        z-index: 1;
        flex-wrap: wrap;
        height: auto;
        min-height: 32px;
      }

      &:not(.is-disabled,.is-simplicity):hover {
        border-color: #979ba5;
      }

      &.is-disabled {
        cursor: not-allowed;
        background-color: #fafbfd;
        border-color: #dcdee5;

        input {
          cursor: not-allowed;
        }

        .@{bk-prefix}-tag {
          cursor: not-allowed;

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

          .@{bk-prefix}-tag-close {
            cursor: not-allowed;
          }
        }

        .is-disabled {
          padding-left: 0;
        }
      }

      &-input {
        .input();
        .ellipsis();
        flex-grow: 1;
        width: 1%;
        height: 22px;
        padding: 0;
        margin: 0px 5px 0px 0;
        background-color: transparent;
        border: none;
      }

      .@{bk-prefix}-tag {
        max-width: 190px;
        padding: 0 4px;
      }
    }

    .angle-down {
      right: 4px;
      transition: transform .3s cubic-bezier(.4, 0, .2, 1);
      .select-icon();
      .fix-icon();
    }

    .clear-icon {
      right: 4px;
      cursor: pointer;
      transition: all .1s;
      .select-icon(14px, #c4c6cc);
      .fix-icon();

      &:hover {
        color: #979ba5;
      }
    }

    .spinner {
      right: 6px;
      .fix-icon();
    }
  }

  &--prefix-area {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 10px;
    margin-right: 10px;
    color: #63656e;
    background-color: @select-hover-color;
    border-right: 1px solid #c4c6cc;
  }
}

.@{bk-prefix}-popover {
  &.@{bk-prefix}-pop2-content {
    &.@{bk-prefix}-select-popover {
      padding: 0;
      border: 1px solid @disable-color;
      border-radius: 2px;
      box-shadow: 0 2px 6px 0 rgba(0, 0, 0, .10);

      .@{bk-prefix}-select-content-wrapper {
        .@{bk-prefix}-select-empty {
          .flex-center();
          height: 56px;
          color: #63656e;

          .spinner {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 14px;
            height: 14px;
            margin-right: 4px;
            font-size: 14px;
            color: #c4c6cc;
          }

          span {
            .icon-text()
          }
        }

        .@{bk-prefix}-select-dropdown {
          overflow: auto;

          &::-webkit-scrollbar {
            width: 4px;
            height: 4px;
          }
      
          &::-webkit-scrollbar-thumb {
            background: #dde4eb;
            border-radius: 20px;
            box-shadow: inset 0 0 6px hsla(0,0%,80%,.3);
          }
        }

        .@{bk-prefix}-select-extension {
          display: flex;
          align-items: center;
          height: 40px;
          background-color: #fafbfd;
          border-top: 1px solid #dcdee5;
          border-radius: 0 0 2px 2px;
        }

        .@{bk-prefix}-select-options {
          padding: 4px 0;
        }

        .@{bk-prefix}-select-all {
          padding: 4px 0;
          border-bottom: 1px solid @border-color;

          .wrapper {
            display: flex;
            align-items: center;
            height: 32px;
            padding: 0 12px;
            color: @default-color;
            cursor: pointer;

            &:hover {
              background-color: @select-hover-color;
            }

            &.active {
              color: @primary-color;
              background-color: @select-active-color;
            }

            .select-all-icon {
              margin-right: 4px;
              font-size: 16px;
            }
          }  
        }

        .@{bk-prefix}-select-option {
          position: relative;
          display: flex;
          align-items: center;
          min-height: 32px;
          padding: 0 12px;
          color: #63656e;
          text-align: left;
          cursor: pointer;
          user-select: none;

          .ellipsis();

          .@{bk-prefix}-select-selected-icon {
            position: absolute;
            top: 5px;
            right: 10px
          }
          .@{bk-prefix}-select-checkbox {
            margin-right: 6px;
            pointer-events: none;
            .@{bk-prefix}-checkbox-original {
              opacity: 0;
            }
          }

          &-item {
            .ellipsis();

            .is-keyword {
              display: inline-flex;
              color: @primary-color;
            }
          }

          &.is-hover {
            background-color: @select-hover-color;
          }

          &:hover {
            color: #63656e;
            background-color: @select-hover-color;
          }

          &.is-selected:not(.is-checkbox) {
            color: #3a84ff;
            background-color: #e1ecff;
          }

          &.is-disabled {
            color: #c4c6cc;
            cursor: not-allowed;
            background-color: transparent;
          }

          &.is-multiple {
            padding-right: 32px;

            &.is-selected {
              background-color: #fff
            }

            &.is-hover {
              background-color: @select-hover-color;
            }

            &:hover {
              background-color: @select-hover-color;
            }
          }
        }

        .@{bk-prefix}-select-options-loading {
          .flex-center();

          span {
            .icon-text()
          }
        }

        .@{bk-prefix}-option-group {
          &-divider-container {
            padding: 4px 11px;
          }

          &-divider {
            &:first-child .@{bk-prefix}-divider {
              display: none;
            }

            .@{bk-prefix}-select-option {
              padding-left: 12px !important;
            }
          }

          &-label {
            height: 32px;
            padding: 0 8px;
            line-height: 32px;
            color: #979ba5;
            text-align: left;

            &.collapsible {
              cursor: pointer;
            }

            // 虚拟滚动模式下不再有 .bk-option-group 容器包裹，
            // 这里补齐 disabled 的 label 样式
            &.disabled {
              .default-group-label {
                color: #c4c6cc;
                cursor: not-allowed;
              }
            }
          }

          &.collapsible {
            .@{bk-prefix}-select-option {
              padding-left: 40px;
            }
          }

          &.disabled {
            .default-group-label {
              color: #c4c6cc;
              cursor: not-allowed;
            }
          }

          .default-group-label {
            display: flex;
            align-items: center;
            user-select: none;

            &-icon {
              display: flex;
              align-items: center;
              justify-content: center;
              width: 12px;
              height: 12px;
              margin-right: 8px;
              transition: all .1s;

              &.collapse {
                transform: rotate(-90deg);
              }
            }
          }

          .@{bk-prefix}-select-option {
            padding-left: 24px;
          }
        }

        // 虚拟滚动模式：分组项缩进（无 .bk-option-group 容器时用）
        .@{bk-prefix}-select-option {
          &.is-grouped {
            padding-left: 24px;
          }

          &.is-grouped.is-group-collapsible {
            padding-left: 40px;
          }
        }

        .@{bk-prefix}-select-search-wrapper {
          display: flex;
          align-items: center;
          margin: 4px 8px 0 8px;
          border-bottom: 1px solid @input-block-hover-color;

          .icon-search {
            margin-left: 2px;
            color: @gray-color;
          }

          .@{bk-prefix}-select-search-input {
            .input();
            padding: 0 8px;
            cursor: text;
            border: none;
          }

          .@{bk-prefix}-select-search-clear {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 14px;
            height: 14px;
            margin-right: 2px;
            font-size: 14px;
            color: #c4c6cc;
            cursor: pointer;

            &:hover {
              color: #979ba5;
            }
          }
        }
      }
    }
  }
}

.@{bk-prefix}-select-tooltips {
  max-width: 600px;
}

.@{bk-prefix}-select-popover-reference {
  width: 100%;
}

.@{bk-prefix}-select-tag-overflow-title {
  height: 22px;
}