import { jsx as o, jsxs as i } from "@emotion/react/jsx-runtime";
import { useMemo as E, Children as h, isValidElement as d } from "react";
import w from "clsx";
import { useFlagsPresent as P, CommonFlags as A } from "@m4l/core";
import { StepperRootStyled as R, ContentSectionStyled as g } from "./slots/StepperSlot.js";
import { getComponentSlotRoot as y } from "../../utils/getComponentSlotRoot.js";
import { STEPPER_PREFIX_NAME as x } from "./constants.js";
import { StepArea as z } from "./subcomponents/StepArea/index.js";
import { ContentArea as N } from "./subcomponents/ContentArea/index.js";
import { StepperProvider as _ } from "./store/StepperContext/index.js";
import { useComponentSize as j } from "../../hooks/useComponentSize/index.js";
import { StepperFooter as D } from "./subcomponents/StepperFooter/index.js";
import { StepperContent as I } from "./subcomponents/StepperContent/index.js";
function J(r) {
  const { orientation: l, size: S, children: t, className: f } = r, { currentSize: c } = j(S), a = {
    size: c,
    orientation: l
  }, u = y(x), { stepperFooter: C, stepperContent: F } = E(() => {
    let n = null, p = null, s = 0, m = 0;
    return t && h.forEach(t, (e) => {
      if (d(e))
        if (e.type === D) {
          if (s++, s > 1)
            throw new Error(
              "Stepper: Solo se permite un componente StepperFooter. Se encontraron múltiples StepperFooter."
            );
          n = e;
        } else if (e.type === I) {
          if (m++, m > 1)
            throw new Error(
              "Stepper: Solo se permite un componente StepperContent. Se encontraron múltiples StepperContent."
            );
          p = e;
        } else
          throw new Error(
            "Stepper: Solo se permiten componentes StepperContent y StepperFooter como hijos."
          );
    }), { stepperFooter: n, stepperContent: p };
  }, [t]);
  return P([A.FLAG_DICTIONARY_LOADED]) ? /* @__PURE__ */ o(_, { ...r, children: /* @__PURE__ */ i(
    R,
    {
      className: w(u, f),
      "data-testid": "stepper-root",
      children: [
        /* @__PURE__ */ i(g, { ownerState: a, children: [
          /* @__PURE__ */ o(z, {}),
          /* @__PURE__ */ o(N, { children: F })
        ] }),
        C
      ]
    }
  ) }) : null;
}
export {
  J as Stepper
};
