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/ticketBooking/miniRedux.tsx
var miniRedux_exports = {};
__export(miniRedux_exports, {
  Provider: () => Provider,
  createStore: () => createStore,
  useStore: () => useStore
});
module.exports = __toCommonJS(miniRedux_exports);
var import_react = require("react");
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_useSync = require("./hooks/useSync");
var Store = class {
  state;
  listeners;
  constructor(initialState) {
    this.state = initialState;
    this.listeners = /* @__PURE__ */ new Set();
  }
  getState() {
    return this.state;
  }
  setState(partialState, callback, key) {
    console.log("partialState", partialState);
    if (typeof partialState === "function") {
      Object.assign(this.state, partialState(this.state));
    } else {
      Object.assign(this.state, partialState);
    }
    this.notify(key);
    if (callback) {
      callback(this.state);
    }
  }
  subscribe(listener) {
    this.listeners.add(listener);
    return () => {
      this.listeners.delete(listener);
    };
  }
  notify(key) {
    for (const listener of this.listeners) {
      listener(key);
    }
  }
  // 添加获取最新状态的方法
  getLatestState() {
    return this.state;
  }
};
var StoreContext = (0, import_react.createContext)(null);
function Provider({
  store,
  children
}) {
  return /* @__PURE__ */ React.createElement(StoreContext.Provider, { value: store }, children);
}
function createStore(initialState) {
  return new Store(initialState);
}
function useStore() {
  var _a, _b, _c, _d, _e, _f;
  const context = (0, import_useEngineContext.default)();
  const app = (_c = (_b = (_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp) == null ? void 0 : _c.call(_b);
  const { runtime } = ((_f = (_e = (_d = app == null ? void 0 : app.getPlugin) == null ? void 0 : _d.call(app, "unifiedCommunication")) == null ? void 0 : _e.useRuntime) == null ? void 0 : _f.call(_e)) || {};
  const store = (0, import_react.useContext)(StoreContext);
  if (!store) {
    throw new Error("useStore must be used within a Provider");
  }
  const stateRef = (0, import_react.useRef)(store.getState());
  const [, forceUpdate] = (0, import_react.useState)({});
  (0, import_react.useEffect)(() => {
    const unsubscribe = store.subscribe(() => {
      stateRef.current = store.getState();
      forceUpdate({});
    });
    return unsubscribe;
  }, [store, runtime]);
  (0, import_useSync.useSync)(store);
  (0, import_react.useEffect)(() => {
    window._bookingStore = store;
  }, []);
  return [stateRef.current, store.setState.bind(store)];
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Provider,
  createStore,
  useStore
});
