// Utilities
// =========



// Get Function
// ------------
/// Get a first-class function in Sass 3.5+,
/// or the function name string (unchanged)
/// in older Sass versions.
/// This is safe to use internally,
/// as it allows users to pass in
/// either a string, or a previously-captured function.
///
/// @access private
///
/// @param {String | Function} $function -
///   The name (string) of a function,
///   or the function to be called.
/// @return {String | Function} -
///   Returns a first-class function in Sass 3.5+,
///   or the function name string in older Sass versions.
@function _ac-scale-get-function(
  $function
) {
  $type: type-of($function);

  @if ($type == 'function') {
    @return $function;
  } @else if ($type == 'string') {
    @if function-exists('get-function') {
      @return get-function($function);
    }

    @return $function;
  }

  @error 'Invalid function-name, [#{$type}] `#{$function}` must be a function or string';
}

// Merge sizes
// ------------
/// Merge multiple size maps into a single map,
/// in case you want to define sizes in smaller groups
/// such as `container-sizes`, `measure-sizes`, etc
/// but then treat them as a single map of colors.
/// To merge and update the global `$sizes` variable,
/// use the `add-scales()` mixin.
///
/// @group config
///
/// @parameter {Map...} $maps -
///   Pass any number of maps to be merged.
/// @return {Map} -
///   The merged map.
/// @see sizes
/// @see add-sizes
@function merge-sizes(
  $maps...
  ) {
    $return: ();

    @each $map in $maps {
      $return: map-merge($return , $map);
    }

    @return $return;
}

// Add Sizes
// ----------
/// Merge multiple size maps into the global `$sizes` map,
/// in case you want to define sizess in smaller groups
/// such as `container-sizes`, `measure-sizes`, etc
/// before merging them into a single `$sizes` variable,
///
/// @group config
///
/// @parameter {Map...} $maps -
///   Pass any number of maps to be merged.
/// @see sizes
@mixin add-sizes(
  $maps...
  ) {
  $sizes: merge-sizes($sizes, $maps...) !global;
}
