@charset "UTF-8";

// @description
// * from-end mixin.
// * This mixin provides a convenient way to select the
// * from-end child of element in the current context.
// * When you pass a number to the from-end mixin, it will select
// * the child when we count from the end.

// @access public

// @version 1.0.0

// @author Lucas Bonomi
// @link: https://github.com/LukyVj/family.scss

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace children

// @module children/from-end

// @dependencies:
// * - meta.type-of (SASS function).
// * - LibFunc.cut-unit (function).
// * - Error.throw (function).

// @update
// * We updated the mixin with validations

// @param {Number} $num
// * The number of children you want to select from.

// @throw {Exception}
// * Throws exceptions if the provided from-end parameter is not a number.

// @example
// * .example {
// *   .child {
// *     @include from-end(4) {
// *        background-color: #212121;
// *        color: #ffffff;
// *     };
// *   }
// * }

// @output
// * .example .child:nth-last-child(4) {
// *   background-color: #212121;
// *   color: #ffffff;
// * }

@use "sass:meta";
@use "sass:math";
@use "../../functions/global/cut-unit" as LibFunc;
@use "../../development-utils/toggle-error-message" as Error;

@mixin from-end($num: 1) {
    @if meta.type-of($num) != number {
        content: Error.throw("The parameter of from-end mixin must be in a number type.");
    }

    $num-without-unit: LibFunc.cut-unit($num);

    &:nth-last-child(#{$num-without-unit}) {
        @content;
    }
}
