@use "sass:math";
@use "./../abstracts/index";

@keyframes show {
  from {
    @include index.dropdown-animation-hidden;
  }
  to {
    @include index.dropdown-animation-visible;
  }
}

@keyframes hide {
  from {
    @include index.dropdown-animation-visible;
  }
  to {
    @include index.dropdown-animation-hidden;
  }
}

.dropdown {
  position: relative;

  &__label {
    display: block;
    width: 100%;
    appearance: none;
    border: none;
    outline: none;
    font-size: inherit;
    color: inherit;
    text-decoration: inherit;
    text-transform: inherit;
    text-align: center;
    padding: index.$dropdown-label-padding;
    background-color: index.$dropdown-label-background-color;
    border-radius: index.$dropdown-border-radius;
    &:after {
      display: none;
      content: '';
      width: 100%;
      height: index.$dropdown-options-space-from-label * 1.5;
      position: absolute;
      top: 100%;
      left: 0;
      background-color: transparent;
    }
  }

  &__options {
    visibility: visible;
    z-index: 1;
    min-width: 110px;
    max-height: 50vh;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 0);
    list-style: none;
    font-size: 13px;
    background-color: index.$dropdown-options-background-color;
    border-radius: index.$dropdown-border-radius;
    box-shadow: index.$shadow-soft;
    overflow: auto;
    animation: hide math.div(index.$dropdown-animation-timing, 2)  ease forwards;

    @include index.up-to-mobile {
      top: 75%;
    }

    &:before {
      content: '';
      width: 0;
      height: 0;
      position: absolute;
      top: 0;
      left: 50%;
      border-style: solid;
      border-width: 0 index.$dropdown-arrow-size math.div(index.$dropdown-arrow-size, 2) index.$dropdown-arrow-size;
      border-color: transparent transparent index.$dropdown-options-background-color transparent;
      transform: translate(-50%, -100%);
    }
  }

  &__option {
    a {
      display: block;
      padding: index.$dropdown-option-padding;
      color: rgba(black, .6);
      text-decoration: none;
      border-bottom: 1px solid index.$dropdown-option-border-bottom-color;
      transition: background-color .3s ease, color .3s ease;
      text-transform: none;
      font-weight: normal;
      &:hover,
      &:focus {
        color: index.$color-primary;
        background-color: rgba(index.$color-neutral-dark, .025);
      }
    }
    &:last-child a {
      border-bottom: none;
    }
  }

  &:hover &__label:after, &:hover &__options,
  &:focus &__label:after, &:focus &__options {
    display: block;
  }

  &:hover &__options,
  &:focus &__options {
    animation: show index.$dropdown-animation-timing ease forwards;
  }
}
