@import '@financial-times/math';
@import 'src/scss/variables';
@import 'src/scss/functions';

/// Output all o-spacing features.
/// @param {Map} $opts
/// @example
///		@include oSpacing($opts: (
///			'margin-bottom-utilities': true, // Output CSS classes such as `o-spacing-s1`.
///			'custom-properties': true // Output CSS variables.
///		));
@mixin oSpacing($opts: (
	'margin-bottom-utilities': true,
	'custom-properties': true
)) {
	$custom-properties: map-get($opts, 'custom-properties');
	$margin-bottom-utilities: map-get($opts, 'margin-bottom-utilities');

	// Output spacing values as CSS Custom Properties.
	@if($custom-properties) {
		:root {
			// Named spaces.
			@each $space-name, $increment in $_o-spacing-sizes {
				#{--o-spacing-}#{$space-name}: oSpacingByIncrement($increment);
			}
			// Baseline value.
			#{--o-spacing-baseline}: oSpacingGetBaselineValue();
		}
	}

	// Output utility classes to apply bottom margin based on spacing values.
	@if($margin-bottom-utilities) {
		@each $space-name, $increment in $_o-spacing-sizes {
			.o-spacing-#{$space-name} {
				margin-bottom: oSpacingByIncrement($increment);
			}
		}
	}
}

@if ($o-spacing-is-silent == false) {
	@include oSpacing();

	// Set to silent again to avoid being output twice
	$o-spacing-is-silent: true !global;
}
