////
/// Copyright (c) 2016-2021 Martin Donath <martin.donath@squidfunk.com>
///
/// Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
/// and/or sell copies of the Software, and to permit persons to whom the
/// Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
/// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS
////

// ----------------------------------------------------------------------------
// Rules
// ----------------------------------------------------------------------------

// Icon definitions
:root {
  --md-version-icon: svg-load("fontawesome/solid/caret-down.svg");
}

// ----------------------------------------------------------------------------

// Version selection
.md-version {
  flex-shrink: 0;
  height: px2rem(48px);
  font-size: px2rem(16px);

  // Current selection
  &__current {
    position: relative;
    // Hack: in general, we would use `vertical-align` to align the version at
    // the bottom with the title, but since the list uses absolute positioning,
    // this won't work consistently. Furthermore, we would need to use inline
    // positioning to align the links, which looks jagged.
    top: px2rem(1px);
    margin-right: px2rem(8px);
    margin-left: px2rem(28px);

    // Adjust for right-to-left languages
    [dir="rtl"] & {
      margin-right: px2rem(28px);
      margin-left: px2rem(8px);
    }

    // Version selection icon
    &::after {
      display: inline-block;
      width: px2rem(8px);
      height: px2rem(12px);
      margin-left: px2rem(8px);
      background-color: currentColor;
      mask-image: var(--md-version-icon);
      mask-repeat: no-repeat;
      content: "";

      // Adjust for right-to-left languages
      [dir="rtl"] & {
        margin-right: px2rem(8px);
        margin-left: initial;
      }
    }
  }

  // Version selection list
  &__list {
    position: absolute;
    top: px2rem(3px);
    z-index: 1;
    max-height: px2rem(36px);
    margin: px2rem(4px) px2rem(16px);
    padding: 0;
    overflow: auto;
    color: var(--md-default-fg-color);
    list-style-type: none;
    background-color: var(--md-default-bg-color);
    border-radius: px2rem(2px);
    box-shadow:
      0 px2rem(4px) px2rem(10px) hsla(0, 0%, 0%, 0.1),
      0 0           px2rem(1px)  hsla(0, 0%, 0%, 0.25);
    opacity: 0;
    transition:
      max-height 0ms 500ms,
      opacity  250ms 250ms;
    scroll-snap-type: y mandatory;

    // List on focus/hover
    &:focus-within,
    &:hover {
      max-height: px2rem(200px);
      opacity: 1;
      transition:
        max-height 250ms,
        opacity    250ms;
    }
  }

  // Version selection item
  &__item {
    line-height: px2rem(36px);
  }

  // Version selection link
  &__link {
    display: block;
    width: 100%;
    padding-right: px2rem(24px);
    padding-left: px2rem(12px);
    white-space: nowrap;
    cursor: pointer;
    transition:
      color            250ms,
      background-color 250ms;
    scroll-snap-align: start;

    // Adjust for right-to-left languages
    [dir="rtl"] & {
      padding-right: px2rem(12px);
      padding-left: px2rem(24px);
    }

    // Link on focus/hover
    &:focus,
    &:hover {
      background-color: var(--md-default-fg-color--lightest);
    }
  }
}
