"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TokenQtyInput", {
    enumerable: true,
    get: function() {
        return TokenQtyInput;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _input = require("../input");
const _inputMask = require("../input/inputMask");
const _networkImage = require("../icon/networkImage");
const _react = require("react");
const _divider = require("../divider");
const _utils = require("@orderly.network/utils");
const _spinner = require("../spinner");
const TokenQtyInput = (props)=>{
    const { onChange, onValueChange, onTokenChange, token, loading, needCalc = false, ...rest } = props;
    const amount = (0, _react.useMemo)(()=>{
        if (!props.amount) return "";
        const num = Number(props.amount);
        if (isNaN(num)) return "";
        if (num <= 0) return "";
        if (needCalc) {
            return (0, _utils.commify)(new _utils.Decimal(props.amount).sub(props.fee).toFixed(2));
        }
        return (0, _utils.commify)(new _utils.Decimal(props.amount).toFixed(2));
    // return commify(props.amount);
    }, [
        props.amount,
        props.fee,
        needCalc
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_input.Input, {
        ...props,
        // onChange={_onChange}
        placeholder: "Quantity",
        readOnly: true,
        value: amount,
        prefix: loading ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_spinner.Spinner, {
            size: "small",
            className: "orderly-mx-2"
        }) : undefined,
        containerClassName: "orderly-bg-base-500 orderly-rounded-borderRadius",
        className: "orderly-token-quantity-input orderly-text-sm orderly-text-base-contrast-54 desktop:orderly-text-base",
        suffix: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_inputMask.InputMask, {
            className: "orderly-flex-row orderly-items-center orderly-gap-2",
            children: [
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_divider.Divider, {
                    vertical: true
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_networkImage.NetworkImage, {
                    name: token.symbol,
                    type: "token",
                    size: "small"
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
                    className: "orderly-text-base-contrast-80 orderly-text-3xs  desktop:orderly-text-xs",
                    children: token.symbol
                })
            ]
        })
    });
};

//# sourceMappingURL=tokenQtyInput.js.map