// scss-lint:disable NameFormat, ElsePlacement
// Default scales
// You can override these before @importing this file
$numbers-fn--px-to-rem-ratio: 10 !default; // px:rem scale, e.g. 10 => 10px == 1rem
$numbers-fn--base-px-font-size: 16px !default; // Font size used for em scaling



/// Converts css numbers into ints
///
/// @param {number} n - a CSS number, e.g. 1, 2px, 3em, …
///
/// @returns {int} - an integer without units, e.g. 1, 2, 3, …
///
@function parseInt($n) {
  // units cancel out in division, so 4px / 1px => 4
  @return $n / ($n * 0 + 1);
}


/// Converts number to rem
///
/// @param {number} n     - accepts [rem|px|unitless] numbers
/// @param {int}    scale - px:rem scale, e.g. 10 => 10px == 1rem
///
/// @returns {rem}
///
@function rem($n, $scale: $numbers-fn--px-to-rem-ratio) {
  @if unit($n) == 'px' {
    @return parseInt($n) / $scale * 1rem;
  }
  @else if unitless($n) or unit($n) == 'rem'  {
    @return parseInt($n) * 1rem;
  }
  @else {
    @error 'rem() only converts px numbers, #{unit($n)} is not supported';
    @return null;
  }
}


/// Converts number to px
///
/// @param {number} n     - accepts [rem|px|unitless] numbers
/// @param {int}    scale - px:rem scale, e.g. 10 => 10px == 1rem
///
/// @returns {px}
///
@function px($n, $scale: $numbers-fn--px-to-rem-ratio) {
  @if unit($n) == 'rem' {
    @return parseInt($n) * $scale * 1px;
  }
  @else if unitless($n) or unit($n) == 'px' {
    @return parseInt($n) * 1px;
  }
  @else {
    @error 'px() only converts rem numbers, #{unit($n)} is not supported';
    @return null;
  }
}


/// Converts number to an em percentage based off a given font size
///
/// @param {number} n              - accepts [em|rem|px|unitless] numbers
/// @param {px}     base-font-size - font-size to base the percentage off of
///
/// @returns {rem}
///
@function em($n, $base-font-size: $numbers-fn--base-px-font-size) {
  @if unitless($n) or unit($n) == 'em'  {
    @return parseInt($n) * 1em;
  } @else {
    @return rem($n) / rem($base-font-size) * 1em;
  }
}
