@import '../../style/themes/index';
@import '../../style/mixins/index';
@import '../../input/style/mixin';

@yee-select-prefix-cls: ~'@{yee-prefix}-select';

.yee-selection__clear() {
  position: absolute;
  top: 50%;
  right: @yee-control-padding-horizontal - 1px;
  z-index: 1;
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  color: @yee-disabled-color;
  font-size: @yee-font-size-sm;
  font-style: normal;
  line-height: 12px;
  text-align: center;
  text-transform: none;
  background: @yee-component-background;
  cursor: pointer;
  opacity: 0;
  transition:
    color 0.3s ease,
    opacity 0.15s ease;
  text-rendering: auto;
  &::before {
    display: block;
  }
  &:hover {
    color: @yee-text-color-secondary;
  }
}

.@{yee-select-prefix-cls} {
  .yee-reset-component;

  position: relative;
  display: inline-block;
  outline: 0;

  ul,
  ol {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  > ul > li > a {
    padding: 0;
    background-color: @yee-component-background;
  }

  // arrow
  &-arrow {
    .yee-iconfont-mixin();

    position: absolute;
    top: 50%;
    right: @yee-control-padding-horizontal - 1px;
    margin-top: -@yee-font-size-sm / 2;
    color: @yee-disabled-color;
    font-size: @yee-font-size-sm;
    line-height: 1;
    transform-origin: 50% 50%;

    & &-icon svg {
      transition: transform 0.3s;
    }
  }

  &-selection {
    display: block;
    box-sizing: border-box;
    background-color: @yee-select-background;
    border: @yee-border-width-base @yee-border-style-base @yee-select-border-color;
    // strange align fix for chrome but works
    // https://gw.alipayobjects.com/zos/rmsportal/VFTfKXJuogBAXcvfAUWJ.gif
    border-top-width: @yee-border-width-base + 0.02px;
    border-radius: @yee-border-radius-base;
    outline: none;
    transition: all 0.3s @yee-ease-in-out;
    user-select: none;

    &:hover {
      .yee-hover;
    }

    .@{yee-select-prefix-cls}-focused &,
    &:focus,
    &:active {
      .yee-active;
    }

    &__clear {
      .yee-selection__clear();
    }

    &:hover &__clear {
      opacity: 1;
    }

    &-selected-value {
      float: left;
      max-width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }

  &-no-arrow &-selection-selected-value {
    padding-right: 0;
  }

  &-disabled {
    color: @yee-disabled-color;
  }

  &-disabled &-selection {
    background: @yee-input-disabled-bg;
    cursor: not-allowed;
    &:hover,
    &:focus,
    &:active {
      border-color: @yee-select-border-color;
      box-shadow: none;
    }

    &__clear {
      display: none;
      visibility: hidden;
      pointer-events: none;
    }
  }

  &-disabled &-selection--multiple &-selection__choice {
    padding-right: 10px;
    color: fade(@yee-black, 33%);
    background: @yee-background-color-base;
    &__remove {
      display: none;
    }
  }

  &-selection--single {
    position: relative;
    height: @yee-input-height-base;
    cursor: pointer;

    .@{yee-select-prefix-cls}-selection__rendered {
      margin-right: 24px;
    }
  }

  &-no-arrow {
    .@{yee-select-prefix-cls}-selection__rendered {
      margin-right: @yee-control-padding-horizontal - 1px;
    }
  }

  &-selection__rendered {
    position: relative;
    display: block;
    margin-right: @yee-control-padding-horizontal - 1px;
    margin-left: @yee-control-padding-horizontal - 1px;
    line-height: @yee-input-height-base - 2px;
    // https://github.com/ant-design/ant-design/issues/3481#issuecomment-254721026
    &::after {
      display: inline-block;
      width: 0;
      visibility: hidden;
      content: '.';
      pointer-events: none;
    }
  }

  &-lg {
    font-size: @yee-font-size-lg;
    .@{yee-select-prefix-cls}-selection--single {
      height: @yee-input-height-lg;
    }
    .@{yee-select-prefix-cls}-selection__rendered {
      line-height: @yee-input-height-lg - 2px;
    }
    .@{yee-select-prefix-cls}-selection--multiple {
      min-height: @yee-input-height-lg;
      .@{yee-select-prefix-cls}-selection__rendered {
        li {
          height: @yee-input-height-lg - 8px;
          line-height: @yee-input-height-lg - 8px;
        }
      }
      .@{yee-select-prefix-cls}-selection__clear,
      .@{yee-select-prefix-cls}-arrow {
        top: @yee-input-height-lg / 2;
      }
    }
  }

  &-sm {
    .@{yee-select-prefix-cls}-selection--single {
      height: @yee-input-height-sm;
    }
    .@{yee-select-prefix-cls}-selection__rendered {
      margin-left: @yee-control-padding-horizontal-sm - 1px;
      line-height: @yee-input-height-sm - 2px;
    }
    .@{yee-select-prefix-cls}-selection--multiple {
      min-height: @yee-input-height-sm;
      .@{yee-select-prefix-cls}-selection__rendered {
        li {
          height: @yee-input-height-sm - 8px;
          line-height: @yee-input-height-sm - 10px;
        }
      }
      .@{yee-select-prefix-cls}-selection__clear,
      .@{yee-select-prefix-cls}-arrow {
        top: @yee-input-height-sm / 2;
      }
    }
    .@{yee-select-prefix-cls}-selection__clear,
    .@{yee-select-prefix-cls}-arrow {
      right: @yee-control-padding-horizontal-sm;
    }
  }

  &-disabled &-selection__choice__remove {
    color: @yee-disabled-color;
    cursor: default;
    &:hover {
      color: @yee-disabled-color;
    }
  }

  &-search__field__wrap {
    position: relative;
    display: inline-block;
  }

  &-selection__placeholder,
  &-search__field__placeholder {
    // for TreeSelect compatibility
    position: absolute;
    top: 50%;
    right: 9px;
    left: 0;
    max-width: 100%;
    height: 20px;
    margin-top: -10px;
    overflow: hidden;
    color: @yee-input-placeholder-color;
    line-height: 20px;
    white-space: nowrap;
    text-align: left;
    text-overflow: ellipsis;
  }

  &-search__field__placeholder {
    left: @yee-control-padding-horizontal;
  }

  &-search__field__mirror {
    position: absolute;
    top: 0;
    left: 0;
    white-space: pre;
    opacity: 0;
    pointer-events: none;
  }

  &-search--inline {
    position: absolute;
    width: 100%;
    height: 100%;

    .@{yee-select-prefix-cls}-search__field__wrap {
      width: 100%;
      height: 100%;
    }

    .@{yee-select-prefix-cls}-search__field {
      width: 100%;
      height: 100%;
      font-size: 100%;
      line-height: 1;
      background: transparent;
      border-width: 0;
      border-radius: @yee-border-radius-base;
      outline: 0;
    }

    > i {
      float: right;
    }
  }

  &-selection--multiple {
    min-height: @yee-input-height-base;
    padding-bottom: 3px;
    cursor: text;
    .yee-clearfix;

    .@{yee-select-prefix-cls}-search--inline {
      position: static;
      float: left;
      width: auto;
      max-width: 100%;
      padding: 0;
      .@{yee-select-prefix-cls}-search__field {
        width: 0.75em;
        max-width: 100%;
        padding: 1px;
      }
    }

    .@{yee-select-prefix-cls}-selection__rendered {
      height: auto;
      margin-bottom: -3px;
      margin-left: 5px;
    }

    .@{yee-select-prefix-cls}-selection__placeholder {
      margin-left: 6px;
    }

    > ul > li,
    .@{yee-select-prefix-cls}-selection__rendered > ul > li {
      height: @yee-input-height-base - 8px;
      // for tree-select
      margin-top: 3px;
      line-height: @yee-input-height-base - 8px - 2px;
    }

    .@{yee-select-prefix-cls}-selection__choice {
      position: relative;
      float: left;
      max-width: 99%;
      margin-right: 4px;
      padding: 0 20px 0 10px;
      overflow: hidden;
      color: @yee-tag-default-color;
      background-color: @yee-tag-default-bg;
      border: 1px solid @yee-border-color-split;
      border-radius: @yee-border-radius-sm;
      cursor: default;
      transition: padding 0.3s @yee-ease-in-out;
      &__disabled {
        padding: 0 10px;
      }
    }

    .@{yee-select-prefix-cls}-selection__choice__content {
      display: inline-block;
      max-width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      transition: margin 0.3s @yee-ease-in-out;
    }

    .@{yee-select-prefix-cls}-selection__choice__remove {
      .yee-iconfont-mixin();

      position: absolute;
      right: 4px;
      display: inline-block;
      color: @yee-text-color-secondary;
      font-weight: bold;
      font-size: @yee-font-size-sm;
      line-height: inherit;
      cursor: pointer;
      transition: all 0.3s;
      .yee-iconfont-size-under-12px(10px);
      &:hover {
        color: @yee-icon-color-hover;
      }
    }

    .@{yee-select-prefix-cls}-selection__clear,
    .@{yee-select-prefix-cls}-arrow {
      top: @yee-input-height-base / 2;
    }
  }

  &-allow-clear &-selection--multiple &-selection__rendered,
  &-show-arrow &-selection--multiple &-selection__rendered {
    margin-right: 20px; // In case that clear button will overlap content
  }

  &-open {
    .@{yee-select-prefix-cls}-arrow {
      &-icon svg {
        transform: rotate(180deg);
      }
    }
    .@{yee-select-prefix-cls}-selection {
      .yee-active();
    }
  }

  &-combobox {
    .@{yee-select-prefix-cls}-arrow {
      display: none;
    }
    .@{yee-select-prefix-cls}-search--inline {
      float: none;
      width: 100%;
      height: 100%;
    }
    .@{yee-select-prefix-cls}-search__field__wrap {
      width: 100%;
      height: 100%;
    }
    .@{yee-select-prefix-cls}-search__field {
      position: relative;
      z-index: 1;
      width: 100%;
      height: 100%;
      box-shadow: none;
      transition:
        all 0.3s @yee-ease-in-out,
        height 0s;
    }
  }
  &-combobox&-allow-clear &-selection:hover &-selection__rendered,
  &-combobox&-show-arrow &-selection:hover &-selection__rendered {
    margin-right: 20px; // In case that clear button will overlap content
  }
}

.@{yee-select-prefix-cls}-dropdown {
  .yee-reset-component;

  position: absolute;
  top: -9999px;
  left: -9999px;
  z-index: @yee-zindex-dropdown;
  box-sizing: border-box;
  font-size: @yee-font-size-base;
  // Fix select render lag of long text in chrome
  // https://github.com/ant-design/ant-design/issues/11456
  // https://github.com/ant-design/ant-design/issues/11843
  font-variant: initial;
  background-color: @yee-select-dropdown-bg;
  border-radius: @yee-border-radius-base;
  outline: none;
  box-shadow: @yee-box-shadow-base;

  &.slide-up-enter.slide-up-enter-active&-placement-bottomLeft,
  &.slide-up-appear.slide-up-appear-active&-placement-bottomLeft {
    animation-name: antSlideUpIn;
  }

  &.slide-up-enter.slide-up-enter-active&-placement-topLeft,
  &.slide-up-appear.slide-up-appear-active&-placement-topLeft {
    animation-name: antSlideDownIn;
  }

  &.slide-up-leave.slide-up-leave-active&-placement-bottomLeft {
    animation-name: antSlideUpOut;
  }

  &.slide-up-leave.slide-up-leave-active&-placement-topLeft {
    animation-name: antSlideDownOut;
  }

  &-hidden {
    display: none;
  }

  &-menu {
    max-height: 250px;
    margin-bottom: 0;
    padding: @yee-select-dropdown-edge-child-vertical-padding 0; //Change
    padding-left: 0; // Override default ul/ol
    overflow: auto;
    list-style: none;
    outline: none;

    &-item-group-list {
      margin: 0;
      padding: 0;

      > .@{yee-select-prefix-cls}-dropdown-menu-item {
        padding-left: 20px;
      }
    }

    &-item-group-title {
      height: 32px;
      padding: 0 @yee-control-padding-horizontal;
      color: @yee-text-color-secondary;
      font-size: @yee-font-size-sm;
      line-height: 32px;
    }

    &-item-group-list &-item:first-child:not(:last-child),
    &-item-group:not(:last-child) &-item-group-list &-item:last-child {
      border-radius: 0;
    }

    &-item {
      position: relative;
      display: block;
      padding: @yee-select-dropdown-vertical-padding @yee-control-padding-horizontal;
      overflow: hidden;
      color: @yee-text-color;
      font-weight: normal;
      font-size: @yee-select-dropdown-font-size;
      line-height: @yee-select-dropdown-line-height;
      white-space: nowrap;
      text-overflow: ellipsis;
      cursor: pointer;
      transition: background 0.3s ease;

      &:hover:not(&-disabled) {
        background-color: @yee-item-hover-bg;
      }

      &:first-child {
        & when (@yee-select-dropdown-edge-child-vertical-padding = 0) {
          border-radius: @yee-border-radius-base @yee-border-radius-base 0 0;
        }
      }

      &:last-child {
        & when (@yee-select-dropdown-edge-child-vertical-padding = 0) {
          border-radius: 0 0 @yee-border-radius-base @yee-border-radius-base;
        }
      }

      &-selected {
        color: @yee-text-color;
        font-weight: @yee-select-item-selected-font-weight;
        background-color: @yee-select-item-selected-bg;
      }

      &-disabled {
        color: @yee-disabled-color;
        cursor: not-allowed;

        &:hover {
          color: @yee-disabled-color;
          cursor: not-allowed;
        }
      }

      &-active:not(&-disabled) {
        background-color: @yee-select-item-active-bg;
      }

      &-divider {
        height: 1px;
        margin: 1px 0;
        overflow: hidden;
        line-height: 0;
        background-color: @yee-border-color-split;
      }
    }
  }

  &&--multiple {
    .@{yee-select-prefix-cls}-dropdown-menu-item {
      padding-right: @yee-control-padding-horizontal + 20;
      & .@{yee-select-prefix-cls}-selected-icon {
        position: absolute;
        top: 50%;
        right: @yee-control-padding-horizontal;
        color: transparent;
        font-weight: bold;
        font-size: 12px;
        text-shadow:
          0 0.1px 0,
          0.1px 0 0,
          0 -0.1px 0,
          -0.1px 0;
        transform: translateY(-50%);
        transition: all 0.2s;
      }

      &:hover .@{yee-select-prefix-cls}-selected-icon {
        color: fade(@yee-black, 87%);
      }

      &-disabled .@{yee-select-prefix-cls}-selected-icon {
        display: none;
      }

      &-selected .@{yee-select-prefix-cls}-selected-icon,
      &-selected:hover .@{yee-select-prefix-cls}-selected-icon {
        display: inline-block;
        color: @yee-primary-color;
      }
    }
  }

  // Patch for popup adjust
  // https://github.com/ant-design/ant-design/issues/14422
  &--empty&--multiple &-menu-item {
    padding-right: @yee-control-padding-horizontal;
  }

  &-container-open,
  &-open {
    .@{yee-select-prefix-cls}-dropdown {
      display: block;
    }
  }
}
