@charset "UTF-8";

// @description
// * in-to-cm function.
// * This function converts a value with inches unit into centimeters.

// @access public

// @version 1.6.2

// @author Khaled Mohamed

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace converters

// @module converters/in-to-cm

// @dependencies:
// * - meta.type-of (SASS function).
// * - math.unit (SASS function).
// * - LibFunc.cut-unit (function).
// * - Approx.approx (function).
// * - Error.throw (function).

// @param {Number} $inches-val
// * The value in inches unit to convert.

// @throw {Exception}
// * Throws exceptions if the provided parameter is not a number, doesn't
// * have a unit, or doesn't have an inches unit.

// @example
// * .example {
// *   content: in-to-cm(12in);
// * }

// @output
// * .example {
// *   content: 30.48cm;
// * }

// @return {Number} - Returns the converted value in centimeters.

@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 in-to-cm($inches-val) {
    @if meta.type-of($inches-val) != number {
        @return Error.throw("The parameter of in-to-cm function must be in a number type.");
    }

    @if $inches-val == 0 {
        @return 0;
    }

    // stylelint-disable-next-line length-zero-no-unit
    @if $inches-val == 0in {
        @return Error.throw("The parameter does not need a unit if it equals to zero.");
    }

    @if math.unit($inches-val) != in {
        @return Error.throw("The in-to-cm function accepts argument with inch unit only.");
    }

    $actual-number: LibFunc.cut-unit($inches-val);
    $final-result: Approx.of(($actual-number * 2.54cm));

    @return $final-result;
}
