import useEngineContext from "../../../../hooks/useEngineContext.js";
import { useSales } from "../../../../businessModel/SalesModel/Sales/index.js";
import React, { useState } from "react";
import { locales } from "@pisell/utils";
import { PisellHeaderProgressBar, PisellModal } from "@pisell/materials";
import "./index.less";
//#region src/components/eventBooking/components/progressBar/index.tsx
const ProgressBar = ({ title, description, showClose = true, isConfirmClose = true, showStep = true, showBack = true, style, onBack, onClose }) => {
	var _context$appHelper;
	const [open, setOpen] = useState(false);
	const { removeSessionStorage } = useSales();
	const { interaction } = ((_context$appHelper = useEngineContext().appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	/**
	* @title: 点击关闭
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-14 22:41
	*/
	const handleClose = () => {
		if (isConfirmClose) setOpen(true);
		else onClose === null || onClose === void 0 || onClose();
	};
	/**
	* @title: 点击退出
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-02-10 17:46
	*/
	const handleOk = () => {
		var _interaction$utils, _interaction$utils$is;
		if (interaction === null || interaction === void 0 || (_interaction$utils = interaction.utils) === null || _interaction$utils === void 0 || (_interaction$utils$is = _interaction$utils.isAppEnv) === null || _interaction$utils$is === void 0 ? void 0 : _interaction$utils$is.call(_interaction$utils)) {
			const url = window.location.href;
			console.log(url, url.includes("isByTabbar"), "___url");
			if (url.includes("isByTabbar")) {
				removeSessionStorage === null || removeSessionStorage === void 0 || removeSessionStorage();
				const urlParams = new URLSearchParams(window.location.search);
				urlParams.delete("cacheId");
				setOpen(false);
				interaction.utils.postMessageToApp({
					module: "global",
					key: "openNative",
					data: { link: { page: "home" } }
				});
				window.location.href = window.location.pathname + "?" + urlParams.toString();
				return;
			}
			interaction.utils.postMessageToApp({
				module: "global",
				key: "paymentResultAction",
				data: { actionType: "backHome" }
			});
			return;
		}
		onClose === null || onClose === void 0 || onClose();
		setOpen(false);
		removeSessionStorage === null || removeSessionStorage === void 0 || removeSessionStorage();
	};
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(PisellHeaderProgressBar, {
		className: "event-progress-bar",
		style,
		stepText: showStep ? title : "",
		title: description,
		showClose,
		onBack,
		onClose: handleClose,
		enableBorder: true,
		borderColor: "#EAECF0",
		showBack
	}), /* @__PURE__ */ React.createElement(PisellModal.Information, {
		open,
		title: locales.getText("pisell2.event.close.title"),
		describe: locales.getText("pisell2.event.close.tip"),
		okText: locales.getText("pisell2.event.close.exit"),
		cancelText: locales.getText("pisell2.event.close.continue"),
		closable: true,
		okButtonProps: { style: { backgroundColor: "#D92D20" } },
		onCancel: () => {
			setOpen(false);
		},
		onOk: () => handleOk()
	}));
};
//#endregion
export { ProgressBar as default };
