import{o as e,C as t,E as i,O as r,M as n,R as s,S as a,a as o,j as l,l as c,z as f,m as u,n as h,Q as p,q as d}from"./p-BxEPsDRj.js";import{c as m,r as w}from"./p-CrMmJdZ6.js";import{W as v}from"./p-O_x03Lx4.js";import"./p-DJATscC5.js";import"./p-YV_GhS6X.js";import{e as E,n as y}from"./p-B9-TeWdB.js";import"./p-CG_zIdXa.js";import"./p-H9e2kJNd.js";import"./p-BId5WtRC.js";import"buffer";import"events";import"ox";import"viem";import"viem/chains";import"./p-WZF-tHaR.js";import"./p-zNe_7rLp.js";import"./p-CGIQ9z_e.js";var I=undefined&&undefined.__decorate||function(e,t,i,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,i):r,a;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)if(a=e[o])s=(n<3?a(s):n>3?a(t,i,s):a(t,i))||s;return n>3&&s&&Object.defineProperty(t,i,s),s};let x=class l extends v{constructor(){super(...arguments);this.onOtpSubmit=async l=>{try{if(this.authConnector){const o=t.state.activeChain;const c=e.getConnections(o);const f=r.state.remoteFeatures?.multiWallet;const u=c.length>0;await this.authConnector.provider.connectOtp({otp:l});i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_PASS"});if(o){await e.connectExternal(this.authConnector,o)}else{throw new Error("Active chain is not set on ChainController")}if(r.state.remoteFeatures?.emailCapture){return}if(r.state.siwx){n.close();return}if(u&&f){s.replace("ProfileWallets");a.showSuccess("New Wallet Added");return}n.close()}}catch(e){i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_FAIL",properties:{message:o.parseError(e)}});throw e}};this.onOtpResend=async e=>{if(this.authConnector){await this.authConnector.provider.connectEmail({email:e});i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_SENT"})}}}};x=I([m("w3m-email-verify-otp-view")],x);var b=l`
  wui-icon-box {
    height: ${({spacing:e})=>e["16"]};
    width: ${({spacing:e})=>e["16"]};
  }
`;var g=undefined&&undefined.__decorate||function(e,t,i,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,i):r,a;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)if(a=e[o])s=(n<3?a(s):n>3?a(t,i,s):a(t,i))||s;return n>3&&s&&Object.defineProperty(t,i,s),s};let O=class e extends c{constructor(){super();this.email=s.state.data?.email;this.authConnector=f.getAuthConnector();this.loading=false;this.listenForDeviceApproval()}render(){if(!this.email){throw new Error("w3m-email-verify-device-view: No email provided")}if(!this.authConnector){throw new Error("w3m-email-verify-device-view: No auth connector provided")}return u`
      <wui-flex
        flexDirection="column"
        alignItems="center"
        .padding=${["6","3","6","3"]}
        gap="4"
      >
        <wui-icon-box size="xl" color="accent-primary" icon="sealCheck"></wui-icon-box>

        <wui-flex flexDirection="column" alignItems="center" gap="3">
          <wui-flex flexDirection="column" alignItems="center">
            <wui-text variant="md-regular" color="primary">
              Approve the login link we sent to
            </wui-text>
            <wui-text variant="md-regular" color="primary"><b>${this.email}</b></wui-text>
          </wui-flex>

          <wui-text variant="sm-regular" color="secondary" align="center">
            The code expires in 20 minutes
          </wui-text>

          <wui-flex alignItems="center" id="w3m-resend-section" gap="2">
            <wui-text variant="sm-regular" color="primary" align="center">
              Didn't receive it?
            </wui-text>
            <wui-link @click=${this.onResendCode.bind(this)} .disabled=${this.loading}>
              Resend email
            </wui-link>
          </wui-flex>
        </wui-flex>
      </wui-flex>
    `}async listenForDeviceApproval(){if(this.authConnector){try{await this.authConnector.provider.connectDevice();i.sendEvent({type:"track",event:"DEVICE_REGISTERED_FOR_EMAIL"});i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_SENT"});s.replace("EmailVerifyOtp",{email:this.email})}catch(e){s.goBack()}}}async onResendCode(){try{if(!this.loading){if(!this.authConnector||!this.email){throw new Error("w3m-email-login-widget: Unable to resend email")}this.loading=true;await this.authConnector.provider.connectEmail({email:this.email});this.listenForDeviceApproval();a.showSuccess("Code email resent")}}catch(e){a.showError(e)}finally{this.loading=false}}};O.styles=b;g([w()],O.prototype,"loading",void 0);O=g([m("w3m-email-verify-device-view")],O);var R=h`
  wui-email-input {
    width: 100%;
  }

  form {
    width: 100%;
    display: block;
    position: relative;
  }
`;var _=undefined&&undefined.__decorate||function(e,t,i,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,i):r,a;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)if(a=e[o])s=(n<3?a(s):n>3?a(t,i,s):a(t,i))||s;return n>3&&s&&Object.defineProperty(t,i,s),s};let j=class e extends c{constructor(){super(...arguments);this.formRef=E();this.initialEmail=s.state.data?.email??"";this.redirectView=s.state.data?.redirectView;this.email="";this.loading=false}firstUpdated(){this.formRef.value?.addEventListener("keydown",(e=>{if(e.key==="Enter"){this.onSubmitEmail(e)}}))}render(){return u`
      <wui-flex flexDirection="column" padding="4" gap="4">
        <form ${y(this.formRef)} @submit=${this.onSubmitEmail.bind(this)}>
          <wui-email-input
            value=${this.initialEmail}
            .disabled=${this.loading}
            @inputChange=${this.onEmailInputChange.bind(this)}
          >
          </wui-email-input>
          <input type="submit" hidden />
        </form>
        ${this.buttonsTemplate()}
      </wui-flex>
    `}onEmailInputChange(e){this.email=e.detail}async onSubmitEmail(e){try{if(this.loading){return}this.loading=true;e.preventDefault();const t=f.getAuthConnector();if(!t){throw new Error("w3m-update-email-wallet: Auth connector not found")}const r=await t.provider.updateEmail({email:this.email});i.sendEvent({type:"track",event:"EMAIL_EDIT"});if(r.action==="VERIFY_SECONDARY_OTP"){s.push("UpdateEmailSecondaryOtp",{email:this.initialEmail,newEmail:this.email,redirectView:this.redirectView})}else{s.push("UpdateEmailPrimaryOtp",{email:this.initialEmail,newEmail:this.email,redirectView:this.redirectView})}}catch(e){a.showError(e);this.loading=false}}buttonsTemplate(){const e=!this.loading&&this.email.length>3&&this.email!==this.initialEmail;if(!this.redirectView){return u`
        <wui-button
          size="md"
          variant="accent-primary"
          fullWidth
          @click=${this.onSubmitEmail.bind(this)}
          .disabled=${!e}
          .loading=${this.loading}
        >
          Save
        </wui-button>
      `}return u`
      <wui-flex gap="3">
        <wui-button size="md" variant="neutral" fullWidth @click=${s.goBack}>
          Cancel
        </wui-button>

        <wui-button
          size="md"
          variant="accent-primary"
          fullWidth
          @click=${this.onSubmitEmail.bind(this)}
          .disabled=${!e}
          .loading=${this.loading}
        >
          Save
        </wui-button>
      </wui-flex>
    `}};j.styles=R;_([w()],j.prototype,"email",void 0);_([w()],j.prototype,"loading",void 0);j=_([m("w3m-update-email-wallet-view")],j);var A=undefined&&undefined.__decorate||function(e,t,i,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,i):r,a;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)if(a=e[o])s=(n<3?a(s):n>3?a(t,i,s):a(t,i))||s;return n>3&&s&&Object.defineProperty(t,i,s),s};let C=class e extends v{constructor(){super();this.email=s.state.data?.email;this.onOtpSubmit=async e=>{try{if(this.authConnector){await this.authConnector.provider.updateEmailPrimaryOtp({otp:e});i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_PASS"});s.replace("UpdateEmailSecondaryOtp",s.state.data)}}catch(e){i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_FAIL",properties:{message:o.parseError(e)}});throw e}};this.onStartOver=()=>{s.replace("UpdateEmailWallet",s.state.data)}}};C=A([m("w3m-update-email-primary-otp-view")],C);var k=undefined&&undefined.__decorate||function(e,t,i,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,i):r,a;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)if(a=e[o])s=(n<3?a(s):n>3?a(t,i,s):a(t,i))||s;return n>3&&s&&Object.defineProperty(t,i,s),s};let D=class e extends v{constructor(){super();this.email=s.state.data?.newEmail;this.redirectView=s.state.data?.redirectView;this.onOtpSubmit=async e=>{try{if(this.authConnector){await this.authConnector.provider.updateEmailSecondaryOtp({otp:e});i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_PASS"});if(this.redirectView){s.reset(this.redirectView)}}}catch(e){i.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_FAIL",properties:{message:o.parseError(e)}});throw e}};this.onStartOver=()=>{s.replace("UpdateEmailWallet",s.state.data)}}};D=k([m("w3m-update-email-secondary-otp-view")],D);var $=undefined&&undefined.__decorate||function(e,t,i,r){var n=arguments.length,s=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,i):r,a;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")s=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)if(a=e[o])s=(n<3?a(s):n>3?a(t,i,s):a(t,i))||s;return n>3&&s&&Object.defineProperty(t,i,s),s};let N=class e extends c{constructor(){super();this.authConnector=f.getAuthConnector();this.isEmailEnabled=r.state.remoteFeatures?.email;this.isAuthEnabled=this.checkIfAuthEnabled(f.state.connectors);this.connectors=f.state.connectors;f.subscribeKey("connectors",(e=>{this.connectors=e;this.isAuthEnabled=this.checkIfAuthEnabled(this.connectors)}))}render(){if(!this.isEmailEnabled){throw new Error("w3m-email-login-view: Email is not enabled")}if(!this.isAuthEnabled){throw new Error("w3m-email-login-view: No auth connector provided")}return u`<wui-flex flexDirection="column" .padding=${["1","3","3","3"]} gap="4">
      <w3m-email-login-widget></w3m-email-login-widget>
    </wui-flex> `}checkIfAuthEnabled(e){const t=e.filter((e=>e.type===p.CONNECTOR_TYPE_AUTH)).map((e=>e.chain));const i=d.AUTH_CONNECTOR_SUPPORTED_CHAINS;return i.some((e=>t.includes(e)))}};$([w()],N.prototype,"connectors",void 0);N=$([m("w3m-email-login-view")],N);export{N as W3mEmailLoginView,v as W3mEmailOtpWidget,O as W3mEmailVerifyDeviceView,x as W3mEmailVerifyOtpView,C as W3mUpdateEmailPrimaryOtpView,D as W3mUpdateEmailSecondaryOtpView,j as W3mUpdateEmailWalletView};
//# sourceMappingURL=p-D8NnBdgm.js.map