/*
* @Author: zhongjiahao
* @Date:   2016-09-05 17:54:06
* @Last Modified by:   zhongjiahao
* @Last Modified time: 2016-12-12 18:44:30
*/

$enable-flex: true;

$grid-columns: 24;
$grid-gutter-width: 40px;

$grid-breakpoints: (
  xs: 0,
  sm: 544px,
  md: 768px,
  lg: 992px,
  xl: 1200px
);

$container-max-widths: (
  sm: 576px,
  md: 720px,
  lg: 940px,
  xl: 1140px
); 

@mixin make-container($gutter: $grid-gutter-width) {
  margin-left: auto;
  margin-right: auto;
  padding-left:  ($gutter / 2);
  padding-right: ($gutter / 2);
  @if not $enable-flex {
    @include f-cf();
  }
}


// For each breakpoint, define the maximum width of the container in a media query
@mixin make-container-max-widths($max-widths: $container-max-widths, $breakpoints: $grid-breakpoints) {
  @each $breakpoint, $container-max-width in $max-widths {
    @include media-breakpoint-up($breakpoint, $breakpoints) {
      max-width: $container-max-width;
    }
  }
}

@mixin make-row($gutter: $grid-gutter-width) {
  @if $enable-flex {
    display: flex;
    flex-wrap: wrap;
  } @else {
    @include f-cf();
  }
  margin-left:  ($gutter / -2);
  margin-right: ($gutter / -2);
}

@mixin make-col-ready($gutter: $grid-gutter-width) {
  position: relative;
  min-height: 1px; // Prevent collapsing
  padding-right: ($gutter / 2);
  padding-left:  ($gutter / 2);

  // Prevent columns from becoming too narrow when at smaller grid tiers by
  // always setting `width: 100%;`. This works because we use `flex` values
  // later on to override this initial width.
  @if $enable-flex {
    width: 100%;
  }
}

@mixin make-col($size, $columns: $grid-columns) {
  @if $enable-flex {
    flex: 0 0 percentage($size / $columns);
    // Add a `max-width` to ensure content within each column does not blow out
    // the width of the column. Applies to IE10+ and Firefox. Chrome and Safari
    // do not appear to require this.
    max-width: percentage($size / $columns);
  } @else {
    float: left;
    width: percentage($size / $columns);
  }
}

@mixin make-col-offset($size, $columns: $grid-columns) {
  margin-left: percentage($size / $columns);
}

@mixin make-col-push($size, $columns: $grid-columns) {
  left: if($size > 0, percentage($size / $columns), auto);
}

@mixin make-col-pull($size, $columns: $grid-columns) {
  right: if($size > 0, percentage($size / $columns), auto);
}

@mixin make-col-modifier($type, $size, $columns) {
  // Work around the lack of dynamic mixin @include support (https://github.com/sass/sass/issues/626)
  @if $type == push {
    @include make-col-push($size, $columns);
  } @else if $type == pull {
    @include make-col-pull($size, $columns);
  } @else if $type == offset {
    @include make-col-offset($size, $columns);
  }
}

// Framework grid generation
//
// Used only by Bootstrap to generate the correct number of grid classes given
// any value of `$grid-columns`.

@mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter-width, $breakpoints: $grid-breakpoints) {

  // Common properties for all breakpoints
  %grid-column {
    position: relative;
    // Prevent columns from collapsing when empty
    min-height: 1px;
    // Inner gutter via padding
    padding-right: ($gutter / 2);
    padding-left: ($gutter / 2);

    @if $enable-flex {
      width: 100%;
    }
  }

  $breakpoint-counter: 0;
  @each $breakpoint in map-keys($breakpoints) {
    $breakpoint-counter: ($breakpoint-counter + 1);

    @for $i from 1 through $columns {
      .col_#{$breakpoint}-#{$i} {
        @extend %grid-column;
      }
    }

    @include media-breakpoint-up($breakpoint, $breakpoints) {
      // Provide basic `.col-{bp}` classes for equal-width flexbox columns
      @if $enable-flex {
        .col_#{$breakpoint} {
          position: relative;
          flex-basis: 0;
          flex-grow: 1;
          max-width: 100%;
          min-height: 1px;
          padding-right: ($grid-gutter-width / 2);
          padding-left:  ($grid-gutter-width / 2);
          -webkit-box-sizing: border-box;
          -moz-box-sizing: border-box;
          box-sizing: border-box;
        }
      }

      @for $i from 1 through $columns {
        .col_#{$breakpoint}-#{$i} {
          @include make-col($i, $columns);
        }
      }

      @each $modifier in (pull, push) {
        @for $i from 0 through $columns {
          .#{$modifier}_#{$breakpoint}-#{$i} {
            @include make-col-modifier($modifier, $i, $columns)
          }
        }
      }

      // `$columns - 1` because offsetting by the width of an entire row isn't possible
      @for $i from 0 through ($columns - 1) {
        @if $breakpoint-counter != 1 or $i != 0 { // Avoid emitting useless .offset-xs-0
          .offset_#{$breakpoint}-#{$i} {
            @include make-col-modifier(offset, $i, $columns)
          }
        }
      }
    }
  }
}

@function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
  $min: map-get($breakpoints, $name);
  @return if($min != 0, $min, null);
}

@mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
  $min: breakpoint-min($name, $breakpoints);
  @if $min {
    @media (min-width: $min) {
      @content;
    }
  } @else {
    @content;
  }
}
