import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { ModeEnum } from "../../const.js";
import { updateState, useContextData, useDispatch } from "../../store/index.js";
import { useCountdown } from "../../hooks.js";
import { getInitState } from "../../manufacturer.js";
import React, { useEffect, useMemo, useState } from "react";
import { Button } from "antd";
import { locales } from "@pisell/utils";
import { PisellAlert } from "@pisell/materials";
import "./index.less";
//#region src/components/eftposPay/component/prompt/index.tsx
/**
* @title: 支付状态未知页面
* @description:
* @Author: hongbing.wang
* @Date: 2024-08-20 11:42
*/
var prompt_default = ({ onChange, className = "" }) => {
	const [prompt, setPrompt] = useState(0);
	const { eftpos, mode, name, symbol, amount, order_id, number, device, client, originalParams } = useContextData();
	const dispatch = useDispatch();
	const [disabled, setDisabled] = useState(false);
	const { time, isRunning, start, cancel } = useCountdown(30);
	const onNotin = () => {
		setPrompt(2);
		onChange("print", [], "print_on_timeout");
	};
	const onClose = () => {
		setDisabled(true);
		cancel();
		onChange("print", [], "back_home");
	};
	useEffect(() => {
		if (isRunning && time === 0) onChange("print", [], "back_home");
	}, [time, isRunning]);
	useEffect(() => {
		if (prompt === 2) start();
	}, [prompt]);
	/**
	* @title: 重新支付
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:30
	*/
	const onRetry = () => {
		onChange("page", "pay");
		const params = _objectSpread2(_objectSpread2({}, originalParams || {}), {}, {
			mode,
			name,
			symbol,
			amount,
			order_id,
			client
		});
		if (mode !== ModeEnum.Query) params.number = "";
		dispatch(updateState(getInitState(eftpos, params)));
	};
	const context = useMemo(() => {
		if (prompt === 0) return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
			className: "pisell-lowcode__eft-pay-body",
			style: {
				display: "flex",
				flexDirection: "column",
				gap: "16px"
			}
		}, /* @__PURE__ */ React.createElement(PisellAlert, {
			type: "info",
			className: "pisell-lowcode__eft-pay-alert",
			showIcon: true,
			message: locales.getText("page.eftpos-pay.text.prompt.ask.title")
		}), /* @__PURE__ */ React.createElement("h3", {
			style: { margin: 0 },
			className: "pisell-lowcode__eft-pay-notion-title"
		}, locales.getText("page.eftpos-pay.text.prompt.ask.h1")), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-notion-text" }, locales.getText("page.eftpos-pay.text.prompt.ask.text")), /* @__PURE__ */ React.createElement(PisellAlert, {
			className: "pisell-lowcode__eft-pay-alert",
			message: locales.getText("page.eftpos-pay.text.prompt.ask.info")
		})), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ React.createElement(Button, {
			block: true,
			type: "primary",
			className: "pisell-lowcode__eft-pay-step-item-btn",
			onClick: () => {
				setPrompt(1);
			}
		}, locales.getText("page.eftpos-pay.text.prompt.ask.check.btn")), /* @__PURE__ */ React.createElement(Button, {
			block: true,
			className: "pisell-lowcode__eft-pay-step-item-btn",
			onClick: onRetry
		}, locales.getText("page.eftpos-pay.text.prompt.ask.again.btn"))));
		if (prompt === 1) return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
			className: "pisell-lowcode__eft-pay-body",
			style: {
				display: "flex",
				flexDirection: "column",
				gap: "16px"
			}
		}, /* @__PURE__ */ React.createElement(PisellAlert, {
			type: "success",
			className: "pisell-lowcode__eft-pay-alert",
			showIcon: true,
			message: "Let’s check it together!"
		}), /* @__PURE__ */ React.createElement("h3", {
			style: { margin: 0 },
			className: "pisell-lowcode__eft-pay-notion-title"
		}, locales.getText("page.eftpos-pay.text.prompt.submit.title")), /* @__PURE__ */ React.createElement("div", { style: {
			display: "flex",
			flexDirection: "column",
			gap: "16px"
		} }, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-notion-text" }, locales.getText("page.eftpos-pay.text.prompt.submit.text-1")), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-notion-text" }, locales.getText("page.eftpos-pay.text.prompt.submit.text-2")), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-notion-text" }, locales.getText("page.eftpos-pay.text.prompt.submit.text-3"))), /* @__PURE__ */ React.createElement(PisellAlert, {
			className: "pisell-lowcode__eft-pay-alert",
			type: "info",
			message: locales.getText("page.eftpos-pay.text.prompt.submit.info")
		})), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ React.createElement(Button, {
			block: true,
			type: "primary",
			className: "pisell-lowcode__eft-pay-step-item-btn",
			onClick: onNotin
		}, locales.getText("page.eftpos-pay.text.prompt.submit.success.btn")), /* @__PURE__ */ React.createElement(Button, {
			block: true,
			className: "pisell-lowcode__eft-pay-step-item-btn",
			onClick: onRetry
		}, locales.getText("page.eftpos-pay.text.prompt.submit.again.btn"))));
		return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
			className: "pisell-lowcode__eft-pay-body",
			style: {
				display: "flex",
				flexDirection: "column",
				gap: "16px"
			}
		}, /* @__PURE__ */ React.createElement(PisellAlert, {
			type: "success",
			className: "pisell-lowcode__eft-pay-alert",
			showIcon: true,
			message: locales.getText("page.eftpos-pay.text.prompt.notion.title")
		}), /* @__PURE__ */ React.createElement(PisellAlert, {
			type: "success",
			className: "pisell-lowcode__eft-pay-alert",
			message: locales.getText("page.eftpos-pay.text.prompt.notion.info")
		}), /* @__PURE__ */ React.createElement("h3", {
			className: "pisell-lowcode__eft-pay-notion-title",
			style: { margin: 0 }
		}, locales.getText("page.eftpos-pay.text.prompt.notion.h1")), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-notion-text" }, locales.getText("page.eftpos-pay.text.prompt.notion.text-1")), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-notion-text" }, locales.getText("page.eftpos-pay.text.prompt.notion.text-2")))), /* @__PURE__ */ React.createElement("div", { className: "pisell-lowcode__eft-pay-step-item-btns" }, /* @__PURE__ */ React.createElement(Button, {
			type: "primary",
			block: true,
			disabled: disabled || time === 0,
			className: "pisell-lowcode__eft-pay-step-item-btn",
			onClick: onClose
		}, locales.getText("page.eftpos-pay.text.prompt.notion.btn"), !disabled && time ? `(${time}s)` : "")));
	}, [
		prompt,
		time,
		disabled
	]);
	return /* @__PURE__ */ React.createElement("div", { className: `pisell-lowcode__eft-pay-box ${className}` }, context);
};
//#endregion
export { prompt_default as default };
