"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Text", {
    enumerable: true,
    get: function() {
        return Text;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _classvarianceauthority = require("class-variance-authority");
const _css = require("../utils/css");
const _reactslot = require("@radix-ui/react-slot");
const _utils = require("@orderly.network/utils");
const _string = require("../utils/string");
const _types = require("@orderly.network/types");
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 textVariants = (0, _classvarianceauthority.cva)([], {
    variants: {
        variant: {},
        type: {
            primary: "orderly-text-primary",
            secondary: "orderly-text-secondary",
            tertiary: "orderly-text-tertiary",
            quaternary: "orderly-text-gray-300",
            warning: "orderly-text-warning",
            danger: "orderly-text-danger",
            success: "orderly-text-success",
            buy: "orderly-text-trade-profit",
            sell: "orderly-text-trade-loss"
        }
    }
});
const Text = (props)=>{
    const { variant, rule, asChildren, type, className, children, symbolElement, surfix, formatString, ...rest } = props;
    const Comp = asChildren ? _reactslot.Slot : "span";
    const content = (0, _react.useMemo)(()=>{
        if (typeof children === "undefined") return "--";
        if (typeof rule === "undefined" || rule === "text") return children;
        if (rule === "address") {
            const address = children;
            const [start, end] = props.range ?? [
                6,
                4
            ];
            const reg = new RegExp(`^(.{${start}})(.*)(.{${end}})$`);
            return `${address.replace(reg, "$1...$3")}`;
        }
        if (rule === "date") {
            // return new Date(children as string).toLocaleString();
            return (0, _utils.dayjs)(children).format(formatString ?? "YYYY-MM-DD HH:mm:ss");
        }
        if (rule === "symbol") {
            const arr = children.split("_");
            if (typeof symbolElement !== "undefined") {
                if (symbolElement === "base") {
                    return arr[1];
                }
                return arr[2];
            }
            return `${arr[1]}-${arr[0]}`;
        }
        if (rule === "status") {
            const status = children;
            if (status === _types.OrderStatus.NEW || status === _types.OrderStatus.OPEN) {
                return "Pending";
            }
            const text = (0, _string.firstLetterToUpperCase)(status);
            return text;
        }
        return children;
    }, [
        children,
        rule
    ]);
    const contentWithSurfix = (0, _react.useMemo)(()=>{
        if (typeof surfix === "undefined") return content;
        return /*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
            className: "orderly-flex orderly-gap-1",
            children: [
                content,
                surfix
            ]
        });
    }, [
        content,
        surfix
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(Comp, {
        ...rest,
        className: (0, _css.cn)(textVariants({
            variant,
            type,
            className
        })),
        children: contentWithSurfix
    });
};

//# sourceMappingURL=text.js.map