import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import PisellLayout from "../pisellLayout/index.js";
import { mergeClassNames, modifierClassName } from "./utils/classNames.js";
import { isFooterGlobal } from "./utils/footerPosition.js";
import ProcedureHeader from "./components/ProcedureHeader.js";
import { useStepManager } from "./hooks/useStepManager.js";
import ProcedureFooter from "./components/ProcedureFooter.js";
import ProcedureBody from "./components/ProcedureBody.js";
import { useMobile } from "../../hooks/useMobile.js";
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useState } from "react";
import "./PisellProcedure.less";
//#region src/components/PisellProcedure/PisellProcedure.tsx
const _excluded = [
	"className",
	"style",
	"mode",
	"showHeader",
	"showSidebar",
	"showFooter",
	"defaultCurrent",
	"onStepsChange",
	"headerProps",
	"bodyProps",
	"footerProps",
	"onClose",
	"onPrev",
	"onNext",
	"onFirstStepBack",
	"onBackConfirm",
	"onCloseConfirm",
	"__designMode",
	"__id"
];
/**
* PisellProcedure 流程容器组件
*
* @description 用于管理多步骤流程的复合容器组件，基于 PisellLayout 实现三段式布局
* @author Pisell Team
* @version 1.0.0
*
* @example
* // 使用 ref 调用组件方法
* const procedureRef = useRef<PisellProcedureRef>(null);
*
* // 跳转到下一步
* procedureRef.current?.goNext();
*
* // 获取当前步骤
* const currentStep = procedureRef.current?.getCurrentStep();
*/
const PisellProcedure = forwardRef((props, ref) => {
	const { className, style, mode = "page", showHeader = true, showSidebar = true, showFooter = true, defaultCurrent = 0, onStepsChange, headerProps, bodyProps, footerProps, onClose, onPrev, onNext, onFirstStepBack, onBackConfirm, onCloseConfirm, __designMode, __id } = props, other = _objectWithoutProperties(props, _excluded);
	const isMobileDetected = useMobile(744);
	const isMobile = mode === "modal" ? false : isMobileDetected;
	const { currentStep, goPrev, goNext, goToStep } = useStepManager({
		stepsProps: headerProps === null || headerProps === void 0 ? void 0 : headerProps.stepsProps,
		defaultCurrent,
		onPrev,
		onNext,
		onStepsChange
	});
	const [summaryModalOpen, setSummaryModalOpen] = useState(false);
	const openSummaryModal = useCallback(() => setSummaryModalOpen(true), []);
	const closeSummaryModal = useCallback(() => setSummaryModalOpen(false), []);
	useImperativeHandle(ref, () => ({
		goPrev: () => goPrev(),
		goNext: () => goNext(),
		goToStep: (step) => goToStep(step),
		getCurrentStep: () => currentStep,
		openSummaryModal,
		closeSummaryModal
	}), [
		goPrev,
		goNext,
		goToStep,
		currentStep,
		openSummaryModal,
		closeSummaryModal
	]);
	const footerPosition = useMemo(() => {
		if (isMobile && mode !== "modal") return "float-all";
		return (footerProps === null || footerProps === void 0 ? void 0 : footerProps.position) || "float-sidebar";
	}, [
		mode,
		isMobile,
		footerProps === null || footerProps === void 0 ? void 0 : footerProps.position
	]);
	const containerCls = useMemo(() => {
		return mergeClassNames("pisell-procedure", className, mode === "modal" && "pisell-procedure--modal", modifierClassName("pisell-procedure", `footer-${footerPosition}`));
	}, [
		className,
		mode,
		footerPosition
	]);
	const footerIsGlobal = isFooterGlobal(footerPosition);
	return /* @__PURE__ */ React.createElement("div", _objectSpread2({
		className: containerCls,
		style,
		"data-component": "pisell-procedure",
		"data-id": __id
	}, other), /* @__PURE__ */ React.createElement(PisellLayout, null, showHeader && /* @__PURE__ */ React.createElement(ProcedureHeader, {
		headerProps,
		currentStep,
		goPrev,
		onClose,
		onFirstStepBack,
		onBackConfirm,
		onCloseConfirm,
		goToStep
	}), /* @__PURE__ */ React.createElement(ProcedureBody, {
		bodyProps,
		footerProps,
		footerPosition,
		showFooter: showFooter && !footerIsGlobal,
		showSidebar,
		summaryModalOpen,
		onOpenSummaryModal: openSummaryModal,
		onCloseSummaryModal: closeSummaryModal,
		goPrev,
		goNext,
		mode
	}), showFooter && footerIsGlobal && /* @__PURE__ */ React.createElement(ProcedureFooter, {
		footerProps,
		position: footerPosition,
		isGlobal: true,
		sidebarContent: bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarSlot,
		summaryModalOpen,
		onOpenSummaryModal: openSummaryModal,
		onCloseSummaryModal: closeSummaryModal,
		goPrev,
		goNext,
		mode
	})));
});
PisellProcedure.displayName = "PisellProcedure";
//#endregion
export { PisellProcedure as default };
