/// Sans font-family
/// @deprecated Output/set font family using the provided mixins.
/// @see '_o-band.scss' where default typography variables are set.
/// @type String
$_o-typography-sans: '' !default;

/// Serif font-family
/// @deprecated Output/set font family using the provided mixins.
/// @see '_o-brand.scss' where default typography variables are set.
/// @type String
$_o-typography-serif: '' !default;

/// Display font-family
/// @deprecated Output/set font family using the provided mixins.
/// @see '_o-brand.scss' where default typography variables are set.
/// @type String
$_o-typography-display: '' !default;

/// The default font scale of font-sizes and line-heights.
/// This may be customised per font, @see $_o-typography-font-scale-by-font
/// @access private
/// @type Map
$_o-typography-font-scale: (
	-2: (12, 16),
	-1: (14, 16),
	0: (16, 20),
	1: (18, 20),
	2: (20, 24),
	3: (24, 28),
	4: (28, 32),
	5: (32, 32),
	6: (40, 40),
	7: (48, 48),
	8: (56, 56),
	9: (72, 72),
	10: (84, 84),
) !default;

/// Helper for `o-brand` function.
/// @access private
@function _oTypographyGet($variables, $from: null) {
	@return oBrandGet($component: 'o-typography', $variables: $variables, $from: $from);
}

/// Helper for `o-brand` function.
/// @access private
@function _oTypographySupports($variant) {
	@return oBrandSupportsVariant($component: 'o-typography', $variant: $variant);
}

/// Helper for `whitelabel` brand variable customisation.
///
/// @brand whitelabel
/// @param {Map} $variables - Brand variables to customise
/// @access public
/// @example scss
///    @include oTypographyCustomize((
///        'heading-level-one': (
///            'scale': 5,
///            'scale-s': 7,
///            'weight': 'semibold'
///        ),
///        'heading-level-two': (
///            'scale': 6
///        ),
///        'heading-level-three': (
///            'scale': 5
///        ),
///        'heading-level-four': (
///            'scale': 4
///        ),
///        'heading-level-five': (
///            'scale': 3
///        ),
///        'heading-level-six': (
///            'scale': 2
///        )
///    ));
@mixin oTypographyCustomize($variables) {
	// Only allow certain brand variables to be customised.
	$allowed-brand-variables: (
		'heading-level-one',
		'heading-level-two',
		'heading-level-three',
		'heading-level-four',
		'heading-level-five',
		'heading-level-six'
	);
	@each $brand-variable in map-keys($variables) {
		@if not index($allowed-brand-variables, $brand-variable) {
			@error 'You cannot customise the brand variable "#{$brand-variable}". Did you mean one of: "#{$allowed-brand-variables}"? Please contact the Origami team if you need to customise something new.';
		}
	}
	// Customise the brand.
	@include oBrandCustomize('o-typography', $variables);
}


// Register Georgia font and allowed variants with `o-fonts`.
// Shared by all brands.
@include oFontsDefineCustomFont('Georgia, serif', (
	(weight: regular, style: normal),
	(weight: regular, style: italic),
	(weight: bold, style: normal),
	(weight: bold, style: italic)
));

@if oBrandIs('core') {
	$_o-typography-sans: if($_o-typography-sans != '', $_o-typography-sans, oFontsGetFontFamilyWithFallbacks(MetricWeb)) !global;
	$_o-typography-serif: if($_o-typography-serif != '', $_o-typography-serif, (Georgia, serif)) !global;
	$_o-typography-display: if($_o-typography-display != '', $_o-typography-display, oFontsGetFontFamilyWithFallbacks(FinancierDisplayWeb)) !global;

	@include oBrandDefine('o-typography', 'core', (
		'variables': (
			'author-color': oColorsByUsecase('body', 'text'),
			'author-hover-color': oColorsByName('claret'),
			'body': (
				'color': oColorsByUsecase('body', 'text', $fallback: null),
			),
			'body-inverse': (
				'color': oColorsByUsecase('body-inverse', 'text', $fallback: null),
			),
			'link': (
				'base': oColorsByUsecase('link', 'text'),
				'hover': oColorsByUsecase('link-hover', 'text'),
			),
			'link-inverse': (
				'base': oColorsByName('white'),
				'base-decoration': oColorsByName('white'),
				'hover': oColorsMix('white', 'slate', 80),
				'hover-decoration': oColorsMix('white', 'slate', 80)
			),
			'link-professional': (
				'base': oColorsByName('slate'),
				'base-decoration': oColorsByName('mint-80'),
				'hover': oColorsByName('slate'),
				'hover-decoration': oColorsByName('mint-80')
			),
			'link-professional-inverse': (
				'base': oColorsByName('mint'),
				'base-decoration': oColorsByName('mint'),
				'hover': oColorsByName('mint-70'),
				'hover-decoration': oColorsByName('mint-70')
			),
			'link-ft-live': (
				'base': oColorsByName('ft-pink'),
				'base-decoration': oColorsMix('ft-pink', 'slate', 80),
				'hover': oColorsMix('ft-pink', 'slate', 80),
				'hover-decoration': oColorsMix('ft-pink', 'slate', 80)
			),
			'heading-level-one': (
				'scale': 5,
				'weight': 'semibold'
			),
			'heading-level-two': (
				'scale': 4,
				'weight': 'semibold'
			),
			'heading-level-three': (
				'scale': 3,
				'weight': 'semibold'
			),
			'heading-level-four': (
				'scale': 2,
				'weight': 'semibold'
			),
			'heading-level-five': (
				'scale': 1,
				'weight': 'semibold'
			),
			'heading-level-six': (
				'scale': 0,
				'weight': 'semibold'
			)
		),
		'supports-variants': (
			'professional',
			'ft-live'
		)
	));
}

@if oBrandIs('internal') {
	$_o-typography-sans: if($_o-typography-sans != '', $_o-typography-sans, oFontsGetFontFamilyWithFallbacks(MetricWeb)) !global;
	$_o-typography-serif: if($_o-typography-serif != '', $_o-typography-serif, (Georgia, serif)) !global;
	$_o-typography-display: if($_o-typography-display != '', $_o-typography-display, oFontsGetFontFamilyWithFallbacks(MetricWeb)) !global;

	@include oBrandDefine('o-typography', 'internal', (
		'variables': (
			'link': (
				'base': oColorsByUsecase('link', 'text'),
				'hover': oColorsByUsecase('link-hover', 'text'),
			),
			'heading-level-one': (
				'scale': 5,
				'weight': 'semibold'
			),
			'heading-level-two': (
				'scale': 5
			),
			'heading-level-three': (
				'scale': 4,
				'weight': 'semibold'
			),
			'heading-level-four': (
				'scale': 4
			),
			'heading-level-five': (
				'scale': 3,
				'weight': 'semibold'
			),
			'heading-level-six': (
				'scale': 2,
				'weight': 'semibold'
			)
		),
		'supports-variants': ()
	));
}

@if oBrandIs('whitelabel') {
	// Register Arial font with `o-fonts`.
	@include oFontsDefineCustomFont('Arial, sans', (
		(weight: regular, style: normal),
		(weight: regular, style: italic),
		(weight: semibold, style: normal),
		(weight: bold, style: normal),
		(weight: semibold, style: italic),
		(weight: bold, style: italic)
	));

	$_o-typography-sans: if($_o-typography-sans != '', $_o-typography-sans, (Arial, sans)) !global;
	$_o-typography-serif: if($_o-typography-serif != '', $_o-typography-serif, (Georgia, serif)) !global;
	$_o-typography-display: if($_o-typography-display != '', $_o-typography-display, (Arial, sans)) !global;

	// Change the default font scale for the whitelabel brand.
	$_o-typography-font-scale: (
		-2: (12, (12 * 1.2)),
		-1: (14, (14 * 1.2)),
		0: (16, (16 * 1.2)),
		1: (18, (18 * 1.2)),
		2: (20, (20 * 1.2)),
		3: (24, (24 * 1.2)),
		4: (28, (28 * 1.2)),
		5: (32, (32 * 1.2)),
		6: (40, (40 * 1.2)),
		7: (48, (48 * 1.2)),
		8: (56, (56 * 1.2)),
		9: (72, (72 * 1.2)),
		10: (84, (84 * 1.2)),
	) !global;

	@include oBrandDefine('o-typography', 'whitelabel', (
		'variables': (
			'heading-level-one': (
				'scale': 6,
			),
			'heading-level-two': (
				'scale': 5
			),
			'heading-level-three': (
				'scale': 4
			),
			'heading-level-four': (
				'scale': 3
			),
			'heading-level-five': (
				'scale': 2
			),
			'heading-level-six': (
				'scale': 1
			)
		),
		'supports-variants': ()
	));
}
