//////////////////////////////
// Enable ligatures
//////////////////////////////
@mixin enable-ligatures($extend: null) {
  $extend: if($extend != null, $extend, toolkit-get('ligature extend'));

  @if $extend {
    @include dynamic-extend('enable ligatures') {
      @include enable-ligatures;
    }
  }
  @else {
    -webkit-font-feature-settings:"liga","dlig";
    -moz-font-feature-settings:"liga=1, dlig=1";
    -moz-font-feature-settings:"liga","dlig";
    -ms-font-feature-settings:"liga","dlig";
    -o-font-feature-settings:"liga","dlig";
    font-feature-settings: "liga","dlig";
  }
}

//////////////////////////////
// Font Face
//////////////////////////////
@mixin font-face($name, $files, $weight: null, $style: null, $inline-woff: null) {
  $weight: if($weight != null, $weight, toolkit-get('font face weight'));
  $style: if($style != null, $style, toolkit-get('font face style'));
  $inline-woff: if($inline-woff != null, $inline-woff, toolkit-get('font face inline woff'));

  $font-stack: ();
  $font-src: '';
  $eot: false;
  $font-extensions: ('eot': 'embedded-opentype', 'woff2': 'woff2', 'woff': 'woff', 'ttf': 'truetype', 'svg': 'svg');

  @each $ext, $format in $font-extensions {
    @if map-has-key($files, $ext) {
      @if function-exists(inline-font-files) and $inline-woff == true and ($ext == 'woff' or $ext == 'woff2') {
        $font-src: inline-font-files(map-get($files, $ext));
      }
      @else if function-exists(font-url) {
        $font-src: font-url(map-get($files, $ext)) format($format);
        @if $ext == 'eot' {
          $eot: $font-src;
          $font-src: font-url(map-get($files, $ext) + '#iefix') format($format);
        }
      }
      @else {
        $font-src: url(map-get($files, $ext)) format($format);
        @if $ext == 'eot' {
          $eot: $font-src;
          $font-src: url(map-get($files, $ext) + '#iefix') format($format);
        }
      }
      $font-stack: append($font-stack, $font-src, 'comma');
    }

  }

  @font-face {
    font-family: $name;
    font-weight: $weight;
    font-style: $style;
    @if $eot {
      src: $eot;
    }
    @if length($font-stack) > 0 {
      src: $font-stack;
    }
  }
}

//////////////////////////////
// Icon Font
// From http://icomoon.io
//////////////////////////////
@mixin icon-font($font-stack, $speak: null, $extend: null) {
  $speak: if($speak != null, $speak, toolkit-get('icon font speak'));
  $extend: if($extend != null, $extend, toolkit-get('icon font extend'));

  font-family: $font-stack;
  @if $speak == false {
    speak: none;
  }
  @include icon-font--core($extend);
}

@mixin icon-font--core($extend: null) {
  $extend: if($extend != null, $extend, toolkit-get('icon font extend'));

  @if $extend  {
    @include dynamic-extend('icon font core') {
      @include icon-font--core(false);
    }
  }
  @else {
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;

    @include enable-ligatures($extend);

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

//////////////////////////////
// Font Fade In
//////////////////////////////
@mixin content-fade-in($duration: null, $loading: null, $extend: null) {
  $duration: if($duration != null, $duration, toolkit-get('fade in duration'));
  $loading: if($loading != null, $loading, toolkit-get('fade in loading class'));
  $extend: if($extend != null, $extend, toolkit-get('fade in extend'));

  @if $extend == true and $duration == toolkit-get('fade in duration') and $loading == toolkit-get('fade in loading class') {
    @include dynamic-extend('content fade in') {
      @include content-fade-in($extend: false);
    }
  }
  @else {
    opacity: 1;
    @if not mixin-exists('single-transition') {
      -webkit-transition: opacity $duration;
      transition: opacity $duration;
    }
    @else {
      @include single-transition(opacity $duration);
    }

    #{$loading} & {
      opacity: 0;
    }
  }
}
