@charset "UTF-8";

// Built-in modules
@use "sass:color";
@use "sass:list";
@use "sass:map";
@use "sass:math";
@use "sass:meta";
@use "sass:selector";
@use "sass:string";

// Mixkit settings and modules
@use "mixkit/settings" as settings;

/// Specify a shorthand value matrix or generate a list or map
/// of shorthand values.
///
/// @name define
///
/// @group mixkit/shorthand
///
/// @param {string [1|2|3|4]|[top|right|bottom|left|vertical|horizontal|all|map]} $matrix - [map]
///   Value matrix configuration.
///
/// @param {list} $shorthand
///   List of valid CSS lengths ranging from 1-4.
///
/// @return {string}
///
/// @access public
///
/// @since 1.0.0

@function define($matrix: map, $shorthand) {
    // Vars
    $matrix: string.to-lower-case(string.quote(string.unquote("#{$matrix}")));
    $length: list.length($shorthand);
    $map: ();
    $list: ();

    // Check args
    @if not meta.type-of($shorthand) == "string"
        or not meta.type-of($shorthand) == "number"
        or not meta.type-of($shorthand) == "list" {
        @error "Invalid argument type/s.";
    }

    // Logic: 1
    @if $length == 1 {
        $list: (
            list.nth($shorthand, 1),
            list.nth($shorthand, 1),
            list.nth($shorthand, 1),
            list.nth($shorthand, 1)
        );
        $map: (
            1: list.nth($shorthand, 1),
            2: list.nth($shorthand, 1),
            3: list.nth($shorthand, 1),
            4: list.nth($shorthand, 1),
        );
    }

    // Logic: 2
    @else if $length == 2 {
        $list: (
            list.nth($shorthand, 1),
            list.nth($shorthand, 2),
            list.nth($shorthand, 1),
            list.nth($shorthand, 2)
        );
        $map: (
            1: list.nth($shorthand, 1),
            2: list.nth($shorthand, 2),
            3: list.nth($shorthand, 1),
            4: list.nth($shorthand, 2),
        );
    }

    // Logic: 3
    @else if $length == 3 {
        $list: (
            list.nth($shorthand, 1),
            list.nth($shorthand, 2),
            list.nth($shorthand, 3),
            list.nth($shorthand, 2)
        );
        $map: (
            1: list.nth($shorthand, 1),
            2: list.nth($shorthand, 2),
            3: list.nth($shorthand, 3),
            4: list.nth($shorthand, 2),
        );
    }

    // Logic: 4
    @else if $length == 4 {
        $list: (
            list.nth($shorthand, 1),
            list.nth($shorthand, 2),
            list.nth($shorthand, 3),
            list.nth($shorthand, 4)
        );
        $map: (
            1: list.nth($shorthand, 1),
            2: list.nth($shorthand, 2),
            3: list.nth($shorthand, 3),
            4: list.nth($shorthand, 4),
        );
    }

    // Logic: "list"
    @if $matrix == "list" {
        @return $list;
    }

    // Logic: "map"
    @else if $matrix == "map" {
        @return $map;
    }

    // Logic: 1, top|t
    @else if $matrix == "1" or $matrix == "top" or $matrix == "t" {
        @return map.get($map, 1);
    }

    // Logic: 2, right|r
    @else if $matrix == "2" or $matrix == "right" or $matrix == "r" {
        @return map.get($map, 2);
    }

    // Logic: 3, bottom|b
    @else if $matrix == "3" or $matrix == "bottom" or $matrix == "b" {
        @return map.get($map, 3);
    }

    // Logic: 4, left|l
    @else if $matrix == "4" or $matrix == "left" or $matrix == "l" {
        @return map.get($map, 4);
    }

    // Logic: y|vertical|v
    @else if $matrix == "y" or $matrix == "vertical" or $matrix == "v" {
        @return map.get($map, 1) map.get($map, 3);
    }

    // Logic: x|horizontal|h
    @else if $matrix == "x" or $matrix == "horizontal" or $matrix == "h" {
        @return map.get($map, 2) map.get($map, 4);
    }

    // Logic: all|a
    @else if $matrix == "all" or $matrix == "a" {
        @return map.get($map, 1) map.get($map, 2) map.get($map, 3) map.get($map, 4);
    }
}
