@import '@financial-times/o-typography/main';
@import '@financial-times/o-spacing/main';
@import '@financial-times/o-fonts/main';
@import '@financial-times/o-colors/main';

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

/// Output oEditorialTypography features.
///
/// @example Output all o-editorial-typography css classes.
/// 	@include oEditorialTypography();
///
/// @example Output a granular selection of o-editorial-typography css classes. See the [README](https://registry.origami.ft.com/components/o-editorial-typography/readme) for a full list of options.
///     @include oEditorialTypography((
///     	'body': true,
///     	'headings': (1, 2, 3),
///     	'lists': ('unordered'),
///     ));
///
/// @param {Map} $opts [('body': true, 'lists': ('ordered', 'unordered'), 'caption': true, 'headline': true, 'headings': (1, 2, 3, 4, 5), 'author': true, 'standfirst': true, 'topic': true, 'byline': true, 'timestamp': true, 'fonts': true)] - The features of o-editorial-typography to output classes for. See the [README](https://registry.origami.ft.com/components/o-editorial-typography/readme) for more details.
@mixin oEditorialTypography($opts: (
	'body': true,
	'links': true,
	'lists': ('ordered', 'unordered'),
	'caption': true,
	'headline': true,
	'headings': (1, 2, 3, 4, 5),
	'standfirst': true,
	'author': true,
	'topic': true,
	'byline': true,
	'timestamp': true
)) {
	$body: map-get($opts, 'body');
	$links-enabled: map-get($opts, 'links');
	$lists: map-get($opts, 'lists');
	$lists: if($lists, $lists, ());
	@if($lists and type-of($lists) != 'list') {
		@error ('The "lists" option must be a list of list types to include e.g. `(\'ordered\', \'unordered\')`.');
	}
	$caption: map-get($opts, 'caption');
	$headline: map-get($opts, 'headline');
	$headings: map-get($opts, 'headings');
	$headings: if($headings, $headings, ());
	@if($headings and type-of($headings) != 'list' and type-of($headings) != 'number') {
		@error ('The "headings" option must be a list of heading levels to include e.g. `(1, 2, 3, 4, 5)`.');
	}
	$standfirst: map-get($opts, 'standfirst');
	$author: map-get($opts, 'author');
	$topic: map-get($opts, 'topic');
	$byline: map-get($opts, 'byline');
	$timestamp: map-get($opts, 'timestamp');

	// Load fonts within the primary mixin in-case silent mode is on.
	// Don't load fonts if o-typography has output them already since
	// `$o-editorial-typography-load-fonts` was set.
	@if $o-editorial-typography-load-fonts == true and $o-typography-load-fonts == true {
		@include oFonts();
		// Set to false so fonts are not output twice by o-editorial-typography.
		$o-editorial-typography-load-fonts: false !global;
	}

	@if $body {
		.o-editorial-typography-body {
			@include oEditorialTypographyBody();
		}
		.o-editorial-typography-body--inverse {
			--_o-editorial-typography-body-color: #{oColorsByName('white')};
		}
	}

	@if $links-enabled {
		.o-editorial-typography-link {
			@include oTypographyLink;
		}
	}

	@if $body and $links-enabled {
	  .o-editorial-typography-body--inverse .o-editorial-typography-link {
		  @include oTypographyLink($theme: (
				  'base': _oEditorialTypographyGet('base', 'link-inverse'),
				  'base-decoration': _oEditorialTypographyGet('base-decoration', 'link-inverse'),
				  'hover': _oEditorialTypographyGet('hover', 'link-inverse'),
				  'hover-decoration': _oEditorialTypographyGet('hover-decoration', 'link-inverse'),
		  ));
	  }
	}

	@if length($lists) >= 1 {
		.o-editorial-typography-list {
			// Output base styles shared by all list types.
			@include oEditorialTypographyList();
		}
	}

	@if index($lists, 'ordered') {
		.o-editorial-typography-list--ordered {
			// Output list styles unique to an ordered list.
			@include oEditorialTypographyList($type: 'ordered', $include-base-styles: false);
		}
	}

	@if index($lists, 'unordered') {
		.o-editorial-typography-list--unordered {
			// Output list styles unique to an unordered list.
			@include oEditorialTypographyList($type: 'unordered', $include-base-styles: false);
		}
	}

	@if $caption {
		.o-editorial-typography-caption {
			@include oEditorialTypographyCaption();
		}
	}

	@if $headline {
		.o-editorial-typography-headline {
			@include oEditorialTypographyHeadline();
		}
	}

	@each $level in $headings {
		.o-editorial-typography-heading-level-#{$level} {
			@include oEditorialTypographyHeading($level);
		}
	}

	@if $standfirst {
		.o-editorial-typography-standfirst {
			@include oEditorialTypographyStandfirst();
		}
	}

	@if $author {
		.o-editorial-typography-author {
			@include oEditorialTypographyTag('author');
		}
	}

	@if $topic {
		.o-editorial-typography-topic {
			@include oEditorialTypographyTag('topic');
		}
	}

	@if $byline {
		.o-editorial-typography-byline {
			@include oEditorialTypographyByline();
		}
	}

	@if $timestamp {
		.o-editorial-typography-timestamp {
			@include oEditorialTypographyTimestamp();
		}
	}
}

@if ($o-editorial-typography-is-silent == false) {
	@include oEditorialTypography();

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