@use 'sass:map';
@use '../../error/error-to-string';

//
// Return a the value of a nested key in a map if it exists.
// If the key doesn't exist, it throw an error.
//
// Note: This function doesn't support the use
// of the search character in your map key names.
//
// @usage daff-map-get($map, nested, map, key);
// @returns any
// @throws error
@function daff-map-get($map, $keys...) {
	@each $key in $keys {
		@if not map.has-key($map, $key) {
			@return error-to-string.error-to-string("The map doesn't contain the $key: `#{$key}`'");
		}
		$map: map.get($map, $key);
	}

	@return $map;
}
