@import '../../style/mixins/index';

// mixins for grid system
// ------------------------
.yee-make-row(@yee-gutter: @yee-grid-gutter-width) {
  position: relative;
  height: auto;
  margin-right: (@yee-gutter / -2);
  margin-left: (@yee-gutter / -2);
  .yee-clearfix;
}

.yee-make-grid-columns() {
  .col(@index) {
    @item: ~'.@{yee-prefix}-col-@{index}, .@{yee-prefix}-col-xs-@{index}, .@{yee-prefix}-col-sm-@{index}, .@{yee-prefix}-col-md-@{index}, .@{yee-prefix}-col-lg-@{index}';
    .col((@index + 1), @item);
  }
  .col(@index, @yee-list) when (@index =< @yee-grid-columns) {
    @item: ~'.@{yee-prefix}-col-@{index}, .@{yee-prefix}-col-xs-@{index}, .@{yee-prefix}-col-sm-@{index}, .@{yee-prefix}-col-md-@{index}, .@{yee-prefix}-col-lg-@{index}';
    .col((@index + 1), ~'@{yee-list}, @{item}');
  }
  .col(@index, @yee-list) when (@index > @yee-grid-columns) {
    @{yee-list} {
      position: relative;
      padding-right: (@yee-grid-gutter-width / 2);
      padding-left: (@yee-grid-gutter-width / 2);
    }
  }
  .col(1);
}

.yee-float-grid-columns(@yee-class) {
  .col(@index) {
    // initial
    @item: ~'.@{yee-prefix}-col@{yee-class}-@{index}';
    .col((@index + 1), @item);
  }
  .col(@index, @yee-list) when (@index =< @yee-grid-columns) {
    // general
    @item: ~'.@{yee-prefix}-col@{yee-class}-@{index}';
    .col((@index + 1), ~'@{yee-list}, @{item}');
  }
  .col(@index, @yee-list) when (@index > @yee-grid-columns) {
    // terminal
    @{yee-list} {
      flex: 0 0 auto;
      float: left;
    }
  }
  .col(1); // kickstart it
}

.yee-loop-grid-columns(@index, @yee-class) when (@index > 0) {
  .@{yee-prefix}-col@{yee-class}-@{index} {
    display: block;
    box-sizing: border-box;
    width: percentage((@index / @yee-grid-columns));
  }
  .@{yee-prefix}-col@{yee-class}-push-@{index} {
    left: percentage((@index / @yee-grid-columns));
  }
  .@{yee-prefix}-col@{yee-class}-pull-@{index} {
    right: percentage((@index / @yee-grid-columns));
  }
  .@{yee-prefix}-col@{yee-class}-offset-@{index} {
    margin-left: percentage((@index / @yee-grid-columns));
  }
  .@{yee-prefix}-col@{yee-class}-order-@{index} {
    order: @index;
  }
  .yee-loop-grid-columns((@index - 1), @yee-class);
}

.yee-loop-grid-columns(@index, @yee-class) when (@index = 0) {
  .@{yee-prefix}-col@{yee-class}-@{index} {
    display: none;
  }
  .@{yee-prefix}-col-push-@{index} {
    left: auto;
  }
  .@{yee-prefix}-col-pull-@{index} {
    right: auto;
  }
  .@{yee-prefix}-col@{yee-class}-push-@{index} {
    left: auto;
  }
  .@{yee-prefix}-col@{yee-class}-pull-@{index} {
    right: auto;
  }
  .@{yee-prefix}-col@{yee-class}-offset-@{index} {
    margin-left: 0;
  }
  .@{yee-prefix}-col@{yee-class}-order-@{index} {
    order: 0;
  }
}

.yee-make-grid(@yee-class: ~'') {
  .yee-float-grid-columns(@yee-class);
  .yee-loop-grid-columns(@yee-grid-columns, @yee-class);
}
