@charset "UTF-8";

// @description
// * get-first-from function.
// * This function retrieves the first element from the given list.

// @access private

// @version 1.5.0

// @author Kitty Giraudel
// @link https://kittygiraudel.com/

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace list

// @module list/get-first-from

// @update We updated the use of the list library of Sass.

// @dependencies:
// * - meta.type-of (SASS function).
// * - list.index (SASS function).
// * - list.append (SASS function).
// * - list.nth (SASS function).
// * - var.$main-data-types (variable).
// * - LibFunc.flatten-list (function).
// * - Error.throw (function).

// @param {List} $list
// * A list from which to retrieve the first element.

// @throw {Exception}
// * Throws an exception if the provided parameter is not a list or if the
// * list is empty.

// @example 1
// * .example1 {
// *   content: get-first-from((12, 43, 4));
// * }

// @output 1
// * .example1 {
// *   content: 12;
// * }

// @example 2
// * .example2 {
// *   content: get-first-from(((22, 3), 5));
// * }

// @output 2
// * .example2 {
// *   content: 22;
// * }

// @return {Any} - Returns the first element from the list.

@use "sass:meta";
@use "sass:list";
@use "../../abstract/global-variables" as var;
@use "../../functions/list/flatten-list" as LibFunc;
@use "../../development-utils/toggle-error-message" as Error;

@function get-first-from($list: ()) {
    @if meta.type-of($list) != list {
        @return Error.throw("The parameter of get-first-from function must be in a list type.");
    }

    @if list.length($list) == 0 {
        @return Error.throw("You must enter the list values of the list in get-first-from function.");
    }

    @if meta.type-of($list) != list {
        @if list.index(var.$main-data-types, $list) {
            $new-list: list.append($list, null);

            @return list.nth($new-list, 1);
        }
    }

    $new-list: LibFunc.flatten($list);

    @return list.nth($new-list, 1);
}
