import { useId as a } from "react";
import { DefaultMap as n } from "../utils/default-map.js";
import { createStore as p } from "../utils/store.js";
import { useIsoMorphicEffect as u } from "./use-iso-morphic-effect.js";
import { useStore as h } from "./use-store.js";
let l = new n(() => p(() => [], { ADD(t) {
  return this.includes(t) ? this : [...this, t];
}, REMOVE(t) {
  let r = this.indexOf(t);
  if (r === -1) return this;
  let e = this.slice();
  return e.splice(r, 1), e;
} }));
function x(t, r) {
  let e = l.get(r), i = a(), f = h(e);
  if (u(() => {
    if (t) return e.dispatch("ADD", i), () => e.dispatch("REMOVE", i);
  }, [e, t]), !t) return !1;
  let s = f.indexOf(i), o = f.length;
  return s === -1 && (s = o, o += 1), s === o - 1;
}
export {
  x as useIsTopLayer
};
