var _excluded = ["className", "style", "mode", "showHeader", "showSidebar", "showFooter", "defaultCurrent", "onStepsChange", "headerProps", "bodyProps", "footerProps", "onClose", "onPrev", "onNext", "onFirstStepBack", "onBackConfirm", "onCloseConfirm", "__designMode", "__id"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { useMemo, useCallback, useState, forwardRef, useImperativeHandle } from 'react';
import PisellLayout from "../pisellLayout";
import { ProcedureHeader, ProcedureBody, ProcedureFooter } from "./components";
import { useStepManager } from "./hooks";
import { mergeClassNames, modifierClassName, isFooterGlobal } from "./utils";
import { useMobile } from "../../hooks/useMobile";
import "./PisellProcedure.less";

/**
 * 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();
 */
var PisellProcedure = /*#__PURE__*/forwardRef(function (props, ref) {
  var className = props.className,
    style = props.style,
    _props$mode = props.mode,
    mode = _props$mode === void 0 ? 'page' : _props$mode,
    _props$showHeader = props.showHeader,
    showHeader = _props$showHeader === void 0 ? true : _props$showHeader,
    _props$showSidebar = props.showSidebar,
    showSidebar = _props$showSidebar === void 0 ? true : _props$showSidebar,
    _props$showFooter = props.showFooter,
    showFooter = _props$showFooter === void 0 ? true : _props$showFooter,
    _props$defaultCurrent = props.defaultCurrent,
    defaultCurrent = _props$defaultCurrent === void 0 ? 0 : _props$defaultCurrent,
    onStepsChange = props.onStepsChange,
    headerProps = props.headerProps,
    bodyProps = props.bodyProps,
    footerProps = props.footerProps,
    onClose = props.onClose,
    onPrev = props.onPrev,
    onNext = props.onNext,
    onFirstStepBack = props.onFirstStepBack,
    onBackConfirm = props.onBackConfirm,
    onCloseConfirm = props.onCloseConfirm,
    __designMode = props.__designMode,
    __id = props.__id,
    other = _objectWithoutProperties(props, _excluded);

  // 检测是否是移动端（< 744px）
  // 注意：Hook 必须无条件调用，不能放在条件语句中
  var isMobileDetected = useMobile(744);
  // 弹窗模式下不应用移动端检测
  var isMobile = mode === 'modal' ? false : isMobileDetected;

  // 使用步骤管理 Hook
  var _useStepManager = useStepManager({
      stepsProps: headerProps === null || headerProps === void 0 ? void 0 : headerProps.stepsProps,
      defaultCurrent: defaultCurrent,
      onPrev: onPrev,
      onNext: onNext,
      onStepsChange: onStepsChange
    }),
    currentStep = _useStepManager.currentStep,
    _goPrev = _useStepManager.goPrev,
    _goNext = _useStepManager.goNext,
    _goToStep = _useStepManager.goToStep;

  // 移动端弹窗状态
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    summaryModalOpen = _useState2[0],
    setSummaryModalOpen = _useState2[1];
  var openSummaryModal = useCallback(function () {
    return setSummaryModalOpen(true);
  }, []);
  var closeSummaryModal = useCallback(function () {
    return setSummaryModalOpen(false);
  }, []);

  // 暴露组件方法给父组件
  useImperativeHandle(ref, function () {
    return {
      /**
       * 跳转到上一步
       */
      goPrev: function goPrev() {
        return _goPrev();
      },
      /**
       * 跳转到下一步
       */
      goNext: function goNext() {
        return _goNext();
      },
      /**
       * 跳转到指定步骤
       */
      goToStep: function goToStep(step) {
        return _goToStep(step);
      },
      /**
       * 获取当前步骤索引
       */
      getCurrentStep: function getCurrentStep() {
        return currentStep;
      },
      /**
       * 打开移动端总结弹窗
       */
      openSummaryModal: openSummaryModal,
      /**
       * 关闭移动端总结弹窗
       */
      closeSummaryModal: closeSummaryModal
    };
  }, [_goPrev, _goNext, _goToStep, currentStep, openSummaryModal, closeSummaryModal]);

  // 底部操作区位置模式（移动端强制使用 float-all 吸底悬浮，弹窗模式下不强制）
  var footerPosition = useMemo(function () {
    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]);

  // 容器类名
  var containerCls = useMemo(function () {
    return mergeClassNames('pisell-procedure', className,
    // 弹窗模式添加 --modal 修饰类，用于禁用媒体查询
    mode === 'modal' && 'pisell-procedure--modal', modifierClassName('pisell-procedure', "footer-".concat(footerPosition)));
  }, [className, mode, footerPosition]);

  // 判断底部是否全局显示
  var footerIsGlobal = isFooterGlobal(footerPosition);

  // 获取容器宽度和高度（垂直布局下不需要）
  // const containerSize = useElementSize({
  //   selector: bodyProps?.sidebarContainerSelector || '',
  //   enabled:
  //     bodyProps?.direction !== 'vertical' &&
  //     !!bodyProps?.sidebarContainerSelector,
  // });

  // // 使用自定义 Hook 计算响应式类名
  // const responsiveClsComputed =
  //   mode === 'modal' ? useResponsiveClass(containerSize?.width || 0) : '';

  // if (!responsiveClsComputed && mode === 'modal') return null;

  return /*#__PURE__*/React.createElement("div", _extends({
    className: containerCls,
    style: style,
    "data-component": "pisell-procedure",
    "data-id": __id
  }, other), /*#__PURE__*/React.createElement(PisellLayout, null, showHeader && /*#__PURE__*/React.createElement(ProcedureHeader, {
    headerProps: headerProps,
    currentStep: currentStep,
    goPrev: _goPrev,
    onClose: onClose,
    onFirstStepBack: onFirstStepBack,
    onBackConfirm: onBackConfirm,
    onCloseConfirm: onCloseConfirm,
    goToStep: _goToStep
  }), /*#__PURE__*/React.createElement(ProcedureBody, {
    bodyProps: bodyProps,
    footerProps: footerProps,
    footerPosition: footerPosition,
    showFooter: showFooter && !footerIsGlobal,
    showSidebar: showSidebar,
    summaryModalOpen: summaryModalOpen,
    onOpenSummaryModal: openSummaryModal,
    onCloseSummaryModal: closeSummaryModal,
    goPrev: _goPrev,
    goNext: _goNext,
    mode: mode
    // containerSize={containerSize}
    // responsiveClsComputed={responsiveClsComputed}
  }), showFooter && footerIsGlobal && /*#__PURE__*/React.createElement(ProcedureFooter, {
    footerProps: footerProps,
    position: footerPosition,
    isGlobal: true,
    sidebarContent: bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarSlot,
    summaryModalOpen: summaryModalOpen,
    onOpenSummaryModal: openSummaryModal,
    onCloseSummaryModal: closeSummaryModal,
    goPrev: _goPrev,
    goNext: _goNext,
    mode: mode
  })));
});
PisellProcedure.displayName = 'PisellProcedure';
export default PisellProcedure;