@charset "UTF-8";

// @description
// * has-same-keys function.
// * Check if all maps passed as parameters have the same keys.

// @access private

// @version 1.5.0

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace map

// @module map/has-same-keys

// @dependencies:
// * - meta.type-of (SASS function).
// * - map.keys (SASS function).
// * - Error.throw (function).

// @param {Map} $all-maps
// * The maps to be compared.

// @throws {Error}
// * If less than one map is provided.

// @example
// * .example {
// *   content: has-same-keys(("first": 10, "second": 11),
// *            ("first": 12, "second": 13));
// * }

// @output
// * .example {
// *   content: true;
// * }

// @return {Boolean} True if all maps have the same keys, false otherwise.

@use "sass:meta";
@use "sass:list";
@use "sass:map";
@use "../../development-utils/toggle-error-message" as Error;

@function has-same-keys($all-maps...) {
    $keys-list: null;

    @if list.length($all-maps) == 1 {
        @return Error.throw("The parameter of has-same-keys function must has more than one map.");
    }

    @each $map in $all-maps {
        @if meta.type-of($map) != map {
            @return Error.throw("The parameter of has-same-keys function must be in a map type.");
        }

        $keys: map.keys($map);

        // * If keys-list is not initialized, set it
        @if not $keys-list {
            $keys-list: $keys;
        } @else {
            // * Check if the keys are the same for each map
            @if $keys != $keys-list {
                @return false;
            }
        }
    }

    @return true;
}
