import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { ClientEnum } from "../../const.js";
import { updateComponent, updateState, useContextData, useDispatch } from "../../store/index.js";
import payLog from "../../utils/payLog.js";
import { getInitState } from "../../manufacturer.js";
import header_default from "../header/index.js";
import React from "react";
import { Button } from "antd";
import { locales } from "@pisell/utils";
import { useMount } from "ahooks";
import XClose from "@pisell/icon/es/XClose";
//#region src/components/eftposPay/component/fail/index.tsx
var fail_default = ({ onChange, className = "", isMobile }) => {
	var _steps$step;
	const { eftpos, step, steps, mode, name, symbol, amount, order_id, number, device, client, originalParams } = useContextData();
	const isPosNetworkError = ((_steps$step = steps[step]) === null || _steps$step === void 0 || (_steps$step = _steps$step.custom) === null || _steps$step === void 0 ? void 0 : _steps$step.isPosNetworkError) || false;
	const dispatch = useDispatch();
	/**
	* @title: 重新支付
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:30
	*/
	const onRetry = () => {
		payLog.log("失败页：点击重试");
		onChange("page", "pay");
		dispatch(updateState(getInitState(eftpos, _objectSpread2(_objectSpread2({}, originalParams || {}), {}, {
			mode,
			name,
			symbol,
			amount,
			order_id,
			number: "",
			client
		}))));
	};
	/**
	* @title: 手动标记
	* @description: 前往手动标记
	* @return {*}
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:31
	*/
	const onManually = () => {
		payLog.log("失败页：点击手动标记");
		dispatch(updateState({ manual: {
			title: locales.getText("page.eftpos-pay.text.request.unknown.title")(mode),
			text: locales.getText("page.eftpos-pay.text.request.unknown.text")(mode)
		} }));
		dispatch(updateComponent("Manual"));
	};
	const onNotin = () => {
		payLog.log("失败页：点击打印小票");
		onChange("print", [], "print_on_timeout");
	};
	/**
	* @title: 关闭支付页面
	* @description: 交易关闭页面
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:32
	*/
	const onClose = () => {
		payLog.log("失败页：点击关闭");
		onChange("fail", {
			number,
			uniquePaymentNumber: number,
			device,
			order_id
		});
	};
	useMount(() => {
		payLog.log("失败页展示", { status: steps[step].status });
		if (steps[step].status === "fail") onChange("page", "fail");
	});
	return /* @__PURE__ */ React.createElement("div", { className: `pisell-lowcode__eft-pay-box ${className}` }, /* @__PURE__ */ React.createElement(header_default, { status: steps[step].status }, steps[step].status === "fail" && !isMobile ? /* @__PURE__ */ React.createElement(XClose, {
		size: 20,
		style: {
			fontSize: "24px",
			position: "absolute",
			top: 0,
			right: 0
		},
		onClick: onClose
	}) : null), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-fail-title" }, steps[step].title || locales.getText("page.eftpos-pay.text.failed")(mode)), steps[step].status === "fail" ? /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-fail-text pisell-lowcode__eft-pay-body" }, steps[step].fail) : steps[step].status === "warn" ? /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-warn-text pisell-lowcode__eft-pay-body" }, steps[step].warn) : null, isPosNetworkError ? /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, client === ClientEnum.Merchant ? /* @__PURE__ */ React.createElement(Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onManually
	}, locales.getText("page.eftpos-pay.text.manual.marking")) : /* @__PURE__ */ React.createElement(Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onNotin
	}, locales.getText("page.eftpos-pay.text.manual.print_receipt"))) : /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ React.createElement(Button, {
		block: true,
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onClose
	}, locales.getText("page.eftpos-pay.text.cancel")), /* @__PURE__ */ React.createElement(Button, {
		block: true,
		type: "primary",
		className: "pisell-lowcode__eft-pay-step-item-btn",
		onClick: onRetry
	}, locales.getText("page.eftpos-pay.text.retry"))));
};
//#endregion
export { fail_default as default };
