//
// Utility mixins and functions for evalutating source code across our variables, maps, and mixins.
//

@function strip-unit($number) {
  @if type-of($number) == "number" and not unitless($number) {
    @return $number / ($number * 0 + 1);
  }

  @return $number;
}

@function single-unit-rem($value) {
  $converted: $value / $font-size-base;

  @if (unit($value) == "rem") {
    @return $value;
  }

  @return strip-unit($converted) * 1rem;
}

@function multiple-units-rem($px) {
  $rem-values: ();

  @each $value in $px {
    $rem-values: if($value == 0, append($rem-values, $value), append($rem-values, single-unit-rem($value)));
  }

  @return $rem-values;
}

@function px-to-rem($px) {
  @return if(type-of($px) == "number", single-unit-rem($px), multiple-units-rem($px));
}

@function aggregate-selectors($selectors, $modifier) {
  $aggregated: ();

  @if (length($selectors) == 1) {
    @return #{$selectors + $modifier}
  }

  @each $selector in $selectors {
    $aggregated: append($aggregated, #{$selector + $modifier}, comma);
  }

  @return $aggregated;
}
