@charset "UTF-8";

// @description
// * first mixin.
// * This mixin provides a convenient way to select the first child
// * of element(s) in the current context.

// @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/first

// @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.

// @throw {Exception}
// * Throws exceptions if the provided first parameter is not a number.

// @example
// * .example {
// *   .child {
// *     @include first(10) {
// *        background-color: #212121;
// *        color: #ffffff;
// *     };
// *   }
// * }

// @output
// * .example .child:nth-child(-n+10) {
// *   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 first($num: 1) {
    @if meta.type-of($num) != number {
        content: Error.throw("The parameter of first mixin must be in a number type.");
    }

    $num-without-unit: LibFunc.cut-unit($num);

    @if $num-without-unit == 1 {
        &:first-child {
            @content;
        }
    } @else {
        &:nth-child(-n + #{$num-without-unit}) {
            @content;
        }
    }
}
