@import '../../styles/variables';
@import '../../styles/mixins';

.TopMenuItem {
  position: relative;

  &_open {
    .TopMenuItem__button {
      background-color: lighten($gray70, 20%);
      box-shadow: inset 0 2px 0 0 $brand-color;
    }

    .TopMenuItem__dropdown-menu {
      display: inline-block;
    }

    &::after,
    &::before {
      position: absolute;
      left: 50%;
      overflow: hidden;
      width: 0;
      height: 0;
      margin-left: -.5rem;
      content: ' ';
      pointer-events: none;
      border: solid transparent;
      border-width: .8rem .5rem;
      z-index: layer('dropdown');
    }

    &::after {
      bottom: -12px;
      border-bottom-color: $white;
    }

    &::before {
      bottom: -11px;
      border-bottom-color: lighten($gray70, 20%);
    }
  }

  &__button {
    display: flex;
    align-items: center;
    overflow: hidden;
    width: 100%;
    margin: 0;
    padding: 5px 16px;
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    border: 0;
    background: transparent;
    outline: none;
    height: $layout-header-height;

    @media screen and (max-width: $layout-mobile) {
      padding: 16px;
      font-size: 16px;
    }

    & + & {
      border-top: 1px solid lighten($gray70, 20%);
    }

    &:hover,
    &:focus {
      color: $black;
      outline: 0;
      background: lighten($gray70, 20%);
    }
  }

  &__dropdown-menu {
    top: $layout-header-height + 10px;
    left: 50%;
    display: none;
    padding: 4px 0;
    transition: opacity .25s ease;
    transform: translateX(-50%);
    border: solid .5px $gray95;
    border-radius: $border-radius;
    background: $white;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.25), 0 4px 12px 0 rgba(0, 0, 0, 0.1);
    z-index: layer('dropdown');

    @media screen and (min-width: $layout-tablet) {
      max-width: 250px;
    }

    @media screen and (max-width: $layout-mobile) {
      position: fixed;
      width: 95%;
    }

    @media screen and (min-width: $layout-mobile) {
      position: absolute;
    }

    &_right {
      @media screen and (min-width: $layout-mobile) {
        left: 95%;
        transform: translateX(-100%);
      }
    }

    &_left {
      @media screen and (min-width: $layout-mobile) {
        right: 95%;
        transform: translateX(-100%);
      }
    }
  }

  &__dropdown-item {
    display: flex;
    align-items: center;
    overflow: hidden;
    width: 100%;
    margin: 0;
    text-align: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    border: 0;
    background: transparent;
    padding: $spacing * 4;
    font-size: 16px;
    color: $black;
    outline: 0;

    &:hover,
    &:focus {
      color: $black;
      background: lighten($gray70, 20%);
    }

    @media screen and (min-width: $layout-mobile) {
      padding: 5px $spacing * 4;
    }

    & + & {
      border-top: 1px solid lighten($gray70, 20%);
    }

    &-icon {
      margin-right: 5px;
    }
  }

  &__overlay {
    position: fixed;
    z-index: 9;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;

    &:before {
      content: '';
      @include content-overlay;
    }
  }
}
