@charset "UTF-8";

// @description
// * shadow mixin.
// * A mixin for creating box-shadow properties with
// * flexibility and validation with cross-browser support.

// @access public

// @version 1.2.0

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @reference: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow

// @namespace general

// @module general/shadow

// @dependencies:
// * - meta.type-of (SASS function).
// * - var.$main-units (variable).
// * - pref.prefixing-web (mixin).

// @param {List} $val
// * List of values to construct the box-shadow property.

// @throws {Warning}
// * If no arguments are passed, default value is set to `none`.

// @throws {Error}
// * If values are not valid or do not match expected formats.

// @example 1
// * .example {
// *   @include shadow(none);
// * }

// @output 1
// * .example {
// *   -webkit-box-shadow: none;
// *   box-shadow: none;
// * }

// @example 2
// * .example {
// *   @include shadow(
// *            (10px 15px 15px darkslategrey),
// *            (20px 20px coral),
// *            (20px 20px 25px 22px teal)
// *   );
// * }

// @output 2
// * .example {
// *   -webkit-box-shadow: 10px 15px 15px darkslategrey,
// *                       20px 20px coral,
// *                       20px 20px 25px 22px teal;
// *   box-shadow: 10px 15px 15px darkslategrey,
// *               20px 20px coral,
// *               20px 20px 25px 22px teal;
// * }

// stylelint-disable scss/dollar-variable-empty-line-before
// stylelint-disable indentation

@use "sass:meta";
@use "sass:list";
@use "sass:math";
@use "../vendor-prefixes/prefix" as pref;
@use "../../abstract/global-variables" as var;

@mixin shadow($val...) {
    $box-shadow-values: (inherit, initial, revert, revert-layer, unset, none) !default;

    $actual-value-box-shadow: ();

    @if list.length($val) == 0 {
        @warn "The default value now for shadow is none. So, for more readable in using shadow mixin, please, pass (none) value as argument to it.";
        @include pref.prefixing-web(box-shadow, none);
    } @else {
        @each $one-list in $val {
            $first-item-val: list.nth($one-list, 1);

            @if list.length($one-list) == 1 {
                @if meta.type-of($first-item-val) == string {
                    @if not list.index($box-shadow-values, $first-item-val) {
                        @error "The value of box shadow must has one of these values: (#{$box-shadow-values})";
                    }

                    $actual-value-box-shadow: list.append($actual-value-box-shadow, $first-item-val, $separator: comma);

                    @debug $actual-value-box-shadow;
                } @else {
                    @error "The box shadow property receive string type if you pass to it a single value.";
                }
            } @else if list.length($one-list) == 2 {
                @error "Please, Enter the valid values of the shadow mixin. It must be at least 3 values";
            } @else if list.length($one-list) >= 3 {
                $second-item-val: list.nth($one-list, 2);

                @if meta.type-of($first-item-val) == number and meta.type-of($second-item-val) == number {
                    @if not list.index(var.$main-units, math.unit($first-item-val)) {
                        @error "First value of the box shadow must has one of these units: (#{var.$main-units})";
                    }

                    @if not list.index(var.$main-units, math.unit($second-item-val)) {
                        @error "Second value of the box shadow must has one of these units: (#{var.$main-units})";
                    }
                } @else {
                    @error "First and second value in shadow mixin must be in number type. If you want to add (inset) value, add it as last one in arguments.";
                }

                @if list.length($one-list) == 3 {
                    $third-item-val: list.nth($one-list, 3);

                    @if meta.type-of($third-item-val) != color {
                        @error "The third argument of shadow mixin must be in color type.";
                    }

                    $actual-value-box-shadow: list.append(
                        $actual-value-box-shadow,
                        $first-item-val $second-item-val $third-item-val,
                        $separator: comma
                    );
                } @else if list.length($one-list) == 4 {
                    $third-item-val: list.nth($one-list, 3);
                    $fourth-item-val: list.nth($one-list, 4);

                    @if not list.index(var.$main-units, math.unit($third-item-val)) {
                        @error "Third value of the box shadow must has one of these units: (#{var.$main-units})";
                    }

                    @if meta.type-of($fourth-item-val) != color {
                        @error "The fourth argument of shadow mixin must be in color type.";
                    }

                    $actual-value-box-shadow: list.append(
                        $actual-value-box-shadow,
                        $first-item-val $second-item-val $third-item-val $fourth-item-val,
                        $separator: comma
                    );
                } @else if list.length($one-list) == 5 {
                    $third-item-val: list.nth($one-list, 3);
                    $fourth-item-val: list.nth($one-list, 4);
                    $fifth-item-val: list.nth($one-list, 5);

                    @if not list.index(var.$main-units, math.unit($third-item-val)) {
                        @error "Third value of the box shadow must has one of these units: (#{var.$main-units})";
                    }

                    @if not list.index(var.$main-units, math.unit($fourth-item-val)) {
                        @error "Fourth value of the box shadow must has one of these units: (#{var.$main-units})";
                    }

                    @if meta.type-of($fifth-item-val) != color {
                        @error "The fifth argument of shadow mixin must be in color type.";
                    }

                    $actual-value-box-shadow: list.append(
                        $actual-value-box-shadow,
                        $first-item-val $second-item-val $third-item-val $fourth-item-val $fifth-item-val,
                        $separator: comma
                    );
                } @else if list.length($one-list) == 6 {
                    $third-item-val: list.nth($one-list, 3);
                    $fourth-item-val: list.nth($one-list, 4);
                    $fifth-item-val: list.nth($one-list, 5);
                    $sixth-item-val: list.nth($one-list, 6);

                    @if not list.index(var.$main-units, math.unit($third-item-val)) {
                        @error "Third value of the box shadow must has one of these units: (#{var.$main-units})";
                    }

                    @if not list.index(var.$main-units, math.unit($fourth-item-val)) {
                        @error "Fourth value of the box shadow must has one of these units: (#{var.$main-units})";
                    }

                    @if meta.type-of($fifth-item-val) != color {
                        @error "The fifth argument of shadow mixin must be in color type.";
                    }

                    @if $sixth-item-val != inset {
                        @error "Last value of the box shadow must be (inset).";
                    }

                    $current-list: (
                        $actual-value-box-shadow,
                        $first-item-val
                            $second-item-val
                            $third-item-val
                            $fourth-item-val
                            $fifth-item-val
                            $sixth-item-val,
                        comma
                    );
                }
            }
        }

        @include pref.prefixing-web(box-shadow, $actual-value-box-shadow);
    }
}
