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_const$1 = require("./const.js");
const require_index = require("../store/index.js");
const require_hooks = require("../hooks.js");
const require_payLog = require("../utils/payLog.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
//#region src/components/eftposPay/windcave/receiptAction.tsx
/**
* @title: 按钮操作区
* @description: 仅包含签名
* @Author: hongbing.wang
* @Date: 2024-08-20 12:33
*/
const ReceiptAction = ({ api, onChange }) => {
	const dispatch = require_index.useDispatch();
	const { custom, mode } = require_index.useContextData();
	const { numRef } = require_hooks.useStoreRef();
	const listRef = (0, react.useRef)(custom === null || custom === void 0 ? void 0 : custom.list);
	const [receiptLoading, setReceiptLoading] = (0, react.useState)((custom === null || custom === void 0 ? void 0 : custom.receiptLoading) || false);
	const unloadRef = (0, react.useRef)(false);
	(0, react.useEffect)(() => {
		dispatch(require_index.updateCustom({ receiptLoading }));
	}, [receiptLoading]);
	const receiptPage = (0, react.useMemo)(() => (custom === null || custom === void 0 ? void 0 : custom.step) !== require_const$1.StepStatusEnum.Receipt ? "" : (custom === null || custom === void 0 ? void 0 : custom.receiptPage) || "receipt", [custom === null || custom === void 0 ? void 0 : custom.step, custom === null || custom === void 0 ? void 0 : custom.receiptPage]);
	(0, react.useEffect)(() => {
		listRef.current = custom === null || custom === void 0 ? void 0 : custom.list;
	}, [custom === null || custom === void 0 ? void 0 : custom.list]);
	/**
	* @title: 确认签名
	* @description: 确认签名 不阻碍-查询
	* @return null
	* @Author: hongbing.wang
	* @Date: 2024-08-12 11:30
	*/
	const onAccept = () => {
		require_payLog.default.log("Windcave：签名-点击确认");
		dispatch(require_index.updateStatus(require_const.StatusEnum.Loading));
		dispatch(require_index.updateCustom({ list: listRef.current.map((item) => item.index === require_const$1.StepStatusEnum.Receipt ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "resolve" }) : item) }));
		dispatch(require_index.updateState({ title: _pisell_utils.locales.getText("page.eftpos-pay.text.processing") }));
		setReceiptLoading(true);
		api.update({
			type: "YES",
			number: numRef.current
		}).then((res) => {
			if (unloadRef.current) return res;
			if (res && `${res.code}` === "200") {
				setReceiptLoading(false);
				const current = listRef.current.map((item) => {
					if (Number(item === null || item === void 0 ? void 0 : item.index) < require_const$1.StepStatusEnum.Wait) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "resolve" });
					return item;
				});
				const nextStep = require_const$1.getStepMapping(require_const$1.StepStatusEnum.Wait, { mode });
				if (nextStep) {
					current.push(nextStep);
					if (nextStep.type === require_const$1.StemTypeEnum.Passive) dispatch(require_index.updateStatus(require_const.StatusEnum.Question));
					dispatch(require_index.updateState({ title: nextStep.index < require_const$1.StepStatusEnum.Receipt ? _pisell_utils.locales.getText("page.eftpos-pay.text.loading")(mode) : nextStep.index === require_const$1.StepStatusEnum.Receipt ? _pisell_utils.locales.getText("page.eftpos-pay.text.waiting.signature") : _pisell_utils.locales.getText("page.eftpos-pay.text.loading")(mode) }));
				}
				dispatch(require_index.updateCustom({
					step: require_const$1.StepStatusEnum.Wait,
					list: current
				}));
				onChange(true);
				return res;
			}
			return Promise.reject(res);
		}).catch(() => {
			if (unloadRef.current) return;
			dispatch(require_index.updateCustom({ list: listRef.current.map((item) => item.index === require_const$1.StepStatusEnum.Receipt ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "pedding" }) : item) }));
			dispatch(require_index.updateState({ title: _pisell_utils.locales.getText("page.eftpos-pay.text.waiting.signature") }));
			dispatch(require_index.updateStatus(require_const.StatusEnum.Question));
			setReceiptLoading(false);
			onChange(false);
		});
	};
	/**
	* @title: 后退
	* @description: 
	* @Author: hongbing.wang
	* @Date: 2024-08-20 12:34
	*/
	const onBack = () => {
		require_payLog.default.log("Windcave：签名-点击后退");
		dispatch(require_index.updateState({
			title: _pisell_utils.locales.getText("page.eftpos-pay.text.waiting.signature"),
			status: require_const.StatusEnum.Question
		}));
		dispatch(require_index.updateCustom({ receiptPage: "receipt" }));
	};
	/**
	* @title: 取消签名
	* @description: 取消签名 不阻碍-状态查询
	* @return null
	* @Author: hongbing.wang
	* @Date: 2024-08-12 11:30
	*/
	const onConfirm = () => {
		require_payLog.default.log("Windcave：签名-点击取消");
		dispatch(require_index.updateState({
			title: _pisell_utils.locales.getText("page.eftpos-pay.text.processing"),
			status: require_const.StatusEnum.Loading
		}));
		dispatch(require_index.updateCustom({
			list: listRef.current.map((item) => item.index === require_const$1.StepStatusEnum.Receipt ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "reject" }) : item),
			receiptPage: "receipt"
		}));
		setReceiptLoading(true);
		api.update({
			type: "NO",
			number: numRef.current
		}).then((res) => {
			if (unloadRef.current) return res;
			setReceiptLoading(false);
			if (res && `${res.code}` === "200") {
				const current = listRef.current.map((item) => {
					if (Number(item === null || item === void 0 ? void 0 : item.index) === require_const$1.StepStatusEnum.Receipt) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
						resolve: item.reject,
						status: "resolve"
					});
					if (Number(item === null || item === void 0 ? void 0 : item.index) < require_const$1.StepStatusEnum.Wait) return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "resolve" });
					return item;
				});
				const nextStep = require_const$1.getStepMapping(require_const$1.StepStatusEnum.Wait, { mode });
				if (nextStep) {
					nextStep.pedding = _pisell_utils.locales.getText("page.eftpos-pay.text.waiting.decline.signature");
					if (nextStep.type === require_const$1.StemTypeEnum.Passive) dispatch(require_index.updateStatus(require_const.StatusEnum.Question));
					dispatch(require_index.updateState({ title: nextStep.index < require_const$1.StepStatusEnum.Receipt ? _pisell_utils.locales.getText("page.eftpos-pay.text.loading")(mode) : nextStep.index === require_const$1.StepStatusEnum.Receipt ? _pisell_utils.locales.getText("page.eftpos-pay.text.waiting.signature") : _pisell_utils.locales.getText("page.eftpos-pay.text.loading")(mode) }));
					current.push(nextStep);
				}
				dispatch(require_index.updateCustom({
					step: require_const$1.StepStatusEnum.Wait,
					list: current
				}));
				onChange(true);
				return res;
			}
			return Promise.reject(res);
		}).catch(() => {
			if (unloadRef.current) return;
			onChange(false);
			setReceiptLoading(false);
			dispatch(require_index.updateCustom({ list: listRef.current.map((item) => item.index === require_const$1.StepStatusEnum.Receipt ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, { status: "pedding" }) : item) }));
			dispatch(require_index.updateState({ title: _pisell_utils.locales.getText("page.eftpos-pay.text.waiting.signature") }));
			dispatch(require_index.updateStatus(require_const.StatusEnum.Question));
			setReceiptLoading(false);
		});
	};
	/**
	* @title: 前往取消签名
	* @description: 前往取消签名确认流程
	* @Author: hongbing.wang
	* @Date: 2024-08-20 12:40
	*/
	const onDecline = () => {
		require_payLog.default.log("Windcave：签名-点击取消");
		dispatch(require_index.updateState({
			title: _pisell_utils.locales.getText("page.eftpos-pay.text.signature.title"),
			status: require_const.StatusEnum.Warn,
			custom: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, custom), {}, { receiptPage: "again" })
		}));
	};
	(0, react.useEffect)(() => () => {
		unloadRef.current = true;
	}, []);
	if (receiptLoading) return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		disabled: true
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.leave")));
	if (receiptPage === "receipt") return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onDecline
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.decline")), /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		type: "primary",
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onAccept
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.accept")));
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onBack
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.back")), /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		type: "primary",
		onClick: onConfirm,
		disabled: receiptLoading
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.confirm.decline")));
};
/**
* @title: 按钮操作区
* @description: 不包含签名
* @Author: hongbing.wang
* @Date: 2024-08-20 12:32
*/
const Action = ({ index, onCancel, disabled }) => {
	require_index.useDispatch();
	const { custom, mode } = require_index.useContextData();
	/**
	* @title: 前往手动标记页
	* @Author: hongbing.wang
	* @Date: 2024-08-20 12:18
	*/
	if (index < require_const$1.StepStatusEnum.Application) return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onCancel,
		disabled
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.cancel")));
	if (index >= require_const$1.StepStatusEnum.Application && index < require_const$1.StepStatusEnum.Receipt) return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		disabled: true
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.leave")));
	if (index === require_const$1.StepStatusEnum.Receipt) return null;
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		disabled: true
	}, _pisell_utils.locales.getText("page.eftpos-pay.text.leave")));
};
//#endregion
exports.ReceiptAction = ReceiptAction;
exports.default = Action;
