import{a as c,b as d}from"./chunk-2NFLSA4Y.js";var N="__NATIVE_FEDERATION__",R=globalThis;R[N]??={externals:new Map,remoteNamesToRemote:new Map,baseUrlToRemoteNames:new Map};var p=R[N],b=p.externals;function I(e){return`${e.packageName}@${e.version}`}function _(e){let t=I(e);return b.get(t)}function x(e,t){let o=I(e);b.set(o,t)}function T(e,t){return{imports:c(c({},e.imports),t.imports),scopes:c(c({},e.scopes),t.scopes)}}var M=p.remoteNamesToRemote,g=p.baseUrlToRemoteNames;function O(e,t){M.set(e,t),g.set(t.baseUrl,e)}function P(e){return g.get(e)}function U(e){return g.has(e)}function v(e){return M.get(e)}var y=globalThis,f;function j(){if(f===void 0&&(f=null,y.trustedTypes))try{f=y.trustedTypes.createPolicy("native-federation",{createHTML:e=>e,createScript:e=>e,createScriptURL:e=>e})}catch{}return f}function w(e){return j()?.createScript(e)??e}function F(e){document.head.appendChild(Object.assign(document.createElement("script"),{type:w("importmap-shim"),textContent:w(JSON.stringify(e))}))}function h(e){let t=e.split("/");return t.pop(),t.join("/")}function m(e,t){for(;e.endsWith("/");)e=e.substring(0,e.length-1);return t.startsWith("./")&&(t=t.substring(2,t.length)),`${e}/${t}`}var S=(function(e){return e.COMPLETED="federation-rebuild-complete",e.ERROR="federation-rebuild-error",e.CANCELLED="federation-rebuild-cancelled",e})(S||{});function A(e){let t=new EventSource(e);t.onmessage=function(o){JSON.parse(o.data).type===S.COMPLETED&&(console.log("[Federation] Rebuild completed, reloading..."),window.location.reload())},t.onerror=function(o){console.warn("[Federation] SSE connection error:",o)}}async function X(e={},t){let o=t?.cacheTag?`?t=${t.cacheTag}`:"",r=typeof e=="string"?await D(e+o):e,n="./";t?.deployUrl&&(t.deployUrl.endsWith("/")?n=t.deployUrl:n=`${t.deployUrl}/`);let s=await k(`${n}remoteEntry.json${o}`),a=await B(s,n),i=await K(r,c({throwIfRemoteNotFound:!1},t)),l=T(a,i);return F(l),l}async function D(e){return await fetch(e).then(o=>o.json())}function L(e,t){if(!t)return e;let o=e.includes("?")?"&":"?";return`${e}${o}t=${t}`}function W(e,t,o,r){let n=`Error loading remote entry for ${e} from file ${t}`;if(o.throwIfRemoteNotFound)throw new Error(n);return console.error(n),console.error(r),null}async function K(e,t={throwIfRemoteNotFound:!1}){let o=Object.entries(e).map(async([s,a])=>{try{let i=L(a,t.cacheTag);return await $(i,s)}catch(i){return W(s,a,t,i)}});return(await Promise.all(o)).reduce((s,a)=>a?T(s,a):s,{imports:{},scopes:{}})}async function $(e,t){let o=h(e),r=await k(e);t||(t=r.name),r.buildNotificationsEndpoint&&A(o+r.buildNotificationsEndpoint);let n=V(r,t,o);return O(t,d(c({},r),{baseUrl:o})),n}function V(e,t,o){let r=q(e,t,o),n=z(e,o);return{imports:r,scopes:n}}async function k(e){return await fetch(e).then(o=>o.json())}function z(e,t){let o={},r={};for(let n of e.shared){let s=_(n)??m(t,n.outFileName);x(n,s),r[n.packageName]=s}return o[t+"/"]=r,o}function q(e,t,o){let r={};for(let n of e.exposes){let s=m(t,n.key),a=m(o,n.outFileName);r[s]=a}return r}async function B(e,t="./"){let o=e.shared.reduce((r,n)=>d(c({},r),{[n.packageName]:t+n.outFileName}),{});for(let r of e.shared)x(r,t+r.outFileName);return{imports:o,scopes:{}}}async function Y(e,t){let o=Q(e,t);await G(o);let r=J(o),n=v(r),s=o.fallback,a=n?"":"unknown remote "+r;if(!n&&!s)throw new Error(a);if(!n)return E(a),Promise.resolve(s);let i=n.exposes.find(u=>u.key===o.exposedModule),l=i?"":`Unknown exposed module ${o.exposedModule} in remote ${r}`;if(!i&&!s)throw new Error(l);if(!i)return E(l),Promise.resolve(s);let C=m(n.baseUrl,i.outFileName);try{return H(C)}catch(u){if(s)return console.error("error loading remote module",u),s;throw u}}function H(e){return typeof importShim<"u"?importShim(e):import(e)}function J(e){let t;if(e.remoteName)t=e.remoteName;else if(e.remoteEntry){let o=h(e.remoteEntry);t=P(o)}else throw new Error("unexpected arguments: Please pass remoteName or remoteEntry");if(!t)throw new Error("unknown remoteName "+t);return t}async function G(e){if(e.remoteEntry&&!U(h(e.remoteEntry))){let t=await $(e.remoteEntry);F(t)}}function Q(e,t){let o;if(typeof e=="string"&&t)o={remoteName:e,exposedModule:t};else if(typeof e=="object"&&!t)o=e;else throw new Error("unexpected arguments: please pass options or a remoteName/exposedModule-pair");return o}function E(e){typeof window<"u"&&console.error(e)}export{X as a,Y as b};
