@wacht/jsx 0.0.1-alpha.14 → 0.0.1-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1560,81 +1560,81 @@ See https://s-c.sh/2BAXzed for more info.`),window[Qr]+=1);const le=u.div`
1560
1560
  transform: rotate(360deg);
1561
1561
  }
1562
1562
  `,En=u.div`
1563
- max - width: 380px;
1564
- width: 380px;
1565
- padding: var(--space - 3xl);
1566
- background: var(--color - background);
1567
- border - radius: var(--radius - lg);
1568
- box - shadow: 0 4px 12px var(--color - shadow);
1563
+ max-width: 380px;
1564
+ width: 380px;
1565
+ padding: var(--space-3xl);
1566
+ background: var(--color-background);
1567
+ border-radius: var(--radius-lg);
1568
+ box-shadow: 0 4px 12px var(--color-shadow);
1569
1569
  `,ys=u.div`
1570
1570
  display: flex;
1571
- justify - content: center;
1572
- align - items: center;
1573
- min - height: 200px;
1571
+ justify-content: center;
1572
+ align-items: center;
1573
+ min-height: 200px;
1574
1574
 
1575
1575
  svg {
1576
1576
  animation: ${ig} 1s linear infinite;
1577
- color: var(--color - primary);
1577
+ color: var(--color-primary);
1578
1578
  }
1579
1579
  `,ws=u.div`
1580
- text - align: center;
1581
- margin - bottom: var(--space - 2xl);
1582
- position: relative;
1580
+ text-align: center;
1581
+ margin-bottom: var(--space-2xl);
1582
+ position: relative;
1583
1583
  `,js=u.h1`
1584
- font - size: var(--font - lg);
1585
- font - weight: 400;
1586
- color: var(--color - foreground);
1587
- margin - bottom: var(--space - xs);
1588
- margin - top: 0;
1584
+ font-size: var(--font-lg);
1585
+ font-weight: 400;
1586
+ color: var(--color-foreground);
1587
+ margin-bottom: var(--space-xs);
1588
+ margin-top: 0;
1589
1589
  `,ks=u.p`
1590
- color: var(--color - secondary - text);
1591
- font - size: var(--font - xs);
1590
+ color: var(--color-secondary-text);
1591
+ font-size: var(--font-xs);
1592
1592
  `,cg=u.div`
1593
1593
  position: relative;
1594
- text - align: center;
1595
- margin: var(--space - 2xl) 0;
1594
+ text-align: center;
1595
+ margin: var(--space-2xl) 0;
1596
1596
 
1597
1597
  &::before {
1598
1598
  content: "";
1599
1599
  position: absolute;
1600
- top: 50 %;
1600
+ top: 50%;
1601
1601
  left: 0;
1602
1602
  right: 0;
1603
1603
  height: 1px;
1604
- background: var(--color - border);
1604
+ background: var(--color-border);
1605
1605
  }
1606
1606
  `,lg=u.span`
1607
1607
  position: relative;
1608
- background: var(--color - background);
1609
- padding: 0 var(--space - md);
1610
- color: var(--color - muted);
1611
- font - size: var(--font - xs);
1612
- font - weight: 400;
1613
- text - transform: uppercase;
1614
- letter - spacing: 0.05em;
1608
+ background: var(--color-background);
1609
+ padding: 0 var(--space-md);
1610
+ color: var(--color-muted);
1611
+ font-size: var(--font-xs);
1612
+ font-weight: 400;
1613
+ text-transform: uppercase;
1614
+ letter-spacing: 0.05em;
1615
1615
  `,dg=u.div`
1616
1616
  position: relative;
1617
1617
  `,Er=u.p`
1618
- font - size: var(--font - 2xs);
1619
- color: var(--color - error);
1618
+ font-size: var(--font-2xs);
1619
+ color: var(--color-error);
1620
1620
  margin: 0;
1621
- margin - top: var(--space - 2xs);
1621
+ margin-top: var(--space-2xs);
1622
1622
  `,_s=u(K)`
1623
- margin - top: var(--space - lg);
1623
+ margin-top: var(--space-lg);
1624
1624
  `,Pn=u.div`
1625
- margin - top: var(--space - lg);
1626
- text - align: center;
1627
- font - size: var(--font - xs);
1628
- color: var(--color - secondary - text);
1625
+ margin-top: var(--space-lg);
1626
+ text-align: center;
1627
+ font-size: var(--font-xs);
1628
+ color: var(--color-secondary-text);
1629
1629
  `,Lt=u.span`
1630
- color: var(--color - primary);
1631
- text - decoration: none;
1632
- font - weight: 400;
1630
+ color: var(--color-primary);
1631
+ text-decoration: none;
1632
+ font-weight: 400;
1633
1633
  transition: color 0.2s;
1634
1634
  cursor: pointer;
1635
1635
 
1636
1636
  &:hover {
1637
- color: var(--color - primary - hover);
1637
+ color: var(--color-primary-hover);
1638
1638
  }
1639
1639
  `;function ug(){return e.jsx(vf,{children:e.jsx(pg,{})})}function pg(){var U,Z,Q,ae,oe,ce,Y,se,q,H;const{deployment:t}=ve(),{navigate:r}=He(),{session:o,loading:n}=Fe(),{setEmail:a,otpSent:s,setOtpSent:p,showForgotPassword:g,setShowForgotPassword:c,showOtherOptions:h,setShowOtherOptions:d,enabledSocialsProviders:l,firstFactor:m}=sl(),{loading:x,signIn:v,signinAttempt:w,discardSignInAttempt:C,error:$,setSignInAttempt:y}=Ar("generic"),{signIn:z}=Ar("oauth"),[_,k]=i.useState({email:"",username:"",password:"",phone:""}),[b,f]=i.useState({}),[I,j]=i.useState(!1),[S,R]=i.useState(""),[E,T]=i.useState("US"),[P,O]=i.useState(!1),D=A=>{let{name:B,value:L}=A.target;B==="phone"?L=L.replace(/[^0-9]/g,""):B==="email"&&(a(L),L=L.toLowerCase()),k(W=>({...W,[B]:L})),f(W=>({...W,[B]:""}))},M=()=>{k({email:"",username:"",password:"",phone:""}),f({}),T("US")},N=async A=>{if(A.preventDefault(),x||I)return;C();const B={};if(m==="email_password"?(_.email||(B.email="Email address is required"),_.password||(B.password="Password is required")):m==="username_password"?(_.username||(B.username="Username is required"),_.password||(B.password="Password is required")):m==="email_otp"||m==="email_magic_link"?_.email||(B.email="Email address is required"):m==="phone_otp"&&(_.phone?/^\d{7,15}$/.test(_.phone)||(B.phone="Phone number must contain 7-15 digits"):B.phone="Phone number is required"),f(B),Object.keys(B).length>0)return;let L="";switch(m){case"email_password":L="plain_email";break;case"username_password":L="plain_username";break;case"email_otp":L="email_otp";break;case"email_magic_link":L="magic_link";break;case"phone_otp":L="phone_otp";break}j(!0);try{const W={..._,strategy:L};m==="phone_otp"&&E&&(W.phone_country_code=E),await v.create(W)}catch(W){f({submit:W.message}),j(!1)}},F=async A=>{if(A.preventDefault(),x||I)return;const B={};if(!S){B.otp="OTP code is required",f(B);return}j(!0),f({});try{await v.completeVerification(S),p(!1),R("")}catch(L){f({otp:L.message||"Verification failed"})}finally{j(!1)}},J=async A=>{if(!(x||I)){j(!0);try{const L=new URLSearchParams(window.location.search).get("redirect_uri")||void 0,{data:W}=await z.create({provider:A.provider,redirectUri:L});W&&typeof W=="object"&&"oauth_url"in W&&(window.location.href=W.oauth_url)}catch(B){f({submit:B.message})}finally{j(!1)}}},ie=i.useRef(!1);if(i.useEffect(()=>{if(n)return;const A=new URLSearchParams(window.location.search),B=A.get("impersonation_token");if(B&&!w&&!x&&!ie.current){ie.current=!0,A.delete("impersonation_token");const W=A.toString()?`${window.location.pathname}?${A.toString()} `:window.location.pathname;window.history.replaceState({},"",W),(async()=>{try{j(!0),await v.create({strategy:"impersonation",token:B})}catch(pe){f({submit:pe.message}),j(!1),ie.current=!1}})();return}const L=A.get("signin_attempt_id");if(L&&(o!=null&&o.signin_attempts)&&!w){const W=o.signin_attempts.find(ee=>ee.id===L);if(W){y(W),A.delete("signin_attempt_id");const ee=A.toString()?`${window.location.pathname}?${A.toString()} `:window.location.pathname;window.history.replaceState({},"",ee)}}},[o,n,w,y,x]),i.useEffect(()=>{var W;if(!w)return;if(w.completed){O(!0);let ee=new URLSearchParams(window.location.search).get("redirect_uri");if(ee||(ee=((W=t==null?void 0:t.ui_settings)==null?void 0:W.after_signin_redirect_url)||null),!ee&&(t!=null&&t.frontend_host)&&(ee=`https://${t.frontend_host}`),ee){const pe=new URL(ee);(t==null?void 0:t.mode)==="staging"&&pe.searchParams.set("__dev_session__",localStorage.getItem("__dev_session__")||""),r(pe.toString())}return}if(!v||s)return;const B={verify_email:"email_otp",verify_email_otp:"email_otp",verify_email_link:"magic_link",verify_phone:"phone_otp",verify_phone_otp:"phone_otp"}[w.current_step];if(!B)return;(async()=>{try{await v.prepareVerification({strategy:B}),p(!0)}catch(ee){console.error("Failed to prepare verification:",ee),f({submit:"Failed to send verification. Please try again."})}finally{j(!1)}})()},[w,v,s,p,r,t]),i.useEffect(()=>{const A={};if($!=null&&$.errors&&Array.isArray($==null?void 0:$.errors))for(const B of $.errors)sg.has(B.code)&&(A.submit=B.message);f(A)},[$]),h)return e.jsx(Ef,{onBack:()=>d(!1)});if(g)return e.jsx(kf,{onBack:()=>c(!1)});if((w==null?void 0:w.current_step)==="verify_second_factor")return e.jsx(dl,{attempt:w,completeVerification:v.completeVerification,prepareVerification:v.prepareVerification,onBack:()=>{C(),M(),p(!1)}});if((w==null?void 0:w.current_step)==="complete_profile")return e.jsx(ul,{attempt:w,completeProfile:v.completeProfile,completeVerification:v.completeVerification,prepareVerification:v.prepareVerification,onBack:()=>{C(),M(),p(!1)}});if(n)return e.jsx(le,{children:e.jsxs(En,{children:[e.jsx(Ae,{}),e.jsx(ys,{children:e.jsx(vr,{size:32})})]})});if(P)return e.jsx(le,{children:e.jsxs(En,{children:[e.jsx(Ae,{}),e.jsx(ys,{children:e.jsx(vr,{size:32})})]})});const X=(w==null?void 0:w.current_step)&&["verify_email","verify_email_otp","verify_email_link","verify_phone","verify_phone_otp"].includes(w.current_step)&&s;return e.jsx(le,{children:e.jsxs(En,{children:[e.jsx(Ae,{}),X?e.jsx(e.Fragment,{children:e.jsxs(ws,{children:[e.jsx(js,{children:m==="phone_otp"?"Check your phone":"Check your email"}),e.jsx(ks,{children:m==="email_magic_link"?`If ${_.email} exists in our records, you will receive a magic link. Click the link to sign in.`:m==="phone_otp"?`If ${_.phone} exists in our records, you will receive a verification code via SMS. Enter it below to continue.`:`If ${_.email} exists in our records, you will receive a verification code. Enter it below to continue.`})]})}):e.jsxs(ws,{children:[e.jsx(js,{children:"Sign in to your account"}),e.jsxs(ks,{children:["Please enter your details to continue to"," ",(t==null?void 0:t.ui_settings.app_name)||"App","!"]})]}),X?m==="email_magic_link"?e.jsxs(Pn,{children:["Having trouble?"," ",e.jsx(Lt,{children:e.jsx(tt,{to:t.ui_settings.support_page_url,children:"Get help"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Lt,{onClick:()=>{p(!1),C(),M()},style:{cursor:"pointer"},children:"Back to login"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs(dt,{style:{gap:"15px"},onSubmit:F,noValidate:!0,children:[e.jsx(Rt,{onComplete:async A=>{if(R(A),A&&A.length===6){j(!0),f({});try{await v.completeVerification(A),p(!1)}catch(B){f({otp:B.message||"Verification failed"})}finally{j(!1)}}},onResend:async()=>{const A=m==="email_otp"?"email_otp":"phone_otp";await v.prepareVerification({strategy:A})},error:b.otp,isSubmitting:I}),e.jsx(_s,{type:"submit",disabled:I||x||!S,style:{margin:0},children:I?"Verifying...":`Continue to ${(H=t==null?void 0:t.ui_settings)==null?void 0:H.app_name}`})]}),e.jsxs(Pn,{children:["Having trouble?"," ",e.jsx(Lt,{children:e.jsx(tt,{to:t.ui_settings.support_page_url,children:"Get help"})}),e.jsx("div",{style:{marginTop:"var(--space-sm)"},children:e.jsx(Lt,{onClick:()=>{p(!1),C(),M()},style:{cursor:"pointer"},children:"Back to login"})})]})]}):e.jsxs(e.Fragment,{children:[l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(wa,{connections:l,callback:J}),e.jsx(cg,{children:e.jsx(lg,{children:"or"})})]}),e.jsxs(dt,{onSubmit:N,noValidate:!0,children:[(m==="email_password"||m==="email_otp"||m==="email_magic_link")&&((Z=(U=t==null?void 0:t.auth_settings)==null?void 0:U.email_address)==null?void 0:Z.enabled)&&e.jsxs(he,{children:[e.jsx(ue,{htmlFor:"email",children:"Email address"}),e.jsx(de,{type:"email",id:"email",name:"email",value:_.email,onChange:D,placeholder:"Enter your email address","aria-invalid":!!b.email}),b.email&&e.jsx(Er,{children:b.email})]}),m==="username_password"&&((ae=(Q=t==null?void 0:t.auth_settings)==null?void 0:Q.username)==null?void 0:ae.enabled)&&e.jsxs(he,{children:[e.jsx(ue,{htmlFor:"username",children:"Username"}),e.jsx(de,{type:"text",id:"username",name:"username",value:_.username,onChange:D,placeholder:"Enter your username","aria-invalid":!!b.username}),b.username&&e.jsx(Er,{children:b.username})]}),m==="phone_otp"&&((ce=(oe=t==null?void 0:t.auth_settings)==null?void 0:oe.phone_number)==null?void 0:ce.enabled)&&e.jsxs(he,{children:[e.jsx(ue,{htmlFor:"phone",children:"Phone number"}),e.jsx(Br,{value:_.phone,onChange:D,error:b.phone,countryCode:E,setCountryCode:T}),b.phone&&e.jsx(Er,{children:b.phone})]}),(m==="email_password"||m==="username_password")&&((se=(Y=t==null?void 0:t.auth_settings)==null?void 0:Y.password)==null?void 0:se.enabled)&&e.jsxs(he,{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between"},children:[e.jsx(ue,{htmlFor:"password",children:"Password"}),e.jsx(Lt,{style:{fontSize:"12px"},onClick:()=>c(!0),children:"Forgot password?"})]}),e.jsx(dg,{children:e.jsx(de,{type:"password",id:"password",name:"password",value:_.password,onChange:D,placeholder:"Enter your password","aria-invalid":!!b.password})}),b.password&&e.jsx(Er,{children:b.password})]}),e.jsxs("div",{children:[b.submit&&e.jsx(Er,{children:b.submit}),e.jsx(_s,{type:"submit",disabled:I||x,children:I?"Signing in...":"Sign in"})]}),e.jsx(Lt,{style:{fontSize:"12px",textAlign:"center"},onClick:()=>d(!0),children:"Use other methods"})]}),e.jsxs(Pn,{children:["Don't have an account?"," ",e.jsx(Lt,{children:e.jsx(tt,{to:`${(q=t.ui_settings)==null?void 0:q.sign_up_page_url}${window.location.search}`,children:"Sign up"})})]})]})]})})}const Cs=u.div`
1640
1640
  max-width: 380px;
@@ -3922,13 +3922,21 @@ cursor: pointer;
3922
3922
  gap: 12px;
3923
3923
  margin-bottom: 0;
3924
3924
  `,U0=()=>e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",style:{color:"var(--color-secondary-text)"},children:[e.jsx("circle",{cx:"12",cy:"12",r:"11",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.5",opacity:"0.6"}),e.jsx("circle",{cx:"12",cy:"12",r:"8",fill:"none",stroke:"currentColor",strokeWidth:"0.5",opacity:"0.3"}),e.jsx("path",{d:"M12 8c-2.2 0-4 1.8-4 4s1.8 4 4 4 4-1.8 4-4-1.8-4-4-4zm0 6c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z",fill:"currentColor",opacity:"0.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor"}),e.jsx("text",{x:"12",y:"16.5",textAnchor:"middle",fill:"currentColor",fontSize:"6",opacity:"0.7",children:"?"})]}),W0=({browser:t})=>{const r=(t==null?void 0:t.toLowerCase())||"",o={width:20,height:20};return r.includes("chrome")?e.jsx(R0,{...o}):r.includes("firefox")?e.jsx(I0,{...o}):r.includes("safari")?e.jsx(T0,{...o}):r.includes("edge")?e.jsx(O0,{...o}):r.includes("opera")?e.jsx(M0,{...o}):r.includes("brave")?e.jsx(L0,{...o}):e.jsx(U0,{})},V0=()=>{const[t,r]=i.useState(null),{signins:o,removeSignin:n,refetch:a,loading:s}=tc(),{refetch:p}=Fe(),{toast:g}=It(),c=o,h=async l=>{try{await n(l),await Promise.all([a(),p()]),r(null),g("Session ended successfully","info")}catch(m){g(m.message||"Failed to end session. Please try again.","error")}},d=l=>{if(!l||l.trim()==="")return"Unknown";const m=new Date(l);if(isNaN(m.getTime()))return"Unknown";const v=Math.floor((new Date().getTime()-m.getTime())/(1e3*60));return v<1?"Just now":v<60?`${v}m ago`:v<1440?`${Math.floor(v/60)}h ago`:m.toLocaleDateString()};return s?e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"20px"},children:e.jsx(Re,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:0},children:"Active Sessions"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Manage your active browser sessions and sign-ins"})]}),e.jsx("div",{children:c&&c.length>0?e.jsxs(jt,{children:[e.jsx(kt,{children:e.jsxs(Ue,{children:[e.jsx(Ce,{children:"Browser & Device"}),e.jsx(Ce,{children:"Location"}),e.jsx(Ce,{children:"Last Active"}),e.jsx(Ce,{})]})}),e.jsx(_t,{children:c.map(l=>e.jsxs(Ue,{children:[e.jsx(Oe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(Al,{children:e.jsx(W0,{browser:l.browser||"Unknown"})}),e.jsxs("div",{children:[e.jsx("div",{children:l.browser||"Unknown Browser"}),l.device&&e.jsx("div",{style:{fontSize:"12px",color:"var(--color-muted)"},children:l.device})]})]})}),e.jsx(Oe,{children:e.jsxs("div",{children:[e.jsx("div",{children:l.city&&l.country?`${l.city}, ${l.country}`:"Unknown location"}),l.ip_address&&e.jsx("div",{style:{fontSize:"12px",color:"var(--color-muted)"},children:l.ip_address})]})}),e.jsx(Oe,{children:d(l.last_active_at)}),e.jsx(Ct,{children:e.jsxs(ot,{open:t===l.id,openChange:m=>r(m?l.id:null),children:[e.jsx(at,{children:e.jsx(nn,{children:"•••"})}),e.jsx(nt,{children:e.jsx(Pe,{onClick:()=>h(l.id),children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(zt,{size:14}),"End Session"]})})})]})})]},l.id))})]}):e.jsx(it,{title:"No active sessions",description:"You don't have any active sessions at the moment."})})]})},G0=()=>{var b,f,I,j;const{deployment:t}=ve(),{toast:r}=It(),[o,n]=i.useState(null),[a,s]=i.useState(""),[p,g]=i.useState(!1),[c,h]=i.useState(null),[d,l]=i.useState(""),m=i.useRef(null),x=i.useRef({}),{user:v,createEmailAddress:w,deleteEmailAddress:C,prepareEmailVerification:$,attemptEmailVerification:y,makeEmailPrimary:z}=rr();if(!((f=(b=t==null?void 0:t.auth_settings)==null?void 0:b.email_address)!=null&&f.enabled))return null;const _=async S=>{try{if(S===(v==null?void 0:v.primary_email_address_id)){r("Cannot delete primary email address. Please set another email as primary first.","error");return}await C(S),v.refetch(),r("Email address deleted successfully","info")}catch(R){r(R.message||"Failed to delete email address. Please try again.","error")}},k=i.useMemo(()=>v!=null&&v.user_email_addresses?d.trim()?v.user_email_addresses.filter(S=>S.email.toLowerCase().includes(d.toLowerCase())):v.user_email_addresses:[],[v==null?void 0:v.user_email_addresses,d]);return e.jsxs(e.Fragment,{children:[e.jsxs(Bo,{style:{marginBottom:"20px"},children:[e.jsx(wt,{value:d,onChange:l,placeholder:"Search Email"}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:m,onClick:()=>g(!0),style:{padding:"8px 16px",borderRadius:"6px",fontSize:"14px",fontWeight:500,height:"36px"},children:"Add Email"}),p&&e.jsx(ti,{triggerRef:m,onClose:()=>g(!1),onAddEmail:async S=>{const R=await w(S);s(R.data.id),await $(R.data.id),v.refetch()},onPrepareVerification:async()=>{await $(a),v.refetch()},onAttemptVerification:async S=>{await y(a,S),v.refetch(),g(!1),s(""),r("Email added and verified successfully!","info")}})]})]}),k!=null&&k.length?e.jsxs(jt,{children:[e.jsx(kt,{children:e.jsxs(Ue,{children:[e.jsx(Ce,{children:"Email Address"}),e.jsx(Ce,{children:"Status"}),e.jsx(Ce,{})]})}),e.jsx(_t,{children:k.map(S=>e.jsxs(Ue,{children:[e.jsx(Oe,{children:S.email}),e.jsx(Oe,{children:S.id===(v==null?void 0:v.primary_email_address_id)?"Primary":S.verified?"Verified":"Not Verified"}),e.jsx(Ct,{children:S.id!==(v==null?void 0:v.primary_email_address_id)||!S.verified?e.jsxs(ot,{open:o===S.id,openChange:R=>n(R?S.id:null),children:[e.jsx(at,{children:e.jsx(nn,{ref:R=>{R&&(x.current[S.id]=R)},children:"•••"})}),e.jsxs(nt,{children:[S.id!==(v==null?void 0:v.primary_email_address_id)&&S.verified&&e.jsx(Pe,{onClick:async()=>{try{await z(S.id),v.refetch(),n(null),r("Primary email updated successfully","info")}catch(R){r(R.message||"Failed to update primary email","error")}},children:"Make primary"}),!S.verified&&e.jsx(Pe,{onClick:async()=>{n(null),await $(S.id),h(S.id)},children:"Verify email"}),S.id!==(v==null?void 0:v.primary_email_address_id)&&e.jsx(Pe,{$destructive:!0,onClick:()=>{_(S.id),n(null)},children:"Remove"})]})]}):null})]},S.id))})]}):e.jsx(it,{title:d?"No emails match your search":"No email addresses",description:"Add an email address to get started."}),c&&e.jsx(ti,{existingEmail:(j=(I=v==null?void 0:v.user_email_addresses)==null?void 0:I.find(S=>S.id===c))==null?void 0:j.email,triggerRef:{current:x.current[c]},onClose:()=>h(null),onAddEmail:async()=>{},onPrepareVerification:async()=>{await $(c),v.refetch()},onAttemptVerification:async S=>{await y(c,S),v.refetch(),h(null),r("Email verified successfully!","info")}})]})},H0=()=>{var k,b,f,I;const{deployment:t}=ve(),[r,o]=i.useState(null),[n,a]=i.useState(""),[s,p]=i.useState(!1),[g,c]=i.useState(null),[h,d]=i.useState(""),l=i.useRef(null),m=i.useRef({}),{user:x,createPhoneNumber:v,deletePhoneNumber:w,preparePhoneVerification:C,attemptPhoneVerification:$,makePhonePrimary:y}=rr();if(!((b=(k=t==null?void 0:t.auth_settings)==null?void 0:k.phone_number)!=null&&b.enabled))return null;const z=j=>{const S=Eo.find(R=>R.dialCode===j);return(S==null?void 0:S.flag)||"🌍"},_=i.useMemo(()=>x!=null&&x.user_phone_numbers?h.trim()?x.user_phone_numbers.filter(j=>j.phone_number.toLowerCase().includes(h.toLowerCase())):x.user_phone_numbers:[],[x==null?void 0:x.user_phone_numbers,h]);return e.jsxs(e.Fragment,{children:[e.jsxs(Bo,{style:{marginBottom:"20px"},children:[e.jsx(wt,{value:h,onChange:d,placeholder:"Search Phone"}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:l,onClick:()=>p(!0),style:{padding:"8px 16px",borderRadius:"6px",fontSize:"14px",fontWeight:500,height:"36px"},children:"Add Phone"}),s&&e.jsx(ni,{triggerRef:l,onClose:()=>p(!1),onAddPhone:async(j,S)=>{const R=await v(j,S);a(R.data.id),await C(R.data.id)},onPrepareVerification:async()=>{await C(n),x.refetch()},onAttemptVerification:async j=>{await $(n,j),x.refetch(),p(!1)}}),g&&e.jsx(ni,{existingPhone:(I=(f=x==null?void 0:x.user_phone_numbers)==null?void 0:f.find(j=>j.id===g))==null?void 0:I.phone_number,triggerRef:{current:m.current[g]},onClose:()=>c(null),onAddPhone:async()=>{},onPrepareVerification:async()=>{await C(g),x.refetch()},onAttemptVerification:async j=>{await $(g,j),x.refetch(),c(null)}})]})]}),_!=null&&_.length?e.jsxs(jt,{children:[e.jsx(kt,{children:e.jsxs(Ue,{children:[e.jsx(Ce,{children:"Phone Number"}),e.jsx(Ce,{children:"Status"}),e.jsx(Ce,{})]})}),e.jsx(_t,{children:_.map(j=>e.jsxs(Ue,{children:[e.jsx(Oe,{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx("span",{style:{fontSize:"18px"},children:z(j.country_code)}),e.jsx("span",{children:j.country_code}),e.jsx("span",{children:j.phone_number})]})}),e.jsx(Oe,{children:j.id===(x==null?void 0:x.primary_phone_number_id)?"Primary":j.verified?"Verified":"Not Verified"}),e.jsx(Ct,{children:e.jsxs(ot,{open:r===j.id,openChange:S=>o(S?j.id:null),children:[e.jsx(at,{children:e.jsx(nn,{ref:S=>{S&&(m.current[j.id]=S)},children:"•••"})}),e.jsxs(nt,{children:[j.id!==(x==null?void 0:x.primary_phone_number_id)&&j.verified&&e.jsx(Pe,{onClick:async()=>{await y(j.id),o(null),x.refetch()},children:"Make primary"}),!j.verified&&e.jsx(Pe,{onClick:async()=>{await C(j.id),c(j.id),o(null)},children:"Verify phone"}),e.jsx(Pe,{$destructive:!0,onClick:async()=>{await w(j.id),o(null),x.refetch()},children:"Remove"})]})]})})]},j.id))})]}):e.jsx(it,{title:h?"No phones match your search":"No phone numbers",description:"Add a phone number to get started."})]})},Al=u.div`
3925
+ width: 20px;
3926
+ height: 20px;
3927
+ flex-shrink: 0;
3928
+ display: flex;
3929
+ align-items: center;
3930
+ justify-content: center;
3931
+ overflow: hidden;
3932
+
3925
3933
  svg {
3926
3934
  width: 20px;
3927
3935
  height: 20px;
3928
3936
  flex-shrink: 0;
3929
3937
  display: block;
3930
3938
  }
3931
- `,q0=()=>{const{user:t,disconnectSocialConnection:r,connectSocialAccount:o}=rr(),{deployment:n}=ve(),a={google_oauth:{icon:e.jsx(Dc,{}),label:"Google"},microsoft_oauth:{icon:e.jsx(Ac,{}),label:"Microsoft"},github_oauth:{icon:e.jsx(Lc,{}),label:"GitHub"},gitlab_oauth:{icon:e.jsx(Bc,{}),label:"GitLab"},linkedin_oauth:{icon:e.jsx(Fc,{}),label:"LinkedIn"},discord_oauth:{icon:e.jsx(Uc,{}),label:"Discord"},x_oauth:{icon:e.jsx(Nc,{}),label:"X"}},s=(n==null?void 0:n.social_connections.filter(p=>p.enabled))||[];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h3",{style:{fontSize:"16px",margin:"0 0 6px 0",letterSpacing:"-0.01em",color:"var(--color-foreground)"},children:"Connected Accounts"}),e.jsx("p",{style:{fontSize:"13px",margin:0,lineHeight:"1.5",color:"var(--color-muted)"},children:"Connect social accounts for easy sign-in and profile sync"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:s.map((p,g)=>{var d;const c=((d=t==null?void 0:t.social_connections)==null?void 0:d.filter(l=>l.provider===p.provider))||[],h=a[p.provider];return h?e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0",minHeight:"58px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:"var(--color-foreground)"},children:[e.jsx(Al,{children:h.icon}),e.jsx("div",{style:{fontSize:"14px",fontWeight:500},children:h.label})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",gap:"8px"},children:[c.map(l=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"6px",padding:"4px 8px",fontSize:"13px",color:"var(--color-muted)"},children:[e.jsx("span",{children:l.email_address}),e.jsx(nn,{onClick:async()=>{await r(l.id.toString()),t.refetch()},style:{padding:"2px"},children:e.jsx(Ke,{size:14})})]},l.id)),c.length>0?e.jsx(K,{onClick:()=>{o({provider:p.provider,redirectUri:window.location.href})},style:{padding:"6px 24px",fontSize:"13px"},children:"Add"}):e.jsx(K,{onClick:()=>{o({provider:p.provider,redirectUri:window.location.href})},style:{padding:"6px 14px",fontSize:"13px"},children:"Connect"})]})]}),g<s.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)"}})]},p.provider):null})})]})},Dl=()=>{var x,v,w,C,$,y;const{loading:t}=rr(),{deployment:r}=ve(),[o,n]=i.useState("profile"),[a,s]=i.useState(null),[p,g]=i.useState("info"),c=i.useCallback((z,_="info")=>{s(z),g(_),setTimeout(()=>s(null),3e3)},[s]);if(t)return e.jsx(le,{children:e.jsx(di,{style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(Re,{})})});const h=r==null?void 0:r.auth_settings,d=(x=h==null?void 0:h.email_address)==null?void 0:x.enabled,l=(v=h==null?void 0:h.phone_number)==null?void 0:v.enabled,m=((w=h==null?void 0:h.password)==null?void 0:w.enabled)||((C=h==null?void 0:h.auth_factors_enabled)==null?void 0:C.authenticator)||(($=h==null?void 0:h.auth_factors_enabled)==null?void 0:$.phone_otp)||((y=h==null?void 0:h.auth_factors_enabled)==null?void 0:y.backup_code);return e.jsx(le,{children:e.jsx(D0,{children:e.jsx(kr.Provider,{value:{screen:null,setScreen:()=>{},toast:c},children:e.jsxs(di,{children:[e.jsx(N0,{children:e.jsxs(F0,{children:[e.jsx(dr,{$isActive:o==="profile",onClick:()=>n("profile"),children:e.jsxs(ur,{children:[e.jsx(Mo,{size:16}),"Profile"]})}),d&&e.jsx(dr,{$isActive:o==="email",onClick:()=>n("email"),children:e.jsxs(ur,{children:[e.jsx(Wr,{size:16}),"Email"]})}),l&&e.jsx(dr,{$isActive:o==="phone",onClick:()=>n("phone"),children:e.jsxs(ur,{children:[e.jsx(Rh,{size:16}),"Phone"]})}),e.jsx(dr,{$isActive:o==="social",onClick:()=>n("social"),children:e.jsxs(ur,{children:[e.jsx(wh,{size:16}),"Connections"]})}),m&&e.jsx(dr,{$isActive:o==="security",onClick:()=>n("security"),children:e.jsxs(ur,{children:[e.jsx(Xo,{size:16}),"Security"]})}),e.jsx(dr,{$isActive:o==="sessions",onClick:()=>n("sessions"),children:e.jsxs(ur,{children:[e.jsx(Zp,{size:16}),"Sessions"]})})]})}),e.jsxs(B0,{children:[o==="profile"&&e.jsx(Z0,{}),o==="email"&&d&&e.jsx(G0,{}),o==="phone"&&l&&e.jsx(H0,{}),o==="social"&&e.jsx(q0,{}),o==="security"&&m&&e.jsx(Y0,{}),o==="sessions"&&e.jsx(V0,{})]}),a&&e.jsx("div",{style:{position:"absolute",bottom:"20px",right:"20px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"8px",padding:"12px 16px",boxShadow:"0 4px 12px var(--color-shadow)",animation:"slideUp 0.3s ease-out"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[p==="error"?e.jsx(ut,{size:16,color:"var(--color-error)"}):e.jsx(rt,{size:16,color:"var(--color-success)"}),e.jsx("span",{style:{fontSize:"14px",color:"var(--color-foreground)"},children:a})]})})]})})})})},Y0=()=>{var ne,ye,be;const{deployment:t}=ve(),{user:r,updatePassword:o,removePassword:n,setupAuthenticator:a,verifyAuthenticator:s,deleteAuthenticator:p,generateBackupCodes:g,regenerateBackupCodes:c,updateProfile:h}=rr(),{toast:d}=It(),[l,m]=i.useState((r==null?void 0:r.second_factor_policy)||"none"),[x,v]=i.useState(!1),w=async te=>{try{await h({second_factor_policy:te}),m(te),d("Second factor policy updated successfully","info")}catch($e){d($e.message||"Failed to update second factor policy","error")}},[C,$]=i.useState(!1),[y,z]=i.useState(!1),[_,k]=i.useState(!1),[b,f]=i.useState(!1),I=i.useRef(null),j=i.useRef(null),S=i.useRef(null),R=i.useRef(null),[E,T]=i.useState("table"),[P,O]=i.useState(""),[D,M]=i.useState(""),[N,F]=i.useState(""),[J,ie]=i.useState(["",""]),[re,X]=i.useState([]),[U,Z]=i.useState(!1),[Q,ae]=i.useState(!1),[oe]=i.useState(!1),[ce,Y]=i.useState(!1),se=(ne=t==null?void 0:t.auth_settings)==null?void 0:ne.auth_factors_enabled,q=(be=(ye=t==null?void 0:t.auth_settings)==null?void 0:ye.password)==null?void 0:be.enabled;if(!(se!=null&&se.authenticator)&&!(se!=null&&se.backup_code)&&!q)return null;const H=async(te,$e)=>{await o(te,$e),await r.refetch(),d("Password updated successfully","info")},A=async te=>{await n(te),await r.refetch(),d("Password removed successfully","info")},B=()=>{var Ee,or,nr,Vr,za,Ea;if(!r)return!1;const te=(Ee=r.user_email_addresses)==null?void 0:Ee.some(_r=>_r.verified),$e=(or=r.user_phone_numbers)==null?void 0:or.some(_r=>_r.verified),fe=r.social_connections&&r.social_connections.length>0,ke=t==null?void 0:t.auth_settings;return(ke==null?void 0:ke.first_factor)==="email_otp"&&te||((nr=ke==null?void 0:ke.magic_link)==null?void 0:nr.enabled)&&te||((Vr=ke==null?void 0:ke.passkey)==null?void 0:Vr.enabled)||((za=ke==null?void 0:ke.auth_factors_enabled)==null?void 0:za.phone_otp)&&$e||fe&&((Ea=t==null?void 0:t.social_connections)==null?void 0:Ea.some(_r=>_r.enabled))},L=async()=>{if(J.some(te=>te.length!==6)){d("Please enter both 6-digit verification codes","error");return}try{if(ae(!0),await s(N,J),await r.refetch(),se!=null&&se.backup_code){const te=await g();X(te),await r.refetch(),T("backup")}else T("success")}catch(te){d(te.message||"Invalid verification codes","error")}finally{ae(!1)}},W=()=>{T("table"),O(""),M(""),F(""),ie(["",""]),X([]),d("Two-factor authentication setup completed successfully!","info")},ee=async()=>{var te;if((te=r==null?void 0:r.user_authenticator)!=null&&te.id)try{Y(!0),await p(r.user_authenticator.id),await r.refetch(),v(!1),d("Two-factor authentication removed successfully","info")}catch($e){d($e.message||"Failed to remove authenticator","error")}finally{Y(!1)}},pe=async()=>{if(!U)try{Z(!0);const te=await c();X(te),await r.refetch(),f(!0),d("New backup codes generated","info")}catch(te){d(te.message||"Failed to generate backup codes","error")}finally{Z(!1)}},Se=()=>{const te=re.join(`
3939
+ `,q0=()=>{const{user:t,disconnectSocialConnection:r,connectSocialAccount:o}=rr(),{deployment:n}=ve(),a={google_oauth:{icon:e.jsx(Dc,{}),label:"Google"},microsoft_oauth:{icon:e.jsx(Ac,{}),label:"Microsoft"},github_oauth:{icon:e.jsx(Lc,{}),label:"GitHub"},gitlab_oauth:{icon:e.jsx(Bc,{}),label:"GitLab"},linkedin_oauth:{icon:e.jsx(Fc,{}),label:"LinkedIn"},discord_oauth:{icon:e.jsx(Uc,{}),label:"Discord"},x_oauth:{icon:e.jsx(Nc,{}),label:"X"}},s=(n==null?void 0:n.social_connections.filter(p=>p.enabled))||[];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx("h3",{style:{fontSize:"16px",margin:"0 0 6px 0",letterSpacing:"-0.01em",color:"var(--color-foreground)"},children:"Connected Accounts"}),e.jsx("p",{style:{fontSize:"13px",margin:0,lineHeight:"1.5",color:"var(--color-muted)"},children:"Connect social accounts for easy sign-in and profile sync"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:s.map((p,g)=>{var d;const c=((d=t==null?void 0:t.social_connections)==null?void 0:d.filter(l=>l.provider===p.provider))||[],h=a[p.provider];return h?e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0",minHeight:"58px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:"var(--color-foreground)"},children:[e.jsx(Al,{children:h.icon}),e.jsx("div",{style:{fontSize:"14px",fontWeight:500},children:h.label})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-end",gap:"8px"},children:[c.map(l=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"6px",padding:"4px 8px",fontSize:"13px",color:"var(--color-muted)"},children:[e.jsx("span",{children:l.email_address}),e.jsx(nn,{onClick:async()=>{await r(l.id.toString()),t.refetch()},style:{padding:"2px"},children:e.jsx(Ke,{size:14})})]},l.id)),c.length>0?e.jsx(K,{onClick:()=>{o({provider:p.provider,redirectUri:window.location.href})},style:{padding:"6px 24px",fontSize:"13px"},children:"Add"}):e.jsx(K,{onClick:()=>{o({provider:p.provider,redirectUri:window.location.href})},style:{padding:"6px 14px",fontSize:"13px"},children:"Connect"})]})]}),g<s.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)"}})]},p.provider):null})})]})},Dl=()=>{var v,w,C,$,y,z,_;const{loading:t}=rr(),{deployment:r}=ve(),[o,n]=i.useState("profile"),[a,s]=i.useState(null),[p,g]=i.useState("info"),c=i.useCallback((k,b="info")=>{s(k),g(b),setTimeout(()=>s(null),3e3)},[s]);if(t)return e.jsx(le,{children:e.jsx(di,{style:{display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(Re,{})})});const h=r==null?void 0:r.auth_settings,d=(v=h==null?void 0:h.email_address)==null?void 0:v.enabled,l=(w=h==null?void 0:h.phone_number)==null?void 0:w.enabled,m=((C=r==null?void 0:r.social_connections)==null?void 0:C.some(k=>k.enabled))||!1,x=(($=h==null?void 0:h.password)==null?void 0:$.enabled)||((y=h==null?void 0:h.auth_factors_enabled)==null?void 0:y.authenticator)||((z=h==null?void 0:h.auth_factors_enabled)==null?void 0:z.phone_otp)||((_=h==null?void 0:h.auth_factors_enabled)==null?void 0:_.backup_code);return e.jsx(le,{children:e.jsx(D0,{children:e.jsx(kr.Provider,{value:{screen:null,setScreen:()=>{},toast:c},children:e.jsxs(di,{children:[e.jsx(N0,{children:e.jsxs(F0,{children:[e.jsx(dr,{$isActive:o==="profile",onClick:()=>n("profile"),children:e.jsxs(ur,{children:[e.jsx(Mo,{size:16}),"Profile"]})}),d&&e.jsx(dr,{$isActive:o==="email",onClick:()=>n("email"),children:e.jsxs(ur,{children:[e.jsx(Wr,{size:16}),"Email"]})}),l&&e.jsx(dr,{$isActive:o==="phone",onClick:()=>n("phone"),children:e.jsxs(ur,{children:[e.jsx(Rh,{size:16}),"Phone"]})}),m&&e.jsx(dr,{$isActive:o==="social",onClick:()=>n("social"),children:e.jsxs(ur,{children:[e.jsx(wh,{size:16}),"Connections"]})}),x&&e.jsx(dr,{$isActive:o==="security",onClick:()=>n("security"),children:e.jsxs(ur,{children:[e.jsx(Xo,{size:16}),"Security"]})}),e.jsx(dr,{$isActive:o==="sessions",onClick:()=>n("sessions"),children:e.jsxs(ur,{children:[e.jsx(Zp,{size:16}),"Sessions"]})})]})}),e.jsxs(B0,{children:[o==="profile"&&e.jsx(Z0,{}),o==="email"&&d&&e.jsx(G0,{}),o==="phone"&&l&&e.jsx(H0,{}),o==="social"&&m&&e.jsx(q0,{}),o==="security"&&x&&e.jsx(Y0,{}),o==="sessions"&&e.jsx(V0,{})]}),a&&e.jsx("div",{style:{position:"absolute",bottom:"20px",right:"20px",background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"8px",padding:"12px 16px",boxShadow:"0 4px 12px var(--color-shadow)",animation:"slideUp 0.3s ease-out"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[p==="error"?e.jsx(ut,{size:16,color:"var(--color-error)"}):e.jsx(rt,{size:16,color:"var(--color-success)"}),e.jsx("span",{style:{fontSize:"14px",color:"var(--color-foreground)"},children:a})]})})]})})})})},Y0=()=>{var ne,ye,be;const{deployment:t}=ve(),{user:r,updatePassword:o,removePassword:n,setupAuthenticator:a,verifyAuthenticator:s,deleteAuthenticator:p,generateBackupCodes:g,regenerateBackupCodes:c,updateProfile:h}=rr(),{toast:d}=It(),[l,m]=i.useState((r==null?void 0:r.second_factor_policy)||"none"),[x,v]=i.useState(!1),w=async te=>{try{await h({second_factor_policy:te}),m(te),d("Second factor policy updated successfully","info")}catch($e){d($e.message||"Failed to update second factor policy","error")}},[C,$]=i.useState(!1),[y,z]=i.useState(!1),[_,k]=i.useState(!1),[b,f]=i.useState(!1),I=i.useRef(null),j=i.useRef(null),S=i.useRef(null),R=i.useRef(null),[E,T]=i.useState("table"),[P,O]=i.useState(""),[D,M]=i.useState(""),[N,F]=i.useState(""),[J,ie]=i.useState(["",""]),[re,X]=i.useState([]),[U,Z]=i.useState(!1),[Q,ae]=i.useState(!1),[oe]=i.useState(!1),[ce,Y]=i.useState(!1),se=(ne=t==null?void 0:t.auth_settings)==null?void 0:ne.auth_factors_enabled,q=(be=(ye=t==null?void 0:t.auth_settings)==null?void 0:ye.password)==null?void 0:be.enabled;if(!(se!=null&&se.authenticator)&&!(se!=null&&se.backup_code)&&!q)return null;const H=async(te,$e)=>{await o(te,$e),await r.refetch(),d("Password updated successfully","info")},A=async te=>{await n(te),await r.refetch(),d("Password removed successfully","info")},B=()=>{var Ee,or,nr,Vr,za,Ea;if(!r)return!1;const te=(Ee=r.user_email_addresses)==null?void 0:Ee.some(_r=>_r.verified),$e=(or=r.user_phone_numbers)==null?void 0:or.some(_r=>_r.verified),fe=r.social_connections&&r.social_connections.length>0,ke=t==null?void 0:t.auth_settings;return(ke==null?void 0:ke.first_factor)==="email_otp"&&te||((nr=ke==null?void 0:ke.magic_link)==null?void 0:nr.enabled)&&te||((Vr=ke==null?void 0:ke.passkey)==null?void 0:Vr.enabled)||((za=ke==null?void 0:ke.auth_factors_enabled)==null?void 0:za.phone_otp)&&$e||fe&&((Ea=t==null?void 0:t.social_connections)==null?void 0:Ea.some(_r=>_r.enabled))},L=async()=>{if(J.some(te=>te.length!==6)){d("Please enter both 6-digit verification codes","error");return}try{if(ae(!0),await s(N,J),await r.refetch(),se!=null&&se.backup_code){const te=await g();X(te),await r.refetch(),T("backup")}else T("success")}catch(te){d(te.message||"Invalid verification codes","error")}finally{ae(!1)}},W=()=>{T("table"),O(""),M(""),F(""),ie(["",""]),X([]),d("Two-factor authentication setup completed successfully!","info")},ee=async()=>{var te;if((te=r==null?void 0:r.user_authenticator)!=null&&te.id)try{Y(!0),await p(r.user_authenticator.id),await r.refetch(),v(!1),d("Two-factor authentication removed successfully","info")}catch($e){d($e.message||"Failed to remove authenticator","error")}finally{Y(!1)}},pe=async()=>{if(!U)try{Z(!0);const te=await c();X(te),await r.refetch(),f(!0),d("New backup codes generated","info")}catch(te){d(te.message||"Failed to generate backup codes","error")}finally{Z(!1)}},Se=()=>{const te=re.join(`
3932
3940
  `);navigator.clipboard.writeText(te).then(()=>{d("Backup codes copied to clipboard","info")}).catch(()=>{d("Failed to copy backup codes","error")})},Ne=()=>{const te=re.join(`
3933
3941
  `),$e=new Blob([te],{type:"text/plain"}),fe=URL.createObjectURL($e),ke=document.createElement("a");ke.href=fe,ke.download="wacht-backup-codes.txt",ke.click(),URL.revokeObjectURL(fe),d("Backup codes downloaded","info")},G=[];return q&&G.push({id:"password",name:"Password",description:"Secure your account with a strong password",status:r!=null&&r.has_password?"Enabled":"Disabled",actions:r!=null&&r.has_password?["change"]:["setup"]}),se!=null&&se.authenticator&&G.push({id:"authenticator",name:"Two-Factor Authentication",description:"Use an authenticator app for extra security",status:r!=null&&r.user_authenticator?"Enabled":"Disabled",actions:r!=null&&r.user_authenticator?["remove"]:["setup"]}),r!=null&&r.user_authenticator&&G.push({id:"backup_codes",name:"Backup Codes",description:"Recovery codes if you lose your authenticator",status:r!=null&&r.backup_codes_generated?"Generated":"Not Generated",actions:["generate"]}),(r!=null&&r.user_authenticator||r!=null&&r.backup_codes_generated||r.second_factor_policy==="enforced"||r.primary_phone_number_id)&&G.push({id:"second_factor_policy",name:"Second Factor Policy",description:"Require a second factor for all sign-ins",status:l==="enforced"?"Enforced":"Optional",actions:["toggle"]}),E!=="table"?e.jsxs(e.Fragment,{children:[e.jsxs(Bo,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(Xo,{size:16}),e.jsxs("span",{style:{fontSize:"14px",fontWeight:500,color:"var(--color-foreground)"},children:[E==="qr"&&"Setup Two-Factor Authentication",E==="verify"&&"Verify Your Authenticator",E==="backup"&&"Save Your Backup Codes",E==="success"&&"Setup Complete!"]})]}),e.jsx(K,{onClick:()=>T("table"),style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",color:"var(--color-foreground)",fontWeight:"500",cursor:"pointer",transition:"all 0.2s ease"},children:"← Back"})]}),e.jsxs("div",{style:{maxWidth:"500px",margin:"0 auto",textAlign:"center",padding:"24px"},children:[E==="qr"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{color:"var(--color-secondary-text)",marginBottom:"24px"},children:"Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.)"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"24px"},children:oe?e.jsx("div",{style:{width:"200px",height:"200px",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-input-background)"},children:e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{width:"24px",height:"24px",border:"2px solid var(--color-border)",borderTop:"2px solid var(--color-primary)",borderRadius:"50%",animation:`${A0} 1s linear infinite`,margin:"0 auto 8px"}}),e.jsx("div",{style:{fontSize:"12px",color:"var(--color-secondary-text)"},children:"Loading QR Code..."})]})}):P?e.jsx("div",{style:{border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"16px",background:"white"},children:e.jsx(Sa,{value:P,size:200,level:"M",marginSize:0})}):e.jsx("div",{style:{width:"200px",height:"200px",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-input-background)",color:"var(--color-error)",fontSize:"14px",textAlign:"center"},children:"QR Code Not Available"})}),e.jsxs("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"12px",marginBottom:"24px"},children:[e.jsx("p",{style:{fontSize:"14px",color:"var(--color-secondary-text)",margin:"0 0 8px 0"},children:"Or enter this code manually:"}),e.jsx("code",{style:{fontFamily:"monospace",fontSize:"14px",wordBreak:"break-all"},children:D||"Loading..."})]}),e.jsx(K,{onClick:()=>T("verify"),disabled:!P||!D,style:{padding:"10px 20px",background:!P||!D?"var(--color-border)":"var(--color-primary)",color:!P||!D?"var(--color-secondary-text)":"white",border:`1px solid ${!P||!D?"var(--color-border)":"var(--color-primary)"}`,cursor:!P||!D?"not-allowed":"pointer"},children:"I've Scanned the Code"})]}),E==="verify"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{color:"var(--color-secondary-text)",marginBottom:"24px"},children:"Enter two consecutive codes from your authenticator app to verify setup"}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center",marginBottom:"24px"},children:[e.jsx(de,{type:"text",placeholder:"000000",value:J[0],onChange:te=>{const $e=te.target.value.replace(/[^0-9]/g,"").substring(0,6);ie([$e,J[1]])},maxLength:6,style:{width:"100px",textAlign:"center",fontFamily:"monospace"}}),e.jsx(de,{type:"text",placeholder:"000000",value:J[1],onChange:te=>{const $e=te.target.value.replace(/[^0-9]/g,"").substring(0,6);ie([J[0],$e])},maxLength:6,style:{width:"100px",textAlign:"center",fontFamily:"monospace"}})]}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center"},children:[e.jsx(K,{onClick:()=>T("qr"),style:{padding:"8px 16px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:"Back"}),e.jsx(K,{onClick:L,disabled:Q||J.some(te=>te.length!==6),style:{padding:"8px 16px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:Q?"Verifying...":"Verify & Continue"})]})]}),E==="backup"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{background:"var(--color-warning-background)",border:"1px solid var(--color-warning-border)",borderRadius:"var(--radius-md)",padding:"16px",marginBottom:"24px",display:"flex",alignItems:"flex-start",gap:"12px",textAlign:"left"},children:[e.jsx(ut,{size:16,style:{color:"var(--color-warning)",marginTop:"2px"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"4px"},children:"Important!"}),e.jsx("div",{style:{fontSize:"14px",color:"var(--color-secondary-text)"},children:"Store these codes safely. Each code can only be used once if you lose access to your authenticator device."})]})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(2, 1fr)",gap:"8px",marginBottom:"24px",maxWidth:"300px",margin:"0 auto 24px auto"},children:re.map((te,$e)=>e.jsx("div",{style:{background:"var(--color-input-background)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"8px",fontFamily:"monospace",fontSize:"12px",textAlign:"center",cursor:"pointer"},onClick:()=>navigator.clipboard.writeText(te),children:te},$e))}),e.jsxs("div",{style:{display:"flex",gap:"12px",justifyContent:"center",marginBottom:"24px"},children:[e.jsx(K,{onClick:Se,style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:"Copy All"}),e.jsxs(K,{onClick:Ne,style:{padding:"8px 16px",fontSize:"14px",background:"var(--color-background)",border:"1px solid var(--color-border)"},children:[e.jsx(Qo,{size:16,style:{marginRight:"4px"}}),"Download"]})]}),e.jsx(K,{onClick:W,style:{padding:"10px 20px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:"Complete Setup"})]}),E==="success"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:"24px"},children:[e.jsx(rt,{size:48,style:{color:"var(--color-success)",marginBottom:"16px"}}),e.jsx("h3",{style:{fontSize:"18px",fontWeight:600,margin:"0 0 8px 0"},children:"All Set!"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-secondary-text)",margin:0},children:"Your account is now protected with two-factor authentication."})]}),e.jsx(K,{onClick:W,style:{padding:"10px 20px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)"},children:"Continue to Security"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Bo,{children:e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:e.jsx("span",{style:{fontSize:"14px",fontWeight:400,color:"var(--color-foreground)"},children:"Security Settings"})})}),G.length?e.jsx("div",{children:G.map((te,$e)=>e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"16px 0"},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:400,color:"var(--color-foreground)"},children:te.name}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-secondary-text)"},children:te.description})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[e.jsx("span",{style:{padding:"4px 12px",borderRadius:"16px",fontSize:"12px",fontWeight:400,background:te.status==="Enabled"||te.status==="Generated"?"var(--color-success-background)":"var(--color-background-hover)",color:te.status==="Enabled"||te.status==="Generated"?"var(--color-success)":"var(--color-secondary-text)"},children:te.status}),e.jsxs("div",{style:{position:"relative"},children:[te.id==="password"&&e.jsx(e.Fragment,{children:r!=null&&r.has_password?e.jsxs("div",{style:{display:"flex",gap:"8px"},children:[e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:j,onClick:()=>z(!0),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Change"}),y&&e.jsx(ci,{triggerRef:j,onClose:()=>z(!1),onChangePassword:H})]}),B()&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:S,onClick:()=>k(!0),style:{padding:"6px 12px",fontSize:"12px",background:"transparent",color:"var(--color-error)",border:"1px solid var(--color-error)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Remove"}),_&&e.jsx(k0,{triggerRef:S,onClose:()=>k(!1),onRemovePassword:A})]})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:j,onClick:()=>z(!0),style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:"Setup"}),y&&e.jsx(ci,{triggerRef:j,onClose:()=>z(!1),onChangePassword:H,isSetup:!0})]})}),te.id==="authenticator"&&!(r!=null&&r.user_authenticator)&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:I,onClick:()=>$(!0),disabled:oe,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:oe?"Setting up...":"Setup"}),C&&e.jsx(f0,{triggerRef:I,onClose:()=>$(!1),onSetupTOTP:async()=>{const fe=await a();return F(fe.id),fe},onVerifyTOTP:async fe=>{await s(N,fe),await r.refetch(),d("Two-factor authentication enabled successfully!","info")}})]})}),te.id==="authenticator"&&(r==null?void 0:r.user_authenticator)&&e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{onClick:()=>v(!0),disabled:ce,style:{padding:"6px 16px",fontSize:"13px",background:"var(--color-error)",border:"1px solid var(--color-error)",color:"white",cursor:ce?"not-allowed":"pointer",opacity:ce?.6:1},children:ce?"Removing...":"Remove"}),x&&e.jsx(on,{title:"Remove MFA and reset policy to default?",onConfirm:ee,onCancel:()=>v(!1)})]}),te.id==="backup_codes"&&e.jsx(e.Fragment,{children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(K,{ref:R,onClick:pe,disabled:U,style:{padding:"6px 12px",fontSize:"12px",background:"var(--color-primary)",color:"white",border:"1px solid var(--color-primary)",borderRadius:"var(--radius-md)",fontWeight:"400"},children:U?"Generating...":r!=null&&r.backup_codes_generated?"Regenerate":"Generate"}),b&&e.jsx(P0,{triggerRef:R,codes:re,onClose:()=>f(!1),onCopy:Se,onDownload:Ne})]})}),te.id==="second_factor_policy"&&e.jsx(Ao,{checked:l==="enforced",onChange:fe=>{w(fe?"enforced":"none")}})]})]})]}),$e<G.length-1&&e.jsx("div",{style:{height:"1px",background:"var(--color-border)",margin:"0"}})]},te.id))}):e.jsx(it,{title:"No security features available",description:"Contact your administrator to enable security features."})]})},Z0=()=>{var M,N;const{deployment:t}=ve(),{user:r,updateProfile:o,updateProfilePicture:n,deleteAccount:a}=rr(),{toast:s}=It(),[p,g]=i.useState(""),[c,h]=i.useState(""),[d,l]=i.useState(""),[m,x]=i.useState(!1),[v,w]=i.useState(!1),[C,$]=i.useState(!1),[y,z]=i.useState(""),[_,k]=i.useState((r==null?void 0:r.profile_picture_url)||null),b=i.useRef(null);i.useEffect(()=>{r&&!m&&(g(r.first_name||""),h(r.last_name||""),l(r.username||""),k(r.profile_picture_url||null),x(!0))},[r,m]);const f=i.useCallback(async()=>{if(r)try{const F={};p!==r.first_name&&(F.first_name=p),c!==r.last_name&&(F.last_name=c),d!==r.username&&(F.username=d),Object.keys(F).length>0&&await o(F)}catch(F){s(F.message||"Failed to save profile changes","error")}},[r,o,p,c,d,s]),I=F=>{g(F.target.value)},j=F=>{h(F.target.value)},S=F=>{l(F.target.value)},R=()=>{f()},E=()=>{f()},T=()=>{f()},P=F=>{var J;if((J=F.target.files)!=null&&J[0]){const ie=F.target.files[0];k(URL.createObjectURL(ie)),setTimeout(async()=>{try{await n(ie),r.refetch(),s("Profile picture updated successfully","info")}catch(re){s(re.message||"Failed to update profile picture","error"),k((r==null?void 0:r.profile_picture_url)||null)}},100)}},O=()=>{b.current&&b.current.click()};if(!r)return e.jsx("div",{style:{display:"flex",justifyContent:"center",padding:"40px 0"},children:e.jsx(Re,{})});const D=async()=>{if(!(!r||y!==r.username)){$(!0);try{await a(""),s("Account deleted successfully","info")}catch(F){s(F.message||"Failed to delete account","error")}finally{$(!1),z(""),w(!1)}}};return e.jsx(e.Fragment,{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2xl)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-2xl)",alignItems:"center"},children:[e.jsx("div",{style:{flexShrink:0},children:e.jsxs("div",{style:{width:"120px",height:"120px",borderRadius:"50%",border:"2px dashed var(--color-border)",background:_?"transparent":"var(--color-input-background)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",transition:"all 0.2s ease"},onClick:O,onMouseEnter:F=>{F.currentTarget.style.borderColor="var(--color-primary)",F.currentTarget.style.transform="scale(1.02)"},onMouseLeave:F=>{F.currentTarget.style.borderColor="var(--color-border)",F.currentTarget.style.transform="scale(1)"},children:[_?e.jsx("img",{src:_,alt:"Profile Picture",style:{width:"100%",height:"100%",objectFit:"cover",borderRadius:"50%"}}):e.jsx(Mo,{size:32,color:"var(--color-muted)"}),e.jsx("input",{type:"file",ref:b,style:{display:"none"},accept:"image/*",onChange:P})]})}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{marginBottom:"var(--space-lg)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Profile Picture"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Upload an image to represent your profile"})]}),e.jsxs("div",{style:{display:"flex",gap:"var(--space-sm)",marginBottom:"var(--space-sm)"},children:[e.jsxs(K,{onClick:()=>{var F;return(F=b.current)==null?void 0:F.click()},style:{padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(Qo,{size:14}),_?"Change":"Upload"]}),e.jsxs(K,{onClick:async()=>{k(null),b.current&&(b.current.value="");try{await o({remove_profile_picture:!0}),await r.refetch(),s("Profile picture removed successfully","info")}catch(F){s(F.message||"Failed to remove profile picture","error"),k((r==null?void 0:r.profile_picture_url)||null)}},style:{background:"transparent",color:"var(--color-muted)",border:"1px solid var(--color-border)",padding:"var(--space-xs) var(--space-md)",fontSize:"var(--font-xs)",height:"32px",width:"100px",display:"flex",alignItems:"center",gap:"6px"},children:[e.jsx(ut,{size:14}),"Remove"]})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"var(--space-md)"},children:[e.jsx("h3",{style:{fontSize:"var(--font-sm)",color:"var(--color-foreground)",margin:"0 0 var(--space-2xs) 0"},children:"Profile Details"}),e.jsx("p",{style:{fontSize:"var(--font-xs)",color:"var(--color-secondary-text)",margin:0},children:"Basic information about your profile"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-lg)"},children:[e.jsxs("div",{style:{display:"flex",gap:"var(--space-md)"},children:[e.jsxs(he,{style:{flex:1},children:[e.jsx(ue,{htmlFor:"firstName",children:"First Name"}),e.jsx(de,{id:"firstName",type:"text",value:p,onChange:I,onBlur:R,placeholder:"Enter your first name",required:!0})]}),e.jsxs(he,{style:{flex:1},children:[e.jsx(ue,{htmlFor:"lastName",children:"Last Name"}),e.jsx(de,{id:"lastName",type:"text",value:c,onChange:j,onBlur:E,placeholder:"Enter your last name",required:!0})]})]}),((N=(M=t==null?void 0:t.auth_settings)==null?void 0:M.username)==null?void 0:N.enabled)&&e.jsxs(he,{children:[e.jsx(ue,{htmlFor:"username",children:"Username"}),e.jsx(de,{id:"username",type:"text",value:d,onChange:S,onBlur:T,placeholder:"Enter your username",required:!0})]})]})]}),e.jsx("div",{style:{position:"relative",height:"1px",background:"var(--color-divider)",margin:"0"}}),e.jsxs("div",{children:[e.jsxs("div",{style:{marginBottom:"16px"},children:[e.jsx("h3",{style:{fontSize:"16px",color:"var(--color-foreground)",margin:"0 0 4px 0"},children:"Danger Zone"}),e.jsx("p",{style:{fontSize:"14px",color:"var(--color-muted)",margin:0},children:"Irreversible and destructive actions"})]}),e.jsxs("div",{style:{padding:"20px",border:"1px solid var(--color-error)",borderRadius:"8px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:v?"20px":"0"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",color:"var(--color-foreground)",marginBottom:"4px",fontWeight:"500"},children:"Delete Account"}),e.jsx("div",{style:{fontSize:"13px",color:"var(--color-muted)"},children:"Once you delete your account, there is no going back. Please be certain."})]}),e.jsx(K,{onClick:()=>{v?(w(!1),z("")):w(!0)},style:{background:"var(--color-error)",color:"white",border:"none",padding:"6px 12px",fontSize:"13px",height:"32px",width:"auto"},children:v?"Cancel":"Delete"})]}),v&&e.jsxs("div",{style:{maxWidth:"400px"},children:[e.jsxs(he,{children:[e.jsx(ue,{htmlFor:"confirm_username",children:"Confirm by typing your username"}),e.jsx(de,{id:"confirm_username",type:"text",value:y,onChange:F=>z(F.target.value),placeholder:`Type "${r==null?void 0:r.username}" to confirm`})]}),e.jsx(K,{onClick:D,disabled:y!==(r==null?void 0:r.username)||C,style:{background:y===(r==null?void 0:r.username)?"var(--color-error)":"transparent",color:y===(r==null?void 0:r.username)?"white":"var(--color-muted)",border:"1px solid var(--color-border)",padding:"8px 16px",fontSize:"14px",height:"36px",cursor:y===(r==null?void 0:r.username)?"pointer":"not-allowed",opacity:y===(r==null?void 0:r.username)?1:.6,marginTop:"12px"},children:C?e.jsx(Re,{size:12}):"Delete Forever"})]})]})]})]})})},Nl=({isOpen:t,onClose:r,title:o,showHeader:n,headerContent:a,footerContent:s,customContent:p,children:g,showCloseButton:c})=>e.jsx(we,{isOpen:t,onClose:r,children:e.jsx(we.Overlay,{children:e.jsxs(we.Content,{style:{width:"900px",maxWidth:"100%"},children:[n&&e.jsx(we.Header,{showCloseButton:c,children:a||o}),p||g||e.jsx(Dl,{}),s&&e.jsx(we.Footer,{children:s})]})})}),K0=u.div`
3934
3942
  position: relative;