////
/// @group o-grid
/// @link http://registry.origami.ft.com/components/o-grid
////

@import 'src/scss/variables';
@import 'sass-mq/mq';
@import 'src/scss/main';

/// Output debug information about the currently loaded layouts.
///
/// @param {Map} $layouts - Map of layouts
@mixin oGridDebugInfo($layouts: $o-grid-layouts) {
	/*! DEBUG
	 * Layouts:
	 * #{inspect($layouts)}
	 */
}

@if $o-grid-debug-mode {
	@include oGridDebugInfo;
	@include mq-show-breakpoints($_o-grid-layout-names, $o-grid-layouts);
}

/// Surface the layout currently displayed to make it readable in JS.
///
/// In IE 8, assume it is `$o-grid-fixed-layout` (`L`).
///
/// **n.b.:** Only works when silent mode is off.
///
/// @example js
///  // your-app/main.js
///  // Return the current layout (e.g. default, S, M, L, XL)
///  var getCurrentLayout = require('o-grid').getCurrentLayout;
///  console.log(getCurrentLayout());
///
///  // Return the current gutter (e.g. 10px, 20px)
///  var getCurrentGutter = require('o-grid').getCurrentGutter;
///  console.log(getCurrentGutter());
@mixin oGridSurfaceCurrentLayout {
	html:after {
		content: '{ "layout": "default", "gutter": "' + oGridGutter() + '" }';
		display: none;

		@each $breakpoint in $_o-grid-layout-names {
			@include oGridRespondTo($breakpoint) {
				content: '{ "layout": "' + $breakpoint + '", "gutter": "' + oGridGutter($breakpoint) + '" }';
			}
		}
	}
}

@function _oGridQuoteString($value) {
  @return '"#{$value}"';
}

@mixin oGridSurfaceLayoutSizes {
	html:before {
		$combined: '{"layouts": {';

		$keys: map-keys($o-grid-layouts);

		@for $ittr from 1 through length($keys) {
			$key: nth($keys, $ittr);
			$value: map-get($o-grid-layouts, $key);

			$combined: $combined + _oGridQuoteString($key) + ': ' + _oGridQuoteString($value);

			@if $ittr < length($keys) {
				$combined: $combined + ", ";
			}
		}

		$combined: $combined + '}}';

		display: none;
		content: $combined;
	}
}

@if $o-grid-is-silent == false {
	@include oGridSurfaceCurrentLayout;
	@include oGridSurfaceLayoutSizes;
	@include oGridGenerate;

	// Turn silent mode back on to avoid outputting the grid twice
	$o-grid-is-silent: true;
}
