var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pay/toB/components/Cache/index.tsx
var Cache_exports = {};
__export(Cache_exports, {
  default: () => Cache_default
});
module.exports = __toCommonJS(Cache_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils2 = require("../../store/utils");
var import_store = require("../../store");
var import_hooks = require("../../hooks");
var import_index = require("./index.less");
var ToBPayCache = (props) => {
  const { open, title, uuid, expect_amount = "", onCancel, onOk } = props;
  const osPayment = (0, import_store.useOSPayment)();
  const symbol = (0, import_hooks.useSymbol)();
  const [inputAmount, setInputAmount] = (0, import_react.useState)(expect_amount);
  const [payDesc, setPayDesc] = (0, import_react.useState)("");
  (0, import_react.useEffect)(() => {
    setInputAmount(expect_amount);
  }, [expect_amount]);
  (0, import_react.useEffect)(() => {
    osPayment.getRemainingOrderAmountWithInputAsync(inputAmount, uuid).then((res) => {
      if (Number(res) === 0) {
        setPayDesc(import_utils.locales.getText("tobPay.text.cash.modal.no.change.given"));
      }
      if (Number(res) < 0) {
        setPayDesc(
          import_utils.locales.getText("tobPay.text.cash.modal.amount.pay.change")(
            `${symbol}${Math.abs(Number(res))}`
          )
        );
      }
      if (Number(res) > 0) {
        setPayDesc(
          import_utils.locales.getText("tobPay.text.cash.modal.amount.left.pay.paid")(
            `${symbol}${res}`
          )
        );
      }
    });
  }, [inputAmount]);
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      title,
      open,
      onCancel,
      okButtonProps: {
        disabled: Number(inputAmount) <= 0
      },
      okText: import_utils.locales.getText("tobPay.text.cash.modal.ok"),
      onOk: () => {
        onOk(inputAmount);
      },
      destroyOnClose: true
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "tob-pay-cache" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "tob-pay-cache-money" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "tob-pay-cache-text" }, import_utils.locales.getText("tobPay.text.cash.modal.amount.toPay")), /* @__PURE__ */ import_react.default.createElement("div", { className: "tob-pay-cache-num" }, symbol, Number(expect_amount).toFixed(2))), /* @__PURE__ */ import_react.default.createElement("div", { className: "tob-pay-cache-title" }, import_utils.locales.getText("tobPay.text.cash.modal.input.title")), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
      import_antd.InputNumber,
      {
        precision: 2,
        value: inputAmount,
        min: 0,
        formatter: import_utils2.limitDecimals,
        parser: import_utils2.limitDecimals,
        onChange: (event) => {
          if (event !== null && event !== void 0) {
            setInputAmount(event);
          } else {
            setInputAmount("0");
          }
        },
        style: { width: "100%" }
      }
    )), /* @__PURE__ */ import_react.default.createElement("div", { className: "tob-pay-cache-desc" }, payDesc))
  );
};
var Cache_default = ToBPayCache;
