/// Set a nested key in an existing map
///
/// @author Sam Richard
/// @access public
/// @link https://git.io/vPr80
///
/// @param {map} $map - the map which contains the key you wish to set
/// @param {string|list} $keys - the keychain trail to your desired key
/// @param {*} $value - the value you wish to set for the key
///
/// @return {map} - updated map
@function map-set-deep($map, $keys, $value) {

    $private-sassy-maps-suppress-warnings: true !global;
    $length: length($keys);
    $get-keys: ();
    $map-level: ();

    @if $length > 1 {
        $get-keys: get-keys($keys, $length);
        $map-level: map-get-deep($map, $get-keys);
    }

    $merge: (nth($keys, $length): $value);

    @if $map-level {
        $merge: map-merge($map-level, $merge);
    }

    @for $i from ($length * -1 + 1) through -1 {
        $j: abs($i);
        $key: nth($keys, $j);
        @if $j > 1 {
            $get-keys: get-keys($keys, $j);
            $map-level: map-get-deep($map, $get-keys);
            @if $map-level {
                $merge: map-merge($map-level, ($key: $merge));
            } @else {
                $merge: ($key: $merge);
            }
        } @else {
            $merge: ($key: $merge);
        }
    }

    $map: map-merge($map, $merge);
    $private-sassy-maps-suppress-warnings: false !global;

    @return $map;
}