@use 'sass:list';
@use 'sass:map';

////
/// @package theming
/// @group utilities
////

/// Expands the provided list of values in all four directions.
/// Works similar to how to browser expands shorthands for margins.
/// @access private
/// @param {List} $list - The of values to be expanded. Supports up to four values.
/// @param {string} $prop [margin] - The name of the property.
/// @returns {Map} Returns an expanded list of values.
@function expand-shorthand($list, $prop: 'margin') {
    $len: list.length($list);
    $props: (
        '#{$prop}-top': null,
        '#{$prop}-right': null,
        '#{$prop}-bottom': null,
        '#{$prop}-left': null,
    );

    @for $i from 1 through 4 {
        $n: $i % $len;
        $n: if($n != 0, $n, $len);

        @if $len == 3 and $i == 4 {
            $n: 2;
        }

        $key: list.nth(map.keys($props), $i);
        $value: list.nth($list, $n);
        $props: map.merge(
            $props,
            (
                $key: $value,
            )
        );
    }

    @return $props;
}
