import{j as i,l as t,z as e,O as s,I as o,m as r,R as n,a,U as c,x as l,d as u,C as h,o as d,E as p,L as f,S as m,V as w,M as g,T as x}from"./p-BxEPsDRj.js";import{n as v,r as b,c as y}from"./p-CrMmJdZ6.js";import{o as $}from"./p-zNe_7rLp.js";import{O as C}from"./p-UDfqWbD9.js";import{e as I}from"./p-B6UaU4Ic.js";import"./p-DJATscC5.js";import{C as R}from"./p-DtZPtFUa.js";import"./p-CG_zIdXa.js";import"./p-Clzrp4MO.js";import"./p-08zq6pz3.js";import"./p-BId5WtRC.js";import"buffer";import"events";import"ox";import"viem";import"viem/chains";import"./p-B9-TeWdB.js";import"./p-WZF-tHaR.js";import"./p-CbOrugAV.js";var O=i`
  :host {
    margin-top: ${({spacing:i})=>i["1"]};
  }
  wui-separator {
    margin: ${({spacing:i})=>i["3"]} calc(${({spacing:i})=>i["3"]} * -1)
      ${({spacing:i})=>i["2"]} calc(${({spacing:i})=>i["3"]} * -1);
    width: calc(100% + ${({spacing:i})=>i["3"]} * 2);
  }
`;var k=undefined&&undefined.__decorate||function(i,t,e,s){var o=arguments.length,r=o<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(i,t,e,s);else for(var a=i.length-1;a>=0;a--)if(n=i[a])r=(o<3?n(r):o>3?n(t,e,r):n(t,e))||r;return o>3&&r&&Object.defineProperty(t,e,r),r};let L=class i extends t{constructor(){super();this.unsubscribe=[];this.tabIdx=undefined;this.connectors=e.state.connectors;this.authConnector=this.connectors.find((i=>i.type==="AUTH"));this.remoteFeatures=s.state.remoteFeatures;this.isPwaLoading=false;this.hasExceededUsageLimit=o.state.plan.hasExceededUsageLimit;this.unsubscribe.push(e.subscribeKey("connectors",(i=>{this.connectors=i;this.authConnector=this.connectors.find((i=>i.type==="AUTH"))})),s.subscribeKey("remoteFeatures",(i=>this.remoteFeatures=i)))}connectedCallback(){super.connectedCallback();this.handlePwaFrameLoad()}disconnectedCallback(){this.unsubscribe.forEach((i=>i()))}render(){let i=this.remoteFeatures?.socials||[];const t=Boolean(this.authConnector);const e=i?.length;const s=n.state.view==="ConnectSocials";if((!t||!e)&&!s){return null}if(s&&!e){i=u.DEFAULT_SOCIALS}return r` <wui-flex flexDirection="column" gap="2">
      ${i.map((i=>r`<wui-list-social
            @click=${()=>{this.onSocialClick(i)}}
            data-testid=${`social-selector-${i}`}
            name=${i}
            logo=${i}
            ?disabled=${this.isPwaLoading}
          ></wui-list-social>`))}
    </wui-flex>`}async onSocialClick(i){if(this.hasExceededUsageLimit){n.push("UsageExceeded");return}if(i){await I(i)}}async handlePwaFrameLoad(){if(a.isPWA()){this.isPwaLoading=true;try{if(this.authConnector?.provider instanceof c){await this.authConnector.provider.init()}}catch(i){l.open({displayMessage:"Error loading embedded wallet in PWA",debugMessage:i.message},"error")}finally{this.isPwaLoading=false}}}};L.styles=O;k([v()],L.prototype,"tabIdx",void 0);k([b()],L.prototype,"connectors",void 0);k([b()],L.prototype,"authConnector",void 0);k([b()],L.prototype,"remoteFeatures",void 0);k([b()],L.prototype,"isPwaLoading",void 0);k([b()],L.prototype,"hasExceededUsageLimit",void 0);L=k([y("w3m-social-login-list")],L);var S=i`
  wui-flex {
    max-height: clamp(360px, 540px, 80vh);
    overflow: scroll;
    scrollbar-width: none;
    transition: opacity ${({durations:i})=>i["md"]}
      ${({easings:i})=>i["ease-out-power-1"]};
    will-change: opacity;
  }

  wui-flex::-webkit-scrollbar {
    display: none;
  }

  wui-flex.disabled {
    opacity: 0.3;
    pointer-events: none;
    user-select: none;
  }
`;var j=undefined&&undefined.__decorate||function(i,t,e,s){var o=arguments.length,r=o<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(i,t,e,s);else for(var a=i.length-1;a>=0;a--)if(n=i[a])r=(o<3?n(r):o>3?n(t,e,r):n(t,e))||r;return o>3&&r&&Object.defineProperty(t,e,r),r};let _=class i extends t{constructor(){super();this.unsubscribe=[];this.checked=C.state.isLegalCheckboxChecked;this.unsubscribe.push(C.subscribeKey("isLegalCheckboxChecked",(i=>{this.checked=i})))}disconnectedCallback(){this.unsubscribe.forEach((i=>i()))}render(){const{termsConditionsUrl:i,privacyPolicyUrl:t}=s.state;const e=s.state.features?.legalCheckbox;const o=i||t;const n=Boolean(o)&&Boolean(e);const a=n&&!this.checked;const c=a?-1:undefined;return r`
      <w3m-legal-checkbox></w3m-legal-checkbox>
      <wui-flex
        flexDirection="column"
        .padding=${["0","3","3","3"]}
        gap="01"
        class=${$(a?"disabled":undefined)}
      >
        <w3m-social-login-list tabIdx=${$(c)}></w3m-social-login-list>
      </wui-flex>
    `}};_.styles=S;j([b()],_.prototype,"checked",void 0);_=j([y("w3m-connect-socials-view")],_);var A=i`
  wui-logo {
    width: 80px;
    height: 80px;
    border-radius: ${({borderRadius:i})=>i["8"]};
  }
  @keyframes shake {
    0% {
      transform: translateX(0);
    }
    25% {
      transform: translateX(3px);
    }
    50% {
      transform: translateX(-3px);
    }
    75% {
      transform: translateX(3px);
    }
    100% {
      transform: translateX(0);
    }
  }
  wui-flex:first-child:not(:only-child) {
    position: relative;
  }
  wui-loading-thumbnail {
    position: absolute;
  }
  wui-icon-box {
    position: absolute;
    right: calc(${({spacing:i})=>i["1"]} * -1);
    bottom: calc(${({spacing:i})=>i["1"]} * -1);
    opacity: 0;
    transform: scale(0.5);
    transition: all ${({easings:i})=>i["ease-out-power-2"]}
      ${({durations:i})=>i["lg"]};
  }
  wui-text[align='center'] {
    width: 100%;
    padding: 0px ${({spacing:i})=>i["4"]};
  }
  [data-error='true'] wui-icon-box {
    opacity: 1;
    transform: scale(1);
  }
  [data-error='true'] > wui-flex:first-child {
    animation: shake 250ms ${({easings:i})=>i["ease-out-power-2"]} both;
  }
  .capitalize {
    text-transform: capitalize;
  }
`;var E=undefined&&undefined.__decorate||function(i,t,e,s){var o=arguments.length,r=o<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(i,t,e,s);else for(var a=i.length-1;a>=0;a--)if(n=i[a])r=(o<3?n(r):o>3?n(t,e,r):n(t,e))||r;return o>3&&r&&Object.defineProperty(t,e,r),r};let U=class i extends t{constructor(){super();this.unsubscribe=[];this.socialProvider=h.getAccountData()?.socialProvider;this.socialWindow=h.getAccountData()?.socialWindow;this.error=false;this.connecting=false;this.message="Connect in the provider window";this.remoteFeatures=s.state.remoteFeatures;this.address=h.getAccountData()?.address;this.connectionsByNamespace=d.getConnections(h.state.activeChain);this.hasMultipleConnections=this.connectionsByNamespace.length>0;this.authConnector=e.getAuthConnector();this.handleSocialConnection=async i=>{if(i.data?.resultUri){if(i.origin===R.SECURE_SITE_ORIGIN){window.removeEventListener("message",this.handleSocialConnection,false);try{if(this.authConnector&&!this.connecting){this.connecting=true;const t=this.parseURLError(i.data.resultUri);if(t){this.handleSocialError(t);return}this.closeSocialWindow();this.updateMessage();const e=i.data.resultUri;if(this.socialProvider){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_REQUEST_USER_DATA",properties:{provider:this.socialProvider}})}await d.connectExternal({id:this.authConnector.id,type:this.authConnector.type,socialUri:e},this.authConnector.chain);if(this.socialProvider){f.setConnectedSocialProvider(this.socialProvider);p.sendEvent({type:"track",event:"SOCIAL_LOGIN_SUCCESS",properties:{provider:this.socialProvider}})}}}catch(i){this.error=true;this.updateMessage();if(this.socialProvider){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_ERROR",properties:{provider:this.socialProvider,message:a.parseError(i)}})}}}else{n.goBack();m.showError("Untrusted Origin");if(this.socialProvider){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_ERROR",properties:{provider:this.socialProvider,message:"Untrusted Origin"}})}}}};const i=w.EmbeddedWalletAbortController;i.signal.addEventListener("abort",(()=>{this.closeSocialWindow()}));this.unsubscribe.push(...[h.subscribeChainProp("accountState",(i=>{if(i){this.socialProvider=i.socialProvider;if(i.socialWindow){this.socialWindow=i.socialWindow}if(i.address){const t=this.remoteFeatures?.multiWallet;if(i.address!==this.address){if(this.hasMultipleConnections&&t){n.replace("ProfileWallets");m.showSuccess("New Wallet Added");this.address=i.address}else if(g.state.open||s.state.enableEmbedded){g.close()}}}}})),s.subscribeKey("remoteFeatures",(i=>{this.remoteFeatures=i}))]);if(this.authConnector){this.connectSocial()}}disconnectedCallback(){this.unsubscribe.forEach((i=>i()));window.removeEventListener("message",this.handleSocialConnection,false);const i=h.state.activeCaipAddress;if(!i&&this.socialProvider&&!this.connecting){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_CANCELED",properties:{provider:this.socialProvider}})}this.closeSocialWindow()}render(){return r`
      <wui-flex
        data-error=${$(this.error)}
        flexDirection="column"
        alignItems="center"
        .padding=${["10","5","5","5"]}
        gap="6"
      >
        <wui-flex justifyContent="center" alignItems="center">
          <wui-logo logo=${$(this.socialProvider)}></wui-logo>
          ${this.error?null:this.loaderTemplate()}
          <wui-icon-box color="error" icon="close" size="sm"></wui-icon-box>
        </wui-flex>
        <wui-flex flexDirection="column" alignItems="center" gap="2">
          <wui-text align="center" variant="lg-medium" color="primary"
            >Log in with
            <span class="capitalize">${this.socialProvider??"Social"}</span></wui-text
          >
          <wui-text align="center" variant="lg-regular" color=${this.error?"error":"secondary"}
            >${this.message}</wui-text
          ></wui-flex
        >
      </wui-flex>
    `}loaderTemplate(){const i=x.state.themeVariables["--w3m-border-radius-master"];const t=i?parseInt(i.replace("px",""),10):4;return r`<wui-loading-thumbnail radius=${t*9}></wui-loading-thumbnail>`}parseURLError(i){try{const t="error=";const e=i.indexOf(t);if(e===-1){return null}const s=i.substring(e+t.length);return s}catch{return null}}connectSocial(){const i=setInterval((()=>{if(this.socialWindow?.closed){if(!this.connecting&&n.state.view==="ConnectingSocial"){n.goBack()}clearInterval(i)}}),1e3);window.addEventListener("message",this.handleSocialConnection,false)}updateMessage(){if(this.error){this.message="Something went wrong"}else if(this.connecting){this.message="Retrieving user data"}else{this.message="Connect in the provider window"}}handleSocialError(i){this.error=true;this.updateMessage();if(this.socialProvider){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_ERROR",properties:{provider:this.socialProvider,message:i}})}this.closeSocialWindow()}closeSocialWindow(){if(this.socialWindow){this.socialWindow.close();h.setAccountProp("socialWindow",undefined,h.state.activeChain)}}};U.styles=A;E([b()],U.prototype,"socialProvider",void 0);E([b()],U.prototype,"socialWindow",void 0);E([b()],U.prototype,"error",void 0);E([b()],U.prototype,"connecting",void 0);E([b()],U.prototype,"message",void 0);E([b()],U.prototype,"remoteFeatures",void 0);U=E([y("w3m-connecting-social-view")],U);var T=i`
  wui-shimmer {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: ${({borderRadius:i})=>i[4]};
  }

  wui-qr-code {
    opacity: 0;
    animation-duration: ${({durations:i})=>i["xl"]};
    animation-timing-function: ${({easings:i})=>i["ease-out-power-2"]};
    animation-name: fade-in;
    animation-fill-mode: forwards;
  }

  wui-logo {
    width: 80px;
    height: 80px;
    border-radius: ${({borderRadius:i})=>i["8"]};
  }

  wui-flex:first-child:not(:only-child) {
    position: relative;
  }

  wui-loading-thumbnail {
    position: absolute;
  }

  wui-icon-box {
    position: absolute;
    right: calc(${({spacing:i})=>i["1"]} * -1);
    bottom: calc(${({spacing:i})=>i["1"]} * -1);
    opacity: 0;
    transform: scale(0.5);
    transition:
      opacity ${({durations:i})=>i["lg"]} ${({easings:i})=>i["ease-out-power-2"]},
      transform ${({durations:i})=>i["lg"]}
        ${({easings:i})=>i["ease-out-power-2"]};
    will-change: opacity, transform;
  }

  @keyframes fade-in {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
`;var z=undefined&&undefined.__decorate||function(i,t,e,s){var o=arguments.length,r=o<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,n;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(i,t,e,s);else for(var a=i.length-1;a>=0;a--)if(n=i[a])r=(o<3?n(r):o>3?n(t,e,r):n(t,e))||r;return o>3&&r&&Object.defineProperty(t,e,r),r};let D=class i extends t{constructor(){super();this.unsubscribe=[];this.timeout=undefined;this.socialProvider=h.getAccountData()?.socialProvider;this.uri=h.getAccountData()?.farcasterUrl;this.ready=false;this.loading=false;this.remoteFeatures=s.state.remoteFeatures;this.authConnector=e.getAuthConnector();this.forceUpdate=()=>{this.requestUpdate()};this.unsubscribe.push(...[h.subscribeChainProp("accountState",(i=>{this.socialProvider=i?.socialProvider;this.uri=i?.farcasterUrl;this.connectFarcaster()})),s.subscribeKey("remoteFeatures",(i=>{this.remoteFeatures=i}))]);window.addEventListener("resize",this.forceUpdate)}disconnectedCallback(){super.disconnectedCallback();clearTimeout(this.timeout);window.removeEventListener("resize",this.forceUpdate);const i=h.state.activeCaipAddress;if(!i&&this.socialProvider&&(this.uri||this.loading)){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_CANCELED",properties:{provider:this.socialProvider}})}}render(){this.onRenderProxy();return r`${this.platformTemplate()}`}platformTemplate(){if(a.isMobile()){return r`${this.mobileTemplate()}`}return r`${this.desktopTemplate()}`}desktopTemplate(){if(this.loading){return r`${this.loadingTemplate()}`}return r`${this.qrTemplate()}`}qrTemplate(){return r` <wui-flex
      flexDirection="column"
      alignItems="center"
      .padding=${["0","5","5","5"]}
      gap="5"
    >
      <wui-shimmer width="100%"> ${this.qrCodeTemplate()} </wui-shimmer>

      <wui-text variant="lg-medium" color="primary"> Scan this QR Code with your phone </wui-text>
      ${this.copyTemplate()}
    </wui-flex>`}loadingTemplate(){return r`
      <wui-flex
        flexDirection="column"
        alignItems="center"
        .padding=${["5","5","5","5"]}
        gap="5"
      >
        <wui-flex justifyContent="center" alignItems="center">
          <wui-logo logo="farcaster"></wui-logo>
          ${this.loaderTemplate()}
          <wui-icon-box color="error" icon="close" size="sm"></wui-icon-box>
        </wui-flex>
        <wui-flex flexDirection="column" alignItems="center" gap="2">
          <wui-text align="center" variant="md-medium" color="primary">
            Loading user data
          </wui-text>
          <wui-text align="center" variant="sm-regular" color="secondary">
            Please wait a moment while we load your data.
          </wui-text>
        </wui-flex>
      </wui-flex>
    `}mobileTemplate(){return r` <wui-flex
      flexDirection="column"
      alignItems="center"
      .padding=${["10","5","5","5"]}
      gap="5"
    >
      <wui-flex justifyContent="center" alignItems="center">
        <wui-logo logo="farcaster"></wui-logo>
        ${this.loaderTemplate()}
        <wui-icon-box
          color="error"
          icon="close"
          size="sm"
        ></wui-icon-box>
      </wui-flex>
      <wui-flex flexDirection="column" alignItems="center" gap="2">
        <wui-text align="center" variant="md-medium" color="primary"
          >Continue in Farcaster</span></wui-text
        >
        <wui-text align="center" variant="sm-regular" color="secondary"
          >Accept connection request in the app</wui-text
        ></wui-flex
      >
      ${this.mobileLinkTemplate()}
    </wui-flex>`}loaderTemplate(){const i=x.state.themeVariables["--w3m-border-radius-master"];const t=i?parseInt(i.replace("px",""),10):4;return r`<wui-loading-thumbnail radius=${t*9}></wui-loading-thumbnail>`}async connectFarcaster(){if(this.authConnector){try{await(this.authConnector?.provider.connectFarcaster());if(this.socialProvider){f.setConnectedSocialProvider(this.socialProvider);p.sendEvent({type:"track",event:"SOCIAL_LOGIN_REQUEST_USER_DATA",properties:{provider:this.socialProvider}})}this.loading=true;const i=d.getConnections(this.authConnector.chain);const t=i.length>0;await d.connectExternal(this.authConnector,this.authConnector.chain);const e=this.remoteFeatures?.multiWallet;if(this.socialProvider){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_SUCCESS",properties:{provider:this.socialProvider}})}this.loading=false;if(t&&e){n.replace("ProfileWallets");m.showSuccess("New Wallet Added")}else{g.close()}}catch(i){if(this.socialProvider){p.sendEvent({type:"track",event:"SOCIAL_LOGIN_ERROR",properties:{provider:this.socialProvider,message:a.parseError(i)}})}n.goBack();m.showError(i)}}}mobileLinkTemplate(){return r`<wui-button
      size="md"
      ?loading=${this.loading}
      ?disabled=${!this.uri||this.loading}
      @click=${()=>{if(this.uri){a.openHref(this.uri,"_blank")}}}
    >
      Open farcaster</wui-button
    >`}onRenderProxy(){if(!this.ready&&this.uri){this.timeout=setTimeout((()=>{this.ready=true}),200)}}qrCodeTemplate(){if(!this.uri||!this.ready){return null}const i=this.getBoundingClientRect().width-40;const t=x.state.themeVariables["--apkt-qr-color"]??x.state.themeVariables["--w3m-qr-color"];return r` <wui-qr-code
      size=${i}
      theme=${x.state.themeMode}
      uri=${this.uri}
      ?farcaster=${true}
      data-testid="wui-qr-code"
      color=${$(t)}
    ></wui-qr-code>`}copyTemplate(){const i=!this.uri||!this.ready;return r`<wui-button
      .disabled=${i}
      @click=${this.onCopyUri}
      variant="neutral-secondary"
      size="sm"
      data-testid="copy-wc2-uri"
    >
      <wui-icon size="sm" color="default" slot="iconRight" name="copy"></wui-icon>
      Copy link
    </wui-button>`}onCopyUri(){try{if(this.uri){a.copyToClopboard(this.uri);m.showSuccess("Link copied")}}catch{m.showError("Failed to copy")}}};D.styles=T;z([b()],D.prototype,"socialProvider",void 0);z([b()],D.prototype,"uri",void 0);z([b()],D.prototype,"ready",void 0);z([b()],D.prototype,"loading",void 0);z([b()],D.prototype,"remoteFeatures",void 0);D=z([y("w3m-connecting-farcaster-view")],D);export{_ as W3mConnectSocialsView,D as W3mConnectingFarcasterView,U as W3mConnectingSocialView};
//# sourceMappingURL=p-BS1UYGBC.js.map