1import{r as c,j as e,g as Y,n as Z}from"./react-vendor-BDHNqS4B.js";import{u as T,D as q,j as z,k as H,l as V,m as B,B as S,L as F,I as D,aU as Q,n as _,aV as X,aW as J,aX as $,e as ee,h as se,aY as te,aZ as ne}from"./main-m_sUF2N4.js";import{s as b}from"./amplify-DYDcjoow.js";import"./query-7-WHkg5t.js";const ae=({open:n,onClose:s,onSaved:l})=>{const{t:r}=T(),[u,m]=c.useState(""),[t,f]=c.useState(""),[x,g]=c.useState(!1),[k,d]=c.useState(null),[j,p]=c.useState(!1),w=a=>a.length>=8&&/[A-Za-z]/.test(a)&&/\d/.test(a),h=async()=>{if(!w(u)){d(r("auth.passwordInvalid"));return}if(u!==t){d(r("auth.passwordsDoNotMatch"));return}g(!0),d(null);try{await Q(u),p(!0),l==null||l()}catch(a){d(a instanceof Error?a.message:r("auth.unknownError"))}finally{g(!1)}},o=()=>{m(""),f(""),d(null),p(!1),s()};return e.jsx(q,{open:n,onOpenChange:a=>!a&&o(),children:e.jsxs(z,{className:"sm:max-w-md",children:[e.jsxs(H,{children:[e.jsx(V,{children:r("authLinking.setPasswordTitle")}),e.jsx(B,{children:r(j?"authLinking.setPasswordSuccess":"authLinking.setPasswordDescription")})]}),j?e.jsx(S,{onClick:o,children:r("auth.continueBtn")}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{htmlFor:"set-password",children:r("auth.password")}),e.jsx(D,{id:"set-password",type:"password",value:u,onChange:a=>{m(a.target.value),d(null)}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{htmlFor:"confirm-set-password",children:r("auth.confirmPassword")}),e.jsx(D,{id:"confirm-set-password",type:"password",value:t,onChange:a=>{f(a.target.value),d(null)}})]}),k?e.jsx("p",{className:"text-sm text-destructive",children:k}):null,e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:"outline",className:"flex-1",onClick:o,disabled:x,children:r("auth.back")}),e.jsx(S,{className:"flex-1",onClick:h,disabled:x,children:r(x?"auth.verifying":"authLinking.setPasswordSubmit")})]})]})]})})},P=n=>String(n instanceof Error?n.message:n||""),ie=n=>{const s=P(n);return s.includes("ERR_INVALID_PASSWORD")||s.includes("NotAuthorizedException")||s.includes("Incorrect")||s.toLowerCase().includes("incorrect username or password")},re=n=>{const s=P(n);return s.includes("NEW_PASSWORD_REQUIRED")||s.includes("PasswordResetRequiredException")||s.includes("UserNotConfirmedException")||s.toLowerCase().includes("temporary password")||s.toLowerCase().includes("password change required")},oe=n=>{const s=P(n);return s.includes("ERR_AUTH_FLOW")||s.includes("Auth flow not enabled")||s.includes("ADMIN_USER_PASSWORD_AUTH")},ce=n=>P(n).includes("ERR_NATIVE_USER_NOT_FOUND"),le=n=>{const s=P(n);return s.includes("ERR_LINK_MERGE")||s.includes("Merging is not currently supported")},ue=({open:n,email:s,provider:l="Google",onClose:r,onLinked:u,onCancel:m})=>{const{t}=T(),[f,x]=c.useState(""),[g,k]=c.useState(!1),[d,j]=c.useState(!1),[p,w]=c.useState(!1),[h,o]=c.useState(null),a=l==="SignInWithApple"?"SignInWithApple":"Google",N=()=>{x(""),j(!1),k(!1),w(!1),o(null)},L=async()=>{N();
1try{await(m==null?void 0:m())}catch(i){console.warn("Link account cancel cleanup failed:",i)}},R=i=>ie(i)?t("authLinking.linkAccountInvalidPassword"):re(i)?t("authLinking.linkAccountTempPasswordRequired"):oe(i)?t("authLinking.linkAccountAuthFlowError"):ce(i)?t("authLinking.linkAccountNativeMissing"):le(i)?t("authLinking.linkAccountMergeError"):t("authLinking.linkAccountServerError"),y=async()=>{if(!(s!=null&&s.includes("@"))){o(t("auth.unknownError"));return}if(!f){o(t("authLinking.linkAccountPassword"));return}k(!0),o(null);try{await X({email:s,password:f,provider:a}),j(!0),u==null||u()}catch(i){o(R(i))}finally{k(!1)}},C=async()=>{w(!0),o(null);try{try{await b({global:!0})}catch{try{await b()}catch{}}N(),r(),a==="SignInWithApple"?await J():await $()}catch(i){o(i instanceof Error?i.message:t("auth.socialLoginFailed")),w(!1)}};return e.jsx(q,{open:n,onOpenChange:i=>{!i&&!g&&!p&&L()},children:e.jsxs(z,{className:"sm:max-w-md",children:[e.jsxs(H,{children:[e.jsx(V,{children:t("authLinking.linkAccountTitle")}),e.jsx(B,{children:t(d?"authLinking.linkAccountSuccess":"authLinking.linkAccountDescription")})]}),s?e.jsx("p",{className:"text-sm font-medium truncate",children:s}):null,d?e.jsxs("div",{className:"space-y-4",children:[h?e.jsx("p",{className:"text-sm text-destructive",children:h}):null,e.jsx(S,{className:"w-full bg-[#FF902A] hover:bg-[#FF7A1A] text-white",onClick:C,disabled:p,children:p?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),t("auth.redirectingToProvider")]}):t(a==="SignInWithApple"?"auth.continueWithApple":"auth.continueWithGoogle")})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("authLinking.linkAccountTempPasswordHint")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(F,{htmlFor:"link-account-password",children:t("authLinking.linkAccountPassword")}),e.jsx(D,{id:"link-account-password",type:"password",value:f,disabled:g,onChange:i=>{x(i.target.value),o(null)},onKeyDown:i=>{i.key==="Enter"&&!g&&y()}})]}),h?e.jsx("p",{className:"text-sm text-destructive",children:h}):null,e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:"outline",className:"flex-1",onClick:()=>void L(),disabled:g,children:t("auth.back")}),e.jsx(S,{className:"flex-1 bg-[#FF902A] hover:bg-[#FF7A1A] text-white",onClick:()=>void y(),disabled:g,children:g?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),t("auth.verifying")]}):t("authLinking.linkAccountSubmit")})]})]})]})})},G="petwell.social.redirect",fe=()=>{const n=Y(),s=Z(),{t:l}=T(),{setIsAuthenticated:r,setRequiresProfileCompletion:u,setUserInfo:m}=ee(),{openPanel:t,triggerAuthSuccess:f}=se(),x=c.useRef(!1),[g,k]=c.useState(null),[d,j]=c.useState(!1),[p,w]=c.useState(!1),[h,o]=c.useState(null),a=()=>{typeof window<"u"&&window.sessionStorage.removeItem(G)},N=()=>typeof window>"u"?"/":window.sessionStorage.getItem(G)||"/",L=()=>{m(null),r(!1),u(!1)},R=async()=>{try{await b({global:!0})}catch{try{await b()}catch{}}};c.useEffect(()=>{if(x.current)return;x.current=!0,(async()=>{try{const A=new URLSearchParams(n.search),O=A.get("code"),M=A.get("state");if(!O||!M)throw new Error("Missing social login callback parameters.");const{userInfo:v,requiresProfileCompletion:I}=await te(O,M);m(v),r(!0),u(I);let E={canSetPassword:!1,needsAccountLink:!1,linkProvider:null};if(v.email)try{E=await ne(v.email,{currentSub:v.userId})}catch(K){console.warn("resolveSocialLinkingConflict failed after social login:",K),E={canSetPassword:!1,needsAccountLink:!0,linkProvider:"Google"}}if(E.needsAccountLink){r(!1),u(!1),o({email:v.email,provider:E.linkProvider||"Google"}),w(!0);return}if(E.canSetPassword&&!I){j(!0);return}const U=N();if(a(),I){t("PROFILE",v.email),s(U,{replace:!0});return}f(),s(U,{replace:!0})}catch(A){console.error("Error finishing social login:",A),L(),k(A instanceof Error?A.message:l("auth.socialLoginFailed"))}})()},[n.search,s,t,r,u,m,l,f]);const y=async()=>{w(!1),o(null),a(),L(),await R(),s("/",{replace:!0})},C=()=>{w(!1),o(null)},i=()=>{L()};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"container mx-auto flex min-h-[60vh] max-w-lg items-center justify-center px-4 py-16",children:e.jsx("div",{className:"w-full rounded-2xl border bg-background p-8 text-center shadow-sm",children:g?e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:l("auth.socialLoginFailed")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:g}),e.jsx(S,{onClick:()=>s("/",{replace:!0}),children:l("auth.returnHome")}
1)]}):p||d?e.jsxs("div",{className:"space-y-4",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:l("auth.finishingSocialLogin")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l(p?"authLinking.linkAccountTitle":"authLinking.setPasswordTitle")})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx(_,{className:"h-8 w-8 animate-spin text-primary"})}),e.jsx("h1",{className:"text-2xl font-semibold",children:l("auth.finishingSocialLogin")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l("auth.redirectingToProvider")})]})})}),e.jsx(ue,{open:p,email:(h==null?void 0:h.email)||"",provider:(h==null?void 0:h.provider)||"Google",onClose:C,onLinked:i,onCancel:y}),e.jsx(ae,{open:d,onClose:()=>{j(!1);const W=N();a(),f(),s(W,{replace:!0})}})]})};export{fe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.