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/eftposPay/tip.tsx
var tip_exports = {};
__export(tip_exports, {
  default: () => tip_default
});
module.exports = __toCommonJS(tip_exports);
var import_utils = require("@pisell/utils");
var import_antd = require("antd");
var import_react = __toESM(require("react"));
var import_helper = require("./helper");
var import_const = require("./const");
var import_dayjs = __toESM(require("dayjs"));
var import_store = require("./store");
var import_hooks = require("./hooks");
var import_payLog = __toESM(require("./utils/payLog"));
var import_tip = require("./tip.less");
function formatDateUtils(date, format) {
  if (!date) {
    return date;
  }
  if (date.includes("undefined")) {
    return "";
  }
  const lang = localStorage.getItem("umi_locale") || "en-US";
  let _format = format || ["HH:mm:ss DD/MM/YYYY", "YYYY年MM月DD日 HH:mm:ss"];
  let type = lang === "en-US" || lang === "en" ? _format[0] : _format[1];
  return (0, import_dayjs.default)(date).locale(lang).format(type);
}
var tip_default = ({
  onChangeStatus,
  className = "",
  formatAmount,
  cardSurcharge,
  receipts,
  successTime,
  onChangeParams
}) => {
  const [disabled, setDisabled] = (0, import_react.useState)(true);
  const [amount, setAmount] = (0, import_react.useState)("");
  const [surcharge, setSurcharge] = (0, import_react.useState)("");
  const [surMoney, setSurMoney] = (0, import_react.useState)("");
  const [rate, setRate] = (0, import_react.useState)("");
  const [total, setTotal] = (0, import_react.useState)("");
  const [time, setTime] = (0, import_react.useState)("");
  const data = (0, import_store.useContextData)();
  const { symbol, custom } = data;
  const ref = (0, import_react.useRef)();
  const dispatch = (0, import_store.useDispatch)();
  const listRef = (0, import_react.useRef)(custom == null ? void 0 : custom.list);
  const {
    deviceRef,
    payRef,
    numRef,
    orderIdRef,
    modeRef,
    amountRef,
    eftposRef
  } = (0, import_hooks.useStoreRef)();
  (0, import_react.useEffect)(() => {
    import_payLog.default.log("成功确认页展示");
  }, []);
  const onConfirm = () => {
    import_payLog.default.log("确认支付成功");
    onChangeStatus("success", { ...ref.current || {} });
  };
  (0, import_react.useEffect)(() => {
    if (eftposRef.current === import_const.EftposEnum.Payo) {
      dispatch((0, import_store.updateNextStep)());
      dispatch(
        (0, import_store.updateCustom)({
          card_reader_surcharge: cardSurcharge || 0,
          receipt: receipts
        })
      );
    } else if (eftposRef.current === import_const.EftposEnum.Windcave) {
      dispatch(
        (0, import_store.updateCustom)({
          list: listRef.current.map((item) => ({
            ...item,
            status: "resolve"
          })),
          card_reader_surcharge: cardSurcharge || 0,
          receipt: receipts
        })
      );
    }
    const params = (0, import_helper.getPayParams)(
      {
        mode: modeRef.current,
        amount: amountRef.current,
        order_id: orderIdRef.current,
        number: numRef.current,
        device: deviceRef.current,
        pay: payRef.current,
        custom: {
          card_reader_surcharge: cardSurcharge,
          receipt: receipts
        }
      },
      "success"
    );
    ref.current = params;
    setAmount(`${(params == null ? void 0 : params.amount) || ""}`);
    setSurcharge(`${(params == null ? void 0 : params.surcharge) || ""}`);
    setSurMoney(`${(params == null ? void 0 : params.surMoney) || ""}`);
    setRate(`${(params == null ? void 0 : params.surRate) || ""}`);
    setTotal(`${(params == null ? void 0 : params.total) || ""}`);
    setTime(formatDateUtils(successTime));
    setDisabled(false);
    dispatch(
      (0, import_store.updateState)({
        status: "success",
        title: import_utils.locales.getText("page.eftpos-pay.text.successful")(
          modeRef.current
        )
      })
    );
  }, []);
  (0, import_react.useEffect)(() => {
    onChangeParams && onChangeParams({
      ...data,
      form: import_const.RestoreEumn.Restore
    });
  }, [data, onChangeParams]);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: `pisell-lowcode__eft-pay-box ${className}` }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-fail-title" }, import_utils.locales.getText("page.eftpos-pay.text.latest.success")), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-body pisell-lowcode__eft-pay-tip-body" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, import_utils.locales.getText("page.eftpos-pay.text.latest.amount"), ":", " ", formatAmount(`${amount}`, 2, symbol)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, import_utils.locales.getText("page.eftpos-pay.text.latest.surcharge"), ":", " ", formatAmount(`${surcharge}`, 2, symbol), " (", rate, "% +", " ", formatAmount(`${surMoney}`, 2, symbol), ")"), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, import_utils.locales.getText("page.eftpos-pay.text.surcharge.edit.actual.pay"), ":", " ", formatAmount(`${total}`, 2, symbol)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, import_utils.locales.getText("page.eftpos-pay.text.latest.time"), ": ", time)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Button,
    {
      disabled,
      block: true,
      className: "pisell-lowcode__eft-pay-step-item-btn",
      type: "primary",
      onClick: onConfirm
    },
    import_utils.locales.getText("page.eftpos-pay.text.latest.confirm")
  )));
};
