/*! @gold.au/grid-12 v3.0.0 */

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// grid-12 module globals
// Implementation of the Bootstrap 3 grid.
//
// Content:
// - Sass versioning
// - Global variables: none so far
//--------------------------------------------------------------------------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// SASS VERSIONING
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
$name: "@gold.au/grid-12";
$version: "3.0.0";
$dependencies: (
	("@gold.au/core", "5.0.0"),
);


//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// GLOBAL VARIABLES
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
$AU-grid-12-columns: 12 !default;        //column amounts
$AU-grid-12-gutter-width: 24px !default; //gutter space

//--------------------------------------------------------------------------------------------------------------------------------------------------------------
// Mixins and grid class generation
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * Iterates through all 12 columns (≥2) to calculate the correct amount of left
 * and right padding for each of the classes.
 */
@mixin AU-grid-12-make-grid-columns( $i: 1, $list: ".col-xs-#{ $i }, .col-sm-#{ $i }, .col-md-#{ $i }, .col-lg-#{ $i }" ) {
	@for $i from ( 1 + 1 ) through $AU-grid-12-columns {
		$list: "#{ $list }, .col-xs-#{ $i }, .col-sm-#{ $i }, .col-md-#{ $i }, .col-lg-#{ $i }";
	}

	#{ $list } {
		box-sizing: border-box; //we can’t assume that has been added on * {}
		position: relative;
		min-height: 1px;
		padding-left:  ceil( math.div( $AU-grid-12-gutter-width, 2 ) );
		padding-right: floor( math.div( $AU-grid-12-gutter-width, 2 ) );
	}
}


/**
 * Iterates through the columns to create a new list and then sets the float.
 */
@mixin AU-grid-12-float-grid-columns( $class, $i: 1, $list: ".col-#{ $class }-#{ $i }" ) {
	@for $i from ( 1 + 1 ) through $AU-grid-12-columns {
		$list: "#{ $list }, .col-#{ $class }-#{ $i }";
	}

	#{ $list } {
		float: left;
	}
}


/**
 * Calculates the correct widths as a percentage based on the column count,
 * column breakpoint class, and type (pull or offset).
 */
@mixin AU-grid-12-calc-grid-column( $index, $class, $type ) {
	@if ( $type == width ) and ( $index > 0 ) {
		.col-#{ $class }-#{ $index } {
			width: percentage( math.div( $index, $AU-grid-12-columns ) );
		}
	}

	@if ( $type == push ) and ( $index > 0 ) {
		.col-#{ $class }-push-#{ $index } {
			left: percentage( math.div( $index, $AU-grid-12-columns ) );
		}
	}

	@if ( $type == push ) and ( $index == 0 ) {
		.col-#{ $class }-push-0 {
			left: auto;
		}
	}

	@if ($type == pull) and ( $index > 0 ) {
		.col-#{ $class }-pull-#{ $index } {
			right: percentage( math.div( $index, $AU-grid-12-columns ) );
		}
	}

	@if ($type == pull) and ( $index == 0 ) {
		.col-#{ $class }-pull-0 {
			right: auto;
		}
	}

	@if ($type == offset) {
		.col-#{ $class }-offset-#{ $index } {
			margin-left: percentage( math.div( $index, $AU-grid-12-columns ) );
		}
	}
}


/**
 * Calls the above mixins and combines them.
 */
@mixin AU-grid-12-loop-grid-columns( $columns, $class, $type ) {
	@for $i from 0 through $columns {
		@include AU-grid-12-calc-grid-column( $i, $class, $type );
	}
}


/**
 * Finally, we create the grid and all the necessary classes.
 */
@mixin AU-grid-12-make-grid( $class ) {
	@include AU-grid-12-float-grid-columns( $class );
	@include AU-grid-12-loop-grid-columns( $AU-grid-12-columns, $class, width );
	@include AU-grid-12-loop-grid-columns( $AU-grid-12-columns, $class, pull );
	@include AU-grid-12-loop-grid-columns( $AU-grid-12-columns, $class, push );
	@include AU-grid-12-loop-grid-columns( $AU-grid-12-columns, $class, offset );
}
