@charset "UTF-8";

// @description
// * reverse function.
// * This function retrieves the reversed list from the given one.

// @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/reverse

// @update We updated the use of the list library of Sass.

// @dependencies:
// * - meta.type-of (SASS function).
// * - list.length (SASS function).
// * - list.append (SASS function).
// * - list.nth (SASS function).
// * - LibFunc.flatten-list (function).
// * - Error.throw (function).

// @param {List} $list
// * A list from which to reverse.

// @throw {Exception}
// * Throws an exception if the provided parameter is not a list.

// @example
// * .example {
// *   content: reverse(((12, 43, 4), (33, 555, 6)));
// * }

// @output
// * .example {
// *   content: 6, 555, 33, 4, 43, 12;
// * }

// @return {Any} - Returns the reversed list from the given list.

@use "sass:meta";
@use "sass:list";
@use "../../functions/list/flatten-list" as LibFunc;
@use "../../development-utils/toggle-error-message" as Error;

@function reverse($list: ()) {
    @if meta.type-of($list) != list {
        @return Error.throw("The parameter of reverse function must be in a list type.");
    }

    $flat-list: LibFunc.flatten($list);
    $reversed-list: ();

    @for $i from list.length($flat-list) to 0 {
        $reversed-list: list.append($reversed-list, list.nth($flat-list, $i));
    }

    @return $reversed-list;
}
