import { useEffect as d } from "react";
import { isEmpty as p, noop as u } from "es-toolkit/compat";
const l = (o, r) => {
  const i = (s) => {
    const e = document.referrer;
    e && window.parent.postMessage(s, e);
  }, a = (s, e) => {
    if (!e || p(e))
      return;
    [...Array.isArray(e) ? [...e] : [e]].forEach((f) => {
      const t = f.contentWindow;
      t && t.postMessage(s, "*");
    });
  }, c = (s, e) => {
    const n = s.data.type;
    n && n.startsWith(o) && e(s.data);
  };
  return d(() => {
    const s = (e) => c(e, r || u);
    return window.addEventListener("message", s, !1), () => window.removeEventListener("message", s, !1);
  }, []), {
    sendMessageToParent: i,
    sendMessageToWidget: a
  };
};
export {
  l as default
};
//# sourceMappingURL=usePostMessage.js.map
