@use 'sass:map';

@use 'mixins/mixins' as *;
@use 'mixins/utils' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;
@use './select-dropdown.scss';
@use './select/common.scss' as *;

@mixin select-tag-normal {
  white-space: normal;
  z-index: var(--el-index-normal);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

@include b(select) {
  @include set-component-css-var('select', $select);
}

@include b(select) {
  display: inline-block;
  position: relative;
  line-height: map.get($input-height, 'default');

  @include e(popper) {
    @include picker-popper(
      map.get($select-dropdown, 'bg-color'),
      map.get($select-dropdown, 'border'),
      map.get($select-dropdown, 'shadow')
    );
  }

  .#{$namespace}-select-tags-wrapper {
    &.has-prefix {
      margin-left: map.get($select-tags-prefix-padding, 'default');
    }
  }

  @each $size in (large, small) {
    @include m($size) {
      line-height: map.get($input-height, $size);
      .#{$namespace}-select-tags-wrapper {
        &.has-prefix {
          margin-left: map.get($select-tags-prefix-padding, $size);
        }
      }
    }
  }

  .#{$namespace}-select__tags > span {
    display: inline-block;
  }

  &:hover:not(.#{$namespace}-select--disabled) {
    .#{$namespace}-input__inner {
      box-shadow: 0 0 0 1px var(--el-select-border-color-hover) inset;
    }
  }

  @include select-common(select);

  .#{$namespace}-input__inner {
    cursor: pointer;
    display: inline-flex;

    &:focus {
      @include inset-input-border(
        var(--el-select-input-focus-border-color),
        true
      );
    }
  }

  .#{$namespace}-input {
    display: flex;

    & .#{$namespace}-select__caret {
      color: var(--el-select-input-color);
      font-size: var(--el-select-input-font-size);
      transition: transform var(--el-transition-duration);
      transform: rotateZ(180deg);
      cursor: pointer;

      @include when(reverse) {
        transform: rotateZ(0deg);
      }

      @include when(show-close) {
        font-size: var(--el-select-font-size);
        text-align: center;
        transform: rotateZ(180deg);
        border-radius: var(--el-border-radius-circle);
        color: var(--el-select-input-color);
        transition: var(--el-transition-color);

        &:hover {
          color: var(--el-select-close-hover-color);
        }
      }

      &.#{$namespace}-icon {
        position: relative;
        height: inherit;
        z-index: 2;
      }
    }

    &.is-disabled {
      & .#{$namespace}-input__inner {
        cursor: not-allowed;

        &:hover {
          @include inset-input-border(var(--el-select-disabled-border));
        }
      }
      & .#{$namespace}-select__caret {
        cursor: not-allowed;
      }
    }

    &.is-focus .#{$namespace}-input__inner {
      @include inset-input-border(
        var(--el-select-input-focus-border-color),
        true
      );
    }
  }

  @include e(input) {
    border: none;
    outline: none;
    padding: 0;
    margin-left: 15px;
    color: var(--el-select-multiple-input-color);
    font-size: var(--el-select-font-size);
    appearance: none;
    height: 28px;
    background-color: transparent;
  }

  @include e(close) {
    cursor: pointer;
    position: absolute;
    top: 8px;
    z-index: var(--el-index-top);
    right: 25px;
    color: var(--el-select-input-color);
    line-height: 18px;
    font-size: var(--el-select-input-font-size);

    &:hover {
      color: var(--el-select-close-hover-color);
    }
  }

  @include e(tags) {
    position: absolute;
    line-height: normal;
    top: 50%;
    transform: translateY(-50%);
    @include select-tag-normal;
  }

  @include e(collapse-tags) {
    @include select-tag-normal;
  }

  @include e(collapse-tag) {
    line-height: inherit;
    height: inherit;
    display: flex;
  }

  .#{$namespace}-select__tags {
    .#{$namespace}-tag {
      box-sizing: border-box;
      border-color: transparent;
      margin: 4px 8px;
      background-color: var(--el-bg-color-base);
      color: var(--el-text-color-primary);
      height: 24px;
      line-height: 24px;
      &:last-child {
        margin-right: 0;
      }

      .#{$namespace}-icon-close {
        right: -7px;
        top: 0;
        border: 1px solid var(--el-text-color-primary);
        color: var(--el-text-color-primary);
        transform: scale(0.6);

        &:hover {
          color: var(--el-text-color-secondary);
          background-color: transparent;
          border-color: var(--el-text-color-secondary);
        }

        &::before {
          display: block;
          transform: translate(0, 0.5px);
        }
      }
    }
  }
  .#{$namespace}-tag--info {
    background-color: #f0f2f5;
  }
}
