// Adde Dropdown
//
// A dropdown that is triggered upon clicking a target element.
//
// You can implement a dropdown type class and custom placement with the Ember addon like this:
// ```
// {{#adde-dropdown position="left-start" class="custom-class"}}
//   Menu
// {{/adde-dropdown}}
// ```
//
// #### Important
// Note that dropdowns are an official Ember addon in adde-pop,
// so please do not use the below example HTML directly.
// Please use the Ember component instead.
// [See Adde Dropdown Docs >>](/docs/adde-pop/class/addon/components/adde-dropdown.js~AddeDropdown.html)
//
// Markup:
// <div class="adde-dropdown is-visible [modifier-class]" x-placement="left-start">
//   <div class="adde-dropdown-content" tabindex="0">
//     Menu
//   </div>
// </div>
//
// Styleguide Adde Pop - Adde Dropdown

.adde-dropdown {
  position: absolute;
  z-index: $adde-dropdown-z-index;

  background: $adde-dropdown-background-color;
  padding: $adde-dropdown-box-padding;

  border: $adde-dropdown-border-width $adde-dropdown-border-style $adde-dropdown-border-color;
  border-radius: $adde-dropdown-border-radius;

  color: $adde-dropdown-text-color;
  text-align: $adde-dropdown-text-align;
  font-weight: $adde-dropdown-font-weight;
  font-size: $adde-dropdown-font-size;
  line-height: $adde-dropdown-line-height;
  font-family: $adde-dropdown-font-family;

  transition: $adde-dropdown-fade-transition;
  opacity: 0;

  &.is-visible {
    opacity: 1;
  }

  // Determine placement of box shadow and offset depending on direction
  $dropdown-directions: 'bottom', 'top', 'right', 'left';
  @each $direction in $dropdown-directions {
    &[x-placement^=#{$direction}] {
      @include create-offset-box-shadow($direction, $adde-dropdown-box-shadow-x-offset, $adde-dropdown-box-shadow-y-offset, $adde-dropdown-box-shadow-spread, $adde-dropdown-box-shadow-color);
    }
  }

  // If we need margin offset between target and dropdown
  @if ($adde-dropdown-offset != 0) {
    &[x-placement^='bottom'] {
      margin-top: $adde-dropdown-offset;
    }

    &[x-placement^='top'] {
      margin-bottom: $adde-dropdown-offset;
    }

    &[x-placement^='left'] {
      margin-right: $adde-dropdown-offset;
    }

    &[x-placement^='right'] {
      margin-left: $adde-dropdown-offset;
    }
  }
}

// Content level elements

.adde-dropdown-content {
  // We theoretically should not be making super long dropdown menus,
  // but just in case, this sets up the content area to scroll if needed
  overflow: auto;
  min-width: $adde-dropdown-min-width;
  max-width: $adde-dropdown-max-width;

  // We need to check whether a vh height was set (which is by default,
  // but the user may overwrite to '0' or 'none').
  // If set, we need to add the optional max pixel height css media query (explained below).
  @if non-zero-value($adde-dropdown-max-height-vh) {
    max-height: $adde-dropdown-max-height-vh;
    // If the dropdown has been given a vh max height AND a px max height, we want to
    // cap the max-height out once the rendered vh height gets longer than the px amount given.
    // Until there is a better way to cap percentage/viewport based values like this, we are using a media query.
    //
    // Checking if px value was given, otherwise we don't need to do anything
    @if non-zero-value($adde-dropdown-max-height-px) {
      // Figure out the ratio of the given vh height to the current screen height
      $viewport-ratio: $adde-dropdown-max-height-vh / 100vh;
      $viewport-adjusted-height: $adde-dropdown-max-height-px / $viewport-ratio;
      @media screen and (min-height: $viewport-adjusted-height) {
        max-height: $adde-dropdown-max-height-px;
      }
    }
  } @else {
    // If vh var was not set, we need to set the given pixel height onto the content div, since it
    // will not have been set in the mixin (we give the mixin the vh var by default)
    max-height: $adde-dropdown-max-height-px;
  }
}
