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