const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_const = require("./const.js");
const require_helper = require("./helper.js");
const require_index = require("./store/index.js");
const require_hooks = require("./hooks.js");
const require_payLog = require("./utils/payLog.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./tip.less");
//#region src/components/eftposPay/tip.tsx
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, dayjs.default)(date).locale(lang).format(type);
}
/**
* @title: 支付状态未知页面
* @description:
* @Author: hongbing.wang
* @Date: 2024-08-20 11:42
*/
var tip_default = ({ onChangeStatus, className = "", formatAmount, cardSurcharge, receipts, successTime, onChangeParams }) => {
	const [disabled, setDisabled] = (0, react.useState)(true);
	const [amount, setAmount] = (0, react.useState)("");
	const [surcharge, setSurcharge] = (0, react.useState)("");
	const [surMoney, setSurMoney] = (0, react.useState)("");
	const [rate, setRate] = (0, react.useState)("");
	const [total, setTotal] = (0, react.useState)("");
	const [time, setTime] = (0, react.useState)("");
	const data = require_index.useContextData();
	const { symbol, custom } = data;
	const ref = (0, react.useRef)();
	const dispatch = require_index.useDispatch();
	const listRef = (0, react.useRef)(custom === null || custom === void 0 ? void 0 : custom.list);
	const { deviceRef, payRef, numRef, orderIdRef, modeRef, amountRef, eftposRef } = require_hooks.useStoreRef();
	(0, react.useEffect)(() => {
		require_payLog.default.log("成功确认页展示");
	}, []);
	const onConfirm = () => {
		require_payLog.default.log("确认支付成功");
		onChangeStatus("success", require_objectSpread2._objectSpread2({}, ref.current || {}));
	};
	/**
	* @title: 手动标记
	* @description: 前往手动标记
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:31
	*/
	(0, react.useEffect)(() => {
		if (eftposRef.current === require_const.EftposEnum.Payo) {
			dispatch(require_index.updateNextStep());
			dispatch(require_index.updateCustom({
				card_reader_surcharge: cardSurcharge || 0,
				receipt: receipts
			}));
		} else if (eftposRef.current === require_const.EftposEnum.Windcave) dispatch(require_index.updateCustom({
			list: listRef.current.map((item) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "resolve" })),
			card_reader_surcharge: cardSurcharge || 0,
			receipt: receipts
		}));
		const params = require_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 || params === void 0 ? void 0 : params.amount) || ""}`);
		setSurcharge(`${(params === null || params === void 0 ? void 0 : params.surcharge) || ""}`);
		setSurMoney(`${(params === null || params === void 0 ? void 0 : params.surMoney) || ""}`);
		setRate(`${(params === null || params === void 0 ? void 0 : params.surRate) || ""}`);
		setTotal(`${(params === null || params === void 0 ? void 0 : params.total) || ""}`);
		setTime(formatDateUtils(successTime));
		setDisabled(false);
		dispatch(require_index.updateState({
			status: "success",
			title: _pisell_utils.locales.getText("page.eftpos-pay.text.successful")(modeRef.current)
		}));
	}, []);
	(0, react.useEffect)(() => {
		onChangeParams && onChangeParams(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, data), {}, { form: require_const.RestoreEumn.Restore }));
	}, [data, onChangeParams]);
	return /* @__PURE__ */ react.default.createElement("div", { className: `pisell-lowcode__eft-pay-box ${className}` }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-fail-title" }, _pisell_utils.locales.getText("page.eftpos-pay.text.latest.success")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-body pisell-lowcode__eft-pay-tip-body" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, _pisell_utils.locales.getText("page.eftpos-pay.text.latest.amount"), ":", " ", formatAmount(`${amount}`, 2, symbol)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, _pisell_utils.locales.getText("page.eftpos-pay.text.latest.surcharge"), ":", " ", formatAmount(`${surcharge}`, 2, symbol), " (", rate, "% +", " ", formatAmount(`${surMoney}`, 2, symbol), ")"), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, _pisell_utils.locales.getText("page.eftpos-pay.text.surcharge.edit.actual.pay"), ":", " ", formatAmount(`${total}`, 2, symbol)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-tip-text" }, _pisell_utils.locales.getText("page.eftpos-pay.text.latest.time"), ": ", time)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		disabled,
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		type: "primary",
		onClick: onConfirm
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.latest.confirm"))));
};
//#endregion
exports.default = tip_default;
