@charset "UTF-8";

// @description
// * cm-to-px function.
// * This function converts a value with centimeter unit into pixels.

// @access public

// @version 1.7.2

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace converters

// @module converters/cm-to-px

// @dependencies:
// * - meta.type-of (SASS function).
// * - math.unit (SASS function).
// * - LibFunc.cut-unit (function).
// * - Approx.approx (function).
// * - Error.throw (function).

// @param {Number} $cm-val
// * The value in centimeter unit to convert.

// @throw {Exception}
// * Throws exceptions if the provided parameter is not a number, doesn't
// * have a unit, or doesn't have a centimeter unit.

// @example
// * .example {
// *   content: cm-to-px(12cm);
// * }

// @output
// * .example {
// *   content: 453.543px;
// * }

// @return {Number} - Returns the converted value in pixels.

@use "sass:meta";
@use "sass:math";
@use "../../functions/global/cut-unit" as LibFunc;
@use "../../development-utils/approximation-numbers" as Approx;
@use "../../development-utils/toggle-error-message" as Error;

@function cm-to-px($cm-val) {
    @if meta.type-of($cm-val) != number {
        @return Error.throw("The parameter of cm-to-px function must be in a number type.");
    }

    @if $cm-val == 0 {
        @return 0;
    }

    // stylelint-disable-next-line length-zero-no-unit
    @if $cm-val == 0cm {
        @return Error.throw("The parameter does not need a unit if it equals to zero.");
    }

    @if math.unit($cm-val) != cm {
        @return Error.throw("The cm-to-px function accepts argument with centimeter unit only.");
    }

    $actual-number: LibFunc.cut-unit($cm-val);
    // stylelint-disable-next-line number-max-precision
    $final-result: Approx.of(($actual-number * 37.7952755906px));

    @return $final-result;
}
