import { useEffect as c } from "react";
import { e as s } from "./index5.js";
import { A as v } from "./sl-types.js";
let o = [], r = 0;
const u = 4, d = /* @__NO_SIDE_EFFECTS__ */ (i) => {
  let e = [], t = {
    get() {
      return t.lc || t.listen(() => {
      })(), t.value;
    },
    lc: 0,
    listen(n) {
      return t.lc = e.push(n), () => {
        for (let a = r + u; a < o.length; )
          o[a] === n ? o.splice(a, u) : a += u;
        let l = e.indexOf(n);
        ~l && (e.splice(l, 1), --t.lc || t.off());
      };
    },
    notify(n, l) {
      let a = !o.length;
      for (let f of e)
        o.push(f, t.value, n, l);
      if (a) {
        for (r = 0; r < o.length; r += u)
          o[r](
            o[r + 1],
            o[r + 2],
            o[r + 3]
          );
        o.length = 0;
      }
    },
    /* It will be called on last listener unsubscribing.
       We will redefine it in onMount and onStop. */
    off() {
    },
    set(n) {
      let l = t.value;
      l !== n && (t.value = n, t.notify(l));
    },
    subscribe(n) {
      let l = t.listen(n);
      return n(t.value), l;
    },
    value: i
  };
  return t;
}, b = /* @__NO_SIDE_EFFECTS__ */ (i = {}) => {
  let e = /* @__PURE__ */ d(i);
  return e.setKey = function(t, n) {
    let l = e.value;
    typeof n > "u" && t in e.value ? (e.value = { ...e.value }, delete e.value[t], e.notify(l, t)) : e.value[t] !== n && (e.value = {
      ...e.value,
      [t]: n
    }, e.notify(l, t));
  }, e;
}, y = (i) => [(e) => (...t) => (i && s.emit(i == null ? void 0 : i.type, i), e ? e(t) : null)], h = (i) => {
  const e = i.target;
  e instanceof HTMLAnchorElement && e.target === "_blank" && e.getAttribute("data-a") === "web-link" && s.emit("poll", {
    action: "navigated",
    payload: {}
  }), e instanceof Element && e.getAttribute("data-a") === "intr" && s.emit("interactions", {
    action: "tap",
    payload: {}
  });
}, A = (i, e) => {
  const t = window.innerWidth < v.xl;
  c(() => {
    const n = t && e.useDomNode ? document : i.current, l = (a) => {
      e.listener(a, i);
    };
    return e.enabled && (n == null || n.addEventListener(e.event, l)), () => {
      n == null || n.removeEventListener(e.event, l);
    };
  }, [t, e.enabled, e.listener]);
};
export {
  h as A,
  d as a,
  A as b,
  y as c,
  b as f
};
