@use "../../styles/colors" as colors;
@use "../../styles/variables" as vars;
@use "../../styles/fonts" as fonts;

.city-autocomplete {
  display: flex;
  flex-direction: column;
  position: relative;

  &__labels-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    // Matches Angular `city-autocomplete__labels-container { margin-bottom: $space-m }`
    // in `components/city-autocomplete/city-autocomplete.component.scss`.
    margin-bottom: vars.$space-m;
  }

  &__label {
    // Matches Angular `city-autocomplete__label` in
    // `components/city-autocomplete/city-autocomplete.component.scss`:
    // `@include font-small($gray)` — 12px with $gray (#333), not
    // $light-gray (#657). Ensures label color matches the rest of the
    // filter sidebar (which also uses $gray via `.label--filter`).
    color: colors.$gray;
    font-size: fonts.$font-size-s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  // Angular `city-autocomplete__input` measured height = 46px with
  // 16px font-size (`Расписание рейсов` sidebar on the live site).
  // Previously this was 38px / default font-size which looked noticeably
  // shorter than Angular's pill.
  $city-input-h: 46px;

  &__input {
    display: flex;
    flex-direction: row;
    position: relative;
    align-items: center;
    width: 100%;
    height: $city-input-h;
    box-shadow: 0 0 0 1px colors.$border-input;
    border-radius: vars.$border-radius;

    .p-autocomplete {
      flex: 1;
      display: flex;
      align-items: center;
      height: 100%;
    }

    // Reset the inner PrimeReact input's native border — the outer
    // __input div carries the border+shadow already (Angular parity via
    // the global `city-autocomplete input.p-inputtext` reset rule).
    input.p-inputtext {
      border: none !important;
      box-shadow: none !important;
      height: 100%;
      font-size: fonts.$font-size-l; // 16px, matches Angular
      padding: 0 vars.$space-l;
    }

    // Also drop PrimeReact's blue focus shadow on the inner input
    // when it is focused, so the outer box-shadow stays as the only
    // visible border.
    input.p-inputtext:focus {
      box-shadow: none !important;
    }

    .button-clear {
      display: none;
      width: 32px;
      height: $city-input-h;
      border: none;
      background: transparent;
      cursor: pointer;
      font-size: fonts.$font-size-xl;
      color: colors.$light-gray;

      &::before {
        content: "×";
      }
    }
  }

  &__input--has-value {
    .button-clear {
      display: block;
    }

    .city-autocomplete__search-button {
      border-left: 1px solid colors.$border-input !important;
    }
  }

  &__input--has-error {
    box-shadow: 0 0 0 1px colors.$red;
  }

  &__search-button {
    width: 38px !important;
    min-width: 38px;
    height: $city-input-h;
    border-radius: 0 vars.$border-radius vars.$border-radius 0 !important;
    border: none !important;
    border-left: 1px solid white !important;
    background-color: transparent !important;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;

    &::before {
      content: "▾";
      display: inline-block;
      color: colors.$blue;
    }

    &:hover {
      background-color: colors.$white !important;
      border-left-color: colors.$border-input !important;
    }

    &--opened {
      background-color: colors.$blue-extra-light !important;
    }
  }
}

.city-autocomplete-popup-wrapper {
  position: relative;
}

// Mirror Angular `city-autocomplete-item`: 48px row with a thin
// bottom divider and the same 0.429em / $space-xl padding scale.
.city-autocomplete__item {
  white-space: nowrap;
  height: vars.$button-height;
  border-bottom: 1.5px solid colors.$border-input;
  display: flex;
  align-items: center;
  padding-left: 0.429em;

  &:last-child {
    border-bottom: none;
  }

  &--airport {
    padding-left: vars.$space-xl;
  }

  .city {
    white-space: nowrap;
    font-weight: fonts.$font-bold;
    color: colors.$text-color;
  }

  .country {
    white-space: nowrap;
    color: colors.$light-gray;
  }

  .airport {
    white-space: nowrap;
    color: colors.$light-gray;
  }
}

.tooltip {
  color: colors.$red;
  font-size: fonts.$font-size-s;
  margin-bottom: 4px;
}
