import{a as s}from"./chunk-7JKHQSWI.js";import"./chunk-42Y3PAPA.js";import"./chunk-SBZEOPXX.js";function c(){let n=null,e=null;return{promise:new Promise((o,i)=>{n=o,e=i}),resolve:n,reject:e}}var d=({createHost:n})=>({__type:"host",create:e=>({}),host:e=>{let{applicationId:t}=e??{},o=typeof window<"u"?window.wixEmbedsAPI:void 0,i=n(e),r=m();return{...i,apiBaseUrl:r,getMonitoringClient:o?.getMonitoringClientFunction?.(t),essentials:{language:typeof window<"u"?window.commonConfig?.language:void 0,locale:typeof window<"u"?window.commonConfig?.locale:void 0}}},auth:e=>{let t=typeof window<"u"?window.wixEmbedsAPI:void 0;e||(e=t?.getAccessTokenFunction?.());let o=!1,{resolve:i,promise:r}=c();return{getAuthHeaders:async()=>{if(!e&&o&&(e=await r),!e)throw new Error("Failed to resolve auth token");return{headers:{Authorization:await e()}}},getAccessTokenInjector:()=>(o=!0,u=>{i(u)})}}});function m(){let e=(typeof window<"u"?window.wixEmbedsAPI:void 0)?.getExternalBaseUrl?.();if(!e)return;let t=new URL(e);return t?.pathname&&t.pathname!=="/"?`${t.hostname}${t.pathname}`:t.hostname}var l=({clientSdk:n,applicationId:e})=>({invoke:async({namespace:t,method:o,args:i})=>{if(!n)throw new Error("Wix Site SDK only works in a Wix site environment. Learn more: https://dev.wix.com/docs/sdk/host-modules/site/introduction");return n.invoke({namespace:t,method:o,args:i,applicationId:e,accessToken:"accessToken"})},getAccessToken:()=>{throw new Error("Not implemented")},observeState:()=>({disconnect:()=>{}})});var w=function(n){let e=(typeof $wixContext<"u"?$wixContext.clientSdk:void 0)??n?.clientSdk??(typeof window<"u"?window?.clientSdk:void 0),{applicationId:t}=n||{};if(!t)throw new Error('"createHost" was called without a required field "applicationId"');return{channel:l({clientSdk:e,applicationId:t}),close:()=>{}}};var a=d({createHost:w});var v=n=>{let e=a.host({applicationId:n}),t=a.auth(),o=t.getAccessTokenInjector();return s({auth:t,host:e}).enableContext("module"),{injectGetAccessToken:o}},P=({host:n,auth:e})=>{s({host:n,auth:e}).enableContext("module")};export{v as enableClient,P as enablePanelClient};
//# sourceMappingURL=site.js.map