////
/// @group Typography
////

/// Gets a font family from the `$nice-font-families` map, given a name
/// @param {String} $stack The stack name e.g. sans, serif or mono
/// @since 0.1.0
@function font-family($stack) {
  $result: map-get($nice-font-families, $stack);
  @return unquote($result);
}

/// Gets a numeric scale
/// @param $scale {Integer|Name} The integer ratio or named font-size.
/// @since 0.1.0
@function get-scale-integer($scale) {
  @if map-has-key($named-font-sizes, $scale) {
    @return map-get($named-font-sizes, $scale);
  }
  @elseif is-integer($scale) {
    @return $scale;
  }

  @error '`$scale` must either be an integer or exist as a named font size in `$named-font-sizes`';
}


/// Gets a numeric font size (in px) from a given scale multiplier.
/// Usually not used directly - the font-size or font mixin is usually used instead.
/// @param $scale {Integer|Name} The integer ratio or named font-size.
/// @return {Number} Numeric font size (in px)
/// @example
///   $font-size: get-font-size(2)
/// @example
///   $font-size: get-font-size(h1)
/// @since 0.1.0
@function get-font-size($scale) {
  $scale-integer: get-scale-integer($scale);
  $font-map: map-get($font-sizes, $scale-integer);
  @return map-get($font-map, fs);
}

/// Gets a numeric line height (in px) from a given scale multiplier.
/// Usually not used directly - the font-size or font mixin is usually used instead.
/// @param $scale {Integer|Name} The integer ratio or named font-size.
/// @return {Number} Numeric line-height (in px)
/// @example
///   $line-height: get-line-height(2)
/// @example
///   $line-height: get-line-height(h1)
/// @since 0.1.0
@function get-line-height($scale) {
  $scale-integer: get-scale-integer($scale);
  $font-map: map-get($font-sizes, $scale-integer);
  @return map-get($font-map, lh);
}

/// Applies font size and line-height for the given scale.
/// @param $scale {Integer|Name} The integer ratio or named font-size.
/// @example
///   .test {
///     @include font-size(-2);
///   }
/// @example
///   .test {
///     @include font-size(h1);
///   }
/// @since 0.1.0
@mixin font-size($scale: 0) {
  $font-size: get-font-size($scale);
  $line-height: get-line-height($scale);

  font-size: rem($font-size);
  line-height: rem($line-height);
}

/// Nice font: includes font size, line height, and margins.
/// @param $scale {Integer|Name} The integer ratio or named font-size.
/// @example
///   .test {
///     @include font(3);
///   }
/// @example
///   .test {
///     @include font(h1);
///   }
/// @since 0.1.0
@mixin font($scale) {
  @include font-size($scale);

  $scale-integer: get-scale-integer($scale);
  $font-map: map-get($font-sizes, $scale-integer);

  font-weight: map-get($font-map, fw);
  margin-bottom: rem(map-get($font-map, mb));
  margin-top: rem(map-get($font-map, mt));
}

/// Lead paragraph style
/// @since 0.2.12
@mixin lead {
  @include font(lead);
}
