"use client";
import * as React from "react";
const TTL_MS = 12e4;
let current = null;
const emitter = new EventTarget();
function now() {
  return typeof performance !== "undefined" && performance.now ? Math.round(performance.timeOrigin + performance.now()) : Date.now();
}
function subscribe(listener) {
  const wrapped = () => listener();
  emitter.addEventListener("change", wrapped);
  return () => emitter.removeEventListener("change", wrapped);
}
function emit() {
  emitter.dispatchEvent(new Event("change"));
}
function normalizeInput(input) {
  const label = typeof input.entityLabel === "string" && input.entityLabel.trim() ? input.entityLabel.trim() : input.entity;
  return {
    entity: input.entity,
    entityLabel: label,
    baseCount: typeof input.baseCount === "number" ? input.baseCount : null,
    indexedCount: typeof input.indexedCount === "number" ? input.indexedCount : null,
    scope: input.scope === "global" ? "global" : "scoped",
    receivedAt: now()
  };
}
function prune(stale) {
  if (!stale) return null;
  const age = now() - stale.receivedAt;
  if (!Number.isFinite(age) || age > TTL_MS) return null;
  return stale;
}
function getSnapshot() {
  current = prune(current);
  return current;
}
function usePartialIndexWarning() {
  return React.useSyncExternalStore(
    subscribe,
    () => getSnapshot(),
    () => null
  );
}
function pushPartialIndexWarning(input) {
  if (typeof window === "undefined") return;
  if (!input.entity) return;
  const next = normalizeInput(input);
  current = next;
  emit();
}
function dismissPartialIndexWarning() {
  if (typeof window === "undefined") return;
  current = null;
  emit();
}
export {
  dismissPartialIndexWarning,
  pushPartialIndexWarning,
  usePartialIndexWarning
};
//# sourceMappingURL=store.js.map
