@import "variables";

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

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

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

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

@mixin rtl-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 rtl-make-col-push($size, $columns);
	} @else if $type == pull {
		@include rtl-make-col-pull($size, $columns);
	} @else if $type == offset {
		@include rtl-make-col-offset($size, $columns);
	} @else if $type == offset-right {
		@include rtl-make-col-offset-right($size, $columns);
	}
}

@mixin rtl-make-grid-columns($columns: $grid-columns, $gutter: $grid-gutter-width, $breakpoints: $grid-breakpoints) {
	@each $breakpoint in map-keys($breakpoints) {
		@include media-breakpoint-up($breakpoint) {
			@each $modifier in (pull, push, offset, offset-right) {
				@for $i from 0 through $columns {
					.col-#{$breakpoint}-#{$modifier}-#{$i} {
						@include rtl-make-col-modifier($modifier, $i, $columns)
					}
				}
			}
		}
	}
}

@include rtl-make-grid-columns();
