@charset "UTF-8";

// @description
// * ptg-to-dec function.
// * Converts a percentage value to its decimal equivalent.

// @access public

// @version 1.5.1

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace converters

// @module converters/ptg-to-dec

// @dependencies:
// * - meta.type-of (SASS function).
// * - math.div (SASS function).
// * - LibFunc.cut-unit (function).
// * - Error.throw (function).

// @param {Number} $ptg-value
// * The percentage value to be converted into decimal.
// * Defaults to 0%.

// @throws {Error}
// * If the input is not a number.

// @example 1
// * .example {
// *   content: ptg-to-dec(50%);
// * }

// @output 1
// * .example {
// *   content: 0.5;
// * }

// @example 2
// * .example {
// *   content: ptg-to-dec();
// * }

// @output 2
// * .example {
// *   content: 0;
// * }

// @return {Number}
// * The decimal value of the input which is in percentage value.

@use "sass:meta";
@use "sass:math";
@use "sass:list";
@use "../../functions/global/cut-unit" as LibFunc;
@use "../../development-utils/toggle-error-message" as Error;

@function ptg-to-dec($ptg-value: 0%) {
    @if meta.type-of($ptg-value) != number {
        @return Error.throw("The parameter of ptg-to-dec function must be in a number type.");
    }

    @if $ptg-value == 0 {
        @return 0;
    }

    // stylelint-disable-next-line length-zero-no-unit
    @if $ptg-value == 0% {
        @return Error.throw("The parameter does not need a unit if it equals to zero.");
    }

    @if math.unit($ptg-value) != "%" {
        @return Error.throw("The ptg-to-dec function accepts argument with percentage unit only.");
    }

    $value-without-unit: LibFunc.cut-unit($ptg-value);

    @return math.div($value-without-unit, 100);
}
