import { jsx as y } from "@emotion/react/jsx-runtime";
import { createContext as m, useRef as S, useEffect as p } from "react";
import { createStepperStore as v } from "../StepperStore/index.js";
import { findNextVisibleValidStep as h } from "../../helpers/findNextVisibleValidStep/index.js";
const x = m(null), R = (l) => {
  const {
    storeId: f,
    storeDevtoolsEnabled: d,
    steps: n,
    visibleTitle: a = !0,
    indicatorType: o = "number",
    orientation: s = "horizontal",
    visibilityData: r,
    initialStepKey: g,
    children: b
  } = l, t = S(null), u = S(r);
  return t.current || (t.current = v(
    {
      storeId: f,
      steps: n,
      visibleTitle: a,
      ownerState: {},
      indicatorType: o,
      orientation: s,
      visibilityData: r,
      initialStepKey: g
    },
    d
  ), t.current.getState().actions.init(n)), p(() => {
    if (t.current) {
      const i = t.current.getState();
      i.visibleTitle !== a && t.current.setState((e) => ({
        ...e,
        visibleTitle: a
      })), i.orientation !== s && t.current.setState((e) => ({
        ...e,
        orientation: s
      })), i.indicatorType !== o && t.current.setState((e) => ({
        ...e,
        indicatorType: o
      })), i.visibilityData !== r && t.current.setState((e) => ({
        ...e,
        visibilityData: r
      }));
    }
  }, [a, s, o, r]), p(() => {
    if (t.current && n) {
      const i = t.current, e = i.getState();
      if (i.getState().actions.init(n, !0), r && JSON.stringify(u.current) !== JSON.stringify(r)) {
        const c = h(
          e.currentStep,
          n,
          {},
          r
        );
        c < n.length && c !== e.currentStep && (i.getState().actions.setCurrentStep(c), i.getState().actions.setStepValidationStatus(e.currentStep, !0));
      }
    }
    u.current = r;
  }, [n, r]), /* @__PURE__ */ y(x.Provider, { value: t.current, children: b });
};
export {
  x as StepperContext,
  R as StepperProvider
};
