import React from "react";

//#region node_modules/zustand/esm/vanilla.mjs
const createStoreImpl = (createState) => {
	let state;
	const listeners = /* @__PURE__ */ new Set();
	const setState = (partial, replace) => {
		const nextState = typeof partial === "function" ? partial(state) : partial;
		if (!Object.is(nextState, state)) {
			const previousState = state;
			state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
			listeners.forEach((listener) => listener(state, previousState));
		}
	};
	const getState = () => state;
	const getInitialState = () => initialState;
	const subscribe = (listener) => {
		listeners.add(listener);
		return () => listeners.delete(listener);
	};
	const api = {
		setState,
		getState,
		getInitialState,
		subscribe
	};
	const initialState = state = createState(setState, getState, api);
	return api;
};
const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;

//#endregion
//#region node_modules/zustand/esm/react.mjs
const identity = (arg) => arg;
function useStore(api, selector = identity) {
	const slice = React.useSyncExternalStore(api.subscribe, () => selector(api.getState()), () => selector(api.getInitialState()));
	React.useDebugValue(slice);
	return slice;
}
const createImpl = (createState) => {
	const api = createStore(createState);
	const useBoundStore = (selector) => useStore(api, selector);
	Object.assign(useBoundStore, api);
	return useBoundStore;
};
const create = (createState) => createState ? createImpl(createState) : createImpl;

//#endregion
//#region node_modules/zustand/esm/middleware.mjs
const subscribeWithSelectorImpl = (fn) => (set, get, api) => {
	const origSubscribe = api.subscribe;
	api.subscribe = (selector, optListener, options) => {
		let listener = selector;
		if (optListener) {
			const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
			let currentSlice = selector(api.getState());
			listener = (state) => {
				const nextSlice = selector(state);
				if (!equalityFn(currentSlice, nextSlice)) {
					const previousSlice = currentSlice;
					optListener(currentSlice = nextSlice, previousSlice);
				}
			};
			if (options == null ? void 0 : options.fireImmediately) optListener(currentSlice, currentSlice);
		}
		return origSubscribe(listener);
	};
	return fn(set, get, api);
};
const subscribeWithSelector = subscribeWithSelectorImpl;

//#endregion
//#region node_modules/zustand/esm/vanilla/shallow.mjs
const isIterable = (obj) => Symbol.iterator in obj;
const hasIterableEntries = (value) => "entries" in value;
const compareEntries = (valueA, valueB) => {
	const mapA = valueA instanceof Map ? valueA : new Map(valueA.entries());
	const mapB = valueB instanceof Map ? valueB : new Map(valueB.entries());
	if (mapA.size !== mapB.size) return false;
	for (const [key, value] of mapA) if (!Object.is(value, mapB.get(key))) return false;
	return true;
};
const compareIterables = (valueA, valueB) => {
	const iteratorA = valueA[Symbol.iterator]();
	const iteratorB = valueB[Symbol.iterator]();
	let nextA = iteratorA.next();
	let nextB = iteratorB.next();
	while (!nextA.done && !nextB.done) {
		if (!Object.is(nextA.value, nextB.value)) return false;
		nextA = iteratorA.next();
		nextB = iteratorB.next();
	}
	return !!nextA.done && !!nextB.done;
};
function shallow(valueA, valueB) {
	if (Object.is(valueA, valueB)) return true;
	if (typeof valueA !== "object" || valueA === null || typeof valueB !== "object" || valueB === null) return false;
	if (!isIterable(valueA) || !isIterable(valueB)) return compareEntries({ entries: () => Object.entries(valueA) }, { entries: () => Object.entries(valueB) });
	if (hasIterableEntries(valueA) && hasIterableEntries(valueB)) return compareEntries(valueA, valueB);
	return compareIterables(valueA, valueB);
}

//#endregion
export { subscribeWithSelector as n, create as r, shallow as t };