import{proxyCustomElement as t,HTMLElement as e,createEvent as i,h as s,Host as n,transformTag as o}from"@stencil/core/internal/client";import{a,E as l}from"./auth.js";import{i as c}from"./i18next.js";import{d as h}from"./ezp-dialog2.js";import{d as p}from"./ezp-icon2.js";import{d as r}from"./ezp-icon-button2.js";import{d as u}from"./ezp-label2.js";import{d}from"./ezp-status2.js";import{d as m}from"./ezp-text-button2.js";const g=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.authCancel=i(this,"authCancel",7),this.authSuccess=i(this,"authSuccess",7),this.userCancel=i(this,"userCancel",7),this.oauthPopupWindow=null,this.previousUrl=null}listenDialogAction(){this.openSignInWindow(this.auth.authURI.toString(),"ezeep Login")}listenDialogClose(){this.authCancel.emit()}listenStatusCancel(){this.authCancel.emit()}openSignInWindow(t,e){if(a.state.isAuthorized)return this.authCancel.emit(),void this.authSuccess.emit();window.removeEventListener("message",this.receiveMessage);const i="toolbar=no, menubar=no, width=600, height=7000, top=100, left=100";null===this.oauthPopupWindow||this.oauthPopupWindow.closed?this.oauthPopupWindow=window.open(t,e,i):this.previousUrl!==this.auth.authURI.toString()?(this.oauthPopupWindow=window.open(t,e,i),this.oauthPopupWindow&&!this.oauthPopupWindow.closed&&void 0!==this.oauthPopupWindow.closed||alert("popup blocked"),this.oauthPopupWindow.focus()):this.oauthPopupWindow.focus(),window.addEventListener("message",(t=>this.receiveMessage(t)),!1),this.previousUrl=this.auth.authURI}receiveMessage(t){a.state.code=t.data,this.auth.getAccessToken().then((()=>{this.authCancel.emit(),this.authSuccess.emit()}))}async componentWillLoad(){this.auth=new l(this.redirectURI,this.clientID),this.code&&(a.state.code=this.code,await this.auth.getAccessToken(),this.authCancel.emit(),this.authSuccess.emit()),!1===a.state.isAuthorized&&(this.auth.generateCodeVerifier(),await this.auth.generateCodeChallenge(a.state.codeVerifier),this.auth.buildAuthURI()),this.hidelogin&&"button"===this.trigger&&this.openSignInWindow(this.auth.authURI.toString(),"ezeep Login")}render(){return s(n,{key:"a61df2cca2d4ebdf13b0148ad9eed77f2bd6526f"},this.hidelogin&&"button"===this.trigger?s("ezp-status",{description:c.t("login_dialog.action"),processing:!0,cancel:!0}):this.hidelogin&&"file"===this.trigger?s("div",{class:"auth-actions"},s("ezp-text-button",{type:"button",level:"secondary",onClick:()=>this.userCancel.emit(),label:c.t("button_actions.cancel")}),s("ezp-text-button",{type:"button",level:"primary",onClick:()=>this.openSignInWindow(this.auth.authURI.toString(),"ezeep Login"),label:c.t("button_actions.select_printer")})):s("ezp-dialog",{heading:c.t("login_dialog.heading"),description:c.t("login_dialog.description"),action:c.t("login_dialog.action"),iconName:"logo",iconSize:"huge",iconFramed:!1,instance:"login"}))}static get style(){return":host{--ezp-theme-solid:var(--ezp-accent-cyan-solid);--ezp-theme-translucent:var(--ezp-accent-cyan-translucent);display:block}.auth-actions{display:-ms-flexbox;display:flex;gap:var(--ezp-spacing-3);-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:center;align-items:center;width:100%}.auth-actions ezp-text-button{-ms-flex:1;flex:1;max-width:calc(50% - var(--ezp-spacing-3) / 2)}"}},[1,"ezp-auth",{clientID:[1025,"client-i-d"],redirectURI:[1025,"redirect-u-r-i"],hidelogin:[4],trigger:[1],code:[1],auth:[32],authURI:[32],accessToken:[32]},[[0,"dialogAction","listenDialogAction"],[0,"dialogClose","listenDialogClose"],[0,"statusCancel","listenStatusCancel"]]]);function z(){"undefined"!=typeof customElements&&["ezp-auth","ezp-dialog","ezp-icon","ezp-icon-button","ezp-label","ezp-status","ezp-text-button"].forEach((t=>{switch(t){case"ezp-auth":customElements.get(o(t))||customElements.define(o(t),g);break;case"ezp-dialog":customElements.get(o(t))||h();break;case"ezp-icon":customElements.get(o(t))||p();break;case"ezp-icon-button":customElements.get(o(t))||r();break;case"ezp-label":customElements.get(o(t))||u();break;case"ezp-status":customElements.get(o(t))||d();break;case"ezp-text-button":customElements.get(o(t))||m()}}))}export{g as E,z as d}