export const __rspack_esm_id=20937;export const __rspack_esm_ids=[20937];export const __webpack_modules__={42800(e,t,n){n.d(t,{createExternalAuth:()=>d});n(33110);var s=n(20081);class a{async attach(){window.externalBus=e=>this.receiveMessage(e),window.addEventListener("connection-status",e=>this.fireMessage({type:"connection-status",payload:{event:e.detail}})),this.config=await this.sendMessage({type:"config/get"})}addCommandHandler(e){this._commandHandler=e}sendMessage(e){const t=++this.msgId;return e.id=t,this._sendExternal(e),new Promise((e,n)=>{this.commands[t]={resolve:e,reject:n}})}fireMessage(e){e.id||(e.id=++this.msgId),this._sendExternal(e)}receiveMessage(e){if("command"===e.type){if(!this._commandHandler||!this._commandHandler(e)){let t,n;this._commandHandler?(t="not_ready",n="Command handler not ready"):(t="unknown_command",n=`Unknown command ${e.command}`),console.warn(n,e),this.fireMessage({id:e.id,type:"result",success:!1,error:{code:t,message:n}})}return}const t=this.commands[e.id];t?"result"===e.type&&(e.success?t.resolve(e.result):t.reject(e.error)):console.warn("Received unknown msg ID",e.id)}_sendExternal(e){window.externalAppV2?window.externalAppV2.postMessage(JSON.stringify({type:"externalBus",payload:e})):window.externalApp?window.externalApp.externalBus(JSON.stringify(e)):window.webkit.messageHandlers.externalBus.postMessage(e)}constructor(){this.commands={},this.msgId=0}}const r="externalAuthSetToken",o="externalAuthRevokeToken";if(!window.externalApp&&!window.webkit&&!window.externalAppV2)throw new Error("External auth requires either externalApp, externalAppV2, or webkit defined on Window object.");class i extends s.Nj{async refreshAccessToken(e){if(this._tokenCallbackPromise&&!e)try{return void await this._tokenCallbackPromise}catch(e){this._tokenCallbackPromise=void 0}const t={callback:r};e&&(t.force=!0),this._tokenCallbackPromise=new Promise((e,t)=>{window[r]=(n,s)=>n?e(s):t(s)}),await Promise.resolve(),window.externalAppV2?window.externalAppV2.postMessage(JSON.stringify({type:"getExternalAuth",payload:t})):window.externalApp?window.externalApp.getExternalAuth(JSON.stringify(t)):window.webkit.messageHandlers.getExternalAuth.postMessage(t);const n=await this._tokenCallbackPromise;this.data.access_token=n.access_token,this.data.expires=1e3*n.expires_in+Date.now(),this._tokenCallbackPromise=void 0}async revoke(){const e={callback:o},t=new Promise((e,t)=>{window[o]=(n,s)=>n?e(s):t(s)});await Promise.resolve(),window.externalAppV2?window.externalAppV2.postMessage(JSON.stringify({type:"revokeExternalAuth",payload:e})):window.externalApp?window.externalApp.revokeExternalAuth(JSON.stringify(e)):window.webkit.messageHandlers.revokeExternalAuth.postMessage(e),await t}constructor(e){super({hassUrl:e,clientId:"",refresh_token:"",access_token:"",expires_in:0,expires:0})}}const d=async e=>{const t=new i(e);return(window.externalAppV2||window.externalApp?.externalBus||window.webkit&&window.webkit.messageHandlers.externalBus)&&(t.external=new a,await t.external.attach()),t}}};
//# sourceMappingURL=20937.134b3e5947e43948.js.map