/* Utils
*/

@use "sass:math";

$em-base: 16 !default;

@function strip-unit($num) {
  @return math.div($num, $num * 0 + 1);
}

// Converts "px" to "em" using the ($)em-base
@function convert-to-em($value)  {
  $value: math.div(strip-unit($value), strip-unit($em-base)) * 1em;
  @if ($value == 0em) { $value: 0; } // Turn 0em into 0
  @return $value;
}

// Working in ems is annoying. Think in pixels by using this handy function, emCalc(#)
// Just enter the number, no need to mention "px"
@function emCalc($values...) {
  $max: length($values); // Get the total number of parameters passed

  // If there is only 1 parameter, then return it as an integer.
  // This is done because a list can't be multiplied or divided even if it contains a single value
  @if $max == 1 { @return convert-to-em(nth($values, 1)); }

  $emValues: (); // This will eventually store the converted $values in a list
  @for $i from 1 through $max {
    $emValues: append($emValues, convert-to-em(nth($values, $i)));
  }
  @return $emValues;
}

/* Mixins */

@mixin breakpoint($point) {
  @if $point == papa-bear {
    @media (min-width: 978px) { @content; }
  }
  @else if $point == mama-bear {
    @media (min-width: 767px) { @content; }
  }
  @else if $point == baby-bear {
    @media (min-width: 480px)  { @content; }
  }
}
