"use client";
import { useEffect, useRef } from "react";
import { matchesPattern } from "../../backend/injection/useAppEvent.js";
const PORTAL_EVENT_DOM_NAME = "om:portal-event";
function usePortalAppEvent(eventPattern, handler, deps = []) {
  const handlerRef = useRef(handler);
  handlerRef.current = handler;
  useEffect(() => {
    const listener = (e) => {
      const detail = e.detail;
      if (!detail || typeof detail.id !== "string") return;
      if (matchesPattern(eventPattern, detail.id)) {
        handlerRef.current(detail);
      }
    };
    window.addEventListener(PORTAL_EVENT_DOM_NAME, listener);
    return () => {
      window.removeEventListener(PORTAL_EVENT_DOM_NAME, listener);
    };
  }, [eventPattern, ...deps]);
}
export {
  PORTAL_EVENT_DOM_NAME,
  usePortalAppEvent
};
//# sourceMappingURL=usePortalAppEvent.js.map
