@import './token.less';

@import '../../result-box/style/index.less';
@import '../../pop-over/style/index.less';
@import '../../checkbox/style/index.less';
@import '../../transfer/style/index.less';


.input-border {
  &--borderHalf {
    border-left-color: transparent !important;
    border-right-color: transparent !important;
    border-top-color: transparent !important;
  }

  &--borderNone {
    border-color: transparent !important;
  }
}

@paddingY: calc(
  (
      28px - @Form-input-lineHeight *
        @Form-input-fontSize - 1px * 2
    ) / 2
);

.@{ns}-Select2 {
  display: inline-flex;
  &--block {
    display: flex;
  }
  vertical-align: middle;
  text-align: left;
  align-items: center;
  outline: none;
  position: relative;
  font-size: @Form-input-fontSize;
  border: 1px solid var(--color-border);
  background: var(--color-bg-1);
  border-radius: 2px;
  min-height: 28px;
  padding: @paddingY 8px @paddingY 8px;
  cursor: pointer;
  color: var(--color-text-1);
  transition: border-color @animation-duration-3;

  &:hover {
    border-color: var(--primary-5);

    .@{ns}-Select2-arrow:before {
      color: var(--primary);
    }
  }
  &-value{
    .@{ns}-Select2-arrow{
      display: none;
    }
  }

  &.is-disabled {
    color: var(--color-text-4);
    background: var(--color-fill-1);
    cursor: not-allowed
  }


  .input-border();

  &-valueWrap {
    user-select: none;
    position: relative;
    flex-grow: 1;
    line-height: 1;
    // width: 0;
    display: flex;
    flex: auto;
    flex-wrap: wrap;
    max-width: 100%;
    overflow: hidden;
  }
  &-valuesNoWrap {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    line-height: 20px;
  }
  &-placeholder {
    color: var(--color-text-3);
    line-height: @Form-input-lineHeight;
    user-select: none;
    white-space: nowrap;
  }

  &-value {
    line-height: calc(
      @Form-input-lineHeight * @Form-input-fontSize
    );

    &.is-invalid {
      color: var(--color-text-4);
    }

    &.is-disabled {
      color: inherit;
    }
  }
  &--multi {
    height: auto;
    min-height: 28px;
    padding: 0 @size-1 0 @size-1;
    vertical-align: top;
    &.is-quick-static{
      padding: 0 0 0 @size-1;
    }
    &.is-quick-edit,&.is-quick-static{

      &:focus {
        box-shadow:none;
      }
      .@{ns}-Select2-valueWrap {
        .@{ns}-Select2-placeholder {
          margin-left: 0;
        }
      }
    }

    .@{ns}-Select2-valueWrap {
      > input {
        display: inline-block;
        width: 100px;
        margin-bottom: @spacing-2;
      }

      .@{ns}-Select2-placeholder {
      }
    }
    .@{ns}-Select2-values + .@{ns}-Select2-input {
      transform: translateY(0);
    }
    .@{ns}-Select2-value {
      position: static;
      white-space: normal;
      user-select: none;
      line-height: calc(
        @Form-input-lineHeight * @Form-input-fontSize - 2px
      );
      display: inline-block;
      vertical-align: middle;
      font-size: 12px;
      max-width: 100%;
    }

    .@{ns}-Select2-selection-value {
      position: relative;
      display: flex;
      flex: none;
      box-sizing: border-box;
      max-width: 100%;
      height: 22px;
      margin-top: 2px;
      margin-bottom: 2px;
      line-height: 20px;
      background-color: var(--color-fill-2);
      // border: 1px solid @Form-select-value-borderColor;
      border-radius: 2px;
      cursor: default;
      transition: font-size .3s,line-height .3s,height .3s;
      user-select: none;
      margin-inline-end: 4px;
      padding-inline-start: 4px;
      padding-inline-end: 4px;
      overflow: hidden;
      &:hover {
        background-color: var(--color-fill-3);
      }
    }

    .@{ns}-Select2-valueLabel {
      display: inline-flex;
      align-items: center;
      overflow: hidden;

      // max-width: 120px;
      // padding: 0 @size-1;
      &-con{
        width: 100%;
        overflow: hidden;
        // vertical-align: top;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
  }
  &-valueIcon {
    cursor: pointer;
    padding: 0 5px;
    color: inherit;

    &:hover {
      color: var(--color-text-1);
    }

    &.is-disabled {
      pointer-events: none;
      display: none;
      cursor: not-allowed;
      background: var(--color-fill-4);
    }

    svg {
      width: 10px;
      height: 10px;
    }
  }

  &-arrow {
    padding: 0 3px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;

    > svg {
      transition: transform @animation-duration-3;
      display: inline-block;
      color: inherit;
      top: 0;
    }
  }

  &.is-opened:not(.is-mobile) &-arrow > svg {
    transform: rotate(180deg);
  }


  &-menu {
    max-height: 300px;
    padding-top: 4px;
    padding-bottom: 4px;
    overflow: auto;
    user-select: none;
    .@{ns}-Checkbox--sm > i {
      margin-top: -3px;
      margin-right: 4px;
    }
  }
  &--longlist {
    overflow: hidden;
    max-height: max-content;
  }
  &-input {
    cursor: pointer;
    outline: none;
    border: none;
    margin: 0 8px;
    height: 28px;
    font-size: 12px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: @size-1;
    display: flex;
    align-items: center;


    > svg {
      color: #999;
      width: 16px;
      min-width: 16px;
      height: 16px;
      margin-right: @spacing-2;
    }

    > input {
      margin-left: @size-1;
      outline: none;
      border: none;
      flex-grow: 1;
      background: transparent;
      position: relative;
      // top: 0.125em;
    }
  }

  &-option {
    cursor: pointer;
    min-width: 120px;
    padding: calc(
        (
            @Form-select-menu-height - @Form-input-lineHeight *
              @Form-input-fontSize
          ) / 2
      )
      8px;

    &.is-active {
      color: @Form-select-menu-onActive-color;
      background: @Form-select-menu-onActive-bg;
    }

    // 是否高亮样式放到hover中
    // &.is-highlight {
    //   color: @Form-select-menu-onHover-color;
    //   background: @Form-select-menu-onHover-bg;
    //   .checked-i{
    //     border-color: @Form-input-onFocused-borderColor;
    //   }
    // }

    &.is-disabled {
      color: @Form-select-menu-onDisabled-color;
      background: @Form-select-menu-onDisabled-bg;
    }

    > label {
      display: block;
    }

    > a {
      float: right;
      margin-left: @spacing-2;
      display: none;
    }

    &.is-highlight > a {
      display: block;
    }

    // checked  hover效果
    &:hover{
      color: @Form-select-menu-onHover-color;
      background: @Form-select-menu-onHover-bg;
      .checked-i{
        border-color: @Form-input-onFocused-borderColor;
      }
      .@{ns}-Checkbox{
        input{
          &:not(:disabled) + i {
            border-color: @Checkbox-onHover-color;
          }
        }
      }
    }
  }

  &-noResult {
    color: var(--color-border-3);
    line-height: @Form-input-lineHeight;
    font-size: @Form-select-input-fontSize;
    user-select: none;
    padding: calc(
        (
            @Form-select-menu-height - @Form-input-lineHeight *
              @Form-input-fontSize
          ) / 2
      )
      8px;
  }

  &-option-hl {
    color: var(--primary-5);
  }

  &-addBtn {
    display: block;
    cursor: pointer;
    padding: calc(
        (
            @Form-select-menu-height - @Form-input-lineHeight *
              @Form-input-fontSize
          ) / 2

      8px);

    &:hover {
      text-decoration: none;
    }

    > svg {
      width: 16px;
      height: 16px;
      margin-right: @gap-base;
    }
  }

  &.is-focused:not(.is-mobile),
  &.is-opened:not(.is-mobile) {
    border-color: @Form-input-onFocused-borderColor;
    color: @Form-select-onFocused-color;
  }

  &-spinner {
    line-height: calc(
      @Form-input-lineHeight * @Form-input-fontSize
    );
  }

  &-clear {
    .input-clear();
  }

  &-popup {
    height: 320px;
  }
}

.@{ns}-Select2-popover {
  margin-top: calc(@Form-select-outer-borderWidth * -1);

  background: @Form-select-menu-bg;
  color: @Form-select-menu-color;
  border: @Form-select-outer-borderWidth solid
    @Form-input-onFocused-borderColor;
  box-shadow: @Form-select-outer-boxShadow;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  min-width: 100px;

  // PopOver 上已经配置了，这个要是配置就会覆盖，所以先干掉好了
  // z-index: 10;

  &.@{ns}-PopOver--leftTopLeftBottom {
    margin-top: calc(
      (@Form-select-popoverGap - @Form-select-outer-borderWidth) *
        -1
    );
  }
}

.@{ns}-SelectControl {
  position: relative;
  // flex: 1;
  display: flex;
  &.is-inline{
    flex: inherit;
    display: inline-flex;
  }

  &:not(.is-inline) > .@{ns}-Select2 {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }

  &.is-error > .@{ns}-Select2 {
    border-color: @Form-input-onError-borderColor;
    background: @Form-input-onError-bg;
  }

  .@{ns}-TransferDropDown-popover {
    border: none;

    .@{ns}-Tree-list {
      .@{ns}-Tree-item {
        .@{ns}-Tree-itemLabel,
        .@{ns}-Tree-item--isLeaf {
          &:hover {
            background-color: transparent;
            .@{ns}-Tree-itemText {
              background: @Transfer2-title-bg;
            }
          }
          &:active {
            background-color: transparent;
            .@{ns}-Tree-itemText {
              background: @Tree-item-onChekced-bg;
            }
          }
       
        }
      }
    }
  }

}

.@{ns}-Select2.is-quick-edit {
  border-color: transparent;
  .@{ns}-Select2-clear{
    display: none;
  }

  &:focus {
    box-shadow:none;
  }
  &:hover:not(.is-disabled){
    border-color: var(--primary-5);

    .@{ns}-Select2-clear{
      display: inherit;
    }
  }
  &.is-opened,&.is-focused{
    box-shadow: none;
  }

}
.@{ns}-Select2.is-quick-static {
  border-color: transparent;
  background: none;
  box-shadow: none;
  display: inline-flex;
  .@{ns}-Select2-clear{
    display: none;
  }
  &:hover{
    background: none;
    border-color: transparent;
    .@{ns}-Select2-clear{
      display: inherit;
    }
  }
  &.is-opened,&.is-focused{
    border-color: transparent;
  }
}

.@{ns}-Select2.is-error {
  border-color: @Form-input-onError-borderColor !important;
  background: @Form-input-onError-bg;
}

// 需要能撑开
@include media-breakpoint-up(sm) {
  .@{ns}-Form-control--sizeXs > .@{ns}-Select2,
  .@{ns}-Form-control--sizeSm > .@{ns}-Select2,
  .@{ns}-Form-control--sizeMd > .@{ns}-Select2,
  .@{ns}-Form-control--sizeLg > .@{ns}-Select2 {
    min-width: 100%;
    max-width: 100%;
    display: inline-flex !important;

    .@{ns}-Select2-valueWrap {
      width: 0; // ! 没有这个会撑开。
    }
  }
}

.@{ns}-PopOver.@{ns}-Select2-popover {
  .@{ns}-Select2-menu {
    .@{ns}-Select2-option {
      margin-bottom: 4px;
      height: 28px;
      line-height: 18px;
    }
    .@{ns}-Select2-addBtn {
      height: 28px;
      line-height: 26px;
    }
  }
}
