import { createStore as m } from "../../../../zustand@4.5.5_@types_react@18.3.3_immer@10.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/zustand/esm/vanilla.js";
var p = (u, r, l) => (a, t) => ({
  pastStates: l?.pastStates || [],
  futureStates: l?.futureStates || [],
  undo: (S = 1) => {
    if (t().pastStates.length) {
      const c = l?.partialize?.(r()) || r(), s = t().pastStates.splice(-S, S), e = s.shift();
      u(e), a({
        pastStates: t().pastStates,
        futureStates: t().futureStates.concat(
          l?.diff?.(c, e) || c,
          s.reverse()
        )
      });
    }
  },
  redo: (S = 1) => {
    if (t().futureStates.length) {
      const c = l?.partialize?.(r()) || r(), s = t().futureStates.splice(-S, S), e = s.shift();
      u(e), a({
        pastStates: t().pastStates.concat(
          l?.diff?.(c, e) || c,
          s.reverse()
        ),
        futureStates: t().futureStates
      });
    }
  },
  clear: () => a({ pastStates: [], futureStates: [] }),
  isTracking: !0,
  pause: () => a({ isTracking: !1 }),
  resume: () => a({ isTracking: !0 }),
  setOnSave: (S) => a({ _onSave: S }),
  // Internal properties
  _onSave: l?.onSave,
  _handleSet: (S, c, s, e) => {
    l?.limit && t().pastStates.length >= l?.limit && t().pastStates.shift(), t()._onSave?.(S, s), a({
      pastStates: t().pastStates.concat(e || S),
      futureStates: []
    });
  }
}), h = (u, r) => (f, a, t) => {
  t.temporal = m(
    r?.wrapTemporal?.(p(f, a, r)) || p(f, a, r)
  );
  const S = r?.handleSet?.(
    t.temporal.getState()._handleSet
  ) || t.temporal.getState()._handleSet, c = (e) => {
    if (!t.temporal.getState().isTracking) return;
    const n = r?.partialize?.(a()) || a(), i = r?.diff?.(e, n);
    // If the user has provided a diff function but nothing has been changed, deltaState will be null
    i === null || // If the user has provided an equality function, use it
    r?.equality?.(e, n) || S(
      e,
      void 0,
      n,
      i
    );
  }, s = t.setState;
  return t.setState = (...e) => {
    const n = r?.partialize?.(a()) || a();
    s(...e), c(n);
  }, u(
    // Modify the set function to call the userlandSet function
    (...e) => {
      const n = r?.partialize?.(a()) || a();
      f(...e), c(n);
    },
    a,
    t
  );
};
export {
  h as temporal
};
//# sourceMappingURL=index.js.map
