// Mixins

// edit font rendering -> tip: use for light text on dark backgrounds
@mixin fontSmooth {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@mixin tooltip($parent_element, $button, $icon )
{
  .#{$parent_element}
  {
    opacity: 1;
    visibility: visible;
    z-index: 1;
     
    &:hover
    {
      .#{$button}
      {
        visibility: visible;
        overflow: visible;
      }
    }

    .#{$button}
    {
      background: none;
      font-size: 0;
      border-top-width: 0;
      color: inherit; 
      padding: 0;
      text-align: right; 
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer; 
      
      .tooltip {
        max-width: 15rem;
        transition: all .3s ease; 
        font-size: 12px;   
        font-weight: 400;     
        line-height: 1;
        // text-transform: uppercase; 
        // border-radius: 2px;
        position: absolute;
        top: -35px;
        right: auto;
        left: 50%;
        // transform:translateX(-50%);
        transform: translate3d(-50%, 0, 0);
        visibility: hidden;
        pointer-events: none;
        white-space: nowrap;
        text-align: center;
        padding: 8px 9px 6px 9px;
        
        @include breakpoint(large)
        {
          animation: shop_tooltip_hover_out .3s;
        }
        
        &:after {
            position: absolute;
            bottom: -16px;
            right: auto;
            left: 50%;
            transform: translate3d(-50%, 0, 0);
            content: '';
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 10px;
            border-color: transparent transparent transparent;
            border-top-color: #0a0a0a;
        } 
      }

      &:hover
      {
        .tooltip
        {
          @include breakpoint(large)
          {
            animation: shop_tooltip_hover_in .3s;
            animation-fill-mode: forwards;
            visibility: visible;
          }
        }
      }

      &:after
      {
        @include barberry_icon('#{$icon}');
        @include global-transition();
        // border-radius: 50%;
        // padding: 10px;
        font-size: 16px; 
        // border-width: 1px;
        // border-style: solid;
      }
    }
  }
}

@mixin bottom_line_transition()
{
  &:before
  {
    content: "";
    width: 0;
    height: 2px;
    display: block;  
    position: absolute;
    bottom: -2px; 
    transition: width ease .3s;
  }

  &:hover
  {
    &:before
    {
      width: 100%; 
    }
  }
}

@mixin barberry_icon($icon) {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'Barberry' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;

  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  content: $icon;
}



@mixin loader($width: 14px, $height: 14px) {
  @keyframes loader_spinner {
    100% {
      transform: rotate(360deg);
    }
  }

  @keyframes loader_fade {
    0%
    {
      opacity: 0;
    }

    100%
    {
      opacity: 1;
    }
  }
       
  &:after {
    content: '';
    display: inline-block;
    box-sizing: border-box;
    width: $width;
    height: $height;
    border-radius: 100%;
    border: 1px solid transparent;
    animation: loader_fade .5s ease-in, loader_spinner .5s linear infinite;
  }
}

// box-shadow

@mixin box-shadow($value) {
    -webkit-box-shadow: $value;
    -moz-box-shadow: $value;
    box-shadow: $value;
}

// text-shadow

@mixin text-shadow($value) {
    -webkit-text-shadow: $value;
    -moz-text-shadow: $value;
    text-shadow: $value;
}

// border-radius

@mixin border-radius($radius) {
  -moz-border-radius: $radius;
  -webkit-border-radius: $radius;
  -ms-border-radius: $radius;
  border-radius: $radius;
  background-clip: padding-box; /* stops bg color from leaking outside the border: */ 
}

// Responsive Font

@mixin font($family, $weight, $size, $line, $spacing : 'auto', $maxSize: false) {
  font-family: $family;

  @if type-of($weight) == number {
    font-weight: $weight;
  } @else {
    font-weight: map-get($weights, $weight);
  }

  @include responsive-size($size, $size, $maxSize);
  line-height: $line / $size + 0em;
  letter-spacing: $spacing / 1000 + 0em;
}


@function get-vw($target) {
  $vw-context: (1500 * 0.01);
  @return ($target / $vw-context);
}

/// @param {Number}   $responsive  - Viewport-based size
/// @param {Number}   $min         - Minimum font size (px)
/// @param {Number}   $max         - Maximum font size (px)
/// @include responsive-size(5vw, 35px, 150px);
@mixin responsive-size($px, $min, $max: false) {
  $responsive: get-vw($px);
  $min-breakpoint: $min / $responsive * 100;

  @media (max-width: #{$min-breakpoint}px) {
    font-size: $min * 1px;
  }

  @if $max {
    $max-breakpoint: $max / $responsive * 100;

    @media (min-width: #{$max-breakpoint}px) {
      font-size: $max * 1px;
    }
  }

  font-size: $px * 1px;
  font-size: $responsive * 1vw;
}


/* -----
Size
----- */
@mixin size($width, $height) {
	width: $width;
	height: $height;
}

/// linear-interpolation
/// Calculate the definition of a line between two points
/// @param $map - A SASS map of viewport widths and size value pairs
/// @returns A linear equation as a calc() function
/// @example
///   font-size: linear-interpolation((320px: 18px, 768px: 26px));
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@function linear-interpolation($map) {
  $keys: map-keys($map);
  @if (length($keys) != 2) {
    @error "linear-interpolation() $map must be exactly 2 values";
  }
  // The slope
  $m: (map-get($map, nth($keys, 2)) - map-get($map, nth($keys, 1)))/(nth($keys, 2) - nth($keys,1));

  // The y-intercept
  $b: map-get($map, nth($keys, 1)) - $m * nth($keys, 1);

  // Determine if the sign should be positive or negative
  $sign: "+";
  @if ($b < 0) {
    $sign: "-";
    $b: abs($b);
  }

  @return calc(#{$m*100}vw #{$sign} #{$b});
}

/// list-remove
/// Remove an item from a list
/// @param $list - A SASS list
/// @param $index - The list index to remove
/// @returns A SASS list
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@function list-remove($list, $index) {
  $newList: ();
  @for $i from 1 through length($list) {
    @if $i != $index {
      $newList: append($newList, nth($list,$i), 'space');
    }
  }
  @return $newList;
}

/// list-sort
/// Sort a SASS list
/// @param $list - A SASS list
/// @returns A sorted SASS list
/// @requires function list-remove
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@function list-sort($list) {
  $sortedlist: ();
  @while length($list) > 0 {
    $value: nth($list,1);
    @each $item in $list {
      @if $item < $value {
        $value: $item;
      }
    }
    $sortedlist: append($sortedlist, $value, 'space');
    $list: list-remove($list, index($list, $value));
  }
  @return $sortedlist;
}

/// map-sort
/// Sort map by keys
/// @param $map - A SASS map
/// @returns A SASS map sorted by keys
/// @requires function list-sort
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@function map-sort($map) {
  $keys: list-sort(map-keys($map));
  $sortedMap: ();
  @each $key in $keys {
    $sortedMap: map-merge($sortedMap, ($key: map-get($map, $key)));
  }
  @return $sortedMap;
}

/// poly-fluid-sizing
/// Generate linear interpolated size values through multiple break points
/// @param $property - A string CSS property name
/// @param $map - A SASS map of viewport unit and size value pairs
/// @requires function linear-interpolation
/// @requires function map-sort
/// @example
///   @include poly-fluid-sizing('font-size', (576px: 22px, 768px: 24px, 992px: 34px));
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@mixin poly-fluid-sizing($property, $map) {
  // Get the number of provided breakpoints
  $length: length(map-keys($map));

  // Error if the number of breakpoints is < 2
  @if ($length < 2) {
    @error "poly-fluid-sizing() $map requires at least values"
  }

  // Sort the map by viewport width (key)
  $map: map-sort($map);
  $keys: map-keys($map);

  // Minimum size
  #{$property}: map-get($map, nth($keys,1));

  // Interpolated size through breakpoints
  @for $i from 1 through ($length - 1) {
    @media (min-width:nth($keys,$i)) {
      $value1: map-get($map, nth($keys,$i));
      $value2: map-get($map, nth($keys,($i + 1)));
      // If values are not equal, perform linear interpolation
      @if ($value1 != $value2) {
        #{$property}: linear-interpolation((nth($keys,$i): $value1, nth($keys,($i+1)): $value2));
      } @else {
        #{$property}: $value1;
      }
    }
  }

  // Maxmimum size
  @media (min-width:nth($keys,$length)) {
    #{$property}: map-get($map, nth($keys,$length));
  }
}


// opacity

@mixin opacity ($value: 0) {
  $value-percentage: $value * 100;

  opacity: $value;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=#{$value-percentage})";
  filter: alpha(opacity=#{$value-percentage});
}

// transition

@mixin transition($transition...) {
    -moz-transition:    $transition;
    -o-transition:      $transition;
    -webkit-transition: $transition;
    transition:         $transition;
}
@mixin transition-property($property...) {
    -moz-transition-property:    $property;
    -o-transition-property:      $property;
    -webkit-transition-property: $property;
    transition-property:         $property;
}
@mixin transition-duration($duration...) {
    -moz-transition-property:    $duration;
    -o-transition-property:      $duration;
    -webkit-transition-property: $duration;
    transition-property:         $duration;
}
@mixin transition-timing-function($timing...) {
    -moz-transition-timing-function:    $timing;
    -o-transition-timing-function:      $timing;
    -webkit-transition-timing-function: $timing;
    transition-timing-function:         $timing;
}
@mixin transition-delay($delay...) {
    -moz-transition-delay:    $delay;
    -o-transition-delay:      $delay;
    -webkit-transition-delay: $delay;
    transition-delay:         $delay;
}

// transform
@mixin transform($transforms) {
     -moz-transform: $transforms;
       -o-transform: $transforms;
      -ms-transform: $transforms;
  -webkit-transform: $transforms;
          transform: $transforms;
}

@mixin transform-origin($transforms) {
     -moz-transform-origin: $transforms;
       -o-transform-origin: $transforms;
      -ms-transform-origin: $transforms;
  -webkit-transform-origin: $transforms;
          transform-origin: $transforms;
}

// transform
@mixin filter($filters) {
      -webkit-filter: $filters;
         -moz-filter: $filters;
           -o-filter: $filters;
          -ms-filter: $filters;
              filter: $filters;
}

// animation

@mixin keyframes($animation-name) {
    @-webkit-keyframes #{$animation-name} {
        @content;
    }
    @-moz-keyframes #{$animation-name} {
        @content;
    }  
    @-ms-keyframes #{$animation-name} {
        @content;
    }
    @-o-keyframes #{$animation-name} {
        @content;
    }  
    @keyframes #{$animation-name} {
        @content;
    }
}

@mixin animation-name($str) { 
  -webkit-animation-name:: #{$str};
  -moz-animation-name:: #{$str};
  -o-animation-name:: #{$str};
  -ms-animation-name:: #{$str};
  animation-name:: #{$str};   
}

@mixin animation($str) {
  -webkit-animation: #{$str};
  -moz-animation: #{$str};
  -ms-animation: #{$str};
  -o-animation: #{$str};
  animation: #{$str};      
}

@mixin animation-fill-mode($str) {
  -webkit-animation-fill-mode: #{$str};
  -moz-animation-fill-mode: #{$str};
  animation-fill-mode: #{$str};    
}

@mixin backface-visibility ($arguments) {
  -webkit-backface-visibility: $arguments;
     -moz-backface-visibility: $arguments;
      -ms-backface-visibility: $arguments;
       -o-backface-visibility: $arguments;
          backface-visibility: $arguments;
}

@mixin placeholder {
  &::-webkit-input-placeholder {@content};
  &:-moz-placeholder           {@content};
  &::-moz-placeholder          {@content};
  &:-ms-input-placeholder      {@content};  
}

@mixin dropdowns_shadow() 
{
  box-shadow: 0px 0px 35px -10px rgba(0,0,0,0.25);
}

@mixin foundation_dropdown_animation()
{
  @include breakpoint(large)
  {
    > .js-dropdown-active
    {
      animation: drop_down_out .25s ease-in-out;
      animation-fill-mode: forwards;
      transform-origin: center top;
    }

    &:hover
    {
      > .js-dropdown-active
      {
        animation: drop_down_in .3s ease-in-out;
        animation-fill-mode: forwards;
        transform-origin: center top;
      }
    }
  }
}

@mixin form_items_sizes() 
{
  height: rem-calc(48);
  line-height: rem-calc(48);
  padding: 0 $form-spacing;
  font-size: rem-calc(16);
}


@mixin global_transition()
{
  transition: all .3s ease-in-out;
}


@mixin foundation_dropdown-pane_animation($direction: "top")
{
  @include breakpoint(large)
  {
    .dropdown-pane
    {
      opacity: 0;
      transition: all .3s ease-in-out;
      transition-delay: .05s;
      outline: 1px solid transparent;

      transform: perspective(500px) rotateX(-5deg);
      transform-origin: center top;

      @if ($direction == "left") {
        transform: perspective(500px) rotateY(2deg);
            transform-origin: left center;
      }

      &:hover,
      &.is-open.animated
      {
        opacity: 1;
            transform: perspective(9999px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
      }
    }
  }
}

@mixin tag_links {
  display: flex;
  flex-flow: row wrap;
  margin-bottom: rem-calc(-4);

  a  {
    color: inherit;
    padding: rem-calc(8) rem-calc(12);
    margin: 0 rem-calc(4) rem-calc(4) 0;
    text-transform: capitalize;
    font-size: 16px;
    line-height: 1.2;
    
    &:hover {
      opacity: 1;
    }
  }
}