import { _defineProperty } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js";
import { createContext, useContext, useEffect, useRef, useState } from "react";
//#region src/components/ticketBooking/miniRedux.tsx
var Store = class {
	constructor(initialState) {
		_defineProperty(this, "state", void 0);
		_defineProperty(this, "listeners", void 0);
		this.state = initialState;
		this.listeners = /* @__PURE__ */ new Set();
	}
	getState() {
		return this.state;
	}
	setState(partialState, callback) {
		if (typeof partialState === "function") Object.assign(this.state, partialState(this.state));
		else Object.assign(this.state, partialState);
		this.notify();
		if (callback) callback(this.state);
	}
	subscribe(listener) {
		this.listeners.add(listener);
		return () => {
			this.listeners.delete(listener);
		};
	}
	notify() {
		for (const listener of this.listeners) listener();
	}
	getLatestState() {
		return this.state;
	}
};
const StoreContext = createContext(null);
function Provider({ store, children }) {
	return /* @__PURE__ */ React.createElement(StoreContext.Provider, { value: store }, children);
}
function createStore(initialState) {
	return new Store(initialState);
}
function useStore() {
	const store = useContext(StoreContext);
	if (!store) throw new Error("useStore must be used within a Provider");
	const stateRef = useRef(store.getState());
	const [, forceUpdate] = useState({});
	useEffect(() => {
		return store.subscribe(() => {
			stateRef.current = store.getState();
			forceUpdate({});
		});
	}, [store]);
	return [stateRef.current, store.setState.bind(store)];
}
//#endregion
export { Provider, createStore, useStore };
