/// Create a mobile-first responsive grid kind of inspired by Foundation and BassCss
/// You can set some things by overriding some values as follows:
/// ```scss
/// $breakpoints: (
///   'phablet'     : 480px,
///   'tablet'      : 768px,
///   'laptop'      : 992px,
///   'desktop'     : 1200px
/// ) !default;
///
/// $columns--total         : 12 !default;
///
/// $column-gutter          : 20px !default;
/// ```
///
/// @group layout
/// @parameter {measure} $gutter [$column-gutter] The spacing between columns can be on `px`, `em`, `rem` probably even `%`
/// @parameter {number} $total [$columns--total] Total number of columns to have in the grid
/// @parameter {map} $sizes [$breakpoints] A map with the names and measures of each breakpoint.
/// @requires {mixin} cf Clearfix Mixin
///
/// @example scss Input with all defaults
///   @include createGrid;
///
/// @example css Output (Shortened)
///   .row {
///     margin-left: -10px;
///     margin-right: -10px; }
///     .row::after {
///       content: '';
///       display: block;
///       clear: both; }
///
///   [class^='col-'] {
///     float: left;
///     padding-left: 10px;
///     padding-right: 10px;
///     width: 100%;
///   }
///
///   .col-1 {
///     width: 8.33333%; }
///   // All the way to...
///   .col-12 {
///     width: 100%; }
///
///   @media (min-width: 480px) {
///     .col-phablet-1 {
///       width: 8.33333%; }
///     // All the way to...
///     .col-phablet-12 {
///       width: 100%; } }
///
///   @media (min-width: 768px) {
///     .col-tablet-1 {
///       width: 8.33333%; }
///     // All the way to...
///     .col-tablet-12 {
///       width: 100%; } }
///
///   @media (min-width: 992px) {
///     .col-laptop-1 {
///       width: 8.33333%; }
///     // All the way to...
///     .col-laptop-12 {
///       width: 100%; } }
///
///   @media (min-width: 1200px) {
///     .col-desktop-1 {
///       width: 8.33333%; }
///     // All the way to...
///     .col-desktop-12 {
///       width: 100%; } }

@mixin createGrid($gutter: $column-gutter, $total: $columns--total, $sizes: $breakpoints) {
  // First we create the row that will hold the columns
  .row {
    margin-left: $gutter / 2 * -1;
    margin-right: $gutter / 2 * -1;

    // Clearfix
    @include cf;
  }

  [class^='col-'] {
    float: left;
    padding-left: $gutter / 2;
    padding-right: $gutter / 2;
    width: 100%;
  }

  // We do a simple loop to output the bottom level columns
  @for $i from 1 through $columns--total {
    .col-#{$i} {
      width: percentage($i / $total);
    }

    .col-offset-#{$i} {
      margin-left: percentage($i / $total);
    }
  }

  // Now we loop each sizes in the list of breakpoint-classes
  @each $name, $breakpoint in $sizes {
    @media (min-width: $breakpoint) {
      @for $i from 1 through $columns--total {
        .col-#{$name}-#{$i} {
          width: percentage($i / $total);
        }

        .col-#{$name}-offset-#{$i} {
          margin-left: percentage($i / $total);
        }
      }
    }
  }
}
