@import '@financial-times/o-private-foundation/main';
@import '@financial-times/o-brand/main';

@import 'src/scss/variables';
@import 'src/scss/functions';
@import 'src/scss/mixins';
@import 'src/scss/placeholders';

/// Output All oEditorialLayout Features
@mixin oEditorialLayout(
	$opts: (
		'headings': (
			1,
			2,
			3,
			4,
			5,
		),
		'body': true,
		'wrapper': true,
	)
) {
	@include oPrivateFoundation();

	$headings: map-get($opts, 'headings');
	$headings: if($headings, $headings, ());
	$body: map-get($opts, 'body');
	$wrapper: map-get($opts, 'wrapper');

	@if ($headings and type-of($headings) != 'list') {
		@error ('The "headings" option must be a list of heading levels to include e.g. `(1, 2, 3, 4, 5)`.');
	}

	@if index($headings, 1) {
		.o-editorial-layout-heading-1 {
			@include oEditorialLayoutHeading(1);
		}
	}

	@if index($headings, 2) {
		.o-editorial-layout-heading-2 {
			@include oEditorialLayoutHeading(2);
		}
	}

	@if index($headings, 3) {
		.o-editorial-layout-heading-3 {
			@include oEditorialLayoutHeading(3);
		}
	}

	@if index($headings, 4) {
		.o-editorial-layout-heading-4 {
			@include oEditorialLayoutHeading(4);
		}
	}

	@if index($headings, 5) {
		.o-editorial-layout-heading-5 {
			@include oEditorialLayoutHeading(5);
		}
	}

	@if $body {
		.o-editorial-layout-body {
			@include oEditorialLayoutBody();
		}
	}

	@if $wrapper {
		.o-editorial-layout-wrapper {
			> h1 {
				@include oEditorialLayoutHeading(1);
			}

			> h2 {
				@include oEditorialLayoutHeading(2);
			}

			> h3 {
				@include oEditorialLayoutHeading(3);
			}

			> h4 {
				@include oEditorialLayoutHeading(4);
			}

			> h5 {
				@include oEditorialLayoutHeading(5);
			}

			> blockquote,
			> ol,
			> ul,
			> p {
				@include oEditorialLayoutBody();
			}

			> ol,
			> ul {
				@extend %_o-editorial-layout-list;
			}

			> ol {
				margin: 0 0 oPrivateFoundationGet('o3-spacing-s');
			}

			> ul {
				margin: 0 0 oPrivateFoundationGet('o3-spacing-s');
			}

			> footer {
				@include oPrivateTypographySans($scale: 1);
				line-height: 24px;
				color: oPrivateFoundationGet('o3-color-use-case-body-text');
			}

			> blockquote {
				margin-bottom: oPrivateSpacingByIncrement(7);
				max-width: oPrivateTypographyMaxLineWidth(75);
			}
		}

		.o-editorial-layout-wrapper > p a,
		.o-editorial-layout-wrapper > a {
			@include oPrivateTypographyLink;
		}

		.o-editorial-layout-wrapper > p strong,
		.o-editorial-layout-wrapper > strong {
			@include oPrivateTypographySerif($weight: 'bold');
		}

		.o-editorial-layout-wrapper > p em,
		.o-editorial-layout-wrapper > em,
		.o-editorial-layout-wrapper > p i,
		.o-editorial-layout-wrapper > i {
			font-style: italic;
		}

		.o-editorial-layout-wrapper > p sub,
		.o-editorial-layout-wrapper > p sup {
			// make superscript smaller and sans-serif
			// 12px given 18px copy
			@include oPrivateTypographySans();
			font-size: 0.666em;
			// override o-normalise default
			position: static;
			line-height: 0;
			// prevent super increasing line-height
			display: inline-block;
			margin-top: -1em;
		}

		.o-editorial-layout-wrapper > p sup {
			vertical-align: super;
		}

		.o-editorial-layout-wrapper > p sub {
			vertical-align: sub;
		}
	}
}

@if ($o-editorial-layout-is-silent == false) {
	@include oEditorialLayout();

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