1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/analytics-DZfAxZm8.js","assets/index-DGo-vssZ.js","assets/vendor-Qgthw7N1.js","assets/index-C2doZrJs.css","assets/useParallelQueries-BP3is_yX.js","assets/activity-BpWmCysw.js","assets/generateCategoricalChart-Ccg4ytiv.js","assets/PieChart-DvPtr6vS.js","assets/LineChart-D1bfgCBJ.js","assets/AreaChart-CfNv0fRv.js"])))=>i.map(i=>d[i]); 2import{z as vt,aa as Yt,fx as ea,j as e,a_ as He,bT as qe,bU as ze,q as ge,a0 as Me,a1 as Ee,a2 as De,a3 as Pe,a4 as re,e as te,bV as Ge,a as fe,aM as Re,aE as ce,aG as me,B as q,bw as ht,cR as Ua,ah as ne,aL as H,a7 as Q,r as le,fy as ta,L as W,N as ye,d7 as sa,Y as pt,bL as aa,da as pe,aF as zt,bp as Ae,aK as Te,aJ as Ns,C as xe,b as Nt,c as wt,i as je,X as se,d as ie,fz as ws,cs as Ka,bX as oe,b1 as Ne,b2 as Ie,b3 as Le,b4 as _e,b5 as Gt,ck as Ya,fA as Ba,dd as ra,cq as na,fB as ds,fC as ia,fD as la,ba as tt,cU as cs,aI as st,_ as ms,fE as Wa,fF as ks,bb as kt,bc as Ct,bd as St,db as Vt,ae as at,f as gt,bk as rt,Z as Qt,bn as ve,ad as oa,au as Fe,aB as Ve,aO as ft,G as xs,I as us,J as bt,K as yt,bj as nt,bS as da,aZ as ca,ao as ma,d8 as it,F as Lt,a6 as as,U as Ja,aR as Xa,be as xa,p as Tt,dD as Za,fG as er,fH as Cs,fI as tr,fJ as sr,bY as rs,by as Ss,fK as Ts,fL as ua,dI as Ms,aQ as jt,cI as ar,b6 as ha,l as pa,m as Ft,n as Rt,o as It,cO as rr,b0 as lt,dL as ga,b8 as nr,aH as fa,bR as hs,T as Es,fM as ir,fN as lr,fO as or,d9 as ba,d6 as Bt,bK as dr,fP as cr,dS as mr,fQ as xr,fR as ur,cu as ns,fS as hr,fT as pr,fU as gr,dE as fr,dF as br,dG as yr,dH as Ds,c_ as ya,fV as jr,fW as _t,fX as Ot,fY as vr,fZ as Nr,f_ as Ps,f$ as As,aS as wr,g0 as kr,g1 as ja,g2 as Cr,cW as Sr,bf as $t,M as va,ac as Tr,g as Mr,aC as Er,b7 as Dr,aN as Na,h as ps,s as Pr,bM as Ar,D as Fs,O as Fr,$ as wa,an as Rr,dR as Ir,R as dt,V as ct,aT as Lr,aU as _r,aV as Rs,aW as Je,aX as Or,aY as Xe,g3 as $r,g4 as Hr,g5 as qr,g6 as zr,d5 as Gr,dJ as Vr}from"./index-DGo-vssZ.js";import{r as d,u as Mt,a as ka}from"./vendor-Qgthw7N1.js";import{S as gs,a as Qr}from"./useParallelQueries-BP3is_yX.js";import{h as Ur,i as Kr,j as Yr,e as Br,k as Is}from"./CalendarDateRangeFilter-oz7Dy0YO.js";import{i as Ht}from"./authUtils-CcDzk6i0.js";import{S as Wr,a as Ca,b as Sa}from"./index-B1ky1Hhc.js";import{u as fs}from"./useAutomation-B2DSQfVe.js";import{u as Ta,T as Jr,a as Xr,b as Ma,c as Zr,d as en,A as Ea,e as tn,M as Ls}from"./MailActivityCard-CBdQYMfk.js";import{a as sn}from"./automationService-OVbtW0oB.js";import{C as ot}from"./circle-x--5-vDMIU.js";import{u as Da,C as an}from"./CalendarView-B7MNTFos.js";import{C as ut}from"./checkbox-i5ygXx_L.js";import{C as rn}from"./CalendarStatusLegend-XQseVSnX.js";import{P as nn}from"./plug-zap-BZPclcEu.js";import{C as bs}from"./calendar-days-COgXMVIl.js";import{T as ys}from"./timer-DEA0yRXX.js";import{P as is}from"./play-Du1KHNWc.js";import{P as ln}from"./pause-BtInyhHa.js";import{S as Pa,t as _s,A as on}from"./timeEntryService-DCnrU_uK.js";import{T as dn,a as Wt}from"./toggle-group-CZTHaXSB.js";import{B as cn}from"./brain-B45HfaeR.js";import{M as mn}from"./maximize-2-6AmOphWr.js";import{E as Aa,R as Fa}from"./RepsClassificationSection-CqSsZHO1.js";import{S as xn}from"./server-DuiuGkfi.js";import{C as un}from"./ImapProviderPicker-IRBlFdn0.js";import{M as Dt,a as hn}from"./MobileImapConnectSheet-h12j6IgX.js";import{a as pn}from"./ImapConnectionDialog-bvgeU80F.js";import"./differenceInMonths-Cb0HIyJb.js";import"./index-COtV6X2D.js";import"./filter-D8zDqrI6.js";/** 3 * @license lucide-react v0.453.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const gn=vt("CalendarCheck",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"m9 16 2 2 4-4",key:"19s6y9"}]]);/** 8 * @license lucide-react v0.453.0 - ISC 9 * 10 * This source code is licensed under the ISC license. 11 * See the LICENSE file in the root directory of this source tree. 12 */const fn=vt("Gift",[["rect",{x:"3",y:"8",width:"18",height:"4",rx:"1",key:"bkv52"}],["path",{d:"M12 8v13",key:"1c76mn"}],["path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7",key:"6wjy6b"}],["path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5",key:"1ihvrl"}]]);/** 13 * @license lucide-react v0.453.0 - ISC 14 * 15 * This source code is licensed under the ISC license. 16 * See the LICENSE file in the root directory of this source tree. 17 */const bn=vt("Minimize2",[["polyline",{points:"4 14 10 14 10 20",key:"11kfnr"}],["polyline",{points:"20 10 14 10 14 4",key:"rlmsce"}],["line",{x1:"14",x2:"21",y1:"10",y2:"3",key:"o5lafz"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/** 18 * @license lucide-react v0.453.0 - ISC 19 * 20 * This source code is licensed under the ISC license. 21 * See the LICENSE file in the root directory of this source tree. 22 */const yn=vt("PanelRightClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]]);/** 23 * @license lucide-react v0.453.0 - ISC 24 * 25 * This source code is licensed under the ISC license. 26 * See the LICENSE file in the root directory of this source tree. 27 */const jn=vt("PanelRightOpen",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m10 15-3-3 3-3",key:"1pgupc"}]]);
27function vn(t,a){const s=Yt(t.start),r=Yt(t.end);let n=+s>+r;const i=n?+s:+r,l=n?r:s;l.setHours(0,0,0,0);let o=1;const f=[];for(;+l<=i;)f.push(Yt(l)),l.setDate(l.getDate()+o),l.setHours(0,0,0,0);return n?f.reverse():f}function Nn(t,a){return ea(t,-1)}function ls({selectedYear:t,onYearChange:a,currentYear:s=new Date().getFullYear(),compact:r=!1}){const n=Array.from({length:s-2022+1},(l,o)=>s-o),i=t!==s;return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(He,{children:e.jsxs(qe,{children:[e.jsx(ze,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx(ge,{className:r?"h-4 w-4 text-gray-600 dark:text-gray-400 flex-shrink-0":"h-5 w-5 text-gray-600 dark:text-gray-400 flex-shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsxs(Me,{value:t.toString(),onValueChange:l=>a(parseInt(l)),children:[e.jsx(Ee,{className:`w-full min-w-[100px] max-w-[140px]${r?" h-8 text-sm":""}`,children:e.jsx(De,{placeholder:"Select Year"})}),e.jsx(Pe,{children:n.map(l=>e.jsx(re,{value:l.toString(),children:l},l))})]}),i&&e.jsx(te,{variant:"secondary",className:"text-xs flex-shrink-0 hidden sm:inline-flex",children:"Past Year"})]})]})}),e.jsx(Ge,{children:e.jsx("p",{children:"Select a tax year to view hours and progress for that year"})})]})})})}function wn({repType:t}){const[a,s]=d.useState(!1),{toast:r}=fe(),n=Re(),i=ce({mutationFn:async h=>{const N=await me("PATCH","/api/auth/user",{repType:h});if(!N.ok){const u=await N.text();throw new Error(u)}return N.json()},onMutate:async h=>{await n.cancelQueries({queryKey:["/api/auth/user"]});const N=n.getQueryData(["/api/auth/user"]);return n.setQueryData(["/api/auth/user"],u=>u&&{...u,repType:h}),{previousUser:N}},onSuccess:h=>{n.setQueryData(["/api/auth/user"],h),n.invalidateQueries({queryKey:["/api/stats"]}),n.invalidateQueries({queryKey:["/api/time-entries"]}),r({title:"REP Type Updated",description:"Your REP status type has been updated successfully"})},onError:(h,N,u)=>{u!=null&&u.previousUser&&n.setQueryData(["/api/auth/user"],u.previousUser),r({title:"Error",description:"Failed to update REP type",variant:"destructive"})}}),l=h=>{h!==t&&(h==="shortTerm"?s(!0):i.mutate("longTerm"))},o=t==="longTerm",f=t==="shortTerm",x=i.isPending;return e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"mb-2 text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Time-tracking Strategy:"}),e.jsx("div",{className:"rounded-lg border border-gray-200 bg-white p-3 dark:border-gray-700 dark:bg-gray-800",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex flex-1 items-center rounded-full bg-gray-100 p-0.5 dark:bg-gray-700",children:[e.jsx(q,{variant:o?"default":"ghost",size:"sm",className:`h-8 flex-1 rounded-full px-3 text-xs font-medium transition-all ${o?"bg-green-600 text-white shadow-sm hover:bg-green-700":"bg-transparent text-gray-600 hover:bg-gray-200 dark:text-gray-400 dark:hover:bg-gray-600"} ${x?"opacity-75":""}`,onClick:()=>l("longTerm"),disabled:x,children:"REP Status"}),e.jsx(q,{variant:f?"default":"ghost",size:"sm",className:`h-8 flex-1 rounded-full px-3 text-xs font-medium transition-all ${f?"bg-green-600 text-white shadow-sm hover:bg-green-700":"bg-transparent text-gray-600 hover:bg-gray-200 dark:text-gray-400 dark:hover:bg-gray-600"} ${x?"opacity-75":""}`,onClick:()=>l("shortTerm"),disabled:x,children:"STR Loophole"})]}),e.jsx(te,{variant:"outline",className:"flex-shrink-0 text-xs",children:o?"750 hrs":f?"500 + 100 hrs":"750 hrs"})]})}),e.jsx(gs,{isOpen:a,onClose:()=>s(!1),onSelectionComplete:()=>s(!1)})]})}function kn(){const t=new Date().getHours();return t<12?"Good morning":t<18?"Good afternoon":"Good evening"}function Cn(t){var a;return t.firstName||((a=t.email)==null?void 0:a.split("@")[0])||"there"}function Sn({user:t,notificationCount:a=0,onNotificationsClick:s,onProfileClick:r,selectedYear:n,onYearChange:i,repType:l}){var o,f;return e.jsxs("header",{className:"pt-2",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[kn(),", ",Cn(t)," ð"]}),e.jsx("h1",{className:"mt-0.5 text-2xl font-bold leading-tight tracking-tight text-gray-900 dark:text-white",children:"Dashboard"})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("button",{type:"button",onClick:r,className:"flex h-11 w-11 items-center justify-center rounded-full bg-primary text-sm font-bold text-primary-foreground shadow-sm transition hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-95","aria-label":"Open profile",children:t.profileImageUrl?e.jsx(ht,{user:{id:String(t.id||""),firstName:t.firstName||void 0,lastName:t.lastName||void 0,email:t.email||void 0,profileImageUrl:t.profileImageUrl},size:"sm"}
27):(((o=t.firstName)==null?void 0:o[0])||((f=t.email)==null?void 0:f[0])||"U").toUpperCase()})})]}),e.jsx("div",{className:"mt-3",children:n!=null&&i&&e.jsx(ls,{selectedYear:n,onYearChange:i,compact:!0})}),l!=null&&e.jsx(wn,{repType:l})]})}function Tn({count:t,onClick:a}){if(t<=0)return null;const s=t===1?"time entry needs":"time entries need";return e.jsxs("button",{type:"button",onClick:a,className:"flex min-h-14 w-full items-center gap-3 rounded-2xl border border-amber-100 bg-amber-50 px-4 py-3 text-left shadow-sm transition hover:bg-amber-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400 focus-visible:ring-offset-2 active:scale-[0.99] dark:border-amber-900/50 dark:bg-amber-950/40","aria-label":`${t} ${s} review`,children:[e.jsx("span",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-xl bg-amber-200 text-amber-800 dark:bg-amber-900 dark:text-amber-200",children:e.jsx(Ua,{className:"h-5 w-5"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"block text-sm font-bold text-amber-950 dark:text-amber-100",children:[t," ",s," review"]}),e.jsx("span",{className:"block text-xs font-medium text-amber-800/80 dark:text-amber-200/80",children:"Ensure entries are properly categorized"})]}),e.jsx(ne,{className:"h-5 w-5 flex-shrink-0 text-amber-950 dark:text-amber-100"})]})}function Jt(t){return t.toFixed(1).replace(/\.0$/,"")}function Mn({percent:t}){const s=2*Math.PI*42,r=Math.max(0,Math.min(t,100)),n=s*(1-r/100);return e.jsxs("div",{className:"relative h-28 w-28 flex-shrink-0","aria-label":`${r.toFixed(1)} percent complete`,children:[e.jsxs("svg",{className:"h-28 w-28 -rotate-90",viewBox:"0 0 112 112","aria-hidden":"true",children:[e.jsx("circle",{cx:"56",cy:"56",r:42,fill:"none",stroke:"currentColor",strokeWidth:"9",className:"text-gray-200 dark:text-gray-700"}),e.jsx("circle",{cx:"56",cy:"56",r:42,fill:"none",stroke:"currentColor",strokeWidth:"9",strokeDasharray:s,strokeDashoffset:n,strokeLinecap:"round",className:"text-blue-600 transition-all duration-500"})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:"text-lg font-bold leading-none text-blue-600",children:[r.toFixed(1),"%"]}),e.jsx("span",{className:"mt-0.5 text-[9px] font-semibold uppercase tracking-wider text-blue-600",children:"Complete"})]})]})}function En(){return e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-border dark:bg-card","aria-busy":"true",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("div",{className:"h-4 w-28 rounded bg-muted"}),e.jsx("div",{className:"h-4 w-14 rounded bg-muted"})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx("div",{className:"h-28 w-28 rounded-full bg-muted"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"h-6 w-24 rounded bg-muted"}),e.jsx("div",{className:"h-2 w-full rounded bg-muted"}),e.jsx("div",{className:"h-4 w-32 rounded bg-muted"})]})]})]})}function Dn({summary:t,isLoading:a=!1,error:s,onDetailsClick:r,onTimerClick:n}){if(a)return e.jsx(En,{});const i=Math.max(0,Math.min(t.percentComplete,100));return e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-border dark:bg-card",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:"Time tracking"}),(n||r)&&e.jsxs("div",{className:"flex items-center gap-1",children:[n&&e.jsxs("button",{type:"button",onClick:n,className:"inline-flex min-h-11 items-center gap-1 rounded-lg px-2 text-xs font-semibold text-blue-600 transition hover:bg-blue-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 active:scale-95 dark:hover:bg-blue-950/40",children:[e.jsx(ys,{className:"h-4 w-4"}),"Timer"]}),r&&e.jsxs("button",{type:"button",onClick:r,className:"inline-flex min-h-11 items-center gap-1 rounded-lg px-2 text-xs font-semibold text-blue-600 transition hover:bg-blue-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 active:scale-95 dark:hover:bg-blue-950/40",children:["Details",e.jsx(ne,{className:"h-4 w-4"})]})]})]}),s?e.jsx("div",{className:"rounded-xl bg-red-50 p-4 text-sm font-medium text-red-700 dark:bg-red-950/40 dark:text-red-200",children:"Time tracking is unavailable right now."}):e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(Mn,{percent:i}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-2xl font-bold text-blue-600",children:Jt(t.totalHours)}),e.jsxs("span",{className:"ml-1 text-sm text-gray-500 dark:text-gray-400",children:["/ ",Jt(t.goalHours)," hrs"]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700",children:e.jsx("div",{className:H("h-full rounded-full bg-blue-600 transition-all duration-500"),style:{width:`${i}%`}})}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[Jt(t.remainingHours)," hrs remaining"]})]})]})]})}const Xt="reptracker_stopwatch";function Ra({hideFloatingWidget:t=!1,completionSurface:a="dialog",onSubmissionSuccess:s,onClose:r}){const{toast:n}=fe(),i=d.useRef(null),[l,o]=d.useState(!1),[f,x]=d.useState(!1),h=new Date().getFullYear(),N=()=>{try{const m=localStorage.getItem(Xt);if(m){const c=JSON.parse(m);
27if(c.isRunning&&c.startTime){const M=Date.now(),G=c.pausedTime+(M-c.startTime);return{...c,elapsedTime:G}}return c}}catch(m){console.error("Failed to load stopwatch state:",m)}return{isRunning:!1,isPaused:!1,startTime:null,pausedTime:0,elapsedTime:0}},[u,j]=d.useState(N),[b,v]=d.useState(!1),[w,g]=d.useState({date:Q(new Date,"yyyy-MM-dd"),hours:"",activityType:"",propertyId:"none",propertyType:"Long-term Rental",description:"",isMaterialParticipation:!1,evidence:null,timeStarted:"",timeEnded:""});d.useEffect(()=>{if(w.date){const c=new Date(w.date).getFullYear();c<h?(x(!0),n({title:"Previous Tax Year Selected",description:`You are logging hours for ${c}. These will not count toward your current ${h} goals.`})):x(!1)}},[w.date,h,n]);const{data:k=[]}=le({queryKey:["/api/properties"]}),C=m=>{try{localStorage.setItem(Xt,JSON.stringify(m))}catch(c){console.error("Failed to save stopwatch state:",c)}},T=()=>{try{localStorage.removeItem(Xt)}catch(m){console.error("Failed to clear stopwatch state:",m)}};d.useEffect(()=>(u.isRunning&&u.startTime?i.current=setInterval(()=>{const m=Date.now(),c=u.pausedTime+(m-u.startTime);j(M=>({...M,elapsedTime:c}))},100):i.current&&(clearInterval(i.current),i.current=null),()=>{i.current&&clearInterval(i.current)}),[u.isRunning,u.startTime,u.pausedTime]),d.useEffect(()=>{C(u)},[u]);const I=m=>{const c=Math.floor(m/1e3),M=Math.floor(c/60);return`${Math.floor(M/60).toString().padStart(2,"0")}:${(M%60).toString().padStart(2,"0")}:${(c%60).toString().padStart(2,"0")}`},p=()=>{const m=Date.now();Ba(void 0,{timer_type:"real_time_tracking"}),j(c=>({...c,isRunning:!0,isPaused:!1,startTime:m})),g(c=>({...c,timeStarted:new Date(m).toISOString()})),n({title:"Timer Started",description:"Time tracking is now active"})},O=()=>{const m=Date.now();j(c=>({...c,isRunning:!1,isPaused:!0,pausedTime:c.pausedTime+(m-c.startTime),startTime:null})),n({title:"Timer Paused",description:"Time tracking paused"})},A=()=>{const m=Date.now();j(c=>({...c,isRunning:!0,isPaused:!1,startTime:m})),n({title:"Timer Resumed",description:"Time tracking resumed"})},z=()=>{const m=Date.now(),c=u.pausedTime+(u.startTime?m-u.startTime:0),M=Math.round(c/(1e3*60*60)*1e3)/1e3,G=Math.floor(c/1e3),V=Math.floor(G/3600),U=Math.floor(G%3600/60),ae=G%60,J=`${V.toString().padStart(2,"0")}:${U.toString().padStart(2,"0")}:${ae.toString().padStart(2,"0")}`;g(Z=>({...Z,hours:M.toString(),timeEnded:new Date(m).toISOString()})),j(Z=>({...Z,isRunning:!1,isPaused:!1,elapsedTime:c})),o(!0),n({title:"Timer Stopped",description:`Logged ${J} (${M} hours). Complete your entry details.`})},$=()=>
27{j({isRunning:!1,isPaused:!1,startTime:null,pausedTime:0,elapsedTime:0}),T(),n({title:"Timer Reset",description:"Timer has been reset"})},K=ce({mutationFn:async m=>(await me("POST","/api/time-entries",m)).json(),onSuccess:()=>{ta(void 0,{entry_method:"stopwatch",hours_logged:parseFloat(w.hours),activity_type:w.activityType,has_evidence:!!w.evidence,is_material_participation:w.isMaterialParticipation,timer_duration_ms:u.elapsedTime}),R(),o(!1),$(),s==null||s(),n({title:"Time Entry Logged",description:"Your stopwatch session has been successfully logged to the Activity Ledger"})},onError:m=>{const c=m instanceof Error?m.message:"Failed to log time entry";n({title:"Error",description:c,variant:"destructive"})}}),D=()=>{if(!w.activityType){n({title:"Missing Information",description:"Please select an activity type",variant:"destructive"});return}const m=new FormData;m.append("date",w.date),m.append("hours",w.hours),m.append("activityType",w.activityType),m.append("propertyId",w.propertyId),m.append("propertyType",w.propertyType),m.append("description",w.description),m.append("isMaterialParticipation",w.isMaterialParticipation.toString()),m.append("source","stopwatch"),m.append("timeStarted",w.timeStarted),m.append("timeEnded",w.timeEnded),w.evidence&&m.append("evidence",w.evidence),K.mutate(m)},R=()=>{const m=c=>{Ya.invalidateQueries({predicate:M=>{const[G]=M.queryKey;return typeof G=="string"&&G.startsWith(c)}})};m("/api/time-entries"),m("/api/stats/total-hours"),m("/api/stats/material-participation-hours"),m("/api/stats/activity-breakdown"),m("/api/stats/qualified-non-material-hours"),m("/api/stats/rep-progress"),m("/api/stats/rep-requirements"),m("/api/dashboard-data"),m("/api/evidence-files")};d.useEffect(()=>{const m=c=>{if(u.isRunning)return c.preventDefault(),c.returnValue="You have an active timer running. Are you sure you want to leave?",c.returnValue};return window.addEventListener("beforeunload",m),()=>window.removeEventListener("beforeunload",m)},[u.isRunning]);const E=u.isRunning||u.isPaused,_=E&&w.timeStarted?Q(new Date(w.timeStarted),"h:mm a"):null,P=a==="mobile-sheet",F=P?"z-[130]":void 0,S=`Complete Time Entry - ${I(u.elapsedTime)}`,L=e.jsxs("div",{className:P?"space-y-4 px-4 pb-6 pt-1":"space-y-4",children:[P&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Fill out the details for your timed work session and save it to your activity ledger."}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(W,{htmlFor:"date",children:"Date"}),e.jsx(ye,{id:"date",type:"date",value:w.date,onChange:m=>g(c=>({...c,date:m.target.value}))})]}),e.jsxs("div",{children:[e.jsx(sa,{value:w.hours,onChange:m=>g(c=>({...c,hours:m})),label:"Hours Worked",readOnly:!0,showQuickButtons:!1,className:"bg-green-50 border-green-200"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(te,{variant:"secondary",className:"text-xs",children:"Auto-calculated"}),e.jsxs("p",{className:"text-xs text-green-600",children:["â Time from stopwatch session (",I(u.elapsedTime),")"]})]})]})]}),f&&e.jsxs("div",{className:"bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg p-4 flex items-start gap-3",children:[e.jsx(pt,{className:"h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-semibold text-amber-800 dark:text-amber-200 text-sm mb-1",children:"Previous Tax Year Selected"}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:["You are logging hours for a previous tax year. These hours will not count toward your current ",h," goals. You can view previous year data using the Tax Year selector on the dashboard."]})]})]}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"activityType",children:"Activity Type *"}),e.jsx(aa,{value:w.activityType,onValueChange:m=>{const c=pe[m];g(M=>({...M,activityType:m,isMaterialParticipation:(c==null?void 0:c.autoEnable)||!1}))},placeholder:"Select or type activity type...",popoverContentClassName:F})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(W,{htmlFor:"property",children:"Property"}),e.jsxs(Me,{value:w.propertyId,onValueChange:m=>g(c=>({...c,propertyId:m})),children:[e.jsx(Ee,{children:e.jsx(De,{placeholder:"Select property..."})}),e.jsxs(Pe,{className:F,children:[e.jsx(re,{value:"none",children:"No property"}),k.map(m=>e.jsxs(re,{value:m.id.toString(),children:[m.nickname," - ",m.address]},m.id))]})]})]}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"propertyType",children:"Property Type"}),e.jsxs(Me,{value:w.propertyType,onValueChange:m=>g(c=>({...c,propertyType:m})),children:[e.jsx(Ee,{children:e.jsx(De,{})}),e.jsxs(Pe,{className:F,children:[e.jsx(re,{value:"Long-term Rental",children:"Long-term Rental"}),e.jsx(re,{value:"Short-term Rental",children:"Short-term Rental"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"description",children:"Description"}),e.jsx(zt,{id:"description",value:w.description,onChange:m=>g(c=>({...c,description:m.target.value})),placeholder:"Describe the work performed during this time...",rows:3})]}
27),w.propertyType==="Short-term Rental"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ae,{id:"materialParticipation",checked:w.isMaterialParticipation,onCheckedChange:m=>g(c=>({...c,isMaterialParticipation:m}))}),e.jsx(W,{htmlFor:"materialParticipation",className:"text-sm",children:"Material Participation Activity"})]}),w.activityType&&pe[w.activityType]&&e.jsx("div",{className:`p-3 rounded-lg border text-sm ${pe[w.activityType].riskLevel==="low"?"bg-green-50 border-green-200 text-green-800":pe[w.activityType].riskLevel==="moderate"?"bg-yellow-50 border-yellow-200 text-yellow-800":"bg-red-50 border-red-200 text-red-800"}`,children:e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsxs("div",{className:"flex-shrink-0 mt-0.5",children:[pe[w.activityType].riskLevel==="low"&&e.jsx("span",{className:"text-green-600",children:"â "}),pe[w.activityType].riskLevel==="moderate"&&e.jsx("span",{className:"text-yellow-600",children:"â ï¸"}),pe[w.activityType].riskLevel==="high"&&e.jsx("span",{className:"text-red-600",children:"â"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium mb-1",children:pe[w.activityType].autoEnable?"Auto-enabled for material participation":"Not auto-enabled for material participation"}),e.jsx("p",{className:"text-xs leading-relaxed",children:pe[w.activityType].explanation})]})]})})]}),e.jsxs("div",{children:[e.jsx(W,{children:"Evidence Upload (Optional)"}),e.jsxs("div",{className:`mt-2 border-2 border-dashed rounded-lg p-4 text-center transition-colors ${w.evidence?"border-green-500 bg-green-50":"border-gray-300 hover:border-gray-400"}`,onDragOver:m=>{m.preventDefault(),m.currentTarget.classList.add("border-blue-500","bg-blue-50")},onDragLeave:m=>{m.preventDefault(),m.currentTarget.classList.remove("border-blue-500","bg-blue-50")},onDrop:m=>{m.preventDefault(),m.currentTarget.classList.remove("border-blue-500","bg-blue-50");const c=m.dataTransfer.files;c.length>0&&g(M=>({...M,evidence:c[0]}))},children:[e.jsx("input",{type:"file",id:"evidence-upload",className:"hidden",accept:".pdf,.jpg,.jpeg,.png,.docx",onChange:m=>{const c=m.target.files;c&&c.length>0&&g(M=>({...M,evidence:c[0]}))}}),e.jsx("label",{htmlFor:"evidence-upload",className:"cursor-pointer",children:w.evidence?e.jsxs("div",{className:"text-green-700",children:[e.jsx("div",{className:"text-sm font-medium",children:"â File Selected"}),e.jsx("div",{className:"text-xs",children:w.evidence.name}),e.jsx("div",{className:"text-xs mt-1",children:"Click to change or drag another file"})]}):e.jsxs("div",{className:"text-gray-600",children:[e.jsx("div",{className:"text-sm",children:"Drop files here or click to browse"}),e.jsx("div",{className:"text-xs mt-1",children:"PDF, JPG, PNG, DOCX supported"})]})})]}),w.evidence&&e.jsx("p",{className:"text-xs text-green-600 mt-1",children:"File will be analyzed by AI after submission"})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-2 pt-4 sm:flex-row sm:justify-end sm:space-x-2",children:[e.jsx(q,{type:"button",variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsx(q,{onClick:D,disabled:K.isPending,children:K.isPending?"Submitting...":"Submit Entry"})]})]});return e.jsxs(e.Fragment,{children:[!t&&e.jsx("div",{className:"fixed bottom-20 right-4 z-[9999] mobile-optimized safe-area-bottom safe-area-right",style:{pointerEvents:"auto"},children:e.jsxs(Te.div,{whileHover:{scale:1.02},whileTap:{scale:.98},className:"relative",children:[e.jsxs(q,{onClick:()=>v(!b),className:` 28 relative rounded-full w-14 h-14 sm:w-16 sm:h-16 shadow-xl transition-all duration-300 border-0 touch-target 29 bg-gradient-to-br from-[#44958C] to-[#43A047] hover:opacity-95 30 text-white backdrop-blur-sm 31 `,size:"lg",children:[u.isRunning&&e.jsx(Te.div,{className:"absolute inset-0 rounded-full border-4 border-[#43A047]/40",animate:{scale:[1,1.2,1],opacity:[.8,.2,.8]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}}),e.jsx(Te.div,{initial:{scale:.8,opacity:0}
31,animate:{scale:1,opacity:1},transition:{duration:.2},children:e.jsx(ys,{className:"h-6 w-6 sm:h-7 sm:w-7"})},u.isRunning?"running":u.isPaused?"paused":"ready")]}),e.jsx(Ns,{children:E&&e.jsx(Te.div,{initial:{opacity:0,scale:.8,x:10},animate:{opacity:1,scale:1,x:0},exit:{opacity:0,scale:.8,x:10},className:"absolute right-16 sm:right-20 top-1/2 transform -translate-y-1/2",children:e.jsx("div",{className:"bg-gray-900/90 backdrop-blur-md text-white px-2 py-1 sm:px-4 sm:py-2 rounded-full text-xs sm:text-sm font-mono whitespace-nowrap shadow-2xl border border-gray-700/50",children:I(u.elapsedTime)})})})]})}),e.jsx(Ns,{children:(b||t)&&e.jsx(Te.div,{initial:t?{}:{opacity:0,x:120,scale:.85},animate:t?{}:{opacity:1,x:0,scale:1},exit:t?{}:{opacity:0,x:120,scale:.85},transition:{type:"spring",damping:25,stiffness:200,duration:.4},className:t?"w-full":"fixed bottom-20 right-20 sm:right-24 z-50 mobile-optimized safe-area-bottom safe-area-right",children:e.jsxs(xe,{className:t?"w-full rounded-2xl border border-[#e3e8e3] bg-white shadow-[0_1px_3px_rgba(16,24,40,0.06)] overflow-hidden dark:border-gray-800 dark:bg-gray-900":"w-72 sm:w-80 shadow-2xl border-0 bg-white/95 dark:bg-gray-900/95 backdrop-blur-xl rounded-2xl overflow-hidden",children:[e.jsx(Nt,{className:"px-5 pt-5 pb-0 sm:px-6",children:e.jsxs(wt,{className:"flex items-center justify-between text-base",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-[34px] w-[34px] shrink-0 items-center justify-center rounded-[10px] bg-[#dcfce7] dark:bg-[#16a34a]/15",children:e.jsx(je,{className:"h-[18px] w-[18px] text-[#16a34a]"})}),e.jsx("span",{className:"text-[17px] font-semibold text-gray-900 dark:text-white",children:"Timer"}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full px-2.5 py-[3px] text-[11px] font-semibold ${u.isRunning?"bg-[#dcfce7] text-[#166534] dark:bg-[#16a34a]/15 dark:text-green-400":u.isPaused?"bg-[#fef3c7] text-[#92400e] dark:bg-amber-500/15 dark:text-amber-400":"bg-[#f3f4f6] text-[#4b5563] dark:bg-gray-800 dark:text-gray-300"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${u.isRunning?"bg-[#22c55e] shadow-[0_0_0_3px_rgba(34,197,94,0.25)]":u.isPaused?"bg-[#f59e0b]":"bg-[#9ca3af]"}`}),u.isRunning?"Recording":u.isPaused?"Paused":"Ready to start"]})]}),(r||!t)&&e.jsx(q,{onClick:r??(()=>v(!1)),variant:"ghost",size:"sm","aria-label":"Close timer",className:"h-[30px] w-[30px] shrink-0 rounded-full p-0 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-800",children:e.jsx(se,{className:"h-4 w-4"})})]})}),e.jsxs(ie,{className:"px-5 pt-0 pb-6 sm:px-6",children:[e.jsxs("div",{className:"mt-2.5 text-center",children:[e.jsx("div",{className:"font-mono text-[46px] font-bold leading-none tabular-nums tracking-tight text-gray-900 dark:text-white",children:I(u.elapsedTime)}),e.jsxs("div",{className:"mt-2 text-[13px] text-gray-500 dark:text-gray-400",children:[(u.elapsedTime/(1e3*60*60)).toFixed(3)," ","hours logged"]}),_&&e.jsxs("div",{className:"mt-1.5 text-xs text-gray-400 dark:text-gray-500",children:["Started at ",_]})]}),e.jsxs(Te.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:"mt-[18px]",children:[e.jsx("div",{className:"flex gap-2.5",children:E?u.isRunning?e.jsxs(e.Fragment,{children:[e.jsxs(q,{onClick:O,variant:"outline",className:"h-11 sm:h-11 flex-1 rounded-xl border-[#d4d9d4] bg-white px-4 text-sm font-semibold text-[#374151] transition-all duration-200 hover:bg-gray-50 hover:text-[#374151] dark:border-gray-700 dark:bg-transparent dark:text-gray-200 dark:hover:bg-gray-800 dark:hover:text-gray-200",size:"default",children:[e.jsx(ln,{className:"h-4 w-4 mr-1.5"}),"Pause"]}),e.jsxs(q,{onClick:z,className:"h-11 sm:h-11 flex-1 rounded-xl border-0 bg-gradient-to-br from-[#44958C] to-[#43A047] px-4 text-sm font-semibold text-white shadow-[0_1px_3px_rgba(27,94,32,0.25)] transition-all duration-200 hover:opacity-95",size:"default",children:[e.jsx(ws,{className:"h-4 w-4 mr-1.5"}),"Complete"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(q,{onClick:A,className:"h-11 sm:h-11 flex-1 rounded-xl border-0 bg-gradient-to-br from-[#44958C] to-[#43A047] px-4 text-sm font-semibold text-white shadow-[0_1px_3px_rgba(27,94,32,0.25)] transition-all duration-200 hover:opacity-95",
31size:"default",children:[e.jsx(is,{className:"h-4 w-4 mr-1.5"}),"Resume"]}),e.jsxs(q,{onClick:z,variant:"outline",className:"h-11 sm:h-11 flex-1 rounded-xl border-[#d4d9d4] bg-white px-4 text-sm font-semibold text-[#374151] transition-all duration-200 hover:bg-gray-50 hover:text-[#374151] dark:border-gray-700 dark:bg-transparent dark:text-gray-200 dark:hover:bg-gray-800 dark:hover:text-gray-200",size:"default",children:[e.jsx(ws,{className:"h-4 w-4 mr-1.5"}),"Complete"]})]}):e.jsxs(q,{onClick:p,className:"h-11 sm:h-11 flex-1 rounded-xl border-0 bg-gradient-to-br from-[#44958C] to-[#43A047] px-4 text-sm font-semibold text-white shadow-[0_1px_3px_rgba(27,94,32,0.25)] transition-all duration-200 hover:opacity-95",size:"default",children:[e.jsx(is,{className:"h-4 w-4 mr-1.5"}),"Start Timer"]})}),E&&e.jsxs(q,{onClick:$,variant:"ghost",className:"mt-2.5 w-full rounded-xl py-1.5 text-xs text-gray-500 transition-all duration-200 hover:bg-gray-50 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-800",size:"sm",children:[e.jsx(Ka,{className:"h-[13px] w-[13px] mr-1.5"}),"Reset timer"]})]})]})]})})}),P?e.jsx(oe,{open:l,onOpenChange:o,title:S,swipeToDismiss:!K.isPending,children:L}):e.jsx(Ne,{open:l,onOpenChange:o,children:e.jsxs(Ie,{className:"max-w-2xl",children:[e.jsxs(Le,{children:[e.jsxs(_e,{className:"flex items-center",children:[e.jsx(je,{className:"h-5 w-5 mr-2"}),S]}),e.jsx(Gt,{children:"Fill out the details for your timed work session and save it to your activity ledger."})]}),L]})})]})}function Ze(t){return t.toFixed(1).replace(/\.0$/,"")}function Pn({percent:t}){const s=2*Math.PI*36,r=Math.max(0,Math.min(t,100)),n=s*(1-r/100);return e.jsxs("div",{className:"relative mx-auto h-24 w-24","aria-label":`${r.toFixed(1)} percent complete`,children:[e.jsxs("svg",{className:"h-24 w-24 -rotate-90",viewBox:"0 0 96 96","aria-hidden":"true",children:[e.jsx("circle",{cx:"48",cy:"48",r:36,fill:"none",stroke:"currentColor",strokeWidth:"8",className:"text-gray-200 dark:text-gray-700"}),e.jsx("circle",{cx:"48",cy:"48",r:36,fill:"none",stroke:"currentColor",strokeWidth:"8",strokeDasharray:s,strokeDashoffset:n,strokeLinecap:"round",className:"text-blue-600 transition-all duration-500"})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsxs("span",{className:"text-xl font-bold leading-none text-blue-600",children:[r.toFixed(1),"%"]}),e.jsx("span",{className:"mt-0.5 text-[10px] font-semibold uppercase tracking-wide text-blue-600",children:"Complete"})]})]})}function An({open:t,onOpenChange:a,summary:s}){return e.jsx(oe,{open:t,onOpenChange:a,title:"Time Tracking Details",children:e.jsxs("div",{className:"space-y-5 px-4 pb-6",children:[e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(Pn,{percent:s.percentComplete})}),e.jsxs("div",{className:"space-y-0.5 text-center",children:[e.jsx("span",{className:"text-3xl font-bold text-blue-600",children:Ze(s.totalHours)}),e.jsxs("span",{className:"ml-1 text-sm text-gray-500 dark:text-gray-400",children:["/ ",Ze(s.goalHours)," hrs"]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700",children:e.jsx("div",{className:H("h-full rounded-full bg-blue-600 transition-all duration-500"),style:{width:`${Math.max(0,Math.min(s.percentComplete,100))}%`}})}),e.jsxs("div",{className:"space-y-3 pt-1",children:[s.materialGoalHours!=null&&s.materialGoalHours>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-gray-50 px-4 py-3 dark:bg-gray-800/50",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Material Hours"}),e.jsxs("span",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[Ze(s.materialHours??0)," / ",Ze(s.materialGoalHours)," hrs"]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-gray-50 px-4 py-3 dark:bg-gray-800/50",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Remaining"}),e.jsxs("span",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[Ze(s.remainingHours)," hrs"]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-gray-50 px-4 py-3 dark:bg-gray-800/50",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Goal"}),e.jsxs("span",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[Ze(s.goalHours)," hrs"]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-gray-50 px-4 py-3 dark:bg-gray-800/50",children:[e.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Year"}),e.jsx("span",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:s.selectedYear})]})]}),e.jsx("div",{className:"pt-1",children:e.jsx(Ra,{hideFloatingWidget:!0,completionSurface:"mobile-sheet",onSubmissionSuccess:()=>a(!1)})})]})})}function Os({value:t,onChange:a}){const[s,r]=d.useState(!1),n=t?new Date(`${t}T00:00:00`):void 0;return e.jsxs(kt,{open:s,onOpenChange:r,children:[e.jsx(Ct,{asChild:!0,children:e.jsxs("button",{type:"button",className:H("flex h-9 w-full items-center rounded-xl border border-gray-200 bg-white px-2.5 py-1.5 text-left text-xs font-medium shadow-sm transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",!t&&"text-gray-400"),children:[e.jsx("span",{children:n?Q(n,"MMM d, yyyy"):"Pick a date"}),e.jsx(ge,{className:"ml-auto h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(St,{className:"w-auto p-0",align:"start",children:e.jsx(Vt,{mode:"single",selected:n,onSelect:i=>{i&&a(Q(i,"yyyy-MM-dd")),r(!1)},initialFocus:!0})})]})}function $s(t){return Ur(t)}function Fn(t){switch(t){case"approved":return"bg-green-500";
31case"pending":return"bg-amber-500";case"available":return"bg-blue-500"}}function Hs(t,a){const s=new Date(t),r=Q(s,"h:mm a");return a?`${r} - ${Q(new Date(a),"h:mm a")}`:r}function Rn(t,a,s){const r=ra(t),n=na(t),i=ds(r,{weekStartsOn:0}),l=ia(n,{weekStartsOn:0});return vn({start:i,end:l}).map(o=>({date:ks(o,t)?o:null,isCurrentMonth:ks(o,t),isSelected:la(o,a),isToday:Wa(o),hasEvents:s.has(Q(o,"yyyy-MM-dd"))}))}function In({events:t=[],isLoading:a=!1,isSyncing:s=!1,error:r=null,onEventClick:n,onRefresh:i,onSync:l,onVisibleRangeChange:o,onOpenCalendarList:f,onOpenAutomationSettings:x}){const[h,N]=d.useState(()=>new Date),[u,j]=d.useState(()=>new Date),[b,v]=d.useState(!1),[w,g]=d.useState(!1),[k,C]=d.useState(()=>new Date().getFullYear()),[T,I]=d.useState(""),[p,O]=d.useState(""),A=T&&p&&new Date(T)>new Date(p),z=()=>N(c=>ea(c,1)),$=()=>N(c=>Nn(c)),K=()=>{const c=new Date;N(c),j(c)},D=c=>{const M=new Date(k,c,1);N(M),g(!1)};d.useEffect(()=>{if(o){const c=ra(h),M=na(h),G=ds(c,{weekStartsOn:0}),V=ia(M,{weekStartsOn:0});o({start:G,end:V})}},[h,o]);const R=d.useMemo(()=>{if(A||!T&&!p)return t;let c=t;if(T){const M=new Date(T);M.setHours(0,0,0,0),c=c.filter(G=>new Date(G.start)>=M)}if(p){const M=new Date(p);M.setHours(23,59,59,999),c=c.filter(G=>new Date(G.start)<=M)}return c},[t,T,p,A]),E=d.useMemo(()=>{const c=new Set;for(const M of R)c.add(Q(new Date(M.start),"yyyy-MM-dd"));return c},[R]),_=d.useMemo(()=>Rn(h,u,E),[h,u,E]),P=d.useMemo(()=>R.filter(c=>la(new Date(c.start),u)),[R,u]),F=d.useMemo(()=>[...P].sort((c,M)=>new Date(c.start).getTime()-new Date(M.start).getTime()),[P]),S=d.useMemo(()=>P.filter(c=>$s(c)!=="approved").length,[P]),L=["SUN","MON","TUE","WED","THU","FRI","SAT"],m=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];return r?e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"rounded-xl bg-red-50 p-4 text-center text-sm font-medium text-red-700 dark:bg-red-950/40 dark:text-red-200",children:[e.jsx("p",{children:"Unable to load calendar events."}),i&&e.jsx("button",{type:"button",onClick:i,className:"mt-2 text-xs font-semibold text-red-700 underline underline-offset-2 hover:text-red-800 dark:text-red-200",children:"Tap to retry"})]})}):e.jsx("div",{className:"space-y-4",children:a?e.jsxs("div",{className:"space-y-4","aria-busy":"true",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-9 w-20 rounded-full bg-gray-200 dark:bg-gray-700"}),e.jsx("div",{className:"h-9 w-24 rounded-full bg-gray-200 dark:bg-gray-700"}),e.jsx("div",{className:"h-9 w-9 rounded-full bg-gray-200 dark:bg-gray-700"}),e.jsx("div",{className:"h-9 flex-1 rounded-full bg-gray-200 dark:bg-gray-700"})]}),e.jsx("div",{className:"rounded-xl border border-gray-200 overflow-hidden",children:e.jsx("div",{className:"grid grid-cols-7",children:Array.from({length:42}).map((c,M)=>e.jsx("div",{className:H("h-11 border-r border-b border-gray-200 bg-gray-50 dark:bg-gray-800",M<7&&"border-t",M%7===0&&"border-l")},M))})}),e.jsx("div",{className:"h-24 rounded-xl border border-gray-200 bg-gray-50 dark:bg-gray-800"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:K,className:H("flex-shrink-0 rounded-full border px-3.5 py-1.5 text-xs font-semibold transition","border-green-500 text-green-600 bg-white","hover:bg-green-50","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-green-500 focus-visible:ring-offset-2","active:scale-95"),"aria-label":"Go to today",children:"Today"}),e.jsxs("div",{className:"flex-shrink-0 flex items-center rounded-full border border-gray-200 bg-white overflow-hidden",children:[e.jsx("button",{type:"button",onClick:$,className:"flex items-center justify-center h-9 w-9 text-gray-500 transition hover:bg-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary active:scale-95","aria-label":"Previous month",children:e.jsx(tt,{className:"h-4 w-4"})}),e.jsx("div",{className:"h-5 w-px bg-gray-200"}),e.jsx("button",{type:"button",onClick:z,className:"flex items-center justify-center h-9 w-9 text-gray-500 transition hover:bg-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary active:scale-95","aria-label":"Next month",children:e.jsx(ne,{className:"h-4 w-4"})})]}),e.jsx("button",{type:"button",onClick:()=>{v(!b),g(!1)},className:H("flex-shrink-0 flex items-center justify-center h-9 w-9 rounded-full border transition","border-gray-200 bg-white text-gray-500","hover:bg-gray-100","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2","active:scale-95"),"aria-label":"Filter events",children:e.jsx(Pa,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button",onClick:()=>{C(h.getFullYear()),g(!w),v(!1)},className:H("flex-1 flex items-center justify-between rounded-full border px-3.5 py-1.5 transition","border-gray-200 bg-white text-gray-900","hover:bg-gray-50","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2","active:scale-95","min-w-0"),"aria-label":`Current month: ${Q(h,"MMMM yyyy")}. Tap to change month.`,children:[e.jsx("span",{className:"text-xs font-semibold truncate",children:Q(h,"MMMM yyyy")}),e.jsx(cs,{className:"h-3.5 w-3.5 ml-1 flex-shrink-0 text-gray-500"})]})]}),b&&e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-3 shadow-sm dark:border-gray-700 dark:bg-gray-900",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"mb-1.5 px-1 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Date Range"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("label",{className:"mb-0.5 block text-[10px] font-medium text-gray-500",children:"From"}),e.jsx(Os,{value:T,onChange:I})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("label",{className:"mb-0.5 block text-[10px] font-medium text-gray-500",children:"To"}),e.jsx(Os,{value:p,onChange:O})]})]}),A&&e.jsx("p",{className:"mt-1 px-1 text-[10px] text-red-500",children:"From must be before To."}),(T||p)&&e.jsx("button",{type:"button",onClick:()=>{I(""),O("")},className:"mt-1 px-1 text-[11px] font-semibold text-green-600 hover:underline",children:"Clear Range"})]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),f&&e.jsxs("button",{type:"button",onClick:()=>{v(!1),f()},className:"flex w-full items-center justify-between rounded-lg px-3 py-2.5 text-xs font-semibold text-gray-700 transition hover:bg-gray-100",children:[e.jsx("span",{children:"Calendars"}),e.jsx(ne,{className:"h-3.5 w-3.5 text-gray-400"})]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),x&&e.jsxs("button",{type:"button",onClick:()=>{v(!1),x()},className:"flex w-full items-center justify-between rounded-lg px-3 py-2.5 text-xs font-semibold text-gray-700 transition hover:bg-gray-100",children:[e.jsx("span",{children:"Calendar Automation Settings"}),e.jsx(ne,{className:"h-3.5 w-3.5 text-gray-400"})]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),l&&e.jsxs("button",{type:"button",onClick:()=>{v(!1),l()},disabled:s,className:H("flex w-full items-center gap-2 rounded-lg px-3 py-2 text-xs font-semibold transition","text-gray-600 hover:bg-gray-100","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2",s&&"cursor-not-allowed opacity-50"),children:[e.jsx(st,{className:H("h-3.5 w-3.5",
31s&&"animate-spin")}),s?"Syncing...":"Sync Calendar"]})]}),w&&e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-3 shadow-sm dark:border-gray-700 dark:bg-gray-900",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>C(c=>c-1),className:"flex h-8 w-8 items-center justify-center rounded-full text-gray-500 hover:bg-gray-100","aria-label":"Previous year",children:e.jsx(tt,{className:"h-4 w-4"})}),e.jsx("span",{className:"text-sm font-bold text-gray-900",children:k}),e.jsx("button",{type:"button",onClick:()=>C(c=>c+1),className:"flex h-8 w-8 items-center justify-center rounded-full text-gray-500 hover:bg-gray-100","aria-label":"Next year",children:e.jsx(ne,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:m.map((c,M)=>e.jsx("button",{type:"button",onClick:()=>D(M),className:H("rounded-lg py-2 text-xs font-semibold transition",M===h.getMonth()&&k===h.getFullYear()?"bg-green-500 text-white":"text-gray-700 hover:bg-gray-100"),children:c},c))})]}),e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white overflow-hidden",children:[e.jsx("div",{className:"grid grid-cols-7 bg-white border-b border-gray-200",children:L.map((c,M)=>e.jsx("div",{className:H("flex items-center justify-center h-[34px] text-[11px] font-bold uppercase tracking-wide",M===0||M===6?"text-green-600":"text-gray-500"),children:c},c))}),e.jsx("div",{className:"grid grid-cols-7",children:_.map((c,M)=>c.date===null?e.jsx("div",{className:H("h-11 border-r border-b border-gray-200",M<7&&"border-t",M%7===0&&"border-l")},`blank-${M}`):e.jsx("button",{type:"button",onClick:()=>j(c.date),className:H("relative flex items-center justify-center h-11 transition","border-r border-b border-gray-200",M<7&&"border-t",M%7===0&&"border-l","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",c.isSelected&&"bg-green-50",c.isToday&&!c.isSelected&&"ring-2 ring-green-500 ring-inset"),"aria-label":Q(c.date,"EEEE, MMMM d, yyyy"),"aria-selected":c.isSelected,children:c.isSelected?e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx("span",{className:H("flex items-center justify-center w-7 h-7 rounded-full text-sm font-bold shadow-sm","bg-green-500 text-white","relative z-10"),children:Q(c.date,"d")}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-green-500 mt-0.5"})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx("span",{className:H("text-sm font-semibold leading-none","text-gray-900"),children:Q(c.date,"d")}),c.hasEvents&&e.jsx("span",{"data-testid":"event-dot",className:"mt-0.5 h-1 w-1 rounded-full bg-green-500"})]})},c.date.toISOString()))})]}),e.jsx("div",{className:"rounded-xl border border-gray-200 bg-white px-4 py-3 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-3 min-h-[80px]",children:[e.jsx("div",{"data-testid":"detail-day-badge",className:"flex-shrink-0 w-9 h-9 rounded-full bg-green-500 text-white text-sm font-bold flex items-center justify-center shadow-sm",children:Q(u,"d")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:Q(u,"EEEE, MMMM d, yyyy")}),F.length===0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-green-500 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-gray-500",children:"No dates available to convert"})]}),e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:"You're all set for this day."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-green-500 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-gray-500",children:S>0?`${S} date${S!==1?"s":""} available to convert`:"All events approved"})]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[F.length," event",F.length!==1?"s":""," on this day"]})]})]}
31),e.jsxs("div",{className:"flex-shrink-0 w-14 h-14 rounded-2xl bg-green-50 flex items-center justify-center relative",children:[e.jsx(gn,{className:"h-6 w-6 text-green-500"}),e.jsx(ms,{className:"h-3 w-3 text-green-400 absolute -top-0.5 -right-0.5"})]})]})}),F.length>0&&e.jsx("div",{className:"rounded-xl border border-gray-200 bg-white divide-y divide-gray-100 shadow-sm dark:divide-border",children:F.map(c=>{var G,V;const M=$s(c);return e.jsxs("button",{type:"button",onClick:()=>n==null?void 0:n(c),className:"flex w-full items-center gap-3 px-4 py-3 text-left transition hover:bg-gray-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary active:bg-gray-100","aria-label":`${c.title} - ${Hs(c.start,c.end)}`,children:[e.jsx("span",{className:H("mt-0.5 h-2.5 w-2.5 flex-shrink-0 self-start rounded-full",Fn(M))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900",children:c.title||"Untitled Event"}),e.jsx("span",{className:"block truncate text-xs font-medium text-gray-500",children:Hs(c.start,c.end)}),(c.source||c.location)&&e.jsx("span",{className:"mt-0.5 block truncate text-[10px] font-medium text-gray-400",children:[((G=c.source)==null?void 0:G.charAt(0).toUpperCase())+((V=c.source)==null?void 0:V.slice(1)),c.location].filter(Boolean).join(" · ")})]}),e.jsx(ne,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})]},c.id)})})]})})}function Ln({open:t,onOpenChange:a,calendars:s=[],selectedCalendarIds:r=[],showAllCalendars:n=!0,onToggleCalendar:i,onToggleAll:l,isLoading:o=!1}){const f=n||r.length===s.length;return e.jsx(oe,{open:t,onOpenChange:a,title:"Select Calendars",children:e.jsxs("div",{className:"px-4 pb-6",children:[o?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(at,{className:"h-5 w-5 animate-spin text-gray-400"})}):s.length===0?e.jsxs("div",{className:"py-12 text-center",children:[e.jsx("p",{className:"text-sm font-medium text-gray-500",children:"No calendars found"}),e.jsx("p",{className:"mt-1 text-xs text-gray-400",children:"Connect a calendar provider to see your calendars here."})]}):e.jsxs("div",{className:"overflow-hidden rounded-xl border border-gray-200 bg-white",children:[e.jsx("button",{type:"button",onClick:l,className:"flex w-full items-center justify-between border-b border-gray-100 px-4 py-3 text-left transition hover:bg-gray-50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-5 w-5 items-center justify-center",children:f?e.jsx(gt,{className:"h-4 w-4 text-blue-500"}):e.jsx("div",{className:"h-4 w-4 rounded-sm border-2 border-gray-300"})}),e.jsx("span",{className:"text-sm font-semibold text-gray-900",children:"Show All Calendars"})]})}),s.map(x=>{const h=n||r.includes(x.id);return e.jsx("button",{type:"button",onClick:()=>i(x.id),className:H("flex w-full items-center justify-between border-b border-gray-100 px-4 py-3 text-left transition last:border-b-0","hover:bg-gray-50"),children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-5 w-5 items-center justify-center",children:h?e.jsx(gt,{className:"h-4 w-4 text-blue-500"}):e.jsx("div",{className:"h-4 w-4 rounded-sm border-2 border-gray-300"})}),x.backgroundColor&&e.jsx("div",{className:"h-3.5 w-3.5 flex-shrink-0 rounded-full border border-gray-200",style:{backgroundColor:x.backgroundColor}}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:x.name}),x.isPrimary&&e.jsx("span",{className:"rounded-full bg-green-50 px-1.5 py-0.5 text-[10px] font-semibold text-green-600",children:"Primary"})]})]})},x.id)})]}),!o&&s.length>0&&!n&&e.jsx("p",{className:"mt-3 text-center text-xs text-gray-500",children:r.length===0?"No calendars selected":`${r.length} of ${s.length} calendar${s.length!==1?"s":""} selected`})]})})}function _n({open:t,onOpenChange:a}){const{calendarAutomation:s,setCalendarAutomation:r,calendarMutation:n,addTrustedOrganizer:i}=fs(),{suggestions:l,isLoading:o}
31=Ta("calendar",!0),[f,x]=d.useState(""),[h,N]=d.useState(""),u=l.filter(k=>!s.trustedOrganizers.includes(k.email)),j=d.useCallback(()=>{const k=f.trim();k&&(i(k),x(""))},[f,i]),b=d.useCallback(k=>{const C=s.trustedOrganizers.filter(T=>T!==k);r({...s,trustedOrganizers:C}),n.mutate({...s,trustedOrganizers:C,type:"calendar"})},[s,r,n]),v=d.useCallback(()=>{const k=h.trim().toLowerCase();if(k){if(!s.trustedKeywords.includes(k)){const C=[...s.trustedKeywords,k];r({...s,trustedKeywords:C}),n.mutate({...s,trustedKeywords:C,type:"calendar"})}N("")}},[h,s,r,n]),w=d.useCallback(k=>{const C=s.trustedKeywords.filter(T=>T!==k);r({...s,trustedKeywords:C}),n.mutate({...s,trustedKeywords:C,type:"calendar"})},[s,r,n]),g=d.useCallback(k=>{i(k)},[i]);return e.jsx(oe,{open:t,onOpenChange:a,title:"Calendar Automation Settings",children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsx("p",{className:"text-xs leading-relaxed text-gray-500",children:"Automatically approve and organize real-estateârelated calendar events."}),e.jsx("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-green-50",children:e.jsx(rt,{className:"h-4 w-4 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"AI-Assisted Approval"}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"When enabled, high-confidence events are auto-approved."})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s.autoApproveHighConfidence,"aria-label":"AI-Assisted Approval toggle",onClick:()=>{const k=!s.autoApproveHighConfidence;r({...s,autoApproveHighConfidence:k}),n.mutate({...s,autoApproveHighConfidence:k,type:"calendar"})},className:H("relative h-7 w-11 flex-shrink-0 rounded-full transition-colors",s.autoApproveHighConfidence?"bg-green-500":"bg-gray-300"),children:e.jsx("span",{className:H("absolute left-0.5 top-0.5 h-6 w-6 rounded-full bg-white shadow-sm transition-transform",s.autoApproveHighConfidence&&"translate-x-4")})})]})}),e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-amber-50",children:e.jsx(Qt,{className:"h-4 w-4 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Rule-Based Approval"}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"Create conditions to auto-approve events."})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s.enabled,"aria-label":"Rule-Based Approval toggle",onClick:()=>{const k=!s.enabled;r({...s,enabled:k}),n.mutate({...s,enabled:k,type:"calendar"})},className:H("relative h-7 w-11 flex-shrink-0 rounded-full transition-colors",s.enabled?"bg-green-500":"bg-gray-300"),children:e.jsx("span",{className:H("absolute left-0.5 top-0.5 h-6 w-6 rounded-full bg-white shadow-sm transition-transform",s.enabled&&"translate-x-4")})})]}),s.enabled&&e.jsxs("div",{className:"mt-4 space-y-5 border-t border-gray-100 pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Trusted Organizers"}),s.trustedOrganizers.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:s.trustedOrganizers.map(k=>e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1",children:[e.jsx("span",{className:"text-xs font-medium text-gray-700",children:k}),e.jsx("button",{type:"button",onClick:()=>b(k),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${k}`,children:e.jsx(se,{className:"h-3 w-3"})})]},k))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"email",placeholder:"[email protected]",value:f,onChange:k=>x(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),j())},className:"min-w-0 flex-1 rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-medium text-gray-900 placeholder:text-gray-400"}),e.jsx("button",{type:"button",onClick:j,disabled:!f.trim(),className:H("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",f.trim()?"bg-green-500 text-white hover:bg-green-600":"cursor-not-allowed bg-gray-100 text-gray-400"),"aria-label":"Add organizer",children:e.jsx(ve,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Keywords"}),s.trustedKeywords.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:s.trustedKeywords.map(k=>e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1",children:[e.jsx("span",{className:"text-xs font-medium text-gray-700",children:k}),e.jsx("button",{type:"button",onClick:()=>w(k),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${k}`,children:e.jsx(se,{className:"h-3 w-3"})})]},k))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"inspection, showing, ...",value:h,onChange:k=>N(k.target.value),onKeyDown:k=>{k.key==="Enter"&&(k.preventDefault(),v())},className:"min-w-0 flex-1 rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-medium text-gray-900 placeholder:text-gray-400"}),e.jsx("button",{type:"button",onClick:v,disabled:!h.trim(),className:H("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",h.trim()?"bg-green-500 text-white hover:bg-green-600":"cursor-not-allowed bg-gray-100 text-gray-400"),"aria-label":"Add keyword",children:e.jsx(ve,{className:"h-3.5 w-3.5"})})]})]}),u.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Suggested Trusted Organizers"}),e.jsx("p",{className:"mb-2 text-xs text-gray-400",children:"Tap to approve organizers identified from your high-confidence calendar activity."}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[o&&e.jsx("p",{className:"w-full text-center text-xs text-gray-400",children:"Loading suggestions..."}),!o&&u.map(k=>e.jsx("button",{type:"button",onClick:()=>g(k.email),className:"inline-flex items-center gap-1 rounded-full border border-blue-200 bg-blue-50 px-2.5 py-1 text-xs font-medium text-blue-700 transition hover:bg-blue-100",children:k.email},k.email))]})]})]})]})]})})}function On({open:t,onOpenChange:a,selectedEvent:s,reviewFormData:r,setReviewFormData:n,evidenceFiles:i,setEvidenceFiles:l,newEvidenceFiles:o,setNewEvidenceFiles:f,properties:x,syncEventMutation:h,approveTimeEntryMutation:N,updateTimeEntryMutation:u,processEvidenceFile:j,getEventStatus:b}){const v=s?b(s):"available",w=v==="available"?"Review Calendar Event":v==="pending"?"Pending Time Entry":"Approved Time Entry";return e.jsx(oe,{open:t,onOpenChange:a,title:w,children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[v==="available"&&e.jsx(te,{className:"bg-blue-500 text-white",children:"Available to Convert"}),v==="pending"&&e.jsx(te,{className:"bg-amber-500 text-white",children:"Pending Approval"}),v==="approved"&&e.jsx(te,{className:"bg-green-500 text-white",children:"Approved"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"mobile-event-title",className:"text-base font-medium text-gray-900 dark:text-gray-100",children:"Event Title"}),e.jsx(ye,{id:"mobile-event-title",placeholder:"Enter event title",value:r.title,onChange:g=>n(k=>({...k,title:g.target.value})),className:"text-sm text-gray-700 dark:text-gray-300",disabled:v==="pending"})]}),e.jsx(Kr,{selectedEvent:s}),(s==null?void 0:s.aiConfidence)!==void 0&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-blue-200 bg-blue-50 p-4 dark:border-blue-800 dark:bg-blue-950",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-5 w-5 text-blue-600"}),e.jsx("h4",{className:"font-semibold text-blue-900 dark:text-blue-100",children:"AI Analysis"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Confidence Score"}),e.jsxs("span",{className:`text-lg font-bold ${s.aiConfidence>=90?"text-green-600":s.aiConfidence>=50?"text-amber-600":"text-gray-600"}`,children:[s.aiConfidence,"%"]})]}),e.jsx("div",{className:"h-2.5 w-full rounded-full bg-gray-200 dark:bg-gray-700",children:e.jsx("div",{className:`h-2.5 rounded-full transition-all ${s.aiConfidence>=90?"bg-green-600":s.aiConfidence>=50?"bg-amber-500":"bg-gray-400"}`,style:{width:`${s.aiConfidence}%`}})}),s.aiReasoning&&e.jsx("div",{className:"mt-3 rounded-md border border-blue-200 bg-white p-3 dark:border-blue-800 dark:bg-gray-800",children:e.jsxs("p",{className:"text-sm italic text-gray-700 dark:text-gray-300",children:["â",s.aiReasoning,"â"]})}),e.jsx("div",{className:"mt-3 rounded-md border border-blue-200 bg-white p-3 dark:border-blue-800 dark:bg-gray-800",children:e.jsx("p",{className:"flex items-start gap-2 text-xs text-gray-600 dark:text-gray-400",children:s.aiConfidence>=90?e.jsxs(e.Fragment,{children:[e.jsx(gt,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-green-600"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-green-700 dark:text-green-400",children:"Auto-approved:"})," ","High confidence (â¥90%) events are automatically converted to approved time entries."]})]}):s.aiConfidence>=50?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-amber-600"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-amber-700 dark:text-amber-400",children:"Pending review:"})," ","Medium confidence (50â89%) events need manual review before approval."]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-gray-600"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-400",children:"Manual conversion:"})," ","Low confidence (<50%) events require manual review and conversion."]})]})})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{className:"text-base font-medium text-gray-900 dark:text-gray-100",children:"Description"}),e.jsx(zt,{placeholder:"Add additional details about this event...",value:r.description,onChange:g=>{n(k=>({...k,description:g.target.value})),g.target.style.height="auto",g.target.style.height=g.target.scrollHeight+"px"},ref:g=>{g&&r.description&&(g.style.height="auto",g.style.height=g.scrollHeight+"px")},className:"resize-none overflow-hidden text-sm text-gray-700 dark:text-gray-300",style:{minHeight:"100px"}})]}),e.jsx(Aa,{evidenceFiles:i,setEvidenceFiles:l,newEvidenceFiles:o,setNewEvidenceFiles:f}),e.jsx(Fa,{reviewFormData:r,setReviewFormData:n,properties:x}),e.jsx(Yr,{eventStatus:v,selectedEvent:s,reviewFormData:r,evidenceFiles:i,setShowEventDialog:a,syncEventMutation:h,approveTimeEntryMutation:N,updateTimeEntryMutation:u,newEvidenceFiles:o})]})})}function $n(t){return{id:t.id,title:t.title||"",start:t.start,end:t.end,duration:t.duration,location:t.location,attendees:t.attendees,description:t.description,hasLedgerEntry:t.hasLedgerEntry,approvalStatus:t.approvalStatus,aiConfidence:t.aiConfidence,aiReasoning:t.aiReasoning,isRealEstateRelated:t.isRealEstateRelated,source:t.source,automationMatch:t.automationMatch,calendarId:t.calendarId,calendarName:t.calendarName,calendarColor:t.calendarColor,duplicateTimeEntryId:t.duplicateTimeEntryId}}function Hn({open:t,onOpenChange:a}){const s=Da(),{calendarEvents:r,isLoading:n,isFetching:i,error:l,properties:o,showSyncDialog:f,setShowSyncDialog:x,handleRefresh:h,handleConfirmSync:N,reviewFormData:u,setReviewFormData:j,evidenceFiles:b,setEvidenceFiles:v,newEvidenceFiles:w,setNewEvidenceFiles:g,processEvidenceFile:k,getEventStatus:C,syncEventMutation:T,updateTimeEntryMutation:I,approveTimeEntryMutation:p,setDateRange:O,availableCalendars:A,calendarsLoading:z,showAllCalendars:$,selectedCalendarIds:K,handleToggleCalendar:D,handleToggleAllCalendars:R}
31=s,E=i||n,[_,P]=d.useState(!1),[F,S]=d.useState(null),L=d.useCallback(ee=>{if(!ee)return;const ke=$n(ee);S(ke),j({title:ee.title||"",description:ee.description||"",activityType:"Property Management",propertyId:null,materialParticipation:!0,isQualifiedNonMaterial:!1,category:"real-estate"}),P(!0)},[j]),m=d.useCallback(ee=>{P(ee),ee||S(null)},[]),c=d.useCallback(()=>{P(!1),S(null)},[]);d.useEffect(()=>{T.isSuccess&&c()},[T.isSuccess,c]),d.useEffect(()=>{p.isSuccess&&c()},[p.isSuccess,c]),d.useEffect(()=>{I.isSuccess&&c()},[I.isSuccess,c]);const M=d.useCallback(ee=>{O({start:ee.start,end:ee.end})},[O]),[G,V]=d.useState(!1),U=d.useCallback(()=>{V(!0)},[]),ae=d.useCallback(ee=>{V(ee)},[]),[J,Z]=d.useState(!1),ue=d.useCallback(()=>{Z(!0)},[]),we=d.useCallback(ee=>{Z(ee)},[]),he=_&&F!==null;return e.jsxs(e.Fragment,{children:[e.jsx(oe,{open:t,onOpenChange:a,title:"Calendar",children:e.jsx("div",{className:"px-4 pb-6",children:e.jsx(In,{events:r,isLoading:n&&r.length===0,isSyncing:E,error:l,onEventClick:L,onRefresh:h,onSync:h,onVisibleRangeChange:M,onOpenCalendarList:U,onOpenAutomationSettings:ue})})}),e.jsx(Ln,{open:G,onOpenChange:ae,calendars:A,selectedCalendarIds:K,showAllCalendars:$,onToggleCalendar:D,onToggleAll:R,isLoading:z}),e.jsx(_n,{open:J,onOpenChange:we}),e.jsx(Br,{open:f,onOpenChange:x,onConfirm:N,isLoading:E}),e.jsx(On,{open:he,onOpenChange:m,selectedEvent:F,reviewFormData:u??{title:"",description:"",activityType:"Property Management",propertyId:null,materialParticipation:!0,isQualifiedNonMaterial:!1,category:"real-estate"},setReviewFormData:j,evidenceFiles:b,setEvidenceFiles:v,newEvidenceFiles:w,setNewEvidenceFiles:g,properties:o,syncEventMutation:T,approveTimeEntryMutation:p,updateTimeEntryMutation:I,processEvidenceFile:k,getEventStatus:C})]})}function qs({value:t,onChange:a}){const[s,r]=d.useState(!1),n=t?new Date(`${t}T00:00:00`):void 0;return e.jsxs(kt,{open:s,onOpenChange:r,children:[e.jsx(Ct,{asChild:!0,children:e.jsxs("button",{type:"button",className:H("flex h-9 w-full items-center rounded-xl border border-gray-200 bg-white px-2.5 py-1.5 text-left text-xs font-medium shadow-sm transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",!t&&"text-gray-400"),children:[e.jsx("span",{children:n?Q(n,"MMM d, yyyy"):"Pick a date"}),e.jsx(ge,{className:"ml-auto h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(St,{className:"w-auto p-0",align:"start",children:e.jsx(Vt,{mode:"single",selected:n,onSelect:i=>{i&&a(Q(i,"yyyy-MM-dd")),r(!1)},initialFocus:!0})})]})}function Ia(t){var s,r;if(t.hasLedgerEntry&&t.approvalStatus==="approved")return"approved";const a=t.aiConfidence||0;return a>=90?"approved":a>=50?(s=t.automationMatch)!=null&&s.matched&&((r=t.automationMatch)!=null&&r.autoApprove)?"approved":"pending":"available"}function qn(t){switch(t){case"approved":return"Approved";case"pending":return"Pending";case"available":return"Available"}}function zn(t){switch(t){case"approved":return"bg-green-50 text-green-700";case"pending":return"bg-amber-50 text-amber-700";case"available":return"bg-blue-50 text-blue-700"}}function Gn(t){return t==="gmail"?"bg-green-50 text-green-600":t==="outlook"?"bg-amber-50 text-amber-600":"bg-blue-50 text-blue-600"}function Vn(t){if(!t)return"";const a=new Date,s=new Date(t),r=a.getTime()-s.getTime(),n=Math.floor(r/864e5);return n<1?s.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):n===1?"Yesterday":n<7?s.toLocaleDateString("en-US",{weekday:"long"}):s.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Qn(t){return t.length?t[0].split("@")[0].replace(/[._-]/g," ").replace(/\b\w/g,s=>s.toUpperCase()):""}function Un(t){const a=t.trim().split(/\s+/);return a.length>=1&&a[0].length>0?a[0][0].toUpperCase():"?"}function Kn(t){return Ia(t)==="available"}const et=10,Yn=[{key:"all",label:"All"},{key:"approved",label:"Approved"},{key:"pending",label:"Pending"},{key:"available",label:"Available"}];function Bn({id:t}){switch(t){case"gmail":return e.jsx(Ca,{className:"h-3.5 w-3.5 text-red-600"});case"icloud":return e.jsx(Wr,{className:"h-3.5 w-3.5 text-sky-600"});case"yahoo":return e.jsx(Fe,{className:"h-3.5 w-3.5 text-purple-700"});case"outlook":return e.jsx(un,{className:"h-3.5 w-3.5 text-blue-700"});default:return e.jsx(xn,{className:"h-3.5 w-3.5 text-gray-400"})}}function Wn({threads:t=[],isLoading:a=!1,isSyncing:s=!1,error:r=null,activeFilter:n="all",statusCounts:i={},searchQuery:l="",connectedProvider:o,mailboxes:f=[],mailboxFilter:x=null,onMailboxChange:h,onThreadClick:N,onRefresh:u,onSync:j,onFilterChange:b,onSearchChange:v,onClose:w,onOpenMailAutomationSettings:g}
31){const[k,C]=d.useState(!1),[T,I]=d.useState(""),[p,O]=d.useState(""),A=T&&p&&new Date(T)>new Date(p),[z,$]=d.useState(1),K=d.useMemo(()=>{if(A||!T&&!p)return t;let S=t;if(T){const L=new Date(T);L.setHours(0,0,0,0),S=S.filter(m=>m.lastMessageDate&&new Date(m.lastMessageDate)>=L)}if(p){const L=new Date(p);L.setHours(23,59,59,999),S=S.filter(m=>m.lastMessageDate&&new Date(m.lastMessageDate)<=L)}return S},[t,T,p,A]),D=Math.max(1,Math.ceil(K.length/et)),R=d.useMemo(()=>{const S=(z-1)*et;return K.slice(S,S+et)},[K,z]),E=K.length>0?(z-1)*et+1:0,_=Math.min(z*et,K.length),P=()=>$(S=>Math.min(D,S+1)),F=()=>$(S=>Math.max(1,S-1));return d.useMemo(()=>K.length,[K]),r?e.jsx("div",{className:"px-6",children:e.jsxs("div",{className:"mt-4 rounded-xl bg-red-50 p-4 text-center",children:[e.jsx("p",{className:"text-sm font-medium text-red-700",children:"Unable to load emails."}),u&&e.jsx("button",{type:"button",onClick:u,className:"mt-2 text-xs font-semibold text-red-700 underline underline-offset-2 hover:text-red-800",children:"Tap to retry"})]})}):e.jsxs("div",{className:"flex flex-col flex-1 min-h-0 px-6",children:[e.jsxs("div",{className:"mt-4 flex items-start justify-between flex-shrink-0",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold tracking-tight text-gray-900",children:"Mail"}),o&&e.jsxs("div",{className:"mt-0.5 flex items-center gap-1.5",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-green-500"}),e.jsxs("span",{className:"text-xs text-gray-500",children:["Connected to ",o]})]})]}),w&&e.jsx("button",{type:"button",onClick:w,className:"flex h-9 w-9 items-center justify-center rounded-full bg-gray-100 text-gray-500 transition hover:bg-gray-200","aria-label":"Close",children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2 flex-shrink-0",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oa,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search emails...",value:l,onChange:S=>v==null?void 0:v(S.target.value),className:"h-10 w-full rounded-lg border border-gray-200 bg-white pl-9 pr-3 text-sm font-medium text-gray-900 placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500","aria-label":"Search emails"})]}),e.jsx("button",{type:"button",onClick:()=>C(!k),className:H("flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg border transition","border-gray-200 bg-white text-gray-500 hover:bg-gray-50"),"aria-label":"Filter",children:e.jsx(Pa,{className:"h-4 w-4"})})]}),k&&e.jsxs("div",{className:"mt-3 rounded-xl border border-gray-200 bg-white p-3 shadow-sm flex-shrink-0",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"mb-1.5 px-1 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Date Range"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("label",{className:"mb-0.5 block text-[10px] font-medium text-gray-500",children:"From"}),e.jsx(qs,{value:T,onChange:S=>{I(S),$(1)}})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("label",{className:"mb-0.5 block text-[10px] font-medium text-gray-500",children:"To"}),e.jsx(qs,{value:p,onChange:S=>{O(S),$(1)}})]})]}),A&&e.jsx("p",{className:"mt-1 px-1 text-[10px] text-red-500",children:"From must be before To."}),(T||p)&&e.jsx("button",{type:"button",onClick:()=>{I(""),O(""),$(1)},className:"mt-1 px-1 text-[11px] font-semibold text-green-600 hover:underline",children:"Clear Range"})]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),j&&e.jsxs("button",{type:"button",onClick:()=>{C(!1),j()},disabled:s,className:H("flex w-full items-center gap-2 rounded-lg px-3 py-2.5 text-xs font-semibold text-gray-600 transition hover:bg-gray-100",s&&"cursor-not-allowed opacity-50"),children:[e.jsx(st,{className:H("h-3.5 w-3.5",s&&"animate-spin")}),s?"Syncing...":"Sync"]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),g&&e.jsxs("button",{type:"button",onClick:()=>{C(!1),g()},className:"flex w-full items-center justify-between rounded-lg px-3 py-2.5 text-xs font-semibold text-gray-700 transition hover:bg-gray-100",children:[e.jsx("span",{children:"Mail Automation Settings"}),e.jsx(ne,{className:"h-3.5 w-3.5 text-gray-400"})]})]}),f.length>0&&e.jsxs("div",{role:"group","aria-label":"Filter by mailbox",className:"mt-3 flex gap-2 overflow-x-auto scrollbar-hide flex-shrink-0",children:[e.jsx("button",{type:"button","aria-pressed":x===null,onClick:()=>{h==null||h(null),$(1)},className:H("flex h-8 flex-shrink-0 items-center gap-1.5 rounded-full border px-3 text-xs font-medium normal-case transition",x===null?"border-gray-900 bg-gray-900 text-white":"border-gray-200 bg-white text-gray-700 hover:bg-gray-50"),children:"All mail"}),f.map(S=>{const L=S.email||S.username,m=x===S.id;return e.jsxs("button",{type:"button","aria-pressed":m,title:L,onClick:()=>
31{h==null||h(S.id),$(1)},className:H("flex h-8 flex-shrink-0 items-center gap-1.5 rounded-full border px-3 text-xs font-medium normal-case transition",m?"border-gray-900 bg-gray-900 text-white":"border-gray-200 bg-white text-gray-700 hover:bg-gray-50"),children:[S.provider&&e.jsx(Bn,{id:S.provider}),e.jsx("span",{className:"max-w-[10rem] truncate",children:L})]},S.id)})]}),e.jsx("div",{className:"mt-3 flex gap-2 overflow-x-auto scrollbar-hide flex-shrink-0",children:Yn.map(({key:S,label:L})=>{const m=i[S]??0,c=n===S;let M;return S==="approved"?M="bg-green-500":S==="pending"?M="bg-amber-500":S==="available"?M="bg-blue-500":M="bg-green-500",e.jsxs("button",{type:"button",onClick:()=>{b==null||b(S),$(1)},className:H("flex h-9 flex-shrink-0 items-center gap-1.5 rounded-full border px-3 text-sm font-semibold transition",c?"border-green-500 bg-green-50 text-green-600":"border-gray-200 bg-white text-gray-900 hover:bg-gray-50"),children:[L,e.jsx("span",{className:H("flex h-5 min-w-[20px] items-center justify-center rounded-full px-1.5 text-xs font-bold text-white",M),children:m})]},S)})}),e.jsxs("div",{className:"flex-1 overflow-y-auto scrollbar-hide min-h-0",children:[a?e.jsx("div",{className:"mt-3 space-y-2","aria-busy":"true",children:Array.from({length:3}).map((S,L)=>e.jsx("div",{className:"animate-pulse rounded-xl border border-gray-100 bg-white p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-10 w-10 flex-shrink-0 rounded-full bg-gray-200"}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("div",{className:"h-3 w-1/3 rounded bg-gray-200"}),e.jsx("div",{className:"h-3 w-12 rounded bg-gray-200"})]}),e.jsx("div",{className:"h-3 w-3/4 rounded bg-gray-200"}),e.jsx("div",{className:"h-2.5 w-full rounded bg-gray-200"})]})]})},L))}):K.length===0?e.jsx("div",{className:"mt-3 rounded-xl bg-gray-50 py-10 text-center",children:s?e.jsxs(e.Fragment,{children:[e.jsx(at,{className:"mx-auto mb-4 h-8 w-8 animate-spin text-blue-500"}),e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Analyzing emails with AI & automation..."}),e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"Processing email threads..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-2xl bg-green-50",children:e.jsx(Fe,{className:"h-8 w-8 text-green-400"})}),e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"No emails pending"}),e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"You're all caught up."}),u&&e.jsxs("button",{type:"button",onClick:u,className:"mt-4 inline-flex items-center gap-1.5 rounded-full border border-gray-200 px-4 py-2 text-xs font-semibold text-green-600 transition hover:bg-green-50",children:[e.jsx(st,{className:H("h-3.5 w-3.5",s&&"animate-spin")}),"Refresh"]})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-3 space-y-2",children:R.map(S=>{const L=Ia(S),m=Qn(S.participants)||S.subject||"Unknown",c=Un(m),M=S.participants.length>0;return e.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white",children:e.jsxs("button",{type:"button",onClick:()=>N==null?void 0:N(S),className:"flex w-full items-start gap-3 p-4 text-left transition hover:bg-gray-50/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-green-500 active:bg-gray-100/50",children:[M?e.jsx("div",{className:H("flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full text-sm font-bold",Gn(S.source)),children:c}):e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-blue-50 text-blue-600",children:e.jsx(bs,{className:"h-5 w-5"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:"truncate text-sm font-bold text-gray-900",children:m}),e.jsx("span",{className:"flex-shrink-0 text-xs text-gray-400",children:Vn(S.lastMessageDate)})]}),e.jsx("p",{className:"mt-0.5 truncate text-sm font-semibold text-gray-900",children:S.subject||"(No subject)"}),S.snippet&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-xs leading-snug text-gray-500",children:S.snippet}),e.jsxs("span",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:H("inline-flex rounded-full px-2.5 py-1 text-xs font-semibold",zn(L)),children:qn(L)}),L==="approved"&&S.approvalStatus==="pending"&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-50 px-2 py-0.5 text-[10px] font-medium text-amber-600",children:[e.jsx(Ve,{className:"h-3 w-3"}),"pending review"]}),Kn(S)&&e.jsx("span",{onClick:G=>{G.stopPropagation(),N==null||N(S)},className:"inline-flex cursor-pointer items-center rounded-lg border border-green-500 bg-white px-3 py-1.5 text-xs font-semibold text-green-600 transition hover:bg-green-50",children:"Convert"})]})]})]})},S.id)})}),K.length>et&&e.jsxs("div",{className:"mt-3 flex items-center justify-between px-1 py-2 text-xs text-gray-500",children:[e.jsxs("span",{children:["Showing ",E," to ",_," of ",K.length," entries"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:F,disabled:z<=1,className:H("flex h-7 w-7 items-center justify-center rounded-md border transition",z<=1?"cursor-not-allowed border-gray-100 text-gray-300":"border-gray-200 text-gray-600 hover:bg-gray-50"),"aria-label":"Previous page",children:e.jsx(tt,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"font-medium text-gray-700",children:["Page ",z," of ",D]}),e.jsx("button",{type:"button",onClick:P,disabled:z>=D,className:H("flex h-7 w-7 items-center justify-center rounded-md border transition",z>=D?"cursor-not-allowed border-gray-100 text-gray-300":"border-gray-200 text-gray-600 hover:bg-gray-50"),"aria-label":"Next page",children:e.jsx(ne,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-3 rounded-xl border border-gray-200 bg-white p-4",children:[e.jsx("div",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full bg-green-50",children:e.jsx(Fe,{className:"h-4 w-4 text-green-600"})}),e.jsx("p",{className:"flex-1 text-xs leading-relaxed text-gray-500",children:"Emails you approve can be converted into time entries."}),e.jsxs("a",{href:"#",onClick:S=>S.preventDefault(),className:"flex flex-shrink-0 items-center gap-0.5 text-xs font-semibold text-green-600 hover:text-green-700",children:["Learn more",e.jsx(ne,{className:"h-3.5 w-3.5"})]})]})]})]})}function Jn({open:t,onOpenChange:a}){const{emailAutomation:s,setEmailAutomation:r,emailMutation:n,addTrustedContact:i}=fs(),[l,o]=d.useState(""),[f,x]=d.useState(""),h=d.useCallback(()=>{const b=l.trim();b&&(i(b),o(""))},[l,i]),N=d.useCallback(b=>{const v=s.trustedContacts.filter(w=>w!==b);r({...s,trustedContacts:v}),n.mutate({...s,trustedContacts:v,type:"email"})},[s,r,n]),u=d.useCallback(()=>{const b=f.trim().toLowerCase();if(b){if(!s.keywords.includes(b)){const v=[...s.keywords,b];r({...s,keywords:v}),n.mutate({...s,keywords:v,type:"email"})}x("")}},[f,s,r,n]),j=d.useCallback(b=>{const v=s.keywords.filter(w=>w!==b);r({...s,keywords:v}),n.mutate({...s,keywords:v,type:"email"})},[s,r,n]);return e.jsx(oe,{open:t,onOpenChange:a,title:"Mail Automation Settings",children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsx("p",{className:"text-xs leading-relaxed text-gray-500",children:"Automatically approve and organize real-estateârelated email threads."}),e.jsx("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-green-50",children:e.jsx(rt,{className:"h-4 w-4 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"AI-Assisted Approval"}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"When enabled, high-confidence emails are auto-approved."})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s.autoApproveHighConfidence,"aria-label":"AI-Assisted Approval toggle",onClick:()=>{const b=!s.autoApproveHighConfidence;r({...s,autoApproveHighConfidence:b}),n.mutate({...s,autoApproveHighConfidence:b,type:"email"})},className:H("relative h-7 w-11 flex-shrink-0 rounded-full transition-colors",s.autoApproveHighConfidence?"bg-green-500":"bg-gray-300"),children:e.jsx("span",{className:H("absolute left-0.5 top-0.5 h-6 w-6 rounded-full bg-white shadow-sm transition-transform",s.autoApproveHighConfidence&&"translate-x-4")})})]})}),e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-amber-50",children:e.jsx(Qt,{className:"h-4 w-4 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Rule-Based Approval"}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"Create conditions to auto-approve emails."})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":s.enabled,"aria-label":"Rule-Based Approval toggle",onClick:()=>{const b=!s.enabled;r({...s,enabled:b}),n.mutate({...s,enabled:b,type:"email"})},className:H("relative h-7 w-11 flex-shrink-0 rounded-full transition-colors",s.enabled?"bg-green-500":"bg-gray-300"),children:e.jsx("span",{className:H("absolute left-0.5 top-0.5 h-6 w-6 rounded-full bg-white shadow-sm transition-transform",s.enabled&&"translate-x-4")})})]}),s.enabled&&e.jsxs("div",{className:"mt-4 space-y-5 border-t border-gray-100 pt-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Trusted Contacts"}),s.trustedContacts.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:s.trustedContacts.map(b=>e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1",children:[e.jsx("span",{className:"text-xs font-medium text-gray-700",children:b}),e.jsx("button",{type:"button",onClick:()=>N(b),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${b}`,children:e.jsx(se,{className:"h-3 w-3"})})]},b))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"email",placeholder:"[email protected]",value:l,onCh
31ange:b=>o(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),h())},className:"min-w-0 flex-1 rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-medium text-gray-900 placeholder:text-gray-400"}),e.jsx("button",{type:"button",onClick:h,disabled:!l.trim(),className:H("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",l.trim()?"bg-green-500 text-white hover:bg-green-600":"cursor-not-allowed bg-gray-100 text-gray-400"),"aria-label":"Add contact",children:e.jsx(ve,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-[11px] font-semibold uppercase tracking-wider text-gray-500",children:"Keywords"}),s.keywords.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:s.keywords.map(b=>e.jsxs("div",{className:"flex items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1",children:[e.jsx("span",{className:"text-xs font-medium text-gray-700",children:b}),e.jsx("button",{type:"button",onClick:()=>j(b),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${b}`,children:e.jsx(se,{className:"h-3 w-3"})})]},b))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"inspection, showing, ...",value:f,onChange:b=>x(b.target.value),onKeyDown:b=>{b.key==="Enter"&&(b.preventDefault(),u())},className:"min-w-0 flex-1 rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-medium text-gray-900 placeholder:text-gray-400"}),e.jsx("button",{type:"button",onClick:u,disabled:!f.trim(),className:H("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",f.trim()?"bg-green-500 text-white hover:bg-green-600":"cursor-not-allowed bg-gray-100 text-gray-400"),"aria-label":"Add keyword",children:e.jsx(ve,{className:"h-3.5 w-3.5"})})]})]})]})]})]})})}function Xn({open:t,onOpenChange:a,selectedThread:s,reviewFormData:r,setReviewFormData:n,evidenceFiles:i,setEvidenceFiles:l,newEvidenceFiles:o,setNewEvidenceFiles:f,properties:x,convertThreadMutation:h,approveTimeEntryMutation:N,updateTimeEntryMutation:u,processEvidenceFile:j,getThreadStatus:b}){const v=s?b(s):"available",w=v==="available"?"Review Email Thread":v==="pending"?"Pending Time Entry":"Approved Time Entry";return e.jsx(oe,{open:t,onOpenChange:a,title:w,children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[v==="available"&&e.jsx(te,{className:"bg-blue-500 text-white",children:"Available to Convert"}),v==="pending"&&e.jsx(te,{className:"bg-amber-500 text-white",children:"Pending Approval"}),v==="approved"&&e.jsx(te,{className:"bg-green-500 text-white",children:"Approved"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"mobile-thread-subject",className:"text-base font-medium text-gray-900",children:"Email Subject"}),e.jsx(ye,{id:"mobile-thread-subject",placeholder:"Enter email subject",value:r.title,onChange:g=>n(k=>({...k,title:g.target.value})),className:"text-sm text-gray-700",disabled:v==="pending"})]}),s&&e.jsx(Jr,{selectedThread:s}),(s==null?void 0:s.aiConfidence)!==void 0&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-blue-200 bg-blue-50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-5 w-5 text-blue-600"}),e.jsx("h4",{className:"font-semibold text-blue-900",children:"AI Analysis"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Confidence Score"}),e.jsxs("span",{className:`text-lg font-bold ${s.aiConfidence>=90?"text-green-600":s.aiConfidence>=50?"text-amber-600":"text-gray-600"}`,children:[s.aiConfidence,"%"]})]}),e.jsx("div",{className:"h-2.5 w-full rounded-full bg-gray-200",children:e.jsx("div",{className:`h-2.5 rounded-full transition-all ${s.aiConfidence>=90?"bg-green-600":s.aiConfidence>=50?"bg-amber-500":"bg-gray-400"}`,style:{width:`${s.aiConfidence}%`}})}),s.aiReasoning&&e.jsx("div",{className:"mt-3 rounded-md border border-blue-200 bg-white p-3",children:e.jsxs("p",{className:"text-sm italic text-gray-700",children:["â",s.aiReasoning,"â"]})}),e.jsx("div",{className:"mt-3 rounded-md border border-blue-200 bg-white p-3",children:e.jsx("p",{className:"flex items-start gap-2 text-xs text-gray-600",children:s.aiConfidence>=90?e.jsxs(e.Fragment,{children:[e.jsx(gt,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-green-600"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-green-700",children:"Auto-approved:"})," High confidence (â¥90%) threads are automatically converted."]})]}):s.aiConfidence>=50?e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-amber-600"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-amber-700",children:"Pending review:"})," Medium confidence (50â89%) threads need manual review."]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-gray-600"}),e.jsxs("span",{children:[e.jsx("strong",{className:"text-gray-700",children:"Manual conversion:"})," Low confidence (<50%) threads require manual review."]})]})})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{className:"text-base font-medium text-gray-900",children:"Description"}),e.jsx(zt,{placeholder:"Add additional details about this email thread...",value:r.description,onChange:g=>{n(k=>({...k,description:g.target.value})),g.target.style.height="auto",g.target.style.height=g.target.scrollHeight+"px"},ref:g=>{g&&r.description&&(g.style.height="auto",g.style.height=g.scrollHeight+"px")},className:"resize-none overflow-hidden text-sm text-gray-700",style:{minHeight:"100px"},disabled:v==="pending"})]}),e.jsx(Aa,{evidenceFiles:i,setEvidenceFiles:l,newEvidenceFiles:o,setNewEvidenceFiles:f}),e.jsx(Fa,{reviewFormData:r,setReviewFormData:n,properties:x}),s&&e.jsx(Xr,{threadStatus:v,selectedThread:s,reviewFormData:r,evidenceFiles:i,newEvidenceFiles:o,setShowThreadDialog:a,c
31onvertThreadMutation:h,approveTimeEntryMutation:N,updateTimeEntryMutation:u})]})})}function Zn({open:t,onOpenChange:a}){var J;const s=Ma(),{threads:r,filteredThreads:n,isLoading:i,isRefetching:l,error:o,listFilter:f,setListFilter:x,searchQuery:h,setSearchQuery:N,mailboxFilter:u,setMailboxFilter:j,imapStatusQuery:b,microsoftMailStatusQuery:v,statusCounts:w,handleRefresh:g,handleConfirmSync:k,handleThreadClick:C,showSyncDialog:T,setShowSyncDialog:I,showThreadDialog:p,setShowThreadDialog:O,selectedThread:A,reviewFormData:z,setReviewFormData:$,evidenceFiles:K,setEvidenceFiles:D,newEvidenceFiles:R,setNewEvidenceFiles:E,properties:_,convertThreadMutation:P,approveTimeEntryMutation:F,updateTimeEntryMutation:S,processEvidenceFile:L,getThreadStatus:m,gmailConnected:c,outlookConnected:M}=s,G=l||i,V=d.useMemo(()=>{if(c)return"Gmail";if(M)return"Outlook"},[c,M]);d.useEffect(()=>{(P.isSuccess||P.isError)&&O(!1)},[P.isSuccess,P.isError]),d.useEffect(()=>{(F.isSuccess||F.isError)&&O(!1)},[F.isSuccess,F.isError]),d.useEffect(()=>{(S.isSuccess||S.isError)&&O(!1)},[S.isSuccess,S.isError]);const[U,ae]=d.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{open:t,onOpenChange:a,children:e.jsx(Wn,{threads:n,isLoading:i&&r.length===0,isSyncing:G,error:o,activeFilter:f,statusCounts:w,searchQuery:h,connectedProvider:V,mailboxes:Zr((J=b.data)==null?void 0:J.accounts,v.data),mailboxFilter:u,onMailboxChange:j,onThreadClick:C,onRefresh:g,onSync:()=>I(!0),onFilterChange:Z=>x(Z),onSearchChange:Z=>N(Z),onClose:()=>a(!1),onOpenMailAutomationSettings:()=>ae(!0)})}),e.jsx(Jn,{open:U,onOpenChange:ae}),e.jsx(en,{open:T,onOpenChange:I,onConfirm:k,isLoading:G}),e.jsx(Xn,{open:p,onOpenChange:O,selectedThread:A,reviewFormData:z,setReviewFormData:$,evidenceFiles:K,setEvidenceFiles:D,newEvidenceFiles:R,setNewEvidenceFiles:E,properties:_,convertThreadMutation:P,approveTimeEntryMutation:F,updateTimeEntryMutation:S,processEvidenceFile:L,getThreadStatus:m})]})}function ei({open:t,onOpenChange:a,onConnectImap:s}){var T,I,p,O,A,z,$,K,D,R,E;const{googleCalendarStatusQuery:r,imapStatusQuery:n,microsoftCalendarStatusQuery:i,microsoftMailStatusQuery:l,handleGoogleCalendarConnect:o,handleMicrosoftCalendarConnect:f,handleMicrosoftMailConnect:x,disconnectGoogleCalendarMutation:h,disconnectMicrosoftCalendarMutation:N,disconnectMicrosoftMailMutation:u,disconnectImapMutation:j,isGoogleCalendarConnecting:b,isMicrosoftCalendarConnecting:v,isMicrosoftMailConnecting:w,isImapConnecting:g}=ft(),k=((T=n.data)==null?void 0:T.accounts)??[],C=_=>{j.mutate(_)};return e.jsx(oe,{open:t,onOpenChange:a,title:"Sync Settings",children:e.jsx("div",{className:"px-4 pb-10",children:e.jsxs(xs,{defaultValue:"mail",children:[e.jsxs(us,{className:"mb-3 inline-flex w-full rounded-2xl bg-muted p-1",children:[e.jsx(bt,{value:"calendar",className:"flex-1 rounded-xl text-xs",children:"Calendar"}),e.jsx(bt,{value:"mail",className:"flex-1 rounded-xl text-xs",children:"Mail"})]}),e.jsxs(yt,{value:"calendar",className:"space-y-3",children:[e.jsx(Dt,{icon:e.jsx(ge,{className:"h-5 w-5"}),providerName:"Google Calendar",isConnected:!!((I=r.data)!=null&&I.connected),connectedLabel:((p=r.data)==null?void 0:p.email)??void 0,isConnecting:b,onConnect:o,onDisconnect:()=>h.mutate()}),e.jsx(Dt,{icon:e.jsx(ge,{className:"h-5 w-5"}),providerName:"Outlook Calendar",isConnected:!!((O=i.data)!=null&&O.connected),connectedLabel:((A=l.data)==null?void 0:A.email)??void 0,isConnecting:v,onConnect:f,onDisconnect:()=>N.mutate()})]}),e.jsxs(yt,{value:"mail",className:"space-y-3",children:[e.jsx(Dt,{icon:e.jsx(Fe,{className:"h-5 w-5"}),providerName:"Email (IMAP)",isConnected:!!((z=n.data)!=null&&z.connected),connectedLabel:(($=k[0])==null?void 0:$.email)??((K=k[0])==null?void 0:K.username)??void 0,isConnecting:g,onConnect:s,onDisconnect:k.length===1?()=>C(k[0].id):void 0}),k.length>1&&e.jsxs("div",{className:"space-y-2 rounded-xl border bg-card p-3",children:[e.jsxs("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:["Connected mailboxes (",k.length,")"]}),e.jsx(pn,{accounts:k,onDisconnect:C,isDisconnecting:j.isPending})]}),((D=n.data)==null?void 0:D.connected)&&e.jsxs("button",{type:"button",onClick:s,className:"flex w-full items-center justify-center gap-2 rounded-xl border border-dashed py-3 text-sm normal-case tracking-normal text-muted-foreground transition-colors active:bg-muted",children:[e.jsx(ve,{className:"h-4 w-4"}),"Add another mailbox"]}),e.jsx(Dt,{icon:e.jsx(Fe,{className:"h-5 w-5"}),providerName:"Outlook Mail",isConnected:!!((R=l.data)!=null&&R.connected),connectedLabel:((E=l.data)==null?void 0:E.email)??void 0,isConnecting:w,onConnect:x,onDisconnect:()=>u.mutate()})]})]})})})}function ti(){return e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-border dark:bg-card","aria-busy":"true",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("div",{className:"h-4 w-20 rounded bg-muted"}),e.jsx("div",{className:"h-4 w-16 rounded bg-muted"})]}),e.jsx("div",{className:"h-24 rounded-xl bg-muted"})]})}function si({summary:t,state:a,onPreviousWeek:s,onNextWeek:r,onFullViewClick:n}){return a==="loading"?e.jsx(ti,{}):e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-border dark:bg-card",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-bold text-gray-900 dark:text-white",children:"Calendar"}),n&&e.jsx("button",{type:"button",onClick:n,className:"min-h-11 rounded-lg px-2 text-xs font-semibold text-blue-600 transition hover:bg-blue-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 active:scale-95 dark:hover:bg-blue-950/40",children:"Full view"})]}),e.jsxs("div",{className:"rounded-xl border border-gray-100 px-3 py-3 dark:border-border",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:s,disabled:!s,className:"flex h-10 w-10 items-center justify-center rounded-full text-gray-500 dark:text-gray-400 transition hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-95 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Previous week",children:e.jsx(tt,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white",children:t.monthLabel}),e.jsx("button",{type:"button",onClick:r,disabled:!r,className:"flex h-10 w-10 items-center justify-center rounded-full text-gray-500 dark:text-gray-400 transition hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-95 disabled:cursor-not-allowed disabled:opacity-40","aria-label":"Next week",children:e.jsx(ne,{className:"h-4 w-4"})})]}),a==="error"?e.jsx("div",{className:"rounded-lg bg-red-50 p-3 text-sm font-medium text-red-700 dark:bg-red-950/40 dark:text-red-200",children:"Calendar unavailable"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-7 gap-1 text-center",children:t.days.map(i=>e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("span",{className:"text-[10px] font-bold uppercase text-gray-500 dark:text-gray-400",children:i.dayLabel}),e.jsx("span",{className:H("flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold",i.isSelected?"bg-primary text-primary-foreground shadow-sm":"text-gray-900 dark:text-white"),children:i.dayNumber}),e.jsx("span",{className:H("h-1.5 w-1.5 rounded-full",i.availableCount?"bg-primary":"bg-transparent")})]},i.date.toISOString()))}),e.jsxs("div",{className:"mt-3 flex min-h-11 items-center justify-between border-t border-gray-100 pt-3 text-xs font-semibold dark:border-border",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-gray-500 dark:text-gray-400",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-primary"}),t.availableToConvertCount>0?`${t.availableToConvertCount} date available to convert`:"No dates available to convert"]}),e.jsx(ne,{className:"h-4 w-4 text-gray-500 dark:text-gray-400","aria-hidden":"true"})]})]})]})]})}function ai({pendingReviewCount:t,isSyncing:a=!1,syncError:s=!1,onFullViewClick:r}){const n=a?"Syncing...":s?"Sync failed":t>0?`Synced â ${t} pending`:"No emails pending",i=a,l=!a&&!s&&t>0;return e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white p-4 shadow-sm dark:border-border dark:bg-card",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:"Mail"}),r&&e.jsx("button",{type:"button",onClick:r,className:"min-h-11 rounded-lg px-2 text-xs font-semibold text-blue-600 transition hover:bg-blue-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 active:scale-95 dark:hover:bg-blue-950/40",children:"Full view"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-indigo-100 text-indigo-600 dark:bg-indigo-900/40 dark:text-indigo-400",children:e.jsx(Fe,{className:"h-5 w-5"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900 dark:text-white",children:a?"Mail":l?`${t} ${t===1?"email":"emails"}`:"Mail"}),i&&e.jsx(st,{className:"h-3.5 w-3.5 animate-spin text-gray-500"})]}),e.jsx("span",{className:"block truncate text-xs text-gray-500 dark:text-gray-400",children:n})]}),e.jsx("span",{className:H("flex-shrink-0 rounded-full px-3 py-1 text-[11px] font-bold",s?"bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-200":a?"bg-blue-50 text-blue-700 dark:bg-blue-950/40 dark:text-blue-200":l?"bg-amber-50 text-amber-700 dark:bg-amber-950/40 dark:text-amber-200":"bg-gray-100 text-gray-600 dark:bg-muted dark:text-gray-500"),children:s?"ERROR":a?"SYNCING":l?"PENDING":"CLEAR"})]})]})}const ri={error:"bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-200",available:"bg-blue-50 text-blue-700 dark:bg-blue-950/40 dark:text-blue-200",pending:"bg-amber-50 text-amber-700 dark:bg-amber-950/40 dark:text-amber-200",connected:"bg-green-50 text-green-700 dark:bg-green-950/40 dark:text-green-200",inactive:"bg-gray-100 text-gray-600 dark:bg-muted dark:text-gray-500 dark:text-gray-400",warning:"bg-amber-50 text-amber-700 dark:bg-amber-950/40 dark:text-amber-200"},ni={error:"bg-red-50 text-red-600 dark:bg-red-950/40 dark:text-red-200",available:"bg-blue-50 text-blue-600 dar
31k:bg-blue-950/40 dark:text-blue-200",pending:"bg-amber-50 text-amber-600 dark:bg-amber-950/40 dark:text-amber-200",connected:"bg-green-50 text-green-600 dark:bg-green-950/40 dark:text-green-200",inactive:"bg-gray-100 text-gray-500 dark:bg-muted dark:text-gray-500 dark:text-gray-400",warning:"bg-amber-50 text-amber-600 dark:bg-amber-950/40 dark:text-amber-200"};function ii({item:t}){const a="h-5 w-5";return t.icon==="mail"?e.jsx(Fe,{className:a}):t.icon==="calendar"?e.jsx(bs,{className:a}):e.jsx(nt,{className:a})}function li({item:t}){const a=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:H("flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl",ni[t.status]),children:e.jsx(ii,{item:t})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900 dark:text-white",children:t.label}),e.jsx("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:t.subtitle})]}),e.jsx("span",{className:H("rounded-full px-3 py-1 text-[11px] font-bold",ri[t.status]),children:t.badgeLabel}),t.onClick&&e.jsx(ne,{className:"h-4 w-4 flex-shrink-0 text-gray-500 dark:text-gray-400"})]});return t.onClick?e.jsx("button",{type:"button",onClick:t.onClick,className:"flex min-h-14 w-full items-center gap-3 rounded-xl px-3 py-2 text-left transition hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-[0.99]",children:a}):e.jsx("div",{className:"flex min-h-14 items-center gap-3 px-3 py-2",children:a})}function oi({items:t,onManageClick:a}){return e.jsxs("section",{className:"overflow-hidden rounded-2xl border border-gray-100 bg-white shadow-sm dark:border-border dark:bg-card",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-gray-100 px-4 py-3 dark:border-border",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:"Sync status"}),a&&e.jsx("button",{type:"button",onClick:a,className:"min-h-11 rounded-lg px-2 text-xs font-semibold text-blue-600 transition hover:bg-blue-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2 active:scale-95 dark:hover:bg-blue-950/40",children:"Manage"})]}),t.map((s,r)=>e.jsx("div",{className:H(r>0&&"border-t border-gray-100 dark:border-border"),children:e.jsx(li,{item:s})},s.id))]})}function La(){return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-4 gap-y-2 pb-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:"#22c55e"},title:"Approved"}),e.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Approved"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:"#f59e0b"},title:"Pending Approval"}),e.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Pending Approval"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:"#9ca3af"},title:"Discarded"}),e.jsx("span",{className:"text-xs font-medium text-gray-700 dark:text-gray-300",children:"Discarded"})]})]}),e.jsx("span",{className:"hidden text-xs text-muted-foreground lg:block",children:"Approved visits count toward your REPS hours"})]})}function qt(t){me("POST","/api/mobile/cta-clicked",t).catch(a=>{console.warn("Mobile CTA tracking failed:",a)})}const js="https://play.google.com/store/apps/details?id=com.repsshield.app",Ut="",_a=!!Ut,Zt=4;function Pt(t){const a=t instanceof Date?t:new Date(t);return Number.isNaN(a.getTime())?"Date unavailable":Q(a,"MMM d, yyyy")}function di(){return e.jsxs("section",{className:"rounded-2xl border border-gray-100 bg-white shadow-sm dark:border-border dark:bg-card","aria-busy":"true",children:[e.jsx("div",{className:"border-b border-gray-100 px-4 py-3 dark:border-border",children:e.jsx("div",{className:"h-4 w-36 rounded bg-muted"})}),e.jsx("div",{className:"p-3",children:e.jsx("div",{className:"h-16 rounded-xl bg-muted"})})]})}function ci({pendingEntries:t=[],approvedEntries:a=[],discardedEntries:s=[],statusCounts:r,state:n,isMutating:i=!1,onApprove:l,onReject:o,onOpenDetails:f,onManageClick:x}
31){const[h,N]=d.useState("approved"),[u,j]=d.useState(1),b=[{value:"approved",label:"Approved",count:r.approved},{value:"pending",label:"Pending",count:r.pending},{value:"discarded",label:"Discarded",count:r.discarded},{value:"all",label:"All",count:r.all}],v=(()=>{switch(h){case"approved":return a;case"discarded":return s;case"all":return[...t.map(p=>({...p,_type:"pending"})),...a.map(p=>({...p,_type:"approved"})),...s.map(p=>({...p,_type:"discarded"}))];default:return t}})(),w=Math.ceil(v.length/Zt),g=Math.min(u,w||1),k=(g-1)*Zt,C=v.slice(k,k+Zt),T=p=>{N(p),j(1)},I=n==="success"||n==="empty";return n==="loading"?e.jsx(di,{}):e.jsxs("section",{className:"overflow-hidden rounded-2xl border border-gray-100 bg-white shadow-sm dark:border-border dark:bg-card",children:[I&&e.jsxs("div",{className:"flex items-center justify-between border-b border-gray-100 px-4 py-3 dark:border-border",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:"Geo Fence Sync"}),x&&e.jsx("button",{type:"button",onClick:x,className:"text-xs font-semibold text-green-600 hover:text-green-700",children:"Manage"})]}),e.jsx("div",{className:"overflow-x-auto scrollbar-hide border-b border-gray-100 dark:border-border",children:e.jsx("div",{className:"flex gap-1 px-3 pt-2 pb-0 min-w-max",children:b.map(p=>e.jsxs("button",{onClick:()=>T(p.value),className:`shrink-0 rounded-t-lg px-3 py-2 text-xs font-medium transition-colors whitespace-nowrap ${h===p.value?"bg-green-50 text-green-700 dark:bg-green-950/40 dark:text-green-300":"text-gray-500 hover:text-gray-700 hover:bg-gray-50 dark:text-gray-400 dark:hover:text-gray-200"}`,children:[p.label," (",p.count,")"]},p.value))})}),e.jsxs("div",{className:"p-3",children:[n==="error"?e.jsx("p",{className:"rounded-xl bg-red-50 p-3 text-sm font-medium text-red-700 dark:bg-red-950/40 dark:text-red-200",children:"Could not load geo fence entries."}):v.length===0?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"rounded-xl bg-muted/60 p-3 text-sm font-medium text-gray-500 dark:text-gray-400",children:h==="pending"?"No geo fence entries pending.":h==="approved"?"No approved entries yet.":h==="discarded"?"No discarded entries.":"No entries found."}),h==="pending"&&!da()&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:js,target:"_blank",rel:"noopener noreferrer",onClick:()=>qt({platform:"android",source:"mobile_geofence_empty_state"}),className:"relative inline-block",children:e.jsx("img",{src:"/images/google-play-badge.svg",alt:"Get it on Google Play",className:"h-8 w-auto"})}),_a?e.jsx("a",{href:Ut,target:"_blank",rel:"noopener noreferrer",onClick:()=>qt({platform:"ios",source:"mobile_geofence_empty_state"}),className:"relative inline-block",children:e.jsx("img",{src:"/images/app-store-badge.svg",alt:"Download on the App Store",className:"h-8 w-auto"})}):e.jsxs("div",{className:"relative inline-block",children:[e.jsx("div",{className:"opacity-30 grayscale cursor-not-allowed",children:e.jsx("img",{src:"/images/app-store-badge.svg",alt:"Download on the App Store",className:"h-8 w-auto"})}),e.jsx("span",{className:"absolute -top-2 -right-1 bg-primary text-white text-[9px] font-bold px-1 py-0.5 rounded-full shadow-sm",children:"COMING SOON"})]})]}),e.jsx("p",{className:"text-[11px] text-gray-400 dark:text-gray-500",children:"Mobile app coming soon for geo-fence tracking."})]})]}):h==="discarded"?e.jsx("div",{className:"space-y-2",children:C.map(p=>e.jsx("div",{className:"flex items-center gap-3 rounded-xl border-l-4 border-l-gray-400 bg-white p-3 dark:bg-card",children:e.jsxs("button",{type:"button",onClick:()=>f==null?void 0:f(p.id),disabled:!f,className:"flex min-w-0 flex-1 items-center gap-3 text-left transition hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-[0.99] disabled:cursor-default",children:[e.jsx(ht,{user:{id:String(p.id),firstName:(p.propertyName||"Unknown").split(" ")[0]||void 0,lastName:(p.propertyName||"").split(" ").slice(1).join(" ")||void 0,profileImageUrl:void 0},size:"sm"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900 dark:text-white",children:p.propertyName||"Unknown property"}),e.jsxs("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:[p.discardReason,p.enteredAt?` ⢠${Pt(p.enteredAt)}`:""]})]})]})},p.id))}):e.jsx("div",{className:"space-y-2",children:C.map(p=>{const O=p._type==="discarded"||p.discardReason,A=!O&&(p._type==="pending"||h==="pending");return O?e.jsx("div",{className:"flex items-center gap-3 rounded-xl border-l-4 border-l-gray-400 bg-white p-3 dark:bg-card",children:e.jsxs("button",{type:"button",onClick:()=>f==null?void 0:f(p.id),disabled:!f,className:"flex min-w-0 flex-1 items-center gap-3 text-left transition hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-[0.99] disabled:cursor-default",children:[e.jsx(ht,{user:{id:String(p.id),firstName:(p.propertyName||"Unknown").split(" ")[0]||void 0,lastName:(p.propertyName||"").split(" ").slice(1).join(" ")||void 0,profileImageUrl:void 0},size:"sm"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900 dark:text-white",children:p.propertyName||"Unknown property"}),e.jsxs("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:[p.discardReason,p.enteredAt?` ⢠${Pt(p.enteredAt)}`:"",p.date&&!p.enteredAt?` ⢠${Pt(p.date)}`:""]})]})]})},p.id):e.jsxs("div",{className:`flex items-center gap-3 rounded-xl border-l-4 p-3 bg-white dark:bg-card ${A?"border-l-amber-500":"border-l-green-500"}`,children:[e.jsxs("button",{type:"button",onClick:()=>f==null?void 0:f(p.id),disabled:!f,className:"flex min-w-0 flex-1 items-center gap-3 text-left transition hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 active:scale-[0.99] disabled:cursor-default",children:[e.jsx(ht,{user:{id:String(p.id),firstName:(p.visitorName||"").split(" ")[0]||void 0,lastName:(p.visitorName||"").split(" ").slice(1).join(" ")||void 0,profileImageUrl:p.visitorProfileImageUrl||void 0},size:"sm"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900 dark:text-white",children:p.visitorName||"Unknown visitor"}),e.jsxs("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:[p.propertyName&&`${p.propertyName} ⢠`,Pt(p.date),p.hours!=null&&` ⢠${Number(p.hours).toFixed(1)} hrs`]})]})]}),A&&e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>l(p.id),disabled:i,className:"flex h-11 w-11 items-center justify-center rounded-xl bg-green-50 text-green-700 transition hover:bg-green-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-green-500 focus-visible:ring-offset-2 active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-green-950/40 dark:text-green-200","aria-label":"Approve",children:e.jsx(gt,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:()=>o(p.id),disabled:i,className:"flex h-11 w-11 items-center justify-center rounded-xl bg-red-50 text-red-700 transition hover:bg-red-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-red-500 focus-visible:ring-offset-2 active:scale-95 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-red-950/40 dark:text-red-200","aria-label":"Reject",children:e.jsx(se,{className:"h-5 w-5"})})]})]}
31,p.id)})}),w>1&&e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-2 border-t border-gray-100 dark:border-border",children:[e.jsxs("button",{onClick:()=>j(p=>Math.max(1,p-1)),disabled:g<=1,className:"flex items-center gap-1 text-xs font-medium text-gray-600 disabled:opacity-30 dark:text-gray-400",children:[e.jsx(tt,{className:"h-3.5 w-3.5"})," Previous"]}),e.jsxs("span",{className:"text-xs text-gray-400",children:[g," of ",w]}),e.jsxs("button",{onClick:()=>j(p=>Math.min(w,p+1)),disabled:g>=w,className:"flex items-center gap-1 text-xs font-medium text-gray-600 disabled:opacity-30 dark:text-gray-400",children:["Next ",e.jsx(ne,{className:"h-3.5 w-3.5"})]})]}),e.jsx("div",{className:"mt-3 pt-3 border-t border-gray-100 dark:border-border",children:e.jsx(La,{})})]})]})}function mi({value:t,onChange:a}){const[s,r]=d.useState(!1),n=t?new Date(t+"T00:00:00"):new Date;return e.jsxs(kt,{open:s,onOpenChange:r,children:[e.jsx(Ct,{asChild:!0,children:e.jsxs("button",{type:"button",className:H("flex w-full items-center rounded-xl border border-input bg-background px-3 py-2","h-12 sm:h-10 text-base sm:text-sm","text-left font-normal","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","cursor-pointer",!t&&"text-muted-foreground"),children:[t?Q(n,"MMM d, yyyy"):"Pick a date",e.jsx(ge,{className:"ml-auto h-4 w-4 opacity-50 shrink-0"})]})}),e.jsx(St,{className:"w-auto p-0",align:"start",children:e.jsx(Vt,{mode:"single",selected:n,onSelect:i=>{i&&a(Q(i,"yyyy-MM-dd")),r(!1)},initialFocus:!0})})]})}function zs({value:t,onChange:a}){const[s,r]=d.useState(!1),n=t?(()=>{const[i,l]=t.split(":").map(Number),o=i>=12?"PM":"AM";return`${i%12||12}:${String(l).padStart(2,"0")} ${o}`})():"";return e.jsxs(kt,{open:s,onOpenChange:r,children:[e.jsx(Ct,{asChild:!0,children:e.jsxs("button",{type:"button",className:H("flex w-full items-center rounded-xl border border-input bg-background px-3 py-2","h-12 sm:h-10 text-base sm:text-sm","text-left font-normal","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","cursor-pointer",!t&&"text-muted-foreground"),children:[n||"Pick a time",e.jsx(je,{className:"ml-auto h-4 w-4 opacity-50 shrink-0"})]})}),e.jsx(St,{className:"w-auto p-0",align:"start",children:e.jsx("div",{className:"p-2",children:e.jsx("input",{type:"time",value:t,onChange:i=>{a(i.target.value),i.target.value&&r(!1)},className:H("w-48 rounded-md border border-input bg-background px-3 py-2","h-12 sm:h-10 text-base sm:text-sm","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","appearance-none","cursor-pointer"),style:{minHeight:"48px"}})})})]})}function Oa({entry:t,onSaveAndApprove:a,onSaveDraft:s,onReject:r,onCancel:n}){const[i,l]=d.useState(""),[o,f]=d.useState(""),[x,h]=d.useState(""),[N,u]=d.useState(""),[j,b]=d.useState(""),[v,w]=d.useState(""),[g,k]=d.useState(!1),[C,T]=d.useState(null);d.useEffect(()=>{if(t){const $=t.date instanceof Date?t.date:t.date?new Date(String(t.date)):null,K=$&&!isNaN($.getTime())?Q($,"yyyy-MM-dd"):"";l(K),b(t.description||""),w(t.activityType||"property-visitation"),k(t.isMaterialParticipation??!1);const D=R=>{if(R instanceof Date)return R;if(typeof R=="string"||typeof R=="number"){const E=new Date(R);return isNaN(E.getTime())?null:E}return null};if(t.timeStarted&&t.timeEnded){const R=D(t.timeStarted),E=D(t.timeEnded);if(R&&E){f(Q(R,"HH:mm")),h(Q(E,"HH:mm"));const P=(E.getTime()-R.getTime())/(1e3*60*60);u(Math.max(0,P).toFixed(1))}}else{const R=Number(t.hours);if(!isNaN(R)&&R>0){u(R.toFixed(1));const E=t.date instanceof Date?new Date(t.date):new Date;E.setHours(9,0,0,0),f(Q(E,"HH:mm"));const _=new Date(E);_.setHours(_.getHours()+Math.floor(R)),_.setMinutes(_.getMinutes()+Math.round(R%1*60)),h(Q(_,"HH:mm"))}}}},[t]);const I=()=>{if(!o||!x)return!0;const[$,K]=o.split(":").map(Number),[D,R]=x.split(":").map(Number),E=$*60+K;return D*60+R<=E?(T("End time must be after start time"),!1):(T(null),!0)},p=()=>{if(!t)throw new Error("No entry");return{id:t.id,date:i,hours:parseFloat(N)||0,description:j,activityType:v,isMaterialParticipation:g,timeStarted:o||void 0,timeEnded:x||void 0}},O=()=>{I()&&a(p())},A=()=>{I()&&s(p())},z=()=>
31{t&&r(t.id)};return t?e.jsxs("div",{className:"space-y-5 sm:space-y-6 py-3 sm:py-4",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Visit Information"}),e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900 rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/20 rounded-md",children:e.jsx(ca,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx(W,{className:"text-xs text-muted-foreground",children:"Visitor"}),e.jsx("p",{className:"font-medium",children:t.visitorName||"Unknown Visitor"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-100 dark:bg-green-900/20 rounded-md",children:e.jsx(nt,{className:"h-4 w-4 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx(W,{className:"text-xs text-muted-foreground",children:"Property"}),e.jsx("p",{className:"font-medium",children:t.propertyName||"Unknown Property"})]})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Time Details"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"date",children:"Date"}),e.jsx(mi,{value:i,onChange:l})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"hours",children:"Duration (hours)"}),e.jsx(ye,{id:"hours",type:"text",inputMode:"decimal",value:N,onChange:$=>{const K=$.target.value.replace(/[^0-9.]/g,"");u(K)},placeholder:"0.0"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"startTime",children:"Start Time"}),e.jsx(zs,{value:o,onChange:f})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"endTime",children:"End Time"}),e.jsx(zs,{value:x,onChange:h})]})]}),C&&e.jsxs("div",{className:"flex items-center gap-2 text-red-600 text-sm",children:[e.jsx(ma,{className:"h-4 w-4"}),C]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Activity Details"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"description",children:"Description"}),e.jsx(ye,{id:"description",value:j,onChange:$=>b($.target.value),placeholder:"Describe the visit..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"activityType",children:"Category"}),e.jsxs(Me,{value:v,onValueChange:w,children:[e.jsx(Ee,{id:"activityType",children:e.jsx(De,{placeholder:"Select category"})}),e.jsxs(Pe,{children:[it.filter($=>$.value!=="real-estate").map($=>e.jsx(re,{value:$.value,children:$.label},$.value)),e.jsx(re,{value:"property-visitation",children:"Property Visitation"}),e.jsx(re,{value:"tenant-meeting",children:"Tenant Meeting"}),e.jsx(re,{value:"maintenance",children:"Maintenance"}),e.jsx(re,{value:"inspection",children:"Inspection"})]})]})]})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Classification"}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"p-2 bg-purple-100 dark:bg-purple-900/20 rounded-md shrink-0",children:e.jsx(Lt,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(W,{className:"font-medium",children:"Material Participation"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:"Mark if this activity counts toward your material participation hours"})]})]}),e.jsx(Ae,{checked:g,onCheckedChange:k,className:"shrink-0 ml-2"})]}),g&&e.jsx(te,{variant:"secondary",className:"ml-2",children:"This entry will count toward your 100-hour material participation goal"})]}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row gap-2 pt-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 sm:flex-1",children:[e.jsx(q,{variant:"outline",onClick:z,children:"Reject"}),e.jsx(q,{variant:"outline",onClick:n,children:"Cancel"}),e.jsx(q,{variant:"outline",onClick:A,children:"Save Draft"})]}),e.jsx(q,{onClick:O,className:"bg-green-600 hover:bg-green-700 text-white sm:flex-1",children:"Save & Approve"})]})]}):null}function xi({open:t,onOpenChange:a,entry:s,onSaveAndApprove:r,onSaveDraft:n,onReject:i}){return e.jsx(oe,{open:t,onOpenChange:a,title:"Review Detected Visit",children:e.jsx("div",{className:"px-4 pb-6",children:e.jsx(Oa,{entry:s,onSaveAndApprove:r,onSaveDraft:n,onReject:i,onCancel:()=>a(!1)})})})}function ui({open:t,onOpenChange:a,settings:s,onUpdateSettings:r,isSaving:n=!1}){const i=(s==null?void 0:s.autoApproveGeoSync)??!1;return e.jsx(oe,{open:t,onOpenChange:a,title:"Geo Fence Automation Settings",children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsx("p",{className:"text-xs leading-relaxed text-gray-500",children:"Automatically approve and manage geo fence visits."}),e.jsx("div",{className:"rounded-xl border border-gray-200 bg-white p-4 shadow-sm",children:s?e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-green-50",children:e.jsx(rt,{className:"h-4 w-4 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Enable Automation"}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"Allow automatic approval of qualifying visits."})]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":i,"aria-label":"Enable geo fence automation",disabled:n,onClick:()=>r==null?void 0:r(!i),className:H("relative h-7 w-11 flex-shrink-0 rounded-full transition-colors",i?"bg-green-500":"bg-gray-300",n&&"opacity-60 cursor-not-allowed"),children:e.jsx("span",{className:H("absolute left-0.5 top-0.5 h-6 w-6 rounded-full bg-white shadow-sm transition-transform",i&&"translate-x-4")})})]}):e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-green-50",children:e.jsx(rt,{className:"h-4 w-4 text-green-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Enable Automation"}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:"Loading..."})]})]}),e.jsx("div",{className:"h-7 w-11 rounded-full bg-gray-200 animate-pulse"})]})})]})})}function hi({open:t,onOpenChange:a,entry:s}){const r=s!=null&&s.enteredAt?new Date(s.enteredAt):null,n=s!=null&&s.exitedAt?new Date(s.exitedAt):null;return e.jsx(oe,{open:t,onOpenChange:a,title:"Discarded Visit Details",children:e.jsxs("div",{className:"space-y-2 px-4 pb-6",children:[(s==null?void 0:s.propertyName)&&e.jsx("div",{children:e.jsx("p",{className:"text-xs font-semibold text-gray-900 dark:text-white",children:s.propertyName})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Reason:"}),e.jsx("p",{className:"mt-0.5",children:s==null?void 0:s.discardReason})]}),(s==null?void 0:s.durationMinutes)!==null&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Duration:"}),e.jsxs("p",{className:"mt-0.5",children:[s==null?void 0:s.durationMinutes," min"]})]}),r&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Entered:"}),e.jsx("p",{className:"mt-0.5",children:Q(r,"MMM d, h:mm a")})]}),n&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Exited:"}),e.jsx("p",{className:"mt-0.5",children:Q(n,"MMM d, h:mm a")})]})]})]})})}const $a="mobile_reward_banner_dismissed";function pi(t){try{return localStorage.getItem(`${$a}:${t}`)==="1"}catch{return!1}}function gi(t){try{localStorage.setItem(`${$a}:${t}`,"1")}catch{}}function Ha({userId:t,isSubscribed:a,isOnTrial:s,mobileInstallCompleted:r}
31){const[n,i]=d.useState(!1),[l,o]=d.useState(()=>pi(t)),f=a,x=s&&!a,h=!l&&!r&&(f||x),N=d.useCallback(async()=>{try{await me("POST","/api/mobile/cta-clicked",{platform:"android",source:"dashboard-banner"})}catch{}i(!0)},[]),u=d.useCallback(()=>{o(!0),gi(t)},[t]),j=d.useCallback(b=>{try{me("POST","/api/mobile/cta-clicked",{platform:b,source:"dashboard-banner-modal"})}catch{}},[]);return h?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-3xl border border-emerald-200 bg-emerald-50 p-4 shadow-sm dark:border-emerald-800 dark:bg-emerald-950/30",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-emerald-600 text-white shadow-sm dark:bg-emerald-500",children:e.jsx("span",{className:"text-lg",children:"ð±"})}),e.jsx("div",{className:"min-w-0 flex-1",children:x?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white",children:"Subscribe and get 1 free month"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-gray-600 dark:text-gray-300",children:"Once you subscribe, install the app for a free billing cycle"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white",children:"Get 1 free month"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-gray-600 dark:text-gray-300",children:"Install the mobile app for a free billing cycle"})]})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx("button",{type:"button",onClick:N,className:"text-xs font-semibold text-emerald-700 hover:text-emerald-900 dark:text-emerald-300 dark:hover:text-emerald-200",children:x?"Details":"Get"}),e.jsx("button",{type:"button",onClick:u,className:"rounded-full p-1 text-emerald-400 hover:text-emerald-600 dark:text-emerald-500 dark:hover:text-emerald-300","aria-label":"Dismiss",children:e.jsx(se,{className:"h-3.5 w-3.5"})})]})]})}),e.jsx(Ne,{open:n,onOpenChange:i,children:e.jsxs(Ie,{className:"sm:max-w-sm",children:[e.jsxs(Le,{children:[e.jsxs(_e,{className:"flex items-center gap-2 text-center",children:["ð± ",x?"How It Works":"Get the App"]}),e.jsx(Gt,{className:"text-center",children:x?"Subscribe to any monthly plan, install the REPSShield mobile app, and log in. Your next billing cycle will be free.":"Download the REPSShield mobile app, log in with your account, and your free month credit is applied automatically."})]}),e.jsxs("div",{className:"flex flex-col gap-3 py-2",children:[e.jsxs("a",{href:js,target:"_blank",rel:"noopener noreferrer",onClick:()=>j("android"),className:"inline-flex items-center justify-center gap-2 rounded-md border border-gray-300 bg-white px-4 py-2.5 text-sm font-medium text-gray-800 hover:bg-gray-50 dark:border-gray-600 dark:bg-gray-900 dark:text-gray-200 dark:hover:bg-gray-800",children:[e.jsx("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M17.523 16.62c-.51.75-1.02 1.5-1.73 2.02-.74.54-1.38.76-2.22.76-.86 0-1.45-.33-2.3-.33-.87 0-1.14.33-2.32.33-.84 0-1.48-.22-2.22-.76-.72-.52-1.23-1.27-1.74-2.02-.96-1.45-1.69-3.08-1.69-4.84 0-1.72.61-3.1 1.67-4.08.78-.72 1.57-1.03 2.56-1.08.83-.04 1.55.27 2.22.48.46.16.91.35 1.37.35.5 0 .97-.19 1.44-.35.73-.25 1.45-.56 2.26-.48.97.04 1.85.34 2.63.98-2.08 1.94-1.76 5.19.12 6.72-.66.94-1.51 1.87-2.53 2.46zm-3.41-10.65c.03-1.15.47-2.22 1.12-2.96.72-.82 1.76-1.35 2.77-1.35.06 1.16-.3 2.27-.94 3.02-.69.84-1.72 1.41-2.68 1.47-.07-.09-.14-.18-.2-.27-.07-.1-.13-.19-.19-.28-.08-.13-.12-.2-.12-.31-.01-.1.02-.2.05-.32.04-.1.08-.2.12-.3.05-.1.1-.2.16-.3.07-.1.13-.2.21-.27z"})}),"Google Play"]}),Ut,e.jsx("p",{className:"text-center text-xs text-gray-400 dark:text-gray-500",children:x?"Free month applied after subscribing and logging into the mobile app.":"Free month applied after logging into the mobile app."})]})]})})]}):null}const Kt="mobile_reward_granted_banner";function fi(t){try{return localStorage.getItem(`${Kt}_dismissed:${t}`)==="1"}catch{return!1}}function bi(t){try{localStorage.setItem(`${Kt}_dismissed:${t}`,"1")}catch{}}function yi(t){try{return localStorage.getItem(`${Kt}:${t}`)!==null}catch{return!1}}function ji(t){try{localStorage.removeItem(`${Kt}:${t}`)}catch{}}function qa({userId:t,isSubscribed:a}){const[s,r]=d.useState(()=>fi(t)),n=yi(t),i=d.useCallback(()=>{r(!0),bi(t),ji(t)},[t]);return!n||s||!a?null:e.jsx("div",{className:"rounded-3xl border border-emerald-200 bg-emerald-50 p-4 shadow-sm dark:border-emerald-800 dark:bg-emerald-950/30",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-emerald-600 text-white shadow-sm dark:bg-emerald-500",children:e.jsx(fn,{className:"h-6 w-6"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white",children:"You earned a free month!"}),e.jsx("p",{className:"mt-0.5 text-xs font-medium text-gray-600 dark:text-gray-300",children:"Your mobile reward has been credited to your account."})]}),e.jsx("button",{type:"button",onClick:i,className:"rounded-full p-1 text-emerald-400 hover:text-emerald-600 dark:text-emerald-500 dark:hover:text-emerald-300","aria-label":"Dismiss",children:e.jsx(se,{className:"h-3.5 w-3.5"})})]})})}async function vi(){const t=await fetch("/api/geo-sync/entries/pending",{credentials:"include",headers:{"Cache-Control":"no-cache"}});if(!t.ok)throw new Error("Failed to fetch geo sync entries");return(await t.json()).map(s=>{var r,n;return{...s,propertyName:s.propertyName??((r=s.property)==null?void 0:r.nickname)??void 0,visitorName:s.visitorName??(s.recordedBy&&`${s.recordedBy.firstName||""} ${s.recordedBy.lastName||""}`.trim()||void 0),visitorProfileImageUrl:s.visitorProfileImageUrl??((n=s.recordedBy)==null?void 0:n.profileImageUrl)??void 0}})}async function Ni(){const t=await fetch("/api/geo-sync/entries/approved",{credentials:"include",headers:{"Cache-Control":"no-cache"}});if(!t.ok)throw new Error("Failed to fetch approved geo sync entries");return(await t.json()).map(s=>{var r,n;return{...s,propertyName:s.propertyName??((r=s.property)==null?void 0:r.nickname)??void 0,visitorName:s.visitorName??(s.recordedBy&&`${s.recordedBy.firstName||""} ${s.recordedBy.lastName||""}`.trim()||void 0),visitorProfileImageUrl:s.visitorProfileImageUrl??((n=s.recordedBy)==null?void 0:n.profileImageUrl)??void 0}})}async function wi(){const t=await fetch("/api/geo-sync/entries/discarded",{credentials:"include",headers:{"Cache-Control":"no-cache"}});if(!t.ok)throw new Error("Failed to fetch discarded geo sync entries");return t.json()}async function ki(t){const a=await fetch("/api/geo-sync/save-and-approve",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!a.ok)throw new Error("Failed to save and approve entry");return a.json()}async function Ci(t){if(!(await fetch("/api/geo-sync/save-draft",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)})).ok)throw new Error("Failed to save draft")}async function Si(){const t=await fetch("/api/geo-sync/settings",{credentials:"include"});if(!t.ok)throw new Error("Failed to fetch geo sync settings");return t.json()}async function Ti(t){const a=await fetch("/api/geo-sync/approve",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({id:t})});if(!a.ok)throw new Error("Failed to approve entry");return a.json()}async function Mi(t){if(!(await fetch("/api/geo-sync/reject",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({id:t})})).ok)throw new Error("Failed to reject entry")}async function Ei(t){const a=await fetch("/api/geo-sync/bulk-approve",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({ids:t})});if(!a.ok)throw new Error("Failed to bulk approve entries");return a.json()}async function Di(t){const a=await fetch("/api/geo-sync/settings",{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({autoApproveGeoSync:t})});if(!a.ok)throw new Error("Failed to update settings");return a.json()}
31function za(){const t=Re(),[a,s]=d.useState("approved"),[r,n]=d.useState(null),i=()=>n(null),{data:l=[],isLoading:o,error:f}=le({queryKey:["/api/geo-sync/entries/pending"],queryFn:vi,staleTime:0,refetchInterval:!1}),{data:x=[],isLoading:h,error:N}=le({queryKey:["/api/geo-sync/entries/approved"],queryFn:Ni,staleTime:0,refetchInterval:!1}),{data:u=[],isLoading:j,error:b}=le({queryKey:["/api/geo-sync/entries/discarded"],queryFn:wi,staleTime:0,refetchInterval:!1}),v={pending:l.length,approved:x.length,discarded:u.length,all:l.length+x.length+u.length},w=a==="approved"?x:a==="discarded"?u:a==="all"?[...l,...x,...u]:l,g=a==="approved"?h:a==="discarded"?j:a==="all"?o||h||j:o,k=a==="approved"?N:a==="discarded"?b:a==="all"?f||N||b:f,{data:C}=le({queryKey:["/api/geo-sync/settings"],queryFn:Si,staleTime:0}),T=ce({mutationFn:ki,onSuccess:D=>{D!=null&&D.scoreDelta&&n(D.scoreDelta)},onMutate:async D=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const R=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],E=>(E||[]).filter(_=>_.id!==D.id)),{previousEntries:R}},onError:(D,R,E)=>{E!=null&&E.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],E.previousEntries)},onSettled:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/approved"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/discarded"]})}}),I=ce({mutationFn:({id:D})=>Ti(D),onSuccess:D=>{D!=null&&D.scoreDelta&&n(D.scoreDelta)},onMutate:async({id:D})=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const R=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],E=>(E||[]).filter(_=>_.id!==D)),{previousEntries:R}},onError:(D,R,E)=>{E!=null&&E.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],E.previousEntries)},onSettled:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/approved"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/discarded"]})}}),p=ce({mutationFn:({id:D})=>Mi(D),onMutate:async({id:D})=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const R=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],E=>(E||[]).filter(_=>_.id!==D)),{previousEntries:R}},onError:(D,R,E)=>{E!=null&&E.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],E.previousEntries)},onSettled:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/approved"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/discarded"]})}}),O=ce({mutationFn:D=>Ei(D),onSuccess:D=>{D!=null&&D.scoreDelta&&n(D.scoreDelta)},onMutate:async D=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const R=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],E=>(E||[]).filter(_=>!D.includes(_.id))),{previousEntries:R}},onError:(D,R,E)=>{E!=null&&E.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],E.previousEntries)},onSettled:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/approved"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/discarded"]})}}),A=ce({mutationFn:Di,onSuccess:D=>{t.setQueryData(["/api/geo-sync/settings"],D)}}),z=ce({mutationFn:Ci,onSettled:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]})}}),$=T.isPending||z.isPending||I.isPending||p.isPending||O.isPending;return{entries:w,pendingEntries:l,approvedEntries:x,discardedEntries:u,listFilter:a,setListFilter:s,statusCounts:v,isLoading:g,error:k??null,refetch:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/approved"]}),t.invalidateQueries({queryKey:["/api/geo-sync/entries/discarded"]}),t.invalidateQueries({queryKey:["/api/geo-sync/settings"]})},settings:C,lastScoreDelta:r,clearScoreDelta:i,saveAndApproveEntry:T,s
31aveDraftEntry:z,approveEntry:I,rejectEntry:p,bulkApprove:O,updateSettings:A,isApproving:$}}function Pi(){const{statusCounts:t,isLoading:a,error:s}=Da();return{count:(t==null?void 0:t.available)??0,pendingCount:(t==null?void 0:t.pending)??0,isLoading:a,error:s??null}}function Ai(t,a,s){return t?"loading":a?"error":s?"success":"empty"}function Fi(t,a){const s=ds(t,{weekStartsOn:0}),r=new Date;return{monthLabel:Q(t,"MMMM yyyy"),availableToConvertCount:a,days:Array.from({length:7},(n,i)=>{const l=as(s,i),o=Q(l,"yyyy-MM-dd")===Q(t,"yyyy-MM-dd"),f=Q(l,"yyyy-MM-dd")===Q(r,"yyyy-MM-dd");return{date:l,dayLabel:Q(l,"EEEEE"),dayNumber:Number(Q(l,"d")),isSelected:o,isToday:f,availableCount:o&&a>0?a:0}})}}function Gs(t){if(t)return{id:t.id,visitorName:t.visitorName||"Unknown visitor",visitorProfileImageUrl:t.visitorProfileImageUrl,propertyName:t.propertyName,date:t.date,hours:Number(t.hours||0),description:t.description}}function Ri({user:t,progress:a,pendingReviewCount:s,mailConnected:r,mailHasError:n,mailHasCredentialIssue:i=!1,isMailSyncing:l=!1,calendarConnected:o,calendarHasError:f,selectedYear:x,onYearChange:h,isSubscribed:N,isOnTrial:u}){const[,j]=Mt(),[b,v]=d.useState(()=>
31new Date),[w,g]=d.useState(null),[k,C]=d.useState(!1),[T,I]=d.useState(null),[p,O]=d.useState(!1),[A,z]=d.useState(!1),[$,K]=d.useState(!1),[D,R]=d.useState(!1),[E,_]=d.useState(!1),[P,F]=d.useState(!1),[S,L]=d.useState(!1),{pendingEntries:m,approvedEntries:c,discardedEntries:M,statusCounts:G,isLoading:V,error:U,approveEntry:ae,rejectEntry:J,saveAndApproveEntry:Z,saveDraftEntry:ue,isApproving:we,settings:he,updateSettings:ee}=za(),ke=d.useMemo(()=>m.filter(Y=>Y.approvalStatus==="pending").map(Gs).filter(Y=>!!Y),[m]),Qe=d.useMemo(()=>c.map(Gs).filter(Y=>!!Y),[c]),Ue=Ai(V,!!U,m.length>0||c.length>0||M.length>0),{statusCounts:Ce,isRefetching:Ke}=Ma(),Ye=(Ce==null?void 0:Ce.pending)??0,be=Pi(),Oe=be.count,Be=be.pendingCount,$e=Oe<=0?Be:Oe,de=d.useMemo(()=>Fi(b,$e),[b,$e]),Se=Y=>{j(Y),Xa(Y)},y=r&&i,B=[{id:"mail",label:"MAIL SYNC",subtitle:n?"Sync error...":y?"Credentials expired â reconnect":r?"Connected and ready":"Connect mail to sync",status:n?"error":y?"warning":r?"connected":"inactive",badgeLabel:n?"ERROR":y?"RECONNECT":r?"CONNECTED":"CONNECT",icon:"mail",onClick:()=>{y||!r?F(!0):_(!0)}},{id:"calendar",label:"CALENDAR SYNC",subtitle:be.error?"Sync error...":o?"Connected and ready":"Connect calendar to sync",status:be.error?"error":o?"connected":"inactive",badgeLabel:be.error?"error":o?"CONNECTED":"CONNECT",icon:"calendar",onClick:()=>{o?R(!0):F(!0)}}];return e.jsx("div",{className:"min-h-screen bg-gray-50 pt-3 dark:bg-background","data-testid":"mobile-dashboard-content",children:e.jsxs("div",{className:"mx-auto flex w-full container-mobile flex-col gap-4",children:[e.jsx(Sn,{user:t,notificationCount:s,onNotificationsClick:()=>Se("/activity-ledger"),onProfileClick:()=>Se("/settings"),selectedYear:x,onYearChange:h,repType:t.repType}),e.jsx(Tn,{count:s,onClick:()=>Se("/activity-ledger")}),e.jsx(Ha,{userId:t.id,isSubscribed:N??(!!t.stripeSubscriptionId&&(t.subscriptionStatus==="active"||t.subscriptionStatus==="trialing")),isOnTrial:u,mobileInstallCompleted:t.mobileInstallCompleted}),e.jsx(qa,{userId:t.id,isSubscribed:!!N}),e.jsxs("button",{type:"button",onClick:()=>Se("/team"),className:"flex items-center justify-between rounded-3xl border border-gray-100 bg-white p-4 text-left shadow-sm transition active:scale-[0.99] dark:border-gray-800 dark:bg-card",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-emerald-50 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-300",children:e.jsx(Ja,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-gray-950 dark:text-white",children:"Team Workspace"}),e.jsx("p",{className:"mt-0.5 truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:"Invite members and manage access"})]})]}),e.jsx(ne,{className:"h-5 w-5 shrink-0 text-gray-400"})]}),e.jsx(Dn,{summary:a,onTimerClick:()=>K(!0),onDetailsClick:()=>K(!0)}),e.jsx(An,{open:$,onOpenChange:K,summary:a}),e.jsx(si,{summary:de,state:f?"error":"success",onPreviousWeek:()=>v(Y=>as(Y,-7)),onNextWeek:()=>
31v(Y=>as(Y,7)),onFullViewClick:()=>R(!0)}),e.jsx(ai,{pendingReviewCount:Ye,isSyncing:Ke,syncError:n,onFullViewClick:()=>_(!0)}),e.jsx(oi,{items:B,onManageClick:()=>F(!0)}),e.jsx(ci,{pendingEntries:ke,approvedEntries:Qe,discardedEntries:M,statusCounts:G,state:Ue,isMutating:we,onApprove:Y=>ae.mutate({id:Y}),onReject:Y=>J.mutate({id:Y}),onOpenDetails:Y=>{const X=m.find(We=>We.id===Y)??c.find(We=>We.id===Y)??null,Et=M.find(We=>We.id===Y)??null;Et?(I(Et),O(!0)):(g(X),C(!!X))},onManageClick:()=>z(!0)}),e.jsx(ui,{open:A,onOpenChange:z,settings:he,onUpdateSettings:Y=>ee.mutate(Y),isSaving:ee.isPending}),e.jsx(xi,{open:k,onOpenChange:C,entry:w,onSaveAndApprove:Y=>{Z.mutate(Y),C(!1)},onSaveDraft:Y=>{ue.mutate(Y),C(!1)},onReject:Y=>{J.mutate({id:Y}),C(!1)}}),e.jsx(hi,{open:p,onOpenChange:O,entry:T}),e.jsx(Hn,{open:D,onOpenChange:R}),e.jsx(Zn,{open:E,onOpenChange:_}),e.jsx(ei,{open:P,onOpenChange:F,onConnectImap:()=>L(!0)}),e.jsx(hn,{open:S,onOpenChange:Y=>{L(Y),Y||F(!1)}})]})})}async function Ii(){const t=await fetch("/api/export/csv",{credentials:"include"});if(t.status===403)throw new Error("SUBSCRIPTION_REQUIRED");if(!t.ok)throw new Error(`Export failed: ${t.statusText}`);return t.blob()}async function Li(){const t=await fetch("/api/export/csv-with-files",{credentials:"include"});if(t.status===403)throw new Error("SUBSCRIPTION_REQUIRED");if(!t.ok)throw new Error(`Export failed: ${t.statusText}`);return t.blob()}const _i=()=>{d.useEffect(()=>{const t=()=>setTimeout(()=>{xa(()=>import("./analytics-DZfAxZm8.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])).catch(()=>{})},2e3),a=()=>{t(),document.removeEventListener("mousemove",a),document.removeEventListener("keydown",a),document.removeEventListener("click",a)};return document.addEventListener("mousemove",a,{once:!0}),document.addEventListener("keydown",a,{once:!0}),document.addEventListener("click",a,{once:!0}),()=>{document.removeEventListener("mousemove",a),document.removeEventListener("keydown",a),document.removeEventListener("click",a)}},[])},Oi=()=>{d.useEffect(()=>{const t=document.createElement("link");t.rel="dns-prefetch",t.href="https://fonts.googleapis.com",document.head.appendChild(t);const a=document.createElement("link");return a.rel="preconnect",a.href=window.location.origin,document.head.appendChild(a),()=>{document.head.removeChild(t),document.head.removeChild(a)}},[])};function $i({url:t,enabled:a=!0,delayMs:s=1500,onMessage:r,onConnect:n,onDisconnect:i,onError:l}){const[o,f]=d.useState(!1),[x,h]=d.useState("idle"),N=d.useRef(null),u=d.useRef(),j=d.useRef(),b=d.useRef(0),v=()=>{var k,C;if(!(!a||((k=N.current)==null?void 0:k.readyState)===WebSocket.CONNECTING||((C=N.current)==null?void 0:C.readyState)===WebSocket.OPEN)){h("connecting");try{try{N.current=new WebSocket(t)}catch(T){console.error("[WebSocket] Failed to create WebSocket connection:",T),h("disconnected"),l==null||l(T);return}N.current.onopen=()=>{f(!0),h("connected"),b.current=0,n==null||n()},N.current.onmessage=T=>{try{const I=JSON.parse(T.data);r==null||r(I)}catch(I){console.warn("[WebSocket] Failed to parse message:",I)}},N.current.onclose=()=>{if(f(!1),h("disconnected"),i==null||i(),a&&b.current<5){const T=Math.min(1e3*Math.pow(2,b.current),3e4);u.current=setTimeout(()=>{b.current++,v()},T)}},N.current.onerror=T=>{console.warn("[WebSocket] Connection error:",T),l==null||l(T)}}catch(T){console.error("[WebSocket] Failed to create connection:",T),h("disconnected")}}},w=()=>{u.current&&clearTimeout(u.current),j.current&&clearTimeout(j.current),N.current&&(N.current.close(),N.current=null),f(!1),h("disconnected")},g=k=>{var C;((C=N.current)==null?void 0:C.readyState)===WebSocket.OPEN?N.current.send(JSON.stringify(k)):console.warn("[WebSocket] Cannot send message - connection not open")};return d.useEffect(()=>{if(!a){w();return}if(["/features","/pricing","/why-reps-shield","/about"].includes(window.location.pathname)||window.location.pathname.startsWith("/features/"))return;const C=()=>{if(document.visibilityState==="visible"&&document.querySelector('[data-testid="dashboard-content"], .min-h-screen'))j.current=setTimeout(v,s);else{const I=()=>{document.visibilityState==="visible"&&document.querySelector('[data-testid="dashboard-content"], .min-h-screen')?j.current=setTimeout(v,s):setTimeout(I,100)};I()}};C();const T=()=>{document.visibilityState==="hidden"?w():document.visibilityState==="visible"&&a&&C()};return document.addEventListener("visibilitychange",T),()=>{document.removeEventListener("visibilitychange",T),w()}},[a,t,s]),{isConnected:o,connectionState:x,sendMessage:g,connect:v,disconnect:w}}function Hi(){const{user:t,isLoading:a}=Tt(),{toast:s}
31=fe(),[r,n]=d.useState(!1);return d.useEffect(()=>(document.body.classList.add("wallpaper-bg"),()=>{document.body.classList.remove("wallpaper-bg")}),[]),d.useEffect(()=>{n(!0)},[]),d.useEffect(()=>{!a&&!t&&(s({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500))},[t,a,s]),{hasMounted:r}}const Vs="oauthPending";function qi(){const t=Re(),{toast:a}=fe(),s=d.useCallback(r=>{switch(r){case"googleCalendar":{t.invalidateQueries({queryKey:["google-calendar","status"]}),t.invalidateQueries({queryKey:["calendar","events"]}),t.invalidateQueries({queryKey:["mail","status"]}),Is.triggerAutoSync().catch(()=>{}),a({title:"Calendar Connected!",description:"Your Google Calendar has been successfully connected."});break}case"microsoftCalendar":{t.invalidateQueries({queryKey:["microsoft-calendar","status"]}),t.invalidateQueries({queryKey:["calendar","events"]}),t.invalidateQueries({queryKey:["mail","status"]}),Is.triggerAutoSync().catch(()=>{}),a({title:"Microsoft Calendar Connected!",description:"Your Microsoft Calendar has been successfully connected."});break}case"microsoftMail":{t.invalidateQueries({queryKey:["microsoft-mail","status"]}),t.invalidateQueries({queryKey:["mail","unified"]}),t.invalidateQueries({queryKey:["mail","status"]}),Za.triggerMailAutoSync().catch(()=>{}),t.refetchQueries({queryKey:["mail","unified"]}),a({title:"Outlook Connected!",description:"Your Outlook account has been successfully connected."});break}case"gmail":{t.invalidateQueries({queryKey:["imap","status"]}),t.invalidateQueries({queryKey:["mail","unified"]}),t.invalidateQueries({queryKey:["mail","status"]});break}}},[t,a]);d.useEffect(()=>{const r=new URLSearchParams(window.location.search);let n=!1;if(r.get("calendar")==="success"&&(s("googleCalendar"),n=!0),r.get("microsoft_calendar")==="success"&&(s("microsoftCalendar"),n=!0),r.get("outlook")==="success"&&(s("microsoftMail"),n=!0),!n){const f=sessionStorage.getItem(Vs);f&&(s(f),n=!0)}sessionStorage.removeItem(Vs),n&&window.history.replaceState({},document.title,window.location.pathname)},[t,a,s])}function zi({subscription:t,user:a}){const[s,r]=d.useState(null);return d.useEffect(()=>{if(a!=null&&a.isAdmin)return;const n=t==null?void 0:t.isOnTrial,i=t==null?void 0:t.trialEndDate;if(n&&i){const l=new Date(i),o=new Date,f=l.getTime()-o.getTime(),x=Math.floor(f/(1e3*60*60*24)),h=Math.max(0,x);r(h),localStorage.getItem(`trial_tracked_${a==null?void 0:a.id}`)||(xa(async()=>{const{trackTrialStarted:N}=await import("./index-DGo-vssZ.js").then(u=>u.g7);return{trackTrialStarted:N}},__vite__mapDeps([1,2,3])).then(({trackTrialStarted:N})=>{N(a==null?void 0:a.id,{trial_days_remaining:h,trial_end_date:l.toISOString()})}),localStorage.setItem(`trial_tracked_${a==null?void 0:a.id}`,"true")),r(0)}else r(null)},[t,a]),{trialDaysRemaining:s}}function Gi({user:t,totalHours:a,materialHours:s,selectedYear:r}){const n=new Date().getFullYear(),{data:i}=le({queryKey:["/api/stats/rep-requirements",{repType:t==null?void 0:t.repType,year:n}],enabled:!!(t!=null&&t.repType)}),l=(a==null?void 0:a.totalHours)||0,o=(s==null?void 0:s.materialHours)||0,f=(t==null?void 0:t.repType)==="shortTerm",x=(i==null?void 0:i.totalHoursRequired)??(f?500:750),h=(i==null?void 0:i.materialHoursRequired)??(f?100:500),N=Math.min(l/x*100,100),u=f?Math.min(o/h*100,100):0,j=Math.max(x-l,0),b=er(l,o,(t==null?void 0:t.repType)==="shortTerm"?"shortTerm":"longTerm");return{totalHoursValue:l,materialHoursValue:o,goalHours:x,materialGoal:h,progressPercentage:N,materialProgressPercentage:u,remainingHours:j,complianceStatus:b,repRequirements:i}}function Ga(){const{toast:t}=fe(),a=Re(),[,s]=Mt(),[r,n]=d.useState(!1),[i,l]=d.useState(Cs),o=ce({mutationFn:tr,onSuccess:x=>{sr(void 0,{property_type:i.propertyType});const h=a.getQueryData(["/api/properties"]);rs("property_added",{source:"manual",property_type:i.propertyType,...Array.isArray(h)?{is_first:h.length===0}:{}}),a.invalidateQueries({queryKey:["/api/properties"]}),l(Cs),n(!1),x!=null&&x.id?s(`/properties/${x.id}`):t({title:"Success",description:"Property added successfully"}),Ss.isRunning&&Ss.refreshGeofences().catch(console.error)},onError:x=>{if(Ht(x)){t({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500);return}t({title:"Error",description:"Failed to add property",variant:"destructive"})}});return{showForm:r,setShowForm:n,formData:i,setFormData:l,handleSubmit:x=>{x.preventDefault(),o.mutate(i)},isPending:o.isPending}}function Vi(t){return/^403: .*Subscription required/.test(t.message)||t.message.includes("upgradeRequired")}function os(t,a){return`${t} is a Pro feature. Upgrade to REPSShield to unlock this feature.`}function Qi(t){const{toast:a}=fe(),[s,r]=d.useState(!1),n=(o,f)=>{const x=window.URL.createObjectURL(o),h=document.createElement("a");h.href=x,h.download=f,document.body.appendChild(h),h.click(),window.URL.revokeObjectURL(x),document.body.removeChild(h)};return{handleExportCSV:async()=>
31{if(!t){r(!0);return}Ts(void 0,{export_type:"csv",export_format:"standard"});try{const o=await Ii(),f=`rep-tracker-export-${new Date().toISOString().split("T")[0]}.csv`;n(o,f),ua(void 0,{report_type:"csv_export",export_format:"standard"}),rs("report_exported",{report_type:"csv",export_format:"standard"}),a({title:"Export Successful",description:"Your data has been exported to CSV",variant:"default"})}catch(o){if(o.message==="SUBSCRIPTION_REQUIRED"){a({title:"Subscription Required",description:os("CSV Export"),variant:"destructive"});return}a({title:"Export Failed",description:o.message||"Failed to export CSV",variant:"destructive"})}},handleExportCSVWithFiles:async()=>{if(!t){r(!0);return}Ts(void 0,{export_type:"csv_with_files",export_format:"archive"});try{const o=await Li(),f=`repsshield-export-with-files-${new Date().toISOString().split("T")[0]}.zip`;n(o,f),rs("report_exported",{report_type:"csv_with_files",export_format:"archive"}),a({title:"Export Successful",description:"Your data and files have been exported to a zip file",variant:"default"})}catch(o){if(o.message==="SUBSCRIPTION_REQUIRED"){a({title:"Subscription Required",description:os("CSV Export with Files"),variant:"destructive"});return}a({title:"Export Failed",description:o.message||"Failed to export CSV with files",variant:"destructive"})}},showPaywallModal:s,setShowPaywallModal:r}}function Ui({onClose:t}){const{calendarAutomation:a,setCalendarAutomation:s,handleSaveCalendar:r,isSavingCalendar:n}=fs(),[i,l]=d.useState(""),[o,f]=d.useState(""),[x,h]=d.useState(!1),{toast:N}=fe(),{suggestions:u,isLoading:j,refreshSuggestions:b}=Ta("calendar",!0),v=p=>{const O=p.trim();O&&(a.trustedOrganizers.includes(O)||s({...a,trustedOrganizers:[...a.trustedOrganizers,O]}))},w=p=>{s({...a,trustedOrganizers:a.trustedOrganizers.filter(O=>O!==p)})},g=p=>{const O=p.trim();O&&(a.trustedKeywords.includes(O)||s({...a,trustedKeywords:[...a.trustedKeywords,O]}))},k=p=>{s({...a,trustedKeywords:a.trustedKeywords.filter(O=>O!==p)})},C=p=>{v(p),b()},T=async p=>{try{await sn.dismissSuggestion(p,"calendar"),b(),N({title:"Suggestion dismissed",description:`${p} won't appear in suggestions again.`})}catch{N({title:"Failed to dismiss",description:"Could not dismiss suggestion. Please try again.",variant:"destructive"})}},I=u.filter(p=>!a.trustedOrganizers.includes(p.email));return e.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-slate-900 animate-in fade-in slide-in-from-bottom-4 duration-500",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-slate-100 dark:border-slate-800 top-0 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm z-10",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:"Automation Settings"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Automatically approve and organize real-estateârelated calendar events."})]}),e.jsx(q,{variant:"ghost",size:"icon",onClick:t,className:"h-8 w-8 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-8",children:[e.jsx("section",{children:e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"mt-1 p-1.5 bg-green-50 dark:bg-green-900/20 rounded-md",children:e.jsx(rt,{className:"h-4 w-4 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900 dark:text-slate-100",children:"AI-Assisted Approval"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"When enabled, events our AI confidently identifies as real-estate related are auto-approved."})]})]}),e.jsx(Ae,{checked:a.autoApproveHighConfidence,onCheckedChange:p=>s({...a,autoApproveHighConfidence:p})})]})}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"mt-1 p-1.5 bg-amber-50 dark:bg-amber-900/20 rounded-md",children:e.jsx(Qt,{className:"h-4 w-4 text-amber-600 dar
31k:text-amber-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900 dark:text-slate-100",children:"Rule-Based Approval"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Create your own conditions to automatically approve certain events."})]})]}),e.jsx(Ae,{checked:a.enabled,onCheckedChange:p=>s({...a,enabled:p})})]}),e.jsx("div",{className:"ml-10 mt-4 space-y-6 animate-in fade-in slide-in-from-top-2 duration-300",children:e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900/50 border border-slate-100 dark:border-slate-800 rounded-xl p-5 space-y-6",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm text-slate-900 dark:text-slate-100 mb-3",children:"Trusted Organizers"}),e.jsx("div",{className:"flex gap-2 flex-wrap mb-3",children:a.trustedOrganizers.map(p=>e.jsxs("div",{className:"bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 px-3 py-1.5 rounded-full flex items-center gap-2 shadow-sm",children:[e.jsx("span",{className:"text-sm text-slate-700 dark:text-slate-300",children:p}),e.jsx("button",{onClick:()=>w(p),className:"text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors",children:e.jsx(se,{className:"h-3 w-3"})})]},p))}),e.jsx("input",{placeholder:"Type an email and press Enter...",value:i,onChange:p=>l(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),v(i),l(""))},className:"w-full px-3 py-2 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm focus:outline-none focus:ring-2 focus:ring-slate-200 dark:focus:ring-slate-700 transition-all"}),e.jsx("p",{className:"text-xs text-slate-500 mt-2",children:"Press Enter to add multiple organizers."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm text-slate-900 dark:text-slate-100 mb-3",children:"Keywords"}),e.jsx("div",{className:"flex gap-2 flex-wrap mb-3",children:a.trustedKeywords.map(p=>e.jsxs("div",{className:"bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 px-3 py-1.5 rounded-full flex items-center gap-2 shadow-sm",children:[e.jsx("span",{className:"text-sm text-slate-700 dark:text-slate-300",children:p}),e.jsx("button",{onClick:()=>k(p),className:"text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors",children:e.jsx(se,{className:"h-3 w-3"})})]},p))}),e.jsx("input",{placeholder:"Type a keyword and press Enter...",value:o,onChange:p=>f(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),g(o),f(""))},className:"w-full px-3 py-2 rounded-lg border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm focus:outline-none focus:ring-2 focus:ring-slate-200 dark:focus:ring-slate-700 transition-all"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm text-slate-900 dark:text-slate-100 mb-2",children:"Suggested Trusted Organizers"}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mb-3",children:"Click to approve organizers identified from your high-confidence calendar activity."}),e.jsxs("div",{className:"rounded-xl border border-dashed border-slate-300 dark:border-slate-700 bg-slate-50/50 dark:bg-slate-900/50 p-4 min-h-[100px] flex flex-wrap gap-2 content-start transition-all duration-200 hover:bg-slate-50 dark:hover:bg-slate-900",children:[j&&e.jsx("div",{className:"w-full text-sm text-slate-500 text-center py-4",children:"Loading suggestions..."}),!j&&I.length===0&&e.jsx("div",{className:"w-full text-sm text-slate-500 text-center py-4 italic",children:"No new suggestions available."}),!j&&e.jsx(He,{children:I.map(p=>e.jsxs(qe,{children:[e.jsx(ze,{asChild:!0,children:e.jsxs("div",{className:"group relative",children:[e.jsx(te,{variant:"secondary",className:"cursor-pointer hover:bg-blue-100 dark:hover:bg-blue-900/40 hover:text-blue-700 dark:hover:text-blue-300 border-slate-200 dark:border-slate-700 transition-all active:scale-95 pr-8",onClick:()=>C(p.email),children:p.email}),e.jsx("button",{onClick:O=>{O.stopPropagation(),T(p.email)},className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 transition-opacity text-slate-400 hover:text-red-500 dark:hover:text-red-400",title:"Dismiss suggestion",children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]})}),e.jsx(Ge,{side:"top",children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-semibold mb-1",children:"Click to Approve"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500",children:"Confidence:"}),e.jsxs("span",{className:"font-medium",children:[Math.round(p.avgConfidence),"%"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500",children:"Occurrences:"}),e.jsx("span",{className:"font-medium",children:p.occurrences})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-slate-500",children:"Score:"}),e.jsx("span",{className:"font-medium",children:Math.round(p.score)})]}),e.jsxs("p",{className:"text-slate-400 mt-1 pt-1 border-t border-slate-200 dark:border-slate-700",children:["Last seen:"," ",new Date(p.lastSeen).toLocaleDateString()]})]})})]},p.email))})]})]})]})})]})]}
31),e.jsx("div",{className:"p-6 border-t border-slate-100 dark:border-slate-800 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm bottom-0 z-10",children:e.jsx(q,{onClick:r,disabled:n,className:"w-full bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white shadow-md hover:shadow-lg transition-all duration-300",children:n?"Saving Changes...":"Save Configuration"})})]})}function Qs({label:t,providerName:a,icon:s,isConnected:r,isLoading:n,onClick:i}){return e.jsx(He,{children:e.jsxs(qe,{delayDuration:200,children:[e.jsx(ze,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:i,disabled:n,"aria-label":`${a} ${r?"connected":"not connected"}`,className:"inline-flex h-8 items-center gap-2 rounded-full border border-gray-200 bg-white px-3 text-xs font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:opacity-60 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200 dark:hover:bg-gray-800",children:[s,e.jsx("span",{children:t}),n?e.jsx(at,{className:"h-3 w-3 animate-spin text-gray-500"}):e.jsx("span",{className:`h-2 w-2 rounded-full ${r?"bg-[#16a34a]":"bg-gray-300"}`})]})}),e.jsx(Ge,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-semibold text-sm flex items-center gap-2",children:r?e.jsxs(e.Fragment,{children:[e.jsx(nn,{className:"w-4 h-4 text-green-500"}),a," Connected"]}):e.jsxs(e.Fragment,{children:[e.jsx(ar,{className:"w-4 h-4 text-gray-400"}),"Connect ",a]})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r?"Click to disconnect or manage settings":"Click to connect and start automatic tracking"})]})})]})})}const Ki=e.jsxs("span",{className:"grid grid-cols-2 gap-[1.5px]","aria-hidden":"true",children:[e.jsx("span",{className:"h-[6px] w-[6px] bg-[#f25022]"}),e.jsx("span",{className:"h-[6px] w-[6px] bg-[#7fba00]"}),e.jsx("span",{className:"h-[6px] w-[6px] bg-[#00a4ef]"}),e.jsx("span",{className:"h-[6px] w-[6px] bg-[#ffb900]"})]});function Yi(t){var b,v;const[a,s]=d.useState(!1),[r,n]=d.useState(null),{user:i}=Tt(),{googleCalendarStatusQuery:l,microsoftCalendarStatusQuery:o,isGoogleCalendarConnecting:f,isMicrosoftCalendarConnecting:x}=ft(),h=ka();d.useEffect(()=>{if(new URLSearchParams(h).get("openAutomationSettings")==="1"){s(!0),Ms(i==null?void 0:i.id,"calendar");const g=new URL(window.location.href);g.searchParams.delete("openAutomationSettings"),window.history.replaceState({},"",`${g.pathname}${g.search}`)}},[h,i==null?void 0:i.id]);const N=((b=l.data)==null?void 0:b.connected)||!1,u=((v=o.data)==null?void 0:v.connected)||!1,j=e.jsx(Nt,{className:"pb-4 bg-white rounded-t-lg border-b",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-[34px] w-[34px] shrink-0 items-center justify-center rounded-[10px] bg-[#dcfce7] dark:bg-[#16a34a]/15",children:e.jsx(ge,{className:"h-[17px] w-[17px] text-[#16a34a]"})}),e.jsx("div",{children:e.jsx(wt,{className:"text-lg font-semibold",children:"Calendar Sync"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qs,{label:"Google",providerName:"Google Calendar",icon:e.jsx(Sa,{className:"h-4 w-4 text-blue-600"}),isConnected:N,isLoading:f,onClick:()=>{var w;return(w=t.setGoogleCalendarDialogOpen)==null?void 0:w.call(t,!0)}}),e.jsx(Qs,{label:"Outlook",providerName:"Microsoft Calendar",icon:Ki,isConnected:u,isLoading:x,onClick:()=>{var w;return(w=t.setMicrosoftCalendarDialogOpen)==null?void 0:w.call(t,!0)}}),e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>{s(!0),Ms(i==null?void 0:i.id,"calendar")},className:"text-muted-foreground hover:text-primary transition-colors","aria-label":"Calendar automation settings",children:e.jsx(jt,{className:"h-4 w-4 transition-transform duration-300",style:{transform:a?"rotate(90deg)":"rotate(0deg)"}})})]})]})});return e.jsx(xe,{className:"h-full dashboard-card-base flex flex-col",style:{perspective:"1000px"},children:e.jsxs("div",{className:"relative transition-transform duration-700 ease-in-out h-full",style:{transformStyle:"preserve-3d",transform:a?"rotateY(180deg)":"rotateY(0deg)"},children:[e.jsxs("div",{className:`h-full flex flex-col ${a?"pointer-events-none":""}`,style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},children:[j,e.jsx(Ea,{automationType:"calendar"}),e.jsxs(ie,{className:"p-6 flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(an,{onStatusCountsChange:n})}),e.jsx("div",{className:"mt-auto pt-4 px-6 pb-4 border-t border-gray-200 dark:border-gray-700 -mx-6 -mb-6",children:e.jsx(rn,{counts:r?{approved:r.approved,pending:r.pending,available:r.available}:void 0})})]})]}),e.jsx("div",{className:`absolute inset-0 h-full w-full ${a?"":"pointer-events-none"}`,style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"},children:e.jsx(Ui,{onClose:()=>s(!1)})})]})})}function Bi({onClose:t,settings:a,onUpdateSettings:s}){const r=(a==null?void 0:a.autoApproveGeoSync)??!1;return e.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-slate-900 animate-in fade-in slide-in-from-bottom-4 duration-500",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-slate-100 dar
31k:border-slate-800 top-0 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm z-10",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:"Geo Fence Settings"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Configure automatic approval for GPS-detected visits."})]}),e.jsx(q,{variant:"ghost",size:"icon",onClick:t,className:"h-8 w-8 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:e.jsx("section",{children:e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"mt-1 p-1.5 bg-green-50 dark:bg-green-900/20 rounded-md",children:e.jsx(rt,{className:"h-4 w-4 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900 dark:text-slate-100",children:"Auto-Approve Detected Visits"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"When enabled, visits detected by GPS geofencing that our AI confidently identifies as real-estate related will be automatically approved."})]})]}),e.jsx(Ae,{checked:r,onCheckedChange:n=>s(n)})]})})}),e.jsx("div",{className:"p-6 border-t border-slate-100 dark:border-slate-800 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm bottom-0 z-10",children:e.jsx(q,{onClick:t,className:"w-full",children:"Done"})})]})}function Wi({open:t,onOpenChange:a,entry:s,onSaveAndApprove:r,onSaveDraft:n,onReject:i}){return e.jsx(Ne,{open:t,onOpenChange:a,children:e.jsxs(Ie,{className:"sm:max-w-[600px] max-h-[90vh] overflow-y-auto p-4 sm:p-6 overscroll-contain",children:[e.jsx(Le,{children:e.jsxs(_e,{className:"flex items-center gap-2 text-base sm:text-lg",children:[e.jsx(nt,{className:"h-5 w-5 text-primary shrink-0"}),"Review Detected Visit"]})}),e.jsx(Oa,{entry:s,onSaveAndApprove:r,onSaveDraft:n,onReject:i,onCancel:()=>a(!1)})]})})}const mt=10,es="w-full overflow-hidden [&_h3]:m-2 text-xs hover:bg-muted/50 rounded-md cursor-pointer transition-colors border border-border/30 mb-2 bg-white",ts="flex w-full items-center gap-2 py-1.5 text-left normal-case hover:no-underline";function Us(){const[t,a]=d.useState(!1),[s,r]=d.useState(1),[n,i]=d.useState(null),[l,o]=d.useState(!1),[f,x]=d.useState(""),[h,N]=d.useState(!1),[u,j]=d.use
31State(),[b,v]=d.useState(new Set),{listFilter:w,setListFilter:g,statusCounts:k,entries:C,settings:T,isLoading:I,error:p,approveEntry:O,rejectEntry:A,bulkApprove:z,updateSettings:$,saveAndApproveEntry:K,saveDraftEntry:D,isApproving:R,refetch:E,lastScoreDelta:_,clearScoreDelta:P}=za(),F=y=>{const B=f.toLowerCase(),Y="propertyName"in y&&y.propertyName||"",X="visitorName"in y&&y.visitorName||"",Et="discardReason"in y&&y.discardReason||"";if(!(!f||Y.toLowerCase().includes(B)||X.toLowerCase().includes(B)||Et.toLowerCase().includes(B)))return!1;if(!u)return!0;const vs="discardReason"in y?y.enteredAt:y.date;return vs?Q(new Date(vs),"yyyy-MM-dd")===Q(u,"yyyy-MM-dd"):!1},S=C.filter(F),L=Math.ceil(S.length/mt),m=(s-1)*mt,c=S.slice(m,m+mt),M=c.map(y=>Z(y)),V=c.filter(y=>b.has(Z(y))).filter(y=>!J(y)&&y.approvalStatus==="pending"),U=M.length>0&&M.every(y=>b.has(y)),ae=M.some(y=>b.has(y))&&!U;function J(y){return"discardReason"in y}function Z(y){return J(y)?`discarded-${y.id}`:`entry-${y.id}`}const ue=y=>{const B=Z(y);v(Y=>{const X=new Set(Y);return X.has(B)?X.delete(B):X.add(B),X})},we=y=>{v(B=>{const Y=new Set(B);return y?M.forEach(X=>Y.add(X)):M.forEach(X=>Y.delete(X)),Y})},he=()=>v(new Set),ee=y=>{g(y),r(1),x(""),he()},ke=y=>{i(y),o(!0)},Qe=y=>{O.mutate({id:y.id})},Ue=y=>{A.mutate({id:y.id})},Ce=()=>{const y=V.map(B=>B.id);y.length!==0&&(z.mutate(y),he())},Ke=()=>
31{V.forEach(y=>A.mutate({id:y.id})),he()},Ye=e.jsx(Nt,{className:"pb-4 bg-white dark:bg-slate-900 rounded-t-lg border-b",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-[34px] h-[34px] rounded-[10px] bg-[#dcfce7] dark:bg-[#16a34a]/15 flex items-center justify-center",children:e.jsx(nt,{className:"h-[18px] w-[18px] text-[#16a34a]"})}),e.jsx(wt,{className:"text-lg font-semibold",children:"Geo Fence Sync"})]}),e.jsx("div",{className:"flex gap-2 items-center",children:e.jsx(q,{variant:"ghost",size:"icon",onClick:()=>a(!0),className:"text-muted-foreground hover:text-primary transition-colors","aria-label":"Geo fence automation settings",children:e.jsx(jt,{className:"h-4 w-4 transition-transform duration-300",style:{transform:t?"rotate(90deg)":"rotate(0deg)"}})})})]})}),be=[{value:"approved",label:"Approved",mobileLabel:"Approved",count:k.approved,dot:"#22c55e"},{value:"pending",label:"Pending Approval",mobileLabel:"Pending",count:k.pending,dot:"#f59e0b"},{value:"discarded",label:"Discarded",mobileLabel:"Discarded",count:k.discarded,dot:"#9ca3af"},{value:"all",label:"All",mobileLabel:"All",count:k.all,dot:null}],Oe=()=>e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center",children:[e.jsx(nt,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground mb-2",children:w==="pending"?"No pending visits to review.":w==="approved"?"No approved visits yet.":w==="discarded"?"No discarded visits.":"No visits found."}),w==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground/70 mb-6",children:"Download the mobile app to start tracking property visits."}),e.jsxs("div",{className:"flex items-center justify-center gap-4 flex-wrap",children:[e.jsx("a",{href:js,target:"_blank",rel:"noopener noreferrer",onClick:()=>qt({platform:"android",source:"geofence_empty_state"}),children:e.jsx("img",{src:"/images/google-play-badge.svg",alt:"Get it on Google Play",className:"h-[46px] w-auto"})}),_a?e.jsx("a",{href:Ut,target:"_blank",rel:"noopener noreferrer",onClick:()=>qt({platform:"ios",source:"geofence_empty_state"}),children:e.jsx("img",{src:"/images/app-store-badge.svg",alt:"Download on the App Store",className:"h-[46px] w-auto"})}):e.jsxs("div",{className:"relative inline-block",children:[e.jsx("div",{className:"opacity-30 grayscale cursor-not-allowed",children:e.jsx("img",{src:"/images/app-store-badge.svg",alt:"Download on the App Store",className:"h-[46px] w-auto"})}),e.jsx("span",{className:"absolute -top-2.5 -right-1 bg-primary text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full shadow-sm",children:"COMING SOON"})]})]})]})]}),Be=y=>{var B,Y;return e.jsxs(Ft,{value:`pending-${y.id}`,className:es,children:[e.jsxs(Rt,{className:ts,children:[e.jsx(ut,{checked:b.has(Z(y)),onCheckedChange:()=>ue(y),onClick:X=>X.stopPropagation(),"aria-label":`Select ${y.visitorName||y.propertyName||"geo fence visit"}`,className:"border-amber-500"}),e.jsx("span",{className:"h-[9px] w-[9px] rounded-full flex-none",style:{backgroundColor:"#f59e0b"}}),e.jsxs("div",{className:"w-0 flex-1 min-w-0",children:[e.jsxs("span",{className:"truncate text-xs block",children:[e.jsx("span",{className:"mr-1 font-semibold",children:y.visitorName||"Unknown Visitor"}),y.propertyName&&e.jsxs("span",{className:"text-muted-foreground",children:["â ",y.propertyName]})]}),e.jsxs("span",{className:"mt-0.5 flex items-center gap-1.5 truncate text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"capitalize",children:((B=y.activityType)==null?void 0:B.replace(/-/g," "))||"Property Visitation"}),y.timeStarted&&y.timeEnded&&e.jsxs("span",{children:["· ",Q(new Date(y.timeStarted),"h:mm a")," â"," ",Q(new Date(y.timeEnded),"h:mm a")]}),Number(y.hours)>8&&e.jsxs("span",{className:"inline-flex flex-none items-center gap-1 rounded-full border border-amber-500 bg-amber-50 px-1.5 py-px text-[10px] font-semibold text-amber-700 dark:bg-amber-900/20 dark:text-amber-400",children:[e.jsx(pt,{className:"h-3 w-3"}),"Long visit"]})]})]}),e.jsx("span",{className:"hidden sm:inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold flex-none bg-[#fef3c7] text-[#92400e]",children:"Pending Approval"}),e.jsxs("div",{className:"flex flex-none flex-col items-end",children:[e.jsxs("span",{className:"text-xs font-semibold text-foreground hidden sm:block",children:[Number(y.hours).toFixed(1),"h"]}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:Q(new Date(y.date),"MM/dd")})]})]}),e.jsx(It,{className:"px-4 py-1 text-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-muted-foreground",children:[y.description&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Description:"}),e.jsx("p",{className:"mt-0.5",children:y.description})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Activity:"}),e.jsx("p",{className:"mt-0.5 capitalize",children:((Y=y.activityType)==null?void 0:Y.replace(/-/g," "))||"Property Visitation"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Hours:"}),e.jsxs("p",{className:"mt-0.5",children:[Number(y.hours).toFixed(1)," hrs"]})]}),y.timeStarted&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Started:"}),e.jsx("p",{className:"mt-0.5",children:Q(new Date(y.timeStarted),"h:mm a")})]}),y.timeEnded&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Ended:"}),e.jsx("p",{className:"mt-0.5",children:Q(new Date(y.timeEnded),"h:mm a")})]})]}),e.jsxs("div",{className:"w-full flex justify-end gap-3 mb-2 pt-2",children:[e.jsx(q,{size:"sm",className:"h-7 px-2 gap-1.5 text-xs bg-gradient-to-br from-[#44958C] to-[#43A047] hover:opacity-95 text-white",onClick:X=>{X.stopPropagation(),Qe(y)},disabled:R,children:"Approve"}),e.jsx(q,{size:"sm",variant:"outline",className:"h-7 px-2 gap-1.5 text-xs",onClick:X=>{X.stopPropagation(),ke(y)},children:"Review"}),e.jsx(q,{size:"sm",variant:"outline",className:"h-7 px-2 gap-1.5 text-xs text-destructive",onClick:X=>{X.stopPropagation(),Ue(y)},disabled:R,children:"Discard"})]})]})})]},y.id)},$e=y=>{var B,Y;return e.jsxs(Ft,{value:String(y.id),className:es,children:[e.jsxs(Rt,{className:ts,children:[e.jsx(ut,{checked:b.has(Z(y)),onCheckedChange:()=>ue(y),onClick:X=>X.stopPropagation(),"aria-label":`Select ${y.visitorName||y.propertyName||"geo fence visit"}`,className:"border-green-500"}),e.jsx("span",{className:"h-[9px] w-[9px] rounded-full flex-none",style:{backgroundColor:"#22c55e"}}),e.jsxs("div",{className:"w-0 flex-1 min-w-0",children:[e.jsxs("span",{className:"truncate text-xs block",children:[e.jsx("span",{className:"mr-1 font-semibold",children:y.visitorName||"Unknown Visitor"}),y.propertyName&&e.jsxs("span",{className:"text-muted-foreground",children:["â ",y.propertyName]})]}),e.jsxs("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"capitalize",children:((B=y.activityType)==null?void 0:B.replace(/-/g," "))||"Property Visitation"}),y.timeStarted&&y.timeEnded&&e.jsxs("span",{children:["· ",Q(new Date(y.timeStarted),"h:mm a")," â"," ",Q(new Date(y.timeEnded),"h:mm a")]})]})]}),e.jsx("span",{className:"hidden sm:inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold flex-none bg-[#dcfce7] text-[#166534]",children:"Approved"}),e.jsxs("div",{className:"flex flex-none flex-col items-end",children:[e.jsxs("span",{className:"text-xs font-semibold text-foreground hidden sm:block",children:[Number(y.hours).toFixed(1),"h"]}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:Q(new Date(y.date),"MM/dd")})]})]}),e.jsx(It,{className:"px-4 py-1 text-xs",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-muted-foreground",children:[y.description&&e.jsxs("div",{className:"col-span-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Description:"}),e.jsx("p",{className:"mt-0.5",children:y.description})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Activity:"}),e.jsx("p",{className:"mt-0.5 capitalize",children:((Y=y.activityType)==null?void 0:Y.replace(/-/g," "))||"Property Visitation"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Hours:"}),e.jsxs("p",{className:"mt-0.5",children:[Number(y.hours).toFixed(1)," hrs"]})]}),y.timeStarted&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Started:"}),e.jsx("p",{className:"mt-0.5",children:Q(new Date(y.timeStarted),"h:mm a")})]}),y.timeEnded&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Ended:"}),e.jsx("p",{className:"mt-0.5",children:Q(new Date(y.timeEnded),"h:mm a")})]})]})})]},y.id)},de=y=>{const B=y.enteredAt?new Date(y.enteredAt):null,Y=y.exitedAt?new Date(y.exitedAt):null;return e.jsxs(Ft,{value:String(y.id),className:es,children:[e.jsxs(Rt,{className:ts,children:[e.jsx(ut,{checked:b.has(Z(y)),onCheckedChange:()=>ue(y),onClick:X=>X.stopPropagation(),"aria-label":`Select ${y.propertyName||"discarded geo fence visit"}`,className:"border-slate-400"}),e.jsx("span",{className:"h-[9px] w-[9px] rounded-full flex-none",style:{backgroundColor:"#9ca3af"}}),e.jsxs("div",{className:"w-0 flex-1 min-w-0",children:[e.jsxs("span",{className:"truncate text-xs block",children:[y.propertyName&&e.jsx("span",{className:"mr-1 font-semibold",children:y.propertyName}),e.jsxs("span",{className:"text-muted-foreground",children:["â ",y.discardReason]})]}),(B||y.durationMinutes!==null)&&e.jsxs("span",{className:"mt-0.5 block truncate text-[11px] text-muted-foreground",children:[B&&Y&&e.jsxs("span",{children:[Q(B,"h:mm a")," â ",Q(Y,"h:mm a")]}),y.durationMinutes!==null&&e.jsxs("span",{children:[B&&Y?" · ":"",y.durationMinutes," min"]})]})]}),e.jsx("span",{className:"hidden sm:inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold flex-none bg-[#f3f4f6] text-[#4b5563] dark:bg-slate-800 dark:text-slate-300",children:"Discarded"}),e.jsxs("div",{className:"flex flex-none flex-col items-end",children:[e.jsx("span",{className:"text-xs text-muted-foreground hidden sm:block",children:"â"}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:B?Q(B,"MM/dd"):""})]})]}),e.jsx(It,{className:"px-4 py-1 text-xs",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Reason:"}),e.jsx("p",{className:"mt-0.5",children:y.discardReason})]}),y.durationMinutes!==null&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Duration:"}),e.jsxs("p",{className:"mt-0.5",children:[y.durationMinutes," min"]})]}),B&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Entered:"}),e.jsx("p",{className:"mt-0.5",children:Q(B,"MMM d, h:mm a")})]}),Y&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Exited:"}),e.jsx("p",{className:"mt-0.5",children:Q(Y,"MMM d, h:mm a")})]})]})})]},y.id)},Se=()=>S.length<=mt?null:e.jsxs("div",{className:"flex items-center justify-between py-4 border-t mt
31-2",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Showing ",m+1," to ",Math.min(m+mt,S.length)," of ",S.length," entries"]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>r(y=>Math.max(1,y-1)),disabled:s===1,className:"h-7 w-7 p-0",children:[e.jsx("span",{className:"sr-only",children:"Previous"}),e.jsx(tt,{className:"h-3.5 w-3.5"})]}),e.jsxs("div",{className:"text-xs font-medium",children:["Page ",s," of ",L]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>r(y=>Math.min(L,y+1)),disabled:s===L,className:"h-7 w-7 p-0",children:[e.jsx("span",{className:"sr-only",children:"Next"}),e.jsx(ne,{className:"h-3.5 w-3.5"})]})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-full dashboard-card-base flex flex-col",style:{perspective:"1000px"},children:e.jsxs("div",{className:"relative transition-transform duration-700 ease-in-out h-full",style:{transformStyle:"preserve-3d",transform:t?"rotateY(180deg)":"rotateY(0deg)"},children:[e.jsxs("div",{className:H("h-full flex flex-col",t?"pointer-events-none":""),style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},children:[Ye,e.jsx(Ea,{isOn:T?!!T.autoApproveGeoSync:void 0}),(_==null?void 0:_.after)&&e.jsxs("div",{className:"mx-3 sm:mx-6 mt-3 flex items-center justify-between gap-2 rounded-lg bg-green-50 px-3 py-2 text-sm text-green-800 dark:bg-green-900/30 dark:text-green-200",children:[e.jsxs("span",{children:["ð¡ï¸ Audit-readiness",_.before?` ${Math.round(_.before.composite)} â`:""," ",Math.round(_.after.composite),typeof _.delta=="number"&&_.delta!==0?` (${_.delta>0?"+":""}${_.delta})`:""]}),e.jsx("button",{onClick:P,className:"shrink-0 text-green-700 hover:text-green-900 dark:text-green-300 dark:hover:text-green-100","aria-label":"Dismiss score update",children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"border-b",children:[e.jsxs("div",{className:"relative flex items-center justify-start gap-2 px-3 sm:px-6 pt-4 pb-2 overflow-visible",children:[e.jsx(He,{children:e.jsxs(qe,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(ut,{checked:ae?"indeterminate":U,onCheckedChange:we,"aria-label":"Select all"})}),e.jsx(Ge,{children:e.jsx("p",{children:"Select All"})})]})}),e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(oa,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ye,{placeholder:w==="discarded"?"Search by property or reason...":"Search by visitor or property...",value:f,onChange:y=>{x(y.target.value),r(1)},className:"pl-9 pr-8 h-7 sm:h-8 text-xs"}),f&&e.jsx(He,{children:e.jsxs(qe,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(q,{type:"button",variant:"ghost",size:"icon",onClick:()=>x(""),className:"absolute right-1 top-1/2 -translate-y-1/2 h-5 w-5 text-muted-foreground hover:text-foreground",children:e.jsx(se,{className:"h-3 w-3"})})}),e.jsx(Ge,{children:e.jsx("p",{children:"Clear"})})]})})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsxs(kt,{open:h,onOpenChange:N,children:[e.jsx(Ct,{asChild:!0,children:e.jsxs(q,{variant:u?"default":"outline",size:"sm",className:H("flex items-center gap-2 h-7",u&&"bg-purple-600 hover:bg-purple-700"),"aria-label":"Filter geo fence visits by date",children:[e.jsx(bs,{className:"h-3 w-3 sm:h-4 sm:w-4"}),u&&e.jsx(se,{className:"h-3 w-3 ml-1",onClick:y=>{y.stopPropagation(),j(void 0),r(1)}})]})}),e.jsx(St,{className:"w-auto p-0",align:"end",children:e.jsx(Vt,{mode:"single",selected:u,onSelect:y=>{j(y),r(1),N(!1)},initialFocus:!0})})]}),e.jsx(He,{children:e.jsxs(qe,{children:[e.jsx(ze,{asChild:!0,children:e.jsx(q,{variant:"outline",size:"sm",onClick:E,disabled:I,className:"flex items-center gap-1.5 sm:gap-2 h-7 sm:h-8 px-2 sm:px-3","aria-label":"Refresh geo fence visits",children:e.jsx(st,{className:H("h-3 w-3 sm:h-4 sm:w-4",I&&"animate-spin")})})}),e.jsx(Ge,{children:e.jsx("p",{children:"Refresh geo fence visits"})})]})})]})]}),b.size>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 sm:px-6 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[b.size," selected"]}),V.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(q,{size:"sm",className:"h-7",onClick:Ce,disabled:R,children:"Approve"}),e.jsx(q,{size:"sm",variant:"outline",className:"h-7 text-destructive",onClick:Ke,disabled:R,children:"Discard"})]}),e.jsx(q,{size:"sm",variant:"outline",className:"h-7",onClick:he,children:"Clear"})]})]}),e.jsxs(ie,{className:"pl-3 pr-3 flex flex-1 min-h-0 flex-col overflow-hidden",children:[I?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(at,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):p?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ma,{className:"h-8 w-8 mx-auto mb-2 text-red-500"}),e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:"Error loading entr
31ies"})]})}):e.jsxs(xs,{value:w,onValueChange:ee,className:"mt-4 flex flex-1 min-h-0 flex-col overflow-hidden",children:[e.jsx("div",{className:"relative w-full",children:e.jsx("div",{className:"w-full overflow-x-auto scrollbar-hide",children:e.jsx(us,{className:"w-full rounded-xl p-1 sm:p-1.5 flex gap-1",children:be.map(y=>e.jsxs(bt,{value:y.value,className:H("flex-1 text-[9px] sm:text-xs normal-case px-1 sm:px-4 py-2 sm:py-2.5 rounded-lg","data-[state=active]:bg-white data-[state=active]:text-black data-[state=active]:shadow-sm","text-gray-600 hover:text-gray-800 hover:bg-gray-100","whitespace-nowrap transition-all cursor-pointer"),children:[y.dot&&e.jsx("span",{className:"mr-1.5 h-2 w-2 flex-none rounded-full",style:{backgroundColor:y.dot}}),e.jsx("span",{className:"hidden sm:inline",children:y.label}),e.jsx("span",{className:"sm:hidden",children:y.mobileLabel}),e.jsxs("span",{className:"ml-0.5 sm:ml-1",children:["(",y.count,")"]})]},y.value))})})}),e.jsx(yt,{value:w,className:"mt-3 flex flex-1 min-h-0 flex-col overflow-hidden",children:c.length===0?Oe():e.jsx(e.Fragment,{children:e.jsx("div",{className:"w-full max-w-full overflow-hidden",children:e.jsx(ha,{className:"h-full w-full",children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pa,{type:"single",collapsible:!0,className:"w-full",children:c.map(y=>{if("discardReason"in y)return de(y);const B=y;return B.approvalStatus==="pending"?Be(B):$e(B)})}),Se()]})})})})})]}),e.jsx("div",{className:"mt-auto pt-4 border-t border-gray-200 dark:border-gray-700 -mx-4 -mb-4 px-4 pb-3",children:e.jsx(La,{})})]})]}),e.jsx("div",{className:H("absolute inset-0 h-full w-full",t?"":"pointer-events-none"),style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"},children:e.jsx(Bi,{onClose:()=>a(!1),settings:T,onUpdateSettings:y=>$.mutate(y)})})]})}),e.jsx(Wi,{open:l,onOpenChange:o,entry:n,onSaveAndApprove:y=>{K.mutate(y),o(!1)},onSaveDraft:y=>{D.mutate(y),o(!1)},onReject:y=>{A.mutate({id:y}),o(!1)}})]})}function Ks({open:t,onOpenChange:a}){const{formData:s,setFormData:r,handleSubmit:n,isPending:i}=Ga();return e.jsx(Ne,{open:t,onOpenChange:a,children:e.jsxs(Ie,{className:"sm:max-w-[480px]",children:[e.jsx(Le,{children:e.jsx(_e,{children:"Add New Property"})}),e.jsxs("form",{onSubmit:n,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(W,{htmlFor:"nickname",children:"Property Nickname *"}),e.jsx(ye,{id:"nickname",value:s.nickname,onChange:l=>r(o=>({...o,nickname:l.target.value})),placeholder:"e.g., Downtown Apartment, Beach House",required:!0})]}),e.jsx(rr,{value:s.address,onChange:l=>r(o=>({...o,address:l})),onSelect:({address:l,city:o,state:f,zipCode:x})=>r(h=>({...h,address:l,city:o,state:f,zipCode:x})),required:!0}),(s.city||s.state||s.zipCode)&&e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 -mt-2",children:[s.city,s.state,s.zipCode].filter(Boolean).join(", ")}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"propertyType",children:"Property Type *"}),e.jsxs(Me,{value:s.propertyType,onValueChange:l=>r(o=>({...o,propertyType:l})),children:[e.jsx(Ee,{children:e.jsx(De,{placeholder:"Select type"})}),e.jsxs(Pe,{children:[e.jsx(re,{value:"Long-term Rental",children:"Long-term Rental"}),e.jsx(re,{value:"Short-term Rental",children:"Short-term Rental"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(q,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(q,{type:"submit",disabled:i,children:i?"Addingâ¦":"Add Property"})]})]})]})})}const Ji=()=>e.jsxs(q,{variant:"outline",className:"w-full h-auto flex-col items-center p-3 sm:p-4 whitespace-normal gap-1 sm:gap-2 touch-target text-muted-foreground hover:bg-accent hover:text-accent-foreground",disabled:!0,children:[e.jsx("div",{className:"flex flex-row items-center justify-center flex-wrap w-full",children:e.jsx("div",{className:"h-6 rounded bg-gray-200 dark:bg-gray-700 w-3/4"})}),e.jsx("p",{className:"w-full text-xs sm:text-sm lg:text-base font-normal m-0 text-center",children:e.jsx("span",{className:"block h-3 rounded bg-gray-200 dark:bg-gray-700 w-5
31/6 mx-auto"})})]}),Va=({timeEntries:t,selectedYear:a,pendingCount:s})=>{var I,p,O,A,z;const[r,n]=Mt(),[i,l]=d.useState(!0),{imapStatusQuery:o}=ft(),{googleCalendarStatusQuery:f,microsoftCalendarStatusQuery:x}=ft(),h=((I=f.data)==null?void 0:I.connected)||!1,N=((p=x.data)==null?void 0:p.connected)||!1,{data:u}=tn(),j=((O=u==null?void 0:u.gmail)==null?void 0:O.connected)||!1,b=((A=u==null?void 0:u.outlook)==null?void 0:A.connected)||!1,v=((z=o.data)==null?void 0:z.connected)||!1,w=j||b||v,g=h||N,k=d.useMemo(()=>(t||[]).filter(K=>K.approvalStatus!=="approved"),[t,a]),C=s!==void 0?s:k.length,T=d.useCallback(()=>{const $=a?`&year=${a}`:"";n(`/activity-ledger?status=pending${$}`)},[n,a]);return d.useEffect(()=>{const $=setTimeout(()=>{l(!1)},1e3);return()=>clearTimeout($)},[]),i?e.jsx(Ji,{}):!i&&g===!1&&w===!1?null:k.length===0?e.jsx(Te.div,{animate:{opacity:[0,1]},transition:{duration:.3},className:"w-full",children:e.jsxs(q,{variant:"outline",className:"w-full h-auto min-h-[76px] flex-col items-center p-3 sm:p-4 whitespace-normal gap-1 sm:gap-2 text-muted-foreground hover:bg-accent hover:text-accent-foreground relative sm:h-auto",disabled:!0,children:[e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(lt,{className:"!h-6 !w-6 text-white fill-green-500"})}),e.jsx("div",{className:"flex flex-row items-center justify-center flex-wrap w-full",children:e.jsx("span",{className:"m-0 leading-tight",children:"All Cleared!"})}),e.jsx("p",{className:"w-full font-normal m-0 text-center",children:"All entries manually approved"})]})}):e.jsx(Te.div,{animate:{opacity:[0,1]},transition:{duration:.3},className:"w-full",children:e.jsxs(q,{onClick:T,variant:"outline",className:"w-full h-auto min-h-[76px] flex-row items-center text-left gap-3 p-4 whitespace-normal rounded-2xl border border-[#F0DFA8] bg-[#FEF6E0] shadow-none hover:bg-[#FDF3D8] hover:text-foreground sm:h-auto",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-[#FFD05C]",children:e.jsx(ga,{className:"h-5 w-5 text-[#7A5200]"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsxs("span",{className:"m-0 text-center text-sm font-semibold leading-tight text-foreground",children:["Review"," ",e.jsx("span",{className:"font-bold text-[#D97706]",children:C})," ","Time ",C===1?"Entry":"Entries"]}),e.jsx("span",{className:"m-0 text-[10.5px] font-semibold uppercase tracking-wider text-muted-foreground",children:"Ensure your time entries are properly categorized"})]}),e.jsx(ne,{className:"h-4 w-4 shrink-0 text-gray-400"})]})})};function Xi({user:t,timeEntries:a,selectedYear:s,pendingCount:r}){var b,v,w;const{toast:n}=fe(),i=Re(),[l,o]=d.useState(!1),f=new Date().getFullYear(),{data:x}=le({queryKey:["/api/stats/rep-requirements/all",{year:f}]}),h=(x==null?void 0:x.requirements)||[],N=ce({mutationFn:async g=>{const k=await me("PATCH","/api/auth/user",{repType:g});if(!k.ok){const T=await k.text();throw console.error("â REP type update failed:",T),new Error(T)}return await k.json()},onMutate:async g=>{await i.cancelQueries({queryKey:["/api/auth/user"]});const k=i.getQueryData(["/api/auth/user"]);return i.setQueryData(["/api/auth/user"],C=>C&&{...C,repType:g}),{previousUser:k}},onSuccess:g=>{i.setQueryData(["/api/auth/user"],g),i.invalidateQueries({queryKey:["/api/stats"]}),i.invalidateQueries({queryKey:["/api/time-entries"]}),n({title:"REP Type Updated",description:"Your REP status type has been updated successfully"})},onError:(g,k,C)=>{if(C!=null&&C.previousUser&&i.setQueryData(["/api/auth/user"],C.previousUser),console.error("â REP type mutation failed:",g),Ht(g)){n({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500);return}n({title:"Error",description:"Failed to update REP type",variant:"destructive"})}}),u=g=>{g!==t.repType&&(g==="shortTerm"?o(!0):N.mutate(g))},j=g=>{};return e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"block lg:hidden mb-4",children:a&&e.jsx(Va,{timeEntries:a,selectedYear:s,pendingCount:r})}),e.jsx("div",{className:"flex items-center justify-center mb-2 space-x-2",children:e.jsx("span",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300",children:"Time-tracking Strategy:"})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg p-3 sm:p-4",children:[e.jsx("div",{className:"flex flex-col sm:flex-row items-center sm:items-center justify-between gap-3",children:e.jsxs("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[e.jsx(He,{children:e.jsxs(qe,{children:[e.jsx(ze,{children:e.jsx(Ve,{className:"h-4 w-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex-shrink-0"})}),e.jsx(Ge,{children:e.jsx("p",{className:"text-sm",children:"Toggle reporting between Long-term rentals versus Short-term rentals"})})]})}),e.jsx("div",{className:"relative flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center bg-gray-100 dark:bg-gray-700 rounded-full p-1",children:[e.jsxs(q,{variant:t.repType==="longTerm"?"default":"ghost",size:"sm",className:`h-8 px-2 sm:px-3 text-xs rounded-full transition-all relative flex-1 ${t.repType==="longTerm"?"bg-green-600 text-white shadow-sm hover:bg-green-700":"bg-transparent text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600"} ${N.isPending?"opacity-75":""}`,onClick:()=>u("longTerm"),disabled:N.isPending,children:[N.isPending&&N.variables==="longTerm"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-3 h-3 border-2 border-white border-t-transparent roun
31ded-full animate-spin"})}),e.jsx("span",{className:N.isPending&&N.variables==="longTerm"?"opacity-0":"",children:"REP Status"})]}),e.jsxs(q,{variant:t.repType==="shortTerm"?"default":"ghost",size:"sm",className:`h-8 px-2 sm:px-3 text-xs rounded-full transition-all relative flex-1 ${t.repType==="shortTerm"?"bg-green-600 text-white shadow-sm hover:bg-green-700":"bg-transparent text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-600"} ${N.isPending?"opacity-75":""}`,onClick:()=>u("shortTerm"),disabled:N.isPending,children:[N.isPending&&N.variables==="shortTerm"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-3 h-3 border-2 border-white border-t-transparent rounded-full animate-spin"})}),e.jsx("span",{className:N.isPending&&N.variables==="shortTerm"?"opacity-0":"",children:"STR Loophole"})]})]})}),e.jsx(te,{variant:"outline",className:"text-xs flex-shrink-0",children:t.repType==="longTerm"?`${((b=h==null?void 0:h.find(g=>g.repType==="longTerm"))==null?void 0:b.totalHoursRequired)||750} hrs`:t.strSubType==="path_500"?"500 hrs":t.strSubType==="path_100"?"100 hrs":`${((v=h==null?void 0:h.find(g=>g.repType==="shortTerm"))==null?void 0:v.totalHoursRequired)||500}
31 + ${((w=h==null?void 0:h.find(g=>g.repType==="shortTerm"))==null?void 0:w.materialHoursRequired)||100} hrs`})]})}),N.isPending&&e.jsx("div",{className:"mt-3 flex items-center justify-center",children:e.jsxs("div",{className:"inline-flex items-center px-2 py-1 rounded text-xs text-blue-600 dark:text-blue-400",children:[e.jsx("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-blue-600 mr-2"}),"Updating..."]})})]}),e.jsx(gs,{isOpen:l,onClose:()=>o(!1),onSelectionComplete:j})]})}const xt={async getRepProgress(t,a){const s=new URLSearchParams({repType:t,year:String(a)});return(await me("GET",`/api/stats/rep-progress?${s}`)).json()},async getRepRequirements(t,a){const s=new URLSearchParams({repType:t,year:String(a)});return(await me("GET",`/api/stats/rep-requirements?${s}`)).json()},async getSpouseHourBreakdown(t){const a=new URLSearchParams({year:String(t)});return(await me("GET",`/api/stats/spouse-hour-breakdown?${a}`)).json()},async getQualifiedNonMaterialHours(t){const a=t?`?year=${t}`:"";return(await me("GET",`/api/stats/qualified-non-material-hours${a}`)).json()},async getDailyHours(t){return(await me("GET",`/api/analytics/daily-hours/${t}`)).json()}};function Zi(t,a,s,r,n,i){const l=n||new Date().getFullYear(),o=t==null?void 0:t.repType,f=t==null?void 0:t.strSubType,x=o==="longTerm",h=o==="shortTerm"&&f==="path_500",N=o==="shortTerm"&&f==="path_100",{data:u,isLoading:j}=le({queryKey:["/api/stats/rep-progress",{repType:o,year:l}],queryFn:()=>xt.getRepProgress(o,l),enabled:!!o,staleTime:1e3*60*2,retry:1}),{data:b}=le({queryKey:["/api/stats/rep-requirements",{repType:o,year:l}],queryFn:()=>xt.getRepRequirements(o,l),enabled:!!o,staleTime:1e3*60*5,retry:1}),{data:v}=le({queryKey:["/api/stats/spouse-hour-breakdown",{year:l}],queryFn:()=>xt.getSpouseHourBreakdown(l),enabled:o==="shortTerm",staleTime:1e3*60*2,retry:1}),{data:w}=le({queryKey:["/api/stats/qualified-non-material-hours",{year:l}],queryFn:()=>xt.getQualifiedNonMaterialHours(l),enabled:x,staleTime:1e3*60*2,retry:1}),{data:g,isLoading:k,isError:C}=le({queryKey:["/api/analytics/daily-hours/14"],queryFn:()=>xt.getDailyHours(14),select:E=>!E||!Array.isArray(E)?Array(14).fill(0):Array.from({length:14},(P,F)=>{const S=Q(nr(new Date,13-F),"yyyy-MM-dd"),L=E.find(m=>m.date===S);return L?parseFloat(L.hours):0}),staleTime:1e3*60*5,retry:1}),T=h?500:N?100:x?(b==null?void 0:b.totalHoursRequired)??750:500,I=h?500:N?100:x?(b==null?void 0:b.materialHoursRequired)??500:100,p=h?0:N?100:x?(b==null?void 0:b.qualifiedNonMaterialRequired)??250:0,O=(u==null?void 0:u.totalHours)??a,A=(u==null?void 0:u.materialHours)??s,z=(u==null?void 0:u.qualifiedNonMaterialHours)??((w==null?void 0:w.qualifiedNonMaterialHours)||0),$=o==="shortTerm"&&r&&r.length>0,K=v!=null&&v.pooledTotal?v.pooledTotal.totalHours:$?(r||[]).reduce((E,_)=>E+(parseFloat(_.totalHours)||0),0)+O:O,D=v!=null&&v.pooledTotal?Math.min(v.pooledTotal.totalHours/T*100,100):$?Math.min(K/T*100,100):j?0:(u==null?void 0:u.totalProgress)!=null&&(u==null?void 0:u.totalProgress)>0?u.totalProgress:Math.min(O/T*100,100),R=(()=>{if(O===0)return"Start logging to see projection";const E=T-O;if(E<=0)return"Goal achieved!";if(!g||g.length===0)return"Need more activity to project";const P=g.reduce((L,m)=>L+m,0)/g.length;if(P===0)return"Need more activity to project";const F=Math.ceil(E/P),S=new Date;return S.setDate(S.getDate()+F),Q(S,"MMM dd, yyyy")})();return{repProgress:u,repRequirements:b,spouseBreakdown:v,dailyHoursData:g,goalHours:T,materialGoal:I,qualifiedGoal:p,currentTotalHours:O,currentMaterialHours:A,currentQualifiedHours:z,effectiveTotalHours:K,progressPercentage:D,projectedCompletion:R,isTeamView:$,isLongTerm:x,isStrPath500:h,isStrPath100:N,isRepProgressLoading:j,isLoadingDailyHours:k,isDailyHoursError:C}}function Qa({materialHours:t,qualifiedHours:a,totalHours:s,materialGoal:r,qualifiedGoal:n,totalGoal:i,repType:l,strSubType:o}
31){const[f,x]=d.useState(!1),[h,N]=d.useState(!1),[u,j]=d.useState(!1);if(l==="longTerm"){const w=Math.min(s/i*100,100),g=Math.min(t/r*100,100),k=Math.min(a/n*100,100);return e.jsxs("div",{className:"space-y-[18px]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-medium text-gray-700 dark:text-gray-300",children:"Total Hours"}),e.jsxs("span",{className:"text-[13px] text-gray-600 dark:text-gray-400 cursor-pointer hover:text-[#44958C] transition-colors",onClick:()=>x(!f),"data-testid":"total-metric-toggle",children:[f?`${w.toFixed(1)}% complete`:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:s.toFixed(1)}),e.jsxs("span",{className:"text-gray-400",children:["/",i]})]}),s>=i&&e.jsx("span",{className:"text-green-600 ml-1",children:"â"})]})]}),e.jsx("div",{className:"w-full bg-[#EDF1EF] dark:bg-gray-700 rounded-full h-2.5",children:e.jsx("div",{className:"bg-gradient-to-r from-[#44958C] to-[#43A047] h-2.5 rounded-full transition-all duration-500",style:{width:`${w}%`},"data-testid":"total-progress-bar"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-medium text-gray-700 dark:text-gray-300",children:"Material Participation"}),e.jsxs("span",{className:"text-[13px] text-gray-600 dark:text-gray-400 cursor-pointer hover:text-[#44958C] transition-colors",onClick:()=>N(!h),"data-testid":"material-metric-toggle",children:[h?`${g.toFixed(1)}% complete`:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:t.toFixed(1)}),e.jsxs("span",{className:"text-gray-400",children:["/",r]})]}),t>=r&&e.jsx("span",{className:"text-green-600 ml-1",children:"â"})]})]}),e.jsx("div",{className:"w-full bg-[#EDF1EF] dark:bg-gray-700 rounded-full h-2.5",children:e.jsx("div",{className:"bg-[#44958C] h-2.5 rounded-full transition-all duration-500",style:{width:`${g}%`},"data-testid":"material-progress-bar"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[13px] font-medium text-gray-700 dark:text-gray-300",children:"Qualified Non-Material"}),e.jsxs("span",{className:"text-[13px] text-gray-600 dark:text-gray-400 cursor-pointer hover:text-[#44958C] transition-colors",onClick:()=>j(!u),"data-testid":"qualified-metric-toggle",children:[u?`${k.toFixed(1)}% complete`:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-bold text-gray-900 dark:text-gray-100",children:a.toFixed(1)}),e.jsxs("span",{className:"text-gray-400",children:["/",n]})]}),a>=n&&e.jsx("span",{className:"text-green-600 ml-1",children:"â"})]})]}),e.jsx("div",{className:"w-full bg-[#EDF1EF] dark:bg-gray-700 rounded-full h-2.5",children:e.jsx("div",{className:"bg-[#43A047] h-2.5 rounded-full transition-all duration-500",style:{width:`${k}%`},"data-testid":"qualified-progress-bar"})})]})]})}const v=Math.min(s/i*100,100);return e.jsx("div",{className:"space-y-3 w-full",children:e.jsxs("div",{className:"relative w-full h-5 bg-[#EDF1EF] dark:bg-gray-700 rounded-full overflow-hidden",children:[e.jsx("div",{className:"h-full bg-gradient-to-r from-[#44958C] to-[#43A047] transition-all duration-500",style:{width:`${v}%`},"data-testid":"total-progress-bar"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-10",children:e.jsxs("span",{className:"text-xs font-medium text-white drop-shadow-[0_1px_2px_rgba(0,0,0,0.5)]",children:["Total: ",s.toFixed(1),"/",i,s>=i&&" â"]})})]})})}function ss({user:t,totalHours:a,materialHours:s,goalHours:r,materialGoal:n,isCurrentUser:i=!1,strSubType:l}){return e.jsx("div",{className:`p-3 rounded-lg border ${i?"bg-[#E9F3F1]/60 border-[#CBE3DD] dark:bg-emerald-900/10 dark:border-emerald-800":"bg-white border-gray-100 dark:bg-gray-800/50 dark:border-gray-700"}`,children:e.jsxs("div",{className:"flex items-start gap-3 mb-2",children:[e.jsx(ht,{user:t,size:"sm"}),e.jsx(Qa,{materialHours:s,qualifiedHours:0,totalHours:a,materialGoal:n,qual
31ifiedGoal:0,totalGoal:r,repType:"shortTerm",strSubType:l})]})})}function Ys({data:t,width:a=100,height:s=30}){if(!t||t.length===0)return null;const r=Math.max(...t,1),n=Math.min(...t,0),i=r-n||1,l=Math.max(t.length-1,1),o=4,f=t.map((u,j)=>{const b=o+j/l*(a-o*2),v=o+(1-(u-n)/i)*(s-o*2);return{x:b,y:v}}),x=f.map(u=>`${u.x},${u.y}`).join(" "),h=f[f.length-1],N=`${o},${s-1} ${x} ${a-o},${s-1}`;return e.jsxs("svg",{width:a,height:s,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"sparkline-fill",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#44958C",stopOpacity:"0.28"}),e.jsx("stop",{offset:"100%",stopColor:"#44958C",stopOpacity:"0"})]})}),e.jsx("polygon",{points:N,fill:"url(#sparkline-fill)"}),e.jsx("polyline",{fill:"none",stroke:"#44958C",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",points:x}),e.jsx("circle",{cx:h.x,cy:h.y,r:"3",fill:"#43A047",stroke:"#ffffff",strokeWidth:"1.5"})]})}function el({totalHours:t,materialHours:a,timeEntries:s,user:r,teamStats:n,onAddTimeEntry:i,selectedYear:l,pendingCount:o}){var E,_,P,F,S,L;const[f,x]=d.useState(!1),[h,N]=d.useState(!1),{hasActiveSubscription:u,canAccessPremiumFeatures:j}=fa(),{isActive:b}=hs(),{spouseBreakdown:v,dailyHoursData:w,goalHours:g,materialGoal:k,qualifiedGoal:C,currentTotalHours:T,currentMaterialHours:I,currentQualifiedHours:p,effectiveTotalHours:O,progressPercentage:A,projectedCompletion:z,isRepProgressLoading:$,isLoadingDailyHours:K,isDailyHoursError:D}=Zi(r,t,a,n,l),R=l===new Date().getFullYear()&&new Date().getMonth()===0&&new Date().getDate()===1&&T===0;return e.jsxs(xe,{className:"relative rounded-2xl","data-tour":"progress-overview",children:[e.jsxs(Nt,{className:"flex flex-row items-center justify-between space-y-0",children:[e.jsxs(wt,{className:"flex items-center text-base font-semibold",children:[e.jsx("span",{className:"mr-3 flex h-8 w-8 items-center justify-center rounded-[10px] bg-gradient-to-br from-[#44958C] to-[#43A047]",children:e.jsx(Es,{className:"h-[17px] w-[17px] text-white"})}),"Time Tracking Progress"]}),e.jsxs("span",{className:"ml-4 hidden shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full bg-[#E9F3F1] px-3 py-1.5 text-xs text-gray-600 sm:inline-flex",children:[e.jsx(ge,{className:"h-3.5 w-3.5 text-[#44958C]"}),"Projected completion"," ",e.jsx("span",{className:"font-semibold text-gray-900",children:z})]})]}),e.jsxs(ie,{children:[R&&e.jsx("div",{className:"mb-6 p-6 bg-gradient-to-r from-[#E9F3F1] to-[#E8F5E9] dark:from-emerald-900/20 dark:to-green-900/20 border border-[#CBE3DD] dark:border-emerald-800 rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"h-16 w-16 rounded-full bg-white dark:bg-gray-800 flex items-center justify-center shadow-lg",children:e.jsx("span",{className:"text-4xl",children:"ð"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h3",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:["Welcome to ",l,"!"]}),e.jsxs("p",{className:"text-lg text-gray-700 dark:text-gray-300 mb-4",children:["Your hours have been reset for the new tax year. Your"," ",l-1," data is safe in History."]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsxs("span",{children:["Start logging hours to track your ",l," progress"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(Es,{className:"h-4 w-4"}),e.jsxs("span",{children:["Goal: ",g," hours for the year"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(je,{className:"h-4 w-4"}),e.jsx("span",{children:"Track all your real estate activities"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(jt,{className:"h-4 w-4"}),e.jsx("span",{children:"Generate year-end statements in Settings"})]})]}),e.jsxs(q,{onClick:i,className:"mt-4 bg-gradient-to-br from-[#44958C] to-[#43A047] hover:opacity-95 text-white",children:[e.jsx(ve,{className:"h-4 w-4 mr-2"}),"Log Your First Hours"]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-8 lg:grid-cols-[290px_minmax(0,1fr)_320px] lg:gap-0",children:[e.jsxs("div",{className:"flex flex-col items-center justify-start space-y-5 lg:pr-8",children:[e.jsxs("div",{className:"relative",style:{width:170,height:170},children:[e.jsxs("svg",{width:"170",height:"170",className:"transform -rotate-90",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"repRingGradient",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[e.jsx("stop",{offset:"0%",stopColor:"#44958C"}),e.jsx("stop",{offset:"100%",stopColor:"#43A047"})]})}),e.jsx("circle",{cx:"85",cy:"85",r:"76",fill:"none",stroke:"#E9F3F1",strokeWidth:"13"}),e.jsx("circle",{cx:"85",cy:"85",r:"76",fill:"none",stroke:"url
31(#repRingGradient)",strokeWidth:"13",strokeDasharray:2*Math.PI*76,strokeDashoffset:2*Math.PI*76*(1-A/100),className:"transition-all duration-1000 ease-in-out",strokeLinecap:"round"})]}),e.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center select-none",children:$?e.jsx("span",{className:"text-sm font-medium text-[#44958C] animate-pulse",children:"Loading..."}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[34px] font-extrabold leading-none text-gray-900",children:[A.toFixed(1),"%"]}),e.jsx("span",{className:"mt-1.5 text-[10.5px] font-bold uppercase tracking-[0.14em] text-gray-400",children:"Complete"}),e.jsxs("span",{className:"mt-1 text-[11px] text-gray-500",children:["of ",g," hr goal"]})]})})]}),e.jsx("div",{className:"w-full border-t border-[#E7EBE9] pt-5",children:e.jsx("div",{children:e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-900 dark:text-gray-100",children:"14-Day Trend"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:K?"Loading...":D?"Error loading data":w&&w.length>0?`Avg: ${(w.reduce((m,c)=>m+c,0)/14).toFixed(1)} hrs/day`:"No activity yet"})]}),e.jsx("div",{className:"flex items-center",children:K?e.jsx("div",{className:"text-xs text-gray-400 animate-pulse",children:"Loading..."}):D?e.jsx("div",{className:"text-xs text-red-400",children:"Error"}):w&&w.length>0?e.jsx(Ys,{data:w,width:168,height:46}):e.jsx(Ys,{data:Array(14).fill(0),width:168,height:46})})]})})})]}),e.jsx("div",{className:"space-y-4 lg:border-l lg:border-[#E7EBE9] lg:pl-8 lg:pr-7",children:(r==null?void 0:r.repType)==="shortTerm"&&n&&n.length>0?e.jsxs("div",{className:"space-y-4 max-h-[400px] overflow-y-auto pr-2 custom-scrollbar",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-gray-400",children:"Goal Progress"}),e.jsx("span",{className:"text-xs font-medium text-gray-500",children:$?e.jsx("span",{className:"text-gray-400 animate-pulse",children:"Loading..."}):`${A.toFixed(1)}% Complete`})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-500 mb-2",children:[e.jsx("span",{children:v!=null&&v.spouses&&v.spouses.length>0?"Household STR Hours":"Team Loophole Progress"}),e.jsxs("span",{children:["Goal: ",g," hrs"]})]}),(v==null?void 0:v.spouses)&&v.spouses.length>0&&e.jsx("div",{className:"text-xs text-[#44958C] mb-3 flex items-center gap-1",children:e.jsx("span",{children:"â Includes spouse hours (joint filer rule)"})}
31),e.jsx(ss,{user:{...r,firstName:((_=(E=v==null?void 0:v.primaryUser)==null?void 0:E.name)==null?void 0:_.split(" ")[0])||(r==null?void 0:r.firstName),lastName:((F=(P=v==null?void 0:v.primaryUser)==null?void 0:P.name)==null?void 0:F.split(" ").slice(1).join(" "))||(r==null?void 0:r.lastName)},totalHours:((S=v==null?void 0:v.primaryUser)==null?void 0:S.totalHours)??T,materialHours:((L=v==null?void 0:v.primaryUser)==null?void 0:L.materialHours)??I,goalHours:g,materialGoal:k,isCurrentUser:!0,strSubType:r==null?void 0:r.strSubType}),v!=null&&v.spouses&&v.spouses.length>0?v.spouses.map(m=>e.jsx(ss,{user:{id:m.userId,firstName:m.name.split(" ")[0],lastName:m.name.split(" ").slice(1).join(" "),teamMemberRole:"Spouse"},totalHours:m.totalHours,materialHours:m.materialHours,goalHours:g,materialGoal:k,strSubType:r==null?void 0:r.strSubType},m.userId)):n.map(m=>e.jsx(ss,{user:m,totalHours:parseFloat(m.totalHours)||0,materialHours:parseFloat(m.materialHours)||0,goalHours:g,materialGoal:k,strSubType:r==null?void 0:r.strSubType},m.id)).filter(m=>m.props.user.id!==r.id),e.jsxs("div",{className:"rounded-xl bg-[#E9F3F1] py-2.5 text-center text-[13px] text-gray-600",children:[e.jsx("span",{className:"font-bold text-gray-900",children:Math.max(0,g-O).toFixed(1)})," ","hours remaining to reach Goal status"]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-wider text-gray-400",children:"Goal Progress"}),e.jsx("span",{className:"text-xs font-medium text-gray-500",children:$?e.jsx("span",{className:"text-gray-400 animate-pulse",children:"Loading..."}):`${A.toFixed(1)}% Complete`})]}),e.jsx(Qa,{materialHours:I,qualifiedHours:p,totalHours:T,materialGoal:k,qualifiedGoal:C,totalGoal:g,repType:r==null?void 0:r.repType,strSubType:r==null?void 0:r.strSubType}),e.jsxs("div",{className:"rounded-xl bg-[#E9F3F1] py-2.5 text-center text-[13px] text-gray-600",children:[e.jsx("span",{className:"font-bold text-gray-900",children:Math.max(0,g-O).toFixed(1)})," ","hours remaining to reach Goal status"]})]})}),e.jsx("div",{className:"flex h-full flex-col justify-center lg:border-l lg:border-[#E7EBE9] lg:pl-7",children:e.jsxs("div",{className:"flex w-full flex-col gap-3",children:[e.jsxs(q,{onClick:i,className:"h-11 w-full rounded-xl bg-gradient-to-br from-[#44958C] to-[#43A047] text-[13px] font-bold uppercase tracking-wide text-white shadow-[0_4px_12px_rgba(67,160,71,0.28)] hover:opacity-95 touch-target hidden lg:flex",children:[e.jsx(ve,{className:"h-4 w-4 mr-2"}),"Log Hours"]}),e.jsx(ir,{feature:"Real-Time Stopwatch",tooltipText:"Start a timer for accurate time tracking with automatic entry population. Premium feature for precise hour logging.",showUpgradeButton:!1,children:e.jsxs(q,{"data-tour":"stopwatch",onClick:()=>x(!f),variant:f?"secondary":"outline",className:"h-11 w-full rounded-xl text-[13px] font-semibold uppercase tracking-wide touch-target hidden lg:flex",children:[e.jsx("span",{className:"mr-2 flex h-[22px] w-[22px] items-center justify-center rounded-full bg-[#E9F3F1]",children:e.jsx(is,{className:"h-[10px] w-[10px] fill-[#44958C] text-[#44958C]"})}),f?"Hide Timer":"Start Timer"]})}),e.jsx("div",{className:"hidden lg:block",children:e.jsx(Va,{timeEntries:s,selectedYear:l,pendingCount:o})}),(r==null?void 0:r.repType)==="shortTerm"&&e.jsxs(q,{onClick:()=>N(!0),variant:"outline",className:"w-full touch-target",size:"sm","data-testid":"button-change-str-path",children:[e.jsx(jt,{className:"h-4 w-4 mr-2"}),"Change STR Path"]})]})})]}),f&&(u||j||b)&&e.jsx("div",{className:"mt-6",children:e.jsx(Ra,{hideFloatingWidget:!0,onClose:()=>x(!1)})}),e.jsx(gs,{isOpen:h,onClose:()=>N(!1),onSelectionComplete:()=>{}})]})]})}function tl(t){const{user:a}=Tt(),{toast:s}=fe(),r=Re(),n=(a==null?void 0:a.repType)==="shortTerm"&&((a==null?void 0:a.strSubType)==="path_500"||(a==null?void 0:a.strSubType)==="path_100"),i=(a==null?void 0:a.repType)==="shortTerm"?"Short-term Rental":"Long-term Rental",[l,o]=d.useState({date:Q(new Date,"yyyy-MM-dd"),hours:"",activityType:"",propertyId:"none",propertyType:i,description:"",isMaterialParticipation:n||!1,isQualifiedNonMaterial:!1}
31),[f,x]=d.useState([]),[h,N]=d.useState(!1),[u,j]=d.useState(!1),[b,v]=d.useState(!1),[w,g]=d.useState("idle"),[k,C]=d.useState(""),T=d.useRef(0),I=()=>{o({date:Q(new Date,"yyyy-MM-dd"),hours:"",activityType:"",propertyId:"none",propertyType:i,description:"",isMaterialParticipation:n||!1,isQualifiedNonMaterial:!1}),x([]),g("idle"),C("")},p=async D=>{if(x(D),D.length===0){g("idle"),C("");return}const R=T.current+1;T.current=R,g("scanning"),C("Scanning evidence for date, activity, and description...");try{const E=await or(D);if(R!==T.current)return;const _=E.mappedFields,P=[],F=.7,S=Q(new Date,"yyyy-MM-dd");o(L=>{var c;const m={...L};if(_.date.value&&_.date.confidence>=.65&&(!L.date||L.date===S)&&(m.date=_.date.value,P.push("date")),_.activityType.value&&_.activityType.confidence>=F&&!L.activityType){const M=ba(_.activityType.value),G=pe[_.activityType.value];m.activityType=_.activityType.value,m.hours=((c=M.defaultHours)==null?void 0:c.toString())||L.hours,m.isMaterialParticipation=(G==null?void 0:G.autoEnable)||L.isMaterialParticipation,P.push("activity")}return _.description.value&&_.description.confidence>=.6&&!L.description.trim()&&(m.description=_.description.value,P.push("description")),m}),g("applied"),C(P.length>0?`Filled ${P.join(", ")} from uploaded evidence.`:"Scan complete. Please fill the remaining fields manually.")}catch(E){if(R!==T.current)return;console.error("Evidence extraction failed:",E),g("failed"),C("We couldn't scan this evidence. You can still log the entry manually.")}},O=ce({mutationFn:async D=>await _s.createTimeEntry(D,f),onSuccess:D=>{ta(void 0,{entry_method:"manual",hours_logged:parseFloat(l.hours),activity_type:l.activityType,has_evidence:f.length>0,is_material_participation:l.isMaterialParticipation,is_qualified_non_material:l.isQualifiedNonMaterial}),r.invalidateQueries({queryKey:["/api/time-entries"]}),r.invalidateQueries({queryKey:["/api/stats"]}),r.invalidateQueries({queryKey:["/api/stats/qualified-non-material-hours"]}),r.invalidateQueries({queryKey:["/api/stats/rep-progress"]}),r.invalidateQueries({queryKey:["/api/stats/rep-requirements"]}),I();const R=f.length>0?` with ${f.length} evidence file(s)`:"";s({title:"Success",description:`Time entry logged successfully${R}`})},onError:D=>{if(Ht(D)){s({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500);return}s({title:"Error",description:"Failed to log time entry",variant:"destructive"})}}),A=ce({mutationFn:async D=>await _s.enhanceDescription(D),onSuccess:D=>{D.success&&(o(R=>({...R,description:D.result.enhancedDescription})),j(!0),setTimeout(()=>j(!1),2e3),s({title:"Description Enhanced",description:`AI improvements applied with ${Math.round(D.result.confidence*100)}% confidence`}))},onError:D=>{if(Ht(D)){s({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500);return}if(Vi(D)){s({title:"Shield Advisor Required",description:os(D),variant:"destructive"}),v(!0);return}s({title:"Enhancement Failed",description:D.message||"Failed to enhance description",variant:"destructive"})},onSettled:()=>{N(!1)}});return{formData:l,setFormData:o,selectedFiles:f,setSelectedFiles:x,handleFilesSelected:p,evidenceExtractionStatus:w,evidenceExtractionMessage:k,isEnhancingDescription:h,descriptionGlowing:u,showPaywallModal:b,setShowPaywallModal:v,handleSubmit:D=>{if(D.preventDefault(),!l.hours||!l.activityType){s({title:"Validation Error",description:"Please fill in all required fields",variant:"destructive"});return}const R=parseFloat(l.hours);if(R<.0167||R>24){s({title:"Validation Error",description:"Hours must be between 1 minute and 24 hours",variant:"destructive"});return}if((a==null?void 0:a.repType)==="longTerm"){const{isMaterialParticipation:_,isQualifiedNonMaterial:P}=l;if(!_&&!P){s({title:"Validation Error",description:"Please select Material Participation or Qualified Non-Material",variant:"destructive"});return}if(_&&P){s({title:"Validation Error",description:"You can only select one activity type",variant:"destructive"});return}}O.mutate(l)},handleEnhanceDescription:async()=>
31{if(!l.description.trim()){s({title:"No Description",description:"Please enter a description first",variant:"destructive"});return}lr(void 0,{original_description_length:l.description.length,activity_type:l.activityType,has_property_selected:l.propertyId!=="none"}),N(!0);const D=t.find(R=>R.id.toString()===l.propertyId);A.mutate({originalDescription:l.description,activityType:l.activityType,propertyNickname:D==null?void 0:D.nickname})},handleVoiceTranscription:(D,R)=>{var _;let E=R;if(E||(E=(F=>{const S=F.toLowerCase();let L="",m="",c=Bt();const M=[/(\d+(?:\.\d+)?)\s*(?:hours?|hrs?|h\b)/i,/log\s+(\d+(?:\.\d+)?)/i,/spent\s+(\d+(?:\.\d+)?)/i,/worked\s+(\d+(?:\.\d+)?)/i];for(const V of M){const U=S.match(V);if(U){L=U[1];break}}if(S.includes("today"))c=Bt();else if(S.includes("yesterday")){const V=new Date;V.setDate(V.getDate()-1),c=Bt(V)}const G=it;for(const V of G)if(V.label.toLowerCase().split(" ").filter(J=>J.length>2&&S.includes(J)).length>0){m=V.value;break}return{hours:L,date:c,activityType:m,description:F,confidence:.5,propertyType:void 0}})(D)),E.hours&&E.activityType&&E.date){const P={date:E.date,hours:E.hours.toString(),activityType:E.activityType,propertyId:"none",propertyType:E.propertyType||i,description:`Voice entry: ${D}`,isMaterialParticipation:!1,isQualifiedNonMaterial:!1};O.mutate(P),s({title:"Voice Entry Created!",description:`Automatically logged ${E.hours} hours for ${((_=it.find(F=>F.value===E.activityType))==null?void 0:_.label)||E.activityType}.`,duration:5e3})}else{o(F=>({...F,hours:E.hours?E.hours.toString():F.hours,date:E.date||F.date,activityType:E.activityType||F.activityType,description:D,propertyType:E.propertyType||F.propertyType}));const P=[];E.hours||P.push("hours"),E.activityType||P.push("activity type"),E.date||P.push("date"),s({title:"Form Pre-filled",description:`Missing: ${P.join(", ")}. Please complete and submit manually.`,variant:"default"})}},createTimeEntryMutation:O,enhanceDescriptionMutation:A,resetForm:I,isSubmitting:O.isPending}}function sl({formData:t,setFormData:a,selectedFiles:s,setSelectedFiles:r,evidenceExtractionStatus:n="idle",evidenceExtractionMessage:i,properties:l,handleSubmit:o,handleEnhanceDescription:f,isEnhancingDescription:x,descriptionGlowing:h,navigateToProperties:N,isSubmitting:u=!1,selectedYear:j,scanEnabled:b=!0,evidenceFirst:v=!1}){var p,O;const{user:w}=Tt(),{toast:g}=fe(),k=(w==null?void 0:w.repType)==="shortTerm"?"Short-term Rental":"Long-term Rental",C=new Date().getFullYear(),T=t.date?new Date(t.date).getFullYear()<C:!1;d.useEffect(()=>{T&&g({title:"Previous Tax Year Selected",description:"You are logging hours for a previous tax year. These will not count toward your current year's goals.",variant:"destructive"})},[T]);const I=e.jsxs("div",{children:[e.jsx(W,{className:"text-sm font-normal mb-2 block",children:"Evidence (Optional)"}),e.jsx(dr,{onFilesSelected:r,maxFiles:5,acceptedFileTypes:{"image/*":[".png",".jpg",".jpeg"],"application/pdf":[".pdf"]},initialFiles:s}),s.length>0&&e.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[s.length," file(s) selected"]}),b&&n==="scanning"&&e.jsx("div",{className:"mt-3",children:e.jsx(cr,{title:"Extracting evidence details",label:"Time entry evidence",description:i||"Reading your upload to suggest a date, activity type, and description. Hours and property stay ready for you to confirm."})}),b&&n==="applied"&&i&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-green-600",children:[e.jsx(lt,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:i})]}),b&&n==="failed"&&i&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-amber-600",children:[e.jsx(pt,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:i})]})]});return e.jsxs("form",{onSubmit:o,className:"space-y-4",children:[T&&e.jsx("div",{className:"mb-4 p-4 bg-orange-50 dark:bg-orange-900/20 border border-orange-200 dark:border-orange-800 rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(pt,{className:"h-5 w-5 text-orange-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-medium text-orange-900 dark:text-orange-100 mb-1",children:"Previous Tax Year Selected"}),e.jsx("p",{className:"text-sm text-orange-800 dark:text-orange-200",children:"You are logging hours for a previous tax year. These will not count toward your current year's goals."})]})]})}),v&&I,e.jsxs("div",{className:"form-mobile-stack",children:[e.jsxs("div",{className:"form-mobile-full",children:[e.jsxs(W,{htmlFor:"date",className:"text-sm font-normal",children:["Date ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(ye,{id:"date",type:"date",value:t.date,onChange:A=>a(z=>({...z,date:A.target.value})),required:!0,className:"no-zoom touch-target !text-sm text-gray-600 [&::-webkit-calendar-picker-indicator]:opacity-60 [&::-webkit-calendar-picker-indicator]:cursor-pointer"})]}),e.jsxs("div",{className:"form-mobile-full",children:[e.jsxs(W,{htmlFor:"activityType",className:"text-sm font-normal",children:["Activity Type ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(aa,{value:t.activityType,onValueChange:A=>{const z=ba(A),$=pe[A];a(K=>{var D;return{...K,activityType:A,hours:((D=z.defaultHours)==null?void 0:D.toString())||K.hours,isMaterialParticipation:($==null?void 0:$.autoEnable)||!1}})},placeholder:"Select or type activity type...",className:"touch-target text-xs text-gray-600"}),t.activityType&&e.jsxs("div",{className:"mt-1 text-sm text-gray-600",children:[e.jsx(Ve,{className:"h-4 w-4 inline mr-1"}),"Auto-filled with suggested hours. You can adjust as needed."]})]})]}),e.jsxs("div",{children:[e.jsx(sa,{value:t.hours,onChange:A=>a(z=>({...z,hours:A})),label:"Hours",required:!0,suggestedHours:t.activityType?(O=(p=it.find(A=>A.value===t.activityType))==null?void 0:p.defaultHours)==null?void 0:O.toString():void 0,className:t.activityType&&!t.hours?"border-blue-300 bg-blue-50":""}),t.activityType&&!t.hours&&e.jsxs("div",{className:"mt-1 text-sm text-blue-600",children:[e.jsx(Ve,{className:"h-4 w-4 inline mr-1"}),"Select an activity to auto-fill suggested hours"]})]}),e.jsxs("div",{children:[e.jsx(W,{htmlFor:"propertyId",className:"text-sm font-normal",children:"Property (Optional)"}),e.jsxs("div",{className:"form-mobile-stack","data-tour":"properties-section",children:[e.jsxs(Me,{value:t.propertyId,onValueChange:A=>{const z=l.find($=>
31$.id.toString()===A);a($=>({...$,propertyId:A,propertyType:(z==null?void 0:z.propertyType)||k}))},children:[e.jsx(Ee,{className:"flex-1 touch-target text-xs text-gray-600",children:e.jsx(De,{placeholder:"Select property...",className:"mt-1 text-xs text-gray-600"})}),e.jsxs(Pe,{children:[e.jsx(re,{value:"none",className:"touch-target text-xs text-gray-600",children:"No property"}),l.map(A=>e.jsxs(re,{value:A.id.toString(),className:"text-xs text-gray-600",children:[A.nickname," - ",A.address]},A.id))]})]}),e.jsxs(q,{type:"button",variant:"outline",size:"sm",onClick:()=>N(),className:"touch-target button-mobile-full",children:[e.jsx(ve,{className:"h-4 w-4 mr-1 sm:mr-0"}),e.jsx("span",{className:"sm:hidden",children:"Add Property"})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ae,{id:"materialParticipation",checked:t.isMaterialParticipation,onCheckedChange:A=>a(z=>({...z,isMaterialParticipation:A,isQualifiedNonMaterial:A?!1:z.isQualifiedNonMaterial}))}),e.jsx(W,{htmlFor:"materialParticipation",className:"text-sm font-normal",children:"Material Participation Activity"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ae,{id:"qualifiedNonMaterial",checked:t.isQualifiedNonMaterial,onCheckedChange:A=>a(z=>({...z,isQualifiedNonMaterial:A,isMaterialParticipation:A?!1:z.isMaterialParticipation}))}),e.jsx(W,{htmlFor:"qualifiedNonMaterial",className:"text-sm font-normal",children:"Qualified Non-Material Activity"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-1",children:[e.jsx(W,{htmlFor:"description",className:"text-sm font-normal",children:"Description"}),e.jsx(q,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-2 text-xs text-purple-600 hover:text-purple-700 hover:bg-purple-50",onClick:f,disabled:x||!t.description,children:x?e.jsx("span",{className:"animate-pulse",children:"Enhancing..."}):e.jsxs(e.Fragment,{children:[e.jsx(mr,{className:"h-3 w-3 mr-1"}),"AI Enhance"]})})]}),e.jsx(zt,{id:"description",value:t.description,onChange:A=>a(z=>({...z,description:A.target.value})),placeholder:"Describe your activity...",className:H("touch-target text-sm transition-all duration-500",h&&"shadow-[0_0_15px_rgba(168,85,247,0.5)] border-purple-400")})]}),!v&&I,e.jsx(q,{type:"submit",className:"w-full touch-target",disabled:u,children:u?"Logging...":"Log Time"})]})}function Bs({properties:t}){const[a,s]=d.useState(!1),[r,n]=d.useState(null),{formData:i,setFormData:l,selectedFiles:o,setSelectedFiles:f,handleFilesSelected:x,evidenceExtractionStatus:h,evidenceExtractionMessage:N,isEnhancingDescription:u,descriptionGlowing:j,showPaywallModal:b,setShowPaywallModal:v,handleSubmit:w,handleEnhanceDescription:g,isSubmitting:k}=tl(t),C=()=>{localStorage.setItem("add-property-from-dashboard","true"),window.location.href="/properties"};if(!r)return e.jsx(xr,{onSelect:n});const T=r==="smart",I=T?x:f;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("p",{className:"text-sm font-semibold",children:T?"Smart Assistant":"Manual Entry"}),e.jsx(ur,{onClick:()=>n(null)})]}),e.jsx(sl,{formData:i,setFormData:l,selectedFiles:o,setSelectedFiles:I,evidenceExtractionStatus:h,evidenceExtractionMessage:N,properties:t,handleSubmit:w,handleEnhanceDescription:g,isEnhancingDescription:u,descriptionGlowing:j,navigateToProperties:C,isSubmitting:k,scanEnabled:T,evidenceFirst:T}),e.jsx(ns,{open:b,onOpenChange:v,feature:"AI Description Enhancement"})]})}function al({isOpen:t,onClose:a,session:s}){const[r,n]=d.useState(!0),[i,l]=d.useState("chat"),o=s.isPremium,f=d.useRef(null);return d.useEffect(()=>{if(t&&f.current){const x=setTimeout(()=>{f.current&&(f.current.scrollTop=f.current.scrollHeight)},100);return()=>clearTimeout(x)}},[t]),d.useEffect(()=>{t&&n(!0)},[t]),d.useEffect(()=>{var x,h;if(t)return(h=(x=window.Tawk_API)==null?void 0:x.hideWidget)==null||h.call(x),()=>{var N,u;(u=(N=window.Tawk_API)==null?void 0:N.showWidget)==null||u.call(N)}},[t]),e.jsx(Ne,{open:t,onOpenChange:x=>!x&&a(),children:e.jsxs(hr,{children:[e.jsx(pr,{className:"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),e.jsxs(gr,{className:"fixed inset-x-0 bottom-0 z-50 flex h-[calc(100dvh-5rem)] max-h-[calc(100dvh-5rem)] flex-col overflow-hidden rounded-t-[28px] border border-border bg-white shadow-xl outline-none dark:bg-background md:inset-0 md:h-auto md:max-h-none md:rounded-none md:border-0 md:shadow-none",children:[e.jsxs("div",{className:"relative z-10 grid grid-cols-[2.25rem_minmax(0,auto)_2.25rem] items-center overflow-hidden px-4 py-1.5 shrink-0 bg-white dark:bg-background md:flex md:h-16 md:justify-between md:px-8 md:py-0 border-b border-border/50",children:[e.jsx("div",{className:"hidden md:flex md:items-center",children:e.jsx("span",{className:"text-[15px] font-semibold text-foreground",children:"AI Assistant"})}),e.jsx("div",{className:"col-start-2 flex items-center justify-center justify-self-center md:hidden",children:e.jsxs(fr,{children:[e.jsx(br,{asChild:!0,children:e.jsxs("button",{type:"button",className:"inline-flex h-7 items-center gap-1.5 rounded-md px-2.5 text-sm font-medium text-foreground transition-colors hover:bg-white/50",children:[i==="chat"?"Chat":"History",e.jsx(cs,{className:"h-3.5 w-3.5"})]})}
31),e.jsxs(yr,{align:"center",className:"w-36",children:[e.jsx(Ds,{onClick:()=>l("chat"),children:"Chat"}),e.jsx(Ds,{onClick:()=>l("history"),children:"History"})]})]})}),e.jsxs("div",{className:"col-start-3 flex items-center justify-self-end md:ml-auto md:gap-2",children:[e.jsx("button",{type:"button","aria-label":"New chat",onClick:()=>{s.startNewConversation(),l("chat")},className:"inline-flex h-9 w-9 items-center justify-center rounded-md bg-transparent text-muted-foreground transition-colors hover:bg-accent/70 hover:text-foreground",children:e.jsx(ya,{className:"h-4 w-4"})}),o&&e.jsx("button",{type:"button","aria-label":r?"Hide chat history":"Show chat history",onClick:()=>n(x=>!x),className:"hidden h-9 w-9 items-center justify-center rounded-md bg-transparent text-muted-foreground transition-colors hover:bg-accent/70 hover:text-foreground md:inline-flex",children:r?e.jsx(yn,{className:"h-4 w-4"}):e.jsx(jn,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Minimize chat",onClick:a,className:"hidden h-9 w-9 items-center justify-center rounded-md bg-transparent text-muted-foreground transition-colors hover:bg-accent/70 hover:text-foreground md:inline-flex",children:e.jsx(bn,{className:"h-4 w-4"})}),e.jsx(jr,{"aria-label":"Close chat",className:"inline-flex items-center justify-center h-8 w-8 rounded-md bg-transparent text-muted-foreground hover:text-foreground hover:bg-accent/70 transition-colors",children:e.jsx(se,{className:"h-4 w-4 md:h-4 md:w-4"})})]})]}),e.jsxs("div",{className:"hidden md:flex flex-row flex-1 min-h-0 overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-w-0 overflow-hidden flex flex-col bg-transparent",children:e.jsx("div",{ref:f,className:"flex-1 min-h-0 w-full flex flex-col overflow-y-auto",children:e.jsx("div",{className:"mx-auto w-full max-w-[820px] h-full flex flex-col px-6 py-4",children:e.jsx(_t,{session:s,isExpanded:!0})})})}),e.jsx("div",{className:H("shrink-0 overflow-hidden transition-all duration-200",o&&r?"w-96 pr-6 pt-5 pb-6":"w-0"),children:o&&r&&e.jsx("div",{className:"h-full overflow-hidden rounded-xl border border-slate-300/80 bg-white/70 shadow-sm backdrop-blur-sm dark:border-slate-700/70 dark:bg-slate-950/70",children:e.jsx(Ot,{variant:"sheet",isPremium:s.isPremium,activeConversationId:s.activeConversationId,onSelectConversation:s.setActiveConversationId,onNewChat:s.startNewConversation})})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden md:hidden",children:i==="chat"?e.jsx("div",{className:"h-full px-2 pt-3 pb-4 flex flex-col overflow-hidden",children:e.jsx(_t,{session:s,isExpanded:!0})}):e.jsx("div",{className:"h-full bg-muted/40",children:e.jsx(Ot,{variant:"sheet",isPremium:s.isPremium,activeConversationId:s.activeConversationId,onSelectConversation:x=>{s.setActiveConversationId(x),l("chat")},onNewChat:()=>{s.startNewConversation(),l("chat")}})})})]})]})})}function rl(t){return t>=80?"bg-emerald-500":t>=50?"bg-amber-400":"bg-red-500"}function nl(t){return t>=100?{label:"Complete",className:"border-transparent bg-emerald-100 text-emerald-800 dark:bg-emerald-900/20 dark:text-emerald-400"}:t>=80?{label:"Almost There",className:"border-transparent bg-emerald-100 text-emerald-800 dark:bg-emerald-900/20 dark:text-emerald-400"}:t>=50?{label:"In Progress",className:"border-transparent bg-amber-100 text-amber-800 dark:bg-amber-900/20 dark:text-amber-400"}:{label:"Needs Attention",className:"border-transparent bg-red-100 text-red-800 dark:bg-red-900/20 dark:text-red-400"}}function il({answered:t,total:a}){const s=t===a;return e.jsxs("span",{className:H("inline-flex items-center gap-1 text-xs font-medium tabular-nums shrink-0 ml-3",s?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dark:text-amber-400"),children:[s?e.jsx(lt,{className:"h-3.5 w-3.5"}):e.jsx("span",{className:H("h-2 w-2 rounded-full shrink-0",t===0?"bg-red-400":"bg-amber-400")}),t,"/",a]})}const ll=[{key:"filingStatus",fallback:"Filing status not set"},{key:"employmentType",fallback:"Employment not set"},{key:"involvementStyle",fallback:"Involvement not set"}],ol={single:"Single",mfj:"MFJ",mfs:"MFS",hoh:"HoH",w2:"W-2",self_employed:"Self-Employed",business_owner:"Business Owner",retired:"Retired",full_time_re:"Full-Time RE",self_manage:"Self
31-Managed",hybrid:"Hybrid",pm_runs_most:"PM-Led",mostly_passive:"Passive"};function dl(t,a){if(a==null||a==="")return null;const s=String(a);return ol[s]??s}function cl({field:t,value:a,onUpdate:s,onDebouncedUpdate:r,isUpdating:n,hint:i}){var l;return t.type==="boolean"?e.jsxs("div",{className:"flex items-start justify-between gap-4 rounded-lg border border-border/50 bg-muted/20 px-4 py-3.5 hover:bg-muted/40 transition-colors",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(W,{htmlFor:t.key,className:"text-sm font-medium leading-snug cursor-pointer",children:t.label}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 leading-relaxed",children:t.description}),a===null&&!t.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Not yet answered"}),i&&a===null&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 leading-relaxed",children:i})]}),e.jsx(Ae,{id:t.key,checked:a===!0,disabled:n,onCheckedChange:o=>s(t.key,o),className:"shrink-0 mt-0.5"})]}):t.type==="number"?e.jsxs("div",{className:"rounded-lg border border-border/50 bg-muted/20 px-4 py-3.5 space-y-2 hover:bg-muted/40 transition-colors",children:[e.jsx(W,{htmlFor:t.key,className:"text-sm font-medium",children:t.label}),e.jsx(ye,{id:t.key,type:"number",defaultValue:a!=null?String(a):"",placeholder:t.placeholder??"Not provided",min:t.min,max:t.max,disabled:n,onChange:o=>{const f=o.target.value;if(f==="")return;const x=parseInt(f,10);isNaN(x)||r(t.key,x)},className:"max-w-[180px] h-8 text-sm"})]}):e.jsxs("div",{className:"rounded-lg border border-border/50 bg-muted/20 px-4 py-3.5 space-y-2 hover:bg-muted/40 transition-colors",children:[e.jsx(W,{htmlFor:t.key,className:"text-sm font-medium",children:t.label}),e.jsxs(Me,{value:typeof a=="string"?a:"",disabled:n,onValueChange:o=>s(t.key,o),children:[e.jsx(Ee,{className:"max-w-[280px] h-8 text-sm",id:t.key,children:e.jsx(De,{placeholder:"Not set"})}),e.jsx(Pe,{children:(l=t.options)==null?void 0:l.map(o=>e.jsx(re,{value:o.value,children:o.label},o.value))})]})]})}function ml(){const{profile:t,isLoading:a,isError:s,refetch:r,updateField:n,debouncedUpdateField:i,isUpdating:l}=vr(),{suggestions:o}=Nr(),f=(C,T)=>n(C,T),x=(C,T)=>i(C,T);if(a)return e.jsx(xe,{children:e.jsxs(ie,{className:"flex items-center justify-center p-10",children:[e.jsx("div",{className:"animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full"}),e.jsx("span",{className:"ml-3 text-sm text-muted-foreground",children:"Loading tax profile..."})]})});if(s||!t)return e.jsx(xe,{children:e.jsxs(ie,{className:"flex flex-col items-center justify-center p-10 gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load tax profile."}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>r(),children:[e.jsx(st,{className:"h-4 w-4 mr-2"}),"Retry"]})]})});const h=t,N=Ps.map(C=>({...C,...As(C.key,h)})),u=N.reduce((C,T)=>C+T.answered,0),j=N.reduce((C,T)=>C+T.total,0),b=j>0?Math.round(u/j*100):0,v=nl(b),w=N.filter(C=>C.answered<C.total).map(C=>C.key),g=(()=>{const C=o==null?void 0:o.priorYearRepsQualified;if(!(!C||!C.suggested))return`Based on your ${C.year} logged hours (${C.hours} hrs), you appear to have qualified. Please confirm.`})(),k=ll.map(({key:C,fallback:T})=>{const I=dl(C,h[C]);return{key:C,label:I,fallback:T}});return e.jsxs(xe,{className:"overflow-hidden",children:[e.jsxs(Nt,{className:"pb-4",children:[e.jsxs(wt,{className:"flex items-center gap-2 text-lg sm:text-xl font-semibold",children:[e.jsx(cn,{className:"h-5 w-5 text-primary shrink-0"}),"AI Tax Profile"]}),e.jsx(wr,{className:"text-sm leading-relaxed",children:"This is what your AI advisor knows about your tax situation. Keeping it accurate ensures you receive guidance tailored to your specific circumstances."})]}),e.jsxs(ie,{className:"space-y-5 pt-0",children:[e.jsxs("div",{className:"rounded-xl border bg-muted/30 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-2xl font-bold tabular-nums leading-none",children:[b,"%"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[u," of ",j," fields answered"]})]}),e.jsx(te,{variant:"outline",className:v.className,children:v.label})]}),e.jsx("div",{className:"relative h-1.5 w-full overflow-hidden rounded-full bg-border",children:e.jsx("div",{className:H("h-full rounded-full transition-all duration-500",rl(b)),style:{width:`${b}%`}})}),e.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pt-0.5",children:k.map(({key:C,label:T,fallback:I},p)=>e.jsxs("span",{className:"flex items-center gap-1.5 text-xs",children:[p>
310&&e.jsx("span",{className:"text-border","aria-hidden":!0,children:"·"}),T?e.jsx("span",{className:"font-medium text-foreground",children:T}):e.jsx("span",{className:"text-muted-foreground italic",children:I})]},C))})]}),e.jsx(pa,{type:"multiple",defaultValue:w,className:"rounded-xl border divide-y overflow-hidden",children:Ps.map(C=>{const T=kr(C.key,h);if(T.length===0)return null;const{answered:I,total:p}=As(C.key,h),O=I===p;return e.jsxs(Ft,{value:C.key,className:"border-0",children:[e.jsx(Rt,{className:H("px-4 py-3.5 text-sm font-semibold hover:no-underline hover:bg-muted/30 transition-colors","[&[data-state=open]]:bg-muted/30","[&[data-state=open]>svg]:rotate-180"),children:e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:H("h-1.5 w-1.5 rounded-full shrink-0",O?"bg-emerald-500":"bg-amber-400"),"aria-hidden":!0}),C.label,e.jsx(il,{answered:I,total:p})]})}),e.jsx(It,{className:"px-4 pb-4 pt-0",children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-2 pt-2",children:T.map(A=>e.jsx(cl,{field:A,value:h[A.key]??null,onUpdate:f,onDebouncedUpdate:x,isUpdating:l,hint:A.key==="priorYearRepsQualified"?g:void 0},A.key))})})]},C.key)})})]})]})}const xl={"ai-only":"Show only the AI chat experience.","classic-only":"Show only the classic time entry form.",hybrid:"Show both AI chat and classic form as tabs."};function ul({onClose:t}){const{viewMode:a,setViewMode:s,isSaving:r}=ja(),[n,i]=d.useState(a),l=()=>{s(n,{onSuccess:()=>t()})};return d.useEffect(()=>{i(a)},[a]),e.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-slate-900 animate-in fade-in slide-in-from-bottom-4 duration-500",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-slate-100 dark:border-slate-800 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm z-10",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold text-slate-900 dark:text-slate-50",children:"Chatbot Settings"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-0.5",children:"Configure your AI assistant experience."})]})}),e.jsx(q,{variant:"ghost",size:"icon",onClick:t,className:"h-8 w-8 rounded-full hover:bg-slate-100 dark:hover:bg-slate-800",children:e.jsx(se,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-8",children:[e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h2",{className:"text-base font-semibold text-slate-900 dark:text-slate-100",children:"View Mode"}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mt-1",children:"Choose how you want to interact with the REP Assistant."})]}),e.jsxs(dn,{type:"single",value:n,onValueChange:o=>o&&i(o),"aria-label":"View Mode",className:"flex w-full rounded-lg border border-slate-200 dark:border-slate-700",children:[e.jsx(Wt,{value:"ai-only",className:"flex-1 rounded-none rounded-l-lg border-r border-slate-200 dark:border-slate-700 data-[state=on]:bg-emerald-50 data-[state=on]:text-emerald-700 dark:data-[state=on]:bg-emerald-900/20 dark:data-[state=on]:text-emerald-400",children:"AI Only"}),e.jsx(Wt,{value:"classic-only",className:"flex-1 rounded-none border-r border-slate-200 dark:border-slate-700 data-[state=on]:bg-emerald-50 data-[state=on]:text-emerald-700 dark:data-[state=on]:bg-emerald-900/20 dark:data-[state=on]:text-emerald-400",children:"Classic Only"}),e.jsx(Wt,{value:"hybrid",className:"flex-1 rounded-none rounded-r-lg data-[state=on]:bg-emerald-50 data-[state=on]:text-emerald-700 dark:data-[state=on]:bg-emerald-900/20 dark:data-[state=on]:text-emerald-400",children:"Hybrid"})]}),e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400 mt-2",children:xl[n]})]}),e.jsx("section",{children:e.jsx("div",{className:"border-t border-slate-100 dark:border-slate-800 pt-6",children:e.jsx(ml,{})})})]}),e.jsx("div",{className:"p-6 border-t border-slate-100 dark:border-slate-800 bg-white/80 dark:bg-slate-900/80 backdrop-blur-sm",children:e.jsx(q,{onClick:l,disabled:r,className:"w-full bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white shadow-md hover:shadow-lg transition-all duration-300",children:r?"Saving...":"Save Configuration"})})]})}function hl({session:t,sidebarOpen:a}){const s=t.isPremium&&a;return e.jsxs("div",{className:"flex h-full overflow-hidden gap-0",children:[e.jsx("div",{className:H("shrink-0 border-r border-border/60 overflow-hidden transition-all duration-200",s?"w-48":"w-0"),children:s&&e.jsx(Ot,{isPremium:t.isPremium,activeConversationId:t.activeConversationId,onSelectConversation:t.setActiveConversationId,onNewChat:t.
31startNewConversation})}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden",children:e.jsx(_t,{session:t})})]})}function pl({properties:t}){const a=Cr(),{viewMode:s}=ja(),[r,n]=d.useState(!1),[i,l]=d.useState(!1),[o,f]=d.useState("chat"),x=s!=="classic-only",h=ka();return d.useEffect(()=>{var u;if(new URLSearchParams(h).get("openTaxProfile")==="1"){l(!0),(u=document.querySelector('[data-tour="time-logging-form"]'))==null||u.scrollIntoView({behavior:"smooth",block:"center"});const j=new URL(window.location.href);j.searchParams.delete("openTaxProfile"),window.history.replaceState({},"",`${j.pathname}${j.search}`)}},[h]),e.jsx(Sr,{children:e.jsxs("div",{"data-tour":"time-logging-form",className:"dashboard-card",children:[e.jsx(xe,{className:H("group h-full dashboard-card-base flex flex-col overflow-hidden"),style:{perspective:"1000px"},children:e.jsxs("div",{className:"relative transition-transform duration-700 ease-in-out h-full flex flex-col",style:{transformStyle:"preserve-3d",transform:i?"rotateY(180deg)":"rotateY(0deg)"},children:[e.jsxs("div",{className:H("h-full flex flex-col overflow-hidden rounded-lg bg-card",i&&"pointer-events-none"),style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},children:[e.jsx("div",{className:"relative flex items-center justify-end px-6 pt-4 pb-2 shrink-0 bg-transparent",children:e.jsxs("div",{className:"flex items-center gap-1",children:[x&&s==="ai-only"&&e.jsx("button",{type:"button","aria-label":o==="chat"?"View chat history":"Back to chat",onClick:()=>f(N=>N==="chat"?"history":"chat"),className:"inline-flex items-center justify-center h-9 w-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent/70 transition-colors",children:o==="chat"?e.jsx($t,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})}),x&&e.jsx("button",{type:"button","aria-label":"New chat",onClick:()=>{a.startNewConversation(),f("chat")},className:"inline-flex items-center justify-center h-9 w-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent/70 transition-colors",children:e.jsx(ya,{className:"h-4 w-4"})}),x&&e.jsx("button",{type:"button","aria-label":"Expand chat",onClick:()=>n(!0),className:"inline-flex items-center justify-center h-9 w-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent/70 transition-colors",children:e.jsx(mn,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Chat settings",onClick:()=>l(!0),className:"inline-flex items-center justify-center h-9 w-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent/70 transition-colors",children:e.jsx(jt,{className:"h-4 w-4"})})]})}),s==="ai-only"&&e.jsx("div",{className:"relative flex-1 min-h-0",children:e.jsx(ie,{className:"absolute inset-0 p-0 flex flex-col overflow-hidden",children:e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:o==="chat"?e.jsx("div",{className:"h-full px-6 py-4 flex flex-col overflow-hidden",children:e.jsx(_t,{session:a})}):e.jsx("div",{className:"h-full bg-transparent",children:e.jsx(Ot,{variant:"sheet",isPremium:a.isPremium,activeConversationId:a.activeConversationId,onSelectConversation:N=>{a.setActiveConversationId(N),f("chat")},onNewChat:()=>{a.startNewConversation(),f("chat")}})})})})}),s==="classic-only"&&e.jsx(ie,{className:"p-6 pt-4",children:e.jsx(Bs,{properties:t})}),s==="hybrid"&&e.jsxs(xs,{defaultValue:"chat",className:"flex flex-col flex-1",children:[e.jsx("div",{className:"px-6 pt-4 pb-0",children:e.jsxs(us,{className:"w-full",children:[e.jsxs(bt,{value:"chat",className:"flex-1 gap-1.5",children:[e.jsx(Tr,{className:"h-4 w-4"}),"AI Chat"]}),e.jsxs(bt,{value:"classic",className:"flex-1 gap-1.5",children:[e.jsx(ve,{className:"h-4 w-4"}),"Classic"]})]})}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(yt,{value:"chat",forceMount:!0,className:"absolute inset-0 mt-0 overflow-hidden bg-card transition-opacity duration-200 data-[state=active]:opacity-100 data-[state=inactive]:opacity-0 data-[state=inactive]:pointer-events-none",children:e.jsx(ie,{className:"p-0 h-full flex flex-col overflow-hidden",children:e.jsx("div",{className:"h-full px-6 py-4 flex flex-col overflow-hidden",children:e.jsx(hl,{session:a,sidebarOpen:!1})})})}),e.jsx(yt,{value:"classic",forceMount:!0,className:"mt-0 transition-opacity duration-200 data-[state=active]:opacity-100 data-[state=inactive]:opacity-0 data-[state=inactive]:pointer-events-none",children:e.jsx(ie,{className:"p-6 pt-4",children:e.jsx(Bs,{properties:t})})})]})]})]}),e.jsx("div",{className:`absolute inset-0 h-full w-full ${i?"":"pointer-events-none"}`,style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"},children:e.jsx(ul,{onClose:()=>l(!1)})})]})}),e.jsx(al,{isOpen:r,onClose:()=>n(!1),session:a})]})})}const gl={gmail:{name:"Gmail",icon:Ca,color:"text-red-600",bgColor:"bg-red-50",borderColor:"border-red-200",description:"Connect your Gmail account to automatically track email activities",features:["Automatic email activity detection","AI-powered categorization","Secure OAuth 2.0 authentication","Real-time sync"]},"google-calendar":{name:"Google Calendar",icon:Sa,color:"text-blue-600",bgColor:"bg-blue-50",borderColor:"border-blue-200",description:"Sync your Google Calendar to track scheduled real estate activities",features:["Calendar event tracking","Automatic time entry creation","AI activity classification","Seamless integration"]},"microsoft-mail":{name:"Microsoft Outlook",icon:Fe,color:"text-blue-700",bgColor:"bg-blue-50",borderColor:"border-blue-200",description:"Connect Outlook to track email communications",features:["Email activity monitoring","Smart categorization","Enterprise-grade security","Real-time updates"]},"microsoft-calendar":{name:"Microsoft Calendar",icon:ge,color:"text-blue-700",bgColor:"bg-blue-50",borderColor:"border-blue-200",description:"Sync Microsoft Calendar for comprehensive activity tracking",features:["Event-based tracking","Auto time logging","AI-powered insights","Bi-directional sync"]}};function At({open:t,onOpenChange:a,integrationType:s,isConnected:r,isLoading:n,onConnect:i,onDisconnect:l}){const o=gl[s],f=o.icon;return e.jsx(Ne,{open:t,onOpenChange:a,children:e.jsxs(Ie,{className:"sm:max-w-[500px]",children:[e.jsxs(Le,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("div",{className:`w-12 h-12 rounded-xl ${o.bgColor} border ${o.borderColor} flex items-center justify-center`,children:e.jsx(f,{className:`w-6 h-6 ${o.color}`})}),e.jsxs("div",{children:[e.jsxs(_e,{className:"text-xl",children:[r?"Disconnect":"Connect"," ",o.name]}),r&&e.jsxs(te,{variant:"outline",className:"mt-1 rounded-full border-[#BBF7D0] bg-[#DCFCE7] px-2.5 py-0.5 text-[#166534] dark:border-green-500/30 dark:bg-green-500/15 dark:text-green-300",children:[e.jsx(lt,{className:"w-3 h-3 mr-1 text-[#16A34A] dark:text-green-400"}),"Connected"]})]})]}),e.jsx(Gt,{className:"text-base pt-2",children:o.description})]}),!r&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm font-semibold text-gray-700 dark:text-gray-300 flex items-center gap-2",children:[e.jsx(Qt,{className:"w-4 h-4 text-[#44958C]"}),"What you'll get:"]}),e.jsx("ul",{className:"space-y-2",children:o.features.map((x,h)=>e.jsxs("li",{className:"flex items-start gap-2.5 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx("span",{className:"mt-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center rounded-md bg-[#DCFCE7] dark:bg-green-500/15",children:e.jsx(lt,{className:"w-3.5 h-3.5 text-[#16A34A] dark:text-green-400"})}),e.jsx("span",{children:x})]},h))})]}),e.jsx("div",{className:"bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#DCFCE7] dark:bg-green-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(Mr,{className:"w-4 h-4 text-[#16A34A] dark:text-green-400"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm font-medium text-slate-900 dark:text-slate-100 flex items-center gap-2",children:[e.jsx(Er,{className:"w-3 h-3"}),"Secure OAuth 2.0"]}
31),e.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-400",children:"Your credentials are never stored. All data is encrypted end-to-end."})]})]})})]}),r&&e.jsx("div",{className:"py-6",children:e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950 border border-amber-200 dark:border-amber-800 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-amber-100 dark:bg-amber-900",children:e.jsx(pt,{className:"w-4 h-4 text-amber-600 dark:text-amber-400"})}),e.jsxs("p",{className:"text-sm leading-relaxed text-amber-800 dark:text-amber-200",children:[e.jsx("strong",{className:"font-semibold",children:"Disconnecting stops automatic tracking."})," ","New activity from this integration will no longer sync to REPSShield. Your existing time entries will not be affected."]})]})})}),e.jsxs(Dr,{children:[e.jsx(q,{variant:"outline",onClick:()=>a(!1),disabled:n,children:"Cancel"}),r?e.jsx(q,{variant:"destructive",onClick:l,disabled:n,children:n?e.jsxs(e.Fragment,{children:[e.jsx(at,{className:"w-4 h-4 mr-2 animate-spin"}),"Disconnecting..."]}):"Disconnect"}):e.jsx(q,{onClick:i,disabled:n,className:"bg-gradient-to-r from-[#44958C] to-[#43A047] hover:opacity-95",children:n?e.jsxs(e.Fragment,{children:[e.jsx(at,{className:"w-4 h-4 mr-2 animate-spin"}),"Connecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"w-4 h-4 mr-2"}),"Connect ",o.name]})})]})]})})}const Ws=()=>{var N,u,j,b,v,w;const{startTour:t,hasCompletedOnboarding:a,setHasCompletedOnboarding:s}=hs(),r=Na(),n=new Date().getFullYear(),{data:i}=le({queryKey:["/api/stats/rep-requirements/all",{year:n}]}),l=(i==null?void 0:i.requirements)||[],o=g=>{g&&localStorage.setItem("repshield_onboarding_completed","true"),s(!0)},f=()=>{localStorage.setItem("repshield_onboarding_completed","true"),t()},x=g=>{g&&o(!0)};if(da()||r)return null;const h=[{icon:e.jsx(je,{className:"h-5 w-5 text-blue-500"}),title:"Time Tracking",description:"Log hours for all your real estate activities"},{icon:e.jsx(Lt,{className:"h-5 w-5 text-green-500"}),title:"Evidence Upload",description:"Attach supporting documents for audit protection"},{icon:e.jsx(Pr,{className:"h-5 w-5 text-purple-500"}),title:"Progress Tracking",description:"Monitor your REP status progress in real-time"},{icon:e.jsx(va,{className:"h-5 w-5 text-orange-500"}),title:"AI Assistant",description:"Get expert guidance on REP requirements"},{icon:e.jsx(nt,{className:"h-5 w-5 text-red-500"}),title:"Property Management",description:"Organize and track all your rental properties"},{icon:e.jsx(ys,{className:"h-5 w-5 text-indigo-500"}),title:"Real-time Stopwatch",description:"Track time as you work with built-in timer"}];return e.jsx(Ne,{open:!a,onOpenChange:g=>!g&&o(!1),children:e.jsxs(Ie,{className:"max-w-2xl w-[95vw] sm:w-auto max-h-[90vh] overflow-y-auto",children:[e.jsxs(Le,{children:[e.jsx(_e,{className:"text-xl sm:text-2xl font-bold text-center",children:"Welcome to REPSShield! ð"}),e.jsxs(Gt,{className:"text-center text-base sm:text-lg",children:["Your complete Real Estate Professional time tracking solution",e.jsx("br",{}),e.jsx("span",{className:"text-sm text-primary font-medium",children:"Take a comprehensive tour of all platform features across every module"})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:h.map((g,k)=>e.jsx(xe,{className:"border-l-4 border-l-primary",children:e.jsx(ie,{className:"p-4",children:e.jsxs("div",{className:"flex items-start space-x-3",children:[g.icon,e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:g.title}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:g.description})]})]})})},k))}),e.jsx(xe,{className:"bg-gradient-to-r from-blue-50 to-purple-50 dark:from-blue-900/20 dark:to-purple-900/20",children:e.jsxs(ie,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(ps,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"font-semibold",children:"Time Tracking Requirements"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx(te,{variant:"outline",className:"mb-2",children:"Long-Term Rental"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400",children:[((N=l
31==null?void 0:l.find(g=>g.repType==="longTerm"))==null?void 0:N.totalHoursRequired)||750," ","hours annually",((u=l==null?void 0:l.find(g=>g.repType==="longTerm"))==null?void 0:u.materialHoursRequired)&&` (${(j=l.find(g=>g.repType==="longTerm"))==null?void 0:j.materialHoursRequired} material + ${(b=l.find(g=>g.repType==="longTerm"))==null?void 0:b.qualifiedNonMaterialRequired} qualified)`]})]}),e.jsxs("div",{children:[e.jsx(te,{variant:"outline",className:"mb-2",children:"Short-Term Rental"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400",children:[((v=l==null?void 0:l.find(g=>g.repType==="shortTerm"))==null?void 0:v.totalHoursRequired)||500," ","hour or"," ",((w=l==null?void 0:l.find(g=>g.repType==="shortTerm"))==null?void 0:w.materialHoursRequired)||100," ","hour material participation"]})]})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2 justify-center",children:[e.jsx(ut,{id:"do-not-show-again",onCheckedChange:x}),e.jsx("label",{htmlFor:"do-not-show-again",className:"text-sm font-medium leading-none cursor-pointer",children:"Do not show this again"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-3 sm:gap-0",children:[e.jsx(q,{variant:"outline",onClick:()=>o(!1),className:"flex items-center justify-center space-x-2",children:e.jsx("span",{children:"Skip for now"})}),e.jsxs(q,{onClick:f,className:"flex items-center justify-center space-x-2 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700",children:[e.jsx("span",{children:"Start Interactive Tour"}),e.jsx(je,{className:"h-4 w-4"})]})]}),e.jsx("p",{className:"text-xs text-center text-gray-500 dark:text-gray-400",children:"The tour takes about 2 minutes and shows you all the key features. You can restart it anytime from Settings â Help & Support."})]})]})})};function fl({trigger:t,activityType:a,title:s="File Activity History"}){const[r,n]=d.useState(!1),{data:i=[],isLoading:l,refetch:o}=le({queryKey:["/api/file-activities",a],queryFn:async()=>{const j=a?`/api/file-activities?type=${a}`:"/api/file-activities",b=await fetch(j,{credentials:"include"});if(!b.ok)throw new Error("Failed to fetch file activities");return b.json()},enabled:r});d.useEffect(()=>{r&&o()},[r,o]);const f=(j,b)=>b==="processing"?e.jsx(je,{className:"w-4 h-4 text-yellow-500"}):b==="failed"?e.jsx(ot,{className:"w-4 h-4 text-red-500"}):j==="import"?e.jsx(wa,{className:"w-4 h-4 text-blue-500"}):j==="export"?e.jsx(Fs,{className:"w-4 h-4 text-green-500"}):e.jsx(Lt,{className:"w-4 h-4 text-gray-500"}),x=j=>{switch(j){case"completed":return e.jsxs(te,{variant:"outline",className:"text-green-600 border-green-200 bg-green-50",children:[e.jsx(ps,{className:"w-3 h-3 mr-1"}),"Completed"]});case"failed":return e.jsxs(te,{variant:"outline",className:"text-red-600 border-red-200 bg-red-50",children:[e.jsx(ot,{className:"w-3 h-3 mr-1"}),"Failed"]});case"processing":return e.jsxs(te,{variant:"outline",className:"text-yellow-600 border-yellow-200 bg-yellow-50",children:[e.jsx(je,{className:"w-3 h-3 mr-1"}),"Processing"]});default:return null}},h=j=>{if(!j)return"Unknown size";const b=["Bytes","KB","MB","GB"],v=Math.floor(Math.log(j)/Math.log(1024));return Math.round(j/Math.pow(1024,v)*100)/100+" "+b[v]},N=async j=>{if(j.canDownload)try{if(ua(void 0,{report_type:j.activityType==="export"?"csv_export":"file_download",file_name:j.originalFileName,file_size_kb:Math.round(j.fileSize/1024),entries_count:j.recordCount}),j.downloadUrl){window.open(j.downloadUrl,"_blank");return}const b=await fetch(`/api/file-activities/download/${j.id}`,{credentials:"include"});if(!b.ok)throw new Error("Download failed");const v=await b.blob(),w=window.URL.createObjectURL(v),g=document.createElement("a");g.href=w,g.download=j.originalFileName,document.body.appendChild(g),g.click(),window.URL.revokeObjectURL(w),document.body.removeChild(g)}catch(b){console.error("Download error:",b)}},u=e.jsxs(q,{variant:"outline",size:"sm",children:[e.jsx($t,{className:"w-4 h-4 mr-2"}),a==="import"?"Import History":a==="export"?"Export History":"File History"]});return e.jsxs(Ne,{open:r,onOpenChange:n,children:[e.jsx(Ar,{asChild:!0,children:t||u}),e.jsxs(Ie,{className:"max-w-2xl max-h-[80vh]",children:[e.jsx(Le,{children:e.jsxs(_e,{className:"flex items-center",children:[e.jsx($t,{className:"w-5 h-5 mr-2"}),s]})}),e.jsx(ha,{className:"max-h-[60vh] pr-4",children:l?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"animate-spin w-6 h-6 border-2 border-primary border-t-transparent roun
31ded-full"})}):i.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-500",children:[e.jsx(Lt,{className:"w-12 h-12 mx-auto mb-4 text-gray-300"}),e.jsx("p",{children:"No file activities found"}),e.jsx("p",{className:"text-sm",children:a==="import"?"Import CSV files to see your history here":a==="export"?"Export data to see your history here":"Import or export files to see activity history"})]}):e.jsx("div",{className:"space-y-4",children:i.map((j,b)=>e.jsx(xe,{className:"relative",children:e.jsxs(ie,{className:"p-4",children:[b<i.length-1&&e.jsx("div",{className:"absolute left-6 top-12 w-px h-8 bg-gray-200"}),e.jsxs("div",{className:"flex items-start space-x-4",children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center",children:f(j.activityType,j.status)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("h4",{className:"font-medium text-sm truncate",children:j.originalFileName}),x(j.status)]}),e.jsxs("div",{className:"flex items-center text-xs text-gray-500",children:[e.jsx(ge,{className:"w-3 h-3 mr-1"}),Q(new Date(j.createdAt),"MMM d, yyyy HH:mm")]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-gray-500 mb-2",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("span",{className:"capitalize",children:j.activityType}),e.jsx("span",{children:h(j.fileSize)}),e.jsxs("span",{children:[j.recordCount," records"]}),e.jsxs("span",{className:"text-blue-600",children:[e.jsx(ca,{className:"w-3 h-3 inline mr-1"}),j.userName]})]}),j.canDownload&&e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>N(j),className:"h-6 px-2 text-xs",children:[e.jsx(Fs,{className:"w-3 h-3 mr-1"}),"Download"]})]}),j.metadata&&e.jsx("div",{className:"bg-slate-50 border border-slate-200 rounded p-2 mt-2",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[j.metadata.importType&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Import Type:"})," ",j.metadata.importType]}),j.metadata.exportType&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Export Type:"})," ",j.metadata.exportType]}),j.metadata.successfulImports!==void 0&&e.jsxs("div",{className:"text-green-600",children:[e.jsx("span",{className:"font-medium",children:"Successful:"})," ",j.metadata.successfulImports]}),j.metadata.errors>0&&e.jsxs("div",{className:"text-red-600",children:[e.jsx("span",{className:"font-medium",children:"Errors:"})," ",j.metadata.errors]}),j.metadata.duplicatesSkipped>0&&e.jsxs("div",{className:"text-orange-600",children:[e.jsx("span",{className:"font-medium",children:"Skipped:"})," ",j.metadata.duplicatesSkipped]})]})})]})]})]})},j.id))})}),e.jsx(Fr,{}),e.jsxs("div",{className:"flex justify-between items-center text-xs text-gray-500",children:[e.jsxs("span",{children:[i.length," ",i.length===1?"activity":"activities"," total"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>o(),children:[e.jsx(on,{className:"w-3 h-3 mr-1"}),"Refresh"]})]})]})]})}function Js({open:t,onOpenChange:a}){const[s,r]=d.useState("upload"),[n,i]=d.useState(null),[l,o]=d.useState([]),[f,x]=d.useState([]),[h,N]=d.useState({}
31),[u,j]=d.useState([]),[b,v]=d.useState([]),[w,g]=d.useState(0),{showDuring:k}=Rr(),[C,T]=d.useState({success:0,errors:0,duplicates:0}),{toast:I}=fe(),p=Re(),O=P=>{if(!P||!P.trim())return"";const F=P.toLowerCase().trim(),S=it.find(c=>c.value.toLowerCase()===F);if(S)return S.value;const L=it.find(c=>c.label.toLowerCase()===F);if(L)return L.value;const m=[{keywords:["manage","management","property"],activity:"property-management"},{keywords:["lease","leasing","tenant","screening","application"],activity:"leasing-tenant-relations"},{keywords:["maintenance","repair","fix","plumber","electrical","hvac"],activity:"maintenance-repairs-oversight"},{keywords:["bookkeeping","accounting","financial","expense","income"],activity:"bookkeeping-recordkeeping"},{keywords:["acquisition","purchase","buying","research"],activity:"property-acquisition-activities"},{keywords:["sale","selling","disposition","agent"],activity:"property-sale-disposition"},{keywords:["vendor","contractor","plumber","electrician","landscaper"],activity:"vendor-contractor-management"},{keywords:["compliance","legal","insurance","licensing"],activity:"compliance-legal-administration"},{keywords:["travel","driving","mileage","visit"],activity:"travel-property-tasks"},{keywords:["strategic","planning","portfolio","analysis"],activity:"strategic-planning-portfolio-management"},{keywords:["education","training","learning","seminar"],activity:"education-training-property-specific"},{keywords:["communication","correspondence","email","phone"],activity:"communication-correspondence"},{keywords:["evidence","documentation","receipt","photo"],activity:"evidence-collection-documentation"}];for(const c of m)if(c.keywords.some(M=>F.includes(M)))return c.activity;return"maintenance-repairs"},A=P=>{if(!P||!P.trim())return{isValid:!1,normalized:"",error:"Date is required"};const F=P.trim();if(/^\d{4}-\d{2}-\d{2}$/.test(F)){const m=new Date(F);if(!isNaN(m.getTime()))return{isValid:!0,normalized:F}}const S=/^(\d{1,2})\/(\d{1,2})\/(\d{2,4})$/,L=F.match(S);if(L){let[,m,c,M]=L;M.length===2&&(M=parseInt(M)<=30?`20${M}`:`19${M}`),m=m.padStart(2,"0"),c=c.padStart(2,"0");const G=`${M}-${m}-${c}`,V=new Date(G);if(!isNaN(V.getTime()))return{isValid:!0,normalized:G}}try{const m=new Date(F);if(!isNaN(m.getTime())){const c=m.getFullYear(),M=String(m.getMonth()+1).padStart(2,"0"),G=String(m.getDate()).padStart(2,"0");return{isValid:!0,normalized:`${c}-${M}-${G}`}}}catch{}return{isValid:!1,normalized:"",error:"Invalid date format. Use MM/DD/YY, MM/DD/YYYY, or YYYY-MM-DD"}},z=[{key:"date",label:"Date (YYYY-MM-DD)",required:!0},{key:"hours",label:"Hours (0.0167-24)",required:!0},{key:"activityType",label:"Activity Type",required:!0},{key:"description",label:"Description",required:!1},{key:"propertyType",label:"Property Type",required:!1},{key:"isMaterialParticipation",label:"Material Participation (Yes/No)",required:!1}],$=d.useCallback(P=>{var S;const F=(S=P.target.files)==null?void 0:S[0];if(F){if(!F.name.toLowerCase().endsWith(".csv")){I({title:"Invalid File Type",description:"Please upload a CSV file (.csv)",variant:"destructive"});return}if(F.size>1024*1024){I({title:"File Too Large",description:"Please upload a file smaller than 1MB",variant:"destructive"});return}i(F);try{Ir.parse(F,{header:!0,skipEmptyLines:!0,complete:L=>{if(L.errors&&L.errors.length>0){console.error("CSV Parsing Errors:",L.errors),I({title:"CSV Parse Error",description:`There was an error parsing your CSV file: ${L.errors[0].message}`,variant:"destructive"});return}const c=(L.meta.fields||[]).map(V=>V.replace(/^\uFEFF/,"").trim()).filter(V=>V),M=L.data;if(c.length===0){console.error("No headers found in CSV"),I({title:"CSV Parse Error",description:"No valid headers found in the CSV file",variant:"destructive"});return}x(c),o(M);const G={};
31c.forEach(V=>{const U=V.toLowerCase().trim();U==="date"||U==="day"||U.includes("date")||U.includes("day")?G[V]="date":U==="hours"||U==="hour"||U==="time"||U.includes("hour")||U.includes("time")?G[V]="hours":U==="activity"||U==="type"||U==="task"||U.includes("activity")||U.includes("type")||U.includes("task")?G[V]="activityType":U==="description"||U==="note"||U==="notes"||U.includes("description")||U.includes("note")||U.includes("comment")?G[V]="description":U.includes("property")||U.includes("rental")?G[V]="propertyType":(U.includes("material")||U.includes("participation"))&&(G[V]="isMaterialParticipation")}),N(G),r("mapping")},error:L=>{console.error("Papa.parse error:",L),I({title:"CSV Parse Error",description:L.message,variant:"destructive"})}})}catch(L){console.error("Exception during Papa.parse:",L),I({title:"CSV Parse Error",description:"An unexpected error occurred while parsing the CSV file",variant:"destructive"})}}},[I]),K=(P,F)=>{N(S=>({...S,[P]:F||""}))},D=()=>{const P=[],F=[],S=z.filter(m=>m.required),L=Object.values(h).filter(m=>m&&m!=="");for(const m of S)if(!L.includes(m.key)){I({title:"Missing Required Mapping",description:`Please map a column to ${m.label}`,variant:"destructive"});return}l.slice(0,5).forEach((m,c)=>{const M={};Object.entries(h).forEach(([G,V])=>{var ae;if(!V||V==="")return;const U=(ae=m[G])==null?void 0:ae.trim();if(M[V]=U,V==="date"){const J=A(U);J.isValid?M[V]=J.normalized:P.push({row:c+1,field:V,value:U||"",message:J.error||"Invalid date format"})}else if(V==="hours"){const J=parseFloat(U);(isNaN(J)||J<.0167||J>24)&&P.push({row:c+1,field:V,value:U||"",message:"Hours must be between 1 minute and 24 hours"})}else if(V==="activityType"&&U){const J=O(U);M[V]=J,J||P.push({row:c+1,field:V,value:U||"",message:"Could not match activity type"})}}),M.propertyType=M.propertyType||"Long-term Rental",M.isMaterialParticipation=M.isMaterialParticipation==="Yes"||M.isMaterialParticipation==="true"||M.isMaterialParticipation==="1",F.push(M)}),v(P),j(F),r("preview")},R=async()=>{$r(void 0,{import_type:"csv",rows_to_import:l.length});try{await k((async()=>{const P=l.map(L=>{const m={};return Object.entries(h).forEach(([c,M])=>{var V;if(!M||M==="")return;const G=(V=L[c])==null?void 0:V.trim();if(M==="date"){const U=A(G);m[M]=U.isValid?U.normalized:G}else M==="activityType"?m[M]=G&&O(G):m[M]=G}),m.propertyType=m.propertyType||"Long-term Rental",m.isMaterialParticipation=m.isMaterialParticipation==="Yes"||m.isMaterialParticipation==="true"||m.isMaterialParticipation==="1",m}),S=await(await me("POST","/api/import/csv",{data:P})).json();Hr(void 0,{file_type:"csv",rows_imported:S.success||0,total_rows:P.length,success_rate:S.success?S.success/P.length:0}),T(S),g(100),r("complete"),p.invalidateQueries({queryKey:["/api/time-entries"]}),p.invalidateQueries({queryKey:["/api/stats/total-hours"]}),p.invalidateQueries({queryKey:["/api/stats/material-participation-hours"]}),p.invalidateQueries({queryKey:["/api/stats/activity-breakdown"]})})(),{message:"Importing your time entries...",subMessage:`Processing ${l.length} entries from your CSV file`})}catch(P){I({title:"Import Failed",description:P.message||"Failed to import CSV data",variant:"destructive"}),r("preview")}},E=()=>{r("upload"),i(null),o([]),x([]),N({}),j([]),v([]),g(0),T({success:0,errors:0,duplicates:0})},_=()=>{E(),a(!1)};return e.jsx(Ne,{open:t,onOpenChange:a,children:e.jsxs(Ie,{className:"max-w-4xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Le,{children:e.jsxs(_e,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(wa,{className:"h-5 w-5 mr-2"}),"Import Time Entries from CSV"]}),e.jsx(fl,{activityType:"import",title:"Import History",trigger:e.jsxs(q,{variant:"outline",size:"sm",children:[e.jsx($t,{className:"w-4 h-4 mr-2"}),"History"]})})]})}),s==="upload"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(dt,{children:[e.jsx(Ve,{className:"h-4 w-4"}),e.jsx(ct,{children:"Upload a CSV file containing your time entries from Excel, Google Sheets, or another tool. Ensure columns include date, hours, and activity type. Use the mapping tool below to match your columns to our fields."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"csv-file",children:"Select CSV File (Max 1MB)"}),e.jsx(ye,{id:"csv-file",type:"file",accept:".csv",onChange:$,className:"cursor-pointer"})]}),e.jsx("div",{className:"flex justify-end space-x-2",children:e.jsx(q,{variant:"outline",onClick:_,children:"Cancel"})})]}),s==="mapping"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(dt,{children:[e.jsx(Ve,{className:"h-4 w-4"}),e.jsx(ct,{children:"Map your CSV columns to our database fields. Required fields are marked with an asterisk (*)."})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:f.map(P=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs(W,{className:"text-sm font-medium",children:["Your Column: ",e.jsx("span",{className:"font-mono bg-gray-100 px-1 rounded",children:P})]}),e.jsxs(Me,{value:h[P]||"skip",onValueChange:F=>K(P,F==="skip"?"":F),children:[e.jsx(Ee,{children:e.jsx(De,{placeholder:"Select target field..."})}),e.jsxs(Pe,{children:[e.jsx(re,{value:"skip",children:"-- Skip this column --"}),z.map(F=>e.jsxs(re,{value:F.key,children:[F.label," ",F.required&&"*"]},F.key))]})]})]},P))}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(q,{variant:"outline",onClick:()=>r("upload"),children:"Back"}),e.jsx(q,{variant:"outline",onClick:_,children:"Cancel"}),e.jsx(q,{onClick:D,children:"Preview Import"})]})]}),s==="preview"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(dt,{children:[e.jsx(Ve,{className:"h-4 w-4"}),e.jsx(ct,{children:"Preview of the first 5 rows. Review the data before importing."})]}),b.length>0&&e.jsxs(dt,{variant:"destructive",children:[e.jsx(ot,{className:"h-4 w-4"}),e.jsxs(ct,{children:["Found ",b.length," validation errors:",e.jsx("ul",{className:"mt-2 list-disc list-inside",children:b.slice(0,5).map((P,F)=>e.jsxs("li",{className:"text-sm",children:["Row ",P.row,", ",P.field,": ",P.message,' (value: "',P.value,'")']},F))})]})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(Lr,{children:[e.jsx(_r,{children:e.jsxs(Rs,{children:[e.jsx(Je,{children:"Date"}),e.jsx(Je,{children:"Hours"}),e.jsx(Je,{children:"Activity Type"}),e.jsx(Je,{children:"Description"}),e.jsx(Je,{children:"Property Type"}),e.jsx(Je,{children:"Material Participation"})]})}),e.jsx(Or,{children:u.map((P,F)=>e.jsxs(Rs,{children:[e.jsx(Xe,{className:"font-mono text-sm",children:P.date||"â"}),e.jsx(Xe,{children:P.hours||"â"}),e.jsx(Xe,{children:P.activityType||"â"}),e.jsx(Xe,{className:"max-w-xs truncate",children:P.description||"â"}
31),e.jsx(Xe,{children:P.propertyType||"Long-term Rental"}),e.jsx(Xe,{children:e.jsx(te,{variant:P.isMaterialParticipation?"default":"secondary",children:P.isMaterialParticipation?"Yes":"No"})})]},F))})]})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(q,{variant:"outline",onClick:()=>r("mapping"),children:"Back to Mapping"}),e.jsx(q,{variant:"outline",onClick:_,children:"Cancel"}),e.jsxs(q,{onClick:R,disabled:b.length>0,children:["Import ",l.length," Entries"]})]})]}),s==="complete"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(dt,{children:[e.jsx(ps,{className:"h-4 w-4"}),e.jsx(ct,{children:"Import completed successfully!"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:C.success}),e.jsx("div",{className:"text-sm text-gray-600",children:"Successfully Imported"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-yellow-600",children:C.duplicates}),e.jsx("div",{className:"text-sm text-gray-600",children:"Duplicates Skipped"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-red-600",children:C.errors}),e.jsx("div",{className:"text-sm text-gray-600",children:"Errors"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(q,{onClick:_,children:"Close"})})]})]})})}const bl=()=>null;function Xs(t,a){return`${t} ${a}${t===1?"":"s"}`}function Zs({userId:t,userCreatedAt:a,hasCompletedOnboardingForm:s,welcomeSummary:r,hasSetupProgress:n,selectedYear:i,isOnTrial:l}){const[,o]=Mt(),{startTour:f}=hs(),x=t?`dashboard_welcome_shown_${t}`:null,[h,N]=d.useState(()=>!!x&&localStorage.getItem(x)==="true"),u=a?new Date(a).getTime():NaN,j=!Number.isNaN(u)&&u<qr.getTime();if(!(!!s&&!j&&!h&&n&&!!r)||!r)return null;const v=()=>{x&&localStorage.setItem(x,"true"),N(!0)},w=i?`&year=${i}`:"",g=r.calendarEventCount>0||r.emailCount>0,k=g?`We found ${r.totalHours} hours across ${Xs(r.calendarEventCount,"calendar event")} and ${Xs(r.emailCount,"email")} â ready for you to review.`:"You're all set up. Once we analyze your connected calendar and email, we'll show your hours right here.";return e.jsxs("div",{className:"mb-6 p-6 bg-accent/40 dark:bg-accent/10 border border-primary/20 rounded-lg relative",children:[e.jsx("button",{type:"button",onClick:v,"aria-label":"Dismiss",className:"absolute top-3 right-3 text-muted-foreground hover:text-foreground",children:e.jsx(se,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"h-16 w-16 rounded-full bg-white dark:bg-gray-800 flex items-center justify-center shadow-sm border border-border",children:e.jsx("img",{src:"/repsshield-logo-main.png",alt:"",className:"h-9 w-9 object-contain"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-xl font-bold text-foreground mb-2",children:"Welcome to your dashboard!"}),e.jsx("p",{className:"text-base text-muted-foreground mb-4",children:k}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[g&&e.jsx(q,{onClick:()=>o(`/activity-ledger?status=pending${w}`),className:"bg-primary hover:bg-primary/90 text-primary-foreground",children:"Review them now"}),e.jsx("button",{type:"button",onClick:f,className:"text-sm text-primary underline underline-offset-2 hover:text-primary/80",children:"New here? Take the 2-minute tour"})]}),l&&e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"14 days of full access, no card needed."})]})]})]})}function yl(){const[,t]=Mt(),[a,s]=d.useState(!1),{items:r,completedCount:n,totalCount:i,allComplete:l,isPreLaunchAccount:o}=zr();if(l||o)return null;const f=x=>{var h;(h=x.onAction)==null||h.call(x),x.href&&t(x.href)};return e.jsx(xe,{children:e.jsxs(ie,{className:"p-4 sm:p-6",children:[e.jsxs("button",{type:"button",onClick:()=>s(x=>!x),className:"flex w-full items-center justify-between text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ga,{className:"h-5 w-5 text-primary"}),e.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:"Getting Started"}),e.jsxs("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:[n,"/",i," complete"]})]}),a?e.jsx(cs,{className:"h-5 w-5 text-gray-400"}):e.jsx(Gr,{className:"h-5 w-5 text-gray-400"})]}),!a&&e.jsx("div",{className:"mt-4 space-y-1",children:r.map(x=>e.jsxs("button",{type:"button",onClick:()=>f(x),disabled:x.complete,className:`flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors ${x.complete?"text-gray-400 dark:text-gray-500 cursor-default":"text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800"}`,children:[x.complete?e.jsx(lt,{className:"h-4 w-4 flex-shrink-0 text-green-600"}):e.jsx(Vr,{className:"h-4 w-4 flex-shrink-0 text-gray-300 dark:text-gray-600"}),e.jsx("span",{className:x.complete?"line-through":"",children:x.label}),x.hint&&!x.complete&&e.jsx("span",{className:"ml-auto text-xs text-gray-400",children:x.hint})]},x.id))})]})})}function Wl(){var ke,Qe,Ue,Ce,Ke,Ye,be,Oe,Be,$e;const{user:t,isLoading:a,isAuthenticated:s}=Tt(),r=Re(),n=Na(),{hasMounted:i}=Hi();qi();const{subscription:l,hasActiveSubscription:o,subscribe:f,isSubscribing:x,isOnTrial:h}=fa();zi({subscription:l,user:t});const N=!!(t!=null&&t.stripeSubscriptionId)&&((t==null?void 0:t.subscriptionStatus)==="active"||(t==null?void 0:t.subscriptionStatus)==="trialing");_i(),Oi();const u=new Date().getFullYear(),[j,b]=d.useState(u),{totalHours:v,materialHours:w,properties:g,recentEntries:k,pendingCount:C,welcomeSummary:T,teamStats:I}=Qr(t==null?void 0:t.id,j),p=d.useMemo(()=>Array.isArray(g)?g:[],[g]),O=k||[],A=Gi({user:t,totalHours:v,materialHours:w,selectedYear:j}),z=Qi(o),$=Ga(),{gmailStatusQuery:K,microsoftMailStatusQuery:D,imapStatusQuery:R,googleCalendarStatusQuery:E,microsoftCalendarStatusQuery:_,handleGoogleCalendarConnect:P,handleMicrosoftCalendarConnect:F,disconnectGoogleCalendarMutation:S,disconnectMicrosoftCalendarMutation:L,isGoogleCalendarConnecting:m,isMicrosoftCalendarConnecting:c}=ft(),M=((ke=E.data)==null?void 0:ke.connected)||!1,G=((Qe=_.data)==null?void 0:Qe.connected)||!1,V=!!((Ue=K.data)!=null&&Ue.connected||(Ce=D.data)!=null&&Ce.connected||(Ke=R.data)!=null&&Ke.connected||M||G),U=p.length>0||V||C>0,[ae,J]=d.useState(!1),[Z,ue]=d.useState(!1),[we,he]=d.useState(!1),ee=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;if($i({url:ee,enabled:!!t&&s,delayMs:1500,onMessage:de=>{de.type==="time_entry_update"&&r.invalidateQueries({queryKey:["/api/time-entries/recent"]})},onError:de=>console.warn("[WebSocket] Connection error:",de)}),a)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-primary"})});if(!t)return null;if(!i)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"animate-spin rounded-full h-32 w-32 border-b-2 border-primary"})});if(n){const de=!!((Ye=K.data)!=null&&Ye.connected||(be=D.data)!=null&&be.connected||(Oe=R.data)!=null&&Oe.connected),Se=!!(D.error||R.error),y=!!((Be=R.data)!=null&&Be.connected&&(($e=R.data)==null?void 0:$e.credentialValid)===!1),B=!!(M||G),Y=!!(E.error||_.error);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 pt-4 space-y-3",children:[e.jsx(Zs,{userId:t.id,userCreatedAt:t.createdAt,hasCompletedOnboardingForm:t.hasCompletedOnboardingForm,welcomeSummary:T,hasSetupProgress:U,selectedYear:j,isOnTrial:h}),e.jsx(yl,{})]}),e.jsx(Ri,{user:t,isSubscribed:N,isOnTrial:h,progress:{totalHours:A.totalHoursValue,goalHours:A.goalHours,percentComplete:A.progressPercentage,remainingHours:A.remainingHours,selectedYear:j,materialHours:A.materialHoursValue,materialGoalHours:A.materialGoal},pendingReviewCount:C,mailConnected:de,mailHasError:Se,mailHasCredentialIssue:y,calendarConnected:B,calendarHasError:Y,selectedYear:j,onYearChange:b}),e.jsx(Js,{open:we,onOpenChange:he}),e.jsx(Ks,{open:$.showForm,onOpenChange:$.setShowForm}),e.jsx(Ws,{}),e.jsx(ns,{open:z.showPaywallModal,onOpenChange:z.setShowPaywallModal,onSubscribe:f,isSubscribing:x}),e.jsx(At,{open:ae,onOpenChange:J,integrationType:"google-calendar",isConnected:M,isLoading:m||S.isPending,onConnect:P,onDisconnect:()=>S.mutate()}),e.jsx(At,{open:Z,onOpenChange:ue,integrationType:"microsoft-calendar",isConnected:G,isLoading:c||L.isPending,onConnect:F,onDisconnect:()=>L.mutate()})]})}return e.jsxs("div",{className:"container-mobile py-6 space-y-6","data-testid":"dashboard-content",children:[e.jsxs("div",{className:"mb-3",children:[!n&&e.jsxs("div",{className:"flex flex-col mb-3",children:[e.jsxs("h1",{className:"text-3xl md:text-4xl font-extrabold tracking-tight text-gray-900 dark:text-gray-100",children:["ð ","Welcome"," ",t!=null&&t.firstName&&(t!=null&&t.lastName)?`${t.firstName} ${t.lastName}`:(t==null?void 0:t.firstName)||(t==null?void 0:t.email)||"back","!"]}),e.jsx("p",{className:"text-gray-500 dark:text-gray-400 mt-1 text-sm md:text-base",children:"Ready to track y
31our hours and maintain compliance?"})]}),e.jsxs("div",{className:"flex flex-col space-y-0 sm:flex-row sm:items-center sm:justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center justify-between w-full sm:w-auto",children:[e.jsx("div",{"data-tour":"dashboard-header",children:e.jsx("h2",{className:"text-xl sm:text-2xl font-bold text-gray-900 dark:text-white",children:"Dashboard Overview"})}),e.jsx("div",{className:"flex items-center sm:hidden -mt-4",children:e.jsx(ls,{selectedYear:j,onYearChange:b,currentYear:u,compact:!0})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-4 w-full sm:w-auto",children:[e.jsx("div",{className:"hidden sm:block",children:e.jsx(ls,{selectedYear:j,onYearChange:b,currentYear:u})}),e.jsx("div",{"data-tour":"rep-type-selector",children:e.jsx(Xi,{user:t,timeEntries:O,selectedYear:j,pendingCount:C})})]})]}),e.jsx("div",{className:"mb-3",children:e.jsx(Ha,{userId:t.id,isSubscribed:N,isOnTrial:h,mobileInstallCompleted:t.mobileInstallCompleted})}),e.jsx("div",{className:"mb-3",children:e.jsx(qa,{userId:t.id,isSubscribed:N})}),e.jsx("div",{className:"mb-3",children:e.jsx(bl,{})}),e.jsx(Zs,{userId:t.id,userCreatedAt:t.createdAt,hasCompletedOnboardingForm:t.hasCompletedOnboardingForm,welcomeSummary:T,hasSetupProgress:U,selectedYear:j,isOnTrial:h}),e.jsx("div",{children:e.jsx(el,{totalHours:A.totalHoursValue,materialHours:A.materialHoursValue,timeEntries:O,user:t,teamStats:I,selectedYear:j,pendingCount:C,onAddTimeEntry:()=>{const de=document.querySelector('[data-tour="time-logging-form"]');de&&de.scrollIntoView({behavior:"smooth"})}})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 lg:grid-rows-[1fr_1fr] gap-6 w-full",children:[!n&&e.jsx(pl,{properties:p}),e.jsx("div",{className:"dashboard-card",children:e.jsx(Yi,{setGoogleCalendarDialogOpen:J,setMicrosoftCalendarDialogOpen:ue})}),n?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"dashboard-card",children:e.jsx(Ls,{})}),e.jsx("div",{"data-tour":"recent-activity",className:"dashboard-card",children:e.jsx(Us,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-tour":"recent-activity",className:"dashboard-card",children:e.jsx(Us,{})}),e.jsx("div",{className:"dashboard-card",children:e.jsx(Ls,{})})]})]}),e.jsx(Js,{open:we,onOpenChange:he}),e.jsx(Ks,{open:$.showForm,onOpenChange:$.setShowForm}),e.jsx(Ws,{}),e.jsx(ns,{open:z.showPaywallModal,onOpenChange:z.setShowPaywallModal,onSubscribe:f,isSubscribing:x}),e.jsx(At,{open:ae,onOpenChange:J,integrationType:"google-calendar",isConnected:M,isLoading:m||S.isPending,onConnect:P,onDisconnect:()=>S.mutate()}),e.jsx(At,{open:Z,onOpenChange:ue,integrationType:"microsoft-calendar",isConnected:G,isLoading:c||L.isPending,onConnect:F,onDisconnect:()=>L.mutate()})]})}export{Wl 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.