@charset "UTF-8";

// @description
// * px-to-rem function
// * This function converts a value with pixel unit into rem.

// @access public

// @version 1.2.0

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace converters

// @module converters/px-to-rem

// @dependencies:
// * - meta.type-of (SASS function).
// * - math.unit (SASS function).
// * - Config.$base-font-size (config variable).
// * - LibFunc.cut-unit (function).
// * - Approx.approx (function).
// * - Error.throw (function).

// @param {Number} $px-val
// * The value in pixel unit to convert.

// @throw {Exception}
// * Throws an exception if the provided parameter is not a number or
// * parameter not has a unit.

// @example
// * .example {
// *   content: px-to-rem(12px);
// * }

// @output
// * .example {
// *   content: 0.75rem;
// * }

// @return {Number} - Returns the converted value in rem.

@use "sass:meta";
@use "sass:math";
@use "../../abstract/config" as Config;
@use "../../functions/global/cut-unit" as LibFunc;
@use "../../development-utils/approximation-numbers" as Approx;
@use "../../development-utils/toggle-error-message" as Error;

@function px-to-rem($px-val) {
    @if meta.type-of($px-val) != number {
        @return Error.throw("The parameter of px-to-rem function must be in a number type.");
    }

    @if $px-val == 0 {
        @return 0;
    }

    // stylelint-disable-next-line length-zero-no-unit
    @if $px-val == 0px {
        @return Error.throw("The parameter does not need a unit if it equals to zero.");
    }

    @return Approx.of(calc(LibFunc.cut-unit($px-val) / Config.$base-font-size)) + rem;
}
