// /* SG
// # Tools/Z-Index [[dev]]
//
// @file globals/tools/_t-zindex.scss
//
// ##### `z()`
// ###### function(`$layer`, `$modifier: false`)
// Returns a numeric value (used for z-index) from a named layer, stored in `$$z-index`. Changing the modifier to anything other than `false` will add 1 plus however many times the value has been called. So, if you've called `z(head, true)` 5 times, and `head`'s default value is 100, you would get a value of 105.
//
// The `$modifier` is useful if you'd like to closely layer z-indexes within the same module. It is rarely necessary, though since z-indexes stack.
//
// */

$z-index: (
    reset: 0,
    behind: -100,
    head: 100,
    body: 200,
    foot: 300,
    modal: 500,
) !default;

$z-registry: ();

@function z($layer, $modifier: false) {
    $layer-addition: 0;

    @if map-get($z-index, $layer) != false {
        @if $modifier == null {
            @if map-get($z-registry, $layer) == null {
                $z-registry: map-merge(
                    $z-registry,
                    (
                        $layer: 0,
                    )
                ) !global;
            }

            @return map-get($z-index, $layer);
        } @else {
            @if map-get($z-registry, $layer) == null {
                $z-registry: map-merge(
                    $z-registry,
                    (
                        $layer: 1,
                    )
                ) !global;
            } @else {
                $layer-addition: map-get($z-registry, $layer) + 1;
                $z-registry: map-merge(
                    $z-registry,
                    (
                        $layer: $layer-addition,
                    )
                ) !global;
            }

            $return-value: map-get($z-index, $layer) +
                map-get($z-registry, $layer);

            @return $return-value;
        }
    } @else {
        @warn "#{$layer} is not in the $z-index map, please choose from the following z-index values: #{$z-index}";
    }
}
