import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import React, { useMemo } from "react";
import { cn } from "../utils/css";
import { parseNumber } from "../utils/num";
import { Minus, Plus } from "lucide-react";
const coloringClasses = {
    lose: "orderly-text-trade-loss",
    profit: "orderly-text-trade-profit",
    neutral: "orderly-text-base-contrast-54"
};
export const Numeral = (props)=>{
    const { rule = "price", coloring, precision, tick, surfix, prefix, visible, unit, cureency, truncate = "floor", padding = true, showIcon = false } = props;
    // TODO: check precision
    const num = Number(props.children);
    const child = useMemo(()=>{
        if (isNaN(num)) return "--";
        if (typeof visible !== "undefined" && !visible) return "*****";
        return parseNumber(num, {
            rule,
            precision,
            tick,
            truncate,
            padding,
            abs: showIcon
        });
    }, [
        num,
        precision,
        visible,
        showIcon
    ]);
    const colorClassName = 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 = 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__*/ _jsx(Minus, {
                size: 12
            });
        }
        if (props.icons?.profit) return props.icons?.profit;
        // @ts-ignore
        return /*#__PURE__*/ _jsx(Plus, {
            size: 12
        });
    }, [
        num,
        props.visible,
        showIcon
    ]);
    const childWithUnit = useMemo(()=>{
        if (typeof surfix === "undefined" && typeof prefix === "undefined" && typeof unit === "undefined" && typeof cureency === "undefined" && !showIcon) {
            return child;
        }
        const surfixEle = surfix ? surfix : unit ? /*#__PURE__*/ _jsx("span", {
            children: unit
        }) : undefined;
        const prefixEle = prefix ? prefix : cureency ? /*#__PURE__*/ _jsx("span", {
            children: cureency
        }) : undefined;
        return /*#__PURE__*/ _jsxs("span", {
            className: "orderly-inline-flex orderly-items-center orderly-gap-1 orderly-tabular-nums",
            children: [
                prefixEle,
                child,
                surfixEle
            ]
        });
    }, [
        child,
        surfix,
        unit,
        prefix
    ]);
    if (!colorClassName && !props.className) {
        return /*#__PURE__*/ _jsx(_Fragment, {
            children: childWithUnit
        });
    }
    return /*#__PURE__*/ _jsxs("span", {
        className: cn("orderly-inline-flex orderly-items-center", colorClassName, props.className),
        children: [
            icon,
            childWithUnit
        ]
    });
};

//# sourceMappingURL=numeral.js.map