.select {
  @extend %context;

  max-width: 360px;
  display: flex;
  flex-direction: column;
}

.select__search-icon {
  color: $palette-neutral-600;
  padding: 0 10px;
  font-size: 16px;

  .select__search:focus-within & {
    color: $palette-blue-500;
  }
}

.select__search {
  flex: 0 0;
  position: relative;
  border-bottom: 1px solid $palette-neutral-200;

  @include flex-align-items;
}

.select__search-input {
  display: block;
  width: 100%;
  border: none;
  padding: 0 12px 0 0;

  @include rounded($rounded);
  @include fixed-height(36px, 12px);

  &::placeholder {
    color: $palette-neutral-700;
  }
}

.select__items {
  position: relative;
  list-style: none;
  padding: 0;
  margin: 0;
  min-height: 0;
  max-height: (4 * 36px) + 20px; // we show max 4 items
  // note that the value is `scroll` and not `auto` because it depends on the
  // v-auto-overflow-scroll directive.
  overflow-y: scroll;

  &::before,
  &::after {
    content: '';
    display: block;
    height: 4px;
    width: 100%;
  }

  // This class can be set if the max-height is managed by a container element.
  &.select__items--no-max-height {
    max-height: none;
  }

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

.select__items--empty {
  padding: 20px 10px;
  white-space: normal;
  text-align: center;
  color: $palette-neutral-700;
}

.select__items-loading {
  position: relative;
  height: 32px;

  &::after {
    content: '';
    margin-top: -7px;
    margin-left: -7px;

    @include loading(14px);
    @include absolute(50%, auto, 0, 50%);
  }
}

.select__item-label {
  color: $color-neutral-600;
  margin: 10px 0 10px 10px;
  font-size: 14px;
}

.select__item-active-icon {
  text-align: center;
  color: $palette-neutral-1200;
  position: absolute;
  top: 8px;
  right: 5px;
  font-size: 17px;
  display: none;

  .select__item.disabled &,
  .select__item-link:active & {
    color: $palette-neutral-400;
  }
}

.select__item {
  position: relative;
  margin: 0 4px 3px;
  user-select: none;

  @include rounded($rounded);

  &:last-child {
    margin-bottom: 0;
  }

  &:hover,
  &.hover {
    background-color: $palette-neutral-100;
  }

  &--selected {
    background-color: $palette-neutral-100;
  }

  &--indented {
    margin-left: 20px;
  }

  &.select__item--loading::before {
    content: ' ';

    @include loading(14px);
    @include absolute(9px, 9px, auto, auto);
  }

  &.active:not(.select__item--loading) {
    background-color: rgba($palette-neutral-1300, 0.04);

    .select__item-active-icon {
      display: block;
    }

    &:not(.select__item--no-options):hover {
      .select__item-active-icon {
        display: none;
      }
    }
  }

  &.disabled {
    background-color: transparent;
    cursor: not-allowed;

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

.select__item-link {
  display: block;
  color: $palette-neutral-1300;
  padding: 8px 32px 8px 10px;

  .select__item--has-notification & {
    padding-right: 48px;
  }

  &:hover {
    text-decoration: none;
  }

  .select__item.disabled & {
    color: $palette-neutral-700;

    &:hover {
      cursor: inherit;
    }
  }
}

.select__item-link--indented {
  padding-left: 14px;
}

.select__item-name {
  display: flex;
  align-items: center;
  font-weight: 500;
  line-height: 15px;
  gap: 6px;

  @extend %ellipsis;

  .select__item-link:active & {
    color: $palette-neutral-900;
  }
}

.select__item-name-text {
  @extend %ellipsis;

  &--forced-height {
    height: 16px;
  }
}

.select__item-icon {
  font-size: 16px;

  .select__item.disabled &,
  .select__item-link:active & {
    color: $palette-neutral-900;
  }
}

.select__item-image {
  max-width: 15px;
  max-height: 15px;
}

.select__item-description {
  font-size: 12px;
  color: $palette-neutral-900;
  white-space: normal;
  line-height: 18px;
  font-weight: 400;
  padding-top: 6px;
}

.select__item-options {
  display: none;
  text-align: center;
  width: 32px;
  color: $palette-neutral-800;
  font-size: 17px;

  @include absolute(5px, 0, auto, auto);

  &:hover {
    color: $palette-neutral-1200;
  }

  :not(.select__item--loading):not(.select__item--no-options):hover > & {
    display: block;
  }
}

.select__description {
  padding-bottom: 14px;
  text-align: center;
}

.select__footer {
  flex: 0 0;
  border-top: 1px solid $palette-neutral-200;
  padding: 4px 4px 0;
}

.select__footer-button {
  position: relative;
  display: block;
  padding: 0 10px;
  color: $palette-neutral-1300;
  user-select: none;
  border-bottom-left-radius: 2px;
  border-bottom-right-radius: 2px;
  margin-bottom: 4px;

  @include rounded($rounded);
  @include fixed-height(36px, 14px);
  @include flex-align-items(6px);

  &:hover {
    background-color: rgba($palette-neutral-1300, 0.04);
    text-decoration: none;
  }

  &.button--loading {
    background-color: $palette-neutral-400;
  }
}

.select__footer-create {
  display: flex;
  flex-wrap: wrap;
}

.select__footer-create-link {
  position: relative;
  width: 50%;
  color: $palette-neutral-1300;
  padding: 0 10px;
  margin-bottom: 4px;
  min-width: 0;
  line-height: 26px;
  font-size: 13px;

  @include rounded($rounded);
  @include flex-align-items(4px);

  &:only-child {
    width: 100%;
    flex: unset;
    margin-right: unset !important;
    padding-left: 6px;
  }

  &:hover {
    text-decoration: none;
  }

  &.select__footer-create-link--disabled {
    color: $palette-neutral-1000;
    cursor: inherit;
  }

  &:not(.select__footer-create-link--disabled):hover {
    text-decoration: none;
    background-color: rgba($palette-neutral-1300, 0.04);
  }
}

.select__footer-create-link-icon {
  color: $palette-neutral-800;
  font-size: 14px;
  margin-left: auto;

  .select__footer-create-link:not(.select__footer-create-link--disabled):hover
    & {
    color: $palette-neutral-1300;
  }
}
