PageSourceSearch

https://switchit.ai/assets/Settings-Bv_tE9Sw.js

js switchit.ai collected 2026-10-05 15:18:50 UTC 112,221 bytes, 46 lines download raw bytes

1import{c as le,d as V,r as o,j as e,k as F,B as S,K as U,e as Ye,a2 as Fe,n as b,s as E,m as Ve,u as _s,a5 as Us,D as Ss,x as Cs,y as ks,z as Ds,E as Es,F as O,W as Ze,Y as Je,_ as Xe,$ as es,a0 as Me,L as $,i as Se,w as _e,aa as Ce,H as Ps,ab as Ks,ac as Qs,I as T,a1 as He,f as Ue,X as ae,g as Y,ad as Ws,ae as Oe,af as Ys,ag as ze,ah as Vs,ai as Zs,aj as Js,ak as Xs,al as Ke,v as Is,am as As,an as Ls,ao as et,ap as ss,aq as st,ar as tt,S as Ms,p as at,a7 as rt,Z as Te,as as it}from"./index-BtZ4WYW8.js";import{S as re}from"./switch-C5id4A0c.js";import{W as ce}from"./webauthn-BE8CYhlD.js";import{S as nt}from"./smartphone-JE8VX3I6.js";import{F as Qe}from"./fingerprint-BP39fIob.js";import{S as oe}from"./share-2-CXfromN_.js";import{U as je}from"./users-QTL4WKmc.js";import{T as ot}from"./trending-up-DB2u_fiN.js";import{D as lt}from"./dollar-sign-BIQ5DaDT.js";import{C as We}from"./copy-DKI279qg.js";import{A as Fs,a as qs,b as Rs}from"./avatar-C8qd0ikO.js";import{A as de,a as we,b as ue,c as me,d as he,e as xe,f as pe,g as fe,h as ge}from"./alert-dialog-fHJWzJD1.js";import{D as ct,a as dt,b as ut,c as De}from"./dropdown-menu-BAWkjqiU.js";import{u as te}from"./useMutation-D_GwL3Bp.js";import{u as mt}from"./useHouseholds-DwqbYWHv.js";import{C as ht}from"./crown-l9ZmUP7h.js";import{S as xt}from"./square-pen-LAnaCE2n.js";import{L as Os}from"./log-out-jjSYZTph.js";import{R as ts}from"./refresh-cw-BtHdqdm7.js";import{S as as}from"./separator-PU6u6zX6.js";import{u as zs}from"./useGmailData-Clb_ahzy.js";import{u as pt}from"./useGmailEligible-CAb_f3oc.js";import{u as ft}from"./useGmailScanState-IsG56WDx.js";import{i as gt}from"./gmail-oauth-cVWydm0D.js";import{T as rs}from"./triangle-alert-DerLXNl5.js";import{C as jt}from"./circle-check-Bb5yaGRV.js";import{L as Ts}from"./link-CvwZw3ru.js";import{G as Ne}from"./globe-DZWXRdmA.js";import{S as is}from"./star-cvy61TyP.js";import{B as $s}from"./bell-BFmB1Fhn.js";import{E as vt}from"./external-link-T-x_aCH0.js";import{K as Gs}from"./key-DZb5Wc6f.js";import{A as yt}from"./address-autocomplete-WLhXrKAq.js";import{T as bt}from"./trash-2-Xknzqktg.js";import{H as wt}from"./heart-WIobADv2.js";import{U as Ae}from"./user-C-2Lhzvj.js";import{P as Nt}from"./pen-B9zzbOnl.js";import{M as ns}from"./map-pin-Dij5Py1A.js";import{T as _t,a as St,b as os,c as ls}from"./tabs-B4kx8Rma.js";import{a as Ct}from"./useServiceRequirements-nQgiRf8T.js";import{P as kt}from"./phone-chWn9gh2.js";import{W as Dt}from"./wifi-C9gTB2pT.js";import{S as Bs}from"./save-BNp8Ouip.js";import{u as Et,S as Ee,a as H}from"./useMediaQuery-BeDno4bX.js";import{S as Pt}from"./sun-DQlYdwHI.js";import{M as Le}from"./moon-cwdHDmAD.js";import{L as It}from"./laptop-C0z78MGY.js";import{A as Pe}from"./arrow-left-FSXJEvUo.js";import{B as cs}from"./brain-G1gNYbOX.js";import{S as ds}from"./sliders-horizontal-lkp2Ef5c.js";import{C as $e}from"./circle-help-B_tSgnwY.js";import"./index-DSxIG765.js";import"./circle-B-ddhASS.js";import"./edgeErrors-DVt52H5l.js";import"./profileHelper-DrO6EX-5.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const At=le("Camera",[["path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z",key:"1tc9qg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Lt=le("Cat",[["path",{d:"M12 5c.67 0 1.35.09 2 .26 1.78-2 5.03-2.84 6.42-2.26 1.4.58-.42 7-.42 7 .57 1.07 1 2.24 1 3.44C21 17.9 16.97 21 12 21s-9-3-9-7.56c0-1.25.5-2.4 1-3.44 0 0-1.89-6.42-.5-7 1.39-.58 4.72.23 6.5 2.23A9.04 9.04 0 0 1 12 5Z",key:"x6xyqk"}],["path",{d:"M8 14v.5",key:"1nzgdb"}],["path",{d:"M16 14v.5",key:"1lajdz"}],["path",{d:"M11.25 16.25h1.5L12 17l-.75-.75Z",key:"12kq1m"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Mt=le("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Ft=le("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}
21]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const qt=le("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
27 * @license lucide-react v0.462.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const Rt=le("Stethoscope",[["path",{d:"M11 2v2",key:"1539x4"}],["path",{d:"M5 2v2",key:"1yf1q8"}],["path",{d:"M5 3H4a2 2 0 0 0-2 2v4a6 6 0 0 0 12 0V5a2 2 0 0 0-2-2h-1",key:"rb5t3r"}],["path",{d:"M8 15a6 6 0 0 0 12 0v-3",key:"x18d4x"}],["circle",{cx:"20",cy:"10",r:"2",key:"ts1r5v"}]]);/**
32 * @license lucide-react v0.462.0 - ISC
33 *
34 * This source code is licensed under the ISC license.
35 * See the LICENSE file in the root directory of this source tree.
36 */const us=le("Unlink",[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]);function ms({isDesktopPanel:t=!1}){const{user:r}
36=V(),[a,x]=o.useState(!1),[s,l]=o.useState({hasFaceID:!1,hasFingerprint:!1,hasWindowsHello:!1}),[c,u]=o.useState([]),[h,p]=o.useState(!1);o.useEffect(()=>{(async()=>{const _=ce.isSupported();if(x(_),_){const C=await ce.getDeviceCapabilities();l(C)}})()},[]),o.useEffect(()=>{(async()=>{if(r!=null&&r.id){const _=await ce.getUserCredentials(r.id);u(_)}})()},[r==null?void 0:r.id]);const f=async()=>{if(r!=null&&r.id){p(!0);try{const i=await ce.registerPasskey(r.id);if(i.success){U({title:"Biometric authentication enabled",description:"You can now sign in with your biometric data"});const _=await ce.getUserCredentials(r.id);u(_)}else U({title:"Failed to enable biometric authentication",description:i.error,variant:"destructive"})}catch{U({title:"Error",description:"Failed to register biometric authentication",variant:"destructive"})}finally{p(!1)}}},j=async i=>{const _=await ce.deleteCredential(i);_.success?(U({title:"Biometric credential removed",description:"You'll need to use your email and password to sign in"}),u(C=>C.filter(P=>P.credential_id!==i))):U({title:"Failed to remove credential",description:_.error,variant:"destructive"})},y=()=>s.hasFaceID?"Face ID":s.hasFingerprint?"Fingerprint":s.hasWindowsHello?"Windows Hello":"Biometric Authentication",N=()=>s.hasFaceID?e.jsx(nt,{className:"h-5 w-5"}):s.hasFingerprint?e.jsx(Qe,{className:"h-5 w-5"}):s.hasWindowsHello?e.jsx(qt,{className:"h-5 w-5"}):e.jsx(Qe,{className:"h-5 w-5"});return a?e.jsx(F,{className:"card-tile-gradient rounded-2xl",children:e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between min-h-[44px]",children:[e.jsxs("div",{className:"flex items-center space-x-3 flex-1",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:N()}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base",children:y()}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c.length>0?"Enabled - Sign in faster with biometrics":"Sign in faster with your biometrics"})]})]}),e.jsx(re,{checked:c.length>0,onCheckedChange:i=>{i&&c.length===0?f():!i&&c.length>0&&j(c[0].credential_id)},disabled:h})]}),c.length===0&&e.jsx("div",{className:"pl-8 pt-4",children:e.jsx(S,{variant:"ghost",size:"sm",onClick:f,disabled:h,className:"text-sm",children:h?"Setting up...":`Set up ${y()}`})})]})}):null}function hs(){const{user:t}=V(),[r,a]=o.useState(!1),{data:x,isLoading:s}=Ye({queryKey:["referral-influencer-stats",t==null?void 0:t.id],queryFn:async()=>{if(!t)return null;const{data:f}=await E.from("referral_influencers").select("id, name").eq("user_id",t.id).eq("is_active",!0).maybeSingle();if(!f)return null;const{data:j}=await E.from("referral_links").select("id, code").eq("influencer_id",f.id).eq("is_active",!0).limit(5),{data:y}=await E.from("v_influencer_stats").select("total_clicks, total_installs, total_switches, total_earnings").eq("influencer_id",f.id).maybeSingle();return{influencer:f,links:j||[],stats:y}},enabled:!!t}),l=async f=>{const j=`https://switchit.dk/r/${f}`;await navigator.clipboard.writeText(j),a(!0),b.success("Link copied!"),setTimeout(()=>a(!1),2e3)},c=async f=>{const j=`https://switchit.dk/r/${f}`;if(navigator.share)try{await navigator.share({title:"SwitchIt - Save on your services",text:"I use SwitchIt to save on my household services. Try it!",url:j})}catch{}else l(f)};if(s)return null;if(!x)return e.jsxs(F,{className:"card-tile-gradient p-4 rounded-2xl space-y-3",children:[e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(oe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:"Become a SwitchIt Ambassador"}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:"Earn rewards by referring friends & family"})]})]}),e.jsxs(S,{variant:"default",size:"sm",className:"w-full gap-2",onClick:()=>{const f=encodeURIComponent((t==null?void 0:t.email)||"");window.location.href=`mailto:[email protected]?subject=Ambassad
36or%20Application&body=I'd%20like%20to%20become%20a%20SwitchIt%20Ambassador.%20My%20email%20is%20${f}`},children:[e.jsx(oe,{className:"h-4 w-4"}),"Apply Now"]})]});const{links:u,stats:h}=x,p=u[0];return e.jsxs(F,{className:"card-tile-gradient p-4 rounded-2xl space-y-4",children:[e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(oe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:"Your Referral Links"}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:"Share and earn rewards"})]})]}),h&&e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"text-center p-2 rounded-xl bg-foreground/5",children:[e.jsx(je,{className:"h-4 w-4 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:h.total_installs||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Signups"})]}),e.jsxs("div",{className:"text-center p-2 rounded-xl bg-foreground
36/5",children:[e.jsx(ot,{className:"h-4 w-4 mx-auto mb-1 text-primary"}),e.jsx("p",{className:"text-lg font-bold text-foreground",children:h.total_switches||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Switches"})]}),e.jsxs("div",{className:"text-center p-2 rounded-xl bg-foreground/5",children:[e.jsx(lt,{className:"h-4 w-4 mx-auto mb-1 text-primary"}),e.jsxs("p",{className:"text-lg font-bold text-foreground",children:[h.total_earnings||0," kr"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Earned"})]})]}),p&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",className:"flex-1 gap-2",onClick:()=>l(p.code),children:[r?e.jsx(Fe,{className:"h-4 w-4"}):e.jsx(We,{className:"h-4 w-4"}),r?"Copied!":"Copy Link"]}),e.jsxs(S,{variant:"default",size:"sm",className:"flex-1 gap-2",onClick:()=>c(p.code),children:[e.jsx(oe,{className:"h-4 w-4"}),"Share"]})]})]})}const Ot=t=>{const{user:r}=V(),a=Ve(),x=_s(),{data:s,isLoading:l}=Ye({queryKey:["household-members-full",t],queryFn:async()=>{if(!t)return[];const{data:m,error:k}=await E.from("view_household_members_full").select("*").eq("household_id",t).order("status",{ascending:!0}).order("joined_at",{ascending:!1,nullsFirst:!1});if(k)throw k;return m||[]},enabled:!!t}),c=(s==null?void 0:s.filter(m=>m.status==="active"))||[],u=(s==null?void 0:s.filter(m=>m.status==="pending"))||[],h=(s==null?void 0:s.filter(m=>m.status==="expired"))||[],p=(s==null?void 0:s.filter(m=>m.status==="cancelled"))||[],f=c.find(m=>m.user_id===(r==null?void 0:r.id)),j=(f==null?void 0:f.role)==="owner",y=f==null?void 0:f.permissions,N=j||(y==null?void 0:y.invite_members)===!0,i=te({mutationFn:async m=>{if(!t)throw new Error("Household ID is required");const{data:{session:k}}=await E.auth.getSession();if(!(k!=null&&k.access_token))throw new Error("Not authenticated");const v=await fetch(`${Us}/functions/v1/send-household-invite`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${k.access_token}`},body:JSON.stringify({household_id:t,invitee_email:m.toLowerCase().trim()})});let L;try{L=await v.json()}catch{throw new Error(`Request failed with status ${v.status}`)}if(!v.ok||!(L!=null&&L.success)){const X=typeof(L==null?void 0:L.error)=="object"&&(L==null?void 0:L.error)!==null?L.error.message:(L==null?void 0:L.error)||"Failed to send invitation";throw new Error(X)}return L},onSuccess:m=>{a.invalidateQueries({queryKey:["household-members-full",t]}),b.success("Invitation sent!",{description:`Invite link created for ${m.household_name}`,action:{label:"Copy Link",onClick:()=>{navigator.clipboard.writeText(m.invite_url),b.success("Link copied to clipboard")}}})},onError:m=>{b.error("Failed to send invitation",{description:m.message})}}),_=te({mutationFn:async m=>{const{error:k}=await E.from("household_invitations").update({status:"cancelled"}).eq("id",m);if(k)throw k},onSuccess:()=>{a.invalidateQueries({queryKey:["household-members-full",t]}),b.success("Invitation cancelled")},onError:m=>{b.error("Failed to cancel invitation",{description:m.message})}}),C=te({mutationFn:async m=>{const{data:k,error:v}=await E.functions.invoke("resend-household-invite",{body:{invitation_id:m}});if(v)throw v;if(!k.success){if(k.error==="RESEND_COOLDOWN"){const L=new Error(k.message||`Please wait ${k.retry_after_seconds}s`);throw L.code="RESEND_COOLDOWN",L.retryAfterSeconds=k.retry_after_seconds,L}throw new Error(k.error||"Failed to resend invitation")}return k},onSuccess:m=>{b.success("Invitation resent!",{description:m.email_sent?"Email sent successfully":void 0,action:m.invite_url?{label:"Copy Link",onClick:()=>{navigator.clipboard.writeText(m.invite_url),b.success("Link copied to clipboard")}}:void 0})},onError:m=>{m.code==="RESEND_COOLDOWN"?b.info(`Please wait ${m.retryAfterSeconds}s before resending`):b.error("Failed to resend invitation",{description:m.message})}}),P=te({mutationFn:async({memberId:m,memberUserId:k})=>{if(!t)throw new Error("Household ID is required");const{data:v,error:L}=await E.rpc("remove_member_and_detach",{p_household_id:t,p_member_user_id:k});if(L)throw L;return{success:(v==null?void 0:v.success)??!0,detached_services:(v==null?void 0:v.detached_services)??0,detached_documents:(v==null?void 0:v.detached_documents)??0}},onSuccess:m=>{a.invalidateQueries({queryKey:["household-members-full",t]}),a.invalidateQueries({queryKey:["household-services"]});const k=m.detached_services>0||m.detached_documents>0?`Member removed. ${m.detached_services} service(s) and ${m.detached_documents} document(s) now belong to them personally.`:"Member removed from household";b.success(k)},onError:m=>{b.error("Failed to remove member",{description:m.message})}}),q=te({mutationFn:async()=>
36{if(!t)throw new Error("Household ID is required");const{data:m,error:k}=await E.rpc("leave_household_and_detach",{p_household_id:t});if(k)throw k;return{success:(m==null?void 0:m.success)??!0,detached_services:(m==null?void 0:m.detached_services)??0,detached_documents:(m==null?void 0:m.detached_documents)??0}},onSuccess:m=>{a.invalidateQueries({queryKey:["household-members-full",t]}),a.invalidateQueries({queryKey:["households"]}),a.invalidateQueries({queryKey:["household-services"]}),b.success("You have left the household",{description:m.detached_services>0?`${m.detached_services} service(s) now belong to you personally.`:void 0}),x("/app/home")},onError:m=>{b.error("Failed to leave household",{description:m.message})}}),I=async m=>{if(!t)return null;const{data:k,error:v}=await E.rpc("get_detach_impact",{p_household_id:t,p_member_user_id:m});return v?(console.error("Failed to get detach impact:",v),null):k},g=te({mutationFn:async m=>{if(!t)throw new Error("Household ID is required");const{data:k,error:v}=await E.rpc("transfer_household_ownership",{p_household_id:t,p_new_owner_id:m});if(v)throw v;return k},onSuccess:()=>{a.invalidateQueries({queryKey:["household-members-full",t]}),b.success("Ownership transferred successfully")},onError:m=>{b.error("Failed to transfer ownership",{description:m.message})}}),w=te({mutationFn:async({memberId:m,role:k,permissions:v})=>{const{error:L}=await E.from("household_members").update({role:k,permissions:v}).eq("id",m);if(L)throw L},onSuccess:()=>{a.invalidateQueries({queryKey:["household-members-full",t]}),b.success("Member updated successfully")},onError:m=>{b.error("Failed to update member",{description:m.message})}}),M=te({mutationFn:async()=>{if(!t)throw new Error("Household ID is required");const{data:m,error:k}=await E.rpc("delete_household",{p_household_id:t});if(k)throw k;const v=m;if(v&&"success"in v&&v.success===!1)throw new Error(v.error||"Failed to delete household");return{success:(v==null?void 0:v.success)??!0,services_archived:(v==null?void 0:v.services_archived)??0,documents_archived:(v==null?void 0:v.documents_archived)??0}},onSuccess:m=>{a.invalidateQueries({queryKey:["households"]}),a.invalidateQueries({queryKey:["household-services"]}),b.success("Household deleted",{description:`${m.services_archived} services and ${m.documents_archived} documents archived.`}),x("/app/home")},onError:m=>{b.error("Failed to delete household",{description:m.message})}});return{allMembers:s||[],members:c,pendingInvites:u,expiredInvites:h,cancelledInvites:p,isLoading:l,isOwner:j,canInvite:N,currentUserMembership:f,sendInvite:i.mutate,cancelInvite:_.mutate,resendInvite:C.mutate,removeMember:P.mutate,leaveHousehold:q.mutate,transferOwnership:g.mutate,updateMember:w.mutate,deleteHousehold:M.mutate,getDetachImpact:I,isSendingInvite:i.isPending,isResendingInvite:C.isPending,isUpdatingMember:w.isPending,isRemovingMember:P.isPending,isLeavingHousehold:q.isPending,isTransferringOwnership:g.isPending,isDeletingHousehold:M.isPending}},zt=({member:t,open:r,onOpenChange:a,onUpdate:x,isUpdating:s})=>{var y,N,i,_;const[l,c]=o.useState((t==null?void 0:t.role)||"member"),[u,h]=o.useState(((y=t==null?void 0:t.permissions)==null?void 0:y.invite_members)||!1),[p,f]=o.useState(((N=t==null?void 0:t.permissions)==null?void 0:N.manage_services)||!1);o.useEffect(()=>{var C,P;t&&(c(t.role),h(((C=t.permissions)==null?void 0:C.invite_members)||!1),f(((P=t.permissions)==null?void 0:P.manage_services)||!1))},[t]);const j=()=>{t&&x({memberId:t.id,role:l,permissions:{invite_members:u,manage_services:p}})};return t?e.jsx(Ss,{open:r,onOpenChange:a,children:e.jsxs(Cs,{className:"card-solid no-hover",children:[e.jsxs(ks,{children:[e.jsx(Ds,{children:"Edit Member"}),e.jsxs(Es,{children:["Update role and permissions for ",(i=t.profile)==null?void 0:i.first_name," ",(_=t.profile)==null?void 0:_.last_name]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"role",children:"Role"}),e.jsxs(Ze,{value:l,onValueChange:c,children:[e.jsx(Je,{id:"role",className:"glass-card",children:e.jsx(Xe,{placeholder:"Select role"})}),e.jsxs(es,{children:[e.jsx(Me,{value:"owner",children:"Owner"}),e.jsx(Me,{value:"member",children:"Member"})]})]})]}),e.jsxs("div",{className:"space-y-3 border-t border-white/10 pt-4",children:[e.jsx(O,{children:"Permissions"}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-white/5 border border-white/10",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Invite Members"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Allow sending household invitations"})]}),e.jsx(re,{checked:u,onCheckedChange:h})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-white/5 border border-white/10",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Manage Services"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Allow adding/editing household services"})]}),e.jsx(re,{checked:p,onCheckedChange:f})]})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(S,{variant:"outline",onClick:()=>a(!1),disabled:s,className:"flex-1",children:"Cancel"}),e.jsx(S,{onClick:j,disabled:s,className:"flex-1",children:s?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"h-4 w-4 animate-spin mr-2"}
36),"Updating..."]}):"Update Member"})]})]})]})}):null},xs=({isDesktopPanel:t=!1})=>{const{t:r}=Se("settings"),{households:a,isLoading:x,error:s}=mt(),[l,c]=o.useState(null),[u,h]=o.useState(""),[p,f]=o.useState(!1),[j,y]=o.useState(!1),[N,i]=o.useState(null),[_,C]=o.useState(!1),[P,q]=o.useState(null),{members:I,pendingInvites:g,isLoading:w,isOwner:M,canInvite:m,currentUserMembership:k,sendInvite:v,cancelInvite:L,resendInvite:X,removeMember:R,leaveHousehold:ve,transferOwnership:Q,updateMember:ke,isSendingInvite:ye,isResendingInvite:n,isUpdatingMember:A,isRemovingMember:G,isLeavingHousehold:D,isTransferringOwnership:ee}=Ot(l||void 0),z=d=>`${window.location.origin}/app/household/accept?token=${d}`,Z=async d=>{try{const J=z(d);await navigator.clipboard.writeText(J),b.success("Link copied to clipboard")}catch{b.error("Failed to copy link")}},se=d=>{if(!d)return"";const J=new Date,ne=new Date(d).getTime()-J.getTime(),Re=Math.ceil(ne/(1e3*60*60*24));return Re<=0?"Expires today":Re===1?"Expires tomorrow":`Expires in ${Re} days`},ie=async d=>{if(!d.token)return;const J=z(d.token),be=(B==null?void 0:B.name)||"our household";if(navigator.share)try{await navigator.share({title:"Join my household on SwitchIt",text:`You're invited to join ${be} on SwitchIt!`,url:J})}catch(ne){ne.name!=="AbortError"&&console.error("Share failed:",ne)}else Z(d.token)};o.useEffect(()=>{!l&&a.length>0&&!x&&c(a[0].id)},[l,a,x]),o.useEffect(()=>{},[a,x,l]);const W=()=>{u.trim()&&(v(u),h(""),f(!1))},B=a.find(d=>d.id===l),qe=d=>d.first_name||d.last_name?`${d.first_name||""} ${d.last_name||""}`.trim():d.email,Hs=d=>{var J,be,ne;return d.first_name?`${d.first_name[0]}${((J=d.last_name)==null?void 0:J[0])||""}`:((ne=(be=d.email)==null?void 0:be[0])==null?void 0:ne.toUpperCase())||"?"};return x?e.jsx(F,{className:"card-tile-gradient rounded-2xl",children:e.jsxs(_e,{className:"p-4 flex items-center gap-3",children:[e.jsx($,{className:"h-5 w-5 animate-spin text-primary"}),e.jsx("span",{children:r("household.loading")})]})}):s?e.jsx(F,{className:"card-tile-gradient rounded-2xl",children:e.jsxs(_e,{className:"p-4 text-center text-destructive",children:[e.jsx("p",{children:r("household.error")}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s.message})]})}):a.length===0?null:e.jsxs(F,{className:"card-tile-gradient rounded-2xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 cursor-pointer hover:bg-white/5 transition-colors duration-200",onClick:()=>C(d=>!d),children:[e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px] flex-1",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:e.jsx(je,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base",children:r("household.title")}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[r("household.memberCount",{count:I.length}),g.length>0&&` · ${r("household.pending",{count:g.length})}`]})]})]}),e.jsx(Ce,{className:`h-5 w-5 text-muted-foreground transition-transform duration-200 ml-2 ${_?"rotate-180":""}`})]}),e.jsxs("div",{className:`overflow-hidden transition-all duration-300 ease-out ${_?"max-h-[1000px] opacity-100":"max-h-0 opacity-0"}`,children:[e.jsx("div",{className:"border-t border-white/10 p-4",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3 mb-4",children:[a.length>1&&e.jsxs(Ze,{value:l||void 0,onValueChange:c,children:[e.jsx(Je,{className:"w-[200px] glass-card",children:e.jsx(Xe,{placeholder:"Select household"})}),e.jsx(es,{children:a.map(d=>e.jsx(Me,{value:d.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-4 w-4"}),d.name||[d.address_street,d.city].filter(Boolean).join(", ")||"Unnamed Household"]})},d.id))})]}),m&&e.jsxs(Ss,{open:p,onOpenChange:f,children:[e.jsx(Ks,{asChild:!0,children:e.jsxs(S,{size:"sm",className:"gap-2",children:[e.jsx(Qs,{className:"h-4 w-4"}),"Invite"]})}),e.jsxs(Cs,{className:"card-solid no-hover",children:[e.jsxs(ks,{children:[e.jsx(Ds,{children:"Invite to Household"}),e.jsxs(Es,{children:["Send an invitation to join ",(B==null?void 0:B.name)||"your household"]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(O,{htmlFor:"invite-email",children:"Email Address"}),e.jsx(T,{id:"invite-email",type:"email",placeholder:"[email protected]",value:u,onChange:d=>h(d.target.value),onKeyDown:d=>{d.key==="Enter"&&W()}})]}),e.jsx(S,{onClick:W,disabled:!u.trim()||ye,className:"w-full",children:ye?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"h-4 w-4 animate-spin mr-2"})," Sending..."]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"h-4 w-4 mr-2"})," Send Invitation"]})})]})]})]})]})}),e.jsx("div",{className:"px-4 pb-4 space-y-3",children:w?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx($,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsxs(e.Fragment,{children:[I.map(d=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-white/5 backdrop-blur-sm border border-white/10 hover:bg-white/10 transition-colors duration-200",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(Fs,{className:"h-10 w-10 border-2 border-white/20",children:[e.jsx(qs,{src:d.avatar_url||void 0}),e.jsx(Rs,{className:"bg-primary/20 text-primary",children:Hs(d)})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium",children:qe(d)}),d.role==="owner"&&e.jsx(ht,{className:"h-4 w-4 text-yellow-500"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d.email})]})]}),M&&d.role!=="owner"&&d.user_id&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(de,{children:[e.jsx(we,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"sm",className:"hover:bg-yellow-500/10 hover:text-yellow-500",disabled:ee,title:"Transfer ownership",children:ee?e.jsx($,{className:"h-4 w-4 animate-spin"}):e.jsx(Ue,{className:"h-4 w-4"})})}),e.jsxs(ue,{className:"card-solid no-hover",children:[e.jsxs(me,{children:[e.jsxs(he,{children:["Transfer ownership to ",d.first_name,"?"]}),e.jsxs(xe,{className:"space-y-2",children:[e.jsxs("p",{children:["Are you sure you want to make ",e.jsx("strong",{children:qe(d)})," the owner of this household?"]}),e.jsx("p",{className:"text-muted-foreground",children:"You will become a regular member and will no longer be able to manage the household."})]})]}),e.jsxs(pe,{children:[e.jsx(fe,{children:"Cancel"}),e.jsx(ge,{onClick:()=>
36d.user_id&&Q(d.user_id),className:"bg-yellow-500 text-white hover:bg-yellow-600",children:"Transfer Ownership"})]})]})]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{i(d),y(!0)},className:"hover:bg-primary/10 hover:text-primary",children:e.jsx(xt,{className:"h-4 w-4"})}),e.jsxs(de,{children:[e.jsx(we,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"sm",className:"hover:bg-destructive/10 hover:text-destructive",disabled:G,children:G?e.jsx($,{className:"h-4 w-4 animate-spin"}):e.jsx(ae,{className:"h-4 w-4"})})}),e.jsxs(ue,{className:"card-solid no-hover",children:[e.jsxs(me,{children:[e.jsxs(he,{children:["Remove ",d.first_name,"?"]}),e.jsxs(xe,{className:"space-y-2",children:[e.jsxs("p",{children:["Are you sure you want to remove ",e.jsx("strong",{children:qe(d)})," from this household?"]}),e.jsx("p",{className:"text-muted-foreground",children:"Any services and documents they added will become their personal property and will no longer be visible to the household."})]})]}),e.jsxs(pe,{children:[e.jsx(fe,{children:"Cancel"}),e.jsx(ge,{onClick:()=>d.user_id&&R({memberId:d.record_id,memberUserId:d.user_id}),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove Member"})]})]})]})]}),!M&&d.user_id===(k==null?void 0:k.user_id)&&e.jsxs(de,{children:[e.jsx(we,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"sm",className:"hover:bg-destructive/10 hover:text-destructive gap-1",disabled:D,children:D?e.jsx($,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Os,{className:"h-4 w-4"}),"Leave"]})})}),e.jsxs(ue,{className:"card-solid no-hover",children:[e.jsxs(me,{children:[e.jsx(he,{children:"Leave this household?"}),e.jsxs(xe,{className:"space-y-2",children:[e.jsxs("p",{children:["Are you sure you want to leave ",e.jsx("strong",{children:(B==null?void 0:B.name)||"this household"}),"?"]}),e.jsx("p",{className:"text-muted-foreground",children:"Any services and documents you added will become your personal property and will no longer be visible to other household members."})]})]}),e.jsxs(pe,{children:[e.jsx(fe,{children:"Cancel"}),e.jsx(ge,{onClick:()=>ve(),className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Leave Household"})]})]})]})]},d.record_id)),g.length>0&&M&&e.jsxs("div",{className:"pt-3 border-t border-white/10 space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:["Pending Invitations (",g.length,")"]}),g.map(d=>e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-3 p-3 rounded-xl bg-white/5 backdrop-blur-sm border border-dashed border-white/20",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center border border-primary/20 shrink-0",children:e.jsx(He,{className:"h-5 w-5 text-primary","aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium truncate",children:d.email}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Invited ",d.invited_at?new Date(d.invited_at).toLocaleDateString():""," · ",se(d.expires_at)]})]})]}),e.jsx("div",{className:"sm:hidden flex justify-end",children:e.jsxs(ct,{children:[e.jsx(dt,{asChild:!0,children:e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-foreground","aria-label":`Actions for ${d.email}`,children:e.jsx(Mt,{className:"h-4 w-4"})})}),e.jsxs(ut,{align:"end",children:[e.jsxs(De,{onClick:()=>d.token&&Z(d.token),children:[e.jsx(We,{className:"h-4 w-4 mr-2"}),"Copy link"]}),typeof navigator<"u"&&navigator.share&&e.jsxs(De,{onClick:()=>ie(d),children:[e.jsx(oe,{className:"h-4 w-4 mr-2"}),"Share"]}),e.jsxs(De,{onClick:()=>X(d.record_id),disabled:n,children:[n?e.jsx($,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(ts,{className:"h-4 w-4 mr-2"}),"Resend email"]}),e.jsxs(De,{onClick:()=>q(d.record_id),className:"text-destructive focus:text-destructive",children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),"Cancel invitation"]})]})]})}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 justify-end shrink-0",role:"group","aria-label":`Invitation actions for ${d.email}`,children:[e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>d.token&&Z(d.token),className:"h-8 w-8 text-muted-foreground hover:text-foreground","aria-label":`Copy invite link for ${d.email}`,children:e.jsx(We,{className:"h-4 w-4","aria-hidden":"true"})}),typeof navigator<"u"&&navigator.share&&e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>ie(d),className:"h-8 w-8 text-muted-foreground hover:text-foreground","aria-label":`Share invite for ${d.email}`,children:e.jsx(oe,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>X(d.record_id),disabled:n,className:"h-8 w-8 text-muted-foreground hover:text-foreground","aria-label":`Resend invitation email to ${d.email}`,children:n?e.jsx($,{className:"h-4 w-4 animate-spin","aria-hidden":"true"}):e.jsx(ts,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx(S,{variant:"ghost",size:"icon",onClick:()=>q(d.record_id),className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":`Cancel invitation for ${d.email}`,children:e.jsx(ae,{className:"h-4 w-4","aria-hidden":"true"})})]}),e.jsx(de,{open:P===d.record_id,onOpenChange:J=>q(J?d.record_id:null),children:e.jsxs(ue,{className:"card-solid no-hover",children:[e.jsxs(me,{children:[e.jsx(he,{children:"Cancel invitation?"}),e.jsxs(xe,{children:["This will cancel the invitation sent to ",e.jsx("strong",{children:d.email}),". They will no longer be able to join using the invitation link."]})]}),e.jsxs(pe,{children:[e.jsx(fe,{children:"Keep Invitation"}),e.jsx(ge,{onClick:()=>{L(d.record_id),q(null)},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Cancel Invitation"})]})]})})]},d.record_id))]}),I.length===0&&e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(je,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No members yet"})]})]})})]}),e.jsx(zt,{member:N?{id:N.record_id,user_id:N.user_id||"",role:N.role,permissions:N.permissions,profile:{first_name:N.first_name,last_name:N.last_name,email:N.email}}:null,open:j,onOpenChange:d=>{y(d),d||i(null)},onUpdate:d=>{ke(d),y(!1),i(null)},isUpdating:A})]})};function ps(){const t=pt(),{loading:r,isGoogleConnected:a,syncStatus:x,error:s,triggerGmailSync:l,disconnectGmail:c}
36=zs(),u=ft(),[h,p]=o.useState(!1),[f,j]=o.useState(!1),[y,N]=o.useState(!1),[i,_]=o.useState(!1),[C,P]=o.useState(null);o.useEffect(()=>{const R=u.status;(R==="running"||R==="completed"||R==="failed")&&j(!1)},[u.status]);const q=async()=>{p(!0);try{await gt()}catch(R){console.error("[GmailIntegrationCard] Connect failed:",R),b.error((R==null?void 0:R.message)||"Failed to connect Gmail")}finally{p(!1)}},I=async()=>{j(!0);try{await l("smart")}catch(R){console.error("[GmailIntegrationCard] Scan failed:",R),j(!1)}},g=async()=>{N(!0),P(null);try{const{data:{session:R}}=await E.auth.getSession();if(!(R!=null&&R.access_token)){b.error("Not authenticated");return}const Q=await(await fetch(Ws("gmail-scanner-v2"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${R.access_token}`},body:JSON.stringify({mode:"diagnostic"})})).json();P(Q),Q.emails_found>0?b.success(`Gmail has ${Q.emails_found} emails! Azure LLM filtering is the issue.`):Q.error?b.error(`Diagnostic failed: ${Q.error}`):b.warning("Azure returned 0 emails - check console for details"),console.log("[DIAGNOSTIC RESULT]",Q)}catch(R){console.error("[GmailIntegrationCard] Diagnostic failed:",R),b.error(`Diagnostic failed: ${R.message}`)}finally{N(!1)}},w=async()=>{_(!0);try{await c(),b.success("Gmail disconnected successfully")}catch(R){console.error("[GmailIntegrationCard] Disconnect failed:",R),b.error((R==null?void 0:R.message)||"Failed to disconnect Gmail")}finally{_(!1)}},M=s&&(s.includes("GMAIL_TOKEN_INVALID")||s.includes("expired")||s.includes("revoked")||s.includes("reconnect")),m=u.status==="running"||u.status==="processing"||f,k=m&&!M,v=u.status==="completed"&&u.syncStatusUpdatedAt&&Date.now()-u.syncStatusUpdatedAt.getTime()<3e4,L=r||!u.canStartNewScan||f,X=a&&!t;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-destructive/15 rounded-lg flex items-center justify-center",children:e.jsx(He,{className:"h-4 w-4 text-destructive"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Gmail"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Scan invoices & bills from your inbox"})]})]}),e.jsx(Y,{variant:a?"default":"secondary",className:"text-xs",children:a?"Connected":"Not connected"})]}),a?X?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(rs,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"This connection has no Gmail inbox. Disconnect to remove it."})]}),e.jsxs(de,{children:[e.jsx(we,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",title:"Disconnect Gmail",disabled:i,className:"w-full text-destructive hover:bg-destructive/10",children:i?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(us,{className:"h-3.5 w-3.5"})})}),e.jsxs(ue,{children:[e.jsxs(me,{children:[e.jsx(he,{children:"Disconnect Gmail?"}),e.jsx(xe,{children:"This will revoke access and stop any running scans. Your previously extracted services will be preserved. You can reconnect anytime."})]}),e.jsxs(pe,{children:[e.jsx(fe,{disabled:i,children:"Cancel"}),e.jsx(ge,{onClick:w,disabled:i,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:i?"Disconnecting...":"Disconnect"})]})]})]})]}):e.jsxs("div",{className:"space-y-2",children:[M?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-amber-600 dark:text-amber-400",children:[e.jsx(rs,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Gmail access expired. Please reconnect."})]}),e.jsx(S,{onClick:q,disabled:h,className:"w-full",size:"sm",variant:"outline",children:h?"Reconnecting…":"Reconnect Gmail"})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{onClick:I,disabled:L,className:"flex-1",size:"sm",children:m?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"h-3.5 w-3.5 animate-spin mr-2"}),u.stepLabel||"Scanning…"]}):"Start Scan"}),e.jsx(S,{onClick:g,disabled:y,size:"sm",variant:"ghost",title:"Run diagnostic to check if Gmail has emails",children:y?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Rt,{className:"h-3.5 w-3.5"})}),e.jsxs(de,{children:[e.jsx(we,{asChild:!0,children:e.jsx(S,{size:"sm",variant:"ghost",title:"Disconnect Gmail",disabled:m||i,className:"text-destructive hover:bg-destructive/10",children:i?e.jsx($,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(us,{className:"h-3.5 w-3.5"})})}),e.jsxs(ue,{children:[e.jsxs(me,{children:[e.jsx(he,{children:"Disconnect Gmail?"}),e.jsx(xe,{children:"This will revoke access and stop any running scans. Your previously extracted services will be preserved. You can reconnect anytime."})]}),e.jsxs(pe,{children:[e.jsx(fe,{disabled:i,children:"Cancel"}),e.jsx(ge,{onClick:w,disabled:i,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:i?"Disconnecting...":"Disconnect"})]})]})]})]}),k&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"h-1.5 rounded bg-muted overflow-hidden",children:e.jsx("div",{className:"h-1.5 bg-primary transition-all",style:{width:`${u.progress}%`}})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:u.message})]}),v&&!k&&!M&&e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-primary",children:[e.jsx(jt,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"Scan complete"})]}),C&&e.jsx("div",{className:`text-xs p-2 rounded ${C.emails_found>0?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"}`,children:C.emails_found>0?e.jsxs("span",{children:["✅ Gmail has ",C.emails_found," emails. Azure LLM is filtering."]}):C.error?e.jsxs("span",{children:["❌ ",C.error]}):e.jsx("span",{children:"⚠️ Azure returned 0 emails. Check console."})}),(x==null?void 0:x.last_sync_at)&&!k&&!v&&!M&&!C&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last sync: ",new Date(x.last_sync_at).toLocaleDateString()]})]}):e.jsx(S,{onClick:q,disabled:h||r,className:"w-full",size:"sm",children:h?"Connecting…":"Connect Gmail"}),s&&!M&&e.jsx("p",{className:"text-xs text-destructive",children:s})]})}function Tt(){const t="943cadc2-99cc-4d7d-908d-8c7976c56a1c",r=`${window.location.origin}/oauth/microsoft/callback`,a=["openid","profile","email","offline_access","Mail.Read","Mail.ReadBasic"].join(" "),x=new URLSearchParams({client_id:t,response_type:"code",redirect_uri:r,scope:a,prompt:"consent"});return sessionStorage.setItem("oauth_return_to",window.location.pathname),window.location.href=`https://login.microsoftonline.com/common/o
36auth2/v2.0/authorize?${x.toString()}`,!0}function $t(){const{user:t}=V(),[r,a]=o.useState(null),[x,s]=o.useState(!1),[l,c]=o.useState(!1),[u,h]=o.useState(null),p=o.useRef(!1),f=o.useRef({syncStatus:!1,connection:!1}),j=o.useCallback(async()=>{if(!t||f.current.connection){t||s(!1);return}f.current.connection=!0;try{const{data:g,error:w}=await E.from("user_provider_tokens").select("provider").eq("user_id",t.id).eq("provider","outlook").limit(1);if(w){console.error("[useOutlookData] checkConnection error:",w),s(!1);return}s(g&&g.length>0)}catch(g){console.debug("[useOutlookData] checkConnection catch:",g),s(!1)}finally{f.current.connection=!1}},[t]),y=o.useCallback(async()=>{if(!(!t||f.current.syncStatus)){f.current.syncStatus=!0;try{const{data:g,error:w}=await E.from("gmail_sync_status").select("*").eq("user_id",t.id).eq("provider","outlook").order("updated_at",{ascending:!1}).limit(1).maybeSingle();if(w&&w.code!=="PGRST116")throw w;g&&a(g)}catch(g){console.error("[useOutlookData] loadSyncStatus error:",g)}finally{f.current.syncStatus=!1}}},[t]),N=o.useCallback(async()=>{if(t){c(!0),h(null);try{await Promise.all([j(),y()])}catch(g){console.error("[useOutlookData] reload error:",g),h(g instanceof Error?g.message:"Failed to load Outlook data")}finally{c(!1)}}},[t,j,y]);o.useEffect(()=>{if(t){if(p.current)return;p.current=!0,N()}else p.current=!1,a(null),s(!1)},[t,N]),o.useEffect(()=>{if(!t)return;const g=E.channel("outlook-data-changes").on("postgres_changes",{event:"*",schema:"public",table:"gmail_sync_status",filter:`user_id=eq.${t.id}`},w=>{const M=w.new;(M==null?void 0:M.provider)==="outlook"&&(console.log("[useOutlookData] Realtime: sync status updated"),y())}).on("postgres_changes",{event:"INSERT",schema:"public",table:"user_provider_tokens",filter:`user_id=eq.${t.id}`},()=>{console.log("[useOutlookData] Realtime: tokens updated"),j()}).subscribe();return()=>{E.removeChannel(g)}},[t,y,j]);const[i,_]=o.useState(null),C=o.useCallback(async()=>{if(t)try{const[g,w,M]=await Promise.all([E.from("email_classification_queue").select("id",{count:"exact",head:!0}).eq("user_id",t.id),E.from("email_classification_queue").select("id",{count:"exact",head:!0}).eq("user_id",t.id).in("status",["completed","failed"]),E.from("extracted_services").select("id",{count:"exact",head:!0}).eq("user_id",t.id)]);_({total:g.count||0,done:w.count||0,found:M.count||0})}catch(g){console.debug("[useOutlookData] loadAnalysis:",g)}},[t]);o.useEffect(()=>{if(!t||(C(),!(!i||i.done<i.total)))return;const w=Date.now(),M=setInterval(()=>{if(Date.now()-w>30*6e4){clearInterval(M);return}C()},5e3);return()=>clearInterval(M)},[t,C,i==null?void 0:i.total,i==null?void 0:i.done,r==null?void 0:r.sync_status]),o.useEffect(()=>{if(!t||!(!r||r.sync_status==="running"||r.sync_status==="queued"))return;const w=Date.now(),M=setInterval(()=>{if(Date.now()-w>5*6e4){clearInterval(M);return}y()},3e3);return()=>clearInterval(M)},[t,r==null?void 0:r.sync_status,r,y]);const P=o.useCallback(()=>{Tt()},[]),q=o.useCallback(async()=>{if(!t){b.error("Please sign in to scan Outlook");return}c(!0),h(null);try{const{error:g}=await E.functions.invoke("outlook-orchestrator-proxy",{body:{mode:"smart"}});if(g)throw g;b.success("Outlook scan started"),a(w=>({...w||{},sync_status:"running",phase:"starting",phase_detail:"Connecting to Outlook…",progress:0})),setTimeout(()=>void N(),1500)}catch(g){console.error("[useOutlookData] startScan error:",g);const w=g instanceof Error?g.message:"Failed to start Outlook scan";h(w),b.error(w)}finally{c(!1)}},[t,N]),I=r?r.sync_status==="running"||r.sync_status==="queued"?"running":r.sync_status==="completed"?"done":r.sync_status==="failed"||r.sync_status==="auth_failed"?"error":"idle":"idle";return{syncStatus:r,scanState:I,analysis:i,isConnected:x,loading:l,error:u,connect:P,startScan:q,reload:N}}const Gt=({className:t})=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:t,children:e.jsx("path",{d:"M7.88 12.04q0 .45-.11.87-.1.41-.33.74-.22.33-.58.52-.37.2-.87.2t-.85-.2q-.35-.21-.57-.55-.22-.33-.33-.75-.1-.42-.1-.86t.1-.87q.1-.43.34-.76.22-.34.59-.54.36-.2.87-.2t.86.2q.35.21.57.55.22.34.31.77.1.43.1.88zM24 12v9.38q0 .46-.33.8-.33.32-.8.32H7.13q-.46 0-.8-.33-.32-.33-.32-.8V18H1q-.41 0-.7-.3-.3-.29-.3-.7V7q0-.41.3-.7Q.58 6 1 6h6.5V2.55q0-.44.3-.75.3-.3.75-.3h14.9q.44 0 .75.3.3.3.3.75V12zm-6-8.25v3h3v-3zm0 4.5v3h3v-3zm0 4.5v1.83l3.05-1.83zm-5.25-9v3h3.75v-3zm0 4.5v3h3.75v-3zm0 4.5v2.03l2.41 1.5 1.34-.8v-2.73zM9 3.75V6h2l.13.01.12.04v-2.3zM5.98 15.98q.9 0 1.6-.3.7-.32 1.19-.86.48-.55.73-1.28.25-.74.25-1.61 0-.83-.25-1.55-.24-.71-.71-1.24t-1.15-.83q-.68-.3-1.55-.3-.92 0-1.64.32-.71.32-1.2.87-.5.55-.75 1.3-.25.74-.25 1.63 0 .85.26 1.56.26.72.74 1.23.48.52 1.17.81.69.3 1.56.3zM7.5 21h12.39L12 16.08V17q0 .41-.3.7-.29.3-.7.3H7.5zm15-.13v-7.24l-5.9 3.54Z"})});function fs(){const{loading:t,isConnected:r,syncStatus:a,error:x,scanState:s,analysis:l,connect:c,startScan:u}
36=$t(),[h,p]=o.useState(!1),f=async()=>{p(!0);try{c()}finally{p(!1)}},j=async()=>{try{await u()}catch(y){console.error("[OutlookIntegrationCard] Scan failed:",y)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-blue-500/15 rounded-lg flex items-center justify-center",children:e.jsx(Gt,{className:"h-4 w-4 text-blue-500"})}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Outlook"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Scan invoices & bills from your inbox"})]})]}),e.jsx(Y,{variant:r?"default":"secondary",className:"text-xs",children:r?"Connected":"Not connected"})]}),r?e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{onClick:j,disabled:t||s==="running",className:"w-full",size:"sm",children:s==="running"?"Scanning…":s==="error"?"Try again":"Start Scan"}),s==="running"&&e.jsxs("div",{className:"space-y-1","data-testid":"outlook-scan-progress",children:[e.jsx("div",{className:"h-1.5 rounded bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${Math.round(Math.min(1,Math.max(.05,Number((a==null?void 0:a.progress)??0)))*100)}%`}})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(a==null?void 0:a.phase_detail)||"Reading your inbox…"})]}),s==="error"&&e.jsx("p",{className:"text-xs text-destructive","data-testid":"outlook-scan-error",children:(a==null?void 0:a.phase_detail)||"The scan could not be completed. Please try again."}),s==="done"&&l&&l.total>0&&l.done<l.total&&e.jsxs("div",{className:"space-y-1","data-testid":"outlook-analysis-progress",children:[e.jsx("div",{className:"h-1.5 rounded bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${Math.round(l.done/l.total*100)}%`}})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Analysing your emails: ",l.done," of ",l.total," done · ",l.found," agreement",l.found===1?"":"s"," found so far"]})]}),s==="done"&&(!l||l.total===0||l.done>=l.total)&&e.jsxs("p",{className:"text-xs text-muted-foreground","data-testid":"outlook-scan-done",children:[a!=null&&a.phase_detail?`${a.phase_detail}. `:"",l&&l.total>0?`${l.found} agreement${l.found===1?"":"s"} found. `:"",a!=null&&a.last_sync_at?`Last scan: ${new Date(a.last_sync_at).toLocaleString()}. `:"","Detected agreements appear under Services for your review."]})]}):e.jsx(S,{onClick:f,disabled:h||t,className:"w-full",size:"sm",children:h?"Connecting…":"Connect Outlook"}),x&&e.jsx("p",{className:"text-xs text-destructive",children:x})]})}function gs({initialExpanded:t=!1,isDesktopPanel:r=!1}){const{t:a}=Se("settings"),{isGoogleConnected:x,syncStatus:s}=zs(),{user:l,session:c}=V(),[u,h]=o.useState(t),p=o.useRef(!1),f=o.useRef(!1);o.useEffect(()=>{l&&(c!=null&&c.provider_token)&&(console.log("✅ Gmail OAuth Success: provider_token available"),f.current||(b.success("Gmail connected successfully!"),f.current=!0),!s&&x&&!p.current&&setTimeout(()=>{b("Ready to sync Gmail! Click Start Smart Scan to analyze your emails.",{duration:5e3}),p.current=!0},1e3))},[l,c,s,x]);const j=()=>{h(!u)};return r?e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(ps,{}),e.jsx(fs,{})]})}):e.jsxs(F,{className:"card-tile-gradient overflow-hidden rounded-2xl cursor-pointer hover:bg-white/5 transition-all duration-300 active:scale-[0.98]",onClick:j,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px] flex-1",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:e.jsx(Ts,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base",children:a("integrations.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("integrations.description")})]})]}),e.jsx(Ce,{className:`h-5 w-5 text-muted-foreground transition-transform duration-200 ml-2 ${u?"rotate-180":""}`})]}),e.jsx("div",{className:`transition-all duration-300 ease-in-out overflow-hidden ${u?"max-h-[2000px] opacity-100":"max-h-0 opacity-0"}`,onClick:y=>y.stopPropagation(),children:e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx(as,{}),e.jsx("div",{className:"px-4 pb-4",children:e.jsx(ps,{})}),e.jsx(as,{}),e.jsx("div",{className:"px-4 pb-4",children:e.jsx(fs,{})})]})})]})}const Ie={en:"en-GB","en-GB":"en-GB","en-US":"en-GB",da:"da-DK","da-DK":"da-DK",sv:"sv-SE","sv-SE":"sv-SE",nb:"nb-NO","nb-NO":"nb-NO",no:"nb-NO",nn:"nb-NO",de:"de-DE","de-DE":"de-DE","de-AT":"de-DE","de-CH":"de-DE"};function js(){const t=navigator.language||navigator.userLanguage||"en-GB";if(Ie[t])return Ie[t];const r=t.split("-")[0];return Ie[r]?Ie[r]:"en-GB"}function Bt(){const{i18n:t,t:r}=Se(),{user:a}
36=V(),[x,s]=o.useState(!1),[l,c]=o.useState(null),[u,h]=o.useState(!1),p=o.useRef(!1),f=o.useRef(!1);o.useEffect(()=>{if(!a||p.current)return;p.current=!0,(async()=>{const{data:q,error:I}=await E.from("profiles").select("language_code").eq("user_id",a.id).maybeSingle();if(!I&&(q!=null&&q.language_code)){const g=q.language_code;if(Oe.includes(g)){c(g),t.language!==g&&(await t.changeLanguage(g),localStorage.setItem("switchit_language",g));return}}if(!f.current){f.current=!0;const g=js();console.log("🌍 Auto-detected language:",g,"from browser:",navigator.language),await t.changeLanguage(g),localStorage.setItem("switchit_language",g),c(g),h(!0);const{error:w}=await E.from("profiles").update({language_code:g}).eq("user_id",a.id);if(w)console.warn("Failed to auto-sync language to profile:",w);else if(console.log("✅ Language auto-synced to profile:",g),g!=="en-GB"){const M=ze[g];b.success(r("common:languageAutoDetected",{language:M}),{description:r("common:changeInSettings"),duration:4e3})}}})()},[a,t,r]);const j=o.useCallback(async P=>{if(!Oe.includes(P))return console.error(`Unsupported locale: ${P}`),!1;s(!0);try{if(await t.changeLanguage(P),localStorage.setItem("switchit_language",P),a){const{error:q}=await E.from("profiles").update({language_code:P}).eq("user_id",a.id);if(q)return console.error("Failed to save language preference:",q),!1}return c(P),h(!1),!0}catch(q){return console.error("Error changing language:",q),!1}finally{s(!1)}},[a,t]),y=o.useCallback(P=>Ys[P.toUpperCase()]||"en-GB",[]),N=t.language||"en-GB",i=ze[N]||"English",_=Vs[N]||"GB",C=js();return{currentLocale:N,currentLanguageName:i,currentCountry:_,profileLanguage:l,detectedLocale:C,wasAutoDetected:u,supportedLocales:Oe,localeNames:ze,changeLanguage:j,getLocaleFromCountry:y,isLoading:x}}const Ge={"en-GB":"🇬🇧","da-DK":"🇩🇰","sv-SE":"🇸🇪","nb-NO":"🇳🇴","de-DE":"🇩🇪"};function vs({variant:t="select",showFlag:r=!0,className:a=""}){const{currentLocale:x,supportedLocales:s,localeNames:l,changeLanguage:c,isLoading:u}=Bt();return t==="list"?e.jsx("div",{className:`space-y-2 ${a}`,children:s.map(h=>e.jsxs("button",{onClick:()=>c(h),disabled:u,className:`
37              w-full flex items-center justify-between p-3 rounded-lg border transition-all
38              ${x===h?"border-primary bg-primary/10 text-primary":"border-border hover:border-primary/50 hover:bg-muted/50"}
39              ${u?"opacity-50 cursor-not-allowed":"cursor-pointer"}
40            `,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[r&&e.jsx("span",{className:"text-xl",children:Ge[h]}),e.jsx("span",{className:"font-medium",children:l[h]})]}),x===h&&e.jsx(Fe,{className:"h-5 w-5 text-primary"})]},h))}):e.jsxs(Ze,{value:x,onValueChange:h=>c(h),disabled:u,children:[e.jsx(Je,{className:`w-[180px] ${a}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs(Xe,{children:[r&&Ge[x]," ",l[x]]})]})}),e.jsx(es,{children:s.map(h=>e.jsx(Me,{value:h,children:e.jsxs("div",{className:"flex items-center gap-2",children:[r&&e.jsx("span",{children:Ge[h]}),e.jsx("span",{children:l[h]})]})},h))})]})}const Ht=()=>{const{user:t}=V(),[r,a]=o.useState("default"),[x,s]=o.useState(!1),[l,c]=o.useState(!1),[u,h]=o.useState(!1),p=o.useCallback(async()=>{if(!t)return!1;const{data:i}=await E.from("push_subscriptions").select("id").eq("user_id",t.id).maybeSingle();return!!i},[t]);o.useEffect(()=>{const i=Zs();h(i),i?p().then(_=>{s(_),a(_?"granted":"default")}):"Notification"in window&&a(Notification.permission)},[t,p]);const f=async()=>{if(u)return{subscribed:!1,permissionResult:"default"};c(!0);try{const i=await Xs();return a(i),i==="granted"?{subscribed:await j(),permissionResult:i}:{subscribed:!1,permissionResult:i}}catch(i){return console.error("Permission request failed:",i),{subscribed:!1,permissionResult:"default"}}finally{c(!1)}},j=async()=>{if(!t||u)return!1;c(!0);try{const i=await Js();if(i){const{error:_}=await E.from("push_subscriptions").upsert({user_id:t.id,subscription_json:i.toJSON(),device_type:/iPhone|iPad|iPod/.test(navigator.userAgent)?"ios":"android"});if(!_)return s(!0),!0}return!1}catch(i){return console.error("Subscription failed:",i),!1}finally{c(!1)}},y=async()=>
40{if(t&&!u){c(!0);try{const _=await(await navigator.serviceWorker.ready).pushManager.getSubscription();_&&(await _.unsubscribe(),await E.from("push_subscriptions").delete().eq("user_id",t.id),s(!1))}catch(i){console.error("Unsubscribe failed:",i)}finally{c(!1)}}},N=o.useCallback(async()=>{if(u){const i=await p();s(i),a(i?"granted":"default")}},[u,p]);return{permission:r,isSubscribed:x,isLoading:l,isNativeApp:u,requestPermission:f,subscribe:j,unsubscribe:y,refreshStatus:N}},Ut=()=>{const[t,r]=o.useState(!1),[a,x]=o.useState(!1);o.useEffect(()=>{const c=localStorage.getItem("rate_app_dismissed");if(c){const u=new Date(c);if((Date.now()-u.getTime())/(1e3*60*60*24)<30){r(!0);return}}x(Ke())},[]);const s=async()=>{if(navigator.share)try{await navigator.share({title:"SwitchIt - Save on bills",text:"I love using SwitchIt to save money on my bills!",url:window.location.origin})}catch{console.log("Share cancelled or failed")}else window.open(window.location.origin,"_blank")},l=()=>{localStorage.setItem("rate_app_dismissed",new Date().toISOString()),r(!0)};return!a||t?null:e.jsxs(F,{className:"glass-card transition-all duration-300",children:[e.jsxs(Is,{children:[e.jsxs(As,{className:"flex items-center gap-2",children:[e.jsx(is,{className:"w-5 h-5 text-yellow-500",fill:"currentColor"}),"Rate SwitchIt"]}),e.jsx(Ls,{children:"Loving the app? Share your feedback and help us grow!"})]}),e.jsxs(_e,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{onClick:s,className:"flex-1",children:[e.jsx(is,{className:"w-4 h-4 mr-2"}),"Rate 5 Stars"]}),e.jsx(S,{onClick:l,variant:"ghost",size:"icon",children:e.jsx(ae,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your feedback helps us improve SwitchIt for everyone"})]})]})},ys=({isDesktopPanel:t=!1})=>{const{t:r}=Se("settings"),{permission:a,isSubscribed:x,isLoading:s,isNativeApp:l,requestPermission:c,unsubscribe:u,refreshStatus:h}=Ht(),[p,f]=o.useState(!1);o.useEffect(()=>{if(l){const i=()=>{document.visibilityState==="visible"&&h()};return document.addEventListener("visibilitychange",i),()=>document.removeEventListener("visibilitychange",i)}},[l,h]);const j=async i=>{if(l){b.info(r("notifications.openSettings"),{description:r("notifications.settingsPath"),duration:5e3});return}if(i){const{subscribed:_,permissionResult:C}=await c();_?b.success(r("notifications.enabled","Notifications enabled")):C==="denied"?b.error(r("notifications.blocked","Notifications are blocked. Enable them in your browser settings.")):C==="granted"?b.error(r("notifications.subscriptionFailed","Failed to subscribe to notifications. Please try again.")):b.warning(r("notifications.unavailable","Notifications aren't available in this environment."))}else await u(),b.success(r("notifications.disabled","Notifications disabled"))},y=async()=>{await st()},N=()=>l?r(x?"notifications.active":"notifications.enableInSettings"):a==="granted"&&x?r("notifications.active"):a==="denied"?r("notifications.blocked"):a==="default"?r("notifications.notConfigured"):a==="granted"&&!x?r("notifications.off"):"";return e.jsxs("div",{className:"space-y-4",children:[!l&&!Ke()&&et()&&e.jsxs(F,{className:"card-tile-gradient transition-all duration-300 rounded-2xl",children:[e.jsxs(Is,{children:[e.jsxs(As,{className:"flex items-center gap-2",children:[e.jsx(ss,{className:"w-5 h-5"}),r("pwa.installApp")]}),e.jsx(Ls,{children:r("pwa.installDescription")})]}),e.jsx(_e,{children:e.jsxs(S,{onClick:y,className:"w-full",children:[e.jsx(ss,{className:"w-4 h-4 mr-2"}),r("pwa.installButton")]})})]}),e.jsxs(F,{className:"card-tile-gradient overflow-hidden rounded-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 cursor-pointer hover:bg-white/5 transition-colors duration-200",onClick:()=>f(i=>!i),children:[e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px] flex-1",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:e.jsx($s,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base",children:r("notifications.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N()})]})]}),e.jsx(Ce,{className:`h-5 w-5 text-muted-foreground transition-transform duration-200 ml-2 ${p?"rotate-180":""}`})]}),e.jsx("div",{className:`overflow-hidden transition-all duration-300 ease-out ${p?"max-h-[250px] opacity-100":"max-h-0 opacity-0"}`,children:e.jsx("div",{className:"px-4 pb-4 pt-2 space-y-3",children:l?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:r("notifications.offerAlerts")}),e.jsx(re,{id:"notifications",checked:x,onCheckedChange:j,disabled:s})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:r("notifications.nativeAppInfo")}),e.jsxs(S,{variant:"outline",size:"sm",className:"w-full text-xs",onClick:()=>{b.info(r("notifications.openSettings"),{description:r("notifications.settingsPath"),duration:5e3})},children:[e.jsx(vt,{className:"w-3 h-3 mr-2"}
40),r("notifications.openIOSSettings")]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:r("notifications.offerAlerts")}),e.jsx(re,{id:"notifications",checked:x,onCheckedChange:j,disabled:s||a==="denied"})]}),a==="denied"&&e.jsx("p",{className:"text-xs text-destructive",children:r("notifications.enableInBrowser")}),/iPhone|iPad|iPod/.test(navigator.userAgent)&&!Ke()&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r("notifications.installForPush")})]})})})]}),e.jsx(Ut,{})]})};function bs({isDesktopPanel:t=!1}){var i,_;const{user:r}=V(),[a,x]=o.useState(!1),[s,l]=o.useState(""),[c,u]=o.useState(""),[h,p]=o.useState(!1),f=(i=r==null?void 0:r.identities)==null?void 0:i.some(C=>C.provider==="email"),j=((_=r==null?void 0:r.app_metadata)==null?void 0:_.provider)==="google",y=!f||j,N=async C=>{if(C.preventDefault(),s.length<8){b.error("Password must be at least 8 characters");return}if(s!==c){b.error("Passwords do not match");return}p(!0);try{const{error:P}=await E.auth.updateUser({password:s});if(P)throw P;b.success(y?"Password set successfully":"Password updated successfully"),l(""),u(""),x(!1)}catch(P){console.error("Password update error:",P),b.error(P.message||"Failed to update password")}finally{p(!1)}};return e.jsxs(F,{className:"card-tile-gradient rounded-2xl overflow-hidden",children:[e.jsxs("button",{onClick:()=>x(!a),className:"w-full p-4 flex items-center justify-between min-h-[44px]",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(Gs,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 text-left",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:"Password"}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:y?"Set a password for email sign-in":"Change your password"})]})]}),a?e.jsx(tt,{className:"h-5 w-5 text-on-tile-muted"}):e.jsx(Ce,{className:"h-5 w-5 text-on-tile-muted"})]}),a&&e.jsxs("form",{onSubmit:N,className:"px-4 pb-4 space-y-4",children:[e.jsx("div",{className:"p-3 bg-primary/10 rounded-xl",children:e.jsx("p",{className:"text-sm text-on-tile-muted",children:y?"Set a password to sign in with your email if magic link doesn't work.":"Enter a new password to update your account."})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"new-password",className:"text-on-tile",children:y?"Password":"New Password"}),e.jsx(T,{id:"new-password",type:"password",value:s,onChange:C=>l(C.target.value),placeholder:"Enter password (min 8 characters)",className:"bg-background/50 border-border/50 rounded-xl h-12",minLength:8,required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"confirm-password",className:"text-on-tile",children:"Confirm Password"}),e.jsx(T,{id:"confirm-password",type:"password",value:c,onChange:C=>u(C.target.value),placeholder:"Confirm your password",className:"bg-background/50 border-border/50 rounded-xl h-12",minLength:8,required:!0})]}),e.jsx(S,{type:"submit",variant:"native",className:"w-full h-12 rounded-xl",disabled:h||!s||!c,children:h?e.jsx($,{className:"h-5 w-5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{className:"h-5 w-5 mr-2"}),y?"Set Password":"Update Password"]})})]})]})}const Kt=t=>{switch(t){case"pet":return Lt;case"health":return wt;case"property":return Ps;default:return Ms}},Qt=({data:t})=>t.length===0?null:e.jsx(F,{className:"glass-card border-primary/20 bg-primary/5",children:e.jsxs(_e,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-primary/15 backdrop-blur-sm rounded-full flex items-center justify-center border border-primary/20",children:e.jsx(Ms,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:"AI-Discovered Information"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"From your searches"})]})]}),e.jsx("div",{className:"space-y-2",children:t.map((r,a)=>{const x=Kt(r.type);return e.jsxs("div",{className:"flex items-center justify-between p-3 bg-white/5 rounded-xl border border-white/10",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 bg-primary/10 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(x,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:r.label}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:r.value}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs(Y,{variant:"outline",className:"text-xs bg-primary/5 border-primary/20",children:["from ",r.source]})})]})]}),r.onRemove&&e.jsx(S,{variant:"ghost",size:"sm",onClick:r.onRemove,className:"h-8 w-8 p-0 hover:bg-destructive/10 hover:text-destructive flex-shrink-0",children:e.jsx(bt,{className:"h-4 w-4"})})]},a)})})]})}),Be=({initialExpanded:t=!1,isDesktopPanel:r=!1})=>{var X,R,ve,Q,ke,ye;const{user:a}=V(),x=Ve(),[s,l]=o.useState(null),[c,u]=o.useState(!1),[h,p]=o.use
40State(!0),[f,j]=o.useState(!1),[y,N]=o.useState(t),[i,_]=o.useState({first_name:"",last_name:"",email:"",phone:"",date_of_birth:"",household_size:1,number_of_children:0,address:"",avatar_url:"",family_members:[],street:"",city:"",postal_code:"",postcode:"",country:"",country_code:"",lat:null,lng:null}),[C,P]=o.useState(!1),[q,I]=o.useState(!1);o.useEffect(()=>{w()},[a]),o.useEffect(()=>{t&&(N(!0),u(!0))},[t]);const g=n=>{if(!n)return!1;const A=n.replace(/[\s()+\-]/g,"");return/[A-Za-z]/.test(n)||A.length>15},w=async()=>{if(a){p(!0);try{const{data:n,error:A}=await E.from("profiles").select("first_name, last_name, email, phone, date_of_birth, household_size, number_of_children, address, avatar_url, family_members, street, city, postal_code, postcode, country, country_code, lat, lng, pets, health_info, property_type, bedrooms").eq("user_id",a.id).maybeSingle();if(A){console.error("Error fetching profile:",A),U({title:"Error",description:"Failed to load profile information",variant:"destructive"});return}if(n){const G={first_name:n.first_name,last_name:n.last_name,email:n.email||a.email,phone:n.phone,date_of_birth:n.date_of_birth,household_size:n.household_size,number_of_children:n.number_of_children||0,address:n.address,avatar_url:n.avatar_url,street:n.street,city:n.city,postal_code:n.postal_code,postcode:n.postcode,country:n.country,country_code:n.country_code,lat:n.lat,lng:n.lng,pets:Array.isArray(n.pets)?n.pets:[],health_info:typeof n.health_info=="object"?n.health_info:{},property_type:n.property_type,bedrooms:n.bedrooms,family_members:Array.isArray(n.family_members)?n.family_members.map(z=>({id:String((z==null?void 0:z.id)??Date.now()+Math.random()),name:String((z==null?void 0:z.name)??""),age:Number((z==null?void 0:z.age)??0),relationship:(z==null?void 0:z.relationship)==="adult"?"adult":"child"})):[]};l(G);const D=n.phone&&g(n.phone)?"":n.phone||"",ee=G.family_members;_({first_name:n.first_name||"",last_name:n.last_name||"",email:n.email||a.email||"",phone:D,date_of_birth:n.date_of_birth||"",household_size:n.household_size||1,number_of_children:n.number_of_children||0,address:n.address||"",avatar_url:n.avatar_url||"",street:n.street||"",city:n.city||"",postal_code:n.postal_code||"",postcode:n.postcode||"",country:n.country||"",country_code:n.country_code||"",lat:n.lat??null,lng:n.lng??null,family_members:ee})}}catch(n){console.error("Error fetching profile:",n)}finally{p(!1)}}},M=()=>{u(!0)},m=()=>{u(!1),s&&_({first_name:s.first_name||"",last_name:s.last_name||"",email:s.email||"",phone:g(s.phone)?"":s.phone||"",date_of_birth:s.date_of_birth||"",household_size:s.household_size||1,number_of_children:s.number_of_children||0,address:s.address||"",avatar_url:s.avatar_url||"",street:s.street||"",city:s.city||"",postal_code:s.postal_code||"",postcode:s.postcode||"",country:s.country||"",country_code:s.country_code||"",lat:s.lat??null,lng:s.lng??null,family_members:s.family_members||[]})},k=async()=>{if(a){j(!0);try{console.log("💾 Saving profile data:",i);const n=i.country_code||(s==null?void 0:s.country_code)||"",A=i.postcode||(s==null?void 0:s.postcode)||"",G=i.country||(s==null?void 0:s.country)||"";if(!n||n.length!==2){U({title:"Country code required",description:"Please provide a valid 2-letter country code or select your address from suggestions",variant:"destructive"}),j(!1);return}if(!A||A.trim().length===0){U({title:"Postal code required",description:"Please provide your postal code for accurate service matching",variant:"destructive"}),j(!1);return}const D={...i,country_code:n.toUpperCase().trim(),postcode:A.trim(),country:G},ee=D.phone&&D.phone.trim().length>0?D.phone:(s==null?void 0:s.phone)??null,z=D.email||(a==null?void 0:a.email)||null;if(!z){U({title:"Email required",description:"Your account must have an email address. Please contact support.",variant:"destructive"}),j(!1);return}console.log("💾 Saving profile with email:",z);const Z={first_name:D.first_name||null,last_name:D.last_name||null,email:z,phone:ee,date_of_birth:D.date_of_birth||null,household_size:D.household_size,number_of_children:D.number_of_children||0,address:D.address||null,avatar_url:D.avatar_url||null,family_members:D.family_members,street:D.street||null,city:D.city||null,postal_code:D.postcode||null,postcode:D.postcode,country:D.country||null,country_code:D.country_code,lat:D.lat,lng:D.lng},se=i.first_name&&i.last_name&&i.phone&&i.date_of_birth;se&&(Z.is_onboarded=!0,Z.onboarding_completed=!0);const{data:ie,error:W}=await E.from("profiles").update(Z).eq("user_id",a.id).select().single();if(W&&W.code==="PGRST116"){console.log("📝 Creating new profile for user");const{error:B}=await E.from("profiles").insert({...Z,user_id:a.id});if(B){console.error("Error creating profile:",B),U({title:"Error",description:"Failed to create profile. Please try again.",variant:"destructive"});return}}else if(W){console.error("Error updating profile:",W),U({title:"Error",description:"Failed to update profile. Please try again.",variant:"destructive"});return}console.log("✅ Profile saved successfully"),l(i),u(!1),se&&localStorage.removeItem("profile_auto_expand_dismissed"),console.log("🔄 Invalidating validation cache..."),await x.invalidateQueries({queryKey:["onboarding-validation",a.id]});try{const{data:B}=await E.from("household_members").select("household_id, role").eq("user_id",a.id).eq("role","owner").single();B&&(await E.from("households").update({household_size:D.household_size,number_of_children:i.number_of_children||0,property_type:i.property_type||null,bedrooms:i.bedrooms||null,country_code:D.country_code,country:D.country,postal_code:D.postcode,address_street:D.street,city:D.city}).eq("id",B.household_id),console.log("✅ Household data synced successfully"))}catch(B){console.error("⚠️ Failed to sync household data:",B)}U({title:"Success",description:"Profile updated successfully!"}),await w()}catch(n){console.error("Error updating profile:",n),U({title:"Error",description:"An unexpected error occurred while saving.",variant:"destructive"})}finally{j(!1)}}},v=(n,A)=>
40{_(G=>({...G,[n]:A}))},L=async n=>{var G;const A=(G=n.target.files)==null?void 0:G[0];if(!(!A||!a)){console.log("📸 Uploading avatar image for user:",a.id),P(!0);try{const D=A.name.split(".").pop(),ee=`${a.id}/avatar.${D}`,{error:z}=await E.storage.from("avatars").upload(ee,A,{upsert:!0});if(z)throw console.error("Upload error:",z),z;const{data:Z}=E.storage.from("avatars").getPublicUrl(ee),se=`${Z.publicUrl}?t=${Date.now()}`;console.log("🖼️ Generated avatar URL:",se),v("avatar_url",se),l(W=>W&&{...W,avatar_url:se});const{error:ie}=await E.from("profiles").update({avatar_url:se}).eq("user_id",a.id);if(ie)throw console.error("Database save error:",ie),ie;console.log("✅ Avatar uploaded and saved successfully"),U({title:"Success",description:"Profile image uploaded and saved successfully"})}catch(D){console.error("Error uploading image:",D),U({title:"Error",description:"Failed to upload image. Please try again.",variant:"destructive"})}finally{P(!1)}}};return h?e.jsx(F,{className:"card-tile-gradient p-4",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx($,{className:"h-5 w-5 text-on-tile-muted animate-spin"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium",children:"Loading Profile..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Fetching your account details"})]})]})}):e.jsxs(F,{className:"card-tile-gradient overflow-hidden rounded-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 cursor-pointer hover:bg-white/5 transition-colors duration-200",onClick:()=>{const n=!y;N(n),n||localStorage.setItem("profile_auto_expand_dismissed","true")},children:[e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px] flex-1",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:e.jsx(Ae,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-base",children:"Profile Information"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c?"Edit your account details":"Your account details from onboarding"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[c?e.jsxs("div",{className:"flex space-x-2",onClick:n=>n.stopPropagation(),children:[e.jsx(S,{variant:"ghost",size:"sm",onClick:m,disabled:f,className:"min-h-[44px] min-w-[44px] rounded-2xl p-2 hover:bg-white/10",children:e.jsx(ae,{className:"h-4 w-4"})}),e.jsx(S,{variant:"primary",size:"sm",onClick:k,disabled:f,className:"min-h-[44px] min-w-[44px] rounded-2xl p-2",children:f?e.jsx($,{className:"h-4 w-4 animate-spin"}):e.jsx(Fe,{className:"h-4 w-4"})})]}):e.jsxs(S,{variant:"secondary",size:"sm",onClick:n=>{n.stopPropagation(),M(),N(!0)},className:"min-h-[44px] px-4 rounded-2xl",children:[e.jsx(Nt,{className:"h-4 w-4 mr-2"}),"Edit"]}),e.jsx(Ce,{className:`h-5 w-5 text-muted-foreground transition-transform duration-200 ${y?"rotate-180":""}`})]})]}),e.jsx("div",{className:`overflow-hidden transition-all duration-300 ease-out ${y?"max-h-[90vh] opacity-100":"max-h-0 opacity-0"}`,onClick:()=>{y?(localStorage.setItem("profileSectionCollapsed","true"),I(!0)):(localStorage.removeItem("profileSectionCollapsed"),I(!1))},children:e.jsxs("div",{className:"px-4 sm:px-6 pb-6 space-y-6 overflow-y-auto max-h-[80vh]",children:[e.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsxs(Fs,{className:"h-20 w-20 sm:h-24 sm:w-24",children:[e.jsx(qs,{src:i.avatar_url||(s==null?void 0:s.avatar_url)||void 0},i.avatar_url||(s==null?void 0:s.avatar_url)),e.jsxs(Rs,{className:"text-base sm:text-lg bg-primary/20 rounded-2xl",children:[((X=i.first_name)==null?void 0:X[0])||((R=s==null?void 0:s.first_name)==null?void 0:R[0]),((ve=i.last_name)==null?void 0:ve[0])||((Q=s==null?void 0:s.last_name)==null?void 0:Q[0])]})]}),c&&e.jsxs("label",{htmlFor:"avatar-upload",className:"absolute -bottom-2 -right-2 bg-primary hover:bg-primary/80 rounded-2xl p-2 cursor-pointer transition-all duration-300 min-h-[44px] min-w-[44px] flex items-center justify-center",children:[C?e.jsx($,{className:"h-4 w-4 text-white animate-spin"}):e.jsx(At,{className:"h-4 w-4 text-white"}),e.jsx("input",{id:"avatar-upload",type:"file",accept:"image/*",className:"hidden",onChange:L,disabled:C})]})]}),c&&e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Click the camera icon to upload a profile picture. Changes are saved automatically."})]}),s&&(((ke=s.pets)==null?void 0:ke.length)>0||s.health_info||s.property_type||s.bedrooms)&&e.jsx(Qt,{data:[...s.pets&&s.pets.length>0?s.pets.map((n,A)=>({type:"pet",label:n.type?`${n.count||1} ${n.type}${(n.count||1)>1?"s":""}`:"Pet",value:n.discovered_at?`Added ${new Date(n.discovered_at).toLocaleDateString()}`:"",source:"insurance search",discoveredAt:n.discovered_at||""})):[],...s.health_info&&Object.keys(s.health_info).length>0?[{type:"health",label:"Health Information",value:((ye=s.health_info.conditions)==null?void 0:ye.join(", "))||s.health_info.notes||"Recorded",source:"insurance search",discoveredAt:s.health_info.discovered_at||""}]:[],...s.property_type?[{type:"property",label:"Property Type",value:s.property_type,source:"insurance search",discoveredAt:""}]:[],...s.bedrooms?[{type:"other",label:"Bedrooms",value:`${s.bedrooms} bedroom${s.bedrooms!==1?"s":""}`,source:"property search",discoveredAt:""}]:[]]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"first_name",className:"text-sm font-medium",children:"First Name"}),c?e.jsx(T,{id:"first_name",value:i.first_name,onChange:n=>v("first_name",n.target.value),placeholder:"Enter your first name",autoComplete:"given-name",className:"input-glass h-12 rounded-2xl"}):e.jsx("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:(s==null?void 0:s.first_name)||"Not provided"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"last_name",className:"text-sm font-medium",children:"Last Name"}),c?e.jsx(T,{id:"last_name",value:i.last_name,onChange:n=>v("last_name",n.target.value),placeholder:"Enter your last name",autoComplete:"family-name",className:"input-glass h-12 rounded-2xl"}):e.jsx("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:(s==null?void 0:s.last_name)||"Not provided"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"email",className:"text-sm font-medium",children:"Email"}),c?e.jsx(T,{id:"email",type:"email",inputMode:"email",value:i.email,onChange:n=>v("email",n.target.value),placeholder:"Enter your email",autoComplete:"email",className:"input-glass h-12 rounded-2xl"}):e.jsx("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:(s==null?void 0:s.email)||"Not provided"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"phone",className:"text-sm font-medium",children:"Phone Number"}),c?e.jsx(T,{id:"phone",type:"tel",inputMode:"tel",value:i.phone,onChange:n=>v("phone",n.target.value),placeholder:"Enter your phone number",autoComplete:"tel",className:"input-glass h-12 rounded-2xl"}):e.jsx("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:s!=null&&s.phone&&s.phone.length>20?"Phone number added ✓":(s==null?void 0:s.phone)||"Not provided"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"date_of_birth",className:"text-sm font-medium",children:"Date of Birth"}),c?e.jsx(T,{id:"date_of_birth",type:"date",value:i.date_of_birth,onChange:n=>v("date_of_birth",n.target.value),autoComplete:"bday",className:"input-glass h-12 rounded-2xl"}):e.jsx("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:s!=null&&s.date_of_birth?new Date(s.date_of_birth).toLocaleDateString():"Not provided"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(O,{htmlFor:"address",className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(ns,{className:"h-4 w-4"}),"Address"]}),c?e.jsxs(e.Fragment,{children:[e.jsx(yt,{value:i.address||"",onChange:n=>v("address",n),onAddressSelect:n=>{console.log("📍 Address data received:",n),_(A=>({...A,address:n.formatted,street:n.street||A.street||"",city:n.city||A.city||"",postal_code:n.postalCode||A.postal_code||"",postcode:n.postalCode||A.postcode||"",country:n.country||A.country||"",country_code:n.countryCode||A.country_code||"",lat:n.lat??A.lat,lng:n.lng??A.lng}))},placeholder:"Enter your address",className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Please select from the dropdown suggestions to ensure accurate location data"})]}):e.jsx("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:(s==null?void 0:s.address)||"Not provided"}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-blue-500/10 border border-blue-500/20 rounded-2xl p-3 mb-4 mt-4",children:[e.jsx("p",{className:"text-xs text-blue-400 font-medium mb-2",children:"Current Location Data:"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(s==null?void 0:s.country_code)&&e.jsxs(Y,{variant:"outline",className:"text-xs",children:["Country: ",s.country_code]}),(s==null?void 0:s.postcode)&&e.jsxs(Y,{variant:"outline",className:"text-xs",children:["Postcode: ",s.postcode]}),(s==null?void 0:s.city)&&e.jsxs(Y,{variant:"outline",className:"text-xs",children:["City: ",s.city]}),!(s!=null&&s.country_code)&&!(s!=null&&s.postcode)&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"No location data saved"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Country Code"}),e.jsx(T,{value:i.country_code||"",onChange:n=>v("country_code",n.target.value.toUpperCase().slice(0,2)),placeholder:(s==null?void 0:s.country_code)||"e.g. DK, GB, US",maxLength:2,autoComplete:"country",className:"input-glass h-12 rounded-2xl"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"2-letter ISO country code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Postal Code"}),e.jsx(T,{value:i.postcode||"",onChange:n=>v("postcode",n.target.value),placeholder:(s==null?void 0:s.postcode)||"Enter postal code",autoComplete:"postal-code",className:"input-glass h-12 rounded-2xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"city",children:"City"}),e.jsx(T,{id:"city",value:i.city||"",onChange:n=>v("city",n.target.value),placeholder:(s==null?void 0:s.city)||"Enter city",className:"input-glass h-12 rounded-2xl"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter your city for accurate local searches"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Country"}),e.jsx(T,{value:i.country||"",onChange:n=>v("country",n.target.value),placeholder:(s==null?void 0:s.country)||"Enter country name",className:"input-glass h-12 rounded-2xl"})]})]}),!c&&((s==null?void 0:s.country)||(s==null?void 0:s.postcode)||(s==null?void 0:s.city))&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[(s==null?void 0:s.country)&&e.jsxs(Y,{variant:"secondary",className:"flex items-center gap-1.5 px-3 py-1.5 bg-white/10 border-white/20",children:[e.jsx(Ne,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:s.country}),s.country_code&&e.jsxs("span",{className:"ml-1 opacity-70",children:["(",s.country_code,")"]})]}),(s==null?void 0:s.postcode)&&e.jsxs(Y,{variant:"secondary",className:"flex items-center gap-1.5 px-3 py-1.5 bg-white/10 border-white/20",children:[e.jsx(Ft,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:s.postcode})]}),(s==null?void 0:s.city)&&e.jsxs(Y,{variant:"secondary",className:"flex items-center gap-1.5 px-3 py-1.5 bg-white/10 border-white/20",children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:s.city})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(O,{htmlFor:"household_size",className:"text-sm font-medium flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:e.jsx(je,{className:"h-4 w-4 text-primary"})}),"Number of Adults in Household"]}),c?e.jsx(T,{id:"household_size",type:"number",inputMode:"numeric",min:"1",max:"10",value:i.household_size??"",onChange:n=>{const A=n.target.value;if(A===""){v("household_size",null);return}const G=Number(A);
40if(Number.isNaN(G))return;const D=Math.max(1,Math.min(10,Math.floor(G)));v("household_size",D)},className:"input-glass h-12 rounded-2xl",placeholder:"e.g., 2"}):e.jsxs("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:[(s==null?void 0:s.household_size)||1," ",(s==null?void 0:s.household_size)===1?"adult":"adults"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(O,{htmlFor:"number_of_children",className:"text-sm font-medium flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center border border-white/20",children:e.jsx(je,{className:"h-4 w-4 text-primary"})}),"Number of Children in Household"]}),c?e.jsx(T,{id:"number_of_children",type:"number",inputMode:"numeric",min:"0",max:"10",value:i.number_of_children??"",onChange:n=>{const A=n.target.value;if(A===""){v("number_of_children",null);return}const G=Number(A);if(Number.isNaN(G))return;const D=Math.max(0,Math.min(10,Math.floor(G)));v("number_of_children",D)},className:"input-glass h-12 rounded-2xl",placeholder:"e.g., 2"}):e.jsxs("div",{className:"p-4 rounded-2xl bg-white/5 border border-white/15 min-h-[48px] flex items-center shadow-sm shadow-white/5 ring-1 ring-white/10",children:[(s==null?void 0:s.number_of_children)||0," ",(s==null?void 0:s.number_of_children)===1?"child":"children"]})]})]})})]})};function ws({isDesktopPanel:t}){const{isLoading:r,upsertRequirements:a,isUpdating:x,getRequirements:s}=Ct(),[l,c]=o.useState("mobile");return r?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx($,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set minimum requirements for offers. Offers that don't meet these will be filtered out."}),e.jsxs(_t,{value:l,onValueChange:u=>c(u),children:[e.jsxs(St,{className:"grid w-full grid-cols-2",children:[e.jsxs(os,{value:"mobile",className:"flex items-center gap-2",children:[e.jsx(kt,{className:"h-4 w-4"}),"Mobile"]}),e.jsxs(os,{value:"broadband",className:"flex items-center gap-2",children:[e.jsx(Dt,{className:"h-4 w-4"}),"Broadband"]})]}),e.jsx(ls,{value:"mobile",className:"mt-4",children:e.jsx(Wt,{requirements:s("mobile"),onSave:u=>a({serviceType:"mobile",requirements:u}),isUpdating:x})}),e.jsx(ls,{value:"broadband",className:"mt-4",children:e.jsx(Yt,{requirements:s("broadband"),onSave:u=>a({serviceType:"broadband",requirements:u}),isUpdating:x})})]})]})}function Wt({requirements:t,onSave:r,isUpdating:a}){var q,I,g;const[x,s]=o.useState(((q=t==null?void 0:t.min_data_gb)==null?void 0:q.toString())||""),[l,c]=o.useState((t==null?void 0:t.requires_5g)||!1),[u,h]=o.useState(((I=t==null?void 0:t.max_binding_months)==null?void 0:I.toString())||""),[p,f]=o.useState(((g=t==null?void 0:t.min_monthly_savings)==null?void 0:g.toString())||""),[j,y]=o.useState((t==null?void 0:t.excluded_providers)||[]),[N,i]=o.useState(""),_=async()=>{try{await r({min_data_gb:x?parseInt(x):null,requires_5g:l,max_binding_months:u?parseInt(u):null,min_monthly_savings:p?parseInt(p):null,excluded_providers:j.length>0?j:null,source:"manual",confidence:1}),b.success("Mobile requirements saved")}catch{b.error("Failed to save requirements")}},C=()=>{N&&!j.includes(N)&&(y([...j,N]),i(""))},P=w=>{y(j.filter(M=>M!==w))};return e.jsxs(F,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"min-data",children:"Minimum Data (GB)"}),e.jsx(T,{id:"min-data",type:"number",placeholder:"e.g., 50",value:x,onChange:w=>s(w.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only show offers with at least this much data"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(O,{children:"Require 5G"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only show offers with 5G network"})]}),e.jsx(re,{checked:l,onCheckedChange:c})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"max-binding",children:"Maximum Binding (months)"}),e.jsx(T,{id:"max-binding",type:"number",placeholder:"e.g., 6",value:u,onChange:w=>h(w.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only show offers with binding period up to this"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"min-savings",children:"Minimum Monthly Savings (kr)"}),e.jsx(T,{id:"min-savings",type:"number",placeholder:"e.g., 50",value:p,onChange:w=>f(w.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only show offers that save at least this much per month"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Excluded Providers"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{placeholder:"Provider name",value:N,onChange:w=>i(w.target.value),onKeyDown:w=>w.key==="Enter"&&C()}),e.jsx(S,{type:"button",variant:"outline",onClick:C,children:"Add"})]}),j.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:j.map(w=>e.jsxs(Y,{variant:"secondary",className:"flex items-center gap-1",children:[w,e.jsx(ae,{className:"h-3 w-3 cursor-pointer",onClick:()=>P(w)})]},w))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Never show offers from these providers"})]}),e.jsxs(S,{onClick:_,disabled:a,className:"w-full",children:[a?e.jsx($,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Bs,{className:"h-4 w-4 mr-2"}),"Save Mobile Requirements"]})]})}function Yt({requirements:t,onSave:r,isUpdating:a}){var C,P,q;const[x,s]=o.useState(((C=t==null?void 0:t.min_speed_mbps)==null?void 0:C.toString())||""),[l,c]=o.useState(((P=t==null?void 0:t.max_binding_months)==null?void 0:P.toString())||""),[u,h]=o.use
40State(((q=t==null?void 0:t.min_monthly_savings)==null?void 0:q.toString())||""),[p,f]=o.useState((t==null?void 0:t.excluded_providers)||[]),[j,y]=o.useState(""),N=async()=>{try{await r({min_speed_mbps:x?parseInt(x):null,max_binding_months:l?parseInt(l):null,min_monthly_savings:u?parseInt(u):null,excluded_providers:p.length>0?p:null,source:"manual",confidence:1}),b.success("Broadband requirements saved")}catch{b.error("Failed to save requirements")}},i=()=>{j&&!p.includes(j)&&(f([...p,j]),y(""))},_=I=>{f(p.filter(g=>g!==I))};return e.jsxs(F,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"min-speed",children:"Minimum Speed (Mbps)"}),e.jsx(T,{id:"min-speed",type:"number",placeholder:"e.g., 100",value:x,onChange:I=>s(I.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only show offers with at least this speed"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"bb-max-binding",children:"Maximum Binding (months)"}),e.jsx(T,{id:"bb-max-binding",type:"number",placeholder:"e.g., 6",value:l,onChange:I=>c(I.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"bb-min-savings",children:"Minimum Monthly Savings (kr)"}),e.jsx(T,{id:"bb-min-savings",type:"number",placeholder:"e.g., 50",value:u,onChange:I=>h(I.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Excluded Providers"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{placeholder:"Provider name",value:j,onChange:I=>y(I.target.value),onKeyDown:I=>I.key==="Enter"&&i()}),e.jsx(S,{type:"button",variant:"outline",onClick:i,children:"Add"})]}),p.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:p.map(I=>e.jsxs(Y,{variant:"secondary",className:"flex items-center gap-1",children:[I,e.jsx(ae,{className:"h-3 w-3 cursor-pointer",onClick:()=>_(I)})]},I))})]}),e.jsxs(S,{onClick:N,disabled:a,className:"w-full",children:[a?e.jsx($,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Bs,{className:"h-4 w-4 mr-2"}),"Save Broadband Requirements"]})]})}function K({title:t,description:r,children:a}){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"pb-4 border-b border-border/30",children:[e.jsx("h2",{className:"text-2xl font-semibold text-foreground",children:t}),r&&e.jsx("p",{className:"text-muted-foreground mt-1",children:r})]}),e.jsx("div",{className:"space-y-6",children:a})]})}function Ns(){const{theme:t,setTheme:r}
40=at(),[a,x]=o.useState(!1);if(o.useEffect(()=>{x(!0)},[]),!a)return e.jsx("div",{className:"flex items-center gap-1 glass-card p-1 rounded-xl border border-white/10",children:e.jsx("div",{className:"w-10 h-10"})});const s=[{value:"light",icon:Pt,label:"Light"},{value:"dark",icon:Le,label:"Dark"},{value:"system",icon:It,label:"System"}];return e.jsx("div",{className:"flex items-center gap-1 glass-card p-1 rounded-xl border border-white/10",children:s.map(({value:l,icon:c,label:u})=>e.jsx("button",{onClick:()=>r(l),className:`
41            relative flex items-center justify-center
42            w-10 h-10 rounded-lg
43            transition-all duration-200
44            touch-manipulation
45            ${t===l?"bg-primary text-primary-foreground shadow-md":"text-muted-foreground hover:bg-white/5 active:bg-white/10"}
46          `,"aria-label":u,"aria-pressed":t===l,children:e.jsx(c,{className:"h-4 w-4"})},l))})}function Vt(){const{user:t}=V(),r=Ve(),{data:a,isLoading:x}=Ye({queryKey:["renegotiation-enabled",t==null?void 0:t.id],queryFn:async()=>{if(!t)return!1;const{data:l,error:c}=await E.from("profiles").select("renegotiation_enabled").eq("user_id",t.id).maybeSingle();if(c)throw c;return(l==null?void 0:l.renegotiation_enabled)??!1},enabled:!!t,retry:1}),s=te({mutationFn:async l=>{if(!t)throw new Error("Not authenticated");const{error:c}=await E.from("profiles").update({renegotiation_enabled:l}).eq("user_id",t.id);if(c)throw c;return l},onMutate:async l=>{await r.cancelQueries({queryKey:["renegotiation-enabled",t==null?void 0:t.id]});const c=r.getQueryData(["renegotiation-enabled",t==null?void 0:t.id]);return r.setQueryData(["renegotiation-enabled",t==null?void 0:t.id],l),{previous:c}},onError:(l,c,u)=>{r.setQueryData(["renegotiation-enabled",t==null?void 0:t.id],u==null?void 0:u.previous),b.error("Failed to update renegotiation setting")},onSuccess:l=>{b.success(l?"Re-negotiate enabled":"Re-negotiate disabled")},onSettled:()=>{r.invalidateQueries({queryKey:["renegotiation-enabled",t==null?void 0:t.id]})}});return{isEnabled:a??!1,isLoading:x,toggleRenegotiation:s.mutate,isToggling:s.isPending}}function Ja(){const{signOut:t}=V(),r=_s(),{t:a}=Se("settings"),x=Et(),{isEnabled:s,toggleRenegotiation:l,isToggling:c}=Vt(),u=rt(),h=(()=>{const i=u.pathname;return i.includes("/settings/notifications")?"notifications":i.includes("/settings/integrations")?"integrations":i.includes("/settings/appearance")?"appearance":i.includes("/settings/language")?"language":i.includes("/settings/password")?"password":i.includes("/settings/biometric")?"biometric":i.includes("/settings/support")?"support":i.includes("/settings/household-members")?"household-members":i.includes("/settings/requirements")?"requirements":i.includes("/settings/referral")?"referral":"profile"})(),p=i=>{r(i==="profile"?"/app/settings":`/app/settings/${i}`)},f=async()=>{try{console.log("Sign out button clicked"),await t(),console.log("Sign out completed"),r("/")}catch(i){console.error("Sign out error:",i)}},j=()=>{r("/app/home")},y=()=>e.jsxs(F,{className:"card-tile-gradient p-6 rounded-2xl",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsx("div",{className:"w-12 h-12 bg-primary/15 rounded-2xl flex items-center justify-center",children:e.jsx($e,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Need Help?"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Our support team is here to assist you"})]})]}),e.jsx(S,{variant:"outline",className:"w-full",onClick:()=>window.location.href="mailto:[email protected]",children:"Contact Support"})]}),N=()=>{switch(h){case"profile":return e.jsx(K,{title:a("account.profile"),description:a("account.profileDescription"),children:e.jsx(Be,{initialExpanded:!0,isDesktopPanel:!0})});case"notifications":return e.jsx(K,{title:a("notifications.title","Notifications"),description:a("notifications.description","Manage push notifications"),children:e.jsx(ys,{isDesktopPanel:!0})});case"household-members":return e.jsx(K,{title:a("householdMembers.title","Household"),description:a("householdMembers.description","Manage members"),children:e.jsx(xs,{isDesktopPanel:!0})});case"integrations":return e.jsx(K,{title:a("integrations.title"),description:a("integrations.description"),children:e.jsx(gs,{initialExpanded:!0,isDesktopPanel:!0})});case"appearance":return e.jsx(K,{title:a("preferences.theme"),description:"Customize the look and feel",children:e.jsx(F,{className:"card-tile-gradient p-6 rounded-2xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-primary/15 rounded-2xl flex items-center justify-center",children:e.jsx(Le,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Dark Mode"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Toggle between light and dark themes"})]})]}),e.jsx(Ns,{})]})})});case"language":return e.jsx(K,{title:a("language.title"),description:a("language.description"),children:e.jsx(F,{className:"card-tile-gradient p-6 rounded-2xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-primary/15 rounded-2xl flex items-center justify-center",children:e.jsx(Ne,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Language"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose your preferred language"})]})]}),e.jsx(vs,{variant:"select",className:"w-auto"})]})})});
46case"support":return e.jsx(K,{title:a("support.title"),description:a("support.description"),children:y()});case"password":return e.jsx(K,{title:a("password.title","Password"),description:a("password.description","Update your password"),children:e.jsx(bs,{isDesktopPanel:!0})});case"biometric":return e.jsx(K,{title:a("biometric.title","Biometric"),description:a("biometric.description","Face ID / Touch ID"),children:e.jsx(ms,{isDesktopPanel:!0})});case"requirements":return e.jsx(K,{title:a("requirements.title","Service Requirements"),description:a("requirements.description","Set minimum requirements for offers"),children:e.jsx(ws,{isDesktopPanel:!0})});case"renegotiate":return e.jsx(K,{title:"Re-negotiate",description:"Negotiate better deals on your behalf",children:e.jsxs(F,{className:"card-tile-gradient p-6 rounded-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-primary/15 rounded-2xl flex items-center justify-center",children:e.jsx(Te,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:"Re-negotiate"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Allow SwitchIt to contact your providers to negotiate better rates on your behalf"})]})]}),e.jsx(re,{checked:s,onCheckedChange:i=>l(i),disabled:c})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3 ml-16",children:"We only renegotiate confirmed services where we have full details."})]})});case"referral":return e.jsx(K,{title:"Refer Friends",description:"Share SwitchIt and earn rewards",children:e.jsx(hs,{})});default:return e.jsx(K,{title:a("account.profile"),description:a("account.profileDescription"),children:e.jsx(Be,{initialExpanded:!0,isDesktopPanel:!0})})}};return x?e.jsxs("div",{className:"container mx-auto px-6 py-8 pb-28",style:{maxWidth:`${it.settings}px`},children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(S,{variant:"ghost",size:"sm",onClick:j,className:"p-2 hover:bg-foreground
46/10 rounded-xl",children:e.jsx(Pe,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:a("title")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage your account and preferences"})]})]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:j,className:"p-2 hover:bg-foreground/10 rounded-xl",children:e.jsx(ae,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-8",children:[e.jsx("aside",{className:"col-span-3",children:e.jsx(F,{className:"card-tile-gradient p-4 rounded-2xl sticky top-8",children:e.jsxs("nav",{className:"space-y-1",children:[e.jsx(Ee,{label:"Account"}),e.jsx(H,{icon:Ae,label:a("account.profile"),isActive:h==="profile",onClick:()=>p("profile")}),e.jsx(H,{icon:Ae,label:a("preferences.title"),onClick:()=>r("/app/preferences")}),e.jsx(H,{icon:cs,label:a("householdProfile.title"),onClick:()=>r("/app/household-profile")}),e.jsx(H,{icon:je,label:a("householdMembers.title","Household"),isActive:h==="household-members",onClick:()=>p("household-members")}),e.jsx(Ee,{label:"Settings"}),e.jsx(H,{icon:$s,label:a("notifications.title","Notifications"),isActive:h==="notifications",onClick:()=>p("notifications")}),e.jsx(H,{icon:Ts,label:a("integrations.title"),isActive:h==="integrations",onClick:()=>p("integrations")}),e.jsx(H,{icon:ds,label:a("requirements.title","Requirements"),isActive:h==="requirements",onClick:()=>p("requirements")}),e.jsx(H,{icon:Te,label:"Re-negotiate",isActive:h==="renegotiate",onClick:()=>p("renegotiate")}),e.jsx(H,{icon:oe,label:"Refer Friends",isActive:h==="referral",onClick:()=>p("referral")}),e.jsx(H,{icon:Le,label:a("preferences.theme"),isActive:h==="appearance",onClick:()=>p("appearance")}),e.jsx(H,{icon:Ne,label:a("language.title"),isActive:h==="language",onClick:()=>p("language")}),e.jsx(Ee,{label:"Security"}),e.jsx(H,{icon:Ue,label:a("privacy.title"),onClick:()=>r("/app/privacy")}),e.jsx(H,{icon:Gs,label:a("password.title","Password"),isActive:h==="password",onClick:()=>p("password")}),e.jsx(H,{icon:Qe,label:a("biometric.title","Biometric"),isActive:h==="biometric",onClick:()=>p("biometric")}),e.jsx(Ee,{label:"Help"}),e.jsx(H,{icon:$e,label:a("support.title"),isActive:h==="support",onClick:()=>p("support")}),e.jsx("div",{className:"pt-4 mt-4 border-t border-border/20",children:e.jsx(H,{icon:Os,label:a("signOut"),variant:"destructive",onClick:f})})]})})}),e.jsx("main",{className:"col-span-9",children:e.jsx(F,{className:"card-tile-gradient p-8 rounded-2xl min-h-[600px]",children:N()})})]})]}):h==="support"?e.jsxs("div",{className:"container max-w-lg mx-auto px-4 py-6 pb-28",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>
46r("/app/settings"),className:"p-2 hover:bg-foreground/10 rounded-2xl min-h-[44px] min-w-[44px]",children:e.jsx(Pe,{className:"h-5 w-5"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:a("support.title")})]})}),e.jsx("div",{className:"space-y-4",children:y()})]}):h==="requirements"?e.jsxs("div",{className:"container max-w-lg mx-auto px-4 py-6 pb-28",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>r("/app/settings"),className:"p-2 hover:bg-foreground/10 rounded-2xl min-h-[44px] min-w-[44px]",children:e.jsx(Pe,{className:"h-5 w-5"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:a("requirements.title","Requirements")})]})}),e.jsx(ws,{})]}):e.jsxs("div",{className:"container max-w-lg mx-auto px-4 py-6 pb-28",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(S,{variant:"ghost",size:"sm",onClick:j,className:"p-2 hover:bg-foreground
46/10 rounded-2xl min-h-[44px] min-w-[44px]",children:e.jsx(Pe,{className:"h-5 w-5"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:a("title")})]}),e.jsx(S,{variant:"ghost",size:"sm",onClick:j,className:"p-2 hover:bg-foreground/10 rounded-2xl min-h-[44px] min-w-[44px]",children:e.jsx(ae,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Be,{initialExpanded:!1}),e.jsx(F,{className:"card-tile-gradient p-4 cursor-pointer hover:scale-[1.02] active:scale-[0.98] transition-all duration-200 rounded-2xl",onClick:()=>r("/app/preferences"),children:e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(Ae,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("preferences.title")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("preferences.description")})]})]})}),e.jsx(F,{className:"card-tile-gradient p-4 cursor-pointer hover:scale-[1.02] active:scale-[0.98] transition-all duration-200 rounded-2xl",onClick:()=>r("/app/household-profile"),children:e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(cs,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("householdProfile.title")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("householdProfile.description")})]})]})}),e.jsx(ys,{}),e.jsx(xs,{}),e.jsx(hs,{}),e.jsx(gs,{initialExpanded:!1}),e.jsx(F,{className:"card-tile-gradient p-4 cursor-pointer hover:scale-[1.02] active:scale-[0.98] transition-all duration-200 rounded-2xl",onClick:()=>p("requirements"),children:e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(ds,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("requirements.title","Requirements")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("requirements.description","Set minimum requirements for offers")})]})]})}),e.jsxs(F,{className:"card-tile-gradient p-4 rounded-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between min-h-[44px]",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(Te,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:"Re-negotiate"}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:"Negotiate better deals on your behalf"})]})]}),e.jsx(re,{checked:s,onCheckedChange:i=>l(i),disabled:c})]}),e.jsx("p",{className:"text-xs text-on-tile-muted mt-2 ml-13",children:"We only renegotiate confirmed services where we have full details."})]}),e.jsx(F,{className:"card-tile-gradient p-4 rounded-2xl",children:e.jsxs("div",{className:"flex items-center justify-between min-h-[44px]",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(Le,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("preferences.theme")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("preferences.themeLight")})]})]}),e.jsx(Ns,{})]})}),e.jsx(F,{className:"card-tile-gradient p-4 rounded-2xl",children:e.jsxs("div",{className:"flex items-center justify-between min-h-[44px]",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(Ne,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("language.title")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("language.description")})]})]}),e.jsx(vs,{variant:"select",className:"w-auto"})]})}),e.jsx(F,{className:"card-tile-gradient p-4 cursor-pointer hover:scale-[1.02] active:scale-[0.98] transition-all duration-200 rounded-2xl",onClick:()=>r("/app/privacy"),children:e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx(Ue,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("privacy.title")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("privacy.description")})]})]})}),e.jsx(F,{className:"card-tile-gradient p-4 cursor-pointer hover:scale-[1.02] active:scale-[0.98] transition-all duration-200 rounded-2xl",onClick:()=>p("support"),children:e.jsxs("div",{className:"flex items-center space-x-3 min-h-[44px]",children:[e.jsx("div",{className:"w-10 h-10 bg-primary/15 backdrop-blur-sm rounded-2xl flex items-center justify-center",children:e.jsx($e,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-base text-on-tile",children:a("support.title")}),e.jsx("p",{className:"text-sm text-on-tile-muted",children:a("support.description")})]})]})}),e.jsx(bs,{}),e.jsx(ms,{}),e.jsx("div",{className:"pt-4",children:e.jsx(S,{variant:"glass",className:"w-full h-12 rounded-2xl text-base font-medium",onClick:f,children:a("signOut")})})]})]})}export{Ja 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.