@use '@/styles/variables' as *;
@use '@/styles/mixins' as *;

.selectWrapper {
  display: flex;
  flex-direction: column;
  gap: $spacing-xs;
  position: relative;

  &__label {
    font-size: $font-size-sm;
    font-weight: $font-weight-medium;
    color: $text-primary;
  }

  &__error {
    font-size: $font-size-xs;
    color: $error-color;
  }
}

.select {
  @include flex-between;
  border: 1px solid $border-color;
  border-radius: $border-radius-base;
  background-color: $card-background;
  cursor: pointer;
  @include transition-fast;

  &--sm {
    padding: $spacing-sm $spacing-md;
    font-size: $font-size-sm;
  }

  &--md {
    padding: $spacing-md $spacing-base;
    font-size: $font-size-base;
  }

  &--lg {
    padding: $spacing-base $spacing-lg;
    font-size: $font-size-md;
  }

  &--open {
    border-color: $primary-color;
    box-shadow: 0 0 0 3px rgba($primary-color, 0.1);
  }

  &--disabled {
    background-color: $background-color;
    cursor: not-allowed;
    opacity: 0.6;
  }

  &--error {
    border-color: $error-color;

    &.select--open {
      box-shadow: 0 0 0 3px rgba($error-color, 0.1);
    }
  }

  &__value {
    flex: 1;
    @include text-ellipsis;
    color: $text-primary;

    &--placeholder {
      color: $text-disabled;
    }
  }

  &__search {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: inherit;
    color: $text-primary;

    &::placeholder {
      color: $text-disabled;
    }
  }

  &__arrow {
    @include flex-center;
    width: 16px;
    height: 16px;
    color: $text-secondary;
    @include transition-fast;
    flex-shrink: 0;
    margin-left: $spacing-sm;

    svg {
      width: 100%;
      height: 100%;
    }

    &--open {
      transform: rotate(180deg);
    }
  }

  &__dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: $spacing-xs;
    background-color: $card-background;
    border: 1px solid $border-color;
    border-radius: $border-radius-base;
    box-shadow: $shadow-md;
    max-height: 240px;
    overflow-y: auto;
    z-index: $z-index-dropdown;
    @include custom-scrollbar;
    animation: slideInDown $duration-fast $ease-out;
  }

  &__option {
    padding: $spacing-md $spacing-base;
    cursor: pointer;
    @include transition-fast;
    @include text-ellipsis;

    &:hover {
      background-color: $background-color;
    }

    &--selected {
      background-color: rgba($primary-color, 0.08);
      color: $primary-color;
    }

    &--disabled {
      color: $text-disabled;
      cursor: not-allowed;

      &:hover {
        background-color: transparent;
      }
    }
  }

  &__empty {
    padding: $spacing-xl $spacing-base;
    text-align: center;
    color: $text-secondary;
    font-size: $font-size-sm;
  }
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
