@remit/web-client-dist 0.0.134 → 0.0.135
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/assets/{ComposeBody-Bb-eV7oX.js → ComposeBody-CXluR0mJ.js} +3 -3
- package/assets/{ErrorState-DaIYWAtU.js → ErrorState-xuU2Ycex.js} +1 -1
- package/assets/{OnboardingWizard-74ApF1TM.js → OnboardingWizard-DlBawZQa.js} +1 -1
- package/assets/{account-form-helpers-C1-XCp2v.js → account-form-helpers-C-R-t-TP.js} +1 -1
- package/assets/{accounts-BCrN_WZY.js → accounts-ADCcmorB.js} +1 -1
- package/assets/{advanced-hyewI6NP.js → advanced-CRu4UqDe.js} +1 -1
- package/assets/{appearance-CEbzMr1T.js → appearance-DDoSefIs.js} +1 -1
- package/assets/{avatar-WAi3XoGV.js → avatar-DO7vnPxY.js} +1 -1
- package/assets/{browser-ponyfill-odsmUzM4.js → browser-ponyfill-FuWjKEd5.js} +1 -1
- package/assets/{circle-check-Ccc0DpRT.js → circle-check-C86Aiiep.js} +1 -1
- package/assets/{download-B21Knqu2.js → download-C1F8f8Cm.js} +1 -1
- package/assets/filters-B-QK-_x9.js +1 -0
- package/assets/{flagged-CWyvtGeg.js → flagged-dNLl7pSz.js} +1 -1
- package/assets/{folder-DOSErHSR.js → folder-AERC-jiq.js} +1 -1
- package/assets/folders-D_SSE4kH.js +1 -0
- package/assets/index-CA8m1jib.js +1 -0
- package/assets/{index-ChxiTmNG.css → index-CIEsBq5i.css} +1 -1
- package/assets/index-DccQqmHT.js +295 -0
- package/assets/{index-DFY6-7Ge.js → index-Ds6rm6WR.js} +1 -1
- package/assets/{kbd-BKNut3M9.js → kbd-CJm0PdtR.js} +1 -1
- package/assets/mail-CGtAo1Ry.js +118 -0
- package/assets/{onboarding-yY91msSU.js → onboarding-Dd5aSsGp.js} +1 -1
- package/assets/{rotate-ccw-EQBbw3Gs.js → rotate-ccw-Vwe0kY7O.js} +1 -1
- package/assets/{senders-DKiu2US4.js → senders-d0E-TE0w.js} +1 -1
- package/assets/settings-epL7Dplk.js +1 -0
- package/assets/{settings-screen-6C3zeyy1.js → settings-screen-CGcJfaFe.js} +1 -1
- package/assets/{suggested-vips-BvoEfJ52.js → suggested-vips-DzhuY5XT.js} +1 -1
- package/assets/useCreateMailbox-C4OH6qHD.js +1 -0
- package/assets/{useDebouncedValue-C_J4lOpx.js → useDebouncedValue-DZZtIlXe.js} +1 -1
- package/assets/{useRulePreview-Ct7Q8uG2.js → useRulePreview-B7LWIphh.js} +1 -1
- package/assets/{useSignature-B22ZnEj4.js → useSignature-BuMCTh1I.js} +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/assets/filters-Tqa-_zb9.js +0 -1
- package/assets/folders-CLWqJfFM.js +0 -1
- package/assets/index-DsR4Mk7n.js +0 -295
- package/assets/index-aL9qdiwR.js +0 -1
- package/assets/mail-BMBn_nLi.js +0 -118
- package/assets/settings-BGBibXai.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as t,f as r}from"./index-
|
|
1
|
+
import{j as t,f as r}from"./index-DccQqmHT.js";const d=e=>e instanceof Error?e.message:typeof e=="string"?e:typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"?e.message:"An unexpected error occurred",l=({title:e="Couldn't load content",error:a,onRetry:s,variant:i="block"})=>{const n=d(a);return i==="inline"?t.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft px-3 py-2 text-sm",children:[t.jsx(r,{className:"size-4 shrink-0 text-danger mt-0.5","aria-hidden":"true"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"font-medium text-danger",children:e}),t.jsx("p",{className:"text-fg-muted mt-0.5 break-words",children:n})]}),s&&t.jsx("button",{type:"button",onClick:s,className:"shrink-0 text-sm font-medium text-accent hover:underline",children:"Retry"})]}):t.jsxs("div",{role:"alert",className:"flex flex-col items-center justify-center gap-3 p-8 text-center",children:[t.jsx(r,{className:"size-8 text-danger","aria-hidden":"true"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium text-danger",children:e}),t.jsx("p",{className:"text-sm text-fg-muted mt-1 break-words",children:n})]}),s&&t.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center rounded-md border border-line bg-canvas px-4 py-2 text-sm font-medium hover:bg-surface-raised transition-colors",children:"Retry"})]})};export{l as E,d as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ot,j as t,b as O,bt as U,h as rt,r as c,d as ct,y as A,$ as lt,at as V,bo as mt,br as ut,aq as X,bG as Y,ay as dt,B as N,i as W,bq as pt,k as Q,bB as ht,n as xt}from"./index-DsR4Mk7n.js";import{K as ft}from"./kbd-BKNut3M9.js";import{c as yt,M as gt}from"./account-form-helpers-C1-XCp2v.js";const K=ot("AtSign",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]]);const vt=ot("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);function bt({url:e}){return t.jsxs("p",{className:"text-2xs text-fg-subtle",children:["Stored encrypted, used only to connect to your mail server."," ",e?t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"How to create an app password"}):t.jsx("span",{children:"Check your provider's help for app password instructions."})]})}function jt({raised:e,className:r,...s}){return t.jsx("div",{className:O("rounded-sm border border-line bg-surface",e?"bg-surface-raised shadow-sm":"",r),...s})}function I({className:e,children:r,...s}){return t.jsx("label",{className:O("mb-1 block text-xs font-medium text-fg-muted",e),...s,children:r})}function J({value:e,defaultValue:r,onValueChange:s,...a}){return s?t.jsxs(U,{value:e,onChange:n=>s(n.target.value),...a,children:[t.jsx("option",{value:"tls",children:"TLS/SSL"}),t.jsx("option",{value:"starttls",children:"STARTTLS"}),t.jsx("option",{value:"none",children:"None (insecure)"})]}):t.jsxs(U,{defaultValue:r??e,...a,children:[t.jsx("option",{value:"tls",children:"TLS/SSL"}),t.jsx("option",{value:"starttls",children:"STARTTLS"}),t.jsx("option",{value:"none",children:"None (insecure)"})]})}function q(e){return{tls:e==="tls",startTls:e==="starttls"}}function St({steps:e,activeStep:r}){return t.jsx("ol",{className:"flex items-center gap-1",children:e.map((s,a)=>{const n=a<r,o=a===r;return t.jsxs("li",{className:"flex items-center gap-1",children:[a>0&&t.jsx("span",{className:"h-px w-5 bg-line","aria-hidden":!0}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:O("flex size-5 items-center justify-center rounded-full text-2xs font-semibold tabular-nums",n&&"bg-accent text-accent-fg",o&&"bg-accent-soft text-accent ring-1 ring-accent",!n&&!o&&"bg-surface-sunken text-fg-subtle"),children:n?t.jsx(rt,{className:"size-3"}):a+1}),t.jsx("span",{className:O("hidden text-2xs sm:inline",o?"font-medium text-fg":"text-fg-subtle"),children:s})]})]},s)})})}function L({steps:e,activeStep:r,title:s,subtitle:a,children:n,footer:o,hideSteps:m}){return t.jsxs("div",{className:"flex min-h-dvh w-full flex-col items-center overflow-y-auto bg-canvas px-8 pb-8 pt-8 font-sans text-fg sm:pt-[30vh]",children:[!m&&t.jsx("div",{className:"mb-5 w-full max-w-xl",children:t.jsx(St,{steps:e,activeStep:r})}),t.jsxs(jt,{raised:!0,className:"w-full max-w-xl",children:[t.jsxs("div",{className:"px-5 pt-5",children:[t.jsx("h1",{className:"text-xl font-semibold text-fg",children:s}),a&&t.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:a})]}),t.jsx("div",{className:"px-5 py-5",children:n}),o&&t.jsx("div",{className:"flex items-center justify-between gap-3 border-t border-line px-5 py-3",children:o})]})]})}const wt="Coming soon — use IMAP for now.";function B({name:e,description:r,icon:s,comingSoon:a,selected:n,onSelect:o}){const[m,d]=c.useState(!1),i=()=>{if(o){o();return}a&&d(!0)};return t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("button",{type:"button",onClick:i,"aria-disabled":a||void 0,className:O("flex flex-col items-start gap-2 rounded-sm border p-3 text-left transition-colors",n?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:border-line-strong",a&&"opacity-55"),children:[t.jsx("span",{className:O("text-fg-muted",n&&"text-accent-2"),children:s}),t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-semibold text-fg",children:e}),a&&t.jsx("span",{className:"rounded-full bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-subtle",children:"soon"})]}),t.jsx("span",{className:"text-xs text-fg-subtle",children:r})]}),m&&t.jsx("p",{className:"text-2xs text-fg-subtle",children:wt})]})}function Z({legend:e,badge:r,host:s,port:a,security:n,readOnly:o,onHostChange:m,onPortChange:d,onSecurityChange:i,hostPlaceholder:x,portPlaceholder:k}){const j=c.useId(),f=c.useId(),S=c.useId();return t.jsxs("fieldset",{children:[t.jsxs("legend",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[e,r&&t.jsx(ct,{tone:r.tone,children:r.label})]}),t.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-3 sm:grid-cols-[1fr_6rem_8rem] sm:gap-2",children:[t.jsxs("div",{children:[t.jsx(I,{htmlFor:j,children:"Host"}),m?t.jsx(A,{id:j,readOnly:o,value:s,onChange:h=>m(h.target.value),placeholder:x}):t.jsx(A,{id:j,readOnly:o,defaultValue:s,placeholder:x})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:f,children:"Port"}),d?t.jsx(A,{id:f,readOnly:o,value:a,onChange:h=>d(h.target.value),placeholder:k}):t.jsx(A,{id:f,readOnly:o,defaultValue:a,placeholder:k})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:S,children:"Security"}),i?t.jsx(J,{id:S,value:n,onValueChange:i}):t.jsx(J,{id:S,defaultValue:n})]})]})]})}function H({label:e,detail:r,state:s}){return t.jsxs("div",{className:"flex items-start gap-3 py-2",children:[t.jsxs("span",{className:O("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-2xs",s==="ok"&&"bg-positive text-accent-fg",s==="failed"&&"bg-danger text-accent-fg",s==="running"&&"border border-accent text-accent",s==="pending"&&"border border-line text-fg-subtle"),children:[s==="ok"&&t.jsx(rt,{className:"size-3"}),s==="failed"&&"!",s==="running"&&t.jsx("span",{className:"size-2 animate-pulse rounded-full bg-accent"})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:O("text-sm",s==="failed"?"font-medium text-danger":"text-fg"),children:e}),r&&t.jsx("div",{className:"mt-0.5 text-xs text-fg-subtle",children:r})]})]})}const kt={"gmail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"googlemail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"outlook.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"hotmail.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"live.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"msn.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"icloud.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"me.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"mac.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"fastmail.com":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"fastmail.fm":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"yahoo.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"yahoo.co.uk":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"ymail.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"aol.com":{imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},source:"provider-table"},"zoho.com":{imap:{host:"imap.zoho.com",port:993,security:"tls"},smtp:{host:"smtp.zoho.com",port:465,security:"tls"},source:"provider-table"},"gmx.com":{imap:{host:"imap.gmx.com",port:993,security:"tls"},smtp:{host:"smtp.gmx.com",port:587,security:"starttls"},source:"provider-table"},"gmx.net":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"gmx.de":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"web.de":{imap:{host:"imap.web.de",port:993,security:"tls"},smtp:{host:"smtp.web.de",port:587,security:"starttls"},source:"provider-table"},"mail.com":{imap:{host:"imap.mail.com",port:993,security:"tls"},smtp:{host:"smtp.mail.com",port:465,security:"tls"},source:"provider-table"},"hey.com":{imap:{host:"imap.hey.com",port:993,security:"tls"},smtp:{host:"smtp.hey.com",port:465,security:"tls"},source:"provider-table"},"tutanota.com":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"tuta.io":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"posteo.de":{imap:{host:"posteo.de",port:993,security:"tls"},smtp:{host:"posteo.de",port:465,security:"tls"},source:"provider-table"},"runbox.com":{imap:{host:"imap.runbox.com",port:993,security:"tls"},smtp:{host:"smtp.runbox.com",port:587,security:"starttls"},source:"provider-table"},"mailbox.org":{imap:{host:"imap.mailbox.org",port:993,security:"tls"},smtp:{host:"smtp.mailbox.org",port:465,security:"tls"},source:"provider-table"},"hushmail.com":{imap:{host:"imap.hushmail.com",port:993,security:"tls"},smtp:{host:"smtp.hushmail.com",port:465,security:"tls"},source:"provider-table"}},Nt={"gmail.com":"https://support.google.com/accounts/answer/185833","googlemail.com":"https://support.google.com/accounts/answer/185833","yahoo.com":"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html","icloud.com":"https://support.apple.com/en-us/102654","me.com":"https://support.apple.com/en-us/102654","mac.com":"https://support.apple.com/en-us/102654","fastmail.com":"https://www.fastmail.help/hc/en-us/articles/360058752854","fastmail.fm":"https://www.fastmail.help/hc/en-us/articles/360058752854","outlook.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","hotmail.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","zoho.com":"https://help.zoho.com/portal/en/kb/zoho-mail/client-configuration/imap-access/articles/zoho-mail-app-passwords"};function nt(e){try{const s=new DOMParser().parseFromString(e,"application/xml");if(s.querySelector("parsererror"))return null;const a=s.querySelectorAll("incomingServer[type='imap']"),n=s.querySelectorAll("outgoingServer[type='smtp']");if(!a.length||!n.length)return null;const o=a[0],m=n[0],d=o.querySelector("hostname")?.textContent?.trim(),i=o.querySelector("port")?.textContent?.trim(),x=o.querySelector("socketType")?.textContent?.trim().toUpperCase(),k=m.querySelector("hostname")?.textContent?.trim(),j=m.querySelector("port")?.textContent?.trim(),f=m.querySelector("socketType")?.textContent?.trim().toUpperCase();if(!d||!i||!k||!j)return null;const S=h=>h==="SSL"||h==="TLS"||h==="SSL/TLS"?"tls":h==="STARTTLS"?"starttls":"none";return{imap:{host:d,port:Number.parseInt(i,10),security:S(x)},smtp:{host:k,port:Number.parseInt(j,10),security:S(f)},source:"mozilla-autoconfig"}}catch{return null}}async function Ct(e,r){try{const s=`https://autoconfig.thunderbird.net/v1.1/${e}`,a=await fetch(s,{signal:r});if(!a.ok)return null;const n=await a.text(),o=nt(n);return o||null}catch{return null}}async function Et(e,r){try{const s=`https://autoconfig.${e}/mail/config-v1.1.xml`,a=await fetch(s,{signal:r});if(!a.ok)return null;const n=await a.text(),o=nt(n);return o?{...o,source:"domain-autoconfig"}:null}catch{return null}}function Tt(e){return{imap:{host:`imap.${e}`,port:993,security:"tls"},smtp:{host:`smtp.${e}`,port:587,security:"starttls"},source:"heuristic"}}async function Pt(e,r=1500){const s=e.indexOf("@");if(s===-1)return null;const a=e.slice(s+1).toLowerCase();if(!a)return null;const n=kt[a];if(n)return n;const o=new AbortController,m=setTimeout(()=>o.abort(),r);try{const d=await Ct(a,o.signal);if(d)return d;const i=await Et(a,o.signal);if(i)return i}finally{clearTimeout(m)}return Tt(a)}function At(e){const r=e.indexOf("@");return r===-1?"Looking up server settings…":`Looking up settings for ${e.slice(r+1)}…`}function at(e){const r=e.indexOf("@");if(r===-1)return;const s=e.slice(r+1).toLowerCase();return Nt[s]}const it=[{id:"icloud",label:"iCloud",username:"full-email",imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},passwordHelp:{text:"iCloud requires an app-specific password, not your Apple ID password. Generate one under Sign-In & Security → App-Specific Passwords.",url:"https://support.apple.com/en-us/102654"}},{id:"yahoo",label:"Yahoo",username:"full-email",imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},passwordHelp:{text:"Yahoo requires an app password, not your login password. Generate one under Account Security.",url:"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html"}},{id:"aol",label:"AOL",username:"full-email",imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},passwordHelp:{text:"AOL requires an app password, not your login password. Generate one under Account Security.",url:"https://login.aol.com/account/security"}},{id:"fastmail",label:"Fastmail",username:"full-email",imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},passwordHelp:{text:"Fastmail requires an app password, not your login password. Create one under Settings → Privacy & Security → App passwords.",url:"https://www.fastmail.help/hc/en-us/articles/360058752854"}}];function tt(e){return it.find(r=>r.id===e)}const It={"icloud.com":"icloud","me.com":"icloud","mac.com":"icloud","yahoo.com":"yahoo","yahoo.co.uk":"yahoo","ymail.com":"yahoo","aol.com":"aol","fastmail.com":"fastmail","fastmail.fm":"fastmail"};function Lt(e){const r=e.indexOf("@");if(r===-1)return"";const s=e.slice(r+1).toLowerCase();return It[s]??""}const M=["Connector","Address","Servers","Credentials","Test","Sync"],z={connector:0,address:1,servers:2,credentials:3,test:4,sync:5},et={host:"",port:993,security:"tls"},st={host:"",port:587,security:"starttls"};function Mt({onStart:e}){return c.useEffect(()=>{const r=s=>{s.key==="Enter"&&e()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e]),t.jsx(L,{steps:M,activeStep:0,hideSteps:!0,title:"Welcome to Remit",subtitle:"One inbox for all your mail, with context about every message.",footer:t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"text-2xs text-fg-subtle",children:[t.jsx(ft,{children:"Enter"})," to continue"]}),t.jsx(N,{variant:"primary",onClick:e,children:"Add your first account"})]}),children:t.jsxs("div",{className:"flex flex-col items-start py-5",children:[t.jsx("span",{className:"flex size-14 items-center justify-center rounded-md bg-accent-soft",children:t.jsx(gt,{className:"size-7 text-accent"})}),t.jsx("p",{className:"mt-5 max-w-sm text-sm leading-relaxed text-fg-muted",children:"Remit syncs your existing mailboxes and tells you who is really writing to you — sender history, authenticity checks, and similar messages, right next to every email."})]})})}function Ft({onContinue:e,onMicrosoft:r,onBack:s,showBack:a}){const[n,o]=c.useState("imap");c.useEffect(()=>{const d=i=>{i.key==="Enter"&&(n==="microsoft"?r():e()),i.key==="Escape"&&s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[e,r,s,n]);const m=()=>{n==="microsoft"?r():e()};return t.jsx(L,{steps:M,activeStep:z.connector,title:"How does this account connect?",subtitle:"Choose a sign-in method. IMAP works with any provider.",footer:t.jsxs(t.Fragment,{children:[a?t.jsx(N,{variant:"ghost",onClick:s,children:"Back"}):t.jsx("span",{}),t.jsx(N,{variant:"primary",onClick:m,children:n==="microsoft"?"Continue with Microsoft":"Continue with IMAP"})]}),children:t.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[t.jsx(B,{name:"IMAP / SMTP",description:"Any mail provider — Fastmail, iCloud, your own server.",icon:t.jsx(vt,{className:"size-5"}),selected:n==="imap",onSelect:()=>o("imap")}),t.jsx(B,{name:"Gmail",description:"Sign in with Google. No app passwords.",icon:t.jsx(K,{className:"size-5"}),comingSoon:!0}),t.jsx(B,{name:"Outlook / Microsoft 365",description:"Sign in with Microsoft. Works with Outlook.com and work accounts.",icon:t.jsx(xt,{className:"size-5"}),selected:n==="microsoft",onSelect:()=>o("microsoft")})]})})}function Ot({onBack:e,onRedirecting:r}){const[s,a]=c.useState(""),[n,o]=c.useState(null),m=V({...ht(),onSuccess:i=>{r(),window.location.assign(i.authorizationUrl)},onError:i=>{o(i instanceof Error?i.message:"Failed to start sign-in")}}),d=()=>{o(null),m.mutate({body:{email:s.trim()||void 0}})};return c.useEffect(()=>{const i=x=>{x.key==="Enter"&&!m.isPending&&d(),x.key==="Escape"&&e()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[e,m.isPending]),t.jsx(L,{steps:M,activeStep:z.connector,title:"Sign in with Microsoft",subtitle:"You'll be redirected to Microsoft to sign in securely.",footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:e,children:"Back"}),t.jsx(N,{variant:"primary",onClick:d,disabled:m.isPending,icon:m.isPending?t.jsx(W,{className:"size-4 animate-spin"}):void 0,children:m.isPending?"Redirecting…":"Sign in with Microsoft"})]}),children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx(I,{htmlFor:"microsoft-email",children:"Email address (optional)"}),t.jsx(A,{id:"microsoft-email",icon:t.jsx(K,{className:"size-4"}),placeholder:"you@outlook.com",value:s,onChange:i=>a(i.target.value),type:"email",autoComplete:"email"}),t.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"Pre-fills the Microsoft sign-in form. Leave blank to choose on the Microsoft page."})]}),n&&t.jsx(Q,{tone:"danger",children:n})]})})}function zt({initialEmail:e,initialDisplayName:r,onContinue:s,onBack:a}){const[n,o]=c.useState(e),[m,d]=c.useState(r),[i,x]=c.useState(!1),[k,j]=c.useState(""),[f,S]=c.useState(null),h=c.useCallback(async()=>{const y=n.trim();if(!y.includes("@")||!y.includes(".")){S("Enter a valid email address.");return}S(null),x(!0),j(At(y));try{const u=await Pt(y);s(y,m.trim(),u)}finally{x(!1)}},[n,m,s]);return c.useEffect(()=>{const y=u=>{u.key==="Enter"&&!i&&h(),u.key==="Escape"&&a()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[h,i,a]),t.jsx(L,{steps:M,activeStep:z.address,title:"What's the email address?",subtitle:"We'll detect the server settings for you.",footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:a,children:"Back"}),t.jsx(N,{variant:"primary",disabled:i,onClick:()=>{h()},children:"Continue"})]}),children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx(I,{htmlFor:"onboarding-email",children:"Email address"}),t.jsx(A,{id:"onboarding-email",icon:t.jsx(K,{className:"size-4"}),placeholder:"you@example.com",value:n,onChange:y=>{o(y.target.value),S(null)},type:"email",autoComplete:"email"})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"onboarding-display-name",children:"Display name (optional)"}),t.jsx(A,{id:"onboarding-display-name",placeholder:"Alice",value:m,onChange:y=>d(y.target.value)}),t.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"What to call this account in Remit. Leave blank to use a name derived from the address."})]}),i&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-fg-muted",children:[t.jsx(W,{className:"size-3.5 animate-spin text-accent"}),k]}),f&&!i&&t.jsx("div",{className:"mt-3",children:t.jsx(Q,{tone:"danger",children:f})})]})})}function Rt({email:e,imapConfig:r,smtpConfig:s,discovered:a,onContinue:n,onBack:o,onChange:m}){const[d,i]=c.useState(r),[x,k]=c.useState(s),[j,f]=c.useState(()=>Lt(e)),[S,h]=c.useState(!1),[y,u]=c.useState(null),v=tt(j),p=v!==void 0&&!S,C=c.useCallback(l=>{f(l),h(!1),u(null);const w=tt(l);w&&(i({host:w.imap.host,port:w.imap.port,security:w.imap.security}),k({host:w.smtp.host,port:w.smtp.port,security:w.smtp.security}))},[]);c.useEffect(()=>{m(d,x)},[d,x,m]);const g=d.host.trim()!=="",b=c.useCallback(()=>{if(!g){u("Enter the IMAP host.");return}u(null),n()},[g,n]);c.useEffect(()=>{const l=w=>{w.key==="Enter"&&b(),w.key==="Escape"&&o()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[b,o]);const T=e.split("@")[1]??"your domain",P=v?"Pick your provider to fill in the right settings — or choose Custom to enter them by hand.":a?"Found via autodiscovery — adjust anything that looks off.":`We couldn't detect settings for ${T} — enter them manually.`,F=p?{label:"preset",tone:"neutral"}:!v&&a?{label:"detected",tone:"positive"}:void 0,R=v?.passwordHelp.url??at(e);return t.jsx(L,{steps:M,activeStep:z.servers,title:"Confirm server settings",subtitle:P,footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:o,children:"Back"}),t.jsx(N,{variant:"primary",onClick:b,children:"Continue"})]}),children:t.jsxs("div",{className:"space-y-5",children:[y&&t.jsx(Q,{tone:"danger",children:y}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"provider-select",children:"Provider"}),t.jsxs(U,{id:"provider-select",value:j,onChange:l=>C(l.target.value),children:[t.jsx("option",{value:"",children:"Custom / other"}),it.map(l=>t.jsx("option",{value:l.id,children:l.label},l.id))]}),v&&t.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:p?t.jsxs(t.Fragment,{children:["Server settings are pre-filled for ",v.label," and locked."," ",t.jsx("button",{type:"button",className:"text-accent underline",onClick:()=>h(!0),children:"Advanced"})," ","lets you edit them by hand."]}):t.jsxs(t.Fragment,{children:["Editing ",v.label,"'s settings by hand."]})})]}),t.jsx(Z,{legend:"IMAP — incoming",badge:F,readOnly:p,host:d.host,port:String(d.port),security:d.security,hostPlaceholder:"imap.example.com",portPlaceholder:"993",onHostChange:l=>{i(w=>({...w,host:l})),u(null)},onPortChange:l=>i(w=>({...w,port:Number(l)})),onSecurityChange:l=>i(w=>({...w,security:l}))}),t.jsx("p",{className:"text-2xs text-fg-subtle",children:"Sending (SMTP) is optional — leave it blank to set up a receive-only account and add sending later in Settings."}),t.jsx(Z,{legend:"SMTP — outgoing (optional)",badge:F,readOnly:p,host:x.host,port:String(x.port),security:x.security,hostPlaceholder:"smtp.example.com",portPlaceholder:"587",onHostChange:l=>{k(w=>({...w,host:l})),u(null)},onPortChange:l=>k(w=>({...w,port:Number(l)})),onSecurityChange:l=>k(w=>({...w,security:l}))}),v&&t.jsxs("p",{className:"text-2xs text-fg-subtle",children:[v.passwordHelp.text," ",R&&t.jsx("a",{href:R,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"Get an app password"})]})]})})}function Ht({email:e,username:r,password:s,onContinue:a,onBack:n,onChange:o}){const[m,d]=c.useState(r||e),[i,x]=c.useState(s),[k,j]=c.useState(null),f=e.split("@")[1]??"",S=at(e),h=m.trim()!==""&&i.trim()!=="";c.useEffect(()=>{o(m,i)},[m,i,o]);const y=c.useCallback(()=>{if(!h){j("Enter your username and password.");return}j(null),a()},[h,a]);return c.useEffect(()=>{const u=v=>{v.key==="Enter"&&y(),v.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[y,n]),t.jsx(L,{steps:M,activeStep:z.credentials,title:`Sign in to ${f||"your mail server"}`,subtitle:"Many providers require an app password instead of your normal one.",footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:n,children:"Back"}),t.jsx(N,{variant:"primary",onClick:y,children:"Test connection"})]}),children:t.jsxs("div",{className:"space-y-3",children:[k&&t.jsx("div",{className:"rounded-md bg-danger-soft px-3 py-2 text-sm text-danger",children:k}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"credentials-username",children:"Username"}),t.jsx(A,{id:"credentials-username",value:m,onChange:u=>{d(u.target.value),j(null)},autoComplete:"username"})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"credentials-password",children:"Password or app password"}),t.jsx(A,{id:"credentials-password",type:"password",value:i,onChange:u=>{x(u.target.value),j(null)},autoComplete:"current-password"})]}),t.jsx(bt,{url:S})]})})}function $t({email:e,imapConfig:r,smtpConfig:s,username:a,password:n,onSuccess:o,onBackToCredentials:m,onBackToServers:d}){const[i,x]=c.useState({imapState:"running",smtpState:"pending",phase:"running"}),[k,j]=c.useState(0),f=s.host.trim()!=="",S=q(r.security),h=q(s.security),y=V({...pt()});c.useEffect(()=>{let p=!1;const C=[];return x({imapState:"running",smtpState:"pending",phase:"running"}),y.mutate({body:{username:a,password:n,imapHost:r.host,imapPort:r.port,imapTls:S.tls,imapStartTls:S.startTls,smtpHost:s.host,smtpPort:s.port,smtpTls:h.tls,smtpStartTls:h.startTls}},{onSuccess:g=>{if(p)return;const b=g.imapSuccess,T=f?g.smtpSuccess:!0;x({imapState:b?"ok":"failed",smtpState:f?"running":"ok",imapDetail:b?`Connected — ${r.host}:${r.port}`:g.imapError,phase:"running"}),C.push(window.setTimeout(()=>{if(p)return;const P=R=>{const l=R?.toLowerCase()??"";return l.includes("auth")||l.includes("login")||l.includes("535")||l.includes("credential")},F=!b&&P(g.imapError)||b&&f&&!g.smtpSuccess&&P(g.smtpError);x({imapState:b?"ok":"failed",smtpState:f?g.smtpSuccess?"ok":"failed":"ok",imapDetail:b?`Connected — ${r.host}:${r.port}`:g.imapError,smtpDetail:f?g.smtpSuccess?`Connected — ${s.host}:${s.port}`:g.smtpError:"Not set up — receive-only",rawError:b?f&&!g.smtpSuccess?g.smtpError:void 0:g.imapError,phase:b&&T?"success":F?"auth-failure":"network-failure"}),b&&T&&C.push(window.setTimeout(()=>{p||o()},800))},400))},onError:g=>{if(p)return;const b=g instanceof Error?g.message:"Connection failed";x({imapState:"failed",smtpState:"failed",imapDetail:b,smtpDetail:b,rawError:b,phase:"network-failure"})}}),()=>{p=!0;for(const g of C)window.clearTimeout(g)}},[k]);const{phase:u}=i;c.useEffect(()=>{const p=C=>{C.key==="Escape"&&(u==="auth-failure"?m():u==="network-failure"&&d())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[u,m,d]);const v=u==="auth-failure"?t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:m,children:"Back to credentials"}),t.jsx(N,{variant:"primary",onClick:()=>j(p=>p+1),children:"Retry"})]}):u==="network-failure"?t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:d,children:"Back to servers"}),t.jsx(N,{variant:"primary",onClick:()=>j(p=>p+1),children:"Retry"})]}):u==="success"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-2xs text-fg-subtle",children:"Connection verified"}),t.jsx(N,{variant:"primary",onClick:o,children:"Start syncing"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-2xs text-fg-subtle",children:"Testing…"}),t.jsx("span",{})]});return t.jsx(L,{steps:M,activeStep:z.test,title:"Testing the connection",subtitle:`Checking ${e}`,footer:v,children:t.jsxs("div",{className:"divide-y divide-line",children:[t.jsx(H,{label:`IMAP — ${r.host}:${r.port}`,detail:i.imapDetail,state:i.imapState}),t.jsx(H,{label:f?`SMTP — ${s.host}:${s.port}`:"SMTP — sending",detail:f?i.smtpDetail:"Not set up — you can add sending later in Settings",state:i.smtpState}),(u==="auth-failure"||u==="network-failure")&&i.rawError&&t.jsxs("div",{className:"py-3",children:[u==="auth-failure"&&t.jsx("p",{className:"mb-2 text-xs text-fg-muted",children:"Check your password — many providers require an app password."}),t.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:i.rawError})]})]})})}function _t({email:e,displayName:r,imapConfig:s,smtpConfig:a,username:n,password:o,onGoToInbox:m}){const d=lt(),[i,x]=c.useState(null),[k,j]=c.useState(null),f=c.useRef(!1),S=q(s.security),h=q(a.security),y=V({...ut(),onSuccess:E=>{x(E.accountId),d.invalidateQueries({queryKey:mt()})},onError:E=>{j(E instanceof Error?E.message:"Failed to create account")}});c.useEffect(()=>{if(f.current)return;f.current=!0;const E=a.host.trim()!=="",$=yt({imapHost:s.host,smtpHost:a.host,smtpPort:a.port}),_=E?$??{smtpHost:a.host,smtpPort:a.port,smtpTls:h.tls,smtpStartTls:h.startTls}:null;y.mutate({body:{email:e,displayName:r||void 0,username:n!==e?n:void 0,password:o,imapHost:s.host,imapPort:s.port,imapTls:S.tls,imapStartTls:S.startTls,smtpHost:_?.smtpHost||void 0,smtpPort:_?.smtpPort||void 0,smtpTls:_?.smtpTls??!1,smtpStartTls:_?.smtpStartTls??!1}})},[]);const{data:u}=X({...Y({path:{accountId:i??""}}),enabled:!!i,refetchInterval:E=>{const $=E.state.data?.syncPhase;return $==="complete"||$==="error"?!1:2e3}}),v=u?.syncPhase==="error",{data:p}=X({...dt(),enabled:!!i&&v}),C=p?.accounts.find(E=>E.accountId===i)?.lastError,g=u?.mailboxes.find(E=>E.fullPath==="INBOX"||E.fullPath==="Inbox"),b=u?.mailboxCountTotal??0,T=u?.mailboxCountSynced??0,P=g?.messagesTotal??0,F=g?.messagesSynced??0,R=P>0?F/P:0,l=u?.syncPhase,w=v?"failed":l==="idle"||l===void 0||l==="discovering_mailboxes"?"running":b>0?"ok":"running",D=v?"failed":!l||l==="idle"||l==="discovering_mailboxes"?"pending":l==="syncing_inbox"||l==="syncing_others"?"running":"ok",G=v?"failed":!l||l==="idle"||l==="discovering_mailboxes"||l==="syncing_inbox"?"pending":l==="syncing_others"?"running":"ok";return k?t.jsx(L,{steps:M,activeStep:z.sync,title:"Couldn't create account",subtitle:"Something went wrong saving your account.",footer:t.jsxs(t.Fragment,{children:[t.jsx("span",{}),t.jsx(N,{variant:"primary",onClick:()=>{f.current=!1,j(null),y.mutate({body:{email:e,displayName:r||void 0,username:n!==e?n:void 0,password:o,imapHost:s.host,imapPort:s.port,imapTls:S.tls,imapStartTls:S.startTls,smtpHost:a.host||void 0,smtpPort:a.port||void 0,smtpTls:h.tls,smtpStartTls:h.startTls}})},children:"Retry"})]}),children:t.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:k})}):t.jsx(L,{steps:M,activeStep:z.sync,title:`Syncing ${e}`,subtitle:"Newest mail first — you can start reading right away.",footer:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-2xs text-fg-subtle",children:"Sync continues in the background"}),t.jsx(N,{variant:"primary",onClick:()=>i&&m(i),children:"Go to inbox"})]}),children:y.isPending?t.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-muted",children:[t.jsx(W,{className:"size-4 animate-spin text-accent"}),"Creating your account…"]}):t.jsxs("div",{className:"space-y-3",children:[P>0&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-baseline justify-between text-xs",children:[t.jsx("span",{className:"font-medium text-fg",children:"INBOX"}),t.jsxs("span",{className:"text-fg-subtle tabular-nums",children:[F.toLocaleString()," / ",P.toLocaleString()," ","messages"]})]}),t.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-surface-sunken",children:t.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500",style:{width:`${Math.max(2,R*100)}%`}})})]}),t.jsxs("div",{className:"divide-y divide-line",children:[t.jsx(H,{label:"Mailboxes discovered",detail:b>0?`${b} mailbox${b===1?"":"es"} found`:"Discovering…",state:w}),t.jsx(H,{label:"INBOX",detail:D==="ok"?`${F.toLocaleString()} messages synced`:D==="running"?"Syncing newest first…":"Queued",state:D}),T>1||l==="syncing_others"||l==="complete"?t.jsx(H,{label:"Other mailboxes",detail:G==="ok"?`${T-1} mailboxes synced`:G==="running"?"Syncing…":"Queued",state:G}):null]}),v&&t.jsxs("div",{className:"mt-2 space-y-2",children:[t.jsxs("p",{className:"text-xs text-danger",children:["Sync stalled. The account is still active —"," ",t.jsx("button",{type:"button",className:"underline",onClick:()=>{d.invalidateQueries({queryKey:Y({path:{accountId:i??""}}).queryKey})},children:"retry"})]}),C&&t.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:C})]})]})})}function Bt({skipWelcome:e=!1,onComplete:r,onCancel:s}){const[a,n]=c.useState(e?"connector":"welcome"),[o,m]=c.useState({email:"",displayName:"",imapConfig:et,smtpConfig:st,username:"",password:"",discoveryResult:null,discovered:!1,createdAccountId:null}),d=c.useCallback(()=>n("connector"),[]),i=c.useCallback(()=>n("address"),[]),x=c.useCallback(()=>n("microsoft-email"),[]),k=c.useCallback(()=>{e?s?.():n("welcome")},[e,s]),j=c.useCallback((u,v,p)=>{let C=et,g=st,b=!1;p&&(b=p.source!=="heuristic",C={host:p.imap.host,port:p.imap.port,security:p.imap.security},g={host:p.smtp.host,port:p.smtp.port,security:p.smtp.security}),m(T=>({...T,email:u,displayName:v,imapConfig:C,smtpConfig:g,discoveryResult:p,discovered:b,username:u})),n("servers")},[]),f=c.useCallback((u,v)=>{m(p=>({...p,imapConfig:u,smtpConfig:v}))},[]),S=c.useCallback((u,v)=>{m(p=>({...p,username:u,password:v}))},[]),h=c.useCallback(()=>n("sync"),[]),y=c.useCallback(u=>{r(u)},[r]);switch(a){case"welcome":return t.jsx(Mt,{onStart:d});case"connector":return t.jsx(Ft,{onContinue:i,onMicrosoft:x,onBack:k,showBack:!e});case"microsoft-email":return t.jsx(Ot,{onBack:()=>n("connector"),onRedirecting:()=>{}});case"address":return t.jsx(zt,{initialEmail:o.email,initialDisplayName:o.displayName,onContinue:j,onBack:()=>n("connector")});case"servers":return t.jsx(Rt,{email:o.email,imapConfig:o.imapConfig,smtpConfig:o.smtpConfig,discovered:o.discovered,onContinue:()=>n("credentials"),onBack:()=>n("address"),onChange:f});case"credentials":return t.jsx(Ht,{email:o.email,username:o.username,password:o.password,onContinue:()=>n("test"),onBack:()=>n("servers"),onChange:S});case"test":return t.jsx($t,{email:o.email,imapConfig:o.imapConfig,smtpConfig:o.smtpConfig,username:o.username,password:o.password,onSuccess:h,onBackToCredentials:()=>n("credentials"),onBackToServers:()=>n("servers")});case"sync":return t.jsx(_t,{email:o.email,displayName:o.displayName,imapConfig:o.imapConfig,smtpConfig:o.smtpConfig,username:o.username,password:o.password,onGoToInbox:y})}}export{Bt as O,it as P,tt as g,q as s};
|
|
1
|
+
import{a as ot,j as t,b as O,bt as U,h as rt,r as c,d as ct,y as A,$ as lt,at as V,bo as mt,br as ut,aq as X,bG as Y,ay as dt,B as N,i as W,bq as pt,k as Q,bB as ht,n as xt}from"./index-DccQqmHT.js";import{K as ft}from"./kbd-CJm0PdtR.js";import{c as yt,M as gt}from"./account-form-helpers-C-R-t-TP.js";const K=ot("AtSign",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8",key:"7n84p3"}]]);const vt=ot("Server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]);function bt({url:e}){return t.jsxs("p",{className:"text-2xs text-fg-subtle",children:["Stored encrypted, used only to connect to your mail server."," ",e?t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"How to create an app password"}):t.jsx("span",{children:"Check your provider's help for app password instructions."})]})}function jt({raised:e,className:r,...s}){return t.jsx("div",{className:O("rounded-sm border border-line bg-surface",e?"bg-surface-raised shadow-sm":"",r),...s})}function I({className:e,children:r,...s}){return t.jsx("label",{className:O("mb-1 block text-xs font-medium text-fg-muted",e),...s,children:r})}function J({value:e,defaultValue:r,onValueChange:s,...a}){return s?t.jsxs(U,{value:e,onChange:n=>s(n.target.value),...a,children:[t.jsx("option",{value:"tls",children:"TLS/SSL"}),t.jsx("option",{value:"starttls",children:"STARTTLS"}),t.jsx("option",{value:"none",children:"None (insecure)"})]}):t.jsxs(U,{defaultValue:r??e,...a,children:[t.jsx("option",{value:"tls",children:"TLS/SSL"}),t.jsx("option",{value:"starttls",children:"STARTTLS"}),t.jsx("option",{value:"none",children:"None (insecure)"})]})}function q(e){return{tls:e==="tls",startTls:e==="starttls"}}function St({steps:e,activeStep:r}){return t.jsx("ol",{className:"flex items-center gap-1",children:e.map((s,a)=>{const n=a<r,o=a===r;return t.jsxs("li",{className:"flex items-center gap-1",children:[a>0&&t.jsx("span",{className:"h-px w-5 bg-line","aria-hidden":!0}),t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:O("flex size-5 items-center justify-center rounded-full text-2xs font-semibold tabular-nums",n&&"bg-accent text-accent-fg",o&&"bg-accent-soft text-accent ring-1 ring-accent",!n&&!o&&"bg-surface-sunken text-fg-subtle"),children:n?t.jsx(rt,{className:"size-3"}):a+1}),t.jsx("span",{className:O("hidden text-2xs sm:inline",o?"font-medium text-fg":"text-fg-subtle"),children:s})]})]},s)})})}function L({steps:e,activeStep:r,title:s,subtitle:a,children:n,footer:o,hideSteps:m}){return t.jsxs("div",{className:"flex min-h-dvh w-full flex-col items-center overflow-y-auto bg-canvas px-8 pb-8 pt-8 font-sans text-fg sm:pt-[30vh]",children:[!m&&t.jsx("div",{className:"mb-5 w-full max-w-xl",children:t.jsx(St,{steps:e,activeStep:r})}),t.jsxs(jt,{raised:!0,className:"w-full max-w-xl",children:[t.jsxs("div",{className:"px-5 pt-5",children:[t.jsx("h1",{className:"text-xl font-semibold text-fg",children:s}),a&&t.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:a})]}),t.jsx("div",{className:"px-5 py-5",children:n}),o&&t.jsx("div",{className:"flex items-center justify-between gap-3 border-t border-line px-5 py-3",children:o})]})]})}const wt="Coming soon — use IMAP for now.";function B({name:e,description:r,icon:s,comingSoon:a,selected:n,onSelect:o}){const[m,d]=c.useState(!1),i=()=>{if(o){o();return}a&&d(!0)};return t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("button",{type:"button",onClick:i,"aria-disabled":a||void 0,className:O("flex flex-col items-start gap-2 rounded-sm border p-3 text-left transition-colors",n?"border-accent-2 bg-accent-2-soft":"border-line bg-surface hover:border-line-strong",a&&"opacity-55"),children:[t.jsx("span",{className:O("text-fg-muted",n&&"text-accent-2"),children:s}),t.jsxs("span",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm font-semibold text-fg",children:e}),a&&t.jsx("span",{className:"rounded-full bg-surface-sunken px-1.5 py-0.5 text-2xs text-fg-subtle",children:"soon"})]}),t.jsx("span",{className:"text-xs text-fg-subtle",children:r})]}),m&&t.jsx("p",{className:"text-2xs text-fg-subtle",children:wt})]})}function Z({legend:e,badge:r,host:s,port:a,security:n,readOnly:o,onHostChange:m,onPortChange:d,onSecurityChange:i,hostPlaceholder:x,portPlaceholder:k}){const j=c.useId(),f=c.useId(),S=c.useId();return t.jsxs("fieldset",{children:[t.jsxs("legend",{className:"flex items-center gap-2 text-sm font-semibold text-fg",children:[e,r&&t.jsx(ct,{tone:r.tone,children:r.label})]}),t.jsxs("div",{className:"mt-2 grid grid-cols-1 gap-3 sm:grid-cols-[1fr_6rem_8rem] sm:gap-2",children:[t.jsxs("div",{children:[t.jsx(I,{htmlFor:j,children:"Host"}),m?t.jsx(A,{id:j,readOnly:o,value:s,onChange:h=>m(h.target.value),placeholder:x}):t.jsx(A,{id:j,readOnly:o,defaultValue:s,placeholder:x})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:f,children:"Port"}),d?t.jsx(A,{id:f,readOnly:o,value:a,onChange:h=>d(h.target.value),placeholder:k}):t.jsx(A,{id:f,readOnly:o,defaultValue:a,placeholder:k})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:S,children:"Security"}),i?t.jsx(J,{id:S,value:n,onValueChange:i}):t.jsx(J,{id:S,defaultValue:n})]})]})]})}function H({label:e,detail:r,state:s}){return t.jsxs("div",{className:"flex items-start gap-3 py-2",children:[t.jsxs("span",{className:O("mt-0.5 flex size-5 shrink-0 items-center justify-center rounded-full text-2xs",s==="ok"&&"bg-positive text-accent-fg",s==="failed"&&"bg-danger text-accent-fg",s==="running"&&"border border-accent text-accent",s==="pending"&&"border border-line text-fg-subtle"),children:[s==="ok"&&t.jsx(rt,{className:"size-3"}),s==="failed"&&"!",s==="running"&&t.jsx("span",{className:"size-2 animate-pulse rounded-full bg-accent"})]}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:O("text-sm",s==="failed"?"font-medium text-danger":"text-fg"),children:e}),r&&t.jsx("div",{className:"mt-0.5 text-xs text-fg-subtle",children:r})]})]})}const kt={"gmail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"googlemail.com":{imap:{host:"imap.gmail.com",port:993,security:"tls"},smtp:{host:"smtp.gmail.com",port:587,security:"starttls"},source:"provider-table"},"outlook.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"hotmail.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"live.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"msn.com":{imap:{host:"outlook.office365.com",port:993,security:"tls"},smtp:{host:"smtp.office365.com",port:587,security:"starttls"},source:"provider-table"},"icloud.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"me.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"mac.com":{imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},source:"provider-table"},"fastmail.com":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"fastmail.fm":{imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},source:"provider-table"},"yahoo.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"yahoo.co.uk":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"ymail.com":{imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},source:"provider-table"},"aol.com":{imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},source:"provider-table"},"zoho.com":{imap:{host:"imap.zoho.com",port:993,security:"tls"},smtp:{host:"smtp.zoho.com",port:465,security:"tls"},source:"provider-table"},"gmx.com":{imap:{host:"imap.gmx.com",port:993,security:"tls"},smtp:{host:"smtp.gmx.com",port:587,security:"starttls"},source:"provider-table"},"gmx.net":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"gmx.de":{imap:{host:"imap.gmx.net",port:993,security:"tls"},smtp:{host:"mail.gmx.net",port:587,security:"starttls"},source:"provider-table"},"web.de":{imap:{host:"imap.web.de",port:993,security:"tls"},smtp:{host:"smtp.web.de",port:587,security:"starttls"},source:"provider-table"},"mail.com":{imap:{host:"imap.mail.com",port:993,security:"tls"},smtp:{host:"smtp.mail.com",port:465,security:"tls"},source:"provider-table"},"hey.com":{imap:{host:"imap.hey.com",port:993,security:"tls"},smtp:{host:"smtp.hey.com",port:465,security:"tls"},source:"provider-table"},"tutanota.com":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"tuta.io":{imap:{host:"mail.tutanota.com",port:993,security:"tls"},smtp:{host:"mail.tutanota.com",port:465,security:"tls"},source:"provider-table"},"posteo.de":{imap:{host:"posteo.de",port:993,security:"tls"},smtp:{host:"posteo.de",port:465,security:"tls"},source:"provider-table"},"runbox.com":{imap:{host:"imap.runbox.com",port:993,security:"tls"},smtp:{host:"smtp.runbox.com",port:587,security:"starttls"},source:"provider-table"},"mailbox.org":{imap:{host:"imap.mailbox.org",port:993,security:"tls"},smtp:{host:"smtp.mailbox.org",port:465,security:"tls"},source:"provider-table"},"hushmail.com":{imap:{host:"imap.hushmail.com",port:993,security:"tls"},smtp:{host:"smtp.hushmail.com",port:465,security:"tls"},source:"provider-table"}},Nt={"gmail.com":"https://support.google.com/accounts/answer/185833","googlemail.com":"https://support.google.com/accounts/answer/185833","yahoo.com":"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html","icloud.com":"https://support.apple.com/en-us/102654","me.com":"https://support.apple.com/en-us/102654","mac.com":"https://support.apple.com/en-us/102654","fastmail.com":"https://www.fastmail.help/hc/en-us/articles/360058752854","fastmail.fm":"https://www.fastmail.help/hc/en-us/articles/360058752854","outlook.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","hotmail.com":"https://support.microsoft.com/en-us/account-billing/manage-app-passwords-for-two-step-verification-d6dc8c6d-4bf7-4851-ad95-6d07799387e9","zoho.com":"https://help.zoho.com/portal/en/kb/zoho-mail/client-configuration/imap-access/articles/zoho-mail-app-passwords"};function nt(e){try{const s=new DOMParser().parseFromString(e,"application/xml");if(s.querySelector("parsererror"))return null;const a=s.querySelectorAll("incomingServer[type='imap']"),n=s.querySelectorAll("outgoingServer[type='smtp']");if(!a.length||!n.length)return null;const o=a[0],m=n[0],d=o.querySelector("hostname")?.textContent?.trim(),i=o.querySelector("port")?.textContent?.trim(),x=o.querySelector("socketType")?.textContent?.trim().toUpperCase(),k=m.querySelector("hostname")?.textContent?.trim(),j=m.querySelector("port")?.textContent?.trim(),f=m.querySelector("socketType")?.textContent?.trim().toUpperCase();if(!d||!i||!k||!j)return null;const S=h=>h==="SSL"||h==="TLS"||h==="SSL/TLS"?"tls":h==="STARTTLS"?"starttls":"none";return{imap:{host:d,port:Number.parseInt(i,10),security:S(x)},smtp:{host:k,port:Number.parseInt(j,10),security:S(f)},source:"mozilla-autoconfig"}}catch{return null}}async function Ct(e,r){try{const s=`https://autoconfig.thunderbird.net/v1.1/${e}`,a=await fetch(s,{signal:r});if(!a.ok)return null;const n=await a.text(),o=nt(n);return o||null}catch{return null}}async function Et(e,r){try{const s=`https://autoconfig.${e}/mail/config-v1.1.xml`,a=await fetch(s,{signal:r});if(!a.ok)return null;const n=await a.text(),o=nt(n);return o?{...o,source:"domain-autoconfig"}:null}catch{return null}}function Tt(e){return{imap:{host:`imap.${e}`,port:993,security:"tls"},smtp:{host:`smtp.${e}`,port:587,security:"starttls"},source:"heuristic"}}async function Pt(e,r=1500){const s=e.indexOf("@");if(s===-1)return null;const a=e.slice(s+1).toLowerCase();if(!a)return null;const n=kt[a];if(n)return n;const o=new AbortController,m=setTimeout(()=>o.abort(),r);try{const d=await Ct(a,o.signal);if(d)return d;const i=await Et(a,o.signal);if(i)return i}finally{clearTimeout(m)}return Tt(a)}function At(e){const r=e.indexOf("@");return r===-1?"Looking up server settings…":`Looking up settings for ${e.slice(r+1)}…`}function at(e){const r=e.indexOf("@");if(r===-1)return;const s=e.slice(r+1).toLowerCase();return Nt[s]}const it=[{id:"icloud",label:"iCloud",username:"full-email",imap:{host:"imap.mail.me.com",port:993,security:"tls"},smtp:{host:"smtp.mail.me.com",port:587,security:"starttls"},passwordHelp:{text:"iCloud requires an app-specific password, not your Apple ID password. Generate one under Sign-In & Security → App-Specific Passwords.",url:"https://support.apple.com/en-us/102654"}},{id:"yahoo",label:"Yahoo",username:"full-email",imap:{host:"imap.mail.yahoo.com",port:993,security:"tls"},smtp:{host:"smtp.mail.yahoo.com",port:465,security:"tls"},passwordHelp:{text:"Yahoo requires an app password, not your login password. Generate one under Account Security.",url:"https://help.yahoo.com/kb/generate-manage-third-party-passwords-sln15241.html"}},{id:"aol",label:"AOL",username:"full-email",imap:{host:"imap.aol.com",port:993,security:"tls"},smtp:{host:"smtp.aol.com",port:465,security:"tls"},passwordHelp:{text:"AOL requires an app password, not your login password. Generate one under Account Security.",url:"https://login.aol.com/account/security"}},{id:"fastmail",label:"Fastmail",username:"full-email",imap:{host:"imap.fastmail.com",port:993,security:"tls"},smtp:{host:"smtp.fastmail.com",port:465,security:"tls"},passwordHelp:{text:"Fastmail requires an app password, not your login password. Create one under Settings → Privacy & Security → App passwords.",url:"https://www.fastmail.help/hc/en-us/articles/360058752854"}}];function tt(e){return it.find(r=>r.id===e)}const It={"icloud.com":"icloud","me.com":"icloud","mac.com":"icloud","yahoo.com":"yahoo","yahoo.co.uk":"yahoo","ymail.com":"yahoo","aol.com":"aol","fastmail.com":"fastmail","fastmail.fm":"fastmail"};function Lt(e){const r=e.indexOf("@");if(r===-1)return"";const s=e.slice(r+1).toLowerCase();return It[s]??""}const M=["Connector","Address","Servers","Credentials","Test","Sync"],z={connector:0,address:1,servers:2,credentials:3,test:4,sync:5},et={host:"",port:993,security:"tls"},st={host:"",port:587,security:"starttls"};function Mt({onStart:e}){return c.useEffect(()=>{const r=s=>{s.key==="Enter"&&e()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e]),t.jsx(L,{steps:M,activeStep:0,hideSteps:!0,title:"Welcome to Remit",subtitle:"One inbox for all your mail, with context about every message.",footer:t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"text-2xs text-fg-subtle",children:[t.jsx(ft,{children:"Enter"})," to continue"]}),t.jsx(N,{variant:"primary",onClick:e,children:"Add your first account"})]}),children:t.jsxs("div",{className:"flex flex-col items-start py-5",children:[t.jsx("span",{className:"flex size-14 items-center justify-center rounded-md bg-accent-soft",children:t.jsx(gt,{className:"size-7 text-accent"})}),t.jsx("p",{className:"mt-5 max-w-sm text-sm leading-relaxed text-fg-muted",children:"Remit syncs your existing mailboxes and tells you who is really writing to you — sender history, authenticity checks, and similar messages, right next to every email."})]})})}function Ft({onContinue:e,onMicrosoft:r,onBack:s,showBack:a}){const[n,o]=c.useState("imap");c.useEffect(()=>{const d=i=>{i.key==="Enter"&&(n==="microsoft"?r():e()),i.key==="Escape"&&s()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[e,r,s,n]);const m=()=>{n==="microsoft"?r():e()};return t.jsx(L,{steps:M,activeStep:z.connector,title:"How does this account connect?",subtitle:"Choose a sign-in method. IMAP works with any provider.",footer:t.jsxs(t.Fragment,{children:[a?t.jsx(N,{variant:"ghost",onClick:s,children:"Back"}):t.jsx("span",{}),t.jsx(N,{variant:"primary",onClick:m,children:n==="microsoft"?"Continue with Microsoft":"Continue with IMAP"})]}),children:t.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[t.jsx(B,{name:"IMAP / SMTP",description:"Any mail provider — Fastmail, iCloud, your own server.",icon:t.jsx(vt,{className:"size-5"}),selected:n==="imap",onSelect:()=>o("imap")}),t.jsx(B,{name:"Gmail",description:"Sign in with Google. No app passwords.",icon:t.jsx(K,{className:"size-5"}),comingSoon:!0}),t.jsx(B,{name:"Outlook / Microsoft 365",description:"Sign in with Microsoft. Works with Outlook.com and work accounts.",icon:t.jsx(xt,{className:"size-5"}),selected:n==="microsoft",onSelect:()=>o("microsoft")})]})})}function Ot({onBack:e,onRedirecting:r}){const[s,a]=c.useState(""),[n,o]=c.useState(null),m=V({...ht(),onSuccess:i=>{r(),window.location.assign(i.authorizationUrl)},onError:i=>{o(i instanceof Error?i.message:"Failed to start sign-in")}}),d=()=>{o(null),m.mutate({body:{email:s.trim()||void 0}})};return c.useEffect(()=>{const i=x=>{x.key==="Enter"&&!m.isPending&&d(),x.key==="Escape"&&e()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[e,m.isPending]),t.jsx(L,{steps:M,activeStep:z.connector,title:"Sign in with Microsoft",subtitle:"You'll be redirected to Microsoft to sign in securely.",footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:e,children:"Back"}),t.jsx(N,{variant:"primary",onClick:d,disabled:m.isPending,icon:m.isPending?t.jsx(W,{className:"size-4 animate-spin"}):void 0,children:m.isPending?"Redirecting…":"Sign in with Microsoft"})]}),children:t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{children:[t.jsx(I,{htmlFor:"microsoft-email",children:"Email address (optional)"}),t.jsx(A,{id:"microsoft-email",icon:t.jsx(K,{className:"size-4"}),placeholder:"you@outlook.com",value:s,onChange:i=>a(i.target.value),type:"email",autoComplete:"email"}),t.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"Pre-fills the Microsoft sign-in form. Leave blank to choose on the Microsoft page."})]}),n&&t.jsx(Q,{tone:"danger",children:n})]})})}function zt({initialEmail:e,initialDisplayName:r,onContinue:s,onBack:a}){const[n,o]=c.useState(e),[m,d]=c.useState(r),[i,x]=c.useState(!1),[k,j]=c.useState(""),[f,S]=c.useState(null),h=c.useCallback(async()=>{const y=n.trim();if(!y.includes("@")||!y.includes(".")){S("Enter a valid email address.");return}S(null),x(!0),j(At(y));try{const u=await Pt(y);s(y,m.trim(),u)}finally{x(!1)}},[n,m,s]);return c.useEffect(()=>{const y=u=>{u.key==="Enter"&&!i&&h(),u.key==="Escape"&&a()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[h,i,a]),t.jsx(L,{steps:M,activeStep:z.address,title:"What's the email address?",subtitle:"We'll detect the server settings for you.",footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:a,children:"Back"}),t.jsx(N,{variant:"primary",disabled:i,onClick:()=>{h()},children:"Continue"})]}),children:t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{children:[t.jsx(I,{htmlFor:"onboarding-email",children:"Email address"}),t.jsx(A,{id:"onboarding-email",icon:t.jsx(K,{className:"size-4"}),placeholder:"you@example.com",value:n,onChange:y=>{o(y.target.value),S(null)},type:"email",autoComplete:"email"})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"onboarding-display-name",children:"Display name (optional)"}),t.jsx(A,{id:"onboarding-display-name",placeholder:"Alice",value:m,onChange:y=>d(y.target.value)}),t.jsx("p",{className:"mt-1.5 text-2xs text-fg-subtle",children:"What to call this account in Remit. Leave blank to use a name derived from the address."})]}),i&&t.jsxs("div",{className:"mt-3 flex items-center gap-2 text-xs text-fg-muted",children:[t.jsx(W,{className:"size-3.5 animate-spin text-accent"}),k]}),f&&!i&&t.jsx("div",{className:"mt-3",children:t.jsx(Q,{tone:"danger",children:f})})]})})}function Rt({email:e,imapConfig:r,smtpConfig:s,discovered:a,onContinue:n,onBack:o,onChange:m}){const[d,i]=c.useState(r),[x,k]=c.useState(s),[j,f]=c.useState(()=>Lt(e)),[S,h]=c.useState(!1),[y,u]=c.useState(null),v=tt(j),p=v!==void 0&&!S,C=c.useCallback(l=>{f(l),h(!1),u(null);const w=tt(l);w&&(i({host:w.imap.host,port:w.imap.port,security:w.imap.security}),k({host:w.smtp.host,port:w.smtp.port,security:w.smtp.security}))},[]);c.useEffect(()=>{m(d,x)},[d,x,m]);const g=d.host.trim()!=="",b=c.useCallback(()=>{if(!g){u("Enter the IMAP host.");return}u(null),n()},[g,n]);c.useEffect(()=>{const l=w=>{w.key==="Enter"&&b(),w.key==="Escape"&&o()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[b,o]);const T=e.split("@")[1]??"your domain",P=v?"Pick your provider to fill in the right settings — or choose Custom to enter them by hand.":a?"Found via autodiscovery — adjust anything that looks off.":`We couldn't detect settings for ${T} — enter them manually.`,F=p?{label:"preset",tone:"neutral"}:!v&&a?{label:"detected",tone:"positive"}:void 0,R=v?.passwordHelp.url??at(e);return t.jsx(L,{steps:M,activeStep:z.servers,title:"Confirm server settings",subtitle:P,footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:o,children:"Back"}),t.jsx(N,{variant:"primary",onClick:b,children:"Continue"})]}),children:t.jsxs("div",{className:"space-y-5",children:[y&&t.jsx(Q,{tone:"danger",children:y}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"provider-select",children:"Provider"}),t.jsxs(U,{id:"provider-select",value:j,onChange:l=>C(l.target.value),children:[t.jsx("option",{value:"",children:"Custom / other"}),it.map(l=>t.jsx("option",{value:l.id,children:l.label},l.id))]}),v&&t.jsx("p",{className:"mt-1 text-2xs text-fg-subtle",children:p?t.jsxs(t.Fragment,{children:["Server settings are pre-filled for ",v.label," and locked."," ",t.jsx("button",{type:"button",className:"text-accent underline",onClick:()=>h(!0),children:"Advanced"})," ","lets you edit them by hand."]}):t.jsxs(t.Fragment,{children:["Editing ",v.label,"'s settings by hand."]})})]}),t.jsx(Z,{legend:"IMAP — incoming",badge:F,readOnly:p,host:d.host,port:String(d.port),security:d.security,hostPlaceholder:"imap.example.com",portPlaceholder:"993",onHostChange:l=>{i(w=>({...w,host:l})),u(null)},onPortChange:l=>i(w=>({...w,port:Number(l)})),onSecurityChange:l=>i(w=>({...w,security:l}))}),t.jsx("p",{className:"text-2xs text-fg-subtle",children:"Sending (SMTP) is optional — leave it blank to set up a receive-only account and add sending later in Settings."}),t.jsx(Z,{legend:"SMTP — outgoing (optional)",badge:F,readOnly:p,host:x.host,port:String(x.port),security:x.security,hostPlaceholder:"smtp.example.com",portPlaceholder:"587",onHostChange:l=>{k(w=>({...w,host:l})),u(null)},onPortChange:l=>k(w=>({...w,port:Number(l)})),onSecurityChange:l=>k(w=>({...w,security:l}))}),v&&t.jsxs("p",{className:"text-2xs text-fg-subtle",children:[v.passwordHelp.text," ",R&&t.jsx("a",{href:R,target:"_blank",rel:"noopener noreferrer",className:"text-accent underline",children:"Get an app password"})]})]})})}function Ht({email:e,username:r,password:s,onContinue:a,onBack:n,onChange:o}){const[m,d]=c.useState(r||e),[i,x]=c.useState(s),[k,j]=c.useState(null),f=e.split("@")[1]??"",S=at(e),h=m.trim()!==""&&i.trim()!=="";c.useEffect(()=>{o(m,i)},[m,i,o]);const y=c.useCallback(()=>{if(!h){j("Enter your username and password.");return}j(null),a()},[h,a]);return c.useEffect(()=>{const u=v=>{v.key==="Enter"&&y(),v.key==="Escape"&&n()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[y,n]),t.jsx(L,{steps:M,activeStep:z.credentials,title:`Sign in to ${f||"your mail server"}`,subtitle:"Many providers require an app password instead of your normal one.",footer:t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:n,children:"Back"}),t.jsx(N,{variant:"primary",onClick:y,children:"Test connection"})]}),children:t.jsxs("div",{className:"space-y-3",children:[k&&t.jsx("div",{className:"rounded-md bg-danger-soft px-3 py-2 text-sm text-danger",children:k}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"credentials-username",children:"Username"}),t.jsx(A,{id:"credentials-username",value:m,onChange:u=>{d(u.target.value),j(null)},autoComplete:"username"})]}),t.jsxs("div",{children:[t.jsx(I,{htmlFor:"credentials-password",children:"Password or app password"}),t.jsx(A,{id:"credentials-password",type:"password",value:i,onChange:u=>{x(u.target.value),j(null)},autoComplete:"current-password"})]}),t.jsx(bt,{url:S})]})})}function $t({email:e,imapConfig:r,smtpConfig:s,username:a,password:n,onSuccess:o,onBackToCredentials:m,onBackToServers:d}){const[i,x]=c.useState({imapState:"running",smtpState:"pending",phase:"running"}),[k,j]=c.useState(0),f=s.host.trim()!=="",S=q(r.security),h=q(s.security),y=V({...pt()});c.useEffect(()=>{let p=!1;const C=[];return x({imapState:"running",smtpState:"pending",phase:"running"}),y.mutate({body:{username:a,password:n,imapHost:r.host,imapPort:r.port,imapTls:S.tls,imapStartTls:S.startTls,smtpHost:s.host,smtpPort:s.port,smtpTls:h.tls,smtpStartTls:h.startTls}},{onSuccess:g=>{if(p)return;const b=g.imapSuccess,T=f?g.smtpSuccess:!0;x({imapState:b?"ok":"failed",smtpState:f?"running":"ok",imapDetail:b?`Connected — ${r.host}:${r.port}`:g.imapError,phase:"running"}),C.push(window.setTimeout(()=>{if(p)return;const P=R=>{const l=R?.toLowerCase()??"";return l.includes("auth")||l.includes("login")||l.includes("535")||l.includes("credential")},F=!b&&P(g.imapError)||b&&f&&!g.smtpSuccess&&P(g.smtpError);x({imapState:b?"ok":"failed",smtpState:f?g.smtpSuccess?"ok":"failed":"ok",imapDetail:b?`Connected — ${r.host}:${r.port}`:g.imapError,smtpDetail:f?g.smtpSuccess?`Connected — ${s.host}:${s.port}`:g.smtpError:"Not set up — receive-only",rawError:b?f&&!g.smtpSuccess?g.smtpError:void 0:g.imapError,phase:b&&T?"success":F?"auth-failure":"network-failure"}),b&&T&&C.push(window.setTimeout(()=>{p||o()},800))},400))},onError:g=>{if(p)return;const b=g instanceof Error?g.message:"Connection failed";x({imapState:"failed",smtpState:"failed",imapDetail:b,smtpDetail:b,rawError:b,phase:"network-failure"})}}),()=>{p=!0;for(const g of C)window.clearTimeout(g)}},[k]);const{phase:u}=i;c.useEffect(()=>{const p=C=>{C.key==="Escape"&&(u==="auth-failure"?m():u==="network-failure"&&d())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[u,m,d]);const v=u==="auth-failure"?t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:m,children:"Back to credentials"}),t.jsx(N,{variant:"primary",onClick:()=>j(p=>p+1),children:"Retry"})]}):u==="network-failure"?t.jsxs(t.Fragment,{children:[t.jsx(N,{variant:"ghost",onClick:d,children:"Back to servers"}),t.jsx(N,{variant:"primary",onClick:()=>j(p=>p+1),children:"Retry"})]}):u==="success"?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-2xs text-fg-subtle",children:"Connection verified"}),t.jsx(N,{variant:"primary",onClick:o,children:"Start syncing"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-2xs text-fg-subtle",children:"Testing…"}),t.jsx("span",{})]});return t.jsx(L,{steps:M,activeStep:z.test,title:"Testing the connection",subtitle:`Checking ${e}`,footer:v,children:t.jsxs("div",{className:"divide-y divide-line",children:[t.jsx(H,{label:`IMAP — ${r.host}:${r.port}`,detail:i.imapDetail,state:i.imapState}),t.jsx(H,{label:f?`SMTP — ${s.host}:${s.port}`:"SMTP — sending",detail:f?i.smtpDetail:"Not set up — you can add sending later in Settings",state:i.smtpState}),(u==="auth-failure"||u==="network-failure")&&i.rawError&&t.jsxs("div",{className:"py-3",children:[u==="auth-failure"&&t.jsx("p",{className:"mb-2 text-xs text-fg-muted",children:"Check your password — many providers require an app password."}),t.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:i.rawError})]})]})})}function _t({email:e,displayName:r,imapConfig:s,smtpConfig:a,username:n,password:o,onGoToInbox:m}){const d=lt(),[i,x]=c.useState(null),[k,j]=c.useState(null),f=c.useRef(!1),S=q(s.security),h=q(a.security),y=V({...ut(),onSuccess:E=>{x(E.accountId),d.invalidateQueries({queryKey:mt()})},onError:E=>{j(E instanceof Error?E.message:"Failed to create account")}});c.useEffect(()=>{if(f.current)return;f.current=!0;const E=a.host.trim()!=="",$=yt({imapHost:s.host,smtpHost:a.host,smtpPort:a.port}),_=E?$??{smtpHost:a.host,smtpPort:a.port,smtpTls:h.tls,smtpStartTls:h.startTls}:null;y.mutate({body:{email:e,displayName:r||void 0,username:n!==e?n:void 0,password:o,imapHost:s.host,imapPort:s.port,imapTls:S.tls,imapStartTls:S.startTls,smtpHost:_?.smtpHost||void 0,smtpPort:_?.smtpPort||void 0,smtpTls:_?.smtpTls??!1,smtpStartTls:_?.smtpStartTls??!1}})},[]);const{data:u}=X({...Y({path:{accountId:i??""}}),enabled:!!i,refetchInterval:E=>{const $=E.state.data?.syncPhase;return $==="complete"||$==="error"?!1:2e3}}),v=u?.syncPhase==="error",{data:p}=X({...dt(),enabled:!!i&&v}),C=p?.accounts.find(E=>E.accountId===i)?.lastError,g=u?.mailboxes.find(E=>E.fullPath==="INBOX"||E.fullPath==="Inbox"),b=u?.mailboxCountTotal??0,T=u?.mailboxCountSynced??0,P=g?.messagesTotal??0,F=g?.messagesSynced??0,R=P>0?F/P:0,l=u?.syncPhase,w=v?"failed":l==="idle"||l===void 0||l==="discovering_mailboxes"?"running":b>0?"ok":"running",D=v?"failed":!l||l==="idle"||l==="discovering_mailboxes"?"pending":l==="syncing_inbox"||l==="syncing_others"?"running":"ok",G=v?"failed":!l||l==="idle"||l==="discovering_mailboxes"||l==="syncing_inbox"?"pending":l==="syncing_others"?"running":"ok";return k?t.jsx(L,{steps:M,activeStep:z.sync,title:"Couldn't create account",subtitle:"Something went wrong saving your account.",footer:t.jsxs(t.Fragment,{children:[t.jsx("span",{}),t.jsx(N,{variant:"primary",onClick:()=>{f.current=!1,j(null),y.mutate({body:{email:e,displayName:r||void 0,username:n!==e?n:void 0,password:o,imapHost:s.host,imapPort:s.port,imapTls:S.tls,imapStartTls:S.startTls,smtpHost:a.host||void 0,smtpPort:a.port||void 0,smtpTls:h.tls,smtpStartTls:h.startTls}})},children:"Retry"})]}),children:t.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:k})}):t.jsx(L,{steps:M,activeStep:z.sync,title:`Syncing ${e}`,subtitle:"Newest mail first — you can start reading right away.",footer:t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-2xs text-fg-subtle",children:"Sync continues in the background"}),t.jsx(N,{variant:"primary",onClick:()=>i&&m(i),children:"Go to inbox"})]}),children:y.isPending?t.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-muted",children:[t.jsx(W,{className:"size-4 animate-spin text-accent"}),"Creating your account…"]}):t.jsxs("div",{className:"space-y-3",children:[P>0&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-baseline justify-between text-xs",children:[t.jsx("span",{className:"font-medium text-fg",children:"INBOX"}),t.jsxs("span",{className:"text-fg-subtle tabular-nums",children:[F.toLocaleString()," / ",P.toLocaleString()," ","messages"]})]}),t.jsx("div",{className:"mt-1 h-1.5 overflow-hidden rounded-full bg-surface-sunken",children:t.jsx("div",{className:"h-full rounded-full bg-accent transition-all duration-500",style:{width:`${Math.max(2,R*100)}%`}})})]}),t.jsxs("div",{className:"divide-y divide-line",children:[t.jsx(H,{label:"Mailboxes discovered",detail:b>0?`${b} mailbox${b===1?"":"es"} found`:"Discovering…",state:w}),t.jsx(H,{label:"INBOX",detail:D==="ok"?`${F.toLocaleString()} messages synced`:D==="running"?"Syncing newest first…":"Queued",state:D}),T>1||l==="syncing_others"||l==="complete"?t.jsx(H,{label:"Other mailboxes",detail:G==="ok"?`${T-1} mailboxes synced`:G==="running"?"Syncing…":"Queued",state:G}):null]}),v&&t.jsxs("div",{className:"mt-2 space-y-2",children:[t.jsxs("p",{className:"text-xs text-danger",children:["Sync stalled. The account is still active —"," ",t.jsx("button",{type:"button",className:"underline",onClick:()=>{d.invalidateQueries({queryKey:Y({path:{accountId:i??""}}).queryKey})},children:"retry"})]}),C&&t.jsx("code",{className:"block rounded bg-surface-sunken px-2.5 py-2 text-2xs text-fg-muted",children:C})]})]})})}function Bt({skipWelcome:e=!1,onComplete:r,onCancel:s}){const[a,n]=c.useState(e?"connector":"welcome"),[o,m]=c.useState({email:"",displayName:"",imapConfig:et,smtpConfig:st,username:"",password:"",discoveryResult:null,discovered:!1,createdAccountId:null}),d=c.useCallback(()=>n("connector"),[]),i=c.useCallback(()=>n("address"),[]),x=c.useCallback(()=>n("microsoft-email"),[]),k=c.useCallback(()=>{e?s?.():n("welcome")},[e,s]),j=c.useCallback((u,v,p)=>{let C=et,g=st,b=!1;p&&(b=p.source!=="heuristic",C={host:p.imap.host,port:p.imap.port,security:p.imap.security},g={host:p.smtp.host,port:p.smtp.port,security:p.smtp.security}),m(T=>({...T,email:u,displayName:v,imapConfig:C,smtpConfig:g,discoveryResult:p,discovered:b,username:u})),n("servers")},[]),f=c.useCallback((u,v)=>{m(p=>({...p,imapConfig:u,smtpConfig:v}))},[]),S=c.useCallback((u,v)=>{m(p=>({...p,username:u,password:v}))},[]),h=c.useCallback(()=>n("sync"),[]),y=c.useCallback(u=>{r(u)},[r]);switch(a){case"welcome":return t.jsx(Mt,{onStart:d});case"connector":return t.jsx(Ft,{onContinue:i,onMicrosoft:x,onBack:k,showBack:!e});case"microsoft-email":return t.jsx(Ot,{onBack:()=>n("connector"),onRedirecting:()=>{}});case"address":return t.jsx(zt,{initialEmail:o.email,initialDisplayName:o.displayName,onContinue:j,onBack:()=>n("connector")});case"servers":return t.jsx(Rt,{email:o.email,imapConfig:o.imapConfig,smtpConfig:o.smtpConfig,discovered:o.discovered,onContinue:()=>n("credentials"),onBack:()=>n("address"),onChange:f});case"credentials":return t.jsx(Ht,{email:o.email,username:o.username,password:o.password,onContinue:()=>n("test"),onBack:()=>n("servers"),onChange:S});case"test":return t.jsx($t,{email:o.email,imapConfig:o.imapConfig,smtpConfig:o.smtpConfig,username:o.username,password:o.password,onSuccess:h,onBackToCredentials:()=>n("credentials"),onBackToServers:()=>n("servers")});case"sync":return t.jsx(_t,{email:o.email,displayName:o.displayName,imapConfig:o.imapConfig,smtpConfig:o.smtpConfig,username:o.username,password:o.password,onGoToInbox:y})}}export{Bt as O,it as P,tt as g,q as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s}from"./index-
|
|
1
|
+
import{a as s}from"./index-DccQqmHT.js";const u=s("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]),o=587,i=!1,e=!0,c=t=>t.replace(/^imap\./i,"smtp."),a=t=>{if((t.smtpHost?.trim()??"").length>0)return null;const n=t.imapHost.trim();return n.length===0?null:{smtpHost:c(n),smtpPort:o,smtpTls:i,smtpStartTls:e}},m=t=>{const r=t?.toLowerCase()??"";return r.includes("auth")||r.includes("login")||r.includes("535")||r.includes("credential")},l=(t,r)=>!t||!r||!m(t)?t:`${t} — ${r}`,d=t=>t.smtpEnabled!==!0;export{u as M,d as a,l as b,a as c,c as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as i,z as nt,r as O,b as jt,X as Oe,R as X,$ as Gt,at as Ne,bq as Ns,bo as Fe,br as Ts,bs as As,B as se,bt as _s,y as de,i as et,h as St,ah as wt,bu as Es,bv as ke,bw as be,bx as Nt,ai as Ps,by as Vs,bz as ks,D as Yt,bA as Tt,ae as Ds,aq as Fs,ay as Cs,bB as Os,bC as Is,bD as Rs,k as At,d as Ms,bE as _t,bF as Us,T as Ls}from"./index-DsR4Mk7n.js";import{u as Hs,R as zs}from"./useSignature-B22ZnEj4.js";import{S as Bs,A as qs}from"./settings-screen-6C3zeyy1.js";import{g as Et,P as $s,s as Ue,O as Ws}from"./OnboardingWizard-74ApF1TM.js";import{c as Ks,b as Pt,d as Gs}from"./account-form-helpers-C1-XCp2v.js";import{D as Ys}from"./download-B21Knqu2.js";import{E as Zs}from"./ErrorState-DaIYWAtU.js";import{e as Qs}from"./format-B6Elex-n.js";import"./avatar-WAi3XoGV.js";import"./kbd-BKNut3M9.js";function Xs({title:e,description:s,action:t}){return i.jsxs("div",{className:"rounded-sm border border-danger/50",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-danger/30 bg-danger-soft px-row-inset py-2",children:[i.jsx(nt,{className:"size-4 text-danger"}),i.jsx("h2",{className:"text-sm font-semibold text-danger",children:"Danger zone"})]}),i.jsxs("div",{className:"flex flex-col gap-3 px-row-inset py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-fg",children:e}),i.jsx("p",{className:"text-xs text-fg-muted",children:s})]}),i.jsx("div",{className:"shrink-0",children:t})]})]})}function Vt({isOpen:e,onClose:s,title:t,children:a,footer:c}){return O.useEffect(()=>{if(!e)return;const d=n=>{n.key==="Escape"&&s()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,s]),i.jsxs(i.Fragment,{children:[i.jsx("div",{className:jt("fixed inset-0 z-40 bg-black/30 transition-opacity",e?"opacity-100":"pointer-events-none opacity-0"),onClick:s,"aria-hidden":"true"}),i.jsxs("div",{className:jt("fixed top-0 right-0 z-50 h-full w-full border-l border-line bg-canvas shadow-xl sm:w-[400px] sm:max-w-[90vw]","transform transition-transform duration-200 ease-out",e?"translate-x-0":"pointer-events-none translate-x-full"),role:"dialog","aria-modal":"true","aria-hidden":!e,inert:!e,"aria-labelledby":"slide-panel-title",children:[i.jsxs("div",{className:"flex h-14 items-center justify-between border-b border-line px-4",children:[i.jsx("h2",{id:"slide-panel-title",className:"font-semibold",children:t}),i.jsx("button",{type:"button",onClick:s,className:"rounded-md p-1.5 transition-colors hover:bg-surface-raised","aria-label":"Close",children:i.jsx(Oe,{className:"size-5"})})]}),i.jsxs("div",{className:"flex h-[calc(100%-3.5rem)] flex-col",children:[i.jsx("div",{className:"flex-1 overflow-auto p-4",children:a}),c&&i.jsx("div",{className:"flex justify-end gap-3 border-t border-line bg-canvas p-4",children:c})]})]})]})}var Ie=e=>e.type==="checkbox",je=e=>e instanceof Date,G=e=>e==null;const ot=e=>typeof e=="object";var z=e=>!G(e)&&!Array.isArray(e)&&ot(e)&&!je(e),Js=e=>z(e)&&e.target?Ie(e.target)?e.target.checked:e.target.value:e,er=(e,s)=>s.split(".").some((t,a,c)=>!isNaN(Number(t))&&e.has(c.slice(0,a).join("."))),Zt=e=>{const s=e.constructor&&e.constructor.prototype;return z(s)&&s.hasOwnProperty("isPrototypeOf")},$e=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function B(e){if(e instanceof Date)return new Date(e);const s=typeof FileList<"u"&&e instanceof FileList;if($e&&(e instanceof Blob||s))return e;const t=Array.isArray(e);if(!t&&!(z(e)&&Zt(e)))return e;const a=t?[]:Object.create(Object.getPrototypeOf(e));for(const c in e)Object.prototype.hasOwnProperty.call(e,c)&&(a[c]=B(e[c]));return a}const Ae={BLUR:"blur",FOCUS_OUT:"focusout",SUBMIT:"submit",TRIGGER:"trigger",VALID:"valid"},fe={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},ue={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Qt="root",lt=["__proto__","constructor","prototype"],tr=/^\w*$/;var Re=e=>tr.test(e),M=e=>e===void 0;const sr=/[.[\]'"]/;var We=e=>e.split(sr).filter(Boolean),g=(e,s,t)=>{if(!s||!z(e))return t;const a=Re(s)?[s]:We(s);if(a.some(d=>lt.includes(d)))return t;const c=a.reduce((d,n)=>G(d)?void 0:d[n],e);return M(c)||c===e?M(e[s])?t:e[s]:c},me=e=>typeof e=="boolean",ne=e=>typeof e=="function",F=(e,s,t)=>{let a=-1;const c=Re(s)?[s]:We(s),d=c.length,n=d-1;for(;++a<d;){const u=c[a];let j=t;if(a!==n){const E=e[u];j=z(E)||Array.isArray(E)?E:isNaN(+c[a+1])?{}:[]}if(lt.includes(u))return;e[u]=j,e=e[u]}};const rr=X.createContext(null);rr.displayName="HookFormControlContext";var ir=(e,s,t,a=!0)=>{const c={};for(const d in e)Object.defineProperty(c,d,{get:()=>{const n=d;return s._proxyFormState[n]!==fe.all&&(s._proxyFormState[n]=!a||fe.all),e[n]}});return c};const ar=$e?X.useLayoutEffect:X.useEffect;var Y=e=>typeof e=="string",nr=(e,s,t,a,c)=>Y(e)?(a&&s.watch.add(e),g(t,e,c)):Array.isArray(e)?e.map(d=>(a&&s.watch.add(d),g(t,d))):(a&&(s.watchAll=!0),t),tt=e=>G(e)||!ot(e);const kt=(e,s)=>s.length===0&&!Array.isArray(e)&&!Zt(e);function he(e,s,t=new WeakMap){if(e===s)return!0;if(tt(e)||tt(s))return Object.is(e,s);if(je(e)&&je(s))return Object.is(e.getTime(),s.getTime());const a=Object.keys(e),c=Object.keys(s);if(a.length!==c.length)return!1;if(kt(e,a)||kt(s,c))return Object.is(e,s);if(!a.length&&Array.isArray(e)!==Array.isArray(s))return!1;const d=t.get(e);if(d&&d.has(s))return!0;if(d)d.add(s);else{const n=new WeakSet;n.add(s),t.set(e,n)}for(const n of a){const u=e[n];if(!(n in s))return!1;if(n!=="ref"){const j=s[n];if(je(u)&&je(j)||(z(u)||Array.isArray(u))&&(z(j)||Array.isArray(j))?!he(u,j,t):!Object.is(u,j))return!1}}return!0}var Le=e=>({isOnSubmit:!e||e===fe.onSubmit,isOnBlur:e===fe.onBlur,isOnChange:e===fe.onChange,isOnAll:e===fe.all,isOnTouch:e===fe.onTouched}),Qe=(e,s,t)=>{if(t)return!1;if(s.watchAll||s.watch.has(e))return!0;for(const a of s.watch)if(e.startsWith(a)&&e.charAt(a.length)===".")return!0;return!1};const Ce=(e,s,t,a)=>{for(const c of t||Object.keys(e)){const d=g(e,c);if(d){const{_f:n,...u}=d;if(n){if(n.refs&&n.refs[0]&&s(n.refs[0],c)&&!a)return!0;if(n.ref&&s(n.ref,n.name)&&!a)return!0;if(Ce(u,s))break}else if(z(u)&&Ce(u,s))break}}};var Dt=(e,s,t)=>{const a=g(e,t),c=Array.isArray(a)?a:[];return F(c,Qt,s[t]),F(e,t,c),e},K=e=>z(e)&&!Object.keys(e).length,ct=e=>e.type==="file",Be=e=>{if(!$e)return!1;const s=e?e.ownerDocument:0;return e instanceof(s&&s.defaultView?s.defaultView.HTMLElement:HTMLElement)},dt=e=>e.type==="radio",qe=e=>e instanceof RegExp,ut=(e,s,t,a,c)=>s?{...t[e],types:{...t[e]&&t[e].types?t[e].types:{},[a]:c||!0}}:{};const Ft={value:!1,isValid:!1},Ct={value:!0,isValid:!0};var Xt=e=>{if(Array.isArray(e)){if(e.length>1){const s=e.filter(t=>t&&t.checked&&!t.disabled).map(t=>t.value);return{value:s,isValid:!!s.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!M(e[0].attributes.value)?M(e[0].value)||e[0].value===""?Ct:{value:e[0].value,isValid:!0}:Ct:Ft}return Ft};const Ot={isValid:!1,value:null};var Jt=e=>Array.isArray(e)?e.reduce((s,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:s,Ot):Ot;function It(e,s,t="validate"){if(Y(e)||Array.isArray(e)&&e.every(Y)||me(e)&&!e)return{type:t,message:Y(e)?e:"",ref:s}}var _e=e=>z(e)&&!qe(e)?e:{value:e,message:""},Rt=async(e,s,t,a,c,d)=>{const{ref:n,refs:u,required:j,maxLength:E,minLength:P,min:H,max:I,pattern:C,validate:N,name:f,valueAsNumber:b,mount:ie}=e._f,T=g(t,f);if(!ie||s.has(f))return{};const J=u?u[0]:n,R=A=>{if(c&&J.reportValidity){const _=me(A)?"":A||"";u?u.forEach(D=>D.setCustomValidity(_)):J.setCustomValidity(_),J.reportValidity()}},V={},oe=dt(n),re=Ie(n),pe=oe||re,le=(b||ct(n))&&M(n.value)&&M(T)||Be(n)&&n.value===""||T===""||Array.isArray(T)&&!T.length,W=ut.bind(null,f,a,V),ee=(A,_,D,$=ue.maxLength,w=ue.minLength)=>{const L=A?_:D;V[f]={type:A?$:w,message:L,ref:n,...W(A?$:w,L)}};if(d?!Array.isArray(T)||!T.length:j&&(!pe&&(le||G(T))||me(T)&&!T||re&&!Xt(u).isValid||oe&&!Jt(u).isValid)){const{value:A,message:_}=Y(j)?{value:!!j,message:j}:_e(j);if(A&&(V[f]={type:ue.required,message:_,ref:J,...W(ue.required,_)},!a))return R(_),V}if(!le&&(!G(H)||!G(I))){let A,_;const D=_e(I),$=_e(H);if(!G(T)&&!isNaN(T)){const w=n.valueAsNumber||T&&+T;G(D.value)||(A=w>D.value),G($.value)||(_=w<$.value)}else{const w=n.valueAsDate||new Date(T),L=ve=>new Date(new Date().toDateString()+" "+ve),ye=n.type=="time",Z=n.type=="week";Y(D.value)&&T&&(A=ye?L(T)>L(D.value):Z?T>D.value:w>new Date(D.value)),Y($.value)&&T&&(_=ye?L(T)<L($.value):Z?T<$.value:w<new Date($.value))}if((A||_)&&(ee(!!A,D.message,$.message,ue.max,ue.min),!a))return R(V[f].message),V}if((E||P)&&!le&&(Y(T)||d&&Array.isArray(T))){const A=_e(E),_=_e(P),D=!G(A.value)&&T.length>+A.value,$=!G(_.value)&&T.length<+_.value;if((D||$)&&(ee(D,A.message,_.message),!a))return R(V[f].message),V}if(C&&!le&&Y(T)){const{value:A,message:_}=_e(C);if(qe(A)&&!T.match(A)&&(V[f]={type:ue.pattern,message:_,ref:n,...W(ue.pattern,_)},!a))return R(_),V}if(N){if(ne(N)){const A=await N(T,t),_=It(A,J);if(_&&(V[f]={..._,...W(ue.validate,_.message)},!a))return R(_.message),V}else if(z(N)){let A={};for(const _ in N){if(!K(A)&&!a)break;const D=It(await N[_](T,t),J,_);D&&(A={...D,...W(_,D.message)},R(D.message),a&&(V[f]=A))}if(!K(A)&&(V[f]={ref:J,...A},!a))return V}}return R(!0),V},ze=e=>Array.isArray(e)?e:[e],es=e=>Array.isArray(e)?e.filter(Boolean):[];function or(e,s){const t=s.slice(0,-1).length;let a=0;for(;a<t;){if(G(e)){e=void 0;break}e=e[s[a]],a++}return e}function lr(e){for(const s in e)if(e.hasOwnProperty(s)&&!M(e[s]))return!1;return!0}function q(e,s){if(Y(s)&&Object.prototype.hasOwnProperty.call(e,s))return delete e[s],e;const t=Array.isArray(s)?s:Re(s)?[s]:We(s);if(t.some(n=>lt.includes(String(n))))return e;const a=t.length===1?e:or(e,t),c=t.length-1,d=t[c];return a&&delete a[d],c!==0&&(z(a)&&K(a)||Array.isArray(a)&&lr(a))&&q(e,t.slice(0,-1)),e}const ts=e=>{const s={};for(const t of Object.keys(e))if(ot(e[t])&&e[t]!==null&&!je(e[t])){const a=ts(e[t]);for(const c of Object.keys(a))s[`${t}.${c}`]=a[c]}else s[t]=e[t];return s},cr=X.createContext(null);cr.displayName="HookFormContext";var Mt=()=>{let e=[];return{get observers(){return e},next:c=>{for(const d of e)d.next&&d.next(c)},subscribe:c=>(e.push(c),{unsubscribe:()=>{e=e.filter(d=>d!==c)}}),unsubscribe:()=>{e=[]}}};function ss(e,s){const t={};for(const a in e)if(e.hasOwnProperty(a)){const c=e[a],d=s[a];if(c&&z(c)&&d){const n=ss(c,d);z(n)&&(t[a]=n)}else e[a]&&(t[a]=d)}return t}var rs=e=>e.type==="select-multiple",dr=e=>dt(e)||Ie(e),Xe=e=>Be(e)&&e.isConnected,ur=e=>{for(const s in e)if(ne(e[s]))return!0;return!1};function is(e){return Array.isArray(e)||z(e)&&!ur(e)}function as(e){return!!(e&&"_f"in e)}function ns(e){return Array.isArray(e)?!e.some(s=>!M(s)):!Object.keys(e).length}function st(e,s){Array.isArray(e)?e[s]=void 0:delete e[s]}function rt(e,s={},t){for(const a in e){const c=e[a],d=t&&t[a];is(c)&&(!Array.isArray(c)||!as(d))?(s[a]=Array.isArray(c)?[]:{},rt(c,s[a],d),ns(s[a])&&st(s,a)):M(c)||(s[a]=!0)}return s}function we(e,s,t,a){t||(t=rt(s,{},a));for(const c in e){const d=e[c],n=a&&a[c];is(d)&&(!Array.isArray(d)||!as(n))?(M(s)||tt(t[c])?t[c]=rt(d,Array.isArray(d)?[]:{},n):we(d,G(s)?{}:s[c],t[c],n),ns(t[c])&&st(t,c)):he(d,s[c])?st(t,c):t[c]=!0}return t}var os=(e,{valueAsNumber:s,valueAsDate:t,setValueAs:a})=>M(e)?e:s?e===""?NaN:e&&+e:t&&Y(e)?new Date(e):a?a(e):e;function Ut(e){const s=e.ref;return ct(s)?s.files:dt(s)?Jt(e.refs).value:rs(s)?[...s.selectedOptions].map(({value:t})=>t):Ie(s)?Xt(e.refs).value:os(M(s.value)?e.ref.value:s.value,e)}var fr=(e,s,t,a)=>{const c={};for(const d of e){const n=g(s,d);n&&F(c,d,n._f)}return{criteriaMode:t,names:[...e],fields:c,shouldUseNativeValidation:a}},De=e=>M(e)?e:qe(e)?e.source:z(e)?qe(e.value)?e.value.source:e.value:e;const Lt="AsyncFunction";var mr=e=>{if(!e||!e.validate)return!1;if(ne(e.validate))return e.validate.constructor.name===Lt;if(z(e.validate)){for(const s in e.validate)if(e.validate[s].constructor.name===Lt)return!0}return!1},hr=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Ht(e,s,t){const a=g(e,t);if(a||Re(t))return{error:a,name:t};const c=t.split(".");for(;c.length;){const d=c.join("."),n=g(s,d),u=g(e,d);if(n&&!Array.isArray(n)&&t!==d)return{name:t};if(u&&u.type)return{name:d,error:u};if(u&&u.root&&u.root.type)return{name:`${d}.root`,error:u.root};c.pop()}return{name:t}}var pr=(e,s,t,a)=>{t(e);const{name:c,...d}=e,n=Object.keys(d);return!n.length||a&&n.length>=Object.keys(s).length||n.find(u=>s[u]===(!a||fe.all))},yr=(e,s,t)=>!e||!s||e===s||ze(e).some(a=>a&&(t?a===s||a.startsWith(s+"."):a.startsWith(s)||s.startsWith(a))),xr=(e,s,t,a,c)=>c.isOnAll?!1:!t&&c.isOnTouch?!(s||e):(t?a.isOnBlur:c.isOnBlur)?!e:(t?a.isOnChange:c.isOnChange)?e:!0,gr=(e,s)=>!es(g(e,s)).length&&q(e,s);const vr={mode:fe.onSubmit,reValidateMode:fe.onChange,shouldFocusError:!0},Je="form",ls={submitCount:0,isDirty:!1,isReady:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{}};function br(e={}){let s={...vr,...e},t={...B(ls),isLoading:ne(s.defaultValues),errors:s.errors||{},disabled:s.disabled||!1},a={},c=z(s.defaultValues)||z(s.values)?B(s.defaultValues||s.values)||{}:{},d=s.shouldUnregister?{}:B(c),n={action:!1,mount:!1,watch:!1,keepIsValid:!1},u={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set,registerName:new Set};const j={},E={};let P=0,H=Le(s.mode),I=Le(s.reValidateMode);const C={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},N={...C};let f={...N};const b={array:Mt(),state:Mt()};let ie=0;const T=s.criteriaMode===fe.all,J=(r,o)=>l=>{clearTimeout(E[r]),E[r]=setTimeout(o,l)},R=async r=>{if(!n.keepIsValid&&!s.disabled&&(N.isValid||f.isValid||r)){const o=++ie;let l;s.resolver?(l=K((await D()).errors),o===ie&&V()):l=await L({fields:a,onlyCheckValid:!0,eventType:Ae.VALID}),o===ie&&l!==t.isValid&&b.state.next({isValid:l})}},V=(r,o)=>{!s.disabled&&(N.isValidating||N.validatingFields||f.isValidating||f.validatingFields)&&((r||Array.from(u.mount)).forEach(l=>{l&&(o?F(t.validatingFields,l,o):q(t.validatingFields,l))}),b.state.next({validatingFields:t.validatingFields,isValidating:!K(t.validatingFields)}))},oe=()=>{t.dirtyFields=we(c,d,void 0,a)},re=(r,o=[],l,m,h=!0,x=!0)=>{if(m&&l&&!s.disabled){if(n.action=!0,x&&Array.isArray(g(a,r))){const y=l(g(a,r),m.argA,m.argB);h&&F(a,r,y)}if(x&&Array.isArray(g(t.errors,r))){const y=l(g(t.errors,r),m.argA,m.argB);h&&F(t.errors,r,y),gr(t.errors,r)}if((N.touchedFields||f.touchedFields)&&x&&Array.isArray(g(t.touchedFields,r))){const y=l(g(t.touchedFields,r),m.argA,m.argB);h&&F(t.touchedFields,r,y)}(N.dirtyFields||f.dirtyFields)&&oe(),b.state.next({name:r,isDirty:Z(r,o),dirtyFields:t.dirtyFields,errors:t.errors,isValid:t.isValid})}else F(d,r,o)},pe=(r,o)=>{F(t.errors,r,o),t.errors={...t.errors},b.state.next({errors:t.errors})},le=r=>{t.errors=r,b.state.next({errors:t.errors,isValid:!1})},W=r=>{const o=Re(r)?[r]:We(r);let l=d,m=c;for(let h=0;h<o.length-1;h++){const x=o[h];if(l=G(l)?l:l[x],m=G(m)?m:m[x],l===null&&m!==null)return!0}return!1},ee=(r,o,l,m)=>{const h=g(a,r);if(h){if(W(r))return;const x=M(g(d,r)),y=g(d,r,M(l)?g(c,r):l);M(y)||m&&m.defaultChecked||o?F(d,r,o?y:Ut(h._f)):k(r,y),n.mount&&!n.action&&(R(),x&&t.isDirty&&(N.isDirty||f.isDirty)&&(Z()||(t.isDirty=!1,b.state.next({...t}))),e.shouldUnregister&&x&&!M(g(d,r))&&Qe(r,u)&&(n.watch=!0))}},A=(r,o,l,m,h)=>{let x=!1,y=!1;const v={name:r};if(!s.disabled||m===!0){if(!l||m){const S=he(g(c,r),o);(N.isDirty||f.isDirty)&&(y=t.isDirty,t.isDirty=v.isDirty=!S||Z(),x=y!==v.isDirty),y=!!g(t.dirtyFields,r),S!==t.isDirty?t.dirtyFields=we(c,d,void 0,a):S?q(t.dirtyFields,r):F(t.dirtyFields,r,!0),v.dirtyFields=t.dirtyFields,x=x||(N.dirtyFields||f.dirtyFields)&&y!==!S}if(l){const S=g(t.touchedFields,r);S||(F(t.touchedFields,r,l),v.touchedFields=t.touchedFields,x=x||(N.touchedFields||f.touchedFields)&&S!==l)}x&&h&&b.state.next(v)}return x?v:{}},_=(r,o,l,m)=>{const h=g(t.errors,r),x=(N.isValid||f.isValid)&&me(o)&&t.isValid!==o;if(s.delayError&&l?(j[r]=J(r,()=>pe(r,l)),j[r](s.delayError)):(clearTimeout(E[r]),delete j[r],l?F(t.errors,r,l):q(t.errors,r),t.errors={...t.errors}),(l?!he(h,l):h)||!K(m)||x){const y={...m,...x&&me(o)?{isValid:o}:{},errors:t.errors,name:r};t={...t,...y},b.state.next(y)}},D=async r=>(V(r,!0),await s.resolver(d,s.context,fr(r||u.mount,a,s.criteriaMode,s.shouldUseNativeValidation))),$=async r=>{const{errors:o}=await D(r);if(V(r),r){for(const l of r){const m=g(o,l);m?u.array.has(l)&&z(m)&&!Object.keys(m).some(h=>!Number.isNaN(Number(h)))?Dt(t.errors,{[l]:m},l):F(t.errors,l,m):q(t.errors,l)}t.errors={...t.errors}}else t.errors=o;return o},w=async({name:r,eventType:o})=>{if(e.validate){const l=await e.validate({formValues:d,formState:t,name:r,eventType:o});if(z(l))for(const m in l){const h=l[m];h&&Me(`${Je}.${m}`,{message:Y(h.message)?h.message:"",type:h.type||ue.validate})}else Y(l)||!l?Me(Je,{message:l||"",type:ue.validate}):mt(Je);return l}return!0},L=async({fields:r,onlyCheckValid:o,name:l,eventType:m,context:h={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(h.runRootValidation=!0,!await w({name:l,eventType:m})&&(h.valid=!1,o)))return h.valid;for(const x in r){const y=r[x];if(y){const{_f:v,...S}=y;if(v){const U=u.array.has(v.name),Q=y._f&&mr(y._f),xe=N.validatingFields||N.isValidating||f.validatingFields||f.isValidating;Q&&xe&&V([v.name],!0);const ge=await Rt(y,u.disabled,d,T,s.shouldUseNativeValidation&&!o,U);if(Q&&xe&&V([v.name]),ge[v.name]&&(h.valid=!1,o)||(!o&&(g(ge,v.name)?U?Dt(t.errors,ge,v.name):F(t.errors,v.name,ge[v.name]):q(t.errors,v.name)),e.shouldUseNativeValidation&&ge[v.name]))break}!K(S)&&await L({context:h,onlyCheckValid:o,fields:S,name:x,eventType:m})}}return h.valid},ye=()=>{for(const r of u.unMount){const o=g(a,r);o&&(o._f.refs?o._f.refs.every(l=>!Xe(l)):!Xe(o._f.ref))&&Ge(r)}u.unMount=new Set},Z=(r,o)=>(r&&o&&F(d,r,o),!he(n.mount?d:c,c)),ve=(r,o,l)=>nr(r,u,{...n.mount?d:M(o)?c:Y(r)?{[r]:o}:o},l,o),p=r=>es(g(n.mount?d:c,r,s.shouldUnregister?g(c,r,[]):[])),k=(r,o,l={},m=!1,h=!1)=>{const x=g(a,r);let y=o;if(x){const v=x._f;v&&(!v.disabled&&F(d,r,os(o,v)),y=Be(v.ref)&&G(o)?"":o,rs(v.ref)?[...v.ref.options].forEach(S=>S.selected=y.includes(S.value)):v.refs?Ie(v.ref)?v.refs.forEach(S=>{(!S.defaultChecked||!S.disabled)&&(Array.isArray(y)?S.checked=!!y.find(U=>U===S.value):S.checked=y===S.value||!!y)}):v.refs.forEach(S=>S.checked=S.value===y):ct(v.ref)?v.ref.value="":(v.ref.value=y,!v.ref.type&&!h&&b.state.next({name:r,values:m?d:B(d)})))}(l.shouldDirty||l.shouldTouch)&&A(r,y,l.shouldTouch,l.shouldDirty,!h),l.shouldValidate&&Ke(r,{delayError:l.delayError})},ce=(r,o,l,m=!1,h=!1)=>{for(const x in o){if(!o.hasOwnProperty(x))return;const y=o[x],v=r+"."+x,S=g(a,v);(u.array.has(r)||z(y)||S&&!S._f)&&!je(y)?ce(v,y,l,m,h):k(v,y,l,m,h)}},te=(r,o,l,m,h=!1)=>{const x=g(a,r),y=u.array.has(r),v=m?o:B(o),S=g(d,r),U=he(S,v);if(U||F(d,r,v),y)b.array.next({name:r,values:m?d:B(d)}),(N.isDirty||N.dirtyFields||f.isDirty||f.dirtyFields)&&l.shouldDirty&&(oe(),h||b.state.next({name:r,dirtyFields:t.dirtyFields,isDirty:Z(r,v)}));else{const Q=Array.isArray(v)&&!v.length||K(v);!x||x._f||G(v)||Q?k(r,v,l,m,h):ce(r,v,l,m,h)}if(!U&&!h){const Q=Qe(r,u),xe=m?d:B(d);b.state.next({...Q&&t,name:n.mount||Q?r:void 0,values:xe})}},ae=(r,o,l={})=>te(r,o,l,!1),Se=(r,o={})=>{const l=ne(r)?r(d):r;if(!he(d,l)){d={...d,...l};const m=ts(l);for(const h of u.mount)h in m&&te(h,m[h],o,!0,!0);b.state.next({...t,name:void 0,type:void 0,...P?{values:d}:{}}),o.shouldValidate&&R()}},Ee=async r=>{n.mount=!0;const o=r.target;let l=o.name,m=!0;const h=g(a,l),x=y=>{m=Number.isNaN(y)||je(y)&&isNaN(y.getTime())||he(y,g(d,l,y))};if(h){let y,v;const S=o.type?Ut(h._f):Js(r),U=r.type===Ae.BLUR||r.type===Ae.FOCUS_OUT,Q=!hr(h._f)&&!e.validate&&!s.resolver&&!g(t.errors,l)&&!h._f.deps,xe=Q||xr(U,g(t.touchedFields,l),t.isSubmitted,I,H),ge=Qe(l,u,U);if(F(d,l,S),U){if(!o||!o.readOnly){h._f.onBlur&&h._f.onBlur(r);const Ve=j[l];Ve&&Ve(0)}}else h._f.onChange&&h._f.onChange(r);const Pe=A(l,S,U),Ss=!K(Pe)||ge;if(!U&&b.state.next({name:l,type:r.type,...P?{values:B(d)}:{}}),xe)return(!Q||!t.isValid)&&(N.isValid||f.isValid)&&(s.mode==="onBlur"?U&&R():U||R()),Ss&&b.state.next({name:l,...ge?{}:Pe});if(!s.resolver&&e.validate&&await w({name:l,eventType:r.type}),!U&&ge&&b.state.next({...t}),s.resolver){const{errors:Ve}=await D([l]);if(V([l]),x(S),!m){!K(Pe)&&b.state.next(Pe);return}const ws=Ht(t.errors,a,l),bt=Ht(Ve,a,ws.name||l);y=bt.error,l=bt.name,v=K(Ve)}else V([l],!0),y=(await Rt(h,u.disabled,d,T,s.shouldUseNativeValidation))[l],V([l]),x(S),m&&(y?v=!1:(N.isValid||f.isValid)&&(v=await L({fields:a,onlyCheckValid:!0,name:l,eventType:r.type})));m&&(h._f.deps&&(!Array.isArray(h._f.deps)||h._f.deps.length>0)&&Ke(h._f.deps),_(l,v,y,Pe))}},Te=(r,o)=>{if(g(t.errors,o)&&r.focus)return r.focus(),1},Ke=async(r,o={})=>{let l,m;const h=ze(r);if(s.resolver){const x=await $(M(r)?r:h);l=K(x),m=r?!h.some(y=>g(x,y)):l}else r?(m=(await Promise.all(h.map(async x=>{const y=g(a,x);return await L({fields:y&&y._f?{[x]:y}:y,eventType:Ae.TRIGGER})}))).every(Boolean),!(!m&&!t.isValid)&&R()):m=l=await L({fields:a,name:r,eventType:Ae.TRIGGER});if(o.delayError&&s.delayError&&Y(r)){const x=g(t.errors,r);x?(q(t.errors,r),j[r]=J(r,()=>pe(r,x)),j[r](s.delayError)):(clearTimeout(E[r]),delete j[r])}return b.state.next({...!Y(r)||(N.isValid||f.isValid)&&l!==t.isValid?{}:{name:r},...s.resolver||!r?{isValid:l}:{},errors:t.errors}),o.shouldFocus&&!m&&Ce(a,Te,r?h:u.mount),m},ps=(r,o)=>{let l={...n.mount?d:c};return o&&(l=ss(o.dirtyFields?t.dirtyFields:t.touchedFields,l)),M(r)?l:Y(r)?g(l,r):r.map(m=>g(l,m))},ft=(r,o)=>({invalid:!!g((o||t).errors,r),isDirty:!!g((o||t).dirtyFields,r),error:g((o||t).errors,r),isValidating:!!g(t.validatingFields,r),isTouched:!!g((o||t).touchedFields,r)}),mt=r=>{const o=r?ze(r):void 0;o?.forEach(l=>q(t.errors,l)),o?o.forEach(l=>{b.state.next({name:l,errors:t.errors})}):b.state.next({errors:{}})},Me=(r,o,l)=>{const m=(g(a,r,{_f:{}})._f||{}).ref,h=g(t.errors,r)||{},{ref:x,message:y,type:v,...S}=h;F(t.errors,r,{...S,...o,ref:m}),b.state.next({name:r,errors:t.errors,isValid:!1}),l&&l.shouldFocus&&m&&m.focus&&m.focus()},ys=(r,o)=>{if(ne(r)){P++;const{unsubscribe:l}=b.state.subscribe({next:h=>"values"in h&&r(h.values||ve(void 0,o),h)});let m=!1;return{unsubscribe:()=>{m||(m=!0,P--,l())}}}return ve(r,o,!0)},ht=r=>{var o;const l=!!(!((o=r.formState)===null||o===void 0)&&o.values);l&&P++;const{unsubscribe:m}=b.state.subscribe({next:x=>{if(yr(r.name,x.name,r.exact)&&pr(x,r.formState||N,js,r.reRenderRoot)){const y={...d};r.callback({values:y,...t,...x,defaultValues:c})}}});if(!l)return m;let h=!1;return()=>{h||(h=!0,P--,m())}},xs=r=>(n.mount=!0,f={...f,...r.formState},ht({...r,formState:{...C,...r.formState}})),Ge=(r,o={})=>{for(const l of r?ze(r):u.mount)u.mount.delete(l),u.array.delete(l),o.keepValue||(q(a,l),q(d,l)),!o.keepError&&q(t.errors,l),!o.keepDirty&&q(t.dirtyFields,l),!o.keepTouched&&q(t.touchedFields,l),!o.keepIsValidating&&q(t.validatingFields,l),!s.shouldUnregister&&!o.keepDefaultValue&&q(c,l);b.state.next({values:B(d)}),b.state.next({...t,...o.keepDirty?{isDirty:Z()}:{}}),!o.keepIsValid&&R()},pt=({disabled:r,name:o})=>{if(me(r)&&n.mount||r||u.disabled.has(o)){const h=u.disabled.has(o)!==!!r;r?u.disabled.add(o):u.disabled.delete(o),h&&n.mount&&!n.action&&R()}},Ye=(r,o={})=>{let l=g(a,r);const m=me(o.disabled)||me(s.disabled),h=!u.registerName.has(r)&&l&&l._f&&!l._f.mount;return F(a,r,{...l||{},_f:{...l&&l._f?l._f:{ref:{name:r}},name:r,mount:!0,...o}}),u.mount.add(r),l&&!h?pt({disabled:me(o.disabled)?o.disabled:s.disabled,name:r}):ee(r,!0,o.value),{...m?{disabled:o.disabled||s.disabled}:{},...s.progressive?{required:!!o.required,min:De(o.min),max:De(o.max),minLength:De(o.minLength),maxLength:De(o.maxLength),pattern:De(o.pattern)}:{},name:r,onChange:Ee,onBlur:Ee,ref:x=>{if(x){u.registerName.add(r),Ye(r,o),u.registerName.delete(r),l=g(a,r);const y=M(x.value)&&x.querySelectorAll&&x.querySelectorAll("input,select,textarea")[0]||x,v=dr(y),S=l._f.refs||[];if(v?S.find(U=>U===y):y===l._f.ref)return;F(a,r,{_f:{...l._f,...v?{refs:[...S.filter(Xe),y,...Array.isArray(g(c,r))?[{}]:[]],ref:{type:y.type,name:r}}:{ref:y}}}),ee(r,!1,void 0,y)}else l=g(a,r,{}),l._f&&(l._f.mount=!1),(s.shouldUnregister||o.shouldUnregister)&&!(er(u.array,r)&&n.action)&&u.unMount.add(r)}}},Ze=()=>s.shouldFocusError&&!s.shouldUseNativeValidation&&Ce(a,Te,u.mount),gs=r=>{me(r)&&(b.state.next({disabled:r}),Ce(a,(o,l)=>{const m=g(a,l);m&&(o.disabled=m._f.disabled||r,Array.isArray(m._f.refs)&&m._f.refs.forEach(h=>{h.disabled=m._f.disabled||r}))},0,!1))},yt=(r,o)=>async l=>{let m;l&&(l.preventDefault&&l.preventDefault(),l.persist&&l.persist());let h=B(d);if(b.state.next({isSubmitting:!0}),s.resolver){const{errors:x,values:y}=await D();V(),t.errors=x,h=B(y)}else await L({fields:a,eventType:Ae.SUBMIT});if(u.disabled.size)for(const x of u.disabled)q(h,x);if(q(t.errors,Qt),K(t.errors)){b.state.next({errors:{}});try{await r(h,l)}catch(x){m=x}}else o&&await o({...t.errors},l),Ze(),setTimeout(Ze);if(b.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:K(t.errors)&&!m,submitCount:t.submitCount+1,errors:t.errors}),m)throw m},vs=(r,o={})=>{g(a,r)&&(M(o.defaultValue)?ae(r,B(g(c,r))):(ae(r,o.defaultValue),F(c,r,B(o.defaultValue))),o.keepTouched||q(t.touchedFields,r),o.keepDirty||(q(t.dirtyFields,r),t.isDirty=o.defaultValue?Z(r,B(g(c,r))):Z()),o.keepError||(q(t.errors,r),N.isValid&&R()),b.state.next({...t}))},xt=(r,o={})=>{const l=r?B(r):c,m=B(l),h=K(r),x=m,y=a;if(o.keepDefaultValues||(c=l),!o.keepValues){if(o.keepDirtyValues){const v=new Set([...u.mount,...Object.keys(we(c,d,void 0,y))]);for(const S of Array.from(v)){const U=g(t.dirtyFields,S),Q=g(d,S),xe=g(x,S);U&&!M(Q)?F(x,S,Q):!U&&!M(xe)&&ae(S,xe)}}else{if($e&&M(r))for(const v of u.mount){const S=g(a,v);if(S&&S._f){const U=Array.isArray(S._f.refs)?S._f.refs[0]:S._f.ref;if(Be(U)){const Q=U.closest("form");if(Q){Q.reset();break}}}}if(o.keepFieldsRef)for(const v of u.mount)ae(v,g(x,v));else a={}}if(s.shouldUnregister){if(d=o.keepDefaultValues?B(c):{},o.keepFieldsRef)for(const v of u.mount)F(d,v,g(x,v))}else d=B(x);b.array.next({values:{...x}}),b.state.next({name:void 0,type:void 0,values:{...x}})}u={mount:o.keepDirtyValues?u.mount:new Set,unMount:new Set,array:new Set,registerName:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},n.mount=!N.isValid||!!o.keepIsValid||!!o.keepDirtyValues||!s.shouldUnregister&&!K(x),n.watch=!!s.shouldUnregister,n.keepIsValid=!!o.keepIsValid,n.action=!1,o.keepErrors||(t.errors={}),b.state.next({submitCount:o.keepSubmitCount?t.submitCount:0,isDirty:h?!1:o.keepDirty?t.isDirty:o.keepValues?Z():!!(o.keepDefaultValues&&!he(r,c)),isSubmitted:o.keepIsSubmitted?t.isSubmitted:!1,dirtyFields:h?{}:o.keepDirtyValues?o.keepDefaultValues&&d?we(c,d,void 0,y):t.dirtyFields:o.keepDefaultValues&&r?we(c,r,void 0,y):o.keepDirty?t.dirtyFields:{},touchedFields:o.keepTouched?t.touchedFields:{},errors:o.keepErrors?t.errors:{},isSubmitSuccessful:o.keepIsSubmitSuccessful?t.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:c})},gt=(r,o)=>xt(ne(r)?r(d):r,{...s.resetOptions,...o}),bs=(r,o={})=>{const l=g(a,r),m=l&&l._f;if(m){const h=m.refs?m.refs[0]:m.ref;h.focus&&setTimeout(()=>{h.focus(),o.shouldSelect&&ne(h.select)&&h.select()})}},js=r=>{const{name:o,type:l,values:m,...h}=r;t={...t,...h}},vt={control:{register:Ye,unregister:Ge,getFieldState:ft,handleSubmit:yt,setError:Me,_subscribe:ht,_runSchema:D,_updateIsValidating:V,_focusError:Ze,_getWatch:ve,_getDirty:Z,_setValid:R,_setFieldArray:re,_setDisabledField:pt,_setErrors:le,_getFieldArray:p,_reset:xt,_resetDefaultValues:()=>ne(s.defaultValues)&&s.defaultValues().then(r=>{gt(r,s.resetOptions),b.state.next({isLoading:!1})}),_removeUnmounted:ye,_disableForm:gs,_subjects:b,_proxyFormState:N,get _fields(){return a},get _formValues(){return d},get _state(){return n},set _state(r){n=r},get _defaultValues(){return c},get _names(){return u},set _names(r){u=r},get _formState(){return t},get _options(){return s},set _options(r){s={...s,...r},H=Le(s.mode),I=Le(s.reValidateMode)}},subscribe:xs,trigger:Ke,register:Ye,handleSubmit:yt,watch:ys,setValue:ae,setValues:Se,getValues:ps,reset:gt,resetField:vs,resetDefaultValues:(r,o={})=>{if(c=B(r),!o.keepDirty){const l=we(c,d,void 0,a);t.dirtyFields=l,t.isDirty=!K(l)}o.keepIsValid||R(),b.state.next({...t,defaultValues:c})},clearErrors:mt,unregister:Ge,setError:Me,setFocus:bs,getFieldState:ft};return{...vt,formControl:vt}}function jr(e={}){const s=X.useRef(void 0),t=X.useRef(void 0),a=X.useRef(e.formControl),[c,d]=X.useState(()=>({...B(ls),isLoading:ne(e.defaultValues),errors:e.errors||{},disabled:e.disabled||!1,defaultValues:ne(e.defaultValues)?void 0:e.defaultValues}));if(!s.current||e.formControl&&a.current!==e.formControl)if(a.current=e.formControl,e.formControl)s.current={...e.formControl,formState:c},e.defaultValues&&!ne(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:u,...j}=br(e);s.current={...j,formState:c}}const n=s.current.control;return n._options=e,ar(()=>{const u=n._subscribe({formState:n._proxyFormState,callback:()=>d({...n._formState,defaultValues:n._defaultValues}),reRenderRoot:!0});return d(j=>({...j,isReady:!0})),n._formState.isReady=!0,u},[n]),X.useEffect(()=>n._disableForm(e.disabled),[n,e.disabled]),X.useEffect(()=>{e.mode&&(n._options.mode=e.mode),e.reValidateMode&&(n._options.reValidateMode=e.reValidateMode)},[n,e.mode,e.reValidateMode]),X.useEffect(()=>{e.errors&&(n._setErrors(e.errors),n._focusError())},[n,e.errors]),X.useEffect(()=>{e.shouldUnregister&&n._subjects.state.next({values:n._getWatch()})},[n,e.shouldUnregister]),X.useEffect(()=>{if(n._proxyFormState.isDirty){const u=n._getDirty();u!==c.isDirty&&n._subjects.state.next({isDirty:u})}},[n,c.isDirty]),X.useEffect(()=>{var u;e.values&&!he(e.values,t.current)?(n._reset(e.values,{keepFieldsRef:!0,...n._options.resetOptions}),!((u=n._options.resetOptions)===null||u===void 0)&&u.keepIsValid||n._setValid(),t.current=e.values,d(j=>({...j}))):n._resetDefaultValues()},[n,e.values]),X.useEffect(()=>{n._state.mount||(n._setValid(),n._state.mount=!0),n._state.watch&&(n._state.watch=!1,n._subjects.state.next({...n._formState})),n._removeUnmounted()}),s.current.formState=X.useMemo(()=>ir(c,n),[n,c]),s.current}const zt=(e,s,t)=>{if(e&&"reportValidity"in e){const a=g(t,s);e.setCustomValidity(a&&a.message||""),e.reportValidity()}},it=(e,s)=>{for(const t in s.fields){const a=s.fields[t];a&&a.ref&&"reportValidity"in a.ref?zt(a.ref,t,e):a&&a.refs&&a.refs.forEach(c=>zt(c,t,e))}},Bt=(e,s)=>{s.shouldUseNativeValidation&&it(e,s);const t={};for(const a in e){const c=g(s.fields,a),d=Object.assign(e[a]||{},{ref:c&&c.ref});if(Sr(s.names||Object.keys(e),a)){const n=Object.assign({},g(t,a));F(n,"root",d),F(t,a,n)}else F(t,a,d)}return t},Sr=(e,s)=>{const t=qt(s).replace(/[.*+?^${}()|\\]/g,"\\$&");return e.some(a=>qt(a).match(`^${t}\\.\\d+`))};function qt(e){return e.replace(/[\[\]]/g,"")}function cs(e,s,t){function a(u,j){var E;Object.defineProperty(u,"_zod",{value:u._zod??{},enumerable:!1}),(E=u._zod).traits??(E.traits=new Set),u._zod.traits.add(e),s(u,j);for(const P in n.prototype)P in u||Object.defineProperty(u,P,{value:n.prototype[P].bind(u)});u._zod.constr=n,u._zod.def=j}const c=t?.Parent??Object;class d extends c{}Object.defineProperty(d,"name",{value:e});function n(u){var j;const E=t?.Parent?new d:this;a(E,u),(j=E._zod).deferred??(j.deferred=[]);for(const P of E._zod.deferred)P();return E}return Object.defineProperty(n,"init",{value:a}),Object.defineProperty(n,Symbol.hasInstance,{value:u=>t?.Parent&&u instanceof t.Parent?!0:u?._zod?.traits?.has(e)}),Object.defineProperty(n,"name",{value:e}),n}class wr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const Nr={};function ds(e){return Nr}function Tr(e,s){return typeof s=="bigint"?s.toString():s}const us=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function He(e){return typeof e=="string"?e:e?.message}function fs(e,s,t){const a={...e,path:e.path??[]};if(!e.message){const c=He(e.inst?._zod.def?.error?.(e))??He(s?.error?.(e))??He(t.customError?.(e))??He(t.localeError?.(e))??"Invalid input";a.message=c}return delete a.inst,delete a.continue,s?.reportInput||delete a.input,a}const ms=(e,s)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:s,enumerable:!1}),Object.defineProperty(e,"message",{get(){return JSON.stringify(s,Tr,2)},enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Ar=cs("$ZodError",ms),hs=cs("$ZodError",ms,{Parent:Error}),_r=e=>(s,t,a,c)=>{const d=a?Object.assign(a,{async:!1}):{async:!1},n=s._zod.run({value:t,issues:[]},d);if(n instanceof Promise)throw new wr;if(n.issues.length){const u=new(c?.Err??e)(n.issues.map(j=>fs(j,d,ds())));throw us(u,c?.callee),u}return n.value},Er=_r(hs),Pr=e=>async(s,t,a,c)=>{const d=a?Object.assign(a,{async:!0}):{async:!0};let n=s._zod.run({value:t,issues:[]},d);if(n instanceof Promise&&(n=await n),n.issues.length){const u=new(c?.Err??e)(n.issues.map(j=>fs(j,d,ds())));throw us(u,c?.callee),u}return n.value},Vr=Pr(hs);function at(){return at=Object.assign?Object.assign.bind():function(e){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var a in t)({}).hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},at.apply(null,arguments)}function $t(e,s){try{var t=e()}catch(a){return s(a)}return t&&t.then?t.then(void 0,s):t}function kr(e,s){for(var t={};e.length;){var a=e[0],c=a.code,d=a.message,n=a.path.join(".");if(!t[n])if("unionErrors"in a){var u=a.unionErrors[0].errors[0];t[n]={message:u.message,type:u.code}}else t[n]={message:d,type:c};if("unionErrors"in a&&a.unionErrors.forEach(function(P){return P.errors.forEach(function(H){return e.push(H)})}),s){var j=t[n].types,E=j&&j[a.code];t[n]=ut(n,s,t,c,E?[].concat(E,a.message):a.message)}e.shift()}return t}function Dr(e,s){for(var t={},a=function(){var c=e[0],d=c.code,n=c.message,u=c.path.join(".");if(!t[u])if(c.code==="invalid_union"&&c.errors.length>0){var j=c.errors[0][0];t[u]={message:j.message,type:j.code}}else t[u]={message:n,type:d};if(c.code==="invalid_union"&&c.errors.forEach(function(H){return H.forEach(function(I){return e.push(at({},I,{path:[].concat(c.path,I.path)}))})}),s){var E=t[u].types,P=E&&E[c.code];t[u]=ut(u,s,t,d,P?[].concat(P,c.message):c.message)}e.shift()};e.length;)a();return t}function Fr(e,s,t){if(t===void 0&&(t={}),(function(a){return"_def"in a&&typeof a._def=="object"&&"typeName"in a._def})(e))return function(a,c,d){try{return Promise.resolve($t(function(){return Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](a,s)).then(function(n){return d.shouldUseNativeValidation&&it({},d),{errors:{},values:t.raw?Object.assign({},a):n}})},function(n){if((function(u){return Array.isArray(u?.issues)})(n))return{values:{},errors:Bt(kr(n.errors,!d.shouldUseNativeValidation&&d.criteriaMode==="all"),d)};throw n}))}catch(n){return Promise.reject(n)}};if((function(a){return"_zod"in a&&typeof a._zod=="object"})(e))return function(a,c,d){try{return Promise.resolve($t(function(){return Promise.resolve((t.mode==="sync"?Er:Vr)(e,a,s)).then(function(n){return d.shouldUseNativeValidation&&it({},d),{errors:{},values:t.raw?Object.assign({},a):n}})},function(n){if((function(u){return u instanceof Ar})(n))return{values:{},errors:Bt(Dr(n.issues,!d.shouldUseNativeValidation&&d.criteriaMode==="all"),d)};throw n}))}catch(n){return Promise.reject(n)}};throw new Error("Invalid input: not a Zod schema")}const Cr=e=>e.authType==="oauthMicrosoft",Or="••••••••••",Ir=e=>{const s=e.smtpUsername?.trim();return s?s!==e.username:!1},Rr=Es({email:be().email().min(1,"Email is required"),displayName:be().optional(),username:be().optional(),password:be().optional(),imapHost:be().min(1,"IMAP host is required"),imapPort:Nt.number().int().min(1).max(65535),imapTls:ke(),imapStartTls:ke(),smtpHost:be().optional(),smtpPort:Nt.number().int().min(1).max(65535).optional(),smtpTls:ke().optional(),smtpStartTls:ke().optional(),smtpUsername:be().optional(),smtpPassword:be().optional(),useDifferentSmtpCreds:ke().optional()}),Mr=({isOpen:e,onClose:s,account:t,focusSmtp:a})=>{const c=Gt(),d=!!t,[n,u]=O.useState(!1),[j,E]=O.useState(""),[P,H]=O.useState(!1),I=Et(j),C=!!I&&!P,N=O.useRef(null),f=jr({resolver:Fr(Rr),defaultValues:{email:"",displayName:"",username:"",password:"",imapHost:"",imapPort:993,imapTls:!0,imapStartTls:!1,smtpHost:"",smtpPort:587,smtpTls:!1,smtpStartTls:!0,useDifferentSmtpCreds:!1}});O.useEffect(()=>{if(t){const p=Ir(t);f.reset({email:t.email,displayName:t.displayName||"",username:t.username||"",password:Or,imapHost:t.imapHost,imapPort:t.imapPort,imapTls:t.imapTls,imapStartTls:t.imapStartTls,smtpHost:t.smtpHost||"",smtpPort:t.smtpPort||587,smtpTls:t.smtpTls||!1,smtpStartTls:t.smtpStartTls||!0,smtpUsername:p&&t.smtpUsername||"",smtpPassword:"",useDifferentSmtpCreds:p}),u(!1)}else f.reset({email:"",displayName:"",username:"",password:"",imapHost:"",imapPort:993,imapTls:!0,imapStartTls:!1,smtpHost:"",smtpPort:587,smtpTls:!1,smtpStartTls:!0,useDifferentSmtpCreds:!1}),u(!1)},[t,f]);const b=Ne({...Ns()}),ie=Ne({...Ts(),onSuccess:()=>{c.invalidateQueries({queryKey:Fe()}),s()}}),T=Ne({...As(),onSuccess:()=>{c.invalidateQueries({queryKey:Fe()}),s()}}),J=()=>{const p=f.getValues(),k=d&&!n;b.mutate({body:{accountId:k?t?.accountId:void 0,username:p.username||p.email,password:k?void 0:p.password||void 0,imapHost:p.imapHost,imapPort:Number(p.imapPort),imapTls:p.imapTls,imapStartTls:p.imapStartTls}})},R=()=>{const p=f.getValues(),k=d&&!n;b.mutate({body:{accountId:k?t?.accountId:void 0,username:p.username||p.email,password:k?void 0:p.password||void 0,imapHost:p.imapHost,imapPort:Number(p.imapPort),imapTls:p.imapTls,imapStartTls:p.imapStartTls,smtpHost:p.smtpHost||void 0,smtpPort:p.smtpPort?Number(p.smtpPort):void 0,smtpTls:p.smtpTls,smtpStartTls:p.smtpStartTls,smtpUsername:p.useDifferentSmtpCreds?p.smtpUsername:void 0,smtpPassword:p.useDifferentSmtpCreds?p.smtpPassword:void 0}})},V=f.handleSubmit(p=>{if(!d&&!p.password){f.setError("password",{message:"Password is required"});return}const k=Ks({imapHost:p.imapHost,smtpHost:p.smtpHost,smtpPort:p.smtpPort,smtpTls:p.smtpTls,smtpStartTls:p.smtpStartTls});k&&(f.setValue("smtpHost",k.smtpHost),f.setValue("smtpPort",k.smtpPort),f.setValue("smtpTls",k.smtpTls),f.setValue("smtpStartTls",k.smtpStartTls));const ce=k?.smtpHost??p.smtpHost,te=k?.smtpPort??p.smtpPort,ae=k?.smtpTls??p.smtpTls,Se=k?.smtpStartTls??p.smtpStartTls,Ee={email:p.email,displayName:p.displayName?.trim()||void 0,username:p.username||void 0,imapHost:p.imapHost,imapPort:Number(p.imapPort),imapTls:p.imapTls,imapStartTls:p.imapStartTls,smtpHost:ce||void 0,smtpPort:te?Number(te):void 0,smtpTls:ae,smtpStartTls:Se,smtpUsername:p.useDifferentSmtpCreds&&p.smtpUsername||void 0,smtpPassword:p.useDifferentSmtpCreds&&p.smtpPassword||void 0};if(d&&t){const Te={...Ee,password:n?p.password:void 0};T.mutate({path:{accountId:t.accountId},body:Te})}else{const Te={...Ee,password:p.password};ie.mutate({body:Te})}}),oe=ie.isPending||T.isPending,{signature:re,setSignature:pe,isSaving:le}=Hs(t?.accountId),[W,ee]=O.useState(re.plainText);O.useEffect(()=>{ee(re.plainText)},[re.plainText]),O.useEffect(()=>{if(!e||!a)return;const p=N.current;if(!p)return;const k=window.setTimeout(()=>{p.scrollIntoView({behavior:"smooth",block:"start"})},250);return()=>window.clearTimeout(k)},[e,a]);const A=O.useCallback(()=>{W!==re.plainText&&pe(W,W)},[W,re.plainText,pe]),_=p=>{const{tls:k,startTls:ce}=Ue(p);f.setValue("imapTls",k),f.setValue("imapStartTls",ce);const te=f.getValues("imapPort");(te===993||te===143)&&f.setValue("imapPort",p==="tls"?993:143)},D=p=>{const{tls:k,startTls:ce}=Ue(p);f.setValue("smtpTls",k),f.setValue("smtpStartTls",ce);const te=f.getValues("smtpPort");if(te===465||te===587||te===25){const Se=p==="tls"?465:p==="starttls"?587:25;f.setValue("smtpPort",Se)}},$=()=>{const p=f.getValues("imapHost");f.setValue("smtpHost",Gs(p)),f.setValue("smtpTls",!1),f.setValue("smtpStartTls",!0),f.setValue("smtpPort",587)},w=p=>{E(p),H(!1);const k=Et(p);if(!k)return;const ce=Ue(k.imap.security);f.setValue("imapHost",k.imap.host),f.setValue("imapPort",k.imap.port),f.setValue("imapTls",ce.tls),f.setValue("imapStartTls",ce.startTls);const te=Ue(k.smtp.security);f.setValue("smtpHost",k.smtp.host),f.setValue("smtpPort",k.smtp.port),f.setValue("smtpTls",te.tls),f.setValue("smtpStartTls",te.startTls);const ae=f.getValues("email").trim(),Se=f.getValues("username")?.trim();ae&&!Se&&f.setValue("username",ae)},L=I?.passwordHelp.text,ye=Pt(b.data?.imapError,L),Z=Pt(b.data?.smtpError,L);return(t?Cr(t):!1)&&d?i.jsx(Vt,{isOpen:e,onClose:s,title:"Edit Account",footer:i.jsx(se,{type:"button",variant:"secondary",onClick:s,children:"Close"}),children:i.jsxs("div",{className:"space-y-6",children:[i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Microsoft 365 Account"}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"rounded-md border border-line bg-surface-sunken px-3 py-2.5 text-sm text-fg-muted",children:[i.jsx("span",{className:"block text-2xs font-medium uppercase tracking-wider text-fg-subtle mb-1",children:"Email"}),i.jsx("span",{className:"text-fg",children:t?.email})]}),i.jsxs("div",{className:"rounded-md border border-line bg-surface-sunken px-3 py-2.5 text-sm text-fg-muted",children:[i.jsx("span",{className:"block text-2xs font-medium uppercase tracking-wider text-fg-subtle mb-1",children:"Authentication"}),i.jsx("span",{className:"text-fg",children:"Microsoft OAuth (XOAUTH2)"})]}),i.jsx("p",{className:"text-xs text-fg-muted",children:"Server settings are managed automatically for Microsoft 365 accounts. To update credentials, use the Reconnect button."})]})]}),d&&i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Signature"}),i.jsx("div",{className:"space-y-3",children:i.jsxs("div",{children:[i.jsx("label",{htmlFor:"email-sig-view",className:"text-sm font-medium mb-1.5 block",children:"Email Signature"}),i.jsx("textarea",{id:"email-sig-view",value:W,onChange:p=>ee(p.target.value),onBlur:A,rows:5,className:"w-full px-3 py-2 border border-line rounded-md bg-surface-sunken text-sm text-fg placeholder:text-fg-subtle focus-within:border-line-strong focus-within:ring-2 focus-within:ring-ring/30 transition-colors resize-y outline-none",placeholder:"Enter your email signature..."}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:le?"Saving signature...":"This signature will be appended to new emails."})]})})]})]})}):i.jsx(Vt,{isOpen:e,onClose:s,title:d?"Edit Account":"Add Account",footer:i.jsxs(i.Fragment,{children:[i.jsx(se,{type:"button",variant:"secondary",onClick:s,children:"Cancel"}),i.jsx(se,{type:"submit",form:"account-form",variant:"primary",disabled:oe,children:oe?"Saving...":"Save Account"})]}),children:i.jsxs("form",{id:"account-form",onSubmit:V,className:"space-y-6",children:[i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Account Information"}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-provider",className:"text-sm font-medium mb-1.5 block",children:"Provider"}),i.jsxs(_s,{id:"account-provider",value:j,onChange:p=>w(p.target.value),children:[i.jsx("option",{value:"",children:"Custom / other"}),$s.map(p=>i.jsx("option",{value:p.id,children:p.label},p.id))]}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:"Pick your email provider to fill in server settings automatically, or choose Custom to enter them by hand."})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-email",className:"text-sm font-medium mb-1.5 block",children:"Email Address"}),i.jsx(de,{id:"account-email",...f.register("email"),placeholder:"alice@example.com"}),f.formState.errors.email&&i.jsx("p",{className:"text-sm text-danger mt-1",children:f.formState.errors.email.message})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-displayName",className:"text-sm font-medium mb-1.5 block",children:"Display name (optional)"}),i.jsx(de,{id:"account-displayName",...f.register("displayName"),placeholder:"Alice"}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:"What to call this account in Remit. Leave blank to use a name derived from the address."})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-username",className:"text-sm font-medium mb-1.5 block",children:"Username"}),i.jsx(de,{id:"account-username",...f.register("username"),placeholder:"Same as email if empty"})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-password",className:"text-sm font-medium mb-1.5 block",children:"Password"}),i.jsx(de,{id:"account-password",...f.register("password",{onChange:()=>u(!0)}),type:"password",onFocus:()=>{d&&!n&&(f.setValue("password",""),u(!0))},placeholder:d?"Leave empty to keep current":""}),f.formState.errors.password&&i.jsx("p",{className:"text-sm text-danger mt-1",children:f.formState.errors.password.message}),I&&i.jsxs("p",{className:"text-xs text-fg-muted mt-1",children:[I.passwordHelp.text," ",i.jsx("a",{href:I.passwordHelp.url,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:"Get an app password"})]})]})]})]}),i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider",children:"Incoming Mail (IMAP)"}),I&&i.jsx("button",{type:"button",onClick:()=>H(p=>!p),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:P?"Use preset settings":"Advanced"})]}),C&&i.jsxs("p",{className:"text-xs text-fg-muted mb-3",children:["Server settings are pre-filled for ",I?.label," and locked. Choose Advanced to edit them by hand."]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"imap-host",className:"text-sm font-medium mb-1.5 block",children:"Server"}),i.jsx(de,{id:"imap-host",...f.register("imapHost"),readOnly:C,placeholder:"imap.example.com"}),f.formState.errors.imapHost&&i.jsx("p",{className:"text-sm text-danger mt-1",children:f.formState.errors.imapHost.message})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"imap-port",className:"text-sm font-medium mb-1.5 block",children:"Port"}),i.jsx(de,{id:"imap-port",...f.register("imapPort"),readOnly:C,type:"number"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-sm font-medium mb-1.5 block",children:"Security"}),i.jsxs("div",{className:"space-y-1.5 mt-2",children:[i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:f.watch("imapTls"),onChange:()=>_("tls")}),"TLS (Port 993)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("imapTls")&&f.watch("imapStartTls"),onChange:()=>_("starttls")}),"STARTTLS (Port 143)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("imapTls")&&!f.watch("imapStartTls"),onChange:()=>_("none")}),"None (Unencrypted)"]})]})]})]}),i.jsx(se,{type:"button",variant:"secondary",onClick:J,disabled:b.isPending,className:"w-full",icon:b.isPending?i.jsx(et,{className:"size-4 animate-spin"}):void 0,children:b.isPending?"Testing...":"Test IMAP Connection"}),b.data&&i.jsxs("div",{className:wt("p-2 rounded-md text-sm",b.data.imapSuccess?"bg-positive/10 text-positive":"bg-danger-soft text-danger"),children:[b.data.imapSuccess?i.jsx(St,{className:"inline size-4 mr-1"}):i.jsx(Oe,{className:"inline size-4 mr-1"}),b.data.imapSuccess?"IMAP Connected":ye]})]})]}),i.jsxs("section",{ref:N,"data-testid":"smtp-section",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider",children:"Outgoing Mail (SMTP)"}),!C&&i.jsx("button",{type:"button",onClick:$,disabled:!f.watch("imapHost"),className:"text-xs text-fg-muted hover:text-fg transition-colors disabled:opacity-50",children:"Pre-fill from IMAP"})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-host",className:"text-sm font-medium mb-1.5 block",children:"Server"}),i.jsx(de,{id:"smtp-host",...f.register("smtpHost"),readOnly:C,placeholder:"smtp.example.com"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-port",className:"text-sm font-medium mb-1.5 block",children:"Port"}),i.jsx(de,{id:"smtp-port",...f.register("smtpPort"),readOnly:C,type:"number"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-sm font-medium mb-1.5 block",children:"Security"}),i.jsxs("div",{className:"space-y-1.5 mt-2",children:[i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:f.watch("smtpTls")===!0,onChange:()=>D("tls")}),"TLS (Port 465)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("smtpTls")&&f.watch("smtpStartTls")===!0,onChange:()=>D("starttls")}),"STARTTLS (Port 587)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("smtpTls")&&!f.watch("smtpStartTls"),onChange:()=>D("none")}),"None (Unencrypted)"]})]})]})]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"checkbox",...f.register("useDifferentSmtpCreds")}),"Use different credentials for SMTP"]}),f.watch("useDifferentSmtpCreds")&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-username",className:"text-sm font-medium mb-1.5 block",children:"SMTP Username"}),i.jsx(de,{id:"smtp-username",...f.register("smtpUsername")})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-password",className:"text-sm font-medium mb-1.5 block",children:"SMTP Password"}),i.jsx(de,{id:"smtp-password",...f.register("smtpPassword"),type:"password"})]})]}),i.jsx(se,{type:"button",variant:"secondary",onClick:R,disabled:b.isPending||!f.watch("smtpHost"),className:"w-full",icon:b.isPending?i.jsx(et,{className:"size-4 animate-spin"}):void 0,children:b.isPending?"Testing...":"Test SMTP Connection"}),b.data?.smtpSuccess!==void 0&&i.jsxs("div",{className:wt("p-2 rounded-md text-sm",b.data.smtpSuccess?"bg-positive/10 text-positive":"bg-danger-soft text-danger"),children:[b.data.smtpSuccess?i.jsx(St,{className:"inline size-4 mr-1"}):i.jsx(Oe,{className:"inline size-4 mr-1"}),b.data.smtpSuccess?"SMTP Connected":Z]})]})]}),d&&i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Signature"}),i.jsx("div",{className:"space-y-3",children:i.jsxs("div",{children:[i.jsx("label",{htmlFor:"email-sig-edit",className:"text-sm font-medium mb-1.5 block",children:"Email Signature"}),i.jsx("textarea",{id:"email-sig-edit",value:W,onChange:p=>ee(p.target.value),onBlur:A,rows:5,className:"w-full px-3 py-2 border border-line rounded-md bg-surface-sunken text-sm text-fg placeholder:text-fg-subtle focus-within:border-line-strong focus-within:ring-2 focus-within:ring-ring/30 transition-colors resize-y outline-none",placeholder:"Enter your email signature..."}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:le?"Saving signature...":"This signature will be appended to new emails."})]})})]})]})})};function Wt({open:e,onClose:s,accountEmail:t,signOut:a}){const[c,d]=O.useState(""),[n,u]=O.useState(!1),[j,E]=O.useState(!1),P=Ne({...Vs(),onSuccess:()=>{E(!0),setTimeout(()=>a(),2e3)}}),H=Ne(ks()),I=()=>{P.isPending||(d(""),u(!1),E(!1),P.reset(),H.reset(),s())},C=()=>{if(c.trim().toLowerCase()!==t.toLowerCase()){u(!0);return}u(!1),P.mutate({body:{confirmEmail:c.trim()}})};return i.jsxs(Yt,{open:e,onClose:I,title:"Delete your Remit account",children:[i.jsxs("header",{className:"flex items-center gap-2 border-b border-line px-5 py-3",children:[i.jsx(nt,{className:"size-4 shrink-0 text-danger"}),i.jsx("span",{className:"flex-1 text-sm font-semibold text-fg",children:"Delete your Remit account"}),i.jsx(se,{variant:"ghost",size:"sm",icon:i.jsx(Oe,{className:"size-3.5"}),onClick:I,"aria-label":"Cancel"})]}),j?i.jsxs("div",{className:"px-5 py-6 text-sm text-fg-muted",children:[i.jsx("p",{className:"font-medium text-fg",children:"Account deletion scheduled."}),i.jsx("p",{className:"mt-1",children:"Your data will be erased shortly. Signing you out…"})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"space-y-4 px-5 py-4 text-sm text-fg-muted",children:[i.jsx("p",{children:"This permanently erases everything Remit holds for you:"}),i.jsxs("ul",{className:"space-y-1.5 text-xs",children:[i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"All connected accounts disconnected and access tokens revoked."]}),i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"Synced mail cache and search index."]}),i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"AI history and insights."]}),i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"Preferences and rules."]})]}),i.jsxs("div",{className:"rounded-sm border border-line bg-surface-sunken px-3 py-2 text-xs",children:[i.jsx("strong",{className:"text-fg",children:"Your mail at Gmail / IMAP is not deleted."})," ","This only removes Remit's copy and its access — the mail stays in your provider mailboxes."]}),i.jsxs("div",{className:"text-xs",children:[i.jsxs("button",{type:"button",onClick:()=>H.mutate({}),"aria-busy":H.isPending,className:"inline-flex items-center gap-1.5 font-medium text-accent hover:underline",children:[i.jsx(Ys,{className:"size-3.5"}),H.isPending?"Requesting export…":"Export my data first"]}),H.isSuccess&&i.jsx("p",{className:"mt-1.5 text-fg-muted",role:"status",children:"Export requested. We'll prepare a ZIP of your mail — find it under your data exports when it's ready."}),H.isError&&i.jsx("p",{className:"mt-1.5 text-danger",role:"alert",children:"Couldn't start the export. Please try again."})]}),i.jsxs("div",{children:[i.jsxs("label",{htmlFor:"confirm-remit-email",className:"mb-1 block text-xs font-medium text-fg",children:["Type"," ",i.jsx("span",{className:"font-mono text-fg-muted",children:t})," ","to confirm"]}),i.jsx(de,{id:"confirm-remit-email",type:"email",placeholder:t,value:c,onChange:N=>{d(N.target.value),n&&u(!1),P.isError&&P.reset()},autoComplete:"off"}),n&&i.jsx("p",{className:"mt-1.5 text-xs text-danger",role:"alert",children:"That doesn't match your account email. Type it exactly to confirm."}),P.isError&&i.jsx("p",{className:"mt-1.5 text-xs text-danger",role:"alert",children:P.error instanceof Error?P.error.message:"Something went wrong. Please try again."})]})]}),i.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-line px-5 py-3",children:[i.jsx(se,{variant:"secondary",size:"sm",onClick:I,children:"Cancel"}),i.jsx(se,{variant:"danger",size:"sm",onClick:C,"aria-busy":P.isPending,children:P.isPending?"Deleting…":"Delete everything"})]})]})]})}function Ur(e){const{Account:s}=Ps();return i.jsx(s,{fallback:i.jsx(Wt,{...e,accountEmail:"",signOut:()=>{}}),children:({email:t,signOut:a})=>i.jsx(Wt,{...e,accountEmail:t??"",signOut:a})})}function Lr(){const[e,s]=O.useState(!1);return i.jsxs("section",{className:"mt-8 border-t border-line pt-6",children:[i.jsx(Xs,{title:"Delete your Remit account",description:"Disconnects every account and erases Remit's copy of your mail, insights and preferences. Your mail at the providers is untouched.",action:i.jsx(se,{variant:"danger",size:"sm",onClick:()=>s(!0),children:"Delete your Remit account"})}),i.jsx(Ur,{open:e,onClose:()=>s(!1)})]})}function Hr(e){const s=e.toLowerCase();return s==="access_denied"?"You cancelled the sign-in.":s==="consent_required"||s.includes("admin_consent")||s.includes("interaction_required")?"Your organisation's admin needs to approve Remit. Ask your IT admin to grant the required permissions.":s.includes("imap_disabled")||s.includes("imap disabled")?"IMAP is disabled for this account. Ask your admin to enable IMAP access in the Microsoft 365 admin centre.":`Sign-in failed: ${e}. Please try again.`}function zr(e){const s=e.split("@")[0]??"";return s?s.split(/[._-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "):e}function Br(e){const s=e.displayName?.trim();return s||zr(e.email)}function qr(e){if(!e.lastSyncAt)return"never synced";const s=Qs(e.lastSyncAt);return s?`synced ${s}`:"never synced"}function Kt(e){return e.muted?.value?"muted":e.lastError?"error":e.connectionState==="authenticated"?"healthy":"error"}function $r(e){return e.connectionState==="reauth_required"}const Wr=i.jsxs("div",{className:"space-y-3",children:[i.jsxs("p",{children:[i.jsx("strong",{className:"text-fg",children:"Sync health"})," shows the IMAP connection state and the last successful sync per account."]}),i.jsxs("p",{children:[i.jsx("strong",{className:"text-fg",children:"Error"})," means the last connection attempt failed — the raw server response is shown on the card. Reconnect re-runs the connection test from the add-account wizard."]}),i.jsxs("p",{children:[i.jsx("strong",{className:"text-fg",children:"Muted"})," accounts keep syncing but stay out of the daily brief and unified counts."]})]}),Kr=()=>i.jsx("div",{className:"space-y-3",role:"status","aria-busy":"true","aria-label":"Loading accounts",children:["skeleton-0","skeleton-1"].map(e=>i.jsx("div",{className:"rounded-sm border border-line bg-surface animate-pulse p-4",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"size-10 rounded-full bg-surface-sunken"}),i.jsxs("div",{className:"flex-1 space-y-2",children:[i.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/3"}),i.jsx("div",{className:"h-3 bg-surface-sunken rounded w-2/3"})]})]})},e))});function ni(){const e=Tt.useSearch(),s=Ds({from:Tt.fullPath}),[t,a]=O.useState(!0),[c,d]=O.useState(!1),[n,u]=O.useState(!1),[j,E]=O.useState(null),[P,H]=O.useState(!1),[I,C]=O.useState(null),[N,f]=O.useState(null),[b,ie]=O.useState(null),[T,J]=O.useState(null),R=Gt(),{data:V,isPending:oe,isError:re,error:pe,refetch:le}=Fs(Cs());O.useEffect(()=>{e.editAccountId&&(E(e.editAccountId),H(!!e.focusSmtp),s({search:{editAccountId:void 0,focusSmtp:void 0,connected:e.connected,oauthError:e.oauthError},replace:!0}))},[e.editAccountId,e.focusSmtp,s,e.connected,e.oauthError]),O.useEffect(()=>{e.connected&&(f("Account connected successfully."),E(e.connected),R.invalidateQueries({queryKey:Fe()}),s({search:{connected:void 0,oauthError:void 0,editAccountId:void 0,focusSmtp:void 0},replace:!0}))},[e.connected,s,R]),O.useEffect(()=>{e.oauthError&&(ie(Hr(e.oauthError)),s({search:{oauthError:void 0,connected:void 0,editAccountId:void 0,focusSmtp:void 0},replace:!0}))},[e.oauthError,s]);const W=Ne({...Os(),onSuccess:w=>{window.location.assign(w.authorizationUrl)},onError:w=>{ie(w instanceof Error?w.message:"Failed to start reconnect"),J(null)}}),ee=Ne({...Is(),onSuccess:()=>{R.invalidateQueries({queryKey:Fe()}),C(null)}}),A=V?.accounts.find(w=>w.accountId===I),_=V?.accounts.find(w=>w.accountId===j),D=()=>{d(!1),u(!1),E(null),H(!1)},$=w=>{const L=Us[w];L&&s({to:L})};return i.jsxs(Bs,{items:Rs,activeId:"accounts",title:"Accounts",description:"Every account keeps syncing — muted ones just stay out of unified views.",help:Wr,helpOpen:t,onToggleHelp:()=>a(w=>!w),onSelect:$,onBackToMail:()=>{s({to:"/mail"})},children:[N&&i.jsx(At,{tone:"success",variant:"soft","data-testid":"oauth-success-banner",onDismiss:()=>f(null),children:N}),b&&i.jsx(At,{tone:"danger",variant:"soft","data-testid":"oauth-error-banner",onDismiss:()=>ie(null),children:b}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(Ms,{tone:"neutral",children:oe||re?"accounts":`${V.accounts.length} ${V.accounts.length===1?"account":"accounts"}`}),i.jsx(se,{variant:"primary",size:"sm",icon:i.jsx(_t,{className:"size-3.5"}),onClick:()=>u(!0),children:"Add account"})]}),oe?i.jsx(Kr,{}):re?i.jsx(Zs,{title:"Couldn't load accounts",error:pe,onRetry:()=>{le()}}):V.accounts.length===0?i.jsxs("div",{className:"py-12 text-sm text-fg-muted","data-testid":"accounts-empty",children:[i.jsx("p",{className:"mb-3",children:"No accounts configured."}),i.jsx(se,{variant:"primary",size:"sm",icon:i.jsx(_t,{className:"size-3.5"}),onClick:()=>u(!0),children:"Add your first account"})]}):i.jsx("div",{className:"space-y-3",children:V.accounts.map(w=>{const L=$r(w),ye=w.authType==="oauthMicrosoft",Z=T===w.accountId&&W.isPending,ve=L&&ye?{label:"Reconnect",variant:"secondary",busy:Z,busyLabel:"Redirecting…",onClick:()=>{J(w.accountId),W.mutate({body:{email:w.email}})}}:Kt(w)==="error"?{label:"Reconnect",variant:"secondary",onClick:()=>E(w.accountId)}:{label:"Manage",variant:"ghost",onClick:()=>E(w.accountId)},p=i.jsx(zs,{actions:[ve],destructive:{label:"Delete account",iconOnly:!0,icon:i.jsx(Ls,{className:"size-3.5"}),onClick:()=>C(w.accountId)}});return i.jsx(qs,{label:Br(w),email:w.email,connector:ye?"Microsoft 365":"IMAP",syncLabel:qr(w),state:Kt(w),errorDetail:L?"Re-authentication required":w.lastError,trailing:p},w.accountId)})}),n&&i.jsx("div",{className:"fixed inset-0 z-40 overflow-auto bg-canvas",children:i.jsx(Ws,{skipWelcome:!0,onComplete:()=>{u(!1),R.invalidateQueries({queryKey:Fe()})},onCancel:()=>u(!1)})}),i.jsx(Mr,{isOpen:c||!!j,account:_,focusSmtp:P,onClose:D}),i.jsxs(Yt,{open:!!I,onClose:()=>C(null),title:"Delete account",children:[i.jsxs("header",{className:"flex items-center gap-2 border-b border-line px-5 py-3",children:[i.jsx(nt,{className:"size-4 shrink-0 text-danger"}),i.jsx("span",{className:"flex-1 text-sm font-semibold text-fg",children:"Delete account"}),i.jsx(se,{variant:"ghost",size:"sm",icon:i.jsx(Oe,{className:"size-3.5"}),onClick:()=>C(null),"aria-label":"Cancel"})]}),i.jsxs("div",{className:"space-y-3 px-5 py-4 text-sm text-fg-muted",children:[i.jsx("p",{className:"text-center text-lg font-medium text-fg",children:"Are you sure?"}),A&&i.jsx("p",{className:"text-center",children:A.email}),i.jsxs("ul",{className:"list-inside list-disc space-y-1",children:[i.jsx("li",{children:"Remove the account from your settings"}),i.jsx("li",{children:"Stop syncing mail for this account"}),i.jsx("li",{children:"Delete all associated data (within 24 hours)"})]})]}),i.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-line px-5 py-3",children:[i.jsx(se,{variant:"secondary",size:"sm",onClick:()=>C(null),children:"Cancel"}),i.jsx(se,{variant:"danger",size:"sm","aria-busy":ee.isPending,icon:ee.isPending?i.jsx(et,{className:"size-3.5 animate-spin"}):void 0,onClick:()=>{ee.isPending||I&&ee.mutate({path:{accountId:I}})},children:ee.isPending?"Deleting…":"Delete account"})]})]}),i.jsx(Lr,{})]})}export{ni as component,Hr as mapOauthError};
|
|
1
|
+
import{j as i,z as nt,r as O,b as jt,X as Oe,R as X,$ as Gt,at as Ne,bq as Ns,bo as Fe,br as Ts,bs as As,B as se,bt as _s,y as de,i as et,h as St,ah as wt,bu as Es,bv as ke,bw as be,bx as Nt,ai as Ps,by as Vs,bz as ks,D as Yt,bA as Tt,ae as Ds,aq as Fs,ay as Cs,bB as Os,bC as Is,bD as Rs,k as At,d as Ms,bE as _t,bF as Us,T as Ls}from"./index-DccQqmHT.js";import{u as Hs,R as zs}from"./useSignature-BuMCTh1I.js";import{S as Bs,A as qs}from"./settings-screen-CGcJfaFe.js";import{g as Et,P as $s,s as Ue,O as Ws}from"./OnboardingWizard-DlBawZQa.js";import{c as Ks,b as Pt,d as Gs}from"./account-form-helpers-C-R-t-TP.js";import{D as Ys}from"./download-C1F8f8Cm.js";import{E as Zs}from"./ErrorState-xuU2Ycex.js";import{e as Qs}from"./format-B6Elex-n.js";import"./avatar-DO7vnPxY.js";import"./kbd-CJm0PdtR.js";function Xs({title:e,description:s,action:t}){return i.jsxs("div",{className:"rounded-sm border border-danger/50",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-danger/30 bg-danger-soft px-row-inset py-2",children:[i.jsx(nt,{className:"size-4 text-danger"}),i.jsx("h2",{className:"text-sm font-semibold text-danger",children:"Danger zone"})]}),i.jsxs("div",{className:"flex flex-col gap-3 px-row-inset py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"text-sm font-medium text-fg",children:e}),i.jsx("p",{className:"text-xs text-fg-muted",children:s})]}),i.jsx("div",{className:"shrink-0",children:t})]})]})}function Vt({isOpen:e,onClose:s,title:t,children:a,footer:c}){return O.useEffect(()=>{if(!e)return;const d=n=>{n.key==="Escape"&&s()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[e,s]),i.jsxs(i.Fragment,{children:[i.jsx("div",{className:jt("fixed inset-0 z-40 bg-black/30 transition-opacity",e?"opacity-100":"pointer-events-none opacity-0"),onClick:s,"aria-hidden":"true"}),i.jsxs("div",{className:jt("fixed top-0 right-0 z-50 h-full w-full border-l border-line bg-canvas shadow-xl sm:w-[400px] sm:max-w-[90vw]","transform transition-transform duration-200 ease-out",e?"translate-x-0":"pointer-events-none translate-x-full"),role:"dialog","aria-modal":"true","aria-hidden":!e,inert:!e,"aria-labelledby":"slide-panel-title",children:[i.jsxs("div",{className:"flex h-14 items-center justify-between border-b border-line px-4",children:[i.jsx("h2",{id:"slide-panel-title",className:"font-semibold",children:t}),i.jsx("button",{type:"button",onClick:s,className:"rounded-md p-1.5 transition-colors hover:bg-surface-raised","aria-label":"Close",children:i.jsx(Oe,{className:"size-5"})})]}),i.jsxs("div",{className:"flex h-[calc(100%-3.5rem)] flex-col",children:[i.jsx("div",{className:"flex-1 overflow-auto p-4",children:a}),c&&i.jsx("div",{className:"flex justify-end gap-3 border-t border-line bg-canvas p-4",children:c})]})]})]})}var Ie=e=>e.type==="checkbox",je=e=>e instanceof Date,G=e=>e==null;const ot=e=>typeof e=="object";var z=e=>!G(e)&&!Array.isArray(e)&&ot(e)&&!je(e),Js=e=>z(e)&&e.target?Ie(e.target)?e.target.checked:e.target.value:e,er=(e,s)=>s.split(".").some((t,a,c)=>!isNaN(Number(t))&&e.has(c.slice(0,a).join("."))),Zt=e=>{const s=e.constructor&&e.constructor.prototype;return z(s)&&s.hasOwnProperty("isPrototypeOf")},$e=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function B(e){if(e instanceof Date)return new Date(e);const s=typeof FileList<"u"&&e instanceof FileList;if($e&&(e instanceof Blob||s))return e;const t=Array.isArray(e);if(!t&&!(z(e)&&Zt(e)))return e;const a=t?[]:Object.create(Object.getPrototypeOf(e));for(const c in e)Object.prototype.hasOwnProperty.call(e,c)&&(a[c]=B(e[c]));return a}const Ae={BLUR:"blur",FOCUS_OUT:"focusout",SUBMIT:"submit",TRIGGER:"trigger",VALID:"valid"},fe={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},ue={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Qt="root",lt=["__proto__","constructor","prototype"],tr=/^\w*$/;var Re=e=>tr.test(e),M=e=>e===void 0;const sr=/[.[\]'"]/;var We=e=>e.split(sr).filter(Boolean),g=(e,s,t)=>{if(!s||!z(e))return t;const a=Re(s)?[s]:We(s);if(a.some(d=>lt.includes(d)))return t;const c=a.reduce((d,n)=>G(d)?void 0:d[n],e);return M(c)||c===e?M(e[s])?t:e[s]:c},me=e=>typeof e=="boolean",ne=e=>typeof e=="function",F=(e,s,t)=>{let a=-1;const c=Re(s)?[s]:We(s),d=c.length,n=d-1;for(;++a<d;){const u=c[a];let j=t;if(a!==n){const E=e[u];j=z(E)||Array.isArray(E)?E:isNaN(+c[a+1])?{}:[]}if(lt.includes(u))return;e[u]=j,e=e[u]}};const rr=X.createContext(null);rr.displayName="HookFormControlContext";var ir=(e,s,t,a=!0)=>{const c={};for(const d in e)Object.defineProperty(c,d,{get:()=>{const n=d;return s._proxyFormState[n]!==fe.all&&(s._proxyFormState[n]=!a||fe.all),e[n]}});return c};const ar=$e?X.useLayoutEffect:X.useEffect;var Y=e=>typeof e=="string",nr=(e,s,t,a,c)=>Y(e)?(a&&s.watch.add(e),g(t,e,c)):Array.isArray(e)?e.map(d=>(a&&s.watch.add(d),g(t,d))):(a&&(s.watchAll=!0),t),tt=e=>G(e)||!ot(e);const kt=(e,s)=>s.length===0&&!Array.isArray(e)&&!Zt(e);function he(e,s,t=new WeakMap){if(e===s)return!0;if(tt(e)||tt(s))return Object.is(e,s);if(je(e)&&je(s))return Object.is(e.getTime(),s.getTime());const a=Object.keys(e),c=Object.keys(s);if(a.length!==c.length)return!1;if(kt(e,a)||kt(s,c))return Object.is(e,s);if(!a.length&&Array.isArray(e)!==Array.isArray(s))return!1;const d=t.get(e);if(d&&d.has(s))return!0;if(d)d.add(s);else{const n=new WeakSet;n.add(s),t.set(e,n)}for(const n of a){const u=e[n];if(!(n in s))return!1;if(n!=="ref"){const j=s[n];if(je(u)&&je(j)||(z(u)||Array.isArray(u))&&(z(j)||Array.isArray(j))?!he(u,j,t):!Object.is(u,j))return!1}}return!0}var Le=e=>({isOnSubmit:!e||e===fe.onSubmit,isOnBlur:e===fe.onBlur,isOnChange:e===fe.onChange,isOnAll:e===fe.all,isOnTouch:e===fe.onTouched}),Qe=(e,s,t)=>{if(t)return!1;if(s.watchAll||s.watch.has(e))return!0;for(const a of s.watch)if(e.startsWith(a)&&e.charAt(a.length)===".")return!0;return!1};const Ce=(e,s,t,a)=>{for(const c of t||Object.keys(e)){const d=g(e,c);if(d){const{_f:n,...u}=d;if(n){if(n.refs&&n.refs[0]&&s(n.refs[0],c)&&!a)return!0;if(n.ref&&s(n.ref,n.name)&&!a)return!0;if(Ce(u,s))break}else if(z(u)&&Ce(u,s))break}}};var Dt=(e,s,t)=>{const a=g(e,t),c=Array.isArray(a)?a:[];return F(c,Qt,s[t]),F(e,t,c),e},K=e=>z(e)&&!Object.keys(e).length,ct=e=>e.type==="file",Be=e=>{if(!$e)return!1;const s=e?e.ownerDocument:0;return e instanceof(s&&s.defaultView?s.defaultView.HTMLElement:HTMLElement)},dt=e=>e.type==="radio",qe=e=>e instanceof RegExp,ut=(e,s,t,a,c)=>s?{...t[e],types:{...t[e]&&t[e].types?t[e].types:{},[a]:c||!0}}:{};const Ft={value:!1,isValid:!1},Ct={value:!0,isValid:!0};var Xt=e=>{if(Array.isArray(e)){if(e.length>1){const s=e.filter(t=>t&&t.checked&&!t.disabled).map(t=>t.value);return{value:s,isValid:!!s.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!M(e[0].attributes.value)?M(e[0].value)||e[0].value===""?Ct:{value:e[0].value,isValid:!0}:Ct:Ft}return Ft};const Ot={isValid:!1,value:null};var Jt=e=>Array.isArray(e)?e.reduce((s,t)=>t&&t.checked&&!t.disabled?{isValid:!0,value:t.value}:s,Ot):Ot;function It(e,s,t="validate"){if(Y(e)||Array.isArray(e)&&e.every(Y)||me(e)&&!e)return{type:t,message:Y(e)?e:"",ref:s}}var _e=e=>z(e)&&!qe(e)?e:{value:e,message:""},Rt=async(e,s,t,a,c,d)=>{const{ref:n,refs:u,required:j,maxLength:E,minLength:P,min:H,max:I,pattern:C,validate:N,name:f,valueAsNumber:b,mount:ie}=e._f,T=g(t,f);if(!ie||s.has(f))return{};const J=u?u[0]:n,R=A=>{if(c&&J.reportValidity){const _=me(A)?"":A||"";u?u.forEach(D=>D.setCustomValidity(_)):J.setCustomValidity(_),J.reportValidity()}},V={},oe=dt(n),re=Ie(n),pe=oe||re,le=(b||ct(n))&&M(n.value)&&M(T)||Be(n)&&n.value===""||T===""||Array.isArray(T)&&!T.length,W=ut.bind(null,f,a,V),ee=(A,_,D,$=ue.maxLength,w=ue.minLength)=>{const L=A?_:D;V[f]={type:A?$:w,message:L,ref:n,...W(A?$:w,L)}};if(d?!Array.isArray(T)||!T.length:j&&(!pe&&(le||G(T))||me(T)&&!T||re&&!Xt(u).isValid||oe&&!Jt(u).isValid)){const{value:A,message:_}=Y(j)?{value:!!j,message:j}:_e(j);if(A&&(V[f]={type:ue.required,message:_,ref:J,...W(ue.required,_)},!a))return R(_),V}if(!le&&(!G(H)||!G(I))){let A,_;const D=_e(I),$=_e(H);if(!G(T)&&!isNaN(T)){const w=n.valueAsNumber||T&&+T;G(D.value)||(A=w>D.value),G($.value)||(_=w<$.value)}else{const w=n.valueAsDate||new Date(T),L=ve=>new Date(new Date().toDateString()+" "+ve),ye=n.type=="time",Z=n.type=="week";Y(D.value)&&T&&(A=ye?L(T)>L(D.value):Z?T>D.value:w>new Date(D.value)),Y($.value)&&T&&(_=ye?L(T)<L($.value):Z?T<$.value:w<new Date($.value))}if((A||_)&&(ee(!!A,D.message,$.message,ue.max,ue.min),!a))return R(V[f].message),V}if((E||P)&&!le&&(Y(T)||d&&Array.isArray(T))){const A=_e(E),_=_e(P),D=!G(A.value)&&T.length>+A.value,$=!G(_.value)&&T.length<+_.value;if((D||$)&&(ee(D,A.message,_.message),!a))return R(V[f].message),V}if(C&&!le&&Y(T)){const{value:A,message:_}=_e(C);if(qe(A)&&!T.match(A)&&(V[f]={type:ue.pattern,message:_,ref:n,...W(ue.pattern,_)},!a))return R(_),V}if(N){if(ne(N)){const A=await N(T,t),_=It(A,J);if(_&&(V[f]={..._,...W(ue.validate,_.message)},!a))return R(_.message),V}else if(z(N)){let A={};for(const _ in N){if(!K(A)&&!a)break;const D=It(await N[_](T,t),J,_);D&&(A={...D,...W(_,D.message)},R(D.message),a&&(V[f]=A))}if(!K(A)&&(V[f]={ref:J,...A},!a))return V}}return R(!0),V},ze=e=>Array.isArray(e)?e:[e],es=e=>Array.isArray(e)?e.filter(Boolean):[];function or(e,s){const t=s.slice(0,-1).length;let a=0;for(;a<t;){if(G(e)){e=void 0;break}e=e[s[a]],a++}return e}function lr(e){for(const s in e)if(e.hasOwnProperty(s)&&!M(e[s]))return!1;return!0}function q(e,s){if(Y(s)&&Object.prototype.hasOwnProperty.call(e,s))return delete e[s],e;const t=Array.isArray(s)?s:Re(s)?[s]:We(s);if(t.some(n=>lt.includes(String(n))))return e;const a=t.length===1?e:or(e,t),c=t.length-1,d=t[c];return a&&delete a[d],c!==0&&(z(a)&&K(a)||Array.isArray(a)&&lr(a))&&q(e,t.slice(0,-1)),e}const ts=e=>{const s={};for(const t of Object.keys(e))if(ot(e[t])&&e[t]!==null&&!je(e[t])){const a=ts(e[t]);for(const c of Object.keys(a))s[`${t}.${c}`]=a[c]}else s[t]=e[t];return s},cr=X.createContext(null);cr.displayName="HookFormContext";var Mt=()=>{let e=[];return{get observers(){return e},next:c=>{for(const d of e)d.next&&d.next(c)},subscribe:c=>(e.push(c),{unsubscribe:()=>{e=e.filter(d=>d!==c)}}),unsubscribe:()=>{e=[]}}};function ss(e,s){const t={};for(const a in e)if(e.hasOwnProperty(a)){const c=e[a],d=s[a];if(c&&z(c)&&d){const n=ss(c,d);z(n)&&(t[a]=n)}else e[a]&&(t[a]=d)}return t}var rs=e=>e.type==="select-multiple",dr=e=>dt(e)||Ie(e),Xe=e=>Be(e)&&e.isConnected,ur=e=>{for(const s in e)if(ne(e[s]))return!0;return!1};function is(e){return Array.isArray(e)||z(e)&&!ur(e)}function as(e){return!!(e&&"_f"in e)}function ns(e){return Array.isArray(e)?!e.some(s=>!M(s)):!Object.keys(e).length}function st(e,s){Array.isArray(e)?e[s]=void 0:delete e[s]}function rt(e,s={},t){for(const a in e){const c=e[a],d=t&&t[a];is(c)&&(!Array.isArray(c)||!as(d))?(s[a]=Array.isArray(c)?[]:{},rt(c,s[a],d),ns(s[a])&&st(s,a)):M(c)||(s[a]=!0)}return s}function we(e,s,t,a){t||(t=rt(s,{},a));for(const c in e){const d=e[c],n=a&&a[c];is(d)&&(!Array.isArray(d)||!as(n))?(M(s)||tt(t[c])?t[c]=rt(d,Array.isArray(d)?[]:{},n):we(d,G(s)?{}:s[c],t[c],n),ns(t[c])&&st(t,c)):he(d,s[c])?st(t,c):t[c]=!0}return t}var os=(e,{valueAsNumber:s,valueAsDate:t,setValueAs:a})=>M(e)?e:s?e===""?NaN:e&&+e:t&&Y(e)?new Date(e):a?a(e):e;function Ut(e){const s=e.ref;return ct(s)?s.files:dt(s)?Jt(e.refs).value:rs(s)?[...s.selectedOptions].map(({value:t})=>t):Ie(s)?Xt(e.refs).value:os(M(s.value)?e.ref.value:s.value,e)}var fr=(e,s,t,a)=>{const c={};for(const d of e){const n=g(s,d);n&&F(c,d,n._f)}return{criteriaMode:t,names:[...e],fields:c,shouldUseNativeValidation:a}},De=e=>M(e)?e:qe(e)?e.source:z(e)?qe(e.value)?e.value.source:e.value:e;const Lt="AsyncFunction";var mr=e=>{if(!e||!e.validate)return!1;if(ne(e.validate))return e.validate.constructor.name===Lt;if(z(e.validate)){for(const s in e.validate)if(e.validate[s].constructor.name===Lt)return!0}return!1},hr=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Ht(e,s,t){const a=g(e,t);if(a||Re(t))return{error:a,name:t};const c=t.split(".");for(;c.length;){const d=c.join("."),n=g(s,d),u=g(e,d);if(n&&!Array.isArray(n)&&t!==d)return{name:t};if(u&&u.type)return{name:d,error:u};if(u&&u.root&&u.root.type)return{name:`${d}.root`,error:u.root};c.pop()}return{name:t}}var pr=(e,s,t,a)=>{t(e);const{name:c,...d}=e,n=Object.keys(d);return!n.length||a&&n.length>=Object.keys(s).length||n.find(u=>s[u]===(!a||fe.all))},yr=(e,s,t)=>!e||!s||e===s||ze(e).some(a=>a&&(t?a===s||a.startsWith(s+"."):a.startsWith(s)||s.startsWith(a))),xr=(e,s,t,a,c)=>c.isOnAll?!1:!t&&c.isOnTouch?!(s||e):(t?a.isOnBlur:c.isOnBlur)?!e:(t?a.isOnChange:c.isOnChange)?e:!0,gr=(e,s)=>!es(g(e,s)).length&&q(e,s);const vr={mode:fe.onSubmit,reValidateMode:fe.onChange,shouldFocusError:!0},Je="form",ls={submitCount:0,isDirty:!1,isReady:!1,isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{}};function br(e={}){let s={...vr,...e},t={...B(ls),isLoading:ne(s.defaultValues),errors:s.errors||{},disabled:s.disabled||!1},a={},c=z(s.defaultValues)||z(s.values)?B(s.defaultValues||s.values)||{}:{},d=s.shouldUnregister?{}:B(c),n={action:!1,mount:!1,watch:!1,keepIsValid:!1},u={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set,registerName:new Set};const j={},E={};let P=0,H=Le(s.mode),I=Le(s.reValidateMode);const C={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},N={...C};let f={...N};const b={array:Mt(),state:Mt()};let ie=0;const T=s.criteriaMode===fe.all,J=(r,o)=>l=>{clearTimeout(E[r]),E[r]=setTimeout(o,l)},R=async r=>{if(!n.keepIsValid&&!s.disabled&&(N.isValid||f.isValid||r)){const o=++ie;let l;s.resolver?(l=K((await D()).errors),o===ie&&V()):l=await L({fields:a,onlyCheckValid:!0,eventType:Ae.VALID}),o===ie&&l!==t.isValid&&b.state.next({isValid:l})}},V=(r,o)=>{!s.disabled&&(N.isValidating||N.validatingFields||f.isValidating||f.validatingFields)&&((r||Array.from(u.mount)).forEach(l=>{l&&(o?F(t.validatingFields,l,o):q(t.validatingFields,l))}),b.state.next({validatingFields:t.validatingFields,isValidating:!K(t.validatingFields)}))},oe=()=>{t.dirtyFields=we(c,d,void 0,a)},re=(r,o=[],l,m,h=!0,x=!0)=>{if(m&&l&&!s.disabled){if(n.action=!0,x&&Array.isArray(g(a,r))){const y=l(g(a,r),m.argA,m.argB);h&&F(a,r,y)}if(x&&Array.isArray(g(t.errors,r))){const y=l(g(t.errors,r),m.argA,m.argB);h&&F(t.errors,r,y),gr(t.errors,r)}if((N.touchedFields||f.touchedFields)&&x&&Array.isArray(g(t.touchedFields,r))){const y=l(g(t.touchedFields,r),m.argA,m.argB);h&&F(t.touchedFields,r,y)}(N.dirtyFields||f.dirtyFields)&&oe(),b.state.next({name:r,isDirty:Z(r,o),dirtyFields:t.dirtyFields,errors:t.errors,isValid:t.isValid})}else F(d,r,o)},pe=(r,o)=>{F(t.errors,r,o),t.errors={...t.errors},b.state.next({errors:t.errors})},le=r=>{t.errors=r,b.state.next({errors:t.errors,isValid:!1})},W=r=>{const o=Re(r)?[r]:We(r);let l=d,m=c;for(let h=0;h<o.length-1;h++){const x=o[h];if(l=G(l)?l:l[x],m=G(m)?m:m[x],l===null&&m!==null)return!0}return!1},ee=(r,o,l,m)=>{const h=g(a,r);if(h){if(W(r))return;const x=M(g(d,r)),y=g(d,r,M(l)?g(c,r):l);M(y)||m&&m.defaultChecked||o?F(d,r,o?y:Ut(h._f)):k(r,y),n.mount&&!n.action&&(R(),x&&t.isDirty&&(N.isDirty||f.isDirty)&&(Z()||(t.isDirty=!1,b.state.next({...t}))),e.shouldUnregister&&x&&!M(g(d,r))&&Qe(r,u)&&(n.watch=!0))}},A=(r,o,l,m,h)=>{let x=!1,y=!1;const v={name:r};if(!s.disabled||m===!0){if(!l||m){const S=he(g(c,r),o);(N.isDirty||f.isDirty)&&(y=t.isDirty,t.isDirty=v.isDirty=!S||Z(),x=y!==v.isDirty),y=!!g(t.dirtyFields,r),S!==t.isDirty?t.dirtyFields=we(c,d,void 0,a):S?q(t.dirtyFields,r):F(t.dirtyFields,r,!0),v.dirtyFields=t.dirtyFields,x=x||(N.dirtyFields||f.dirtyFields)&&y!==!S}if(l){const S=g(t.touchedFields,r);S||(F(t.touchedFields,r,l),v.touchedFields=t.touchedFields,x=x||(N.touchedFields||f.touchedFields)&&S!==l)}x&&h&&b.state.next(v)}return x?v:{}},_=(r,o,l,m)=>{const h=g(t.errors,r),x=(N.isValid||f.isValid)&&me(o)&&t.isValid!==o;if(s.delayError&&l?(j[r]=J(r,()=>pe(r,l)),j[r](s.delayError)):(clearTimeout(E[r]),delete j[r],l?F(t.errors,r,l):q(t.errors,r),t.errors={...t.errors}),(l?!he(h,l):h)||!K(m)||x){const y={...m,...x&&me(o)?{isValid:o}:{},errors:t.errors,name:r};t={...t,...y},b.state.next(y)}},D=async r=>(V(r,!0),await s.resolver(d,s.context,fr(r||u.mount,a,s.criteriaMode,s.shouldUseNativeValidation))),$=async r=>{const{errors:o}=await D(r);if(V(r),r){for(const l of r){const m=g(o,l);m?u.array.has(l)&&z(m)&&!Object.keys(m).some(h=>!Number.isNaN(Number(h)))?Dt(t.errors,{[l]:m},l):F(t.errors,l,m):q(t.errors,l)}t.errors={...t.errors}}else t.errors=o;return o},w=async({name:r,eventType:o})=>{if(e.validate){const l=await e.validate({formValues:d,formState:t,name:r,eventType:o});if(z(l))for(const m in l){const h=l[m];h&&Me(`${Je}.${m}`,{message:Y(h.message)?h.message:"",type:h.type||ue.validate})}else Y(l)||!l?Me(Je,{message:l||"",type:ue.validate}):mt(Je);return l}return!0},L=async({fields:r,onlyCheckValid:o,name:l,eventType:m,context:h={valid:!0,runRootValidation:!1}})=>{if(e.validate&&(h.runRootValidation=!0,!await w({name:l,eventType:m})&&(h.valid=!1,o)))return h.valid;for(const x in r){const y=r[x];if(y){const{_f:v,...S}=y;if(v){const U=u.array.has(v.name),Q=y._f&&mr(y._f),xe=N.validatingFields||N.isValidating||f.validatingFields||f.isValidating;Q&&xe&&V([v.name],!0);const ge=await Rt(y,u.disabled,d,T,s.shouldUseNativeValidation&&!o,U);if(Q&&xe&&V([v.name]),ge[v.name]&&(h.valid=!1,o)||(!o&&(g(ge,v.name)?U?Dt(t.errors,ge,v.name):F(t.errors,v.name,ge[v.name]):q(t.errors,v.name)),e.shouldUseNativeValidation&&ge[v.name]))break}!K(S)&&await L({context:h,onlyCheckValid:o,fields:S,name:x,eventType:m})}}return h.valid},ye=()=>{for(const r of u.unMount){const o=g(a,r);o&&(o._f.refs?o._f.refs.every(l=>!Xe(l)):!Xe(o._f.ref))&&Ge(r)}u.unMount=new Set},Z=(r,o)=>(r&&o&&F(d,r,o),!he(n.mount?d:c,c)),ve=(r,o,l)=>nr(r,u,{...n.mount?d:M(o)?c:Y(r)?{[r]:o}:o},l,o),p=r=>es(g(n.mount?d:c,r,s.shouldUnregister?g(c,r,[]):[])),k=(r,o,l={},m=!1,h=!1)=>{const x=g(a,r);let y=o;if(x){const v=x._f;v&&(!v.disabled&&F(d,r,os(o,v)),y=Be(v.ref)&&G(o)?"":o,rs(v.ref)?[...v.ref.options].forEach(S=>S.selected=y.includes(S.value)):v.refs?Ie(v.ref)?v.refs.forEach(S=>{(!S.defaultChecked||!S.disabled)&&(Array.isArray(y)?S.checked=!!y.find(U=>U===S.value):S.checked=y===S.value||!!y)}):v.refs.forEach(S=>S.checked=S.value===y):ct(v.ref)?v.ref.value="":(v.ref.value=y,!v.ref.type&&!h&&b.state.next({name:r,values:m?d:B(d)})))}(l.shouldDirty||l.shouldTouch)&&A(r,y,l.shouldTouch,l.shouldDirty,!h),l.shouldValidate&&Ke(r,{delayError:l.delayError})},ce=(r,o,l,m=!1,h=!1)=>{for(const x in o){if(!o.hasOwnProperty(x))return;const y=o[x],v=r+"."+x,S=g(a,v);(u.array.has(r)||z(y)||S&&!S._f)&&!je(y)?ce(v,y,l,m,h):k(v,y,l,m,h)}},te=(r,o,l,m,h=!1)=>{const x=g(a,r),y=u.array.has(r),v=m?o:B(o),S=g(d,r),U=he(S,v);if(U||F(d,r,v),y)b.array.next({name:r,values:m?d:B(d)}),(N.isDirty||N.dirtyFields||f.isDirty||f.dirtyFields)&&l.shouldDirty&&(oe(),h||b.state.next({name:r,dirtyFields:t.dirtyFields,isDirty:Z(r,v)}));else{const Q=Array.isArray(v)&&!v.length||K(v);!x||x._f||G(v)||Q?k(r,v,l,m,h):ce(r,v,l,m,h)}if(!U&&!h){const Q=Qe(r,u),xe=m?d:B(d);b.state.next({...Q&&t,name:n.mount||Q?r:void 0,values:xe})}},ae=(r,o,l={})=>te(r,o,l,!1),Se=(r,o={})=>{const l=ne(r)?r(d):r;if(!he(d,l)){d={...d,...l};const m=ts(l);for(const h of u.mount)h in m&&te(h,m[h],o,!0,!0);b.state.next({...t,name:void 0,type:void 0,...P?{values:d}:{}}),o.shouldValidate&&R()}},Ee=async r=>{n.mount=!0;const o=r.target;let l=o.name,m=!0;const h=g(a,l),x=y=>{m=Number.isNaN(y)||je(y)&&isNaN(y.getTime())||he(y,g(d,l,y))};if(h){let y,v;const S=o.type?Ut(h._f):Js(r),U=r.type===Ae.BLUR||r.type===Ae.FOCUS_OUT,Q=!hr(h._f)&&!e.validate&&!s.resolver&&!g(t.errors,l)&&!h._f.deps,xe=Q||xr(U,g(t.touchedFields,l),t.isSubmitted,I,H),ge=Qe(l,u,U);if(F(d,l,S),U){if(!o||!o.readOnly){h._f.onBlur&&h._f.onBlur(r);const Ve=j[l];Ve&&Ve(0)}}else h._f.onChange&&h._f.onChange(r);const Pe=A(l,S,U),Ss=!K(Pe)||ge;if(!U&&b.state.next({name:l,type:r.type,...P?{values:B(d)}:{}}),xe)return(!Q||!t.isValid)&&(N.isValid||f.isValid)&&(s.mode==="onBlur"?U&&R():U||R()),Ss&&b.state.next({name:l,...ge?{}:Pe});if(!s.resolver&&e.validate&&await w({name:l,eventType:r.type}),!U&&ge&&b.state.next({...t}),s.resolver){const{errors:Ve}=await D([l]);if(V([l]),x(S),!m){!K(Pe)&&b.state.next(Pe);return}const ws=Ht(t.errors,a,l),bt=Ht(Ve,a,ws.name||l);y=bt.error,l=bt.name,v=K(Ve)}else V([l],!0),y=(await Rt(h,u.disabled,d,T,s.shouldUseNativeValidation))[l],V([l]),x(S),m&&(y?v=!1:(N.isValid||f.isValid)&&(v=await L({fields:a,onlyCheckValid:!0,name:l,eventType:r.type})));m&&(h._f.deps&&(!Array.isArray(h._f.deps)||h._f.deps.length>0)&&Ke(h._f.deps),_(l,v,y,Pe))}},Te=(r,o)=>{if(g(t.errors,o)&&r.focus)return r.focus(),1},Ke=async(r,o={})=>{let l,m;const h=ze(r);if(s.resolver){const x=await $(M(r)?r:h);l=K(x),m=r?!h.some(y=>g(x,y)):l}else r?(m=(await Promise.all(h.map(async x=>{const y=g(a,x);return await L({fields:y&&y._f?{[x]:y}:y,eventType:Ae.TRIGGER})}))).every(Boolean),!(!m&&!t.isValid)&&R()):m=l=await L({fields:a,name:r,eventType:Ae.TRIGGER});if(o.delayError&&s.delayError&&Y(r)){const x=g(t.errors,r);x?(q(t.errors,r),j[r]=J(r,()=>pe(r,x)),j[r](s.delayError)):(clearTimeout(E[r]),delete j[r])}return b.state.next({...!Y(r)||(N.isValid||f.isValid)&&l!==t.isValid?{}:{name:r},...s.resolver||!r?{isValid:l}:{},errors:t.errors}),o.shouldFocus&&!m&&Ce(a,Te,r?h:u.mount),m},ps=(r,o)=>{let l={...n.mount?d:c};return o&&(l=ss(o.dirtyFields?t.dirtyFields:t.touchedFields,l)),M(r)?l:Y(r)?g(l,r):r.map(m=>g(l,m))},ft=(r,o)=>({invalid:!!g((o||t).errors,r),isDirty:!!g((o||t).dirtyFields,r),error:g((o||t).errors,r),isValidating:!!g(t.validatingFields,r),isTouched:!!g((o||t).touchedFields,r)}),mt=r=>{const o=r?ze(r):void 0;o?.forEach(l=>q(t.errors,l)),o?o.forEach(l=>{b.state.next({name:l,errors:t.errors})}):b.state.next({errors:{}})},Me=(r,o,l)=>{const m=(g(a,r,{_f:{}})._f||{}).ref,h=g(t.errors,r)||{},{ref:x,message:y,type:v,...S}=h;F(t.errors,r,{...S,...o,ref:m}),b.state.next({name:r,errors:t.errors,isValid:!1}),l&&l.shouldFocus&&m&&m.focus&&m.focus()},ys=(r,o)=>{if(ne(r)){P++;const{unsubscribe:l}=b.state.subscribe({next:h=>"values"in h&&r(h.values||ve(void 0,o),h)});let m=!1;return{unsubscribe:()=>{m||(m=!0,P--,l())}}}return ve(r,o,!0)},ht=r=>{var o;const l=!!(!((o=r.formState)===null||o===void 0)&&o.values);l&&P++;const{unsubscribe:m}=b.state.subscribe({next:x=>{if(yr(r.name,x.name,r.exact)&&pr(x,r.formState||N,js,r.reRenderRoot)){const y={...d};r.callback({values:y,...t,...x,defaultValues:c})}}});if(!l)return m;let h=!1;return()=>{h||(h=!0,P--,m())}},xs=r=>(n.mount=!0,f={...f,...r.formState},ht({...r,formState:{...C,...r.formState}})),Ge=(r,o={})=>{for(const l of r?ze(r):u.mount)u.mount.delete(l),u.array.delete(l),o.keepValue||(q(a,l),q(d,l)),!o.keepError&&q(t.errors,l),!o.keepDirty&&q(t.dirtyFields,l),!o.keepTouched&&q(t.touchedFields,l),!o.keepIsValidating&&q(t.validatingFields,l),!s.shouldUnregister&&!o.keepDefaultValue&&q(c,l);b.state.next({values:B(d)}),b.state.next({...t,...o.keepDirty?{isDirty:Z()}:{}}),!o.keepIsValid&&R()},pt=({disabled:r,name:o})=>{if(me(r)&&n.mount||r||u.disabled.has(o)){const h=u.disabled.has(o)!==!!r;r?u.disabled.add(o):u.disabled.delete(o),h&&n.mount&&!n.action&&R()}},Ye=(r,o={})=>{let l=g(a,r);const m=me(o.disabled)||me(s.disabled),h=!u.registerName.has(r)&&l&&l._f&&!l._f.mount;return F(a,r,{...l||{},_f:{...l&&l._f?l._f:{ref:{name:r}},name:r,mount:!0,...o}}),u.mount.add(r),l&&!h?pt({disabled:me(o.disabled)?o.disabled:s.disabled,name:r}):ee(r,!0,o.value),{...m?{disabled:o.disabled||s.disabled}:{},...s.progressive?{required:!!o.required,min:De(o.min),max:De(o.max),minLength:De(o.minLength),maxLength:De(o.maxLength),pattern:De(o.pattern)}:{},name:r,onChange:Ee,onBlur:Ee,ref:x=>{if(x){u.registerName.add(r),Ye(r,o),u.registerName.delete(r),l=g(a,r);const y=M(x.value)&&x.querySelectorAll&&x.querySelectorAll("input,select,textarea")[0]||x,v=dr(y),S=l._f.refs||[];if(v?S.find(U=>U===y):y===l._f.ref)return;F(a,r,{_f:{...l._f,...v?{refs:[...S.filter(Xe),y,...Array.isArray(g(c,r))?[{}]:[]],ref:{type:y.type,name:r}}:{ref:y}}}),ee(r,!1,void 0,y)}else l=g(a,r,{}),l._f&&(l._f.mount=!1),(s.shouldUnregister||o.shouldUnregister)&&!(er(u.array,r)&&n.action)&&u.unMount.add(r)}}},Ze=()=>s.shouldFocusError&&!s.shouldUseNativeValidation&&Ce(a,Te,u.mount),gs=r=>{me(r)&&(b.state.next({disabled:r}),Ce(a,(o,l)=>{const m=g(a,l);m&&(o.disabled=m._f.disabled||r,Array.isArray(m._f.refs)&&m._f.refs.forEach(h=>{h.disabled=m._f.disabled||r}))},0,!1))},yt=(r,o)=>async l=>{let m;l&&(l.preventDefault&&l.preventDefault(),l.persist&&l.persist());let h=B(d);if(b.state.next({isSubmitting:!0}),s.resolver){const{errors:x,values:y}=await D();V(),t.errors=x,h=B(y)}else await L({fields:a,eventType:Ae.SUBMIT});if(u.disabled.size)for(const x of u.disabled)q(h,x);if(q(t.errors,Qt),K(t.errors)){b.state.next({errors:{}});try{await r(h,l)}catch(x){m=x}}else o&&await o({...t.errors},l),Ze(),setTimeout(Ze);if(b.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:K(t.errors)&&!m,submitCount:t.submitCount+1,errors:t.errors}),m)throw m},vs=(r,o={})=>{g(a,r)&&(M(o.defaultValue)?ae(r,B(g(c,r))):(ae(r,o.defaultValue),F(c,r,B(o.defaultValue))),o.keepTouched||q(t.touchedFields,r),o.keepDirty||(q(t.dirtyFields,r),t.isDirty=o.defaultValue?Z(r,B(g(c,r))):Z()),o.keepError||(q(t.errors,r),N.isValid&&R()),b.state.next({...t}))},xt=(r,o={})=>{const l=r?B(r):c,m=B(l),h=K(r),x=m,y=a;if(o.keepDefaultValues||(c=l),!o.keepValues){if(o.keepDirtyValues){const v=new Set([...u.mount,...Object.keys(we(c,d,void 0,y))]);for(const S of Array.from(v)){const U=g(t.dirtyFields,S),Q=g(d,S),xe=g(x,S);U&&!M(Q)?F(x,S,Q):!U&&!M(xe)&&ae(S,xe)}}else{if($e&&M(r))for(const v of u.mount){const S=g(a,v);if(S&&S._f){const U=Array.isArray(S._f.refs)?S._f.refs[0]:S._f.ref;if(Be(U)){const Q=U.closest("form");if(Q){Q.reset();break}}}}if(o.keepFieldsRef)for(const v of u.mount)ae(v,g(x,v));else a={}}if(s.shouldUnregister){if(d=o.keepDefaultValues?B(c):{},o.keepFieldsRef)for(const v of u.mount)F(d,v,g(x,v))}else d=B(x);b.array.next({values:{...x}}),b.state.next({name:void 0,type:void 0,values:{...x}})}u={mount:o.keepDirtyValues?u.mount:new Set,unMount:new Set,array:new Set,registerName:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},n.mount=!N.isValid||!!o.keepIsValid||!!o.keepDirtyValues||!s.shouldUnregister&&!K(x),n.watch=!!s.shouldUnregister,n.keepIsValid=!!o.keepIsValid,n.action=!1,o.keepErrors||(t.errors={}),b.state.next({submitCount:o.keepSubmitCount?t.submitCount:0,isDirty:h?!1:o.keepDirty?t.isDirty:o.keepValues?Z():!!(o.keepDefaultValues&&!he(r,c)),isSubmitted:o.keepIsSubmitted?t.isSubmitted:!1,dirtyFields:h?{}:o.keepDirtyValues?o.keepDefaultValues&&d?we(c,d,void 0,y):t.dirtyFields:o.keepDefaultValues&&r?we(c,r,void 0,y):o.keepDirty?t.dirtyFields:{},touchedFields:o.keepTouched?t.touchedFields:{},errors:o.keepErrors?t.errors:{},isSubmitSuccessful:o.keepIsSubmitSuccessful?t.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:c})},gt=(r,o)=>xt(ne(r)?r(d):r,{...s.resetOptions,...o}),bs=(r,o={})=>{const l=g(a,r),m=l&&l._f;if(m){const h=m.refs?m.refs[0]:m.ref;h.focus&&setTimeout(()=>{h.focus(),o.shouldSelect&&ne(h.select)&&h.select()})}},js=r=>{const{name:o,type:l,values:m,...h}=r;t={...t,...h}},vt={control:{register:Ye,unregister:Ge,getFieldState:ft,handleSubmit:yt,setError:Me,_subscribe:ht,_runSchema:D,_updateIsValidating:V,_focusError:Ze,_getWatch:ve,_getDirty:Z,_setValid:R,_setFieldArray:re,_setDisabledField:pt,_setErrors:le,_getFieldArray:p,_reset:xt,_resetDefaultValues:()=>ne(s.defaultValues)&&s.defaultValues().then(r=>{gt(r,s.resetOptions),b.state.next({isLoading:!1})}),_removeUnmounted:ye,_disableForm:gs,_subjects:b,_proxyFormState:N,get _fields(){return a},get _formValues(){return d},get _state(){return n},set _state(r){n=r},get _defaultValues(){return c},get _names(){return u},set _names(r){u=r},get _formState(){return t},get _options(){return s},set _options(r){s={...s,...r},H=Le(s.mode),I=Le(s.reValidateMode)}},subscribe:xs,trigger:Ke,register:Ye,handleSubmit:yt,watch:ys,setValue:ae,setValues:Se,getValues:ps,reset:gt,resetField:vs,resetDefaultValues:(r,o={})=>{if(c=B(r),!o.keepDirty){const l=we(c,d,void 0,a);t.dirtyFields=l,t.isDirty=!K(l)}o.keepIsValid||R(),b.state.next({...t,defaultValues:c})},clearErrors:mt,unregister:Ge,setError:Me,setFocus:bs,getFieldState:ft};return{...vt,formControl:vt}}function jr(e={}){const s=X.useRef(void 0),t=X.useRef(void 0),a=X.useRef(e.formControl),[c,d]=X.useState(()=>({...B(ls),isLoading:ne(e.defaultValues),errors:e.errors||{},disabled:e.disabled||!1,defaultValues:ne(e.defaultValues)?void 0:e.defaultValues}));if(!s.current||e.formControl&&a.current!==e.formControl)if(a.current=e.formControl,e.formControl)s.current={...e.formControl,formState:c},e.defaultValues&&!ne(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:u,...j}=br(e);s.current={...j,formState:c}}const n=s.current.control;return n._options=e,ar(()=>{const u=n._subscribe({formState:n._proxyFormState,callback:()=>d({...n._formState,defaultValues:n._defaultValues}),reRenderRoot:!0});return d(j=>({...j,isReady:!0})),n._formState.isReady=!0,u},[n]),X.useEffect(()=>n._disableForm(e.disabled),[n,e.disabled]),X.useEffect(()=>{e.mode&&(n._options.mode=e.mode),e.reValidateMode&&(n._options.reValidateMode=e.reValidateMode)},[n,e.mode,e.reValidateMode]),X.useEffect(()=>{e.errors&&(n._setErrors(e.errors),n._focusError())},[n,e.errors]),X.useEffect(()=>{e.shouldUnregister&&n._subjects.state.next({values:n._getWatch()})},[n,e.shouldUnregister]),X.useEffect(()=>{if(n._proxyFormState.isDirty){const u=n._getDirty();u!==c.isDirty&&n._subjects.state.next({isDirty:u})}},[n,c.isDirty]),X.useEffect(()=>{var u;e.values&&!he(e.values,t.current)?(n._reset(e.values,{keepFieldsRef:!0,...n._options.resetOptions}),!((u=n._options.resetOptions)===null||u===void 0)&&u.keepIsValid||n._setValid(),t.current=e.values,d(j=>({...j}))):n._resetDefaultValues()},[n,e.values]),X.useEffect(()=>{n._state.mount||(n._setValid(),n._state.mount=!0),n._state.watch&&(n._state.watch=!1,n._subjects.state.next({...n._formState})),n._removeUnmounted()}),s.current.formState=X.useMemo(()=>ir(c,n),[n,c]),s.current}const zt=(e,s,t)=>{if(e&&"reportValidity"in e){const a=g(t,s);e.setCustomValidity(a&&a.message||""),e.reportValidity()}},it=(e,s)=>{for(const t in s.fields){const a=s.fields[t];a&&a.ref&&"reportValidity"in a.ref?zt(a.ref,t,e):a&&a.refs&&a.refs.forEach(c=>zt(c,t,e))}},Bt=(e,s)=>{s.shouldUseNativeValidation&&it(e,s);const t={};for(const a in e){const c=g(s.fields,a),d=Object.assign(e[a]||{},{ref:c&&c.ref});if(Sr(s.names||Object.keys(e),a)){const n=Object.assign({},g(t,a));F(n,"root",d),F(t,a,n)}else F(t,a,d)}return t},Sr=(e,s)=>{const t=qt(s).replace(/[.*+?^${}()|\\]/g,"\\$&");return e.some(a=>qt(a).match(`^${t}\\.\\d+`))};function qt(e){return e.replace(/[\[\]]/g,"")}function cs(e,s,t){function a(u,j){var E;Object.defineProperty(u,"_zod",{value:u._zod??{},enumerable:!1}),(E=u._zod).traits??(E.traits=new Set),u._zod.traits.add(e),s(u,j);for(const P in n.prototype)P in u||Object.defineProperty(u,P,{value:n.prototype[P].bind(u)});u._zod.constr=n,u._zod.def=j}const c=t?.Parent??Object;class d extends c{}Object.defineProperty(d,"name",{value:e});function n(u){var j;const E=t?.Parent?new d:this;a(E,u),(j=E._zod).deferred??(j.deferred=[]);for(const P of E._zod.deferred)P();return E}return Object.defineProperty(n,"init",{value:a}),Object.defineProperty(n,Symbol.hasInstance,{value:u=>t?.Parent&&u instanceof t.Parent?!0:u?._zod?.traits?.has(e)}),Object.defineProperty(n,"name",{value:e}),n}class wr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}const Nr={};function ds(e){return Nr}function Tr(e,s){return typeof s=="bigint"?s.toString():s}const us=Error.captureStackTrace?Error.captureStackTrace:(...e)=>{};function He(e){return typeof e=="string"?e:e?.message}function fs(e,s,t){const a={...e,path:e.path??[]};if(!e.message){const c=He(e.inst?._zod.def?.error?.(e))??He(s?.error?.(e))??He(t.customError?.(e))??He(t.localeError?.(e))??"Invalid input";a.message=c}return delete a.inst,delete a.continue,s?.reportInput||delete a.input,a}const ms=(e,s)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:s,enumerable:!1}),Object.defineProperty(e,"message",{get(){return JSON.stringify(s,Tr,2)},enumerable:!0}),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Ar=cs("$ZodError",ms),hs=cs("$ZodError",ms,{Parent:Error}),_r=e=>(s,t,a,c)=>{const d=a?Object.assign(a,{async:!1}):{async:!1},n=s._zod.run({value:t,issues:[]},d);if(n instanceof Promise)throw new wr;if(n.issues.length){const u=new(c?.Err??e)(n.issues.map(j=>fs(j,d,ds())));throw us(u,c?.callee),u}return n.value},Er=_r(hs),Pr=e=>async(s,t,a,c)=>{const d=a?Object.assign(a,{async:!0}):{async:!0};let n=s._zod.run({value:t,issues:[]},d);if(n instanceof Promise&&(n=await n),n.issues.length){const u=new(c?.Err??e)(n.issues.map(j=>fs(j,d,ds())));throw us(u,c?.callee),u}return n.value},Vr=Pr(hs);function at(){return at=Object.assign?Object.assign.bind():function(e){for(var s=1;s<arguments.length;s++){var t=arguments[s];for(var a in t)({}).hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},at.apply(null,arguments)}function $t(e,s){try{var t=e()}catch(a){return s(a)}return t&&t.then?t.then(void 0,s):t}function kr(e,s){for(var t={};e.length;){var a=e[0],c=a.code,d=a.message,n=a.path.join(".");if(!t[n])if("unionErrors"in a){var u=a.unionErrors[0].errors[0];t[n]={message:u.message,type:u.code}}else t[n]={message:d,type:c};if("unionErrors"in a&&a.unionErrors.forEach(function(P){return P.errors.forEach(function(H){return e.push(H)})}),s){var j=t[n].types,E=j&&j[a.code];t[n]=ut(n,s,t,c,E?[].concat(E,a.message):a.message)}e.shift()}return t}function Dr(e,s){for(var t={},a=function(){var c=e[0],d=c.code,n=c.message,u=c.path.join(".");if(!t[u])if(c.code==="invalid_union"&&c.errors.length>0){var j=c.errors[0][0];t[u]={message:j.message,type:j.code}}else t[u]={message:n,type:d};if(c.code==="invalid_union"&&c.errors.forEach(function(H){return H.forEach(function(I){return e.push(at({},I,{path:[].concat(c.path,I.path)}))})}),s){var E=t[u].types,P=E&&E[c.code];t[u]=ut(u,s,t,d,P?[].concat(P,c.message):c.message)}e.shift()};e.length;)a();return t}function Fr(e,s,t){if(t===void 0&&(t={}),(function(a){return"_def"in a&&typeof a._def=="object"&&"typeName"in a._def})(e))return function(a,c,d){try{return Promise.resolve($t(function(){return Promise.resolve(e[t.mode==="sync"?"parse":"parseAsync"](a,s)).then(function(n){return d.shouldUseNativeValidation&&it({},d),{errors:{},values:t.raw?Object.assign({},a):n}})},function(n){if((function(u){return Array.isArray(u?.issues)})(n))return{values:{},errors:Bt(kr(n.errors,!d.shouldUseNativeValidation&&d.criteriaMode==="all"),d)};throw n}))}catch(n){return Promise.reject(n)}};if((function(a){return"_zod"in a&&typeof a._zod=="object"})(e))return function(a,c,d){try{return Promise.resolve($t(function(){return Promise.resolve((t.mode==="sync"?Er:Vr)(e,a,s)).then(function(n){return d.shouldUseNativeValidation&&it({},d),{errors:{},values:t.raw?Object.assign({},a):n}})},function(n){if((function(u){return u instanceof Ar})(n))return{values:{},errors:Bt(Dr(n.issues,!d.shouldUseNativeValidation&&d.criteriaMode==="all"),d)};throw n}))}catch(n){return Promise.reject(n)}};throw new Error("Invalid input: not a Zod schema")}const Cr=e=>e.authType==="oauthMicrosoft",Or="••••••••••",Ir=e=>{const s=e.smtpUsername?.trim();return s?s!==e.username:!1},Rr=Es({email:be().email().min(1,"Email is required"),displayName:be().optional(),username:be().optional(),password:be().optional(),imapHost:be().min(1,"IMAP host is required"),imapPort:Nt.number().int().min(1).max(65535),imapTls:ke(),imapStartTls:ke(),smtpHost:be().optional(),smtpPort:Nt.number().int().min(1).max(65535).optional(),smtpTls:ke().optional(),smtpStartTls:ke().optional(),smtpUsername:be().optional(),smtpPassword:be().optional(),useDifferentSmtpCreds:ke().optional()}),Mr=({isOpen:e,onClose:s,account:t,focusSmtp:a})=>{const c=Gt(),d=!!t,[n,u]=O.useState(!1),[j,E]=O.useState(""),[P,H]=O.useState(!1),I=Et(j),C=!!I&&!P,N=O.useRef(null),f=jr({resolver:Fr(Rr),defaultValues:{email:"",displayName:"",username:"",password:"",imapHost:"",imapPort:993,imapTls:!0,imapStartTls:!1,smtpHost:"",smtpPort:587,smtpTls:!1,smtpStartTls:!0,useDifferentSmtpCreds:!1}});O.useEffect(()=>{if(t){const p=Ir(t);f.reset({email:t.email,displayName:t.displayName||"",username:t.username||"",password:Or,imapHost:t.imapHost,imapPort:t.imapPort,imapTls:t.imapTls,imapStartTls:t.imapStartTls,smtpHost:t.smtpHost||"",smtpPort:t.smtpPort||587,smtpTls:t.smtpTls||!1,smtpStartTls:t.smtpStartTls||!0,smtpUsername:p&&t.smtpUsername||"",smtpPassword:"",useDifferentSmtpCreds:p}),u(!1)}else f.reset({email:"",displayName:"",username:"",password:"",imapHost:"",imapPort:993,imapTls:!0,imapStartTls:!1,smtpHost:"",smtpPort:587,smtpTls:!1,smtpStartTls:!0,useDifferentSmtpCreds:!1}),u(!1)},[t,f]);const b=Ne({...Ns()}),ie=Ne({...Ts(),onSuccess:()=>{c.invalidateQueries({queryKey:Fe()}),s()}}),T=Ne({...As(),onSuccess:()=>{c.invalidateQueries({queryKey:Fe()}),s()}}),J=()=>{const p=f.getValues(),k=d&&!n;b.mutate({body:{accountId:k?t?.accountId:void 0,username:p.username||p.email,password:k?void 0:p.password||void 0,imapHost:p.imapHost,imapPort:Number(p.imapPort),imapTls:p.imapTls,imapStartTls:p.imapStartTls}})},R=()=>{const p=f.getValues(),k=d&&!n;b.mutate({body:{accountId:k?t?.accountId:void 0,username:p.username||p.email,password:k?void 0:p.password||void 0,imapHost:p.imapHost,imapPort:Number(p.imapPort),imapTls:p.imapTls,imapStartTls:p.imapStartTls,smtpHost:p.smtpHost||void 0,smtpPort:p.smtpPort?Number(p.smtpPort):void 0,smtpTls:p.smtpTls,smtpStartTls:p.smtpStartTls,smtpUsername:p.useDifferentSmtpCreds?p.smtpUsername:void 0,smtpPassword:p.useDifferentSmtpCreds?p.smtpPassword:void 0}})},V=f.handleSubmit(p=>{if(!d&&!p.password){f.setError("password",{message:"Password is required"});return}const k=Ks({imapHost:p.imapHost,smtpHost:p.smtpHost,smtpPort:p.smtpPort,smtpTls:p.smtpTls,smtpStartTls:p.smtpStartTls});k&&(f.setValue("smtpHost",k.smtpHost),f.setValue("smtpPort",k.smtpPort),f.setValue("smtpTls",k.smtpTls),f.setValue("smtpStartTls",k.smtpStartTls));const ce=k?.smtpHost??p.smtpHost,te=k?.smtpPort??p.smtpPort,ae=k?.smtpTls??p.smtpTls,Se=k?.smtpStartTls??p.smtpStartTls,Ee={email:p.email,displayName:p.displayName?.trim()||void 0,username:p.username||void 0,imapHost:p.imapHost,imapPort:Number(p.imapPort),imapTls:p.imapTls,imapStartTls:p.imapStartTls,smtpHost:ce||void 0,smtpPort:te?Number(te):void 0,smtpTls:ae,smtpStartTls:Se,smtpUsername:p.useDifferentSmtpCreds&&p.smtpUsername||void 0,smtpPassword:p.useDifferentSmtpCreds&&p.smtpPassword||void 0};if(d&&t){const Te={...Ee,password:n?p.password:void 0};T.mutate({path:{accountId:t.accountId},body:Te})}else{const Te={...Ee,password:p.password};ie.mutate({body:Te})}}),oe=ie.isPending||T.isPending,{signature:re,setSignature:pe,isSaving:le}=Hs(t?.accountId),[W,ee]=O.useState(re.plainText);O.useEffect(()=>{ee(re.plainText)},[re.plainText]),O.useEffect(()=>{if(!e||!a)return;const p=N.current;if(!p)return;const k=window.setTimeout(()=>{p.scrollIntoView({behavior:"smooth",block:"start"})},250);return()=>window.clearTimeout(k)},[e,a]);const A=O.useCallback(()=>{W!==re.plainText&&pe(W,W)},[W,re.plainText,pe]),_=p=>{const{tls:k,startTls:ce}=Ue(p);f.setValue("imapTls",k),f.setValue("imapStartTls",ce);const te=f.getValues("imapPort");(te===993||te===143)&&f.setValue("imapPort",p==="tls"?993:143)},D=p=>{const{tls:k,startTls:ce}=Ue(p);f.setValue("smtpTls",k),f.setValue("smtpStartTls",ce);const te=f.getValues("smtpPort");if(te===465||te===587||te===25){const Se=p==="tls"?465:p==="starttls"?587:25;f.setValue("smtpPort",Se)}},$=()=>{const p=f.getValues("imapHost");f.setValue("smtpHost",Gs(p)),f.setValue("smtpTls",!1),f.setValue("smtpStartTls",!0),f.setValue("smtpPort",587)},w=p=>{E(p),H(!1);const k=Et(p);if(!k)return;const ce=Ue(k.imap.security);f.setValue("imapHost",k.imap.host),f.setValue("imapPort",k.imap.port),f.setValue("imapTls",ce.tls),f.setValue("imapStartTls",ce.startTls);const te=Ue(k.smtp.security);f.setValue("smtpHost",k.smtp.host),f.setValue("smtpPort",k.smtp.port),f.setValue("smtpTls",te.tls),f.setValue("smtpStartTls",te.startTls);const ae=f.getValues("email").trim(),Se=f.getValues("username")?.trim();ae&&!Se&&f.setValue("username",ae)},L=I?.passwordHelp.text,ye=Pt(b.data?.imapError,L),Z=Pt(b.data?.smtpError,L);return(t?Cr(t):!1)&&d?i.jsx(Vt,{isOpen:e,onClose:s,title:"Edit Account",footer:i.jsx(se,{type:"button",variant:"secondary",onClick:s,children:"Close"}),children:i.jsxs("div",{className:"space-y-6",children:[i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Microsoft 365 Account"}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"rounded-md border border-line bg-surface-sunken px-3 py-2.5 text-sm text-fg-muted",children:[i.jsx("span",{className:"block text-2xs font-medium uppercase tracking-wider text-fg-subtle mb-1",children:"Email"}),i.jsx("span",{className:"text-fg",children:t?.email})]}),i.jsxs("div",{className:"rounded-md border border-line bg-surface-sunken px-3 py-2.5 text-sm text-fg-muted",children:[i.jsx("span",{className:"block text-2xs font-medium uppercase tracking-wider text-fg-subtle mb-1",children:"Authentication"}),i.jsx("span",{className:"text-fg",children:"Microsoft OAuth (XOAUTH2)"})]}),i.jsx("p",{className:"text-xs text-fg-muted",children:"Server settings are managed automatically for Microsoft 365 accounts. To update credentials, use the Reconnect button."})]})]}),d&&i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Signature"}),i.jsx("div",{className:"space-y-3",children:i.jsxs("div",{children:[i.jsx("label",{htmlFor:"email-sig-view",className:"text-sm font-medium mb-1.5 block",children:"Email Signature"}),i.jsx("textarea",{id:"email-sig-view",value:W,onChange:p=>ee(p.target.value),onBlur:A,rows:5,className:"w-full px-3 py-2 border border-line rounded-md bg-surface-sunken text-sm text-fg placeholder:text-fg-subtle focus-within:border-line-strong focus-within:ring-2 focus-within:ring-ring/30 transition-colors resize-y outline-none",placeholder:"Enter your email signature..."}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:le?"Saving signature...":"This signature will be appended to new emails."})]})})]})]})}):i.jsx(Vt,{isOpen:e,onClose:s,title:d?"Edit Account":"Add Account",footer:i.jsxs(i.Fragment,{children:[i.jsx(se,{type:"button",variant:"secondary",onClick:s,children:"Cancel"}),i.jsx(se,{type:"submit",form:"account-form",variant:"primary",disabled:oe,children:oe?"Saving...":"Save Account"})]}),children:i.jsxs("form",{id:"account-form",onSubmit:V,className:"space-y-6",children:[i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Account Information"}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-provider",className:"text-sm font-medium mb-1.5 block",children:"Provider"}),i.jsxs(_s,{id:"account-provider",value:j,onChange:p=>w(p.target.value),children:[i.jsx("option",{value:"",children:"Custom / other"}),$s.map(p=>i.jsx("option",{value:p.id,children:p.label},p.id))]}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:"Pick your email provider to fill in server settings automatically, or choose Custom to enter them by hand."})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-email",className:"text-sm font-medium mb-1.5 block",children:"Email Address"}),i.jsx(de,{id:"account-email",...f.register("email"),placeholder:"alice@example.com"}),f.formState.errors.email&&i.jsx("p",{className:"text-sm text-danger mt-1",children:f.formState.errors.email.message})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-displayName",className:"text-sm font-medium mb-1.5 block",children:"Display name (optional)"}),i.jsx(de,{id:"account-displayName",...f.register("displayName"),placeholder:"Alice"}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:"What to call this account in Remit. Leave blank to use a name derived from the address."})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-username",className:"text-sm font-medium mb-1.5 block",children:"Username"}),i.jsx(de,{id:"account-username",...f.register("username"),placeholder:"Same as email if empty"})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"account-password",className:"text-sm font-medium mb-1.5 block",children:"Password"}),i.jsx(de,{id:"account-password",...f.register("password",{onChange:()=>u(!0)}),type:"password",onFocus:()=>{d&&!n&&(f.setValue("password",""),u(!0))},placeholder:d?"Leave empty to keep current":""}),f.formState.errors.password&&i.jsx("p",{className:"text-sm text-danger mt-1",children:f.formState.errors.password.message}),I&&i.jsxs("p",{className:"text-xs text-fg-muted mt-1",children:[I.passwordHelp.text," ",i.jsx("a",{href:I.passwordHelp.url,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:underline",children:"Get an app password"})]})]})]})]}),i.jsxs("section",{children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider",children:"Incoming Mail (IMAP)"}),I&&i.jsx("button",{type:"button",onClick:()=>H(p=>!p),className:"text-xs text-fg-muted hover:text-fg transition-colors",children:P?"Use preset settings":"Advanced"})]}),C&&i.jsxs("p",{className:"text-xs text-fg-muted mb-3",children:["Server settings are pre-filled for ",I?.label," and locked. Choose Advanced to edit them by hand."]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"imap-host",className:"text-sm font-medium mb-1.5 block",children:"Server"}),i.jsx(de,{id:"imap-host",...f.register("imapHost"),readOnly:C,placeholder:"imap.example.com"}),f.formState.errors.imapHost&&i.jsx("p",{className:"text-sm text-danger mt-1",children:f.formState.errors.imapHost.message})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"imap-port",className:"text-sm font-medium mb-1.5 block",children:"Port"}),i.jsx(de,{id:"imap-port",...f.register("imapPort"),readOnly:C,type:"number"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-sm font-medium mb-1.5 block",children:"Security"}),i.jsxs("div",{className:"space-y-1.5 mt-2",children:[i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:f.watch("imapTls"),onChange:()=>_("tls")}),"TLS (Port 993)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("imapTls")&&f.watch("imapStartTls"),onChange:()=>_("starttls")}),"STARTTLS (Port 143)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("imapTls")&&!f.watch("imapStartTls"),onChange:()=>_("none")}),"None (Unencrypted)"]})]})]})]}),i.jsx(se,{type:"button",variant:"secondary",onClick:J,disabled:b.isPending,className:"w-full",icon:b.isPending?i.jsx(et,{className:"size-4 animate-spin"}):void 0,children:b.isPending?"Testing...":"Test IMAP Connection"}),b.data&&i.jsxs("div",{className:wt("p-2 rounded-md text-sm",b.data.imapSuccess?"bg-positive/10 text-positive":"bg-danger-soft text-danger"),children:[b.data.imapSuccess?i.jsx(St,{className:"inline size-4 mr-1"}):i.jsx(Oe,{className:"inline size-4 mr-1"}),b.data.imapSuccess?"IMAP Connected":ye]})]})]}),i.jsxs("section",{ref:N,"data-testid":"smtp-section",children:[i.jsxs("div",{className:"flex items-center justify-between mb-3",children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider",children:"Outgoing Mail (SMTP)"}),!C&&i.jsx("button",{type:"button",onClick:$,disabled:!f.watch("imapHost"),className:"text-xs text-fg-muted hover:text-fg transition-colors disabled:opacity-50",children:"Pre-fill from IMAP"})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-host",className:"text-sm font-medium mb-1.5 block",children:"Server"}),i.jsx(de,{id:"smtp-host",...f.register("smtpHost"),readOnly:C,placeholder:"smtp.example.com"})]}),i.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-port",className:"text-sm font-medium mb-1.5 block",children:"Port"}),i.jsx(de,{id:"smtp-port",...f.register("smtpPort"),readOnly:C,type:"number"})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-sm font-medium mb-1.5 block",children:"Security"}),i.jsxs("div",{className:"space-y-1.5 mt-2",children:[i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:f.watch("smtpTls")===!0,onChange:()=>D("tls")}),"TLS (Port 465)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("smtpTls")&&f.watch("smtpStartTls")===!0,onChange:()=>D("starttls")}),"STARTTLS (Port 587)"]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"radio",disabled:C,checked:!f.watch("smtpTls")&&!f.watch("smtpStartTls"),onChange:()=>D("none")}),"None (Unencrypted)"]})]})]})]}),i.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[i.jsx("input",{type:"checkbox",...f.register("useDifferentSmtpCreds")}),"Use different credentials for SMTP"]}),f.watch("useDifferentSmtpCreds")&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-username",className:"text-sm font-medium mb-1.5 block",children:"SMTP Username"}),i.jsx(de,{id:"smtp-username",...f.register("smtpUsername")})]}),i.jsxs("div",{children:[i.jsx("label",{htmlFor:"smtp-password",className:"text-sm font-medium mb-1.5 block",children:"SMTP Password"}),i.jsx(de,{id:"smtp-password",...f.register("smtpPassword"),type:"password"})]})]}),i.jsx(se,{type:"button",variant:"secondary",onClick:R,disabled:b.isPending||!f.watch("smtpHost"),className:"w-full",icon:b.isPending?i.jsx(et,{className:"size-4 animate-spin"}):void 0,children:b.isPending?"Testing...":"Test SMTP Connection"}),b.data?.smtpSuccess!==void 0&&i.jsxs("div",{className:wt("p-2 rounded-md text-sm",b.data.smtpSuccess?"bg-positive/10 text-positive":"bg-danger-soft text-danger"),children:[b.data.smtpSuccess?i.jsx(St,{className:"inline size-4 mr-1"}):i.jsx(Oe,{className:"inline size-4 mr-1"}),b.data.smtpSuccess?"SMTP Connected":Z]})]})]}),d&&i.jsxs("section",{children:[i.jsx("h3",{className:"text-2xs font-semibold text-fg-subtle uppercase tracking-wider mb-3",children:"Signature"}),i.jsx("div",{className:"space-y-3",children:i.jsxs("div",{children:[i.jsx("label",{htmlFor:"email-sig-edit",className:"text-sm font-medium mb-1.5 block",children:"Email Signature"}),i.jsx("textarea",{id:"email-sig-edit",value:W,onChange:p=>ee(p.target.value),onBlur:A,rows:5,className:"w-full px-3 py-2 border border-line rounded-md bg-surface-sunken text-sm text-fg placeholder:text-fg-subtle focus-within:border-line-strong focus-within:ring-2 focus-within:ring-ring/30 transition-colors resize-y outline-none",placeholder:"Enter your email signature..."}),i.jsx("p",{className:"text-xs text-fg-muted mt-1",children:le?"Saving signature...":"This signature will be appended to new emails."})]})})]})]})})};function Wt({open:e,onClose:s,accountEmail:t,signOut:a}){const[c,d]=O.useState(""),[n,u]=O.useState(!1),[j,E]=O.useState(!1),P=Ne({...Vs(),onSuccess:()=>{E(!0),setTimeout(()=>a(),2e3)}}),H=Ne(ks()),I=()=>{P.isPending||(d(""),u(!1),E(!1),P.reset(),H.reset(),s())},C=()=>{if(c.trim().toLowerCase()!==t.toLowerCase()){u(!0);return}u(!1),P.mutate({body:{confirmEmail:c.trim()}})};return i.jsxs(Yt,{open:e,onClose:I,title:"Delete your Remit account",children:[i.jsxs("header",{className:"flex items-center gap-2 border-b border-line px-5 py-3",children:[i.jsx(nt,{className:"size-4 shrink-0 text-danger"}),i.jsx("span",{className:"flex-1 text-sm font-semibold text-fg",children:"Delete your Remit account"}),i.jsx(se,{variant:"ghost",size:"sm",icon:i.jsx(Oe,{className:"size-3.5"}),onClick:I,"aria-label":"Cancel"})]}),j?i.jsxs("div",{className:"px-5 py-6 text-sm text-fg-muted",children:[i.jsx("p",{className:"font-medium text-fg",children:"Account deletion scheduled."}),i.jsx("p",{className:"mt-1",children:"Your data will be erased shortly. Signing you out…"})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"space-y-4 px-5 py-4 text-sm text-fg-muted",children:[i.jsx("p",{children:"This permanently erases everything Remit holds for you:"}),i.jsxs("ul",{className:"space-y-1.5 text-xs",children:[i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"All connected accounts disconnected and access tokens revoked."]}),i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"Synced mail cache and search index."]}),i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"AI history and insights."]}),i.jsxs("li",{className:"flex gap-2",children:[i.jsx("span",{className:"text-danger",children:"•"}),"Preferences and rules."]})]}),i.jsxs("div",{className:"rounded-sm border border-line bg-surface-sunken px-3 py-2 text-xs",children:[i.jsx("strong",{className:"text-fg",children:"Your mail at Gmail / IMAP is not deleted."})," ","This only removes Remit's copy and its access — the mail stays in your provider mailboxes."]}),i.jsxs("div",{className:"text-xs",children:[i.jsxs("button",{type:"button",onClick:()=>H.mutate({}),"aria-busy":H.isPending,className:"inline-flex items-center gap-1.5 font-medium text-accent hover:underline",children:[i.jsx(Ys,{className:"size-3.5"}),H.isPending?"Requesting export…":"Export my data first"]}),H.isSuccess&&i.jsx("p",{className:"mt-1.5 text-fg-muted",role:"status",children:"Export requested. We'll prepare a ZIP of your mail — find it under your data exports when it's ready."}),H.isError&&i.jsx("p",{className:"mt-1.5 text-danger",role:"alert",children:"Couldn't start the export. Please try again."})]}),i.jsxs("div",{children:[i.jsxs("label",{htmlFor:"confirm-remit-email",className:"mb-1 block text-xs font-medium text-fg",children:["Type"," ",i.jsx("span",{className:"font-mono text-fg-muted",children:t})," ","to confirm"]}),i.jsx(de,{id:"confirm-remit-email",type:"email",placeholder:t,value:c,onChange:N=>{d(N.target.value),n&&u(!1),P.isError&&P.reset()},autoComplete:"off"}),n&&i.jsx("p",{className:"mt-1.5 text-xs text-danger",role:"alert",children:"That doesn't match your account email. Type it exactly to confirm."}),P.isError&&i.jsx("p",{className:"mt-1.5 text-xs text-danger",role:"alert",children:P.error instanceof Error?P.error.message:"Something went wrong. Please try again."})]})]}),i.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-line px-5 py-3",children:[i.jsx(se,{variant:"secondary",size:"sm",onClick:I,children:"Cancel"}),i.jsx(se,{variant:"danger",size:"sm",onClick:C,"aria-busy":P.isPending,children:P.isPending?"Deleting…":"Delete everything"})]})]})]})}function Ur(e){const{Account:s}=Ps();return i.jsx(s,{fallback:i.jsx(Wt,{...e,accountEmail:"",signOut:()=>{}}),children:({email:t,signOut:a})=>i.jsx(Wt,{...e,accountEmail:t??"",signOut:a})})}function Lr(){const[e,s]=O.useState(!1);return i.jsxs("section",{className:"mt-8 border-t border-line pt-6",children:[i.jsx(Xs,{title:"Delete your Remit account",description:"Disconnects every account and erases Remit's copy of your mail, insights and preferences. Your mail at the providers is untouched.",action:i.jsx(se,{variant:"danger",size:"sm",onClick:()=>s(!0),children:"Delete your Remit account"})}),i.jsx(Ur,{open:e,onClose:()=>s(!1)})]})}function Hr(e){const s=e.toLowerCase();return s==="access_denied"?"You cancelled the sign-in.":s==="consent_required"||s.includes("admin_consent")||s.includes("interaction_required")?"Your organisation's admin needs to approve Remit. Ask your IT admin to grant the required permissions.":s.includes("imap_disabled")||s.includes("imap disabled")?"IMAP is disabled for this account. Ask your admin to enable IMAP access in the Microsoft 365 admin centre.":`Sign-in failed: ${e}. Please try again.`}function zr(e){const s=e.split("@")[0]??"";return s?s.split(/[._-]+/).filter(Boolean).map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" "):e}function Br(e){const s=e.displayName?.trim();return s||zr(e.email)}function qr(e){if(!e.lastSyncAt)return"never synced";const s=Qs(e.lastSyncAt);return s?`synced ${s}`:"never synced"}function Kt(e){return e.muted?.value?"muted":e.lastError?"error":e.connectionState==="authenticated"?"healthy":"error"}function $r(e){return e.connectionState==="reauth_required"}const Wr=i.jsxs("div",{className:"space-y-3",children:[i.jsxs("p",{children:[i.jsx("strong",{className:"text-fg",children:"Sync health"})," shows the IMAP connection state and the last successful sync per account."]}),i.jsxs("p",{children:[i.jsx("strong",{className:"text-fg",children:"Error"})," means the last connection attempt failed — the raw server response is shown on the card. Reconnect re-runs the connection test from the add-account wizard."]}),i.jsxs("p",{children:[i.jsx("strong",{className:"text-fg",children:"Muted"})," accounts keep syncing but stay out of the daily brief and unified counts."]})]}),Kr=()=>i.jsx("div",{className:"space-y-3",role:"status","aria-busy":"true","aria-label":"Loading accounts",children:["skeleton-0","skeleton-1"].map(e=>i.jsx("div",{className:"rounded-sm border border-line bg-surface animate-pulse p-4",children:i.jsxs("div",{className:"flex items-center gap-3",children:[i.jsx("div",{className:"size-10 rounded-full bg-surface-sunken"}),i.jsxs("div",{className:"flex-1 space-y-2",children:[i.jsx("div",{className:"h-4 bg-surface-sunken rounded w-1/3"}),i.jsx("div",{className:"h-3 bg-surface-sunken rounded w-2/3"})]})]})},e))});function ni(){const e=Tt.useSearch(),s=Ds({from:Tt.fullPath}),[t,a]=O.useState(!0),[c,d]=O.useState(!1),[n,u]=O.useState(!1),[j,E]=O.useState(null),[P,H]=O.useState(!1),[I,C]=O.useState(null),[N,f]=O.useState(null),[b,ie]=O.useState(null),[T,J]=O.useState(null),R=Gt(),{data:V,isPending:oe,isError:re,error:pe,refetch:le}=Fs(Cs());O.useEffect(()=>{e.editAccountId&&(E(e.editAccountId),H(!!e.focusSmtp),s({search:{editAccountId:void 0,focusSmtp:void 0,connected:e.connected,oauthError:e.oauthError},replace:!0}))},[e.editAccountId,e.focusSmtp,s,e.connected,e.oauthError]),O.useEffect(()=>{e.connected&&(f("Account connected successfully."),E(e.connected),R.invalidateQueries({queryKey:Fe()}),s({search:{connected:void 0,oauthError:void 0,editAccountId:void 0,focusSmtp:void 0},replace:!0}))},[e.connected,s,R]),O.useEffect(()=>{e.oauthError&&(ie(Hr(e.oauthError)),s({search:{oauthError:void 0,connected:void 0,editAccountId:void 0,focusSmtp:void 0},replace:!0}))},[e.oauthError,s]);const W=Ne({...Os(),onSuccess:w=>{window.location.assign(w.authorizationUrl)},onError:w=>{ie(w instanceof Error?w.message:"Failed to start reconnect"),J(null)}}),ee=Ne({...Is(),onSuccess:()=>{R.invalidateQueries({queryKey:Fe()}),C(null)}}),A=V?.accounts.find(w=>w.accountId===I),_=V?.accounts.find(w=>w.accountId===j),D=()=>{d(!1),u(!1),E(null),H(!1)},$=w=>{const L=Us[w];L&&s({to:L})};return i.jsxs(Bs,{items:Rs,activeId:"accounts",title:"Accounts",description:"Every account keeps syncing — muted ones just stay out of unified views.",help:Wr,helpOpen:t,onToggleHelp:()=>a(w=>!w),onSelect:$,onBackToMail:()=>{s({to:"/mail"})},children:[N&&i.jsx(At,{tone:"success",variant:"soft","data-testid":"oauth-success-banner",onDismiss:()=>f(null),children:N}),b&&i.jsx(At,{tone:"danger",variant:"soft","data-testid":"oauth-error-banner",onDismiss:()=>ie(null),children:b}),i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(Ms,{tone:"neutral",children:oe||re?"accounts":`${V.accounts.length} ${V.accounts.length===1?"account":"accounts"}`}),i.jsx(se,{variant:"primary",size:"sm",icon:i.jsx(_t,{className:"size-3.5"}),onClick:()=>u(!0),children:"Add account"})]}),oe?i.jsx(Kr,{}):re?i.jsx(Zs,{title:"Couldn't load accounts",error:pe,onRetry:()=>{le()}}):V.accounts.length===0?i.jsxs("div",{className:"py-12 text-sm text-fg-muted","data-testid":"accounts-empty",children:[i.jsx("p",{className:"mb-3",children:"No accounts configured."}),i.jsx(se,{variant:"primary",size:"sm",icon:i.jsx(_t,{className:"size-3.5"}),onClick:()=>u(!0),children:"Add your first account"})]}):i.jsx("div",{className:"space-y-3",children:V.accounts.map(w=>{const L=$r(w),ye=w.authType==="oauthMicrosoft",Z=T===w.accountId&&W.isPending,ve=L&&ye?{label:"Reconnect",variant:"secondary",busy:Z,busyLabel:"Redirecting…",onClick:()=>{J(w.accountId),W.mutate({body:{email:w.email}})}}:Kt(w)==="error"?{label:"Reconnect",variant:"secondary",onClick:()=>E(w.accountId)}:{label:"Manage",variant:"ghost",onClick:()=>E(w.accountId)},p=i.jsx(zs,{actions:[ve],destructive:{label:"Delete account",iconOnly:!0,icon:i.jsx(Ls,{className:"size-3.5"}),onClick:()=>C(w.accountId)}});return i.jsx(qs,{label:Br(w),email:w.email,connector:ye?"Microsoft 365":"IMAP",syncLabel:qr(w),state:Kt(w),errorDetail:L?"Re-authentication required":w.lastError,trailing:p},w.accountId)})}),n&&i.jsx("div",{className:"fixed inset-0 z-40 overflow-auto bg-canvas",children:i.jsx(Ws,{skipWelcome:!0,onComplete:()=>{u(!1),R.invalidateQueries({queryKey:Fe()})},onCancel:()=>u(!1)})}),i.jsx(Mr,{isOpen:c||!!j,account:_,focusSmtp:P,onClose:D}),i.jsxs(Yt,{open:!!I,onClose:()=>C(null),title:"Delete account",children:[i.jsxs("header",{className:"flex items-center gap-2 border-b border-line px-5 py-3",children:[i.jsx(nt,{className:"size-4 shrink-0 text-danger"}),i.jsx("span",{className:"flex-1 text-sm font-semibold text-fg",children:"Delete account"}),i.jsx(se,{variant:"ghost",size:"sm",icon:i.jsx(Oe,{className:"size-3.5"}),onClick:()=>C(null),"aria-label":"Cancel"})]}),i.jsxs("div",{className:"space-y-3 px-5 py-4 text-sm text-fg-muted",children:[i.jsx("p",{className:"text-center text-lg font-medium text-fg",children:"Are you sure?"}),A&&i.jsx("p",{className:"text-center",children:A.email}),i.jsxs("ul",{className:"list-inside list-disc space-y-1",children:[i.jsx("li",{children:"Remove the account from your settings"}),i.jsx("li",{children:"Stop syncing mail for this account"}),i.jsx("li",{children:"Delete all associated data (within 24 hours)"})]})]}),i.jsxs("footer",{className:"flex items-center justify-end gap-2 border-t border-line px-5 py-3",children:[i.jsx(se,{variant:"secondary",size:"sm",onClick:()=>C(null),children:"Cancel"}),i.jsx(se,{variant:"danger",size:"sm","aria-busy":ee.isPending,icon:ee.isPending?i.jsx(et,{className:"size-3.5 animate-spin"}):void 0,onClick:()=>{ee.isPending||I&&ee.mutate({path:{accountId:I}})},children:ee.isPending?"Deleting…":"Delete account"})]})]}),i.jsx(Lr,{})]})}export{ni as component,Hr as mapOauthError};
|