// ----
// Layout
// ----

//- Mixin: Clearfix
///
/// Just your standard clearfix.
///
/// @group layout
/// @example
///   @include clearfix();

@mixin clearfix() {
  &:after {
    clear: both;
    content: '';
    display: table;
  }
}

//- Alias: cf
///
/// @group layout
/// @example
///   @include cf();
/// @alias clearfix

@mixin cf() {
  @include clearfix();
}

//- Mixin: Ratio Box
///
/// This sets a specific width/height ratio. Useful on background images,
/// iframes and Youtube embeds.
///
/// @param {variable} $ratio [1 / 1] - Aspect ratio: height / width
/// @param {variable} $bg-color [$base-gray, .2] - placeholder background color
/// @group layout
/// @example
///   figure {
///     @include ratio(16 / 9);
///   }
/// @link http://www.mademyday.de/css-height-equals-width-with-pure-css.html

@mixin ratio-box($ratio: 1 / 1, $bg-color: rgba($base-gray, .15)) {
  background-color: $bg-color;
  overflow: hidden;
  position: relative;

  > * {
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
  }

  &::before {
    content: '';
    display: block;
    height: 0;
    padding-top: (1 / $ratio) * 100%;
  }
}

//- Mixin: Cover
///
/// Useful shortcut for setting background size to cover
///
/// @param {variable} $x [center] - x position
/// @param {variable} $y [center] - y position
/// @group layout
/// @example
///   div.hero {
///     @include cover(top, center);
///   }

@mixin cover($x: center, $y: center) {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: $x $y;
}
//- Mixin: Full Page
///
/// Create a responsive full page section with intelligent defaults.
/// Resets on mobile.
///
/// @param {variable} $height [100vh] - Page height
/// @param {variable} $max-height [850px] - Max page height
/// @param {variable} $min-height [600px] - Min page height
/// @param {variable} $breakpoint [768px] - Disable below this size or pass
/// 'null' to not use a breakpoint.
/// @group layout
/// @example
///   section {
///     @include full-page();
///   }
///
///   section {
///     @include full-page(calc(100vh - 90px), 800px, 500px);
///   }
/// @link http://codepen.io/dbox/pen/OyzrrV

@mixin full-page($height: 100vh, $max-height: 850px, $min-height: 600px, $breakpoint: 768px) {
  // Disable below set breakpoint
  @if ($breakpoint) {
    @media screen and (min-width: $breakpoint) {
      height: $height;
      max-height: $max-height;
      min-height: $min-height;
    }
  // Show for all sizes
  } @else {
    height: $height;
    max-height: $max-height;
    min-height: $min-height;
  }
}

// Mixin: Vertically Align
// Cross browser vertical align. Works down to IE9.
//
// ex. @include vertically-align();

//- Mixin: Vertically Align
///
/// Cross browser vertical align. Works down to IE9.
///
/// @param {variable} $reset [Null] - Pass `false` to reset override to original
/// values
/// @group layout
/// @example
///   article {
///     @include vertically-align();
///   }
///
///   h4 {
///     @include vertically-align(false);
///   }
/// @link http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/

@mixin vertically-align($reset : null) {
  @if ($reset != false) {
    position: relative;
    top: 50%;
    transform: translateY(-50%);
  } @else {
    position: relative;
    top: 0;
    transform: translateY(0);
  }
}

//- Mixin: Horizontal Rule
///
/// Clean reset for divider lines.
///
/// @param {variable} $color [rgba(#000, .15)] - Line color
/// @param {variable} $spacing [1.5em] - Margin above and below the line
///
/// @group layout
/// @example
///   hr {
///     @include rule();
///   }
///   hr.blue {
///     @include rule(blue);
///   }
/// @todo - $border-width param

@mixin rule($color: rgba(#000, .15), $spacing: 1.5em) {
  border: 0;
  border-bottom: 1px solid $color;
  height: 0;
  padding: 0;
  margin: $spacing 0;
}


//- Mixin: Table Layout
///
/// Sets element and its children to use table layout. An old but very powerful
/// css property for flexible layout challenges.
///
/// @param {variable} $layout-type [fixed] - `fixed` or `auto`
///
/// @group layout
/// @example
///   ul {
///     @include table-layout();
///   }
/// @link http://codepen.io/dbox/pen/pvrZZV
/// @link http://colintoh.com/blog/display-table-anti-hero

@mixin table-layout($layout-type: 'fixed') {
  display: table;
  table-layout: $layout-type;
  margin: 0;
  padding: 0;
  width: 100%;

  > * {
    display: table-cell;
  }
}

//- Mixin: Absolute Center
///
/// Faster centering when your element has to be position: absolute;
///
/// @param {variable} $width [50%] - Width of your item
///
/// @group layout
/// @example
///   div {
///     @include absolute-center(400px);
///   }
/// @link http://codepen.io/dbox/pen/vLgpqL

@mixin absolute-center($width: 50%) {
  left: 0;
  margin-left: auto;
  margin-right: auto;
  max-width: $width;
  position: absolute;
  right: 0;
  width: 100%;
}

//- Mixin: Material Shadow
///
/// Box shadows based on 5 Material Design presets;
///
/// @param {variable} $z-depth [1] - shadow distance on z-axis
/// @param {variable} $strength [1] - multiplier for shadow strength/darkness
/// @param {variable} $color [1] - shadow color
/// @group layout
/// @example
///   div {
///     @include material-shadow(3);
///   }
/// @link http://codepen.io/dbox/pen/RawBEW

@mixin material-shadow($z-depth: 1, $strength: 1, $color: black) {
  @if $z-depth == 1 {
    box-shadow: 0 rem(1px) rem(3px) rgba($color, $strength * 0.14), 0 rem(1px) rem(2px) rgba($color, $strength * 0.24);
  }
  @if $z-depth == 2 {
    box-shadow: 0 rem(3px) rem(6px) rgba($color, $strength * 0.16), 0 rem(3px) rem(6px) rgba($color, $strength * 0.23);
  }
  @if $z-depth == 3 {
    box-shadow: 0 rem(10px) rem(20px) rgba($color, $strength * 0.19), 0 rem(6px) rem(6px) rgba($color, $strength * 0.23);
  }
  @if $z-depth == 4 {
    box-shadow: 0 rem(15px) rem(30px) rgba($color, $strength * 0.25), 0 rem(10px) rem(10px) rgba($color, $strength * 0.22);
  }
  @if $z-depth == 5{
    box-shadow: 0 rem(20px) rem(40px) rgba($color, $strength * 0.30), 0 rem(15px) rem(12px) rgba($color, $strength * 0.22);
  }
  @if ($z-depth < 1) or ($z-depth > 5) {
    @warn '$z-depth must be between 1 and 5';
  }
}
