/**
 * @since Last modified: 2024-09-10 11:20:41
 * @function toPixel
 * @description Convert the REM unit to a pixel unit and take the floor value.
 * @param {string|number} data - Bringing unit size or pure figures,e.g. "2.36rem","23.6px" or number 23.6 .
 * @param {number} [multiple=10] - The multiple of rem unit to px unit.The default value comes from "--fontsize-base" of ax.css
 * @returns  {number} - Return a integer of pixel.
 * @see {@link https://codepen.io/axui/pen/yLZQMgY|demo @ codepen}
 * @example
 * ax.toPixel('24rem');
 * <!--return 240 (pixel)-->
 */
'use strict';
import prefix from '../global/prefix';
import alias from '../global/alias';
import toNumber from './toNumber';
const toPixel = (data: string | number, multiple?: number): number => {
    let result = 0;
    if (!data) {
        return result;
    }
    multiple = multiple || parseInt(getComputedStyle(document.documentElement).getPropertyValue(`--${prefix}fs-base`).trim()) || 10;
    if (typeof data === 'string') {
        data = data.trim();
        if (data.endsWith('rem') || data.endsWith('REM')) {
            result = ~~((toNumber(data.replace('rem', '').replace('REM', '')) as number) * multiple);
        } else if (data.endsWith('px') || data.endsWith('PX')) {
            result = ~~toNumber(data.replace('px', '').replace('PX', ''));
        } else {
            result = ~~data;
        }
    } else if (typeof data === 'number') {
        result = ~~data;
    }
    return result;
}
export default toPixel;
