// =============================================================================
// =ALEKSI - MAP-EXTEND-DEEP
// =============================================================================
////
//// @group aleksi-maps
//// @author [Yoannis Jamar](https://yoannis.com)

@import "aleksi/general/throw";
@import "aleksi/maps/map-merge-deep";
@import "aleksi/lists/slice";

// =map-extend-deep( $maps... )
// -----------------------------------------------------------------------------
/// Merges the given maps successively, and recursively. Allows to merge more
/// then two maps at once, and will extend nested maps as well.
///
/// @param {$map} $maps... - maps to merge
///
/// @return {map}
///
/// @access public
/// @since 0.6.0

@function map-extend-deep( $maps... )
{
  @if length($maps) < 2 {
    $e: throw-warning('map-extend-deep():: trying to extend one map only. Returning the map as is.');
    @return $nth($maps, 1);
  }

  $res: nth($maps, 1);

  @each $map in slice($maps, 2) {
    $res: map-merge-deep($res, $map);
  }

  @return $res;
}