"use strict";
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);
var FlowStepper_exports = {};
__export(FlowStepper_exports, {
  default: () => FlowStepper_default
});
module.exports = __toCommonJS(FlowStepper_exports);
var import_react = __toESM(require("react"));
var import_react_is = require("react-is");
var import_Flex = __toESM(require("../../layout/Flex"));
var import__ = require("..");
function FlowStepper({
  activeIndex,
  header,
  renderStepHeader,
  footer,
  renderStepFooter,
  extraProps,
  extraContainerProps,
  extraStepperProps,
  extraStepperContainerProps,
  extraChildrenContainerProps,
  renderChildren,
  children
}) {
  const { steps, innerContents, stepFooter, stepHeader } = import_react.default.Children.toArray(children).reduce(
    (acc, child, idx) => {
      const index = ((0, import_react_is.isElement)(child) && child.props.index) ?? idx;
      const label = (0, import_react_is.isElement)(child) && child.props.label;
      const hidden = (0, import_react_is.isElement)(child) && child.props.hidden;
      const stepHeader2 = (0, import_react_is.isElement)(child) && child.props.header;
      const stepFooter2 = (0, import_react_is.isElement)(child) && child.props.footer;
      if (label && !hidden) {
        acc.steps[index] = label;
      }
      if (index === activeIndex) {
        acc.innerContents = child;
        acc.stepFooter = stepFooter2;
        acc.stepHeader = stepHeader2;
      }
      return acc;
    },
    {
      steps: [],
      innerContents: null,
      stepHeader: null,
      stepFooter: null
    }
  );
  const renderArgs = { ...extraProps, activeIndex, stepsLength: steps.length };
  function getSectionContents(renderFunc, stepSection, renderStepFunc) {
    return stepSection ? renderStepFunc ? renderStepFunc({ ...renderArgs, children: stepSection }) : stepSection : renderFunc && renderFunc(renderArgs);
  }
  return /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { flex: 1, flexDirection: "column", ...extraContainerProps }, getSectionContents(header, stepHeader, renderStepHeader), /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { my: 8, justifyContent: "center", ...extraStepperContainerProps }, /* @__PURE__ */ import_react.default.createElement(import__.Stepper, { activeIndex, steps, flex: 1, ...extraStepperProps })), /* @__PURE__ */ import_react.default.createElement(import_Flex.default, { flex: 1, flexDirection: "column", position: "relative", ...extraChildrenContainerProps }, renderChildren ? renderChildren({ ...renderArgs, children: innerContents }) : innerContents), getSectionContents(footer, stepFooter, renderStepFooter));
}
function Step({ children }) {
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
}
FlowStepper.Step = Step;
var FlowStepper_default = FlowStepper;
function FlowStepperIndexed(props) {
  const { activeKey, children, ...otherProps } = props;
  const activeIndex = import_react.default.Children.toArray(children).findIndex((child) => {
    const res = (0, import_react_is.isElement)(child) && child.props.itemKey === activeKey;
    return res;
  });
  return /* @__PURE__ */ import_react.default.createElement(FlowStepper, { ...otherProps, activeIndex }, children);
}
function IndexedStep({ children }) {
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, children);
}
FlowStepperIndexed.Step = IndexedStep;
FlowStepper.Indexed = FlowStepperIndexed;
//# sourceMappingURL=index.js.map
