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

/// Check if a font variant exists for a family
///
/// @param {String} family - one of $o-fonts-families
/// @param {String} weight
/// @param {String} style
///
/// @access private
///
/// @return {Bool}
@function _oFontsVariantExists($family, $weight, $style) {
	$font-properties: map-get($o-fonts-families, $family);
	$font-variants: map-get($font-properties, variants);

	@each $variant in $font-variants {
		// Check if this weight and style variant exists for this family
		// Known issue with LibSass 3.0.2 - https://github.com/sass/libsass/issues/741
		@if (map-get($variant, weight) == $weight and map-get($variant, style) == $style) {
			@return true;
		}
	}
	@return false;
}

/// Capitalise first letter of $string
///
/// @param {String} $string - string to update
///
/// @return {String}
@function _oFontsStringCapitalise($string) {
	$string: $string + unquote(''); // Make sure $string has a type of String
	$first-letter: to-upper-case(str-slice($string, 0, 1));
	$rest-of-string: str-slice($string, 2);

	@return $first-letter + $rest-of-string;
}

/// Get a font-family stack with the appropriate fallbacks
///
/// @param {String} family
///
/// @return {String} - font-stack
///
/// @example scss
/// font-family: oFontsGetFontFamilyWithFallbacks(FinancierDisplayWeb);
@function oFontsGetFontFamilyWithFallbacks($family) {
	@if $family == 'Clarion' or $family == 'Benton' or $family == 'Miller' or $family == 'FinancierTextWeb' {
		@error "#{$family} has been removed. Please use either MetricWeb or FinancierDisplayWeb.";
	}


	@if map-has-key($o-fonts-families, $family) {
		$properties: map-get($o-fonts-families, $family);
		@return unquote(map-get($properties, font-family));
	}
	@warn 'Font #{$family} not found. Must be one of $o-fonts-families.';
	@return inherit;
}

/// Path to a font asset
///
/// @param {String} $asset
///
/// @return {String} - Path to the font asset, without the file extension
@function oFontsUseAsset($asset) {
	@return $o-fonts-path + $asset;
}

/// Machine-readable CSS font-weight.
///
/// @param {String} $keyword - Human-readable keyword, one of $_o-fonts-weights
///
/// @example scss
/// font-weight: oFontsWeight(lighter);
///
/// @return {Number} - CSS font-weight
@function oFontsWeight($keyword) {
	@if map-has-key($_o-fonts-weights, $keyword) {
		@return map-get($_o-fonts-weights, $keyword);
	} @else {
		@warn 'Keyword "#{$keyword}" not found. Must be one of $_o-fonts-weights.';
	}
}
