/**
 * @Author 瞿龙俊 - qulongjun@shine.design
 * @Date 2019/3/24 14:40
 */
@import './breakpoints';

@mixin make-container($gutter: $grid-gutter-width) {
  width: 100%;
  padding-right: $gutter / 2;
  padding-left: $gutter / 2;
  margin-right: auto;
  margin-left: auto;
}

@mixin make-container-max-widths() {
  @each $breakpoint, $container-max-width in $container-max-widths {
    @include media-breakpoint-up($breakpoint, $breakpoints) {
      max-width: $container-max-width;
    }
  }
}

@mixin make-row($gutter: $grid-gutter-width) {
  display: flex;
  flex-wrap: wrap;
  margin-right: -$gutter / 2;
  margin-left: -$gutter / 2;
}

@mixin make-col($size, $columns: $grid-columns) {
  flex: 0 0 percentage($size / $columns);
  max-width: percentage($size / $columns);
}

@mixin make-col-ready($gutter: $grid-gutter-width) {
  position: relative;
  width: 100%;
  padding-right: $gutter / 2;
  padding-left: $gutter / 2;
}

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

@mixin make-grid-columns() {
  %grid-column {
    position: relative;
    width: 100%;
    padding-right: $gutter / 2;
    padding-left: $gutter / 2;
  }

  @each $breakpoint in map-keys($breakpoints) {
    $infix: breakpoint-infix($breakpoint, $breakpoints);

    @for $i from 1 through $columns {
      .#{$classPrefix}-col#{$infix}-#{$i} {
        @extend %grid-column;
      }
    }
    .#{$classPrefix}-col#{$infix},
    .#{$classPrefix}-col#{$infix}-auto {
      @extend %grid-column;
    }

    @include media-breakpoint-up($breakpoint, $breakpoints) {
      .col#{$infix} {
        flex-basis: 0;
        flex-grow: 1;
        max-width: 100%;
      }
      .#{$classPrefix}-col#{$infix}-auto {
        flex: 0 0 auto;
        width: auto;
        max-width: 100%;
      }

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

      .#{$classPrefix}-order#{$infix}-first {
        order: -1;
      }

      .#{$classPrefix}-order#{$infix}-last {
        order: $columns + 1;
      }

      @for $i from 0 through $columns {
        .#{$classPrefix}-order#{$infix}-#{$i} {
          order: $i;
        }
      }

      @for $i from 0 through ($columns - 1) {
        @if not ($infix == "" and $i == 0) {
          .#{$classPrefix}-offset#{$infix}-#{$i} {
            @include make-col-offset($i, $columns);
          }
        }
      }
    }
  }
}

