@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: getCssVar('index-normal');
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

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

@include b(select) {
  position: relative;

  @include e(popper) {
    @include picker-popper(
      getCssVar('color-white'),
      1px solid getCssVar('color-neutral-2'),
      getCssVar('box-shadow-lv2')
    );
  }

  .#{$namespace}-select-tags-wrapper {
    &.has-prefix {
      margin-left: 6px;
    }
  }

  // @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__wrapper {
      box-shadow: getCssVar('box-shadow-lv1');
    }
  }

  @include select-common(select);

  .#{$namespace}-input__wrapper {
    cursor: pointer;

    .#{$namespace}-input__inner {
      cursor: pointer;
      padding-right: 0;
    }

    @include when(focus) {
      border-color: getCssVar('color-primary-3');
      background-color: getCssVar('color-white');
    }
  }

  .#{$namespace}-input {
    & .#{$namespace}-select__caret {
      font-size: 16px;
      transition: transform getCssVar('transition-duration');
      transform: rotateZ(0deg);
      cursor: pointer;

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

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

      //   &:hover {
      //     color: getCssVar('select-close-hover-color');
      //   }
      // }

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

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

        &:hover {
          box-shadow: none;
        }
      }
      & .#{$namespace}-input__inner {
        cursor: not-allowed;
      }
      & .#{$namespace}-select__caret {
        cursor: not-allowed;
        color: getCssVar('color-neutral-5');
      }
    }

    &.is-focus .#{$namespace}-input__wrapper {
      border-color: getCssVar('color-primary-3');
      background-color: getCssVar('color-white');
    }
  }

  @include e(input) {
    border: none;
    outline: none;
    padding: 0;
    margin-left: 12px;
    color: getCssVar('color-neutral-9');
    font-size: 16px;
    line-height: 20px;
    appearance: none;
    height: 20px;
    background-color: transparent;
  }

  @include e(close) {
    cursor: pointer;
    position: absolute;
    top: 8px;
    z-index: getCssVar('index-top');
    right: 24px;
    color: getCssVar('color-neutral-9');
    font-size: 16px;

    &:hover {
      color: getCssVar('color-primary-3');
    }
  }

  @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: 2px 4px 2px 0;
      &:last-child {
        margin-right: 0;
      }

      .#{$namespace}-tag__close {
        margin-left: 4px;
        color: getCssVar('color-neutral-9');
        background-color: transparent;

        &:hover {
          color: getCssVar('color-primary-3');
        }
      }
    }

    .#{$namespace}-tag--info {
      font-size: 12px;
      line-height: 16px;
      color: getCssVar('color-neutral-9');
      background-color: getCssVar('color-neutral-3');
      border-radius: getCssVar('border-radius-sm');
    }
  }

  @include e(header) {
    padding: 8px;
    border-bottom: 1px solid getCssVar('color-neutral-2');
  }

  @include e(footer) {
    padding: 8px;
    border-top: 1px solid getCssVar('color-neutral-2');
  }
}
