import { jsx as l } from "react/jsx-runtime";
import { a as u } from "./index.CfQlFjZU.js";
import { useRef as d, useEffect as a } from "react";
const p = (e, t) => !e || !e.profileInfo || !e.profileInfo.localization ? null : e.profileInfo.localization.find((n) => n.id === t) || e.profileInfo.localization[0], y = (e) => {
  const t = e.name || e.title;
  return {
    ...e,
    title: t,
    name: t
  };
}, P = (e, t) => {
  const n = p(e, t);
  return {
    ...e.profileInfo,
    ...n,
    themeColor: n?.theme,
    socialProfileLinks: n?.profileLinks,
    privacyPolicyName: n?.displayName || e.profileInfo.name,
    modules: e.modules.map(y)
  };
}, h = ({
  url: e,
  profile: t,
  localizationId: n,
  previewId: c,
  className: f
}) => {
  const o = d(null), i = (s, r) => {
    if (!o.current || !s)
      return;
    const m = {
      type: "komi_talent_profile",
      data: {
        talentProfile: P(s, r),
        previewId: c
      }
    };
    o.current.contentWindow?.postMessage(JSON.stringify(m), "*");
  };
  return a(() => {
    i(t, n);
  }, [t, n]), a(() => {
    const s = () => {
      i(t, n);
    }, r = o.current;
    return r && r.addEventListener("load", s), () => {
      r && r.removeEventListener("load", s);
    };
  }, [o, t, n]), {
    url: e,
    ref: o,
    className: f
  };
}, v = ({ url: e, ref: t, className: n }) => /* @__PURE__ */ l(
  "iframe",
  {
    ref: t,
    src: e,
    frameBorder: "0",
    style: {
      width: "100%",
      height: "100%"
    },
    className: n
  }
), I = u(v, h);
export {
  I as P
};
