"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Numeral", {
    enumerable: true,
    get: function() {
        return Numeral;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _css = require("../utils/css");
const _num = require("../utils/num");
const _lucidereact = require("lucide-react");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const coloringClasses = {
    lose: "orderly-text-trade-loss",
    profit: "orderly-text-trade-profit",
    neutral: "orderly-text-base-contrast-54"
};
const Numeral = (props)=>{
    const { rule = "price", coloring, precision, tick, surfix, prefix, visible, unit, cureency, truncate = "floor", padding = true, showIcon = false, id } = props;
    // TODO: check precision
    const num = Number(props.children);
    const child = (0, _react.useMemo)(()=>{
        if (isNaN(num)) return "--";
        if (typeof visible !== "undefined" && !visible) return "*****";
        return (0, _num.parseNumber)(num, {
            rule,
            precision,
            tick,
            truncate,
            padding,
            abs: showIcon
        });
    }, [
        num,
        precision,
        visible,
        showIcon
    ]);
    const colorClassName = (0, _react.useMemo)(()=>{
        if (!coloring) return "";
        if (typeof visible !== "undefined" && !visible) return "";
        // if (props.value === 0) return coloringClasses.neutral;
        if (Number.isNaN(num)) {
            // console.warn(`if coloring, value is need number: ${props.value}`);
            return "";
        }
        if (num === 0) return coloringClasses.neutral;
        if (num < 0) return coloringClasses.lose;
        return coloringClasses.profit;
    }, [
        coloring,
        num,
        props.visible
    ]);
    const icon = (0, _react.useMemo)(()=>{
        if (!showIcon || Number.isNaN(num) || num === 0) return null;
        if (typeof visible !== "undefined" && !visible) return null;
        if (num < 0) {
            if (props.icons?.loss) return props.icons?.loss;
            // @ts-ignore
            return /*#__PURE__*/ (0, _jsxruntime.jsx)(_lucidereact.Minus, {
                size: 12
            });
        }
        if (props.icons?.profit) return props.icons?.profit;
        // @ts-ignore
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_lucidereact.Plus, {
            size: 12
        });
    }, [
        num,
        props.visible,
        showIcon
    ]);
    const childWithUnit = (0, _react.useMemo)(()=>{
        if (typeof surfix === "undefined" && typeof prefix === "undefined" && typeof unit === "undefined" && typeof cureency === "undefined" && !showIcon) {
            return child;
        }
        const surfixEle = surfix ? surfix : unit ? /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
            children: unit
        }) : undefined;
        const prefixEle = prefix ? prefix : cureency ? /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
            children: cureency
        }) : undefined;
        return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
            children: [
                prefixEle,
                child,
                surfixEle
            ]
        });
    }, [
        child,
        surfix,
        unit,
        prefix
    ]);
    if (!colorClassName && !props.className) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
            children: childWithUnit
        });
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
        id: id,
        className: (0, _css.cn)("orderly-inline-flex orderly-items-center orderly-gap-1 orderly-tabular-nums", colorClassName, props.className),
        children: [
            icon,
            childWithUnit
        ]
    });
};

//# sourceMappingURL=numeral.js.map