import{p as m,Y as v,v as w,j as y,k as C,J as x,B as b,H as h,l as I,m as p,z as f,n as c,q as _,K as E,W as $,r as W,s as j}from"./main-2rA8bEUg.js";const s=m({status:"uninitialized"}),u={state:s,subscribeKey(e,t){return C(s,e,t)},subscribe(e){return y(s,()=>e(s))},_getClient(){if(!s._client)throw new Error("SIWEController client not set");return s._client},async getNonce(e){const t=await this._getClient().getNonce(e);return this.setNonce(t),t},async getSession(){const e=await this._getClient().getSession();return e&&(this.setSession(e),this.setStatus("success")),e},createMessage(e){const t=this._getClient().createMessage(e);return this.setMessage(t),t},async verifyMessage(e){return await this._getClient().verifyMessage(e)},async signIn(){return await this._getClient().signIn()},async signOut(){var e;const t=this._getClient();await t.signOut(),this.setStatus("ready"),(e=t.onSignOut)==null||e.call(t)},onSignIn(e){var t;const i=this._getClient();(t=i.onSignIn)==null||t.call(i,e)},onSignOut(){var e;const t=this._getClient();(e=t.onSignOut)==null||e.call(t)},setSIWEClient(e){s._client=v(e),s.status="ready",w.setIsSiweEnabled(e.options.enabled)},setNonce(e){s.nonce=e},setStatus(e){s.status=e},setMessage(e){s.message=e},setSession(e){s.session=e}},R=x`
  :host {
    display: flex;
    justify-content: center;
    gap: var(--wui-spacing-2xl);
  }

  wui-visual-thumbnail:nth-child(1) {
    z-index: 1;
  }
`;var O=function(e,t,i,l){var a=arguments.length,n=a<3?t:l===null?l=Object.getOwnPropertyDescriptor(t,i):l,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,i,l);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(n=(a<3?r(n):a>3?r(t,i,n):r(t,i))||n);return a>3&&n&&Object.defineProperty(t,i,n),n};let g=class extends h{constructor(){var e;super(...arguments),this.dappImageUrl=(e=w.state.metadata)==null?void 0:e.icons,this.walletImageUrl=I.getConnectedWalletImageUrl()}firstUpdated(){var e;const t=(e=this.shadowRoot)==null?void 0:e.querySelectorAll("wui-visual-thumbnail");t!=null&&t[0]&&this.createAnimation(t[0],"translate(18px)"),t!=null&&t[1]&&this.createAnimation(t[1],"translate(-18px)")}render(){var e;return p`
      <wui-visual-thumbnail
        ?borderRadiusFull=${!0}
        .imageSrc=${(e=this.dappImageUrl)==null?void 0:e[0]}
      ></wui-visual-thumbnail>
      <wui-visual-thumbnail .imageSrc=${this.walletImageUrl}></wui-visual-thumbnail>
    `}createAnimation(e,t){e.animate([{transform:"translateX(0px)"},{transform:t}],{duration:1600,easing:"cubic-bezier(0.56, 0, 0.48, 1)",direction:"alternate",iterations:1/0})}};g.styles=R;g=O([f("w3m-connecting-siwe")],g);var S=function(e,t,i,l){var a=arguments.length,n=a<3?t:l,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,i,l);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(n=(a<3?r(n):a>3?r(t,i,n):r(t,i))||n);return a>3&&n&&Object.defineProperty(t,i,n),n};let d=class extends h{constructor(){var e;super(...arguments),this.dappName=(e=w.state.metadata)==null?void 0:e.name,this.isSigning=!1}render(){return p`
      <wui-flex justifyContent="center" .padding=${["2xl","0","xxl","0"]}>
        <w3m-connecting-siwe></w3m-connecting-siwe>
      </wui-flex>
      <wui-flex
        .padding=${["0","4xl","l","4xl"]}
        gap="s"
        justifyContent="space-between"
      >
        <wui-text variant="paragraph-500" align="center" color="fg-100"
          >${this.dappName??"Dapp"} needs to connect to your wallet</wui-text
        >
      </wui-flex>
      <wui-flex
        .padding=${["0","3xl","l","3xl"]}
        gap="s"
        justifyContent="space-between"
      >
        <wui-text variant="small-400" align="center" color="fg-200"
          >Sign this message to prove you own this wallet and proceed. Canceling will disconnect
          you.</wui-text
        >
      </wui-flex>
      <wui-flex .padding=${["l","xl","xl","xl"]} gap="s" justifyContent="space-between">
        <wui-button
          size="md"
          ?fullwidth=${!0}
          variant="shade"
          @click=${this.onCancel.bind(this)}
          data-testid="w3m-connecting-siwe-cancel"
        >
          Cancel
        </wui-button>
        <wui-button
          size="md"
          ?fullwidth=${!0}
          variant="fill"
          @click=${this.onSign.bind(this)}
          ?loading=${this.isSigning}
          data-testid="w3m-connecting-siwe-sign"
        >
          ${this.isSigning?"Signing...":"Sign"}
        </wui-button>
      </wui-flex>
    `}async onSign(){this.isSigning=!0,c.sendEvent({event:"CLICK_SIGN_SIWE_MESSAGE",type:"track"});try{u.setStatus("loading");const e=await u.signIn();return u.setStatus("success"),c.sendEvent({event:"SIWE_AUTH_SUCCESS",type:"track"}),e}catch{return _.showError("Signature declined"),u.setStatus("error"),c.sendEvent({event:"SIWE_AUTH_ERROR",type:"track"})}finally{this.isSigning=!1}}async onCancel(){const{isConnected:e}=E.state;e?(await $.disconnect(),W.close()):j.push("Connect"),c.sendEvent({event:"CLICK_CANCEL_SIWE",type:"track"})}};S([b()],d.prototype,"isSigning",void 0);d=S([f("w3m-connecting-siwe-view")],d);export{u as SIWEController,g as W3mConnectingSiwe,d as W3mConnectingSiweView};
