@use "pix-design-tokens/typography";
@use "component-state/form";
@use "pix-design-tokens/shadows";

.pix-select {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  gap: var(--pix-spacing-1x);
  width: var(--pix-select-width);
  max-width: 100%;

  &--inline {
    flex-direction: row;
    gap: var(--pix-spacing-2x);
    align-items: baseline;
  }

  &--full-width {
    width: 100%;
  }

  &__dropdown {
    @extend %pix-shadow-xs;

    position: absolute;
    z-index: 200;
    width: 100%;
    min-width: fit-content;
    max-height: 12rem;
    margin-top: var(--pix-spacing-1x);
    padding: 0;
    overflow-y: auto;
    white-space: nowrap;
    list-style-type: none;
    background-color: var(--pix-neutral-0);
    border-top: none;
    border-radius: 0 0 var(--pix-spacing-1x) var(--pix-spacing-1x);
    transition: all 0.1s ease-in-out;

    &::-webkit-scrollbar {
      width: 0.5rem;
    }

    &::-webkit-scrollbar-track {
      background: var(--pix-neutral-20);
      border: 1px solid var(--pix-neutral-20);
      border-radius: var(--pix-spacing-1x);
    }

    &::-webkit-scrollbar-thumb {
      width: 0.375rem;
      background: var(--pix-neutral-100);
      border-radius: var(--pix-spacing-1x);
    }

    &::-webkit-scrollbar-thumb:hover {
      background: var(--pix-neutral-100);
    }

    &--closed {
      visibility: hidden;
      opacity: 0;
    }
  }



  &__search {
    display: flex;
    margin: var(--pix-spacing-2x) var(--pix-spacing-3x);
    color: var(--pix-neutral-100);
    border-bottom: 2px solid var(--pix-neutral-100);
    border-radius: var(--pix-spacing-1x) var(--pix-spacing-1x) 0 0;

    &:focus-within {
      background: var(--pix-neutral-20);
      border-bottom: 2px solid var(--pix-primary-500);
    }
  }

  &__error-message {
    @extend %pix-input-error-message;
  }

  &__button-container {
    flex-grow: 1;
  }
}

.pix-select-button {
  @extend %pix-body-s;
  @extend %pix-form-element-state;

  position: relative;
  display: flex;
  gap: var(--pix-spacing-4x);
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--pix-spacing-2x) var(--pix-spacing-3x);
  color: var(--pix-neutral-900);
  background-color: var(--pix-neutral-0);
  border: 1px var(--pix-neutral-500) solid;
  border-radius: var(--pix-spacing-1x);
  cursor: pointer;

  &__icon {
    color: var(--pix-neutral-900);
  }

  // &#{&}--error is equal to => .pix-select-button.pix-select-button--error
  // https://sass-lang.com/documentation/style-rules/declarations/#interpolation
  &#{&}--error {
    @extend %pix-form-error-state;
  }

  &__text {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  &__dropdown-icon {
    @extend %pix-body-s;

    color: var(--pix-neutral-900);
    pointer-events: none;
  }
}

.pix-select-search {
  &__input {
    @extend %pix-body-s;

    width: 100%;
    margin: var(--pix-spacing-1x);
    padding-left: var(--pix-spacing-2x);
    border: none;

    &:focus {
      background: var(--pix-neutral-20);
      outline: none;
    }
  }

  &__icon {
    margin: auto var(--pix-spacing-1x);
    color: var(--pix-neutral-100)
  }
}
