var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/PisellProcedure/components/ProcedureFooter.tsx
var ProcedureFooter_exports = {};
__export(ProcedureFooter_exports, {
  default: () => ProcedureFooter_default
});
module.exports = __toCommonJS(ProcedureFooter_exports);
var import_react = __toESM(require("react"));
var import_footer = __toESM(require("../../pisellLayout/footer"));
var import_pisellModal = __toESM(require("../../pisellModal"));
var import_FooterActions = __toESM(require("./FooterActions"));
var import_utils = require("../utils");
var ProcedureFooter = ({
  footerProps,
  position,
  className,
  isGlobal = false,
  sidebarContent,
  summaryModalOpen = false,
  onOpenSummaryModal,
  onCloseSummaryModal,
  goPrev,
  goNext,
  mode = "page"
}) => {
  const footerCls = (0, import_react.useMemo)(() => {
    return (0, import_utils.mergeClassNames)(
      "pisell-procedure-footer",
      className,
      footerProps == null ? void 0 : footerProps.className,
      (0, import_utils.modifierClassName)("pisell-procedure-footer", position)
    );
  }, [className, footerProps == null ? void 0 : footerProps.className, position]);
  const processedActions = (0, import_react.useMemo)(() => {
    const actions = footerProps == null ? void 0 : footerProps.actions;
    if (!actions) return null;
    const childrenArray = import_react.Children.toArray(actions);
    if (childrenArray.length === 0) return null;
    return import_react.Children.map(actions, (child, index) => {
      if (!(0, import_react.isValidElement)(child)) return child;
      const childProps = child.props;
      const dataAction = childProps == null ? void 0 : childProps["data-action"];
      const originalOnClick = childProps == null ? void 0 : childProps.onClick;
      let injectedAction;
      if (dataAction === "prev") {
        injectedAction = goPrev;
      } else if (dataAction === "next") {
        injectedAction = goNext;
      }
      if (injectedAction) {
        return (0, import_react.cloneElement)(child, {
          onClick: (...args) => {
            originalOnClick == null ? void 0 : originalOnClick(...args);
            injectedAction == null ? void 0 : injectedAction();
          }
        });
      }
      return child;
    });
  }, [footerProps == null ? void 0 : footerProps.actions, goPrev, goNext]);
  const actionsContent = processedActions;
  const wrappedSummaryButton = (0, import_react.useMemo)(() => {
    var _a;
    const button = footerProps == null ? void 0 : footerProps.summaryButton;
    if (!button || !(0, import_react.isValidElement)(button)) return button;
    const originalOnClick = (_a = button.props) == null ? void 0 : _a.onClick;
    return (0, import_react.cloneElement)(button, {
      onClick: (e) => {
        if (typeof originalOnClick === "function") {
          originalOnClick(e);
        }
        onOpenSummaryModal == null ? void 0 : onOpenSummaryModal();
      }
    });
  }, [footerProps == null ? void 0 : footerProps.summaryButton, onOpenSummaryModal]);
  const footerContent = (0, import_react.useMemo)(() => {
    const hasSummaryButton = mode === "modal" ? false : !!wrappedSummaryButton;
    const hasLeftSlot = (footerProps == null ? void 0 : footerProps.leftSlot) !== void 0 && (footerProps == null ? void 0 : footerProps.leftSlot) !== null;
    const hasActions = actionsContent !== null && actionsContent !== void 0;
    if (!hasSummaryButton && !hasLeftSlot && !hasActions) {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, hasSummaryButton && wrappedSummaryButton && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-procedure-footer__summary" }, wrappedSummaryButton), (hasLeftSlot || hasActions) && ((footerProps == null ? void 0 : footerProps.enableOverflow) !== false ? /* @__PURE__ */ import_react.default.createElement(
      import_FooterActions.default,
      {
        leftSlot: footerProps == null ? void 0 : footerProps.leftSlot,
        moreText: footerProps == null ? void 0 : footerProps.moreText
      },
      actionsContent
    ) : /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-procedure-footer__content" }, (footerProps == null ? void 0 : footerProps.leftSlot) && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-procedure-footer__left" }, footerProps.leftSlot), hasActions && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-procedure-footer__actions" }, actionsContent))));
  }, [
    mode,
    wrappedSummaryButton,
    footerProps == null ? void 0 : footerProps.enableOverflow,
    footerProps == null ? void 0 : footerProps.leftSlot,
    footerProps == null ? void 0 : footerProps.moreText,
    actionsContent
  ]);
  const summaryModal = (0, import_react.useMemo)(() => {
    if (!(footerProps == null ? void 0 : footerProps.summaryButton) || !sidebarContent) return null;
    return /* @__PURE__ */ import_react.default.createElement(
      import_pisellModal.default,
      {
        open: summaryModalOpen,
        onCancel: onCloseSummaryModal,
        title: (footerProps == null ? void 0 : footerProps.summaryModalTitle) || "详情",
        platform: "h5",
        footer: null,
        destroyOnClose: true
      },
      sidebarContent
    );
  }, [
    footerProps == null ? void 0 : footerProps.summaryButton,
    footerProps == null ? void 0 : footerProps.summaryModalTitle,
    sidebarContent,
    summaryModalOpen,
    onCloseSummaryModal
  ]);
  if (!footerContent) {
    return null;
  }
  if (isGlobal) {
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_footer.default, { className: footerCls, style: footerProps == null ? void 0 : footerProps.style }, footerContent), summaryModal);
  }
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: footerCls, style: footerProps == null ? void 0 : footerProps.style }, footerContent), summaryModal);
};
ProcedureFooter.displayName = "ProcedureFooter";
var ProcedureFooter_default = ProcedureFooter;
