////
/// @group Main
////
@use "sass:list";
@use "sass:math";
@use "sass:meta";
@use "../variables/debug" as *;

/// Convert px to em
/// @param {Number | Map} $values - Value or values to convert
/// @param {Number} $context [16px] - Base font size
/// @return {*} - Converted value or list of values
@function em($values, $context: 16px) {
  // Ensure context size is in pixels
  @if math.unit($context) != 'px' {
    @error '🔴  #{$context} size must be in pixels';
  }

  // Placeholder list for converted values
  $output: ();

  @each $val in $values {
    // Check if pixel value
    @if meta.type-of($val) == 'number' and math.unit($val) == 'px' {
      // Convert to ems
      $val: math.div($val, $context) * 1em;
    }

    // Do nothing to all other values
    @else if $debug-mode {
      @warn '⚠️  Can’t convert non-pixel value to ems: #{$val}';
    }

    // Append value to output list
    $output: list.append($output, $val);
  }

  // Return converted value(s)
  @return $output;
}
