////
/// Copyright (c) 2016-2019 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
////

// ----------------------------------------------------------------------------
// Keyframes
// ----------------------------------------------------------------------------

// Show source facts
@keyframes md-source__facts--done {
  0% {
    height: 0;
  }

  100% {
    height: px2rem(13px);
  }
}

// Show source fact
@keyframes md-source__fact--done {
  0% {
    transform: translateY(100%);
    opacity: 0;
  }

  50% {
    opacity: 0;
  }

  100% {
    transform: translateY(0%);
    opacity: 1;
  }
}

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

// Source container
.md-source {
  display: block;
  padding-right: px2rem(12px);
  transition: opacity 0.25s;
  font-size: px2rem(13px);
  line-height: 1.2;
  white-space: nowrap;

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

  // Hovered source container
  &:hover {
    opacity: 0.7;
  }

  // Necessary for vertical alignment
  &::after {
    display: inline-block;
    height: px2rem(48px);
    content: "";
    vertical-align: middle;
  }

  // Repository platform icon
  &__icon {
    display: inline-block;
    width: px2rem(48px);
    height: px2rem(48px);
    content: "";
    vertical-align: middle;

    // Align SVG, do not scale, as this will incur strange formatting bugs
    // in Internet Explorer and Edge
    svg {
      width: px2rem(24px);
      height: px2rem(24px);
      margin-top: px2rem(12px);
      margin-left: px2rem(12px);

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

    // Correct alignment, if icon is present
    + .md-source__repository {
      margin-left: px2rem(-44px);
      padding-left: px2rem(40px);

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

  // Repository name
  &__repository {
    display: inline-block;
    max-width: 100%;
    margin-left: px2rem(12px);
    font-weight: 700;
    text-overflow: ellipsis;
    overflow: hidden;
    vertical-align: middle;
  }

  // Source facts (statistics etc.)
  &__facts {
    margin: 0;
    padding: 0;
    font-size: px2rem(11px);
    font-weight: 700;
    list-style-type: none;
    opacity: 0.75;
    overflow: hidden;

    // Show after the data was loaded
    [data-md-state="done"] & {
      animation: md-source__facts--done 0.25s ease-in;
    }
  }

  // Fact
  &__fact {
    float: left;

    // Adjust for RTL languages
    [dir="rtl"] & {
      float: right;
    }

    // Show after the data was loaded
    [data-md-state="done"] & {
      animation: md-source__fact--done 0.4s ease-out;
    }

    // Middle dot before fact
    &::before {
      margin: 0 px2rem(2px);
      content: "\00B7";
    }

    // Remove middle dot on first fact
    &:first-child::before {
      display: none;
    }
  }
}

// Source file
.md-source-file {
  display: inline-block;
  margin: 1em 0.5em 1em 0;
  padding-right: px2rem(5px);
  border-radius: px2rem(2px);
  background-color: $md-color-black--lightest;
  font-size: ms(-1);
  list-style-type: none;
  cursor: pointer;
  overflow: hidden;

  // Icon
  &::before {
    @extend %md-icon;

    display: inline-block;
    margin-right: px2rem(5px);
    padding: px2rem(5px);
    background-color: $md-color-black--lighter;
    color: $md-color-white;
    font-size: ms(0);
    content: "\E86F"; // code
    vertical-align: middle;
  }

  // Some properties need to be set with higher specificity due to the default
  // styling of text links inside typesetted content
  html & {
    transition:
      background 0.4s,
      color      0.4s,
      box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    // Icon
    &::before {
      transition: inherit;
    }
  }

  // Color needs even higher specifity because custom color palettes are set
  // using the body and override text links inside typesetted content
  html body .md-typeset & {
    color: $md-color-black--light;
  }

  // Hovered source file
  &:hover {
    @include z-depth-focus;

    // Icon
    &::before {
      background-color: $md-color-accent;
    }
  }
}
