@use 'sass:meta';
@use 'sass:map';
@use '../internal/type';
@use '../internal/throw';

/// ## Sass Maps
/// Utility functions that extend the Sass core modules,
/// to help with advanced map manipulation.
///
/// These functions have a `map-` prefix added by default
/// (e.g. `map-multi-merge()`)
/// unless they are imported directly.
/// @group utils

// Map MultiMerge
// --------------
/// Merge multiple maps into a single map,
/// in case you want to define tokens in smaller groups --
/// such as `brand-colors`, `text-colors`, etc. --
/// before merging them into a single map.
///
/// @since 4.0.0 -
/// - NEW: Initial release
///
/// @group utils
/// @param {maps...} $maps -
///   Pass any number of maps to be merged.
/// @return {map} -
///   The merged map of easings.
@function multi-merge($maps...) {
  $return: ();

  @each $map in $maps {
    @if type.check($map, 'map') {
      $return: map.deep-merge($return, $map);
    } @else {
      $type: meta.type-of($map);

      @return throw.error(
        'Each value of `$maps...` must be a map, got `[#{$type}]: #{$map}`',
        'multi-merge'
      );
    }
  }

  @return $return;
}
