1import{j as e}from"./vendor-query-DUki8u-D.js";import{g as $,u as V,I as U,B as S,x as Je,y as Ze,z as Xe,o as W,D as es,a as ss,b as ts,c as as,d as ns,A as Ae,C as Pe,E as Ee,F as ue,G as X,J as ne}from"./App-DQmYVKnt.js";import{r as o,L as G,u as ye,f as rs}from"./vendor-react-DHU755GE.js";import{C as E,a as R,b as L,d as I,c as T}from"./card-DHYvmiDl.js";import{T as is,a as ls,b as os,c as cs}from"./tabs-Djw7dsBS.js";import{S as he,a as xe,b as pe,c as fe,d as Q}from"./select-DEQ3_uib.js";import{supabase as k}from"./client-CNze1gAi.js";import{L as M}from"./label-DjIaEm-j.js";import{T as te}from"./textarea-B-TTCajr.js";import{E as be,P as Re}from"./validated-inputs-CWdh4S3W.js";import{A as ds,a as us,b as ms}from"./avatar-nMrNRpAz.js";import{u as Le}from"./useResolvedAffiliate-DJD0FTLV.js";import{L as F,V as hs,aL as Ie,aj as Ue,j as ve,n as xs,I as oe,ab as ps,a7 as fs,E as ee,u as ge,ax as Fe,T as Be,e as Oe,o as gs,ay as js,aM as ys,O as ze,a0 as We,aN as bs,aO as $e,c as Ye,aP as we,F as Ne,v as ke,aQ as vs,J as ws,aK as ce,aR as Ns,az as je,X as ks,aS as _s,G as Ve,aT as le,aU as He,W as _e,S as Cs,aV as Ss,aW as As,aX as Ps,i as Ce,ao as Ge,B as Es,_ as Ts,aY as Ds}from"./vendor-icons-DQUIN5dH.js";import{h as qs}from"./error-reporter-CRL-ULrG.js";import{B as Ms}from"./BrokerSlugEditDialog-Bk67LJ7r.js";import{f as de}from"./format-D9x0XWGR.js";import{S as Ke}from"./switch-DOyMpYiY.js";import{generateAgreementPdf as Te}from"./agreement-pdf-kzFV7GOn.js";import{A as Rs}from"./AgreementViewer-DAkfI7IH.js";import{A as Ls,a as Is,b as Us,c as Fs,d as Bs,e as Os,f as zs,g as Ws,h as $s}from"./alert-dialog-D4eg6Jhx.js";import"./vendor-pdf-BQwOdAin.js";import"./vendor-charts-DsctC1NR.js";import"./useTheme-CHHwG8SV.js";import"./vendor-supabase-D2XPrbcR.js";import"./vendor-motion-DoyUfQ58.js";import"./index-BdQq_4o_.js";import"./index-BFcYZw7s.js";import"./breadcrumbs-CN3GC8vy.js";import"./en-US-BqCXNUOZ.js";import"./checkbox-CTRyYrqf.js";import"./scroll-area-D4nk6JJE.js";import"./separator-Bfjb0NJN.js";import"./SignaturePad-B1CX7pmq.js";const Ys=()=>{const{user:s}=$(),{toast:t}=V(),{affiliate:a,affiliateId:n}=Le("id, company"),[u,h]=o.useState(!0),[f,i]=o.useState(!1),[b,d]=o.useState(!1),[l,j]=o.useState({full_name:"",display_name:"",company:"",email:"",username:"",phone:"",bio:"",headline:"",avatar_url:"",locale:"en-US",timezone:"America/New_York"});o.useEffect(()=>{s&&(async()=>{const{data:w}=await k.from("profiles").select("*").eq("user_id",s.id).maybeSingle(),r=w||{};j({full_name:r.full_name||"",display_name:r.display_name||"",company:"",email:r.email||s.email||"",username:r.username||"",phone:r.phone||"",bio:r.bio||"",headline:r.headline||"",avatar_url:r.avatar_url||"",locale:r.locale||"en-US",timezone:r.timezone||"America/New_York"}),h(!1)})()},[s]),o.useEffect(()=>{const w=(a==null?void 0:a.company)||"";j(r=>r.company===w?r:{...r,company:w})},[a==null?void 0:a.company]);const _=["image/png","image/jpeg","image/webp","image/gif"],y=5*1024*1024,x=async w=>{var A;const r=(A=w.target.files)==null?void 0:A[0];if(!(!r||!s)){if(!_.includes(r.type)){t({title:"Unsupported file",description:"Use PNG, JPEG, WebP, or GIF.",variant:"destructive"});return}if(r.size>y){t({title:"File too large",description:"Max 5 MB.",variant:"destructive"});return}d(!0);try{const p=(r.name.split(".").pop()||"png").toLowerCase().replace(/[^a-z0-9]/g,""),N=`${s.id}/${Date.now()}.${p}`,{error:Y}=await k.storage.from("avatars").upload(N,r,{upsert:!1,contentType:r.type,cacheControl:"3600"});if(Y)throw Y;const{data:Z}=k.storage.from("avatars").getPublicUrl(N),c=`${Z.publicUrl}?v=${Date.now()}`,m=l.avatar_url;if(j(v=>({...v,avatar_url:c})),m){const v=m.match(/\/avatars\/(.+?)(\?|$)/);v&&v[1]&&!v[1].endsWith(N)&&await k.storage.from("avatars").remove([v[1]]).catch(()=>{})}t({title:"Avatar uploaded â click Save to apply"})}catch(p){t({title:"Upload failed",description:p.message||"Avatar storage may not be configured.",variant:"destructive"})}finally{d(!1)}}},D=async w=>{if(w.preventDefault(),!!s){i(!0);try{const{error:r}=await k.from("profiles").update({full_name:l.full_name,email:l.email,phone:l.phone||null,bio:l.bio||null,headline:l.headline||null,avatar_url:l.avatar_url||null,locale:l.locale,timezone:l.timezone}).eq("user_id",s.id);if(r)throw r;if(n){const{error:A}=await k.from("affiliates").update({company:l.company||null,full_name:l.full_name||null}).eq("id",n);if(A)throw A}if(await k.from("brokers").update({full_name:l.full_name||null}).eq("user_id",s.id),await k.auth.updateUser({data:{full_name:l.full_name,avatar_url:l.avatar_url||null}}),l.email&&l.email!==s.email){const A=`${window.location.origin}/account?tab=profile&email_changed=1`,{error:p}=await k.auth.updateUser({email:l.email},{emailRedirectTo:A});if(p)throw p;t({title:"Profile saved",description:"Check your new email for a confirmation link."})}else t({title:"Profile saved"})}catch(r){t({title:"Save failed",description:r.message,variant:"destructive"})}finally{i(!1)}}};if(u)return e.jsx("div",{className:"flex items-center justify-center p-12",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})});const B=(l.full_name||l.email||"U").split(" ").map(w=>w[0]).join("").slice(0,2).toUpperCase();return e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"font-display text-lg",children:"Profile"}),e.jsx(I,{children:"Personal info shown across the platform."})]}),e.jsx(T,{children:e.jsxs("form",{onSubmit:D,className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(ds,{className:"h-16 w-16 border",children:[e.jsx(us,{src:l.avatar_url}),e.jsx(ms,{children:B})]}),e.jsxs("label",{className:"cursor-pointer",children:[e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:x}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded-md border bg-background hover:bg-muted",children:[b?e.jsx(F,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(hs,{className:"h-3.5 w-3.5"}),b?"Uploadingâ¦":"Change photo"]})]})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(M,{children:"Full name"}),e.jsx(U,{value:l.full_name,onChange:w=>j({...l,full_name:w.target.value})})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Email"}),e.jsx(be,{value:l.email,onChange:w=>j({...l,email:w})})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Company"}),e.jsx(U,{value:l.company,placeholder:"Your company name",onChange:w=>j({...l,company:w.target.value})})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Phone"}),e.jsx(Re,{value:l.phone,onChange:w=>j({...l,phone:w})})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Headline"}),e.jsx(U,{value:l.headline,placeholder:"Optional public tagline",onChange:w=>j({...l,headline:w.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Bio"}),e.jsx(te,{rows:3,value:l.bio,onChange:w=>j({...l,bio:w.target.value}),placeholder:"A short bio shown on your public referral page."})]}),e.jsxs(S,{type:"submit",disabled:f,className:"bg-primary text-primary-foreground",children:[f?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Ie,{className:"h-4 w-4 mr-2"}),f?"Savingâ¦":"Save changes"]})]})})]})},me=s=>({affiliate_id:s,display_name:null,company:null,email:null,phone:null});function Vs(){const{affiliateId:s,loading:t}
1=Je(),[a,n]=o.useState(null),[u,h]=o.useState(!0),[f,i]=o.useState(!1);o.useEffect(()=>{if(t)return;if(!s){n(null),h(!1);return}let d=!1;return(async()=>{h(!0);const{data:l}=await k.from("affiliate_public_contact").select("*").eq("affiliate_id",s).maybeSingle();d||(n(l??me(s)),h(!1))})(),()=>{d=!0}},[s,t]);const b=o.useCallback(async d=>{if(!s)return{error:"No affiliate"};i(!0);const l={...a??me(s),...d,affiliate_id:s},{error:j}=await k.from("affiliate_public_contact").upsert(l,{onConflict:"affiliate_id"});return j||n(l),i(!1),{error:j}},[s,a]);return{affiliateId:s,contact:a??(s?me(s):null),loading:u||t,saving:f,save:b}}const re=(...s)=>{for(const t of s){const a=(t??"").trim();if(a)return a}return""};function Hs(s,t){return{name:re(t==null?void 0:t.display_name,s==null?void 0:s.full_name),company:re(t==null?void 0:t.company,s==null?void 0:s.company),email:re(t==null?void 0:t.email,s==null?void 0:s.email),phone:re(t==null?void 0:t.phone,s==null?void 0:s.phone)}}const Gs=()=>{const{toast:s}=V(),{user:t}=$(),{affiliate:a}=Le("full_name, company, email, phone"),{contact:n,loading:u,saving:h,save:f}=Vs(),[i,b]=o.useState(null);o.useEffect(()=>{t&&(async()=>{const{data:N}=await k.from("profiles").select("full_name, email, phone").eq("user_id",t.id).maybeSingle();b(N??null)})()},[t==null?void 0:t.id]);const d={full_name:(a==null?void 0:a.full_name)||(i==null?void 0:i.full_name)||"",company:(a==null?void 0:a.company)||"",email:(a==null?void 0:a.email)||(i==null?void 0:i.email)||(t==null?void 0:t.email)||"",phone:(a==null?void 0:a.phone)||(i==null?void 0:i.phone)||""},[l,j]=o.useState(""),[_,y]=o.useState(""),[x,D]=o.useState(""),[B,w]=o.useState("");o.useEffect(()=>{n&&(j(n.display_name??""),y(n.company??""),D(n.email??""),w(n.phone??""))},[n]);const r=async()=>{const{error:N}=await f({display_name:l.trim()||null,company:_.trim()||null,email:x.trim()||null,phone:B.trim()||null});s(N?{title:"Couldn't save",description:String(N),variant:"destructive"}:{title:"Public contact updated",description:"Your landing pages and flyers will reflect these changes."})},A=N=>{N==="display_name"&&j(""),N==="company"&&y(""),N==="email"&&D(""),N==="phone"&&w("")},p=Hs(d,{display_name:l,company:_,email:x,phone:B});return u?e.jsx("div",{className:"h-64 flex items-center justify-center",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-5",children:[e.jsx(E,{className:"border-primary/30 bg-primary/[0.03]",children:e.jsxs(T,{className:"p-4 flex items-start gap-3",children:[e.jsx("div",{className:"rounded-md bg-primary/10 p-2 shrink-0",children:e.jsx(Ue,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Public-Facing Contact Info"}),e.jsxs("p",{className:"text-muted-foreground mt-0.5",children:["This is what prospects see on your ",e.jsx("strong",{children:"landing pages, flyers, QR cards, and email signatures"}),". It is ",e.jsx("strong",{children:"separate from your account profile"})," â your login email, internal notifications, and payout info are never affected. Leave a field blank to fall back to your account value."]})]})]})}),e.jsxs(E,{children:[e.jsx(R,{children:e.jsx(L,{className:"text-base",children:"Edit your public contact"})}),e.jsxs(T,{className:"space-y-4",children:[e.jsx(ie,{icon:e.jsx(ve,{className:"h-3.5 w-3.5"}),label:"Display name",help:`Falls back to "${d.full_name||"â"}"`,onReset:()=>A("display_name"),isOverride:!!l.trim(),children:e.jsx(U,{value:l,onChange:N=>j(N.target.value),placeholder:d.full_name})}),e.jsx(ie,{icon:e.jsx(xs,{className:"h-3.5 w-3.5"}),label:"Company",help:`Falls back to "${d.company||"â"}"`,onReset:()=>A("company"),isOverride:!!_.trim(),children:e.jsx(U,{value:_,onChange:N=>y(N.target.value),placeholder:d.company||"e.g. Acme Trade Consulting"})}),e.jsx(ie,{icon:e.jsx(oe,{className:"h-3.5 w-3.5"}),label:"Public email",help:`Falls back to "${d.email||"â"}"`,onReset:()=>A("email"),isOverride:!!x.trim(),children:e.jsx(be,{value:x,onChange:N=>D(N),placeholder:d.email})}),e.jsx(ie,{icon:e.jsx(ps,{className:"h-3.5 w-3.5"}),label:"Public phone",help:`Falls back to "${d.phone||"â"}"`,onReset:()=>A("phone"),isOverride:!!B.trim(),children:e.jsx(Re,{value:B,onChange:N=>w(N),placeholder:d.phone})}),e.jsx("div",{className:"flex items-center justify-end gap-2 pt-2",children:e.jsxs(S,{onClick:r,disabled:h,children:[h&&e.jsx(F,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Public Contact"]})})]})]}),e.jsxs(E,{className:"bg-card",children:[e.jsx(R,{children:e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(fs,{className:"h-4 w-4 text-primary"})," Preview"]})}),e.jsxs(T,{children:[e.jsxs("div",{className:"rounded-lg border bg-background/60 p-4 space-y-1",children:[e.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.22em] text-primary",children:"Referred By"}),e.jsxs("div",{className:"font-display font-bold text-foreground",children:[p.company||p.name||"â",p.company&&p.name&&p.company.toLowerCase()!==p.name.toLowerCase()&&e.jsxs("span",{className:"font-normal text-muted-foreground",children:[" · ",p.name]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground flex flex-wrap gap-x-4 gap-y-0.5",children:[p.email&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-foreground",children:"Email:"})," ",p.email]}),p.phone&&e.jsxs("span",{children:[e.jsx("strong",{className:"text-foreground",children:"Phone:"})," ",p.phone]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["See it live: ",e.jsxs(G,{to:"/partner/marketing",className:"text-primary hover:underline inline-flex items-center gap-1",children:["Marketing Toolbox ",e.jsx(ee,{className:"h-3 w-3"})]})]})]})]})]})},ie=({icon:s,label:t,help:a,onReset:n,isOverride:u,children:h})=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs(M,{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[s,t]}),u&&e.jsxs(S,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px]",onClick:n,children:[e.jsx(ge,{className:"h-3 w-3 mr-1"})," Use account value"]})]}),h,e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:a})]}),Ks=()=>{const{user:s}=$(),{toast:t}
1=V(),[a,n]=o.useState(!0),[u,h]=o.useState(!1),[f,i]=o.useState(null),[b,d]=o.useState(""),[l,j]=o.useState("");o.useEffect(()=>{if(!s){n(!1);return}(async()=>{const{data:x}=await k.from("affiliates").select("id, slug").eq("user_id",s.id).maybeSingle();x&&(i(x.id),d(x.slug||""),j(x.slug||"")),n(!1)})()},[s]);const _=async()=>{if(!f||!l||l===b)return;h(!0);const{data:x,error:D}=await k.from("affiliates").update({slug:l}).eq("id",f).select("id, slug");D?t({title:"Error",description:qs(D),variant:"destructive"}):!x||x.length===0?t({title:"Couldn't update username",description:"Only the partner owner can change the referral username.",variant:"destructive"}):(d(x[0].slug||l),t({title:"Username updated",description:"Your referral links now use the new username."})),h(!1)};if(a||!f)return null;const y=l&&l!==b;return e.jsxs(E,{className:"shadow-lg",children:[e.jsxs(R,{children:[e.jsxs(L,{className:"font-display text-lg flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4 text-primary"})," Referral Username"]}),e.jsx(I,{children:"This is the personalized part of every referral link you share."})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{children:"Username"}),e.jsx(U,{value:l,onChange:x=>j(x.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"your-username",className:"font-mono"}),e.jsxs("p",{className:"text-xs text-muted-foreground break-all",children:["Your link will be:"," ",e.jsx("span",{className:"font-mono font-medium text-foreground break-all",children:Ze(l||"username")})]})]}),y&&e.jsxs("div",{className:"p-3 rounded-lg bg-destructive/8 border border-destructive/20 flex items-start gap-2.5",children:[e.jsx(Be,{className:"h-4 w-4 text-destructive shrink-0 mt-0.5"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Any links you've already shared using"," ",e.jsx("span",{className:"font-mono font-semibold text-foreground",children:b})," will"," ",e.jsx("strong",{className:"text-destructive",children:"stop working immediately"})," after you save."]})]}),e.jsxs(S,{onClick:_,disabled:u||!y,className:"w-full bg-primary text-primary-foreground",children:[u?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Oe,{className:"h-4 w-4 mr-2"}),u?"Saving...":"Update Username"]})]})]})},Qs=()=>{const{user:s}=$(),{toast:t}=V(),[a,n]=o.useState(!0),[u,h]=o.useState(null),[f,i]=o.useState(""),[b,d]=o.useState(!1),[l,j]=o.useState(!1);o.useEffect(()=>{if(!s){n(!1);return}(async()=>{const{data:x}=await k.from("brokers").select("id, slug").eq("user_id",s.id).maybeSingle();x&&(h(x.id),i(x.slug||"")),n(!1)})()},[s]);const _=o.useMemo(()=>f?Xe(f):"",[f]),y=async()=>{if(_)try{await navigator.clipboard.writeText(_),d(!0),t({title:"Link copied"}),setTimeout(()=>d(!1),2e3)}catch{t({title:"Copy failed",variant:"destructive"})}};return a||!u?null:e.jsxs(E,{className:"shadow-lg",children:[e.jsxs(R,{children:[e.jsxs(L,{className:"font-display text-lg flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4 text-primary"})," Referral Slug"]}),e.jsx(I,{children:"The personalized handle in your public referral link. Share it on your website, in emails, or via SMS."})]}),e.jsx(T,{className:"space-y-3",children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs text-muted-foreground",children:"Your link"}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx(U,{readOnly:!0,value:_||"â",onFocus:x=>x.currentTarget.select(),className:"font-mono text-xs bg-muted/40 border-primary/15"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{type:"button",variant:"outline",onClick:()=>j(!0),className:"gap-1.5 shrink-0",children:[e.jsx(gs,{className:"h-4 w-4"})," Edit"]}),e.jsxs(S,{type:"button",onClick:y,disabled:!_,className:"gap-1.5 shrink-0",children:[b?e.jsx(Oe,{className:"h-4 w-4"}):e.jsx(js,{className:"h-4 w-4"}),b?"Copied":"Copy"]})]})]}),f&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Current slug: ",e.jsx("span",{className:"font-mono font-medium text-foreground",children:f})]})]})}),e.jsx(Ms,{brokerId:u,currentSlug:f,open:l,onOpenChange:j,onSaved:x=>i(x)})]})},Js=({isPartner:s})=>{const{isBroker:t}=$(),n=ye().pathname.startsWith("/brokers"),u=n&&t,h=!n&&s;return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ys,{}),h&&e.jsx(Ks,{}),h&&e.jsx(Gs,{}),u&&e.jsx(Qs,{})]})},Zs=()=>{const{user:s,session:t}=$(),{toast:a}=V(),[n,u]=o.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[h,f]=o.useState(!1),[i,b]=o.useState(!1),[d,l]=o.useState([]),[j,_]=o.useState({newEmail:"",password:""}
1),[y,x]=o.useState(!1);o.useEffect(()=>{l(((s==null?void 0:s.identities)||[]).map(p=>p.provider))},[s]);const D=d.includes("email"),B=async p=>{if(p.preventDefault(),n.newPassword!==n.confirmPassword){a({title:"Passwords don't match",variant:"destructive"});return}if(n.newPassword.length<8){a({title:"Use at least 8 characters",variant:"destructive"});return}if(D&&!n.currentPassword){a({title:"Enter your current password",variant:"destructive"});return}f(!0);try{if(D&&(s!=null&&s.email)){const{error:Y}=await k.auth.signInWithPassword({email:s.email,password:n.currentPassword});if(Y){a({title:"Current password is incorrect",variant:"destructive"}),f(!1);return}}const{error:N}=await k.auth.updateUser({password:n.newPassword});if(N)throw N;a({title:"Password updated"}),u({currentPassword:"",newPassword:"",confirmPassword:""})}catch(N){a({title:"Error",description:N.message,variant:"destructive"})}finally{f(!1)}},w=async()=>{b(!0);try{const{error:p}=await k.auth.signOut({scope:"others"});if(p)throw p;a({title:"Signed out of all other devices"})}catch(p){a({title:"Error",description:p.message,variant:"destructive"})}finally{b(!1)}},r=s==null?void 0:s.last_sign_in_at,A=async p=>{if(p.preventDefault(),!(s!=null&&s.email))return;const N=j.newEmail.trim().toLowerCase();if(!N||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(N)){a({title:"Enter a valid email",variant:"destructive"});return}if(N===s.email.toLowerCase()){a({title:"That's already your email",variant:"destructive"});return}if(D&&!j.password){a({title:"Enter your current password",variant:"destructive"});return}x(!0);try{if(D){const{error:c}=await k.auth.signInWithPassword({email:s.email,password:j.password});if(c){a({title:"Current password is incorrect",variant:"destructive"}),x(!1);return}}const Y=`${window.location.origin}/account?tab=security&email_changed=1`,{error:Z}=await k.auth.updateUser({email:N},{emailRedirectTo:Y});if(Z)throw Z;a({title:"Confirmation sent",description:`We sent a confirmation link to ${N}. Click it to finish the change.`}),_({newEmail:"",password:""})}catch(Y){a({title:"Email change failed",description:Y.message,variant:"destructive"})}finally{x(!1)}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4 text-gold"})," Email address"]}),e.jsxs(I,{children:["Your current email is ",e.jsx("span",{className:"font-medium text-foreground",children:s==null?void 0:s.email}),". Enter a new email and confirm with your password."]})]}),e.jsx(T,{children:e.jsxs("form",{onSubmit:A,className:"space-y-3 max-w-md",children:[e.jsxs("div",{children:[e.jsx(M,{children:"New email"}),e.jsx(be,{value:j.newEmail,onChange:p=>_({...j,newEmail:p})})]}),D&&e.jsxs("div",{children:[e.jsx(M,{children:"Current password"}),e.jsx(U,{type:"password",autoComplete:"current-password",value:j.password,onChange:p=>_({...j,password:p.target.value}),required:!0})]}),e.jsxs(S,{type:"submit",variant:"outline",disabled:y,children:[y?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(oe,{className:"h-4 w-4 mr-2"}),y?"Sendingâ¦":"Change email"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A confirmation link will be sent to your new email. The change takes effect once you click it."})]})})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(ys,{className:"h-4 w-4 text-gold"})," Password"]}),e.jsx(I,{children:"Use at least 8 characters with a mix of letters and numbers."})]}),e.jsx(T,{children:e.jsxs("form",{onSubmit:B,className:"space-y-3 max-w-md",children:[D&&e.jsxs("div",{children:[e.jsx(M,{children:"Current password"}),e.jsx(U,{type:"password",autoComplete:"current-password",value:n.currentPassword,onChange:p=>u({...n,currentPassword:p.target.value}),required:!0})]}),e.jsxs("div",{children:[e.jsx(M,{children:"New password"}),e.jsx(U,{type:"password",autoComplete:"new-password",value:n.newPassword,onChange:p=>u({...n,newPassword:p.target.value}),minLength:8,required:!0})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Confirm password"}),e.jsx(U,{type:"password",autoComplete:"new-password",value:n.confirmPassword,onChange:p=>u({...n,confirmPassword:p.target.value}),minLength:8,required:!0})]}),e.jsxs(S,{type:"submit",variant:"outline",disabled:h,children:[h?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ze,{className:"h-4 w-4 mr-2"}),h?"Updatingâ¦":"Change password"]})]})})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4 text-gold"})," Two-factor authentication"]}),e.jsx(I,{children:"Add a second factor (authenticator app) to make your account harder to compromise."})]}),e.jsx(T,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4 p-4 rounded-md border bg-muted/30",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Authenticator app (TOTP)"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Coming soon â contact support to enroll early."})]}),e.jsx(W,{variant:"outline",children:"Coming soon"})]})})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(bs,{className:"h-4 w-4 text-gold"})," Sessions & devices"]}),e.jsx(I,{children:"You're currently signed in on this device. Sign out other sessions if anything looks unfamiliar."})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border divide-y",children:e.jsxs("div",{className:"p-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx($e,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:"This device"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last sign-in: ",r?de(new Date(r),"PPp"):"â"]})]})]}),e.jsx(W,{className:"bg-emerald-500/15 text-emerald-700 border-emerald-500/30 hover:bg-emerald-500/15",children:"Active"})]})}),e.jsxs(S,{variant:"outline",onClick:w,disabled:i,children:[i?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"Sign out of all other devices"]})]})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-base",children:"Connected sign-in methods"}),e.jsx(I,{children:"Providers linked to this account."})]}),e.jsx(T,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[d.length===0&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"Email & password only."}),d.map(p=>e.jsx(W,{variant:"outline",className:"capitalize",children:p},p))]})})]})]})},Xs=()=>{const{user:s,isAdmin:t,isCaseManager:a,isBroker:n}=$(),{toast:u}=V(),[h,f]=o.useState(!0),[i,b]=o.useState(!1),[d,l]=o.useState({email_signature:"",default_reply_template:"",dnd_enabled:!1,auto_responder_until:"",out_of_office_message:""}),j=t||a||n;o.useEffect(()=>{s&&(async()=>{const{data:y}=await k.from("profiles").select("preferences").eq("user_id",s.id).maybeSingle(),x=(y==null?void 0:y.preferences)||{};l({email_signature:x.email_signature||"",default_reply_template:x.default_reply_template||"",dnd_enabled:!!x.dnd_enabled,auto_responder_until:x.auto_responder_until||"",out_of_office_message:x.out_of_office_message||""}),f(!1)})()},[s]);const _=async()=>
1{if(!s)return;b(!0);const{data:y}=await k.from("profiles").select("preferences").eq("user_id",s.id).maybeSingle(),x={...(y==null?void 0:y.preferences)||{},...d},{error:D}=await k.from("profiles").update({preferences:x}).eq("user_id",s.id);b(!1),u(D?{title:"Couldn't save",description:D.message,variant:"destructive"}:{title:"Communication preferences saved"})};return h?e.jsx("div",{className:"flex items-center justify-center p-12",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-base",children:"Email signature"}),e.jsx(I,{children:"Appended to outbound messages sent through the platform."})]}),e.jsx(T,{children:e.jsx(te,{rows:4,value:d.email_signature,onChange:y=>l({...d,email_signature:y.target.value}),placeholder:`â ${s==null?void 0:s.email} 2Tariff Refund Agency`})})]}),j&&e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-base",children:"Default reply template"}),e.jsx(I,{children:"Optional canned response staff can insert with one click."})]}),e.jsx(T,{children:e.jsx(te,{rows:5,value:d.default_reply_template,onChange:y=>l({...d,default_reply_template:y.target.value}),placeholder:"Thanks for your message. I'll review your claim and get back to you within 1 business day."})})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-base",children:"Do not disturb"}),e.jsx(I,{children:"Pause non-urgent notifications and show an away message on your threads."})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(M,{children:"Pause notifications"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Urgent alerts (deadlines, security) still come through."})]}),e.jsx(Ke,{checked:d.dnd_enabled,onCheckedChange:y=>l({...d,dnd_enabled:y})})]}),d.dnd_enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(M,{children:"Auto-responder until"}),e.jsx(U,{type:"datetime-local",value:d.auto_responder_until,onChange:y=>l({...d,auto_responder_until:y.target.value})})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Away message"}),e.jsx(te,{rows:3,value:d.out_of_office_message,onChange:y=>l({...d,out_of_office_message:y.target.value}),placeholder:"I'm out of office until Monday. For urgent matters, contact [email protected]."})]})]})]})]}),e.jsxs(S,{onClick:_,disabled:i,className:"bg-primary text-primary-foreground",children:[i?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Save communication preferences"]})]})},et=({isClient:s,isPartner:t,isBroker:a,isFunder:n})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(we,{className:"h-4 w-4 text-gold"})," Payout method"]}),e.jsx(I,{children:"Where we send refunds and commissions."})]}),e.jsxs(T,{className:"space-y-2",children:[s&&e.jsx(G,{to:"/client/payout",children:e.jsxs(S,{size:"sm",variant:"outline",children:["Client payout account ",e.jsx(ee,{className:"h-3.5 w-3.5 ml-1.5"})]})}),t&&e.jsx(G,{to:"/partner/payment-settings",children:e.jsxs(S,{size:"sm",variant:"outline",children:["Partner payout settings ",e.jsx(ee,{className:"h-3.5 w-3.5 ml-1.5"})]})}),a&&e.jsx(G,{to:"/brokers/payment-settings",children:e.jsxs(S,{size:"sm",variant:"outline",children:["Broker payout settings ",e.jsx(ee,{className:"h-3.5 w-3.5 ml-1.5"})]})}),n&&e.jsx(G,{to:"/funding/account",children:e.jsxs(S,{size:"sm",variant:"outline",children:["Funder payout settings ",e.jsx(ee,{className:"h-3.5 w-3.5 ml-1.5"})]})})]})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 text-gold"})," Tax forms"]}),e.jsx(I,{children:"W-9 (US) or W-8 (non-US) required before payout."})]}),e.jsx(T,{children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Tax form status is managed by your account team. Contact support if you need to update an existing form."})})]})]}),st=()=>e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-gold"})," Team members"]}),e.jsx(I,{children:"Invite teammates and set per-section permissions."})]}),e.jsx(T,{children:e.jsx(G,{to:"/partner/team",children:e.jsxs(S,{variant:"outline",size:"sm",children:["Open team management ",e.jsx(ee,{className:"h-3.5 w-3.5 ml-1.5"})]})})})]});function tt(){const{user:s}
2=$(),[t,a]=o.useState([]),[n,u]=o.useState(null),[h,f]=o.useState(!0);return o.useEffect(()=>{s&&k.from("partner_agreements").select("*").eq("user_id",s.id).order("created_at",{ascending:!1}).then(({data:i})=>{a(i||[]),f(!1)})},[s]),h||t.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(E,{children:e.jsxs(T,{className:"p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(We,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"font-display font-bold text-base sm:text-lg text-foreground",children:"My Agreements"})]}),e.jsx("div",{className:"space-y-2",children:t.map(i=>{const b=["signed","countersigned"].includes(i.status);return e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-border bg-background",children:[e.jsx(Ne,{className:"h-5 w-5 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm text-foreground truncate",children:i.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[e.jsxs(W,{variant:b?"default":"secondary",className:b?"bg-success text-success-foreground gap-1 text-xs":"text-xs",children:[b&&e.jsx(vs,{className:"h-3 w-3"}),i.status]}),i.signed_at&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Signed ",de(new Date(i.signed_at),"MMM d, yyyy")]})]})]}),b&&e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsxs(S,{size:"sm",variant:"outline",className:"gap-1.5 text-xs",onClick:()=>u(i),children:[e.jsx(ws,{className:"h-3.5 w-3.5"})," View"]}),e.jsxs(S,{size:"sm",variant:"outline",className:"gap-1.5 text-xs",onClick:()=>Te(i),children:[e.jsx(ce,{className:"h-3.5 w-3.5"})," PDF"]})]})]},i.id)})})]})}),e.jsx(es,{open:!!n,onOpenChange:i=>!i&&u(null),children:e.jsxs(ss,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ts,{children:[e.jsx(as,{children:n==null?void 0:n.title}),e.jsx(ns,{children:"Your signed referral partner agreement"})]}),n&&e.jsx(Rs,{title:n.title,bodyHtml:n.body_html,status:n.status,signedAt:n.signed_at,signatureData:n.signature_data,signerName:n.signer_name,signerEmail:n.signer_email,countersignedAt:n.countersigned_at,onDownloadPdf:()=>Te(n)})]})})]})}const at=({isPartner:s})=>e.jsxs("div",{className:"space-y-4",children:[s&&e.jsx(tt,{}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-base",children:"Files on record"}),e.jsx(I,{children:"W-9, NDAs, and other compliance documents."})]}),e.jsx(T,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"No additional files on record. Contact your account team to upload tax or compliance documents."})})]})]}),nt=()=>{const{toast:s}=V();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2",children:[e.jsx(ce,{className:"h-4 w-4 text-gold"})," Export my data"]}),e.jsx(I,{children:"Receive a copy of your profile, claims, messages, and notifications via email."})]}),e.jsx(T,{children:e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>s({title:"Export requested",description:"We'll email you a download link within 24 hours."}),children:[e.jsx(Ns,{className:"h-3.5 w-3.5 mr-1.5"})," Request data export"]})})]}),e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-base",children:"Privacy preferences"}),e.jsxs(I,{children:["Read our ",e.jsx("a",{className:"underline",href:"/privacy",target:"_blank",rel:"noreferrer",children:"privacy policy"})," and ",e.jsx("a",{className:"underline",href:"/terms",target:"_blank",rel:"noreferrer",children:"terms"}),"."]})]}),e.jsx(T,{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"We only use your data to operate your account, communicate with you about claims, and meet compliance obligations. We never sell your data."})})]})]})},rt={pending:"bg-amber-500/15 text-amber-700 border-amber-500/30",processing:"bg-blue-500/15 text-blue-700 border-blue-500/30",completed:"bg-emerald-500/15 text-emerald-700 border-emerald-500/30",cancelled:"bg-muted text-muted-foreground border-border",failed:"bg-destructive/15 text-destructive border-destructive/30"},it=()=>{const{toast:s}=V(),{user:t}
2=$(),[a,n]=o.useState(!1),[u,h]=o.useState(!1),[f,i]=o.useState([]),[b,d]=o.useState(""),[l,j]=o.useState(""),_=o.useCallback(async()=>{if(!t)return;const{data:r}=await k.from("account_lifecycle_requests").select("*").eq("user_id",t.id).order("created_at",{ascending:!1}).limit(10);i(r||[])},[t]);o.useEffect(()=>{_()},[_]);const y=async()=>{n(!0);try{const{error:r}=await k.auth.signOut({scope:"global"});if(r)throw r;s({title:"Signed out everywhere"})}catch(r){s({title:"Error",description:r.message,variant:"destructive"})}finally{n(!1)}},x=async()=>{if(t){h(!0);try{const{error:r}=await k.from("account_lifecycle_requests").insert({user_id:t.id,request_type:"export",reason:null});if(r)throw r;s({title:"Data export requested",description:"We'll email you a secure download link when it's ready (typically within 24 hours)."}),_()}catch(r){s({title:"Could not submit request",description:r.message,variant:"destructive"})}finally{h(!1)}}},D=async()=>{if(t){h(!0);try{const{error:r}=await k.from("account_lifecycle_requests").insert({user_id:t.id,request_type:"deletion",reason:l.trim()||null});if(r)throw r;s({title:"Account deletion requested",description:"Your account is scheduled for deletion in 14 days. Cancel anytime from this page before then."}),j(""),d(""),_()}catch(r){s({title:"Could not submit request",description:r.message,variant:"destructive"})}finally{h(!1)}}},B=async r=>{try{const{error:A}=await k.from("account_lifecycle_requests").update({status:"cancelled"}).eq("id",r);if(A)throw A;s({title:"Request cancelled"}),_()}catch(A){s({title:"Could not cancel",description:A.message,variant:"destructive"})}},w=f.find(r=>r.request_type==="deletion"&&r.status==="pending");return e.jsxs(E,{className:"border-destructive/40",children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-base flex items-center gap-2 text-destructive",children:[e.jsx(Be,{className:"h-4 w-4"})," Danger zone"]}),e.jsx(I,{children:"Irreversible actions. Please be sure."})]}),e.jsxs(T,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 p-3 rounded-md border",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Sign out everywhere"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Ends every active session on every device."})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:y,disabled:a,children:[a?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Ye,{className:"h-4 w-4 mr-2"}),"Sign out"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 p-3 rounded-md border",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Export my data"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Request a downloadable archive of your profile, claims, and messages."})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:x,disabled:u,children:[e.jsx(ce,{className:"h-4 w-4 mr-2"})," Request export"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 p-3 rounded-md border border-destructive/40 bg-destructive/5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:"Delete my account"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Submits a deletion request with a 14-d
2ay grace period. You can cancel anytime before it processes."})]}),e.jsxs(Ls,{children:[e.jsx(Is,{asChild:!0,children:e.jsxs(S,{variant:"destructive",size:"sm",disabled:!!w||u,children:[e.jsx(je,{className:"h-4 w-4 mr-2"})," ",w?"Deletion pending":"Request deletion"]})}),e.jsxs(Us,{children:[e.jsxs(Fs,{children:[e.jsx(Bs,{children:"Delete your account?"}),e.jsxs(Os,{children:["Your account will be scheduled for permanent deletion in 14 days. Active claims must be closed or transferred before deletion completes. Type ",e.jsx("strong",{children:"DELETE"})," below to confirm."]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(M,{children:"Reason (optional)"}),e.jsx(te,{rows:2,value:l,onChange:r=>j(r.target.value),placeholder:"Help us improveâ¦"})]}),e.jsxs("div",{children:[e.jsx(M,{children:"Type DELETE to confirm"}),e.jsx(U,{value:b,onChange:r=>d(r.target.value)})]})]}),e.jsxs(zs,{children:[e.jsx(Ws,{onClick:()=>{d(""),j("")},children:"Cancel"}),e.jsxs($s,{disabled:b!=="DELETE"||u,onClick:D,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[u?e.jsx(F,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(je,{className:"h-4 w-4 mr-2"}),"Confirm deletion"]})]})]})]})]}),f.length>0&&e.jsxs("div",{className:"rounded-md border",children:[e.jsx("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground border-b",children:"Recent requests"}),e.jsx("div",{className:"divide-y",children:f.map(r=>e.jsxs("div",{className:"p-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium capitalize",children:r.request_type}),e.jsx(W,{variant:"outline",className:rt[r.status]||"",children:r.status})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:["Submitted ",de(new Date(r.created_at),"PP"),r.scheduled_for&&r.status==="pending"&&e.jsxs(e.Fragment,{children:[" · Scheduled for ",de(new Date(r.scheduled_for),"PP")]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r.download_url&&r.status==="completed"&&e.jsx("a",{href:r.download_url,target:"_blank",rel:"noreferrer",children:e.jsxs(S,{variant:"outline",size:"sm",children:[e.jsx(ce,{className:"h-3.5 w-3.5 mr-1.5"})," Download"]})}),r.status==="pending"&&e.jsxs(S,{variant:"ghost",size:"sm",onClick:()=>B(r.id),children:[e.jsx(ks,{className:"h-3.5 w-3.5 mr-1.5"})," Cancel"]})]})]},r.id))})]})]})]})},P={in_app_prefs:!0,email_prefs:!0,sms_prefs:!1,push_prefs:!0},K={in_app_prefs:!0,email_prefs:!0,sms_prefs:!1,push_prefs:!1},H={in_app_prefs:!0,email_prefs:!0,sms_prefs:!1,push_prefs:!1},lt=[{id:"universal",roles:["any"],title:"Account & Security",blurb:"Applies to every account regardless of role.",icon:"shield",categories:[{key:"message.direct",label:"Direct messages & @mentions",description:"Someone messages or @mentions you directly",defaults:P},{key:"system.security",label:"Security events",description:"New sign-in, password change, 2FA enrollment",defaults:{in_app_prefs:!0,email_prefs:!0,sms_prefs:!0,push_prefs:!0},urgent:!0},{key:"system.billing",label:"Billing & invoices",description:"Card expiring, invoice paid, plan changes",defaults:H},{key:"system.product",label:"Product updates",description:"New features, release notes, scheduled maintenance",defaults:{in_app_prefs:!0,email_prefs:!1,sms_prefs:!1,push_prefs:!1}}]},{id:"client",roles:["client"],title:"My Claim",blurb:"Activity on claims that **you** submitted.",icon:"briefcase",categories:[{key:"claim.mine.status",label:"Status changes",description:"When my claim moves to a new stage",defaults:P},{key:"claim.mine.message",label:"New messages on my claim",description:"Replies from your case manager or broker",defaults:P},{key:"claim.mine.doc_request",label:"Document requests",description:"When we need additional documents from you",defaults:{in_app_prefs:!0,email_prefs:!0,sms_prefs:!0,push_prefs:!0},urgent:!0},{key:"claim.mine.doc_received",label:"Document received",description:"A new document was added to your claim",defaults:K},{key:"claim.mine.deadline",label:"Filing & protest deadlines",description:"Reminders before a hard deadline",defaults:{in_app_prefs:!0,email_prefs:!0,sms_prefs:!0,push_prefs:!0},urgent:!0},{key:"claim.mine.agreement_ready",label:"Agreement ready to sign",description:"An agreement is
2waiting on your signature",defaults:P,urgent:!0},{key:"claim.mine.agreement_executed",label:"Agreement countersigned",description:"Both parties have signed the agreement",defaults:H},{key:"claim.mine.payout",label:"Refund disbursed",description:"Funds released to your payout account",defaults:P},{key:"claim.mine.refund_eta",label:"Refund ETA changes",description:"Estimated payout date shifts",defaults:K}]},{id:"affiliate-referrals",roles:["affiliate"],title:"My Referrals",blurb:"Activity on claims your **referrals** brought in.",icon:"users",categories:[{key:"claim.referred.new",label:"New referral signup",description:"Someone signed up through your link",defaults:P},{key:"claim.referred.intake_complete",label:"Referral completed intake",description:"Referral finished the intake form",defaults:K},{key:"claim.referred.status",label:"Referral claim status changes",description:"A referral's claim moves to a new stage",defaults:K},{key:"claim.referred.signed_agreement",label:"Referral signed agreement",description:"A referral countersigned their consulting agreement",defaults:P},{key:"claim.referred.payout",label:"Referral refund disbursed",description:"A refund was paid out on a referral's claim",defaults:P}]},{id:"affiliate-commissions",roles:["affiliate"],title:"Commissions & Payouts",blurb:"Money earned, adjusted, and paid out to you.",icon:"dollar",categories:[{key:"commission.earned",label:"Commission earned",description:"A new commission posted to your ledger",defaults:P},{key:"commission.adjusted",label:"Commission adjusted",description:"A previously posted commission was modified",defaults:H},{key:"commission.paid",label:"Commission paid",description:"A payout was sent to your account",defaults:P},{key:"commission.statement_ready",label:"Monthly statement ready",description:"Your monthly commission statement is available",defaults:H}]},{id:"affiliate-network",roles:["affiliate"],title:"Network & Pool",blurb:"Sub-affiliates, pool allocations, and downline activity.",icon:"users",categories:[{key:"network.subaffiliate_joined",label:"New sub-affiliate joined",description:"Someone joined your network through your link",defaults:P},{key:"network.subaffiliate_first_claim",label:"Sub-affiliate's first claim",description:"A sub-affiliate brought in their first claim",defaults:P},{key:"pool.allocation_changed",label:"Pool allocation changed",description:"Your pool share % was changed by your grantor",defaults:P,urgent:!0},{key:"pool.grant_received",label:"Pool grant received",description:"You were granted a pool share by an upline partner",defaults:P}]},{id:"affiliate-marketing",roles:["affiliate"],title:"Marketing",blurb:"Campaign performance and marketing kit updates.",icon:"megaphone",categories:[{key:"marketing.campaign_summary",label:"Weekly campaign summary",description:"Performance digest for your active campaigns",defaults:H},{key:"marketing.kit_updated",label:"Marketing kit updated",description:"New creatives or copy added to your kit",defaults:K}]},{id:"broker",roles:["broker"],title:"Claims I'm Brokering",blurb:"Claims assigned to you for broker / filing work.",icon:"briefcase",categories:[{key:"claim.broker.assigned",label:"Claim assigned to me",description:"A new claim was routed to you",defaults:P},{key:"claim.broker.unassigned",label:"Claim removed",description:"A claim was reassigned away from you",defaults:H},{key:"claim.broker.message",label:"Messages on broker claims",description:"Client or admin posted on a thread you're on",defaults:P},{key:"claim.broker.bond_required",label:"Customs bond required",description:"A claim needs a bond to proceed",defaults:P,urgent:!0},{key:"claim.broker.form_4811",label:"Form 4811 status",description:"POA / Form 4811 lifecycle events",defaults:K},{key:"broker.payout",label:"Broker payout sent",description:"A payout was disbursed to your broker account",defaults:P},{key:"broker.commission_statement",label:"Commission statement ready",description:"Monthly broker statement available",defaults:H}]},{id:"funder",roles:["funder"],title:"Funding",blurb:"Application and deal activity for the funding desk.",icon:"wallet",categories:[{key:"funding.application.submitted",label:"Funding application submitted",description:"A new funding application landed in queue",defaults:P},{key:"funding.application.decision",label:"Funding decision rendered",description:"Approval / decline / counter on an application",defaults:P},{key:"funding.deal.funded",label:"Deal funded",description:"A deal was wired and is live",defaults:P},{key:"funding.deal.repayment",label:"Deal repayment event",description:"Repayment received or default flag",defaults:H}]},{id:"ops",roles:["admin","case_manager"],title:"Operations",blurb:"System-wide ops, queues, and lead routing.",icon:"wrench",categories:[{key:"ops.new_lead",label:"New lead arrived",description:"Any new lead lands in intake",defaults:K},{key:"ops.high_priority_lead",label:"High-priority lead",description:"Lead score ⥠80 or VIP flag",defaults:P},{key:"ops.unassigned_claim",label:"Unassigned claim ageing",description:"Claim sitting > 24h with no owner",defaults:P,urgent:!0},{key:"ops.stalled_claim",label:"Stalled claim",description:"Claim with no movement > 7 days",defaults:H},{key:"ops.escalation",label:"Escalation",description:"Client or partner explicitly escalated",defaults:P,urgent:!0},{key:"ops.support_ticket",label:"Support ticket",description:"New help-desk ticket assigned to your queue",defaults:P}
2]},{id:"ops-system",roles:["admin"],title:"System Health",blurb:"Compliance alerts, automation failures, security events.",icon:"shield",categories:[{key:"ops.compliance_alert",label:"Compliance alert",description:"Eligibility / AD-CVD / sanction rule fired",defaults:P,urgent:!0},{key:"ops.rpa_failure",label:"RPA / automation failure",description:"Skyvern or scheduled job errored",defaults:P,urgent:!0},{key:"ops.system_health",label:"Infrastructure health",description:"Database, edge function, or storage degradation",defaults:P,urgent:!0},{key:"ops.security_event",label:"Security event",description:"Suspicious sign-in, RLS violation, secret rotation",defaults:P,urgent:!0}]}];function ot(s){return lt.filter(t=>!!(t.roles.includes("any")||t.roles.includes("client")||t.roles.includes("affiliate")&&s.isAffiliate||t.roles.includes("broker")&&s.isBroker||t.roles.includes("funder")&&s.isFunder||t.roles.includes("admin")&&s.isAdmin||t.roles.includes("case_manager")&&s.isCaseManager))}function De(s,t,a){var u;const n=(s==null?void 0:s[t])||{};return a.key in n?!!n[a.key]:((u=a.defaults)==null?void 0:u[t])??!1}const qe=1,Se="__v";function se(s){return s.urgent?!0:s.key==="system.security"||s.key==="system.billing"}function ct(s){if(!s||typeof s!="object"||Array.isArray(s))return{};const t={};for(const[a,n]of Object.entries(s))a!==Se&&typeof n=="boolean"&&(t[a]=n);return t}function dt(s){if(s&&typeof s=="object"&&!Array.isArray(s)){const t=s[Se];if(typeof t=="number")return t}return 0}function ut(s){const t={...s??{}},a=["in_app_prefs","email_prefs","sms_prefs","push_prefs"],n=Math.max(0,...a.map(h=>dt(t[h])));let u=!1;for(const h of a){const i={...ct(t[h]),[Se]:qe};JSON.stringify(i)!==JSON.stringify(t[h])&&(u=!0),t[h]=i}return n!==qe&&(u=!0),{prefs:t,migrated:u}}const mt=["America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Phoenix","America/Anchorage","Pacific/Honolulu","UTC"],ht=({prefs:s,onSave:t})=>e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsxs(L,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(_s,{className:"h-4 w-4 text-gold"})," Quiet hours & digest"]}),e.jsx(I,{className:"text-xs",children:"Silence non-urgent SMS & push during quiet hours. Urgent alerts (deadlines, security) always deliver."})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:"Digest frequency"}),e.jsxs(he,{value:(s==null?void 0:s.digest_frequency)??"instant",onValueChange:a=>t({digest_frequency:a}),children:[e.jsx(xe,{children:e.jsx(pe,{})}),e.jsxs(fe,{children:[e.jsx(Q,{value:"instant",children:"Instant"}),e.jsx(Q,{value:"hourly",children:"Hourly digest"}),e.jsx(Q,{value:"daily",children:"Daily digest"}),e.jsx(Q,{value:"weekly",children:"Weekly digest"}),e.jsx(Q,{value:"off",children:"Off (no emails)"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:"Timezone"}),e.jsxs(he,{value:(s==null?void 0:s.timezone)??"America/New_York",onValueChange:a=>t({timezone:a}),children:[e.jsx(xe,{children:e.jsx(pe,{})}),e.jsx(fe,{children:mt.map(a=>e.jsx(Q,{value:a,children:a},a))})]})]})]}),e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:"Quiet hours start"}),e.jsx(U,{type:"time",defaultValue:(s==null?void 0:s.quiet_hours_start)??"",onBlur:a=>{const n=a.target.value||null;n!==((s==null?void 0:s.quiet_hours_start)??null)&&t({quiet_hours_start:n})}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(M,{className:"text-xs",children:"Quiet hours end"}),e.jsx(U,{type:"time",defaultValue:(s==null?void 0:s.quiet_hours_end)??"",onBlur:a=>{const n=a.target.value||null;n!==((s==null?void 0:s.quiet_hours_end)??null)&&t({quiet_hours_end:n})}})]})]})]})]}),xt="BINZ8tEpcApOD5tvEs8uY0L3OyA2sPE0FZ48Y-uR91FkO-9-eGQrhouBXrldmz2k36o9hjLVpKHMOw8R3M72S94",Qe=xt,J=()=>typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;function pt(s){const t="=".repeat((4-s.length%4)%4),a=(s+t).replace(/-/g,"+").replace(/_/g,"/"),n=atob(a),u=new Uint8Array(n.length);for(let h=0;h<n.length;h++)u[h]=n.charCodeAt(h);return u}async function ft(){if(!J())return null;const s=await navigator.serviceWorker.getRegistration("/push-sw.js");return s||await navigator.serviceWorker.register("/push-sw.js",{scope:"/"})}async function gt(){if(!J())return{ok:!1,reason:"Push not supported in this browser."};
2if(await Notification.requestPermission()!=="granted")return{ok:!1,reason:"Permission denied."};const t=await ft();if(!t)return{ok:!1,reason:"Service worker failed to register."};let a=await t.pushManager.getSubscription();a||(a=await t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:pt(Qe).buffer}));const n=a.toJSON(),{error:u}=await k.rpc("register_push_subscription",{p_subscription:n});return u?{ok:!1,reason:u.message}:{ok:!0}}async function jt(){if(!J())return{ok:!0};const s=await navigator.serviceWorker.getRegistration("/push-sw.js"),t=await(s==null?void 0:s.pushManager.getSubscription());if(t){const a=t.endpoint;await t.unsubscribe().catch(()=>{});const{error:n}=await k.rpc("unregister_push_subscription",{p_endpoint:a});if(n)return{ok:!1,reason:n.message}}return{ok:!0}}async function yt(){if(!J())return null;const s=await navigator.serviceWorker.getRegistration("/push-sw.js");return await(s==null?void 0:s.pushManager.getSubscription())??null}const bt=({prefs:s,onSave:t})=>{const{toast:a}=V(),[n,u]=o.useState(!1),[h,f]=o.useState(!1);o.useEffect(()=>{J()&&(async()=>{const b=await yt();u(!!b&&Notification.permission==="granted")})()},[]);const i=async b=>{f(!0);const d=b?await gt():await jt();d.ok?(u(b),a({title:b?"Push notifications enabled":"Push notifications disabled"})):a({title:b?"Couldn't enable push":"Couldn't disable push",description:d.reason,variant:"destructive"}),f(!1)};return e.jsxs(E,{children:[e.jsxs(R,{children:[e.jsx(L,{className:"text-sm",children:"Channels"}),e.jsx(I,{className:"text-xs",children:"Required to receive notifications on SMS and push."})]}),e.jsxs(T,{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(M,{className:"text-xs flex items-center gap-1.5",children:[e.jsx($e,{className:"h-3.5 w-3.5"})," SMS phone number (E.164)"]}),e.jsx(U,{placeholder:"+15551234567",defaultValue:(s==null?void 0:s.phone_e164)??"",onBlur:b=>{const d=b.target.value.trim();d!==((s==null?void 0:s.phone_e164)??"")&&t({phone_e164:d||null})}})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(M,{className:"text-sm font-medium flex items-center gap-1.5",children:[e.jsx(Ve,{className:"h-4 w-4"})," Browser push"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:J()?n?"Enabled on this device.":"Get desktop alerts even when this tab is closed.":"Your browser doesn't support push notifications."})]}),e.jsx(S,{size:"sm",variant:n?"outline":"default",disabled:h||!J()||!Qe,onClick:()=>i(!n),children:h?e.jsx(F,{className:"h-4 w-4 animate-spin"}):n?e.jsxs(e.Fragment,{children:[e.jsx(le,{className:"h-4 w-4 mr-1"})," Disable"]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"h-4 w-4 mr-1"})," Enable"]})})]})]})]})},z=[{key:"in_app_prefs",label:"In-app",icon:He},{key:"email_prefs",label:"Email",icon:oe},{key:"sms_prefs",label:"SMS",icon:Ge},{key:"push_prefs",label:"Push",icon:Ve}],vt={user:ve,briefcase:Es,users:ke,shield:Ce,dollar:Ts,wallet:we,megaphone:Ue,wrench:Ds,bell:_e},wt=()=>{const{user:s,isAdmin:t,isCaseManager:a,isAffiliate:n,isBroker:u,isFunder:h}=$(),{toast:f}=V(),[i,b]=o.useState(null),[d,l]=o.useState(!0),[j,_]=o.useState(""),y=o.useMemo(()=>ot({isAdmin:t,isCaseManager:a,isAffiliate:n,isBroker:u,isFunder:h}),[t,a,n,u,h]);o.useEffect(()=>{s&&(async()=>{const{data:c}=await k.from("notification_preferences").select("*").eq("user_id",s.id).maybeSingle();let m=c;if(!m){const{data:q}=await k.from("notification_preferences").insert({user_id:s.id}).select("*").single();m=q}const{prefs:v,migrated:g}=ut(m);b(v),g&&s&&await k.from("notification_preferences").update({in_app_prefs:v.in_app_prefs,email_prefs:v.email_prefs,sms_prefs:v.sms_prefs,push_prefs:v.push_prefs}).eq("user_id",s.id),l(!1)})()},[s]);const x=async c=>{if(!s)return;b(v=>({...v,...c}));const{error:m}=await k.from("notification_preferences").update(c).eq("user_id",s.id);m&&f({title:"Couldn't save",description:m.message,variant:"destructive"})},D=(c,m,v)=>{const g=(i==null?void 0:i[c])||{};x({[c]:{...g,[m.key]:v}})},B=()=>{const c={};let m=0;for(const v of z){const q={...(i==null?void 0:i[v.key])||{}};for(const C of y)for(const O of C.categories){if(se(O)){m++;continue}q[O.key]=!1}c[v.key]=q}x(c),f({title:"All notifications muted",description:m>0?"Urgent & security alerts remain on â they can't be bulk-muted.":"You can re-enable any category individually."})},w=()=>{const c={};for(const m of z){const g={...(i==null?void 0:i[m.key])||{}};for(const q of y)for(const C of q.categories)C.defaults&&m.key in C.defaults&&(g[C.key]=!!C.defaults[m.key]);c[m.key]=g}x(c),f({title:"Defaults restored"})},r=(c,m)=>{const v={};let g=0;for(const q of z){const O={...(i==null?void 0:i[q.key])||{}};for(const ae of c.categories){if(!m&&se(ae)){g++;continue}O[ae.key]=m}v[q.key]=O}x(v),f({title:m?`${c.title} enabled`:`${c.title} muted`,description:!m&&g>0?`${c.categories.length-g/z.length} of ${c.categories.length} event types muted â urgent alerts kept on.`:`Applied to all channels for ${c.categories.length} event types.`})},A=(c,m,v)=>{const q={...(i==null?void 0:i[m])||{}};for(const C of c.categories)!v&&se(C)||(q[C.key]=v);x({[m]:q})},p=c=>{const m={};for(const v of z){const q={...(i==null?void 0:i[v.key])||{}};for(const C of c.categories)C.defaults&&v.key in C.defaults&&(q[C.key]=!!C.defaults[v.key]);m[v.key]=q}x(m),f({title:`${c.title} restored`,description:"Defaults reapplied for this section."})},N=(c,m)=>{var q;const g={...(i==null?void 0:i[c])||{}};for(const C of y)for(const O of C.categories)!m&&se(O)||(g[O.key]=m);x({[c]:g}),f({title:`${(q=z.find(C=>C.key===c))==null?void 0:q.label} ${m?"enabled":"muted"} everywhere`,description:m?void 0:"Urgent alerts are still delivered."})},Y=(c,m)=>{let v=0;for(const g of c.categories)De(i,m,g)&&v++;return v===0?"none":v===c.categories.length?"all":"mixed"},Z=c=>{if(!j.trim())return c;const m=j.toLowerCase();return{...c,categories:c.categories.filter(v=>v.label.toLowerCase().includes(m)||v.description.toLowerCase().includes(m))}};
2return d?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs(E,{className:"border-gold/30 bg-gradient-to-br from-gold/5 via-transparent to-transparent",children:[e.jsx(R,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs(L,{className:"text-base flex items-center gap-1.5",children:[e.jsx(_e,{className:"h-4 w-4 text-gold"})," Notification Settings"]}),e.jsx(I,{className:"text-xs mt-1",children:"Tailored to your roles â toggle per channel for each event type."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[(t||a)&&e.jsx(W,{variant:"outline",className:"text-[10px]",children:"Admin"}),n&&e.jsx(W,{variant:"outline",className:"text-[10px]",children:"Partner"}),u&&e.jsx(W,{variant:"outline",className:"text-[10px]",children:"Broker"}),h&&e.jsx(W,{variant:"outline",className:"text-[10px]",children:"Funder"}),e.jsx(W,{variant:"outline",className:"text-[10px]",children:"Client"})]})]})}),e.jsx(T,{className:"pt-0",children:e.jsxs("div",{className:"flex gap-2 flex-wrap items-center",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(Cs,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(U,{className:"pl-7 h-8 text-xs",placeholder:"Search notification typesâ¦",value:j,onChange:c=>_(c.target.value)})]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:w,children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-1"})," Defaults"]}),e.jsxs(Ae,{children:[e.jsx(Pe,{asChild:!0,children:e.jsxs(S,{size:"sm",variant:"outline",children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1"})," Bulk mute"]})}),e.jsxs(Ee,{align:"end",className:"w-60",children:[e.jsx(ue,{className:"text-[11px]",children:"Mute by channel (all sections)"}),z.map(c=>{const m=c.icon;return e.jsxs(X,{onClick:()=>N(c.key,!1),children:[e.jsx(m,{className:"h-3.5 w-3.5 mr-2"})," Mute all ",c.label]},`mute-${c.key}`)}),e.jsx(ne,{}),e.jsx(ue,{className:"text-[11px]",children:"Enable by channel"}),z.map(c=>{const m=c.icon;return e.jsxs(X,{onClick:()=>N(c.key,!0),children:[e.jsx(m,{className:"h-3.5 w-3.5 mr-2"})," Enable all ",c.label]},`on-${c.key}`)}),e.jsx(ne,{}),e.jsxs(X,{onClick:B,className:"text-destructive focus:text-destructive",children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-2"})," Mute EVERYTHING"]})]})]})]})})]}),y.map(c=>{const m=Z(c);if(!m.categories.length)return null;const v=vt[m.icon];return e.jsxs(E,{className:"overflow-hidden",children:[e.jsx(R,{className:"pb-3 bg-muted/30 border-b",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-md bg-gold/10 border border-gold/30 flex items-center justify-center shrink-0",children:e.jsx(v,{className:"h-4 w-4 text-gold"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(L,{className:"text-sm",children:m.title}),e.jsx(I,{className:"text-xs mt-0.5",children:m.blurb})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs(S,{size:"sm",variant:"ghost",className:"h-7 px-2 text-[11px]",onClick:()=>r(m,!0),title:"Enable all events in this section",children:[e.jsx(Ss,{className:"h-3.5 w-3.5 mr-1"})," All on"]}),e.jsxs(S,{size:"sm",variant:"ghost",className:"h-7 px-2 text-[11px]",onClick:()=>r(m,!1),title:"Mute all events in this section",children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1"})," Mute"]}),e.jsxs(Ae,{children:[e.jsx(Pe,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Section actions",children:e.jsx(As,{className:"h-3.5 w-3.5"})})}),e.jsxs(Ee,{align:"end",className:"w-56",children:[e.jsxs(ue,{className:"text-[11px]",children:[m.title," â per channel"]}),z.map(g=>{const q=g.icon,C=Y(c,g.key);return e.jsxs(X,{onClick:()=>A(c,g.key,!1),children:[e.jsx(q,{className:"h-3.5 w-3.5 mr-2"})," Mute ",g.label,e.jsx("span",{className:"ml-auto text-[10px] text-muted-foreground capitalize",children:C})]},`g-mute-${g.key}`)}),e.jsx(ne,{}),z.map(g=>{const q=g.icon;return e.jsxs(X,{onClick:()=>A(c,g.key,!0),children:[e.jsx(q,{className:"h-3.5 w-3.5 mr-2"})," Enable ",g.label]},`g-on-${g.key}`)}),e.jsx(ne,{}),e.jsxs(X,{onClick:()=>p(c),children:[e.jsx(ge,{className:"h-3.5 w-3.5 mr-2"})," Restore defaults"]})]})]})]})]})}),e.jsx(T,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-background",children:[e.jsx("th",{className:"text-left font-medium text-[11px] uppercase tracking-wide text-muted-foreground py-2 pl-4 pr-2 w-full",children:"Event"}),z.map(g=>{const q=g.icon,C=Y(c,g.key),O=C==="all";return e.jsx("th",{className:"text-center font-medium text-[11px] text-muted-foreground py-2 px-2 w-20",children:e.jsxs("button",{type:"button",onClick:()=>A(c,g.key,!O),className:"flex flex-col items-center gap-0.5 mx-auto hover:text-foreground transition-colors",title:O?`Mute ${g.label} for this section`:`Enable ${g.label} for this section`,children:[e.jsx(q,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:g.label}),e.jsx("span",{className:`text-[9px] ${C==="all"?"text-emerald-600":C==="none"?"text-muted-foreground
2/60":"text-amber-600"}`,children:C==="all"?"all on":C==="none"?"muted":"mixed"})]})},g.key)})]})}),e.jsx("tbody",{children:m.categories.map((g,q)=>e.jsxs("tr",{className:`border-b last:border-0 ${q%2===1?"bg-muted/10":""}`,children:[e.jsxs("td",{className:"py-2.5 pl-4 pr-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("div",{className:"font-medium text-sm",children:g.label}),g.urgent&&e.jsxs(W,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 border-destructive/50 text-destructive",children:[e.jsx(Ps,{className:"h-2.5 w-2.5 mr-0.5"})," URGENT"]}),se(g)&&e.jsxs(W,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 border-amber-500/50 text-amber-700 dark:text-amber-400",title:"Excluded from bulk-mute. Can still be toggled individually.",children:[e.jsx(Ce,{className:"h-2.5 w-2.5 mr-0.5"})," BULK-MUTE PROTECTED"]})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:g.description})]}),z.map(C=>{const O=De(i,C.key,g);return e.jsx("td",{className:"text-center py-2.5 px-2",children:e.jsx(Ke,{checked:O,onCheckedChange:ae=>D(C.key,g,!!ae)})},C.key)})]},g.key))})]})})})]},m.id)}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-4",children:[e.jsx(ht,{prefs:i,onSave:x}),e.jsx(bt,{prefs:i,onSave:x})]})]})},Me=()=>{const{isAdmin:s,isAffiliate:t,isAffiliateStaff:a,isBroker:n,isFunder:u,isCaseManager:h}=$(),f=ye(),[i,b]=rs(),d=t||a||f.pathname.startsWith("/partner"),l=n||f.pathname.startsWith("/brokers"),j=u||f.pathname.startsWith("/funding"),_=f.pathname.startsWith("/client"),y=t&&!a,D=o.useMemo(()=>[{value:"profile",label:"Profile",icon:ve,show:!0,node:e.jsx(Js,{isPartner:d})},{value:"security",label:"Security",icon:Ce,show:!0,node:e.jsx(Zs,{})},{value:"notifications",label:"Notifications",icon:_e,show:!0,node:e.jsx(wt,{})},{value:"communication",label:"Communication",icon:Ge,show:!0,node:e.jsx(Xs,{})},{value:"payouts",label:"Payouts",icon:we,show:_||d||l||j,node:e.jsx(et,{isClient:_,isPartner:d,isBroker:l,isFunder:j})},{value:"team",label:"Team",icon:ke,show:y,node:e.jsx(st,{})},{value:"documents",label:"Documents",icon:Ne,show:!0,node:e.jsx(at,{isPartner:d})},{value:"privacy",label:"Data & Privacy",icon:ze,show:!0,node:e.jsx(nt,{})},{value:"danger",label:"Danger Zone",icon:je,show:!0,node:e.jsx(it,{})}],[d,l,j,_,y]).filter(r=>r.show),B=i.get("tab")&&D.find(r=>r.value===i.get("tab"))?i.get("tab"):"profile",w=r=>{b(A=>{const p=new URLSearchParams(A);return p.set("tab",r),p},{replace:!0})};return e.jsxs("div",{className:"w-full max-w-6xl mx-auto space-y-5 min-w-0",children:[e.jsxs("div",{className:"px-1",children:[e.jsx("h1",{className:"font-display text-xl sm:text-2xl md:text-3xl text-foreground",children:"My Account"}),e.jsx("p",{className:"text-xs sm:text-sm text-muted-foreground mt-1",children:"Manage your profile, security, notifications, and integrations."})]}),e.jsxs(is,{value:B,onValueChange:w,className:"w-full",children:[e.jsx("div",{className:"lg:hidden mb-3",children:e.jsxs(he,{value:B,onValueChange:w,children:[e.jsx(xe,{className:"w-full h-11",children:e.jsx(pe,{})}),e.jsx(fe,{className:"bg-popover z-50",children:D.map(r=>{const A=r.icon;return e.jsx(Q,{value:r.value,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-3.5 w-3.5"}),r.label]})},r.value)})})]})}),e.jsxs("div",{className:"lg:grid lg:grid-cols-[220px_1fr] lg:gap-6",children:[e.jsx(E,{className:"hidden lg:block lg:sticky lg:top-4 self-start",children:e.jsx(T,{className:"p-2",children:e.jsx(ls,{className:"flex flex-col h-auto w-full bg-transparent gap-0.5",children:D.map(r=>{const A=r.icon;return e.jsxs(os,{value:r.value,className:"justify-start gap-2 w-full data-[state=active]:bg-gold/10 data-[state=active]:text-foreground data-[state=active]:shadow-none rounded-md whitespace-nowrap",children:[e.jsx(A,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-sm",children:r.label})]},r.value)})})})}),e.jsx("div",{className:"min-w-0",children:D.map(r=>e.jsx(cs,{value:r.value,className:"mt-0 focus-visible:outline-none",children:r.node},r.value))})]})]})]})},ta=()=>{const{user:s,loading:t}=$(),a=ye(),n=a.pathname.startsWith("/partner")||a.pathname.startsWith("/command")||a.pathname.startsWith("/client")||a.pathname.startsWith("/brokers")||a.pathname.startsWith("/funding");return t?e.jsx("div",{className:`${n?"h-64":"min-h-screen"} flex items-center justify-center bg-background`,children:e.jsx(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):s?n?e.jsx(Me,{}):e.jsx("div",{className:"min-h-screen bg-background py-10 px-4",children:e.jsxs("div",{className:"max-w-6xl mx-auto",children:[e.jsx("div",{className:"mb-6",children:e.jsxs(G,{to:"/",className:"font-display font-semibold text-xl text-foreground",children:["Tariff Refund ",e.jsx("span",{className:"text-gold",children:"Agency"})]})}),e.jsx(Me,{}),e.jsx("div",{className:"text-center mt-8",children:e.jsx(G,{to:"/",className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"â Back to Home"})})]})}):e.jsx("div",{className:`${n?"":"min-h-screen"} flex items-center justify-center bg-background px-4`,children:e.jsx(E,{className:"w-full max-w-md text-center",children:e.jsxs(T,{className:"p-8",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"You need to be signed in to view your account."}),e.jsx(G,{to:"/login",children:e.jsx(S,{children:"Sign In"})})]})})})};export{ta as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.