function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React, { useMemo } from 'react';
import PisellLayout from "../../pisellLayout";
import ProcedureContent from "./ProcedureContent";
import ProcedureSidebar from "./ProcedureSidebar";
import ProcedureFooter from "./ProcedureFooter";
import { mergeClassNames, isFooterInContent, isFooterInSidebar, generateRatioStyles } from "../utils";

/**
 * ProcedureBody 子组件 Props
 */

/**
 * ProcedureBody 主体区域组件
 * 
 * @description 包含内容区和信息区的布局容器，支持固定宽度和比例两种布局模式
 * @author Pisell Team
 */
var ProcedureBody = function ProcedureBody(_ref) {
  var bodyProps = _ref.bodyProps,
    footerProps = _ref.footerProps,
    footerPosition = _ref.footerPosition,
    _ref$showFooter = _ref.showFooter,
    showFooter = _ref$showFooter === void 0 ? true : _ref$showFooter,
    _ref$showSidebar = _ref.showSidebar,
    showSidebar = _ref$showSidebar === void 0 ? true : _ref$showSidebar,
    className = _ref.className,
    summaryModalOpen = _ref.summaryModalOpen,
    onOpenSummaryModal = _ref.onOpenSummaryModal,
    onCloseSummaryModal = _ref.onCloseSummaryModal,
    goPrev = _ref.goPrev,
    goNext = _ref.goNext,
    _ref$mode = _ref.mode,
    mode = _ref$mode === void 0 ? 'page' : _ref$mode,
    containerSize = _ref.containerSize,
    responsiveClsComputed = _ref.responsiveClsComputed;
  /** 排列方向，默认为横向 */
  var direction = (bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.direction) || 'horizontal';
  /** 内容顺序，默认为内容区在前 */
  var contentOrder = (bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.contentOrder) || 'content-first';
  /** 布局模式，默认为固定宽度 */
  var layoutMode = (bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.layoutMode) || 'fixed';
  /** 布局比例，默认为 7:3 */
  var layoutRatio = (bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.layoutRatio) || '7:3';

  /** 主体区域类名 */
  var bodyCls = useMemo(function () {
    return mergeClassNames('pisell-procedure-body', className, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.className, // 添加排列方向类名
    "pisell-procedure-body--".concat(direction), // 添加布局模式类名
    "pisell-procedure-body--".concat(layoutMode), // 添加内容顺序类名
    "pisell-procedure-body--".concat(contentOrder));
  }, [className, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.className, direction, layoutMode, contentOrder]);

  /** 计算比例布局样式 */
  var ratioStyles = useMemo(function () {
    if (layoutMode !== 'ratio') return null;
    return generateRatioStyles(layoutRatio, 16);
  }, [layoutMode, layoutRatio]);

  /** 内容区样式（合并比例样式和用户自定义样式） */
  var contentStyle = useMemo(function () {
    if (layoutMode === 'ratio' && ratioStyles) {
      return _objectSpread(_objectSpread({}, ratioStyles.contentStyle), bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.contentStyle);
    }
    return bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.contentStyle;
  }, [layoutMode, ratioStyles, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.contentStyle]);

  /** 信息区样式（合并比例样式和用户自定义样式） */
  var sidebarStyle = useMemo(function () {
    if (layoutMode === 'ratio' && ratioStyles) {
      return _objectSpread(_objectSpread({}, ratioStyles.sidebarStyle), bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarStyle);
    }
    return bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarStyle;
  }, [layoutMode, ratioStyles, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarStyle]);

  /** 信息区内容（用于移动端弹窗显示） */
  var sidebarContent = bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarSlot;

  /** 内容区底部 */
  var contentFooter = useMemo(function () {
    if (!showFooter || !isFooterInContent(footerPosition)) return null;
    return /*#__PURE__*/React.createElement(ProcedureFooter, {
      footerProps: footerProps,
      position: footerPosition,
      sidebarContent: sidebarContent,
      summaryModalOpen: summaryModalOpen,
      onOpenSummaryModal: onOpenSummaryModal,
      onCloseSummaryModal: onCloseSummaryModal,
      goPrev: goPrev,
      goNext: goNext,
      mode: mode
    });
  }, [showFooter, footerPosition, footerProps, sidebarContent, summaryModalOpen, onOpenSummaryModal, onCloseSummaryModal, goPrev, goNext, mode]);

  /** 信息区底部 */
  var sidebarFooter = useMemo(function () {
    if (!showFooter || !isFooterInSidebar(footerPosition)) return null;
    return /*#__PURE__*/React.createElement(ProcedureFooter, {
      footerProps: footerProps,
      position: footerPosition,
      sidebarContent: sidebarContent,
      summaryModalOpen: summaryModalOpen,
      onOpenSummaryModal: onOpenSummaryModal,
      onCloseSummaryModal: onCloseSummaryModal,
      goPrev: goPrev,
      goNext: goNext,
      mode: mode
    });
  }, [showFooter, footerPosition, footerProps, sidebarContent, summaryModalOpen, onOpenSummaryModal, onCloseSummaryModal, goPrev, goNext, mode]);

  /** PisellLayout 样式（根据排列方向设置 flex-direction） */
  var layoutStyle = useMemo(function () {
    return {
      flexDirection: direction === 'vertical' ? 'column' : 'row'
    };
  }, [direction]);

  /** 内容区组件 */
  var contentComponent = /*#__PURE__*/React.createElement(ProcedureContent, {
    className: bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.contentClassName,
    style: contentStyle,
    extra: contentFooter
  }, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.contentSlot);

  /** 信息区组件 */
  var sidebarComponent = showSidebar ? /*#__PURE__*/React.createElement(ProcedureSidebar, {
    className: bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarClassName,
    style: sidebarStyle,
    extra: sidebarFooter,
    isRatioMode: layoutMode === 'ratio',
    containerSelector: bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarContainerSelector,
    mode: mode,
    direction: direction,
    containerSize: containerSize,
    responsiveClsComputed: responsiveClsComputed
  }, bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.sidebarSlot) : null;

  /** 根据 contentOrder 决定渲染顺序 */
  var orderedChildren = useMemo(function () {
    if (contentOrder === 'sidebar-first') {
      return [sidebarComponent, contentComponent].filter(Boolean);
    }
    return [contentComponent, sidebarComponent].filter(Boolean);
  }, [contentOrder, contentComponent, sidebarComponent]);
  return /*#__PURE__*/React.createElement("div", {
    className: bodyCls,
    style: bodyProps === null || bodyProps === void 0 ? void 0 : bodyProps.style
  }, /*#__PURE__*/React.createElement(PisellLayout, {
    style: layoutStyle
  }, orderedChildren));
};
ProcedureBody.displayName = 'ProcedureBody';
export default ProcedureBody;