const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../pisellModal/index.js");
const require_footer = require("../../pisellLayout/footer.js");
const require_classNames = require("../utils/classNames.js");
const require_FooterActions = require("./FooterActions.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/PisellProcedure/components/ProcedureFooter.tsx
/**
* ProcedureFooter 底部操作区组件
* 
* @description 包含左侧自定义内容和右侧操作按钮（支持溢出收纳功能）
* @author Pisell Team
*/
const ProcedureFooter = ({ footerProps, position, className, isGlobal = false, sidebarContent, summaryModalOpen = false, onOpenSummaryModal, onCloseSummaryModal, goPrev, goNext, mode = "page" }) => {
	/** 底部区域类名 */
	const footerCls = (0, react.useMemo)(() => {
		return require_classNames.mergeClassNames("pisell-procedure-footer", className, footerProps === null || footerProps === void 0 ? void 0 : footerProps.className, require_classNames.modifierClassName("pisell-procedure-footer", position));
	}, [
		className,
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.className,
		position
	]);
	/** 获取操作按钮内容 */
	const actionsContent = (0, react.useMemo)(() => {
		const actions = footerProps === null || footerProps === void 0 ? void 0 : footerProps.actions;
		if (!actions) return null;
		if (react.Children.toArray(actions).length === 0) return null;
		return react.Children.map(actions, (child, index) => {
			if (!(0, react.isValidElement)(child)) return child;
			const childProps = child.props;
			const dataAction = childProps === null || childProps === void 0 ? void 0 : childProps["data-action"];
			const originalOnClick = childProps === null || childProps === void 0 ? void 0 : childProps.onClick;
			let injectedAction;
			if (dataAction === "prev") injectedAction = goPrev;
			else if (dataAction === "next") injectedAction = goNext;
			if (injectedAction) return (0, react.cloneElement)(child, { onClick: (...args) => {
				originalOnClick === null || originalOnClick === void 0 || originalOnClick(...args);
				injectedAction === null || injectedAction === void 0 || injectedAction();
			} });
			return child;
		});
	}, [
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.actions,
		goPrev,
		goNext
	]);
	/**
	* 包装 summaryButton 添加点击事件
	* 如果用户传入的按钮已有 onClick，则先执行用户的 onClick，再打开弹窗
	*/
	const wrappedSummaryButton = (0, react.useMemo)(() => {
		var _button$props;
		const button = footerProps === null || footerProps === void 0 ? void 0 : footerProps.summaryButton;
		if (!button || !(0, react.isValidElement)(button)) return button;
		const originalOnClick = (_button$props = button.props) === null || _button$props === void 0 ? void 0 : _button$props.onClick;
		return (0, react.cloneElement)(button, { onClick: (e) => {
			if (typeof originalOnClick === "function") originalOnClick(e);
			onOpenSummaryModal === null || onOpenSummaryModal === void 0 || onOpenSummaryModal();
		} });
	}, [footerProps === null || footerProps === void 0 ? void 0 : footerProps.summaryButton, onOpenSummaryModal]);
	/** 渲染底部操作区内容 */
	const footerContent = (0, react.useMemo)(() => {
		const hasSummaryButton = mode === "modal" ? false : !!wrappedSummaryButton;
		const hasLeftSlot = (footerProps === null || footerProps === void 0 ? void 0 : footerProps.leftSlot) !== void 0 && (footerProps === null || footerProps === void 0 ? void 0 : footerProps.leftSlot) !== null;
		const hasActions = actionsContent !== null && actionsContent !== void 0;
		if (!hasSummaryButton && !hasLeftSlot && !hasActions) return null;
		return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, hasSummaryButton && wrappedSummaryButton && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-procedure-footer__summary" }, wrappedSummaryButton), (hasLeftSlot || hasActions) && ((footerProps === null || footerProps === void 0 ? void 0 : footerProps.enableOverflow) !== false ? /* @__PURE__ */ react.default.createElement(require_FooterActions.default, {
			leftSlot: footerProps === null || footerProps === void 0 ? void 0 : footerProps.leftSlot,
			moreText: footerProps === null || footerProps === void 0 ? void 0 : footerProps.moreText
		}, actionsContent) : /* @__PURE__ */ react.default.createElement("div", { className: "pisell-procedure-footer__content" }, (footerProps === null || footerProps === void 0 ? void 0 : footerProps.leftSlot) && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-procedure-footer__left" }, footerProps.leftSlot), hasActions && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-procedure-footer__actions" }, actionsContent))));
	}, [
		mode,
		wrappedSummaryButton,
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.enableOverflow,
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.leftSlot,
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.moreText,
		actionsContent
	]);
	/** 移动端信息区弹窗 */
	const summaryModal = (0, react.useMemo)(() => {
		if (!(footerProps === null || footerProps === void 0 ? void 0 : footerProps.summaryButton) || !sidebarContent) return null;
		return /* @__PURE__ */ react.default.createElement(require_index.default, {
			open: summaryModalOpen,
			onCancel: onCloseSummaryModal,
			title: (footerProps === null || footerProps === void 0 ? void 0 : footerProps.summaryModalTitle) || "详情",
			platform: "h5",
			footer: null,
			destroyOnClose: true
		}, sidebarContent);
	}, [
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.summaryButton,
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.summaryModalTitle,
		sidebarContent,
		summaryModalOpen,
		onCloseSummaryModal
	]);
	if (!footerContent) return null;
	if (isGlobal) return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement(require_footer.default, {
		className: footerCls,
		style: footerProps === null || footerProps === void 0 ? void 0 : footerProps.style
	}, footerContent), summaryModal);
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		className: footerCls,
		style: footerProps === null || footerProps === void 0 ? void 0 : footerProps.style
	}, footerContent), summaryModal);
};
ProcedureFooter.displayName = "ProcedureFooter";
//#endregion
exports.default = ProcedureFooter;
