1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/analytics-JOA_m9vc.js","assets/index-Byg2HWAE.js","assets/vendor-Qgthw7N1.js","assets/index-D3-M_W_f.css","assets/useParallelQueries-D2tckJDW.js","assets/info-B94Hlx1u.js","assets/activity-DlNiJWQy.js","assets/arrow-up-right-D1j766Li.js","assets/generateCategoricalChart-BoqWx9k4.js","assets/chart-pie-P9cErRnq.js","assets/PieChart-CAoo1sxk.js","assets/LineChart-CNPEj-ac.js","assets/AreaChart-BtAPz8zO.js"])))=>i.map(i=>d[i]); 2import{y as yt,a8 as Gt,ff as Ks,j as e,aW as Ye,bO as Be,bP as We,m as pe,_ as ke,$ as Ce,a0 as Se,a1 as Te,a2 as te,e as Z,bQ as Je,a as fe,aJ as Pe,aC as ce,az as me,B as G,bp as xt,cG as Fa,af as re,aI as z,a5 as Y,n as ne,fg as Us,L as B,K as ye,cY as Ys,V as Xt,bG as Bs,c$ as ue,aD as Lt,bj as Me,aH as be,aG as fs,C as he,b as vt,c as jt,X as se,d as le,fh as bs,cl as Ia,bH as oe,aZ as ve,a_ as De,a$ as Ae,b0 as Fe,i as ge,b1 as _t,cd as Ra,fi as La,d2 as Ws,cj as Js,fj as is,fk as Xs,fl as Zs,b6 as Xe,cI as ea,aF as Ze,W as ns,fm as _a,fn as ys,b7 as Nt,b8 as wt,b9 as kt,d0 as Ot,ac as ut,f as ht,bf as et,Z as Ht,bh as Ee,ab as ta,as as _e,E as ls,G as os,I as pt,J as gt,be as tt,bN as sa,aV as aa,am as ra,cZ as st,F as Dt,a4 as Zt,U as Oa,aN as Ha,ba as ia,l as $t,fo as $a,fp as vs,fq as qa,fr as za,br as js,fs as Ns,ft as na,aM as ft,b2 as la,p as oa,q as Mt,r as Et,s as Pt,cD as Ga,aY as at,b4 as Va,aE as da,bM as ca,T as ws,fu as Qa,fv as Ka,fw as Ua,c_ as ma,cX as Vt,bF as Ya,fx as Ba,dB as Wa,fy as Ja,fz as Xa,cn as es,fA as Za,fB as er,fC as tr,dq as sr,dr as ar,ds as rr,dt as ks,fD as ir,fE as At,fF as Ft,fG as nr,fH as lr,fI as Cs,fJ as Ss,aO as or,fK as dr,fL as xa,fM as cr,cK as mr,aa as xr,g as ur,aA as hr,b3 as pr,aK as ua,h as ds,o as gr,M as fr,bI as br,D as Ts,N as yr,Y as ha,al as vr,dA as jr,Q as lt,R as ot,aP as Nr,aQ as wr,aR as Ms,aS as Ve,aT as kr,aU as Qe,fN as Cr,fO as Sr}from"./index-Byg2HWAE.js";import{r as d,u as cs}from"./vendor-Qgthw7N1.js";import{S as ms,a as Tr}from"./useParallelQueries-D2tckJDW.js";import{u as bt}from"./useIntegrations-CUanp7GW.js";import{h as Mr,i as Er,e as Pr,j as Es}from"./CalendarDateRangeFilter-BVOXnJ7M.js";import{m as Dr}from"./calendarService-CrpjTGeC.js";import{i as It}from"./authUtils-CcDzk6i0.js";import{u as pa,T as Ar,a as Fr,b as ga,c as Ir,I as Ps,d as Rr,M as Ds}from"./MailActivityCard-G6QR5aNV.js";import{u as xs}from"./useAutomation-lkaxjoGr.js";import{a as Lr}from"./automationService-OVbtW0oB.js";import{C as rt}from"./circle-x-C3yul9_R.js";import{u as fa,C as _r}from"./CalendarView-C6WRDhF9.js";import{C as mt}from"./checkbox-Cqr9jids.js";import{C as Or}from"./CalendarStatusLegend-BpVkF9GW.js";import{C as us}from"./calendar-days-CZv4Giu2.js";import{I as Le}from"./info-B94Hlx1u.js";import{T as hs}from"./timer-B3GC1z8w.js";import{P as ts}from"./play-BTJ7KJDO.js";import{P as Hr}from"./pause-BCrfl0Rj.js";import{S as ba,t as As,A as $r}from"./timeEntryService-DBf_VWTS.js";import{T as qr,a as Qt}from"./toggle-group-BVV0MziZ.js";import{B as zr}from"./brain-CkeK6gqK.js";import{M as Gr}from"./maximize-2-D7IQEluU.js";import{S as Vr,a as Qr}from"./index-Bs2JGf-v.js";import{H as ss}from"./history-DLcruDYK.js";import{E as ya,R as va}from"./RepsClassificationSection-BliMW0iC.js";import{M as Ct,a as Kr}from"./MobileImapConnectSheet-C6JGrTGV.js";import"./differenceInMonths-CWoVTq_U.js";import"./message-circle-CEbsxAUX.js";import"./index-COtV6X2D.js";import"./grid-3x3-Dl22D3mL.js";import"./filter-ejjrE0l5.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 Ur=yt("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 Yr=yt("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 Br=yt("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 Wr=yt("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 Jr=yt("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"}]]);function Xr(t,a){const s=Gt(t.start),r=Gt(t.end);let i=+s>+r;const l=i?+s:+r,n=i?r:s;n.setHours(0,0,0,0);let o=1;const x=[];for(;+n<=l;)x.push(Gt(n)),n.setDate(n.getDate()+o),n.setHours(0,0,0,0);return i?x.reverse():x}function Zr(t,a){return Ks(t,-1)}function as({selectedYear:t,onYearChange:a,currentYear:s=new Date().getFullYear(),compact:r=!1}){const i=Array.from({length:s-2022+1},(n,o)=>s-o),l=t!==s;return e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Ye,{children:e.jsxs(Be,{children:[e.jsx(We,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx(pe,{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(ke,{value:t.toString(),onValueChange:n=>a(parseInt(n)),children:[e.jsx(Ce,{className:`w-full min-w-[100px] max-w-[140px]${r?" h-8 text-sm":""}`,children:e.jsx(Se,{placeholder:"Select Year"})}),e.jsx(Te,{children:i.map(n=>e.jsx(te,{value:n.toString(),children:n},n))})]}),l&&e.jsx(Z,{variant:"secondary",className:"text-xs flex-shrink-0 hidden sm:inline-flex",children:"Past Year"})]})]})}),e.jsx(Je,{children:e.jsx("p",{children:"Select a tax year to view hours and progress for that year"})})]})})})}function ei({repType:t}
27){const[a,s]=d.useState(!1),{toast:r}=fe(),i=Pe(),l=ce({mutationFn:async b=>{const u=await me("PATCH","/api/auth/user",{repType:b});if(!u.ok){const y=await u.text();throw new Error(y)}return u.json()},onMutate:async b=>{await i.cancelQueries({queryKey:["/api/auth/user"]});const u=i.getQueryData(["/api/auth/user"]);return i.setQueryData(["/api/auth/user"],y=>y&&{...y,repType:b}),{previousUser:u}},onSuccess:b=>{i.setQueryData(["/api/auth/user"],b),i.invalidateQueries({queryKey:["/api/stats"]}),i.invalidateQueries({queryKey:["/api/time-entries"]}),r({title:"REP Type Updated",description:"Your REP status type has been updated successfully"})},onError:(b,u,y)=>{y!=null&&y.previousUser&&i.setQueryData(["/api/auth/user"],y.previousUser),r({title:"Error",description:"Failed to update REP type",variant:"destructive"})}}),n=b=>{b!==t&&(b==="shortTerm"?s(!0):l.mutate("longTerm"))},o=t==="longTerm",x=t==="shortTerm",p=l.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(G,{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"} ${p?"opacity-75":""}`,onClick:()=>n("longTerm"),disabled:p,children:"REP Status"}),e.jsx(G,{variant:x?"default":"ghost",size:"sm",className:`h-8 flex-1 rounded-full px-3 text-xs font-medium transition-all ${x?"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"} ${p?"opacity-75":""}`,onClick:()=>n("shortTerm"),disabled:p,children:"STR Loophole"})]}),e.jsx(Z,{variant:"outline",className:"flex-shrink-0 text-xs",children:o?"750 hrs":x?"500 + 100 hrs":"750 hrs"})]})}),e.jsx(ms,{isOpen:a,onClose:()=>s(!1),onSelectionComplete:()=>s(!1)})]})}function ti(){const t=new Date().getHours();return t<12?"Good morning":t<18?"Good afternoon":"Good evening"}function si(t){var a;return t.firstName||((a=t.email)==null?void 0:a.split("@")[0])||"there"}function ai({user:t,notificationCount:a=0,onNotificationsClick:s,onProfileClick:r,selectedYear:i,onYearChange:l,repType:n}){var o,x;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:[ti(),", ",si(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(xt,{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"}):(((o=t.firstName)==null?void 0:o[0])||((x=t.email)==null?void 0:x[0])||"U").toUpperCase()})})]}),e.jsx("div",{className:"mt-3",children:i!=null&&l&&e.jsx(as,{selectedYear:i,onYearChange:l,compact:!0})}),n!=null&&e.jsx(ei,{repType:n})]})}function ri({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(Fa,{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 dar
27k: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(re,{className:"h-5 w-5 flex-shrink-0 text-amber-950 dark:text-amber-100"})]})}function Kt(t){return t.toFixed(1).replace(/\.0$/,"")}function ii({percent:t}){const s=2*Math.PI*42,r=Math.max(0,Math.min(t,100)),i=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:i,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 ni(){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 li({summary:t,isLoading:a=!1,error:s,onDetailsClick:r,onTimerClick:i}){if(a)return e.jsx(ni,{});const l=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"}),(i||r)&&e.jsxs("div",{className:"flex items-center gap-1",children:[i&&e.jsxs("button",{type:"button",onClick:i,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(hs,{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(re,{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(ii,{percent:l}),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:Kt(t.totalHours)}),e.jsxs("span",{className:"ml-1 text-sm text-gray-500 dark:text-gray-400",children:["/ ",Kt(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:z("h-full rounded-full bg-blue-600 transition-all duration-500"),style:{width:`${l}%`}})}),e.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:[Kt(t.remainingHours)," hrs remaining"]})]})]})]})}const Ut="reptracker_stopwatch";function ja({hideFloatingWidget:t=!1,completionSurface:a="dialog",onSubmissionSuccess:s}){const{toast:r}
27=fe(),i=d.useRef(null),[l,n]=d.useState(!1),[o,x]=d.useState(!1),p=new Date().getFullYear(),b=()=>{try{const g=localStorage.getItem(Ut);if(g){const w=JSON.parse(g);if(w.isRunning&&w.startTime){const M=Date.now(),k=w.pausedTime+(M-w.startTime);return{...w,elapsedTime:k}}return w}}catch(g){console.error("Failed to load stopwatch state:",g)}return{isRunning:!1,isPaused:!1,startTime:null,pausedTime:0,elapsedTime:0}},[u,y]=d.useState(b),[N,f]=d.useState(!1),[c,P]=d.useState({date:Y(new Date,"yyyy-MM-dd"),hours:"",activityType:"",propertyId:"none",propertyType:"Long-term Rental",description:"",isMaterialParticipation:!1,evidence:null,timeStarted:"",timeEnded:""});d.useEffect(()=>{if(c.date){const w=new Date(c.date).getFullYear();w<p?(x(!0),r({title:"Previous Tax Year Selected",description:`You are logging hours for ${w}. These will not count toward your current ${p} goals.`})):x(!1)}},[c.date,p,r]);const{data:h=[]}=ne({queryKey:["/api/properties"]}),C=g=>{try{localStorage.setItem(Ut,JSON.stringify(g))}catch(w){console.error("Failed to save stopwatch state:",w)}},v=()=>{try{localStorage.removeItem(Ut)}catch(g){console.error("Failed to clear stopwatch state:",g)}};d.useEffect(()=>(u.isRunning&&u.startTime?i.current=setInterval(()=>{const g=Date.now(),w=u.pausedTime+(g-u.startTime);y(M=>({...M,elapsedTime:w}))},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 S=g=>{const w=Math.floor(g/1e3),M=Math.floor(w/60);return`${Math.floor(M/60).toString().padStart(2,"0")}:${(M%60).toString().padStart(2,"0")}:${(w%60).toString().padStart(2,"0")}`},O=()=>{const g=Date.now();La(void 0,{timer_type:"real_time_tracking"}),y(w=>({...w,isRunning:!0,isPaused:!1,startTime:g})),P(w=>({...w,timeStarted:new Date(g).toISOString()})),r({title:"Timer Started",description:"Time tracking is now active"})},m=()=>{const g=Date.now();y(w=>({...w,isRunning:!1,isPaused:!0,pausedTime:w.pausedTime+(g-w.startTime),startTime:null})),r({title:"Timer Paused",description:"Time tracking paused"})},I=()=>{const g=Date.now();y(w=>({...w,isRunning:!0,isPaused:!1,startTime:g})),r({title:"Timer Resumed",description:"Time tracking resumed"})},A=()=>{const g=Date.now(),w=u.pausedTime+(u.startTime?g-u.startTime:0),M=Math.round(w/(1e3*60*60)*1e3)/1e3,k=Math.floor(w/1e3),R=Math.floor(k/3600),U=Math.floor(k%3600/60),V=k%60,K=`${R.toString().padStart(2,"0")}:${U.toString().padStart(2,"0")}:${V.toString().padStart(2,"0")}`;P(ee=>({...ee,hours:M.toString(),timeEnded:new Date(g).toISOString()})),y(ee=>({...ee,isRunning:!1,isPaused:!1,elapsedTime:w})),n(!0),r({title:"Timer Stopped",description:`Logged ${K} (${M} hours). Complete your entry details.`})},L=()=>
27{y({isRunning:!1,isPaused:!1,startTime:null,pausedTime:0,elapsedTime:0}),v(),r({title:"Timer Reset",description:"Timer has been reset"})},H=ce({mutationFn:async g=>(await me("POST","/api/time-entries",g)).json(),onSuccess:()=>{Us(void 0,{entry_method:"stopwatch",hours_logged:parseFloat(c.hours),activity_type:c.activityType,has_evidence:!!c.evidence,is_material_participation:c.isMaterialParticipation,timer_duration_ms:u.elapsedTime}),_(),n(!1),L(),s==null||s(),r({title:"Time Entry Logged",description:"Your stopwatch session has been successfully logged to the Activity Ledger"})},onError:g=>{const w=g instanceof Error?g.message:"Failed to log time entry";r({title:"Error",description:w,variant:"destructive"})}}),$=()=>{if(!c.activityType){r({title:"Missing Information",description:"Please select an activity type",variant:"destructive"});return}const g=new FormData;g.append("date",c.date),g.append("hours",c.hours),g.append("activityType",c.activityType),g.append("propertyId",c.propertyId),g.append("propertyType",c.propertyType),g.append("description",c.description),g.append("isMaterialParticipation",c.isMaterialParticipation.toString()),g.append("source","stopwatch"),g.append("timeStarted",c.timeStarted),g.append("timeEnded",c.timeEnded),c.evidence&&g.append("evidence",c.evidence),H.mutate(g)},_=()=>{const g=w=>{Ra.invalidateQueries({predicate:M=>{const[k]=M.queryKey;return typeof k=="string"&&k.startsWith(w)}})};g("/api/time-entries"),g("/api/stats/total-hours"),g("/api/stats/material-participation-hours"),g("/api/stats/activity-breakdown"),g("/api/stats/qualified-non-material-hours"),g("/api/stats/rep-progress"),g("/api/stats/rep-requirements"),g("/api/dashboard-data"),g("/api/evidence-files")};d.useEffect(()=>{const g=w=>{if(u.isRunning)return w.preventDefault(),w.returnValue="You have an active timer running. Are you sure you want to leave?",w.returnValue};return window.addEventListener("beforeunload",g),()=>window.removeEventListener("beforeunload",g)},[u.isRunning]);const q=u.isRunning||u.isPaused,F=a==="mobile-sheet",T=F?"z-[130]":void 0,E=`Complete Time Entry - ${S(u.elapsedTime)}`,D=e.jsxs("div",{className:F?"space-y-4 px-4 pb-6 pt-1":"space-y-4",children:[F&&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(B,{htmlFor:"date",children:"Date"}),e.jsx(ye,{id:"date",type:"date",value:c.date,onChange:g=>P(w=>({...w,date:g.target.value}))})]}),e.jsxs("div",{children:[e.jsx(Ys,{value:c.hours,onChange:g=>P(w=>({...w,hours:g})),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(Z,{variant:"secondary",className:"text-xs",children:"Auto-calculated"}),e.jsxs("p",{className:"text-xs text-green-600",children:["â Time from stopwatch session (",S(u.elapsedTime),")"]})]})]})]}),o&&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(Xt,{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 ",p," goals. You can view previous year data using the Tax Year selector on the dashboard."]})]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"activityType",children:"Activity Type *"}),e.jsx(Bs,{value:c.activityType,onValueChange:g=>{const w=ue[g];P(M=>({...M,activityType:g,isMaterialParticipation:(w==null?void 0:w.autoEnable)||!1}))},placeholder:"Select or type activity type...",popoverContentClassName:T})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:"property",children:"Property"}),e.jsxs(ke,{value:c.propertyId,onValueChange:g=>P(w=>({...w,propertyId:g})),children:[e.jsx(Ce,{children:e.jsx(Se,{placeholder:"Select property..."})}),e.jsxs(Te,{className:T,children:[e.jsx(te,{value:"none",children:"No property"}),h.map(g=>e.jsxs(te,{value:g.id.toString(),children:[g.nickname," - ",g.address]},g.id))]})]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"propertyType",children:"Property Type"}),e.jsxs(ke,{value:c.propertyType,onValueChange:g=>P(w=>({...w,propertyType:g})),children:[e.jsx(Ce,{children:e.jsx(Se,{})}),e.jsxs(Te,{className:T,children:[e.jsx(te,{value:"Long-term Rental",children:"Long-term Rental"}),e.jsx(te,{value:"Short-term Rental",children:"Short-term Rental"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"description",children:"Description"}),e.jsx(Lt,{id:"description",value:c.description,onChange:g=>P(w=>({...w,description:g.target.value})),placeholder:"Describe the work performed during this time...",rows:3})]}
27),c.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(Me,{id:"materialParticipation",checked:c.isMaterialParticipation,onCheckedChange:g=>P(w=>({...w,isMaterialParticipation:g}))}),e.jsx(B,{htmlFor:"materialParticipation",className:"text-sm",children:"Material Participation Activity"})]}),c.activityType&&ue[c.activityType]&&e.jsx("div",{className:`p-3 rounded-lg border text-sm ${ue[c.activityType].riskLevel==="low"?"bg-green-50 border-green-200 text-green-800":ue[c.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:[ue[c.activityType].riskLevel==="low"&&e.jsx("span",{className:"text-green-600",children:"â "}),ue[c.activityType].riskLevel==="moderate"&&e.jsx("span",{className:"text-yellow-600",children:"â ï¸"}),ue[c.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:ue[c.activityType].autoEnable?"Auto-enabled for material participation":"Not auto-enabled for material participation"}),e.jsx("p",{className:"text-xs leading-relaxed",children:ue[c.activityType].explanation})]})]})})]}),e.jsxs("div",{children:[e.jsx(B,{children:"Evidence Upload (Optional)"}),e.jsxs("div",{className:`mt-2 border-2 border-dashed rounded-lg p-4 text-center transition-colors ${c.evidence?"border-green-500 bg-green-50":"border-gray-300 hover:border-gray-400"}`,onDragOver:g=>{g.preventDefault(),g.currentTarget.classList.add("border-blue-500","bg-blue-50")},onDragLeave:g=>{g.preventDefault(),g.currentTarget.classList.remove("border-blue-500","bg-blue-50")},onDrop:g=>{g.preventDefault(),g.currentTarget.classList.remove("border-blue-500","bg-blue-50");const w=g.dataTransfer.files;w.length>0&&P(M=>({...M,evidence:w[0]}))},children:[e.jsx("input",{type:"file",id:"evidence-upload",className:"hidden",accept:".pdf,.jpg,.jpeg,.png,.docx",onChange:g=>{const w=g.target.files;w&&w.length>0&&P(M=>({...M,evidence:w[0]}))}}),e.jsx("label",{htmlFor:"evidence-upload",className:"cursor-pointer",children:c.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:c.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"})]})})]}),c.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(G,{type:"button",variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsx(G,{onClick:$,disabled:H.isPending,children:H.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(be.div,{whileHover:{scale:1.02},whileTap:{scale:.98},className:"relative",children:[e.jsxs(G,{onClick:()=>f(!N),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 ${u.isRunning?"bg-gradient-to-br from-red-500 to-red-600 hover:from-red-600 hover:to-red-700":u.isPaused?"bg-gradient-to-br from-amber-500 to-amber-600 hover:from-amber-600 hover:to-amber-700":"bg-gradient-to-br from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700"} 30 text-white backdrop-blur-sm 31 `,size:"lg",children:[u.isRunning&&e.jsx(be.div,{className:"absolute inset-0 rounded-full border-4 border-red-300",animate:{scale:[1,1.2,1],opacity:[.8,.2,.8]},transition:{duration:2,repeat:1/0,ease:"easeInOut"}}),e.jsx(be.div,{initial:{scale:.8,opacity:0}
31,animate:{scale:1,opacity:1},transition:{duration:.2},children:e.jsx(hs,{className:"h-6 w-6 sm:h-7 sm:w-7"})},u.isRunning?"running":u.isPaused?"paused":"ready")]}),e.jsx(fs,{children:q&&e.jsx(be.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:S(u.elapsedTime)})})})]})}),e.jsx(fs,{children:(N||t)&&e.jsx(be.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(he,{className:`shadow-2xl border-0 bg-white/95 dark:bg-gray-900/95 backdrop-blur-xl rounded-2xl overflow-hidden ${t?"w-full":"w-72 sm:w-80"}`,children:[e.jsx(vt,{className:"pb-3",children:e.jsxs(jt,{className:"flex items-center justify-between text-base",children:[e.jsxs(be.div,{className:"flex items-center gap-2",initial:{opacity:0,y:-10},animate:{opacity:1,y:0},children:[e.jsx(be.div,{animate:{scale:u.isRunning?[1,1.2,1]:1,opacity:u.isRunning?[.7,1,.7]:1},transition:{duration:1.5,repeat:u.isRunning?1/0:0,ease:"easeInOut"},className:`w-2.5 h-2.5 rounded-full ${u.isRunning?"bg-red-500":u.isPaused?"bg-amber-500":"bg-gray-400"}`}),e.jsx("span",{className:"text-xs font-semibold text-gray-600 dark:text-gray-300 uppercase tracking-wider",children:u.isRunning?"Recording Time":u.isPaused?"Timer Paused":"Ready to Start"})]}),!t&&e.jsx(G,{onClick:()=>f(!1),variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-full hover:bg-gray-100 dark:hover:bg-gray-800",children:e.jsx(se,{className:"h-4 w-4"})})]})}),e.jsxs(le,{className:"pt-0 pb-6",children:[e.jsxs("div",{className:"text-center mb-5 space-y-1",children:[e.jsx("div",{className:"text-3xl font-mono font-bold text-gray-900 dark:text-white tracking-tight",children:S(u.elapsedTime)}),e.jsxs("div",{className:"text-sm text-gray-500 dark:text-gray-400 font-medium",children:[(u.elapsedTime/(1e3*60*60)).toFixed(3)," ","hours logged"]})]}),e.jsxs(be.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:"space-y-2",children:[e.jsx("div",{className:"flex gap-2",children:q?u.isRunning?e.jsxs(e.Fragment,{children:[e.jsxs(G,{onClick:m,variant:"outline",className:"flex-1 rounded-xl px-4 py-2 font-semibold hover:bg-gray-50 dark:hover:bg-gray-800 transition-all duration-200",size:"default",children:[e.jsx(Hr,{className:"h-4 w-4 mr-1"}),"Pause"]}),e.jsxs(G,{onClick:A,className:"flex-1 bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 text-white border-0 rounded-xl px-4 py-2 font-semibold shadow-lg transition-all duration-200",size:"default",children:[e.jsx(bs,{className:"h-4 w-4 mr-1"}),"Complete"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(G,{onClick:I,className:"flex-1 bg-gradient-to-r from-green-500 to-green-600 hover:from-green-600 hover:to-green-700 text-white border-0 rounded-xl px-4 py-2 font-semibold shadow-lg transition-all duration-200",size:"default",children:[e.jsx(ts,{className:"h-4 w-4 mr-1"}),"Resume"]}),e.jsxs(G,{onClick:A,className:"flex-1 bg-gradient-to-r from-red-500 to-red-600 hover:from-red-600 hover:to-red-700 text-white border-0 rounded-xl px-4 py-2 font-semibold shadow-lg transition-all duration-200",size:"default",children:[e.jsx(bs,{className:"h-4 w-4 mr-1"}),"Complete"]})]}):e.jsxs(G,{onClick:O,className:"flex-1 bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white border-0 rounded-xl px-4 py-2 font-semibold shadow-lg transition-all duration-200",size:"default",children:[e.jsx(ts,{className:"h-4 w-4 mr-1"}),"Start Timer"]})}),q&&e.jsxs(G,{onClick:L,variant:"ghost",className:"w-full text-xs rounded-xl py-1.5 hover:bg-gray-50 dark:hover:bg-gray-800 transition-all duration-200",size:"sm",children:[e.jsx(Ia,{className:"h-3 w-3 mr-1"}),"Reset Timer"]})]})]})]})})}),F?e.jsx(oe,{open:l,onOpenChange:n,title:E,swipeToDismiss:!H.isPending,children:D}):e.jsx(ve,{open:l,onOpenChange:n,children:e.jsxs(De,{className:"max-w-2xl",children:[e.jsxs(Ae,{children:[e.jsxs(Fe,{className:"flex items-center",children:[e.jsx(ge,{className:"h-5 w-5 mr-2"}),E]}),e.jsx(_t,{children:"Fill out the details for your timed work session and save it to your activity ledger."})]}),D]})})]})}function Ke(t){return t.toFixed(1).replace(/\.0$/,"")}function oi({percent:t}){const s=2*Math.PI*36,r=Math.max(0,Math.min(t,100)),i=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:i,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 di({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(oi,{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:Ke(s.totalHours)}),e.jsxs("span",{className:"ml-1 text-sm text-gray-500 dark:text-gray-400",children:["/ ",Ke(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:z("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:[Ke(s.materialHours??0)," / ",Ke(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:[Ke(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:[Ke(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(ja,{hideFloatingWidget:!0,completionSurface:"mobile-sheet",onSubmissionSuccess:()=>a(!1)})})]})})}function Fs({value:t,onChange:a}){const[s,r]=d.useState(!1),i=t?new Date(`${t}T00:00:00`):void 0;return e.jsxs(Nt,{open:s,onOpenChange:r,children:[e.jsx(wt,{asChild:!0,children:e.jsxs("button",{type:"button",className:z("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:i?Y(i,"MMM d, yyyy"):"Pick a date"}),e.jsx(pe,{className:"ml-auto h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(kt,{className:"w-auto p-0",align:"start",children:e.jsx(Ot,{mode:"single",selected:i,onSelect:l=>{l&&a(Y(l,"yyyy-MM-dd")),r(!1)},initialFocus:!0})})]})}function Is(t){var i,l,n;const a=t.hasLedgerEntry??((i=t.extendedProps)==null?void 0:i.hasLedgerEntry),s=t.approvalStatus??((l=t.extendedProps)==null?void 0:l.approvalStatus);if(a&&s==="approved")return"approved";const r=t.aiConfidence??((n=t.extendedProps)==null?void 0:n.aiConfidence)??0;return r>=90?"approved":r>=50?"pending":"available"}function ci(t){switch(t){case"approved":return"bg-green-500";
31case"pending":return"bg-amber-500";case"available":return"bg-blue-500"}}function Rs(t,a){const s=new Date(t),r=Y(s,"h:mm a");return a?`${r} - ${Y(new Date(a),"h:mm a")}`:r}function mi(t,a,s){const r=Ws(t),i=Js(t),l=is(r,{weekStartsOn:0}),n=Xs(i,{weekStartsOn:0});return Xr({start:l,end:n}).map(o=>({date:ys(o,t)?o:null,isCurrentMonth:ys(o,t),isSelected:Zs(o,a),isToday:_a(o),hasEvents:s.has(Y(o,"yyyy-MM-dd"))}))}function xi({events:t=[],isLoading:a=!1,isSyncing:s=!1,error:r=null,onEventClick:i,onRefresh:l,onSync:n,onVisibleRangeChange:o,onOpenCalendarList:x,onOpenAutomationSettings:p}){const[b,u]=d.useState(()=>new Date),[y,N]=d.useState(()=>new Date),[f,c]=d.useState(!1),[P,h]=d.useState(!1),[C,v]=d.useState(()=>new Date().getFullYear()),[S,O]=d.useState(""),[m,I]=d.useState(""),A=S&&m&&new Date(S)>new Date(m),L=()=>u(k=>Ks(k,1)),H=()=>u(k=>Zr(k)),$=()=>{const k=new Date;u(k),N(k)},_=k=>{const R=new Date(C,k,1);u(R),h(!1)};d.useEffect(()=>{if(o){const k=Ws(b),R=Js(b),U=is(k,{weekStartsOn:0}),V=Xs(R,{weekStartsOn:0});o({start:U,end:V})}},[b,o]);const q=d.useMemo(()=>{if(A||!S&&!m)return t;let k=t;if(S){const R=new Date(S);R.setHours(0,0,0,0),k=k.filter(U=>new Date(U.start)>=R)}if(m){const R=new Date(m);R.setHours(23,59,59,999),k=k.filter(U=>new Date(U.start)<=R)}return k},[t,S,m,A]),F=d.useMemo(()=>{const k=new Set;for(const R of q)k.add(Y(new Date(R.start),"yyyy-MM-dd"));return k},[q]),T=d.useMemo(()=>mi(b,y,F),[b,y,F]),E=d.useMemo(()=>q.filter(k=>Zs(new Date(k.start),y)),[q,y]),D=d.useMemo(()=>[...E].sort((k,R)=>new Date(k.start).getTime()-new Date(R.start).getTime()),[E]),g=d.useMemo(()=>E.filter(k=>Is(k)!=="approved").length,[E]),w=["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."}),l&&e.jsx("button",{type:"button",onClick:l,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((k,R)=>e.jsx("div",{className:z("h-11 border-r border-b border-gray-200 bg-gray-50 dark:bg-gray-800",R<7&&"border-t",R%7===0&&"border-l")},R))})}),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:$,className:z("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:H,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(Xe,{className:"h-4 w-4"})}),e.jsx("div",{className:"h-5 w-px bg-gray-200"}),e.jsx("button",{type:"button",onClick:L,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(re,{className:"h-4 w-4"})})]}),e.jsx("button",{type:"button",onClick:()=>{c(!f),h(!1)},className:z("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(ba,{className:"h-4 w-4"})}),e.jsxs("button",{type:"button",onClick:()=>{v(b.getFullYear()),h(!P),c(!1)},className:z("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: ${Y(b,"MMMM yyyy")}. Tap to change month.`,children:[e.jsx("span",{className:"text-xs font-semibold truncate",children:Y(b,"MMMM yyyy")}),e.jsx(ea,{className:"h-3.5 w-3.5 ml-1 flex-shrink-0 text-gray-500"})]})]}),f&&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(Fs,{value:S,onChange:O})]}),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(Fs,{value:m,onChange:I})]})]}),A&&e.jsx("p",{className:"mt-1 px-1 text-[10px] text-red-500",children:"From must be before To."}),(S||m)&&e.jsx("button",{type:"button",onClick:()=>{O(""),I("")},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"}),x&&e.jsxs("button",{type:"button",onClick:()=>{c(!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:"Calendars"}),e.jsx(re,{className:"h-3.5 w-3.5 text-gray-400"})]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),p&&e.jsxs("button",{type:"button",onClick:()=>{c(!1),p()},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(re,{className:"h-3.5 w-3.5 text-gray-400"})]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),n&&e.jsxs("button",{type:"button",onClick:()=>{c(!1),n()},disabled:s,className:z("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(Ze,{className:z("h-3.5 w-3.5",
31s&&"animate-spin")}),s?"Syncing...":"Sync Calendar"]})]}),P&&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:()=>v(k=>k-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(Xe,{className:"h-4 w-4"})}),e.jsx("span",{className:"text-sm font-bold text-gray-900",children:C}),e.jsx("button",{type:"button",onClick:()=>v(k=>k+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(re,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:M.map((k,R)=>e.jsx("button",{type:"button",onClick:()=>_(R),className:z("rounded-lg py-2 text-xs font-semibold transition",R===b.getMonth()&&C===b.getFullYear()?"bg-green-500 text-white":"text-gray-700 hover:bg-gray-100"),children:k},k))})]}),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:w.map((k,R)=>e.jsx("div",{className:z("flex items-center justify-center h-[34px] text-[11px] font-bold uppercase tracking-wide",R===0||R===6?"text-green-600":"text-gray-500"),children:k},k))}),e.jsx("div",{className:"grid grid-cols-7",children:T.map((k,R)=>k.date===null?e.jsx("div",{className:z("h-11 border-r border-b border-gray-200",R<7&&"border-t",R%7===0&&"border-l")},`blank-${R}`):e.jsx("button",{type:"button",onClick:()=>N(k.date),className:z("relative flex items-center justify-center h-11 transition","border-r border-b border-gray-200",R<7&&"border-t",R%7===0&&"border-l","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary",k.isSelected&&"bg-green-50",k.isToday&&!k.isSelected&&"ring-2 ring-green-500 ring-inset"),"aria-label":Y(k.date,"EEEE, MMMM d, yyyy"),"aria-selected":k.isSelected,children:k.isSelected?e.jsxs("div",{className:"flex flex-col items-center justify-center",children:[e.jsx("span",{className:z("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:Y(k.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:z("text-sm font-semibold leading-none","text-gray-900"),children:Y(k.date,"d")}),k.hasEvents&&e.jsx("span",{"data-testid":"event-dot",className:"mt-0.5 h-1 w-1 rounded-full bg-green-500"})]})},k.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:Y(y,"d")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:Y(y,"EEEE, MMMM d, yyyy")}),D.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:g>0?`${g} date${g!==1?"s":""} available to convert`:"All events approved"})]}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[D.length," event",D.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(Ur,{className:"h-6 w-6 text-green-500"}),e.jsx(ns,{className:"h-3 w-3 text-green-400 absolute -top-0.5 -right-0.5"})]})]})}),D.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:D.map(k=>{var U,V;const R=Is(k);return e.jsxs("button",{type:"button",onClick:()=>i==null?void 0:i(k),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":`${k.title} - ${Rs(k.start,k.end)}`,children:[e.jsx("span",{className:z("mt-0.5 h-2.5 w-2.5 flex-shrink-0 self-start rounded-full",ci(R))}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-bold text-gray-900",children:k.title||"Untitled Event"}),e.jsx("span",{className:"block truncate text-xs font-medium text-gray-500",children:Rs(k.start,k.end)}),(k.source||k.location)&&e.jsx("span",{className:"mt-0.5 block truncate text-[10px] font-medium text-gray-400",children:[((U=k.source)==null?void 0:U.charAt(0).toUpperCase())+((V=k.source)==null?void 0:V.slice(1)),k.location].filter(Boolean).join(" · ")})]}),e.jsx(re,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})]},k.id)})})]})})}function ui({open:t,onOpenChange:a,calendars:s=[],selectedCalendarIds:r=[],showAllCalendars:i=!0,onToggleCalendar:l,onToggleAll:n,isLoading:o=!1}){const x=i||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(ut,{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:n,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:x?e.jsx(ht,{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(p=>{const b=i||r.includes(p.id);return e.jsx("button",{type:"button",onClick:()=>l(p.id),className:z("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:b?e.jsx(ht,{className:"h-4 w-4 text-blue-500"}):e.jsx("div",{className:"h-4 w-4 rounded-sm border-2 border-gray-300"})}),p.backgroundColor&&e.jsx("div",{className:"h-3.5 w-3.5 flex-shrink-0 rounded-full border border-gray-200",style:{backgroundColor:p.backgroundColor}}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-gray-900",children:p.name}),p.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"})]})]})},p.id)})]}),!o&&s.length>0&&!i&&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 hi({open:t,onOpenChange:a}){const{calendarAutomation:s,setCalendarAutomation:r,calendarMutation:i,addTrustedOrganizer:l}=xs(),{suggestions:n,isLoading:o}=pa("calendar",!0),[x,p]=d.useState(""),[b,u]=d.useState(""),y=n.filter(C=>!s.trustedOrganizers.includes(C.email)),N=d.useCallback(()=>{const C=x.trim();C&&(l(C),p(""))},[x,l]),f=d.useCallback(C=>{const v=s.trustedOrganizers.filter(S=>S!==C);r({...s,trustedOrganizers:v}),i.mutate({...s,trustedOrganizers:v,type:"calendar"})},[s,r,i]),c=d.useCallback(()=>{const C=b.trim().toLowerCase();if(C){if(!s.trustedKeywords.includes(C)){const v=[...s.trustedKeywords,C];r({...s,trustedKeywords:v}),i.mutate({...s,trustedKeywords:v,type:"calendar"})}u("")}},[b,s,r,i]),P=d.useCallback(C=>{const v=s.trustedKeywords.filter(S=>S!==C);r({...s,trustedKeywords:v}),i.mutate({...s,trustedKeywords:v,type:"calendar"})},[s,r,i]),h=d.useCallback(C=>{l(C)},[l]);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(et,{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 C=!s.autoApproveHighConfidence;r({...s,autoApproveHighConfidence:C}),i.mutate({...s,autoApproveHighConfidence:C,type:"calendar"})},className:z("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:z("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(Ht,{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 C=!s.enabled;r({...s,enabled:C}),i.mutate({...s,enabled:C,type:"calendar"})},className:z("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:z("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(C=>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:C}),e.jsx("button",{type:"button",onClick:()=>f(C),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${C}`,children:e.jsx(se,{className:"h-3 w-3"})})]},C))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"email",placeholder:"[email protected]",value:x,onChange:C=>p(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),N())},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:N,disabled:!x.trim(),className:z("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",x.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(Ee,{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(C=>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:C}),e.jsx("button",{type:"button",onClick:()=>P(C),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${C}`,children:e.jsx(se,{className:"h-3 w-3"})})]},C))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"inspection, showing, ...",value:b,onChange:C=>u(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),c())},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:c,disabled:!b.trim(),className:z("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",b.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(Ee,{className:"h-3.5 w-3.5"})})]})]}),y.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&&y.map(C=>e.jsx("button",{type:"button",onClick:()=>h(C.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:C.email},C.email))]})]})]})]})]})})}function pi({open:t,onOpenChange:a,selectedEvent:s,reviewFormData:r,setReviewFormData:i,evidenceFiles:l,setEvidenceFiles:n,newEvidenceFiles:o,setNewEvidenceFiles:x,properties:p,syncEventMutation:b,approveTimeEntryMutation:u,updateTimeEntryMutation:y,processEvidenceFile:N,getEventStatus:f}){const c=s?f(s):"available",P=c==="available"?"Review Calendar Event":c==="pending"?"Pending Time Entry":"Approved Time Entry";return e.jsx(oe,{open:t,onOpenChange:a,title:P,children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c==="available"&&e.jsx(Z,{className:"bg-blue-500 text-white",children:"Available to Convert"}),c==="pending"&&e.jsx(Z,{className:"bg-amber-500 text-white",children:"Pending Approval"}),c==="approved"&&e.jsx(Z,{className:"bg-green-500 text-white",children:"Approved"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{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:h=>i(C=>({...C,title:h.target.value})),className:"text-sm text-gray-700 dark:text-gray-300",disabled:c==="pending"})]}),e.jsx(Mr,{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(ns,{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(ht,{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(ge,{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(rt,{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(B,{className:"text-base font-medium text-gray-900 dark:text-gray-100",children:"Description"}),e.jsx(Lt,{placeholder:"Add additional details about this event...",value:r.description,onChange:h=>{i(C=>({...C,description:h.target.value})),h.target.style.height="auto",h.target.style.height=h.target.scrollHeight+"px"},ref:h=>{h&&r.description&&(h.style.height="auto",h.style.height=h.scrollHeight+"px")},className:"resize-none overflow-hidden text-sm text-gray-700 dark:text-gray-300",style:{minHeight:"100px"}})]}),e.jsx(ya,{evidenceFiles:l,setEvidenceFiles:n,newEvidenceFiles:o,setNewEvidenceFiles:x}),e.jsx(va,{reviewFormData:r,setReviewFormData:i,properties:p}),e.jsx(Er,{eventStatus:c,selectedEvent:s,reviewFormData:r,evidenceFiles:l,setShowEventDialog:a,syncEventMutation:b,approveTimeEntryMutation:u,updateTimeEntryMutation:y,newEvidenceFiles:o})]})})}function gi(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 fi({open:t,onOpenChange:a}){const s=fa(),{calendarEvents:r,isLoading:i,isFetching:l,error:n,properties:o,showSyncDialog:x,setShowSyncDialog:p,handleRefresh:b,handleConfirmSync:u,reviewFormData:y,setReviewFormData:N,evidenceFiles:f,setEvidenceFiles:c,newEvidence
31Files:P,setNewEvidenceFiles:h,processEvidenceFile:C,getEventStatus:v,syncEventMutation:S,updateTimeEntryMutation:O,approveTimeEntryMutation:m,setDateRange:I,availableCalendars:A,calendarsLoading:L,showAllCalendars:H,selectedCalendarIds:$,handleToggleCalendar:_,handleToggleAllCalendars:q}=s,F=l||i,[T,E]=d.useState(!1),[D,g]=d.useState(null),w=d.useCallback(X=>{if(!X)return;const Ne=gi(X);g(Ne),N({title:X.title||"",description:X.description||"",activityType:"Property Management",propertyId:null,materialParticipation:!0,isQualifiedNonMaterial:!1,category:"real-estate"}),E(!0)},[N]),M=d.useCallback(X=>{E(X),X||g(null)},[]),k=d.useCallback(()=>{E(!1),g(null)},[]);d.useEffect(()=>{S.isSuccess&&k()},[S.isSuccess,k]),d.useEffect(()=>{m.isSuccess&&k()},[m.isSuccess,k]),d.useEffect(()=>{O.isSuccess&&k()},[O.isSuccess,k]);const R=d.useCallback(X=>{I({start:X.start,end:X.end})},[I]),[U,V]=d.useState(!1),K=d.useCallback(()=>{V(!0)},[]),ee=d.useCallback(X=>{V(X)},[]),[W,xe]=d.useState(!1),Ie=d.useCallback(()=>{xe(!0)},[]),de=d.useCallback(X=>{xe(X)},[]),je=T&&D!==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(xi,{events:r,isLoading:i&&r.length===0,isSyncing:F,error:n,onEventClick:w,onRefresh:b,onSync:b,onVisibleRangeChange:R,onOpenCalendarList:K,onOpenAutomationSettings:Ie})})}),e.jsx(ui,{open:U,onOpenChange:ee,calendars:A,selectedCalendarIds:$,showAllCalendars:H,onToggleCalendar:_,onToggleAll:q,isLoading:L}),e.jsx(hi,{open:W,onOpenChange:de}),e.jsx(Pr,{open:x,onOpenChange:p,onConfirm:u,isLoading:F}),e.jsx(pi,{open:je,onOpenChange:M,selectedEvent:D,reviewFormData:y??{title:"",description:"",activityType:"Property Management",propertyId:null,materialParticipation:!0,isQualifiedNonMaterial:!1,category:"real-estate"},setReviewFormData:N,evidenceFiles:f,setEvidenceFiles:c,newEvidenceFiles:P,setNewEvidenceFiles:h,properties:o,syncEventMutation:S,approveTimeEntryMutation:m,updateTimeEntryMutation:O,processEvidenceFile:C,getEventStatus:v})]})}function Ls({value:t,onChange:a}){const[s,r]=d.useState(!1),i=t?new Date(`${t}T00:00:00`):void 0;return e.jsxs(Nt,{open:s,onOpenChange:r,children:[e.jsx(wt,{asChild:!0,children:e.jsxs("button",{type:"button",className:z("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:i?Y(i,"MMM d, yyyy"):"Pick a date"}),e.jsx(pe,{className:"ml-auto h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(kt,{className:"w-auto p-0",align:"start",children:e.jsx(Ot,{mode:"single",selected:i,onSelect:l=>{l&&a(Y(l,"yyyy-MM-dd")),r(!1)},initialFocus:!0})})]})}function Na(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 bi(t){switch(t){case"approved":return"Approved";case"pending":return"Pending";case"available":return"Available"}}function yi(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 vi(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 ji(t){if(!t)return"";const a=new Date,s=new Date(t),r=a.getTime()-s.getTime(),i=Math.floor(r/864e5);return i<1?s.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):i===1?"Yesterday":i<7?s.toLocaleDateString("en-US",{weekday:"long"}):s.toLocaleDateString("en-US",{month:"short",day:"numeric"})}function Ni(t){return t.length?t[0].split("@")[0].replace(/[._-]/g," ").replace(/\b\w/g,s=>s.toUpperCase()):""}function wi(t){const a=t.trim().split(/\s+/);return a.length>=1&&a[0].length>0?a[0][0].toUpperCase():"?"}function ki(t){return Na(t)==="available"}const Ue=10,Ci=[{key:"all",label:"All"},{key:"approved",label:"Approved"},{key:"pending",label:"Pending"},{key:"available",label:"Available"}];function Si({threads:t=[],isLoading:a=!1,isSyncing:s=!1,error:r=null,activeFilter:i="all",statusCounts:l={},searchQuery:n="",connectedProvider:o,onThreadClick:x,onRefresh:p,onSync:b,onFilterChange:u,onSearchChange:y,onClose:N,onOpenMailAutomationSettings:f}
31){const[c,P]=d.useState(!1),[h,C]=d.useState(""),[v,S]=d.useState(""),O=h&&v&&new Date(h)>new Date(v),[m,I]=d.useState(1),A=d.useMemo(()=>{if(O||!h&&!v)return t;let T=t;if(h){const E=new Date(h);E.setHours(0,0,0,0),T=T.filter(D=>D.lastMessageDate&&new Date(D.lastMessageDate)>=E)}if(v){const E=new Date(v);E.setHours(23,59,59,999),T=T.filter(D=>D.lastMessageDate&&new Date(D.lastMessageDate)<=E)}return T},[t,h,v,O]),L=Math.max(1,Math.ceil(A.length/Ue)),H=d.useMemo(()=>{const T=(m-1)*Ue;return A.slice(T,T+Ue)},[A,m]),$=A.length>0?(m-1)*Ue+1:0,_=Math.min(m*Ue,A.length),q=()=>I(T=>Math.min(L,T+1)),F=()=>I(T=>Math.max(1,T-1));return d.useMemo(()=>A.length,[A]),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."}),p&&e.jsx("button",{type:"button",onClick:p,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]})]})]}),N&&e.jsx("button",{type:"button",onClick:N,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(ta,{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:n,onChange:T=>y==null?void 0:y(T.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:()=>P(!c),className:z("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(ba,{className:"h-4 w-4"})})]}),c&&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(Ls,{value:h,onChange:T=>{C(T),I(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(Ls,{value:v,onChange:T=>{S(T),I(1)}})]})]}),O&&e.jsx("p",{className:"mt-1 px-1 text-[10px] text-red-500",children:"From must be before To."}),(h||v)&&e.jsx("button",{type:"button",onClick:()=>{C(""),S(""),I(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"}),b&&e.jsxs("button",{type:"button",onClick:()=>{P(!1),b()},disabled:s,className:z("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(Ze,{className:z("h-3.5 w-3.5",s&&"animate-spin")}),s?"Syncing...":"Sync"]}),e.jsx("div",{className:"my-2 h-px bg-gray-100"}),f&&e.jsxs("button",{type:"button",onClick:()=>{P(!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:"Mail Automation Settings"}),e.jsx(re,{className:"h-3.5 w-3.5 text-gray-400"})]})]}),e.jsx("div",{className:"mt-3 flex gap-2 overflow-x-auto scrollbar-hide flex-shrink-0",children:Ci.map(({key:T,label:E})=>{const D=l[T]??0,g=i===T;let w;return T==="approved"?w="bg-green-500":T==="pending"?w="bg-amber-500":T==="available"?w="bg-blue-500":w="bg-green-500",e.jsxs("button",{type:"button",onClick:()=>{u==null||u(T),I(1)},className:z("flex h-9 flex-shrink-0 items-center gap-1.5 rounded-full border px-3 text-sm font-semibold transition",g?"border-green-500 bg-green-50 text-green-600":"border-gray-200 bg-white text-gray-900 hover:bg-gray-50"),children:[E,e.jsx("span",{className:z("flex h-5 min-w-[20px] items-center justify-center rounded-full px-1.5 text-xs font-bold text-white",w),children:D})]},T)})}),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((T,E)=>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"})]})]})},E))}):A.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(ut,{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(_e,{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."}),p&&e.jsxs("button",{type:"button",onClick:p,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(Ze,{className:z("h-3.5 w-3.5",
31s&&"animate-spin")}),"Refresh"]})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-3 space-y-2",children:H.map(T=>{const E=Na(T),D=Ni(T.participants)||T.subject||"Unknown",g=wi(D),w=T.participants.length>0;return e.jsx("div",{className:"rounded-2xl border border-gray-200 bg-white",children:e.jsxs("button",{type:"button",onClick:()=>x==null?void 0:x(T),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:[w?e.jsx("div",{className:z("flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full text-sm font-bold",vi(T.source)),children:g}):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(us,{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:D}),e.jsx("span",{className:"flex-shrink-0 text-xs text-gray-400",children:ji(T.lastMessageDate)})]}),e.jsx("p",{className:"mt-0.5 truncate text-sm font-semibold text-gray-900",children:T.subject||"(No subject)"}),T.snippet&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-xs leading-snug text-gray-500",children:T.snippet}),e.jsxs("span",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:z("inline-flex rounded-full px-2.5 py-1 text-xs font-semibold",yi(E)),children:bi(E)}),E==="approved"&&T.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(Le,{className:"h-3 w-3"}),"pending review"]}),ki(T)&&e.jsx("span",{onClick:M=>{M.stopPropagation(),x==null||x(T)},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"})]})]})]})},T.id)})}),A.length>Ue&&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 ",$," to ",_," of ",A.length," entries"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:F,disabled:m<=1,className:z("flex h-7 w-7 items-center justify-center rounded-md border transition",m<=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(Xe,{className:"h-3.5 w-3.5"})}),e.jsxs("span",{className:"font-medium text-gray-700",children:["Page ",m," of ",L]}),e.jsx("button",{type:"button",onClick:q,disabled:m>=L,className:z("flex h-7 w-7 items-center justify-center rounded-md border transition",m>=L?"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(re,{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(_e,{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:T=>T.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(re,{className:"h-3.5 w-3.5"})]})]})]})]})}function Ti({open:t,onOpenChange:a}){const{emailAutomation:s,setEmailAutomation:r,emailMutation:i,addTrustedContact:l}=xs(),[n,o]=d.useState(""),[x,p]=d.useState(""),b=d.useCallback(()=>{const f=n.trim();f&&(l(f),o(""))},[n,l]),u=d.useCallback(f=>{const c=s.trustedContacts.filter(P=>P!==f);r({...s,trustedContacts:c}),i.mutate({...s,trustedContacts:c,type:"email"})},[s,r,i]),y=d.useCallback(()=>{const f=x.trim().toLowerCase();if(f){if(!s.keywords.includes(f)){const c=[...s.keywords,f];r({...s,keywords:c}),i.mutate({...s,keywords:c,type:"email"})}p("")}},[x,s,r,i]),N=d.useCallback(f=>{const c=s.keywords.filter(P=>P!==f);r({...s,keywords:c}),i.mutate({...s,keywords:c,type:"email"})},[s,r,i]);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(et,{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 f=!s.autoApproveHighConfidence;r({...s,autoApproveHighConfidence:f}),i.mutate({...s,autoApproveHighConfidence:f,type:"email"})},className:z("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:z("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(Ht,{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 f=!s.enabled;r({...s,enabled:f}),i.mutate({...s,enabled:f,type:"email"})},className:z("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:z("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(f=>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:f}),e.jsx("button",{type:"button",onClick:()=>u(f),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${f}`,children:e.jsx(se,{className:"h-3 w-3"})})]},f))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"email",placeholder:"[email protected]",value:n,onChange:f=>o(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),b())},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:b,disabled:!n.trim(),className:z("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",n.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(Ee,{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(f=>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:f}),e.jsx("button",{type:"button",onClick:()=>N(f),className:"flex-shrink-0 text-gray-400 hover:text-gray-600","aria-label":`Remove ${f}`,children:e.jsx(se,{className:"h-3 w-3"})})]},f))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",placeholder:"inspection, showing, ...",value:x,onChange:f=>p(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),y())},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:y,disabled:!x.trim(),className:z("flex-shrink-0 rounded-lg px-3 py-2 text-xs font-semibold transition",x.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(Ee,{className:"h-3.5 w-3.5"})})]})]})]})]})]})})}function Mi({open:t,onOpenChange:a,selectedThread:s,reviewFormData:r,setReviewFormData:i,evidenceFiles:l,setEvidenceFiles:n,newEvidenceFiles:o,setNewEvidenceFiles:x,properties:p,convertThreadMutation:b,approveTimeEntryMutation:u,updateTimeEntryMutation:y,processEvidenceFile:N,getThreadStatus:f}){const c=s?f(s):"available",P=c==="available"?"Review Email Thread":c==="pending"?"Pending Time Entry":"Approved Time Entry";return e.jsx(oe,{open:t,onOpenChange:a,title:P,children:e.jsxs("div",{className:"space-y-5 px-4 pb-8",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c==="available"&&e.jsx(Z,{className:"bg-blue-500 text-white",children:"Available to Convert"}),c==="pending"&&e.jsx(Z,{className:"bg-amber-500 text-white",children:"Pending Approval"}),c==="approved"&&e.jsx(Z,{className:"bg-green-500 text-white",children:"Approved"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{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:h=>i(C=>({...C,title:h.target.value})),className:"text-sm text-gray-700",disabled:c==="pending"})]}),s&&e.jsx(Ar,{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(ns,{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(ht,{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(ge,{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(rt,{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(B,{className:"text-base font-medium text-gray-900",children:"Description"}),e.jsx(Lt,{placeholder:"Add additional details about this email thread...",value:r.description,onChange:h=>{i(C=>({...C,description:h.target.value})),h.target.style.height="auto",h.target.style.height=h.target.scrollHeight+"px"},ref:h=>{h&&r.description&&(h.style.height="auto",h.style.height=h.scrollHeight+"px")},className:"resize-none overflow-hidden text-sm text-gray-700",style:{minHeight:"100px"},disabled:c==="pending"})]}),e.jsx(ya,{evidenceFiles:l,setEvidenceFiles:n,newEvidenceFiles:o,setNewEvidenceFiles:x}),e.jsx(va,{reviewFormData:r,setReviewFormData:i,properties:p}),s&&e.jsx(Fr,{threadStatus:c,selectedThread:s,reviewFormData:r,evidenceFiles:l,newEvidenceFiles:o,setShowThreadDialog:a,c
31onvertThreadMutation:b,approveTimeEntryMutation:u,updateTimeEntryMutation:y})]})})}function Ei({open:t,onOpenChange:a}){const s=ga(),{threads:r,filteredThreads:i,isLoading:l,isRefetching:n,error:o,listFilter:x,setListFilter:p,searchQuery:b,setSearchQuery:u,statusCounts:y,handleRefresh:N,handleConfirmSync:f,handleThreadClick:c,showSyncDialog:P,setShowSyncDialog:h,showThreadDialog:C,setShowThreadDialog:v,selectedThread:S,reviewFormData:O,setReviewFormData:m,evidenceFiles:I,setEvidenceFiles:A,newEvidenceFiles:L,setNewEvidenceFiles:H,properties:$,convertThreadMutation:_,approveTimeEntryMutation:q,updateTimeEntryMutation:F,processEvidenceFile:T,getThreadStatus:E,gmailConnected:D,outlookConnected:g}=s,w=n||l,M=d.useMemo(()=>{if(D)return"Gmail";if(g)return"Outlook"},[D,g]);d.useEffect(()=>{(_.isSuccess||_.isError)&&v(!1)},[_.isSuccess,_.isError]),d.useEffect(()=>{(q.isSuccess||q.isError)&&v(!1)},[q.isSuccess,q.isError]),d.useEffect(()=>{(F.isSuccess||F.isError)&&v(!1)},[F.isSuccess,F.isError]);const[k,R]=d.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(oe,{open:t,onOpenChange:a,children:e.jsx(Si,{threads:i,isLoading:l&&r.length===0,isSyncing:w,error:o,activeFilter:x,statusCounts:y,searchQuery:b,connectedProvider:M,onThreadClick:c,onRefresh:N,onSync:()=>h(!0),onFilterChange:U=>p(U),onSearchChange:U=>u(U),onClose:()=>a(!1),onOpenMailAutomationSettings:()=>R(!0)})}),e.jsx(Ti,{open:k,onOpenChange:R}),e.jsx(Ir,{open:P,onOpenChange:h,onConfirm:f,isLoading:w}),e.jsx(Mi,{open:C,onOpenChange:v,selectedThread:S,reviewFormData:O,setReviewFormData:m,evidenceFiles:I,setEvidenceFiles:A,newEvidenceFiles:L,setNewEvidenceFiles:H,properties:$,convertThreadMutation:_,approveTimeEntryMutation:q,updateTimeEntryMutation:F,processEvidenceFile:T,getThreadStatus:E})]})}function Pi({open:t,onOpenChange:a}){var O,m,I,A,L,H,$,_,q,F,T;const[s,r]=d.useState(!1),{googleCalendarStatusQuery:i,imapStatusQuery:l,microsoftCalendarStatusQuery:n,microsoftMailStatusQuery:o,handleGoogleCalendarConnect:x,handleMicrosoftCalendarConnect:p,handleMicrosoftMailConnect:b,disconnectGoogleCalendarMutation:u,disconnectMicrosoftCalendarMutation:y,disconnectMicrosoftMailMutation:N,disconnectImapMutation:f,isGoogleCalendarConnecting:c,isMicrosoftCalendarConnecting:P,isMicrosoftMailConnecting:h,isImapConnecting:C}=bt(),v=((O=l.data)==null?void 0:O.accounts)??[],S=(m=v[0])==null?void 0:m.id;return e.jsx(oe,{open:t,onOpenChange:a,title:"Sync Settings",children:e.jsxs("div",{className:"px-4 pb-6",children:[e.jsxs(ls,{defaultValue:"google",children:[e.jsxs(os,{className:"mb-3 inline-flex w-full rounded-2xl bg-muted p-1",children:[e.jsx(pt,{value:"google",className:"flex-1 rounded-xl text-xs",children:"Google"}),e.jsx(pt,{value:"outlook",className:"flex-1 rounded-xl text-xs",children:"Outlook"})]}),e.jsxs(gt,{value:"google",className:"space-y-3",children:[e.jsx(Ct,{icon:e.jsx(pe,{className:"h-5 w-5"}),providerName:"Google Calendar",isConnected:!!((I=i.data)!=null&&I.connected),connectedLabel:((A=i.data)==null?void 0:A.email)??void 0,isConnecting:c,onConnect:x,onDisconnect:()=>u.mutate()}),e.jsx(Ct,{icon:e.jsx(_e,{className:"h-5 w-5"}),providerName:"Gmail IMAP",isConnected:!!((L=l.data)!=null&&L.connected),connectedLabel:((H=v[0])==null?void 0:H.email)??(($=v[0])==null?void 0:$.username)??void 0,isConnecting:C,onConnect:()=>r(!0),onDisconnect:S==null?void 0:()=>f.mutate(S)})]}),e.jsxs(gt,{value:"outlook",className:"space-y-3",children:[e.jsx(Ct,{icon:e.jsx(pe,{className:"h-5 w-5"}),providerName:"Outlook Calendar",isConnected:!!((_=n.data)!=null&&_.connected),connectedLabel:((q=o.data)==null?void 0:q.email)??void 0,isConnecting:P,onConnect:p,onDisconnect:()=>y.mutate()}),e.jsx(Ct,{icon:e.jsx(_e,{className:"h-5 w-5"}),providerName:"Outlook Mail",isConnected:!!((F=o.data)!=null&&F.connected),connectedLabel:((T=o.data)==null?void 0:T.email)??void 0,isConnecting:h,onConnect:b,onDisconnect:()=>N.mutate()})]})]}),e.jsx(Kr,{open:s,onOpenChange:r})]})})}function Di(){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 Ai({summary:t,state:a,onPreviousWeek:s,onNextWeek:r,onFullViewClick:i}){return a==="loading"?e.jsx(Di,{}):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"}),i&&e.jsx("button",{type:"button",onClick:i,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(Xe,{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(re,{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(l=>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:l.dayLabel}),e.jsx("span",{className:z("flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold",l.isSelected?"bg-primary text-primary-foreground shadow-sm":"text-gray-900 dark:text-white"),children:l.dayNumber}),e.jsx("span",{className:z("h-1.5 w-1.5 rounded-full",l.availableCount?"bg-primary":"bg-transparent")})]},l.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(re,{className:"h-4 w-4 text-gray-500 dark:text-gray-400","aria-hidden":"true"})]})]})]})]})}function Fi({pendingReviewCount:t,isSyncing:a=!1,syncError:s=!1,onFullViewClick:r}){const i=a?"Syncing...":s?"Sync failed":t>0?`Synced â ${t} pending`:"No emails pending",l=a,n=!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(_e,{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":n?`${t} ${t===1?"email":"emails"}`:"Mail"}),l&&e.jsx(Ze,{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:i})]}),e.jsx("span",{className:z("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":n?"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":n?"PENDING":"CLEAR"})]})]})}const Ii={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"},Ri={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 Li({item:t}){const a="h-5 w-5";return t.icon==="mail"?e.jsx(_e,{className:a}):t.icon==="calendar"?e.jsx(us,{className:a}):e.jsx(tt,{className:a})}function _i({item:t}){const a=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:z("flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl",Ri[t.status]),children:e.jsx(Li,{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:z("rounded-full px-3 py-1 text-[11px] font-bold",Ii[t.status]),children:t.badgeLabel}),t.onClick&&e.jsx(re,{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:z(r>0&&"border-t border-gray-100 dark:border-border"),children:e.jsx(_i,{item:s})},s.id))]})}function wa(){return e.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-x-4 gap-y-2 pb-3 text-center",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"})]})]})}function Rt(t){me("POST","/api/mobile/cta-clicked",t).catch(a=>{console.warn("Mobile CTA tracking failed:",a)})}const ps="https://play.google.com/store/apps/details?id=com.repsshield.app",qt="",ka=!!qt,Yt=4;function St(t){const a=t instanceof Date?t:new Date(t);return Number.isNaN(a.getTime())?"Date unavailable":Y(a,"MMM d, yyyy")}function Hi(){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 $i({pendingEntries:t=[],approvedEntries:a=[],discardedEntries:s=[],statusCounts:r,state:i,isMutating:l=!1,onApprove:n,onReject:o,onOpenDetails:x,onManageClick:p}
31){const[b,u]=d.useState("approved"),[y,N]=d.useState(1),f=[{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}],c=(()=>{switch(b){case"approved":return a;case"discarded":return s;case"all":return[...t.map(m=>({...m,_type:"pending"})),...a.map(m=>({...m,_type:"approved"})),...s.map(m=>({...m,_type:"discarded"}))];default:return t}})(),P=Math.ceil(c.length/Yt),h=Math.min(y,P||1),C=(h-1)*Yt,v=c.slice(C,C+Yt),S=m=>{u(m),N(1)},O=i==="success"||i==="empty";return i==="loading"?e.jsx(Hi,{}):e.jsxs("section",{className:"overflow-hidden rounded-2xl border border-gray-100 bg-white shadow-sm dark:border-border dark:bg-card",children:[O&&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"}),p&&e.jsx("button",{type:"button",onClick:p,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:f.map(m=>e.jsxs("button",{onClick:()=>S(m.value),className:`shrink-0 rounded-t-lg px-3 py-2 text-xs font-medium transition-colors whitespace-nowrap ${b===m.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:[m.label," (",m.count,")"]},m.value))})}),e.jsxs("div",{className:"p-3",children:[i==="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."}):c.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:b==="pending"?"No geo fence entries pending.":b==="approved"?"No approved entries yet.":b==="discarded"?"No discarded entries.":"No entries found."}),b==="pending"&&!sa()&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:ps,target:"_blank",rel:"noopener noreferrer",onClick:()=>Rt({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"})}),ka?e.jsx("a",{href:qt,target:"_blank",rel:"noopener noreferrer",onClick:()=>Rt({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."})]})]}):b==="discarded"?e.jsx("div",{className:"space-y-2",children:v.map(m=>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:()=>x==null?void 0:x(m.id),disabled:!x,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(xt,{user:{id:String(m.id),firstName:(m.propertyName||"Unknown").split(" ")[0]||void 0,lastName:(m.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:m.propertyName||"Unknown property"}),e.jsxs("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:[m.discardReason,m.enteredAt?` ⢠${St(m.enteredAt)}`:""]})]})]})},m.id))}):e.jsx("div",{className:"space-y-2",children:v.map(m=>
31{const I=m._type==="discarded"||m.discardReason,A=!I&&(m._type==="pending"||b==="pending");return I?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:()=>x==null?void 0:x(m.id),disabled:!x,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(xt,{user:{id:String(m.id),firstName:(m.propertyName||"Unknown").split(" ")[0]||void 0,lastName:(m.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:m.propertyName||"Unknown property"}),e.jsxs("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:[m.discardReason,m.enteredAt?` ⢠${St(m.enteredAt)}`:"",m.date&&!m.enteredAt?` ⢠${St(m.date)}`:""]})]})]})},m.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:()=>x==null?void 0:x(m.id),disabled:!x,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(xt,{user:{id:String(m.id),firstName:(m.visitorName||"").split(" ")[0]||void 0,lastName:(m.visitorName||"").split(" ").slice(1).join(" ")||void 0,profileImageUrl:m.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:m.visitorName||"Unknown visitor"}),e.jsxs("span",{className:"block truncate text-xs font-medium text-gray-500 dark:text-gray-400",children:[m.propertyName&&`${m.propertyName} ⢠`,St(m.date),m.hours!=null&&` ⢠${Number(m.hours).toFixed(1)} hrs`]})]})]}),A&&e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>n(m.id),disabled:l,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(ht,{className:"h-5 w-5"})}),e.jsx("button",{type:"button",onClick:()=>o(m.id),disabled:l,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"})})]})]},m.id)})}),P>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:()=>N(m=>Math.max(1,m-1)),disabled:h<=1,className:"flex items-center gap-1 text-xs font-medium text-gray-600 disabled:opacity-30 dark:text-gray-400",children:[e.jsx(Xe,{className:"h-3.5 w-3.5"})," Previous"]}),e.jsxs("span",{className:"text-xs text-gray-400",children:[h," of ",P]}),e.jsxs("button",{onClick:()=>N(m=>Math.min(P,m+1)),disabled:h>=P,className:"flex items-center gap-1 text-xs font-medium text-gray-600 disabled:opacity-30 dark:text-gray-400",children:["Next ",e.jsx(re,{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(wa,{})})]})]})}function qi({value:t,onChange:a}){const[s,r]=d.useState(!1),i=t?new Date(t+"T00:00:00"):new Date;return e.jsxs(Nt,{open:s,onOpenChange:r,children:[e.jsx(wt,{asChild:!0,children:e.jsxs("button",{type:"button",className:z("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?Y(i,"MMM d, yyyy"):"Pick a date",e.jsx(pe,{className:"ml-auto h-4 w-4 opacity-50 shrink-0"})]})}),e.jsx(kt,{className:"w-auto p-0",align:"start",children:e.jsx(Ot,{mode:"single",selected:i,onSelect:l=>{l&&a(Y(l,"yyyy-MM-dd")),r(!1)},initialFocus:!0})})]})}function _s({value:t,onChange:a}){const[s,r]=d.useState(!1),i=t?(()=>{const[l,n]=t.split(":").map(Number),o=l>=12?"PM":"AM";return`${l%12||12}:${String(n).padStart(2,"0")} ${o}`})():"";return e.jsxs(Nt,{open:s,onOpenChange:r,children:[e.jsx(wt,{asChild:!0,children:e.jsxs("button",{type:"button",className:z("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:[i||"Pick a time",e.jsx(ge,{className:"ml-auto h-4 w-4 opacity-50 shrink-0"})]})}),e.jsx(kt,{className:"w-auto p-0",align:"start",children:e.jsx("div",{className:"p-2",children:e.jsx("input",{type:"time",value:t,onChange:l=>{a(l.target.value),l.target.value&&r(!1)},className:z("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 Ca({entry:t,onSaveAndApprove:a,onSaveDraft:s,onReject:r,onCancel:i}
31){const[l,n]=d.useState(""),[o,x]=d.useState(""),[p,b]=d.useState(""),[u,y]=d.useState(""),[N,f]=d.useState(""),[c,P]=d.useState(""),[h,C]=d.useState(!1),[v,S]=d.useState(null);d.useEffect(()=>{if(t){const H=t.date instanceof Date?t.date:t.date?new Date(String(t.date)):null,$=H&&!isNaN(H.getTime())?Y(H,"yyyy-MM-dd"):"";n($),f(t.description||""),P(t.activityType||"property-visitation"),C(t.isMaterialParticipation??!1);const _=q=>{if(q instanceof Date)return q;if(typeof q=="string"||typeof q=="number"){const F=new Date(q);return isNaN(F.getTime())?null:F}return null};if(t.timeStarted&&t.timeEnded){const q=_(t.timeStarted),F=_(t.timeEnded);if(q&&F){x(Y(q,"HH:mm")),b(Y(F,"HH:mm"));const E=(F.getTime()-q.getTime())/(1e3*60*60);y(Math.max(0,E).toFixed(1))}}else{const q=Number(t.hours);if(!isNaN(q)&&q>0){y(q.toFixed(1));const F=t.date instanceof Date?new Date(t.date):new Date;F.setHours(9,0,0,0),x(Y(F,"HH:mm"));const T=new Date(F);T.setHours(T.getHours()+Math.floor(q)),T.setMinutes(T.getMinutes()+Math.round(q%1*60)),b(Y(T,"HH:mm"))}}}},[t]);const O=()=>{if(!o||!p)return!0;const[H,$]=o.split(":").map(Number),[_,q]=p.split(":").map(Number),F=H*60+$;return _*60+q<=F?(S("End time must be after start time"),!1):(S(null),!0)},m=()=>{if(!t)throw new Error("No entry");return{id:t.id,date:l,hours:parseFloat(u)||0,description:N,activityType:c,isMaterialParticipation:h,timeStarted:o||void 0,timeEnded:p||void 0}},I=()=>{O()&&a(m())},A=()=>{O()&&s(m())},L=()=>{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(aa,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),e.jsxs("div",{children:[e.jsx(B,{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(tt,{className:"h-4 w-4 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx(B,{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(B,{htmlFor:"date",children:"Date"}),e.jsx(qi,{value:l,onChange:n})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"hours",children:"Duration (hours)"}),e.jsx(ye,{id:"hours",type:"text",inputMode:"decimal",value:u,onChange:H=>{const $=H.target.value.replace(/[^0-9.]/g,"");y($)},placeholder:"0.0"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"startTime",children:"Start Time"}),e.jsx(_s,{value:o,onChange:x})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"endTime",children:"End Time"}),e.jsx(_s,{value:p,onChange:b})]})]}),v&&e.jsxs("div",{className:"flex items-center gap-2 text-red-600 text-sm",children:[e.jsx(ra,{className:"h-4 w-4"}),v]})]}),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(B,{htmlFor:"description",children:"Description"}),e.jsx(ye,{id:"description",value:N,onChange:H=>f(H.target.value),placeholder:"Describe the visit..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(B,{htmlFor:"activityType",children:"Category"}),e.jsxs(ke,{value:c,onValueChange:P,children:[e.jsx(Ce,{id:"activityType",children:e.jsx(Se,{placeholder:"Select category"})}),e.jsxs(Te,{children:[st.filter(H=>H.value!=="real-estate").map(H=>e.jsx(te,{value:H.value,children:H.label},H.value)),e.jsx(te,{value:"property-visitation",children:"Property Visitation"}),e.jsx(te,{value:"tenant-meeting",children:"Tenant Meeting"}),e.jsx(te,{value:"maintenance",children:"Maintenance"}),e.jsx(te,{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 dar
31k:bg-purple-900/20 rounded-md shrink-0",children:e.jsx(Dt,{className:"h-4 w-4 text-purple-600 dark:text-purple-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(B,{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(Me,{checked:h,onCheckedChange:C,className:"shrink-0 ml-2"})]}),h&&e.jsx(Z,{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(G,{variant:"outline",onClick:L,children:"Reject"}),e.jsx(G,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(G,{variant:"outline",onClick:A,children:"Save Draft"})]}),e.jsx(G,{onClick:I,className:"bg-green-600 hover:bg-green-700 text-white sm:flex-1",children:"Save & Approve"})]})]}):null}function zi({open:t,onOpenChange:a,entry:s,onSaveAndApprove:r,onSaveDraft:i,onReject:l}){return e.jsx(oe,{open:t,onOpenChange:a,title:"Review Detected Visit",children:e.jsx("div",{className:"px-4 pb-6",children:e.jsx(Ca,{entry:s,onSaveAndApprove:r,onSaveDraft:i,onReject:l,onCancel:()=>a(!1)})})})}function Gi({open:t,onOpenChange:a,settings:s,onUpdateSettings:r,isSaving:i=!1}){const l=(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(et,{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":l,"aria-label":"Enable geo fence automation",disabled:i,onClick:()=>r==null?void 0:r(!l),className:z("relative h-7 w-11 flex-shrink-0 rounded-full transition-colors",l?"bg-green-500":"bg-gray-300",i&&"opacity-60 cursor-not-allowed"),children:e.jsx("span",{className:z("absolute left-0.5 top-0.5 h-6 w-6 rounded-full bg-white shadow-sm transition-transform",l&&"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(et,{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 Vi({open:t,onOpenChange:a,entry:s}){const r=s!=null&&s.enteredAt?new Date(s.enteredAt):null,i=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:Y(r,"MMM d, h:mm a")})]}),i&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Exited:"}),e.jsx("p",{className:"mt-0.5",children:Y(i,"MMM d, h:mm a")})]})]})]})})}const Sa="mobile_reward_banner_dismissed";function Qi(t){try{return localStorage.getItem(`${Sa}:${t}`)==="1"}catch{return!1}}function Ki(t){try{localStorage.setItem(`${Sa}:${t}`,"1")}catch{}}function Ta({userId:t,isSubscribed:a,isOnTrial:s,mobileInstallCompleted:r}){const[i,l]=d.useState(!1),[n,o]=d.useState(()=>Qi(t)),x=a,p=s&&!a,b=!n&&!r&&(x||p),u=d.useCallback(async()=>{try{await me("POST","/api/mobile/cta-clicked",{platform:"android",source:"dashboard-banner"})}catch{}l(!0)},[]),y=d.useCallback(()=>{o(!0),Ki(t)},[t]),N=d.useCallback(f=>{try{me("POST","/api/mobile/cta-clicked",{platform:f,source:"dashboard-banner-modal"})}catch{}},[]);return b?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:p?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:u,className:"text-xs font-semibold text-emerald-700 hover:text-emerald-900 dark:text-emerald-300 dark:hover:text-emerald-200",children:p?"Details":"Get"}),e.jsx("button",{type:"button",onClick:y,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(ve,{open:i,onOpenChange:l,children:e.jsxs(De,{className:"sm:max-w-sm",children:[e.jsxs(Ae,{children:[e.jsxs(Fe,{className:"flex items-center gap-2 text-center",children:["ð± ",p?"How It Works":"Get the App"]}
31),e.jsx(_t,{className:"text-center",children:p?"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:ps,target:"_blank",rel:"noopener noreferrer",onClick:()=>N("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"]}),qt,e.jsx("p",{className:"text-center text-xs text-gray-400 dark:text-gray-500",children:p?"Free month applied after subscribing and logging into the mobile app.":"Free month applied after logging into the mobile app."})]})]})})]}):null}const zt="mobile_reward_granted_banner";function Ui(t){try{return localStorage.getItem(`${zt}_dismissed:${t}`)==="1"}catch{return!1}}function Yi(t){try{localStorage.setItem(`${zt}_dismissed:${t}`,"1")}catch{}}function Bi(t){try{return localStorage.getItem(`${zt}:${t}`)!==null}catch{return!1}}function Wi(t){try{localStorage.removeItem(`${zt}:${t}`)}catch{}}function Ma({userId:t,isSubscribed:a}){const[s,r]=d.useState(()=>Ui(t)),i=Bi(t),l=d.useCallback(()=>{r(!0),Yi(t),Wi(t)},[t]);return!i||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(Yr,{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:l,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 Ji(){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,i;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??((i=s.recordedBy)==null?void 0:i.profileImageUrl)??void 0}})}async function Xi(){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,i;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??((i=s.recordedBy)==null?void 0:i.profileImageUrl)??void 0}})}async function Zi(){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 en(t){if(!(await fetch("/api/geo-sync/save-and-approve",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)})).ok)throw new Error("Failed to save and approve entry")}async function tn(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 sn(){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 an(t){if(!(await fetch("/api/geo-sync/approve",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({id:t})})).ok)throw new Error("Failed to approve entry")}async function rn(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 nn(t){if(!(await fetch("/api/geo-sync/bulk-approve",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({ids:t})})).ok)throw new Error("Failed to bulk approve entries")}async function ln(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 Ea(){const t=Pe(),[a,s]=d.useState("approved"),{data:r=[],isLoading:i,error:l}=ne({queryKey:["/api/geo-sync/entries/pending"],queryFn:Ji,staleTime:0,refetchInterval:!1}),{data:n=[],isLoading:o,error:x}=ne({queryKey:["/api/geo-sync/entries/approved"],queryFn:Xi,staleTime:0,refetchInterval:!1}),{data:p=[],isLoading:b,error:u}=ne({queryKey:["/api/geo-sync/entries/discarded"],queryFn:Zi,staleTime:0,refetchInterval:!1}),y={pending:r.length,approved:n.length,discarded:p.length,all:r.length+n.length+p.length},N=a==="approved"?n:a==="discarded"?p:a==="all"?[...r,...n,...p]:r,f=a==="approved"?o:a==="discarded"?b:a==="all"?i||o||b:i,c=a==="approved"?x:a==="discarded"?u:a==="all"?l||x||u:l,{data:P}=ne({queryKey:["/api/geo-sync/settings"],queryFn:sn,staleTime:0}),h=ce({mutationFn:en,onMutate:async L=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const H=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],$=>($||[]).filter(_=>_.id!==L.id)),{previousEntries:H}},onError:(L,H,$)=>{$!=null&&$.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],$.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"]})}}),C=ce({mutationFn:({id:L})=>an(L),onMutate:async({id:L})=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const H=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],$=>($||[]).filter(_=>_.id!==L)),{previousEntries:H}},onError:(L,H,$)=>{$!=null&&$.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],$.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"]})}}),v=ce({mutationFn:({id:L})=>rn(L),onMutate:async({id:L})=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const H=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],$=>($||[]).filter(_=>_.id!==L)),{previousEntries:H}},onError:(L,H,$)=>{$!=null&&$.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],$.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"]})}}),S=ce({mutationFn:L=>nn(L),onMutate:async L=>{await t.cancelQueries({queryKey:["/api/geo-sync/entries/pending"]});const H=t.getQueryData(["/api/geo-sync/entries/pending"]);return t.setQueryData(["/api/geo-sync/entries/pending"],$=>($||[]).filter(_=>!L.includes(_.id))),{previousEntries:H}},onError:(L,H,$)=>{$!=null&&$.previousEntries&&t.setQueryData(["/api/geo-sync/entries/pending"],$.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:ln,onSuccess:L=>{t.setQueryData(["/api/geo-sync/settings"],L)}}),m=ce({mutationFn:tn,onSettled:()=>{t.invalidateQueries({queryKey:["/api/geo-sync/entries/pending"]})}}),I=h.isPending||m.isPending||C.isPending||v.isPending||S.isPending;return{entries:N,pendingEntries:r,approvedEntries:n,discardedEntries:p,listFilter:a,setListFilter:s,statusCounts:y,isLoading:f,error:c??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:P,saveAndApproveEntry:h,saveDraftEntry:m,approveEntry:C,rejectEntry:v,bulkApprove:S,updateSettings:O,isApproving:I}}function on(){const{statusCounts:t,isLoading:a,error:s}=fa();return{count:(t==null?void 0:t.available)??0,pendingCount:(t==null?void 0:t.pending)??0,isLoading:a,error:s??null}}function dn(t,a,s){return t?"loading":a?"error":s?"success":"empty"}function cn(t,a){const s=is(t,{weekStartsOn:0}),r=new Date;return{monthLabel:Y(t,"MMMM yyyy"),availableToConvertCount:a,days:Array.from({length:7},(i,l)=>{const n=Zt(s,l),o=Y(n,"yyyy-MM-dd")===Y(t,"yyyy-MM-dd"),x=Y(n,"yyyy-MM-dd")===Y(r,"yyyy-MM-dd");return{date:n,dayLabel:Y(n,"EEEEE"),dayNumber:Number(Y(n,"d")),isSelected:o,isToday:x,availableCount:o&&a>0?a:0}})}}function Os(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 mn({user:t,progress:a,pendingReviewCount:s,mailConnected:r,mailHasError:i,mailHasCredentialIssue:l=!1,isMailSyncing:n=!1,calendarConnected:o,calendarHasError:x,selectedYear:p,onYearChange:b,isSubscribed:u,isOnTrial:y}
31){const[,N]=cs(),[f,c]=d.useState(()=>new Date),[P,h]=d.useState(null),[C,v]=d.useState(!1),[S,O]=d.useState(null),[m,I]=d.useState(!1),[A,L]=d.useState(!1),[H,$]=d.useState(!1),[_,q]=d.useState(!1),[F,T]=d.useState(!1),[E,D]=d.useState(!1),{pendingEntries:g,approvedEntries:w,discardedEntries:M,statusCounts:k,isLoading:R,error:U,approveEntry:V,rejectEntry:K,saveAndApproveEntry:ee,saveDraftEntry:W,isApproving:xe,settings:Ie,updateSettings:de}=Ea(),je=d.useMemo(()=>g.filter(Q=>Q.approvalStatus==="pending").map(Os).filter(Q=>!!Q),[g]),X=d.useMemo(()=>w.map(Os).filter(Q=>!!Q),[w]),Ne=dn(R,!!U,g.length>0||w.length>0||M.length>0),{statusCounts:we,isRefetching:Oe}=ga(),He=(we==null?void 0:we.pending)??0,ae=on(),$e=ae.count,it=ae.pendingCount,qe=$e<=0?it:$e,nt=d.useMemo(()=>cn(f,qe),[f,qe]),ze=Q=>{N(Q),Ha(Q)},Ge=r&&l,j=[{id:"mail",label:"MAIL SYNC",subtitle:i?"Sync error...":Ge?"Credentials expired â reconnect":r?"Connected and ready":"Connect mail to sync",status:i?"error":Ge?"warning":r?"connected":"inactive",badgeLabel:i?"ERROR":Ge?"RECONNECT":r?"CONNECTED":"CONNECT",icon:"mail",onClick:()=>{Ge||!r?D(!0):T(!0)}},{id:"calendar",label:"CALENDAR SYNC",subtitle:ae.error?"Sync error...":o?"Connected and ready":"Connect calendar to sync",status:ae.error?"error":o?"connected":"inactive",badgeLabel:ae.error?"error":o?"CONNECTED":"CONNECT",icon:"calendar",onClick:()=>{o?q(!0):D(!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(ai,{user:t,notificationCount:s,onNotificationsClick:()=>ze("/activity-ledger"),onProfileClick:()=>ze("/settings"),selectedYear:p,onYearChange:b,repType:t.repType}),e.jsx(ri,{count:s,onClick:()=>ze("/activity-ledger")}),e.jsx(Ta,{userId:t.id,isSubscribed:u??(!!t.stripeSubscriptionId&&(t.subscriptionStatus==="active"||t.subscriptionStatus==="trialing")),isOnTrial:y,mobileInstallCompleted:t.mobileInstallCompleted}),e.jsx(Ma,{userId:t.id,isSubscribed:!!u}),e.jsxs("button",{type:"button",onClick:()=>ze("/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(Oa,{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(re,{className:"h-5 w-5 shrink-0 text-gray-400"})]}),e.jsx(li,{summary:a,onTimerClick:()=>$(!0),onDetailsClick:()=>$(!0)}),e.jsx(di,{open:H,onOpenChange:$,summary:a}),e.jsx(Ai,{summary:nt,state:x?"error":"success",onPreviousWeek:()=>c(Q=>Zt(Q,-7)),onNextWeek:()=>c(Q=>Zt(Q,7)),onFullViewClick:()=>q(!0)}),e.jsx(Fi,{pendingReviewCount:He,isSyncing:Oe,syncError:i,onFullViewClick:()=>T(!0)}),e.jsx(Oi,{items:j,onManageClick:()=>D(!0)}),e.jsx($i,{pendingEntries:je,approvedEntries:X,discardedEntries:M,statusCounts:k,state:Ne,isMutating:xe,onApprove:Q=>V.mutate({id:Q}),onReject:Q=>K.mutate({id:Q}),onOpenDetails:Q=>{const J=g.find(Re=>Re.id===Q)??w.find(Re=>Re.id===Q)??null,ie=M.find(Re=>Re.id===Q)??null;ie?(O(ie),I(!0)):(h(J),v(!!J))},onManageClick:()=>L(!0)}),e.jsx(Gi,{open:A,onOpenChange:L,settings:Ie,onUpdateSettings:Q=>de.mutate(Q),isSaving:de.isPending}),e.jsx(zi,{open:C,onOpenChange:v,entry:P,onSaveAndApprove:Q=>{ee.mutate(Q),v(!1)},onSaveDraft:Q=>{W.mutate(Q),v(!1)},onReject:Q=>{K.mutate({id:Q}),v(!1)}}),e.jsx(Vi,{open:m,onOpenChange:I,entry:S}),e.jsx(fi,{open:_,onOpenChange:q}),e.jsx(Ei,{open:F,onOpenChange:T}),e.jsx(Pi,{open:E,onOpenChange:D})]})})}async function xn(){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 un(){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 hn=()=>{d.useEffect(()=>{const t=()=>setTimeout(()=>{ia(()=>import("./analytics-JOA_m9vc.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).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)}},[])},pn=()=>{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");
31return a.rel="preconnect",a.href=window.location.origin,document.head.appendChild(a),()=>{document.head.removeChild(t),document.head.removeChild(a)}},[])};function gn({url:t,enabled:a=!0,delayMs:s=1500,onMessage:r,onConnect:i,onDisconnect:l,onError:n}){const[o,x]=d.useState(!1),[p,b]=d.useState("idle"),u=d.useRef(null),y=d.useRef(),N=d.useRef(),f=d.useRef(0),c=()=>{var C,v;if(!(!a||((C=u.current)==null?void 0:C.readyState)===WebSocket.CONNECTING||((v=u.current)==null?void 0:v.readyState)===WebSocket.OPEN)){b("connecting");try{try{u.current=new WebSocket(t)}catch(S){console.error("[WebSocket] Failed to create WebSocket connection:",S),b("disconnected"),n==null||n(S);return}u.current.onopen=()=>{x(!0),b("connected"),f.current=0,i==null||i()},u.current.onmessage=S=>{try{const O=JSON.parse(S.data);r==null||r(O)}catch(O){console.warn("[WebSocket] Failed to parse message:",O)}},u.current.onclose=()=>{if(x(!1),b("disconnected"),l==null||l(),a&&f.current<5){const S=Math.min(1e3*Math.pow(2,f.current),3e4);y.current=setTimeout(()=>{f.current++,c()},S)}},u.current.onerror=S=>{console.warn("[WebSocket] Connection error:",S),n==null||n(S)}}catch(S){console.error("[WebSocket] Failed to create connection:",S),b("disconnected")}}},P=()=>{y.current&&clearTimeout(y.current),N.current&&clearTimeout(N.current),u.current&&(u.current.close(),u.current=null),x(!1),b("disconnected")},h=C=>{var v;((v=u.current)==null?void 0:v.readyState)===WebSocket.OPEN?u.current.send(JSON.stringify(C)):console.warn("[WebSocket] Cannot send message - connection not open")};return d.useEffect(()=>{if(!a){P();return}if(["/features","/pricing","/why-reps-shield","/about"].includes(window.location.pathname)||window.location.pathname.startsWith("/features/"))return;const v=()=>{if(document.visibilityState==="visible"&&document.querySelector('[data-testid="dashboard-content"], .min-h-screen'))N.current=setTimeout(c,s);else{const O=()=>{document.visibilityState==="visible"&&document.querySelector('[data-testid="dashboard-content"], .min-h-screen')?N.current=setTimeout(c,s):setTimeout(O,100)};O()}};v();const S=()=>{document.visibilityState==="hidden"?P():document.visibilityState==="visible"&&a&&v()};return document.addEventListener("visibilitychange",S),()=>{document.removeEventListener("visibilitychange",S),P()}},[a,t,s]),{isConnected:o,connectionState:p,sendMessage:h,connect:c,disconnect:P}}function fn(){const{user:t,isLoading:a}=$t(),{toast:s}=fe(),[r,i]=d.useState(!1);return d.useEffect(()=>(document.body.classList.add("wallpaper-bg"),()=>{document.body.classList.remove("wallpaper-bg")}),[]),d.useEffect(()=>{i(!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 Hs="oauthPending";function bn(){const t=Pe(),{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"]}),Es.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"]}),Es.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"]}),Dr.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(()=>
31{const r=new URLSearchParams(window.location.search);let i=!1;if(r.get("calendar")==="success"&&(s("googleCalendar"),i=!0),r.get("microsoft_calendar")==="success"&&(s("microsoftCalendar"),i=!0),r.get("outlook")==="success"&&(s("microsoftMail"),i=!0),!i){const x=sessionStorage.getItem(Hs);x&&(s(x),i=!0)}sessionStorage.removeItem(Hs),i&&window.history.replaceState({},document.title,window.location.pathname)},[t,a,s])}function yn({subscription:t,user:a}){const[s,r]=d.useState(null);return d.useEffect(()=>{if(a!=null&&a.isAdmin)return;const i=t==null?void 0:t.isOnTrial,l=t==null?void 0:t.trialEndDate;if(i&&l){const n=new Date(l),o=new Date,x=n.getTime()-o.getTime(),p=Math.floor(x/(1e3*60*60*24)),b=Math.max(0,p);r(b),localStorage.getItem(`trial_tracked_${a==null?void 0:a.id}`)||(ia(async()=>{const{trackTrialStarted:u}=await import("./index-Byg2HWAE.js").then(y=>y.fP);return{trackTrialStarted:u}},__vite__mapDeps([1,2,3])).then(({trackTrialStarted:u})=>{u(a==null?void 0:a.id,{trial_days_remaining:b,trial_end_date:n.toISOString()})}),localStorage.setItem(`trial_tracked_${a==null?void 0:a.id}`,"true")),r(0)}else r(null)},[t,a]),{trialDaysRemaining:s}}function vn({user:t,totalHours:a,materialHours:s,selectedYear:r}){const i=new Date().getFullYear(),{data:l}=ne({queryKey:["/api/stats/rep-requirements",{repType:t==null?void 0:t.repType,year:i}],enabled:!!(t!=null&&t.repType)}),n=(a==null?void 0:a.totalHours)||0,o=(s==null?void 0:s.materialHours)||0,x=(t==null?void 0:t.repType)==="shortTerm",p=(l==null?void 0:l.totalHoursRequired)??(x?500:750),b=(l==null?void 0:l.materialHoursRequired)??(x?100:500),u=Math.min(n/p*100,100),y=x?Math.min(o/b*100,100):0,N=Math.max(p-n,0),f=$a(n,o,(t==null?void 0:t.repType)==="shortTerm"?"shortTerm":"longTerm");return{totalHoursValue:n,materialHoursValue:o,goalHours:p,materialGoal:b,progressPercentage:u,materialProgressPercentage:y,remainingHours:N,complianceStatus:f,repRequirements:l}}function Pa(){const{toast:t}=fe(),a=Pe(),[,s]=cs(),[r,i]=d.useState(!1),[l,n]=d.useState(vs),o=ce({mutationFn:qa,onSuccess:p=>{za(void 0,{property_type:l.propertyType}),a.invalidateQueries({queryKey:["/api/properties"]}),n(vs),i(!1),p!=null&&p.id?s(`/properties/${p.id}`):t({title:"Success",description:"Property added successfully"}),js.isRunning&&js.refreshGeofences().catch(console.error)},onError:p=>{if(It(p)){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:i,formData:l,setFormData:n,handleSubmit:p=>{p.preventDefault(),o.mutate(l)},isPending:o.isPending}}function jn(t){return/^403: .*Subscription required/.test(t.message)||t.message.includes("upgradeRequired")}function rs(t,a){return`${t} is a Pro feature. Upgrade to REPSShield to unlock this feature.`}function Nn(t){const{toast:a}=fe(),[s,r]=d.useState(!1),i=(o,x)=>{const p=window.URL.createObjectURL(o),b=document.createElement("a");b.href=p,b.download=x,document.body.appendChild(b),b.click(),window.URL.revokeObjectURL(p),document.body.removeChild(b)};return{handleExportCSV:async()=>{if(!t){r(!0);return}
31Ns(void 0,{export_type:"csv",export_format:"standard"});try{const o=await xn(),x=`rep-tracker-export-${new Date().toISOString().split("T")[0]}.csv`;i(o,x),na(void 0,{report_type:"csv_export",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:rs("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}Ns(void 0,{export_type:"csv_with_files",export_format:"archive"});try{const o=await un(),x=`repsshield-export-with-files-${new Date().toISOString().split("T")[0]}.zip`;i(o,x),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:rs("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 wn({onClose:t}){const{calendarAutomation:a,setCalendarAutomation:s,handleSaveCalendar:r,isSavingCalendar:i}=xs(),[l,n]=d.useState(""),[o,x]=d.useState(""),[p,b]=d.useState(!1),{toast:u}=fe(),{suggestions:y,isLoading:N,refreshSuggestions:f}=pa("calendar",!0),c=m=>{const I=m.trim();I&&(a.trustedOrganizers.includes(I)||s({...a,trustedOrganizers:[...a.trustedOrganizers,I]}))},P=m=>{s({...a,trustedOrganizers:a.trustedOrganizers.filter(I=>I!==m)})},h=m=>{const I=m.trim();I&&(a.trustedKeywords.includes(I)||s({...a,trustedKeywords:[...a.trustedKeywords,I]}))},C=m=>{s({...a,trustedKeywords:a.trustedKeywords.filter(I=>I!==m)})},v=m=>{c(m),f()},S=async m=>{try{await Lr.dismissSuggestion(m,"calendar"),f(),u({title:"Suggestion dismissed",description:`${m} won't appear in suggestions again.`})}catch{u({title:"Failed to dismiss",description:"Could not dismiss suggestion. Please try again.",variant:"destructive"})}},O=y.filter(m=>!a.trustedOrganizers.includes(m.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(G,{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(et,{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(Me,{checked:a.autoApproveHighConfidence,onCheckedChange:m=>s({...a,autoApproveHighConfidence:m})})]})}),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(Ht,{className:"h-4 w-4 text-amber-600 dark: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(Me,{checked:a.enabled,onCheckedChange:m=>s({...a,enabled:m})})]}),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 dar
31k: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(m=>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:m}),e.jsx("button",{onClick:()=>P(m),className:"text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors",children:e.jsx(se,{className:"h-3 w-3"})})]},m))}),e.jsx("input",{placeholder:"Type an email and press Enter...",value:l,onChange:m=>n(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),c(l),n(""))},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(m=>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:m}),e.jsx("button",{onClick:()=>C(m),className:"text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors",children:e.jsx(se,{className:"h-3 w-3"})})]},m))}),e.jsx("input",{placeholder:"Type a keyword and press Enter...",value:o,onChange:m=>x(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),h(o),x(""))},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:[N&&e.jsx("div",{className:"w-full text-sm text-slate-500 text-center py-4",children:"Loading suggestions..."}),!N&&O.length===0&&e.jsx("div",{className:"w-full text-sm text-slate-500 text-center py-4 italic",children:"No new suggestions available."}),!N&&e.jsx(Ye,{children:O.map(m=>e.jsxs(Be,{children:[e.jsx(We,{asChild:!0,children:e.jsxs("div",{className:"group relative",children:[e.jsx(Z,{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:()=>v(m.email),children:m.email}),e.jsx("button",{onClick:I=>{I.stopPropagation(),S(m.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(rt,{className:"h-3.5 w-3.5"})})]})}),e.jsx(Je,{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(m.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:m.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(m.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(m.lastSeen).toLocaleDateString()]})]})})]},m.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(G,{onClick:r,disabled:i,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:i?"Saving Changes...":"Save Configuration"})})]})}function kn(t){var b,u;const[a,s]=d.useState(!1),{googleCalendarStatusQuery:r,microsoftCalendarStatusQuery:i,isGoogleCalendarConnecting:l,isMicrosoftCalendarConnecting:n}=bt(),o=((b=r.data)==null?void 0:b.connected)||!1,x=((u=i.data)==null?void 0:u.connected)||!1,p=e.jsx(vt,{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",children:[e.jsx("div",{className:"w-10 h-10 flex items-center justify-center",children:e.jsx(pe,{className:"h-5 w-5 text-primary"})}),e.jsx("div",{children:e.jsx(jt,{className:"text-xl",children:"Calendar Sync"})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ps,{type:"google-calendar",isConnected:o,isLoading:l,onClick:()=>{var y;return(y=t.setGoogleCalendarDialogOpen)==null?void 0:y.call(t,!0)},iconOnly:!0}),e.jsx(Ps,{type:"microsoft-calendar",isConnected:x,isLoading:n,onClick:()=>{var y;return(y=t.setMicrosoftCalendarDialogOpen)==null?void 0:y.call(t,!0)},iconOnly:!0}),e.jsx(G,{variant:"ghost",size:"icon",onClick:()=>s(!0),className:"text-muted-foreground hover:text-primary transition-colors","aria-label":"Calendar automation settings",children:e.jsx(ft,{className:"h-4 w-4 transition-transform duration-300",style:{transform:a?"rotate(90deg)":"rotate(0deg)"}})})]})]})});return e.jsx(he,{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:[p,e.jsxs(le,{className:"p-6 flex-1 flex flex-col overflow-hidden",children:[e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(_r,{})}),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(Or,{})})]})]}),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(wn,{onClose:()=>s(!1)})})]})})}function Cn({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 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:"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(G,{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(et,{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(Me,{checked:r,onCheckedChange:i=>s(i)})]})})}
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(G,{onClick:t,className:"w-full",children:"Done"})})]})}function Sn({open:t,onOpenChange:a,entry:s,onSaveAndApprove:r,onSaveDraft:i,onReject:l}){return e.jsx(ve,{open:t,onOpenChange:a,children:e.jsxs(De,{className:"sm:max-w-[600px] max-h-[90vh] overflow-y-auto p-4 sm:p-6 overscroll-contain",children:[e.jsx(Ae,{children:e.jsxs(Fe,{className:"flex items-center gap-2 text-base sm:text-lg",children:[e.jsx(tt,{className:"h-5 w-5 text-primary shrink-0"}),"Review Detected Visit"]})}),e.jsx(Ca,{entry:s,onSaveAndApprove:r,onSaveDraft:i,onReject:l,onCancel:()=>a(!1)})]})})}const dt=10,Bt="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 border-l-4 bg-white",Wt="flex w-full items-center gap-1 py-1 text-left normal-case hover:no-underline";function $s(){const[t,a]=d.useState(!1),[s,r]=d.useState(1),[i,l]=d.useState(null),[n,o]=d.useState(!1),[x,p]=d.useState(""),[b,u]=d.useState(!1),[y,N]=d.useState(),[f,c]=d.useState(new Set),{pendingEntries:P,listFilter:h,setListFilter:C,statusCounts:v,entries:S,settings:O,isLoading:m,error:I,approveEntry:A,rejectEntry:L,bulkApprove:H,updateSettings:$,saveAndApproveEntry:_,saveDraftEntry:q,isApproving:F,refetch:T}=Ea(),E=j=>{const Q=x.toLowerCase(),J="propertyName"in j&&j.propertyName||"",ie="visitorName"in j&&j.visitorName||"",Re="discardReason"in j&&j.discardReason||"";if(!(!x||J.toLowerCase().includes(Q)||ie.toLowerCase().includes(Q)||Re.toLowerCase().includes(Q)))return!1;if(!y)return!0;const gs="discardReason"in j?j.enteredAt:j.date;return gs?Y(new Date(gs),"yyyy-MM-dd")===Y(y,"yyyy-MM-dd"):!1},D=S.filter(E),g=Math.ceil(D.length/dt),w=(s-1)*dt,M=D.slice(w,w+dt),k=M.map(j=>W(j)),U=M.filter(j=>f.has(W(j))).filter(j=>!ee(j)&&j.approvalStatus==="pending"),V=k.length>0&&k.every(j=>f.has(j)),K=k.some(j=>f.has(j))&&!V;function ee(j){return"discardReason"in j}function W(j){return ee(j)?`discarded-${j.id}`:`entry-${j.id}`}const xe=j=>{const Q=W(j);c(J=>{const ie=new Set(J);return ie.has(Q)?ie.delete(Q):ie.add(Q),ie})},Ie=j=>{c(Q=>{const J=new Set(Q);return j?k.forEach(ie=>J.add(ie)):k.forEach(ie=>J.delete(ie)),J})},de=()=>c(new Set),je=j=>{C(j),r(1),p(""),de()},X=j=>{l(j),o(!0)},Ne=j=>{A.mutate({id:j.id})},we=j=>{L.mutate({id:j.id})},Oe=()=>{const j=U.map(Q=>Q.id);j.length!==0&&(H.mutate(j),de())},He=()=>{U.forEach(j=>L.mutate({id:j.id})),de()},ae=e.jsx(vt,{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-10 h-10 rounded-lg bg-green-100 dark:bg-green-900 flex items-center justify-center",children:e.jsx(tt,{className:"h-5 w-5 text-green-600 dark:text-green-400"})}),e.jsx(jt,{className:"text-xl",children:"Geo Fence Sync"})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[P.length>0&&e.jsxs(Z,{variant:"secondary",className:"ml-1",children:[P.length," pending"]}),e.jsx(G,{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(ft,{className:"h-4 w-4 transition-transform duration-300",style:{transform:t?"rotate(90deg)":"rotate(0deg)"}})})]})]})}),$e=[{value:"approved",label:"Approved",mobileLabel:"Approved",count:v.approved},{value:"pending",label:"Pending Approval",mobileLabel:"Pending",count:v.pending},{value:"discarded",label:"Discarded",mobileLabel:"Discarded",count:v.discarded},{value:"all",label:"All",mobileLabel:"All",count:v.all}],it=()=>e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center",children:[e.jsx(tt,{className:"h-12 w-12 text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground mb-2",children:h==="pending"?"No pending visits to review.":h==="approved"?"No approved visits yet.":h==="discarded"?"No discarded visits.":"No visits found."}),h==="pending"&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground
31/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:ps,target:"_blank",rel:"noopener noreferrer",onClick:()=>Rt({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"})}),ka?e.jsx("a",{href:qt,target:"_blank",rel:"noopener noreferrer",onClick:()=>Rt({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"})]})]})]})]}),qe=j=>{var Q;return e.jsxs(Mt,{value:`pending-${j.id}`,className:z(Bt,"border-l-amber-500"),children:[e.jsxs(Et,{className:Wt,children:[e.jsx(mt,{checked:f.has(W(j)),onCheckedChange:()=>xe(j),onClick:J=>J.stopPropagation(),"aria-label":`Select ${j.visitorName||j.propertyName||"geo fence visit"}`,className:"border-amber-500"}),e.jsx("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:j.visitorName||"Unknown Visitor"}),j.propertyName&&e.jsxs("span",{className:"text-muted-foreground",children:["â ",j.propertyName]})]})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-right flex-none hidden sm:block",children:[Number(j.hours).toFixed(1),"h"]}),e.jsxs("span",{className:"hidden sm:inline-flex items-center gap-1 text-[10px] text-amber-600 bg-amber-50 dark:bg-amber-900/20 px-1.5 py-0.5 rounded-full font-medium flex-none",children:[e.jsx(ge,{className:"h-3 w-3"}),"pending review"]}),e.jsx("div",{className:"flex-none text-xs text-muted-foreground",children:Y(new Date(j.date),"MM/dd")})]}),e.jsx(Pt,{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:[j.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:j.description})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Activity:"}),e.jsx("p",{className:"mt-0.5 capitalize",children:((Q=j.activityType)==null?void 0:Q.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(j.hours).toFixed(1)," hrs"]})]}),j.timeStarted&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Started:"}),e.jsx("p",{className:"mt-0.5",children:Y(new Date(j.timeStarted),"h:mm a")})]}),j.timeEnded&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Ended:"}),e.jsx("p",{className:"mt-0.5",children:Y(new Date(j.timeEnded),"h:mm a")})]})]}),e.jsxs("div",{className:"w-full flex justify-end gap-3 mb-2 pt-2",children:[e.jsx(G,{size:"sm",className:"h-7 px-2 gap-1.5 text-xs bg-green-600 hover:bg-green-700 text-white",onClick:J=>{J.stopPropagation(),Ne(j)},disabled:F,children:"Approve"}),e.jsx(G,{size:"sm",variant:"outline",className:"h-7 px-2 gap-1.5 text-xs",onClick:J=>{J.stopPropagation(),X(j)},children:"Review"}),e.jsx(G,{size:"sm",variant:"outline",className:"h-7 px-2 gap-1.5 text-xs text-destructive",onClick:J=>{J.stopPropagation(),we(j)},disabled:F,children:"Discard"})]})]})})]},j.id)},nt=j=>{var Q;return e.jsxs(Mt,{value:String(j.id),className:z(Bt,"border-l-green-500"),children:[e.jsxs(Et,{className:Wt,children:[e.jsx(mt,{checked:f.has(W(j)),onCheckedChange:()=>xe(j),onClick:J=>J.stopPropagation(),"aria-label":`Select ${j.visitorName||j.propertyName||"geo fence visit"}`,className:"border-green-500"}),e.jsx("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:j.visitorName||"Unknown Visitor"}),j.propertyName&&e.jsxs("span",{className:"text-muted-foreground",children:["â ",j.propertyName]})]})}),e.jsxs("span",{className:"text-xs text-muted-foreground w-10 text-right flex-none hidden sm:block",children:[Number(j.hours).toFixed(1),"h"]}),e.jsx("div",{className:"flex-none text-xs text-muted-foreground",children:Y(new Date(j.date),"MM/dd")})]}),e.jsx(Pt,{className:"px-4 py-1 text-xs",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs text-muted-foreground",children:[j.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:j.description})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Activity:"}),e.jsx("p",{className:"mt-0.5 capitalize",children:((Q=j.activityType)==null?void 0:Q.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(j.hours).toFixed(1)," hrs"]})]}),j.timeStarted&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Started:"}),e.jsx("p",{className:"mt-0.5",children:Y(new Date(j.timeStarted),"h:mm a")})]}),j.timeEnded&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Time Ended:"}),e.jsx("p",{className:"mt-0.5",children:Y(new Date(j.timeEnded),"h:mm a")})]})]})})]},j.id)},ze=j=>{const Q=j.enteredAt?new Date(j.enteredAt):null,J=j.exitedAt?new Date(j.exitedAt):null;return e.jsxs(Mt,{value:String(j.id),className:z(Bt,"border-l-gray-400"),children:[e.jsxs(Et,{className:Wt,children:[e.jsx(mt,{checked:f.has(W(j)),onCheckedChange:()=>xe(j),onClick:ie=>ie.stopPropagation(),"aria-label":`Select ${j.propertyName||"discarded geo fence visit"}`,className:"border-slate-400"}),e.jsx("div",{className:"w-0 flex-1 min-w-0",children:e.jsxs("span",{className:"truncate text-xs block",children:[j.propertyName&&e.jsx("span",{className:"mr-1 font-semibold",children:j.propertyName}),e.jsxs("span",{className:"text-muted-foreground",children:["â ",j.discardReason]})]})}),e.jsx("span",{className:"text-xs text-muted-foreground w-10 text-right flex-none hidden sm:block",children:"â"}),e.jsx("span",{className:"hidden sm:inline-flex items-center text-[10px] text-slate-600 bg-slate-100 dar
31k:bg-slate-800 px-1.5 py-0.5 rounded-full font-medium flex-none",children:"discarded"}),e.jsx("div",{className:"flex-none text-xs text-muted-foreground",children:Q?Y(Q,"MM/dd"):""})]}),e.jsx(Pt,{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:j.discardReason})]}),j.durationMinutes!==null&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Duration:"}),e.jsxs("p",{className:"mt-0.5",children:[j.durationMinutes," min"]})]}),Q&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Entered:"}),e.jsx("p",{className:"mt-0.5",children:Y(Q,"MMM d, h:mm a")})]}),J&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Exited:"}),e.jsx("p",{className:"mt-0.5",children:Y(J,"MMM d, h:mm a")})]})]})})]},j.id)},Ge=()=>D.length<=dt?null:e.jsxs("div",{className:"flex items-center justify-between py-4 border-t mt-2",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Showing ",w+1," to ",Math.min(w+dt,D.length)," of ",D.length," entries"]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxs(G,{variant:"outline",size:"sm",onClick:()=>r(j=>Math.max(1,j-1)),disabled:s===1,className:"h-7 w-7 p-0",children:[e.jsx("span",{className:"sr-only",children:"Previous"}),e.jsx(Xe,{className:"h-3.5 w-3.5"})]}),e.jsxs("div",{className:"text-xs font-medium",children:["Page ",s," of ",g]}),e.jsxs(G,{variant:"outline",size:"sm",onClick:()=>r(j=>Math.min(g,j+1)),disabled:s===g,className:"h-7 w-7 p-0",children:[e.jsx("span",{className:"sr-only",children:"Next"}),e.jsx(re,{className:"h-3.5 w-3.5"})]})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(he,{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:z("h-full flex flex-col",t?"pointer-events-none":""),style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},children:[ae,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(Ye,{children:e.jsxs(Be,{children:[e.jsx(We,{asChild:!0,children:e.jsx(mt,{checked:K?"indeterminate":V,onCheckedChange:Ie,"aria-label":"Select all"})}),e.jsx(Je,{children:e.jsx("p",{children:"Select All"})})]})}),e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(ta,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ye,{placeholder:h==="discarded"?"Search by property or reason...":"Search by visitor or property...",value:x,onChange:j=>{p(j.target.value),r(1)},className:"pl-9 pr-8 h-7 sm:h-8 text-xs"}),x&&e.jsx(Ye,{children:e.jsxs(Be,{children:[e.jsx(We,{asChild:!0,children:e.jsx(G,{type:"button",variant:"ghost",size:"icon",onClick:()=>p(""),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(Je,{children:e.jsx("p",{children:"Clear"})})]})})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsxs(Nt,{open:b,onOpenChange:u,children:[e.jsx(wt,{asChild:!0,children:e.jsxs(G,{variant:y?"default":"outline",size:"sm",className:z("flex items-center gap-2 h-7",y&&"bg-purple-600 hover:bg-purple-700"),"aria-label":"Filter geo fence visits by date",children:[e.jsx(us,{className:"h-3 w-3 sm:h-4 sm:w-4"}),y&&e.jsx(se,{className:"h-3 w-3 ml-1",onClick:j=>{j.stopPropagation(),N(void 0),r(1)}})]})}),e.jsx(kt,{className:"w-auto p-0",align:"end",children:e.jsx(Ot,{mode:"single",selected:y,onSelect:j=>{N(j),r(1),u(!1)},initialFocus:!0})})]}),e.jsx(Ye,{children:e.jsxs(Be,{children:[e.jsx(We,{asChild:!0,children:e.jsx(G,{variant:"outline",size:"sm",onClick:T,disabled:m,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(Ze,{className:z("h-3 w-3 sm:h-4 sm:w-4",m&&"animate-spin")})})}),e.jsx(Je,{children:e.jsx("p",{children:"Refresh geo fence visits"})})]})})]})]}),f.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:[f.size," selected"]}),U.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(G,{size:"sm",className:"h-7",onClick:Oe,disabled:F,children:"Approve"}),e.jsx(G,{size:"sm",variant:"outline",className:"h-7 text-destructive",onClick:He,disabled:F,children:"Discard"})]}),e.jsx(G,{size:"sm",variant:"outline",className:"h-7",onClick:de,children:"Clear"})]})]}),e.jsxs(le,{className:"pl-3 pr-3 flex flex-1 min-h-0 flex-col overflow-hidden",children:[m?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(ut,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):I?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ra,{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(ls,{value:h,onValueChange:je,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(os,{className:"w-full rounded-xl p-1 sm:p-1.5 flex gap-1",children:$e.map(j=>e.jsxs(pt,{value:j.value,className:z("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:[e.jsx("span",{className:"hidden sm:inline",children:j.label}),e.jsx("span",{className:"sm:hidden",children:j.mobileLabel}),e.jsxs("span",{className:"ml-0.5 sm:ml-1",children:["(",j.count,")"]})]},j.value))})})}),e.jsx(gt,{value:h,className:"mt-3 flex flex-1 min-h-0 flex-col overflow-hidden",children:M.length===0?it():e.jsx(e.Fragment,{children:e.jsx("div",{className:"w-full max-w-full overflow-hidden",children:e.jsx(la,{className:"h-full w-full",children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(oa,{type:"single",collapsible:!0,className:"w-full",children:M.map(j=>{if("discardReason"in j)return ze(j);const Q=j;return Q.approvalStatus==="pending"?qe(Q):nt(Q)})}),Ge()]})})})})})]}),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(wa,{})})]})]}),e.jsx("div",{className:z("absolute inset-0 h-full w-full",t?"":"pointer-events-none"),style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"},children:e.jsx(Cn,{onClose:()=>a(!1),settings:O,onUpdateSettings:j=>$.mutate(j)})})]})}),e.jsx(Sn,{open:n,onOpenChange:o,entry:i,onSaveAndApprove:j=>{_.mutate(j),o(!1)},onSaveDraft:j=>{q.mutate(j),o(!1)},onReject:j=>{L.mutate({id:j}),o(!1)}})]})}function qs({open:t,onOpenChange:a}){const{formData:s,setFormData:r,handleSubmit:i,isPending:l}=Pa();return e.jsx(ve,{open:t,onOpenChange:a,children:e.jsxs(De,{className:"sm:max-w-[480px]",children:[e.jsx(Ae,{children:e.jsx(Fe,{children:"Add New Property"})}),e.jsxs("form",{onSubmit:i,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:"nickname",children:"Property Nickname *"}),e.jsx(ye,{id:"nickname",value:s.nickname,onChange:n=>r(o=>({...o,nickname:n.target.value})),placeholder:"e.g., Downtown Apartment, Beach House",required:!0})]}),e.jsx(Ga,{value:s.address,onChange:n=>r(o=>({...o,address:n})),onSelect:({address:n,city:o,state:x,zipCode:p})=>r(b=>({...b,address:n,city:o,state:x,zipCode:p})),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(B,{htmlFor:"propertyType",children:"Property Type *"}),e.jsxs(ke,{value:s.propertyType,onValueChange:n=>r(o=>({...o,propertyType:n})),children:[e.jsx(Ce,{children:e.jsx(Se,{placeholder:"Select type"})}),e.jsxs(Te,{children:[e.jsx(te,{value:"Long-term Rental",children:"Long-term Rental"}),e.jsx(te,{value:"Short-term Rental",children:"Short-term Rental"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(G,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(G,{type:"submit",disabled:l,children:l?"Addingâ¦":"Add Property"})]})]})]})})}const Tn=()=>e.jsxs(G,{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/6 mx-auto"})})]}),Da=({timeEntries:t,selectedYear:a,pendingCount:s})=>{var O,m,I,A,L;
31const[r,i]=cs(),[l,n]=d.useState(!0),{imapStatusQuery:o}=bt(),{googleCalendarStatusQuery:x,microsoftCalendarStatusQuery:p}=bt(),b=((O=x.data)==null?void 0:O.connected)||!1,u=((m=p.data)==null?void 0:m.connected)||!1,{data:y}=Rr(),N=((I=y==null?void 0:y.gmail)==null?void 0:I.connected)||!1,f=((A=y==null?void 0:y.outlook)==null?void 0:A.connected)||!1,c=((L=o.data)==null?void 0:L.connected)||!1,P=N||f||c,h=b||u,C=d.useMemo(()=>(t||[]).filter($=>$.approvalStatus!=="approved"),[t,a]),v=s!==void 0?s:C.length,S=d.useCallback(()=>{const H=a?`&year=${a}`:"";i(`/activity-ledger?status=pending${H}`)},[i,a]);return d.useEffect(()=>{const H=setTimeout(()=>{n(!1)},1e3);return()=>clearTimeout(H)},[]),l?e.jsx(Tn,{}):!l&&h===!1&&P===!1?null:C.length===0?e.jsx(be.div,{animate:{opacity:[0,1]},transition:{duration:.3},className:"w-full",children:e.jsxs(G,{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 relative",disabled:!0,children:[e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(at,{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(be.div,{animate:{opacity:[0,1]},transition:{duration:.3},className:"w-full",children:e.jsxs(G,{onClick:S,variant:"outline",className:"w-full h-auto sm:h-auto flex-col items-center p-3 sm:p-4 whitespace-normal gap-1 sm:gap-2 touch-target hover:bg-accent hover:text-accent-foreground relative border-[#f59e0b] border",children:[e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(at,{className:"!h-6 !w-6 text-gray-400"})}),e.jsx("div",{className:"flex flex-row items-center justify-center flex-wrap w-full",children:e.jsxs("span",{className:"m-0 leading-tight",children:["Review ",e.jsx("span",{className:"text-red-500",children:v})," ","Time ",v===1?"Entry":"Entries"]})}),e.jsx("p",{className:"w-full font-normal m-0 text-center text-muted-foreground",children:"Ensure your time entries are properly categorized"})]})})};function Mn({user:t,timeEntries:a,selectedYear:s,pendingCount:r}){var f,c,P;const{toast:i}=fe(),l=Pe(),[n,o]=d.useState(!1),x=new Date().getFullYear(),{data:p}=ne({queryKey:["/api/stats/rep-requirements/all",{year:x}]}),b=(p==null?void 0:p.requirements)||[],u=ce({mutationFn:async h=>{const C=await me("PATCH","/api/auth/user",{repType:h});if(!C.ok){const S=await C.text();throw console.error("â REP type update failed:",S),new Error(S)}return await C.json()},onMutate:async h=>{await l.cancelQueries({queryKey:["/api/auth/user"]});const C=l.getQueryData(["/api/auth/user"]);return l.setQueryData(["/api/auth/user"],v=>v&&{...v,repType:h}),{previousUser:C}},onSuccess:h=>{l.setQueryData(["/api/auth/user"],h),l.invalidateQueries({queryKey:["/api/stats"]}),l.invalidateQueries({queryKey:["/api/time-entries"]}),i({title:"REP Type Updated",description:"Your REP status type has been updated successfully"})},onError:(h,C,v)=>{if(v!=null&&v.previousUser&&l.setQueryData(["/api/auth/user"],v.previousUser),console.error("â REP type mutation failed:",h),It(h)){i({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500);return}i({title:"Error",description:"Failed to update REP type",variant:"destructive"})}}),y=h=>{h!==t.repType&&(h==="shortTerm"?o(!0):u.mutate(h))},N=h=>{};return e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"block lg:hidden mb-4",children:a&&e.jsx(Da,{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(Ye,{children:e.jsxs(Be,{children:[e.jsx(We,{children:e.jsx(Le,{className:"h-4 w-4 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 flex-shrink-0"})}),e.jsx(Je,{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(G,{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"} ${u.isPending?"opacity-75":""}`,onClick:()=>y("longTerm"),disabled:u.isPending,children:[u.isPending&&u.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:u.isPending&&u.variables==="longTerm"?"opacity-0":"",children:"REP Status"})]}),e.jsxs(G,{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"} ${u.isPending?"opacity-75":""}`,onClick:()=>y("shortTerm"),disabled:u.isPending,children:[u.isPending&&u.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:u.isPending&&u.variables==="shortTerm"?"opacity-0":"",children:"STR Loophole"})]})]})}),e.jsx(Z,{variant:"outline",className:"text-xs flex-shrink-0",children:t.repType==="longTerm"?`${((f=b==null?void 0:b.find(h=>h.repType==="longTerm"))==null?void 0:f.totalHoursRequired)||750} hrs`:t.strSubType==="path_500"?"500 hrs":t.strSubType==="path_100"?"100 hrs":`${((c=b==null?void 0:b.find(h=>h.repType==="shortTerm"))==null?void 0:c.totalHoursRequired)||500}
31 + ${((P=b==null?void 0:b.find(h=>h.repType==="shortTerm"))==null?void 0:P.materialHoursRequired)||100} hrs`})]})}),u.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(ms,{isOpen:n,onClose:()=>o(!1),onSelectionComplete:N})]})}const ct={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 En(t,a,s,r,i,l){const n=i||new Date().getFullYear(),o=t==null?void 0:t.repType,x=t==null?void 0:t.strSubType,p=o==="longTerm",b=o==="shortTerm"&&x==="path_500",u=o==="shortTerm"&&x==="path_100",{data:y,isLoading:N}=ne({queryKey:["/api/stats/rep-progress",{repType:o,year:n}],queryFn:()=>ct.getRepProgress(o,n),enabled:!!o,staleTime:1e3*60*2,retry:1}),{data:f}=ne({queryKey:["/api/stats/rep-requirements",{repType:o,year:n}],queryFn:()=>ct.getRepRequirements(o,n),enabled:!!o,staleTime:1e3*60*5,retry:1}),{data:c}=ne({queryKey:["/api/stats/spouse-hour-breakdown",{year:n}],queryFn:()=>ct.getSpouseHourBreakdown(n),enabled:o==="shortTerm",staleTime:1e3*60*2,retry:1}),{data:P}=ne({queryKey:["/api/stats/qualified-non-material-hours",{year:n}],queryFn:()=>ct.getQualifiedNonMaterialHours(n),enabled:p,staleTime:1e3*60*2,retry:1}),{data:h,isLoading:C,isError:v}=ne({queryKey:["/api/analytics/daily-hours/14"],queryFn:()=>ct.getDailyHours(14),select:F=>!F||!Array.isArray(F)?Array(14).fill(0):Array.from({length:14},(E,D)=>{const g=Y(Va(new Date,13-D),"yyyy-MM-dd"),w=F.find(M=>M.date===g);return w?parseFloat(w.hours):0}),staleTime:1e3*60*5,retry:1}),S=b?500:u?100:p?(f==null?void 0:f.totalHoursRequired)??750:500,O=b?500:u?100:p?(f==null?void 0:f.materialHoursRequired)??500:100,m=b?0:u?100:p?(f==null?void 0:f.qualifiedNonMaterialRequired)??250:0,I=(y==null?void 0:y.totalHours)??a,A=(y==null?void 0:y.materialHours)??s,L=(y==null?void 0:y.qualifiedNonMaterialHours)??((P==null?void 0:P.qualifiedNonMaterialHours)||0),H=o==="shortTerm"&&r&&r.length>0,$=c!=null&&c.pooledTotal?c.pooledTotal.totalHours:H?(r||[]).reduce((F,T)=>F+(parseFloat(T.totalHours)||0),0)+I:I,_=c!=null&&c.pooledTotal?Math.min(c.pooledTotal.totalHours/S*100,100):H?Math.min($/S*100,100):N?0:(y==null?void 0:y.totalProgress)!=null&&(y==null?void 0:y.totalProgress)>0?y.totalProgress:Math.min(I/S*100,100),q=(()=>{if(I===0)return"Start logging to see projection";const F=S-I;if(F<=0)return"Goal achieved!";if(!h||h.length===0)return"Need more activity to project";const E=h.reduce((w,M)=>w+M,0)/h.length;if(E===0)return"Need more activity to project";const D=Math.ceil(F/E),g=new Date;return g.setDate(g.getDate()+D),Y(g,"MMM dd, yyyy")})();return{repProgress:y,repRequirements:f,spouseBreakdown:c,dailyHoursData:h,goalHours:S,materialGoal:O,qualifiedGoal:m,currentTotalHours:I,currentMaterialHours:A,currentQualifiedHours:L,effectiveTotalHours:$,progressPercentage:_,projectedCompletion:q,isTeamVie
31w:H,isLongTerm:p,isStrPath500:b,isStrPath100:u,isRepProgressLoading:N,isLoadingDailyHours:C,isDailyHoursError:v}}function Aa({materialHours:t,qualifiedHours:a,totalHours:s,materialGoal:r,qualifiedGoal:i,totalGoal:l,repType:n,strSubType:o}){const[x,p]=d.useState(!1),[b,u]=d.useState(!1),[y,N]=d.useState(!1);if(n==="longTerm"){const P=Math.min(s/l*100,100),h=Math.min(t/r*100,100),C=Math.min(a/i*100,100);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Total Hours"}),e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-400 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors",onClick:()=>p(!x),"data-testid":"total-metric-toggle",children:[x?`${P.toFixed(1)}% complete`:`${s.toFixed(1)}/${l}`,s>=l&&e.jsx("span",{className:"text-green-600 ml-1",children:"â"})]})]}),e.jsx("div",{className:"w-full bg-gray-200 dark:bg-gray-700 rounded-full h-3",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-400 to-blue-600 h-3 rounded-full transition-all duration-500",style:{width:`${P}%`},"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-sm font-medium text-gray-700 dark:text-gray-300",children:"Material Participation"}),e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-400 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors",onClick:()=>u(!b),"data-testid":"material-metric-toggle",children:[b?`${h.toFixed(1)}% complete`:`${t.toFixed(1)}/${r}`,t>=r&&e.jsx("span",{className:"text-green-600 ml-1",children:"â"})]})]}),e.jsx("div",{className:"w-full bg-gray-200 dark:bg-gray-700 rounded-full h-3",children:e.jsx("div",{className:"bg-gradient-to-r from-blue-500 to-blue-700 h-3 rounded-full transition-all duration-500",style:{width:`${h}%`},"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-sm font-medium text-gray-700 dark:text-gray-300",children:"Qualified Non-Material"}),e.jsxs("span",{className:"text-sm text-gray-600 dark:text-gray-400 cursor-pointer hover:text-blue-600 dark:hover:text-blue-400 transition-colors",onClick:()=>N(!y),"data-testid":"qualified-metric-toggle",children:[y?`${C.toFixed(1)}% complete`:`${a.toFixed(1)}/${i}`,a>=i&&e.jsx("span",{className:"text-green-600 ml-1",children:"â"})]})]}),e.jsx("div",{className:"w-full bg-gray-200 dark:bg-gray-700 rounded-full h-3",children:e.jsx("div",{className:"bg-gradient-to-r from-green-500 to-green-700 h-3 rounded-full transition-all duration-500",style:{width:`${C}%`},"data-testid":"qualified-progress-bar"})})]})]})}const c=Math.min(s/l*100,100);return e.jsx("div",{className:"space-y-3 w-full",children:e.jsxs("div",{className:"relative w-full h-5 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:[e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${c}%`},"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),"/",l,s>=l&&" â"]})})]})})}function Jt({user:t,totalHours:a,materialHours:s,goalHours:r,materialGoal:i,isCurrentUser:l=!1,strSubType:n}){return e.jsx("div",{className:`p-3 rounded-lg border ${l?"bg-blue-50/50 border-blue-100 dark:bg-blue-900/10 dark:border-blue-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(xt,{user:t,size:"sm"}),e.jsx(Aa,{materialHours:s,qualifiedHours:0,totalHours:a,materialGoal:i,qualifiedGoal:0,totalGoal:r,repType:"shortTerm",strSubType:n})]})})}function zs({data:t,width:a=100,height:s=30}
31){if(!t||t.length===0)return null;const r=Math.max(...t,1),i=Math.min(...t,0),l=r-i||1,n=Math.max(t.length-1,1),o=t.map((x,p)=>{const b=p/n*a,u=s-(x-i)/l*s;return`${b},${u}`}).join(" ");return e.jsx("svg",{width:a,height:s,className:"text-blue-500",children:e.jsx("polyline",{fill:"none",stroke:"currentColor",strokeWidth:"1.5",points:o})})}function Pn({totalHours:t,materialHours:a,timeEntries:s,user:r,teamStats:i,onAddTimeEntry:l,selectedYear:n,pendingCount:o}){var F,T,E,D,g,w;const[x,p]=d.useState(!1),[b,u]=d.useState(!1),{hasActiveSubscription:y,canAccessPremiumFeatures:N}=da(),{isActive:f}=ca(),{spouseBreakdown:c,dailyHoursData:P,goalHours:h,materialGoal:C,qualifiedGoal:v,currentTotalHours:S,currentMaterialHours:O,currentQualifiedHours:m,effectiveTotalHours:I,progressPercentage:A,projectedCompletion:L,isRepProgressLoading:H,isLoadingDailyHours:$,isDailyHoursError:_}=En(r,t,a,i,n),q=n===new Date().getFullYear()&&new Date().getMonth()===0&&new Date().getDate()===1&&S===0;return e.jsxs(he,{className:"relative","data-tour":"progress-overview",children:[e.jsx(vt,{children:e.jsxs(jt,{className:"flex items-center text-lg font-semibold",children:[e.jsx(ws,{className:"h-5 w-5 mr-2 text-primary"}),"Time Tracking Progress"]})}),e.jsxs(le,{children:[q&&e.jsx("div",{className:"mb-6 p-6 bg-gradient-to-r from-blue-50 to-green-50 dark:from-blue-900/20 dark:to-green-900/20 border border-blue-200 dark:border-blue-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-blue-900 dark:text-blue-100 mb-2",children:["Welcome to ",n,"!"]}),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"," ",n-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(pe,{className:"h-4 w-4"}),e.jsxs("span",{children:["Start logging hours to track your ",n," progress"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(ws,{className:"h-4 w-4"}),e.jsxs("span",{children:["Goal: ",h," 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(ge,{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(ft,{className:"h-4 w-4"}),e.jsx("span",{children:"Generate year-end statements in Settings"})]})]}),e.jsxs(G,{onClick:l,className:"mt-4 bg-blue-600 hover:bg-blue-700 text-white",children:[e.jsx(Ee,{className:"h-4 w-4 mr-2"}),"Log Your First Hours"]})]})]})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx("div",{className:"flex flex-col items-center justify-center space-y-4",children:e.jsxs("div",{className:"relative",style:{width:120,height:120},children:[e.jsxs("svg",{width:"120",height:"120",className:"transform -rotate-90",children:[e.jsx("circle",{cx:"60",cy:"60",r:"50",fill:"none",stroke:"#e0e7ff",strokeWidth:"10"}),e.jsx("circle",{cx:"60",cy:"60",r:"50",fill:"none",stroke:"#3b82f6",strokeWidth:"10",strokeDasharray:2*Math.PI*50,strokeDashoffset:2*Math.PI*50*(1-A/100),className:"transition-all duration-1000 ease-in-out",strokeLinecap:"round",style:{filter:"drop-shadow(0 0 6px rgba(59, 130, 246, 0.7))"}})]}),e.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center select-none",children:H?e.jsx("span",{className:"text-sm font-medium text-blue-400 animate-pulse",children:"Loading..."}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-2xl font-extrabold text-blue-600 drop-shadow-sm",children:[A.toFixed(1),"%"]}),e.jsx("span",{className:"text-xs font-medium text-blue-400 uppercase tracking-wide",children:"Complete"})]})})]})}),e.jsxs("div",{className:"space-y-4",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-sm font-medium text-gray-600 dark:text-gray-300",children:"14-Day Trend"}),e.jsx("div",{className:"text-xs text-gray-500 mt-1",children:$?"Loading...":_?"Error loading data":P&&P.length>0?`Avg: ${(P.reduce((M,k)=>M+k,0)/14).toFixed(1)} hrs/day`:"No activity yet"})]}),e.jsx("div",{className:"flex items-center",children:$?e.jsx("div",{className:"text-xs text-gray-400 animate-pulse",children:"Loading..."}):_?e.jsx("div",{className:"text-xs text-red-400",children:"Error"}):P&&P.length>0?e.jsx(zs,{data:P,width:120,height:40}):e.jsx(zs,{data:Array(14).fill(0),width:120,height:40})})]})}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(pe,{className:"h-4 w-4 mr-2 text-gray-400"}),e.jsx("span",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:"Projected Completion"})]}),e.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:L})]})}),(r==null?void 0:r.repType)==="shortTerm"&&i&&i.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 justify-between text-sm",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-300",children:"Goal Progress"}),e.jsx("span",{className:"font-medium",children:H?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:c!=null&&c.spouses&&c.spouses.length>0?"Household STR Hours":"Team Loophole Progress"}),e.jsxs("span",{children:["Goal: ",h," hrs"]})]}
31),(c==null?void 0:c.spouses)&&c.spouses.length>0&&e.jsx("div",{className:"text-xs text-blue-600 dark:text-blue-400 mb-3 flex items-center gap-1",children:e.jsx("span",{children:"â Includes spouse hours (joint filer rule)"})}),e.jsx(Jt,{user:{...r,firstName:((T=(F=c==null?void 0:c.primaryUser)==null?void 0:F.name)==null?void 0:T.split(" ")[0])||(r==null?void 0:r.firstName),lastName:((D=(E=c==null?void 0:c.primaryUser)==null?void 0:E.name)==null?void 0:D.split(" ").slice(1).join(" "))||(r==null?void 0:r.lastName)},totalHours:((g=c==null?void 0:c.primaryUser)==null?void 0:g.totalHours)??S,materialHours:((w=c==null?void 0:c.primaryUser)==null?void 0:w.materialHours)??O,goalHours:h,materialGoal:C,isCurrentUser:!0,strSubType:r==null?void 0:r.strSubType}),c!=null&&c.spouses&&c.spouses.length>0?c.spouses.map(M=>e.jsx(Jt,{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:h,materialGoal:C,strSubType:r==null?void 0:r.strSubType},M.userId)):i.map(M=>e.jsx(Jt,{user:M,totalHours:parseFloat(M.totalHours)||0,materialHours:parseFloat(M.materialHours)||0,goalHours:h,materialGoal:C,strSubType:r==null?void 0:r.strSubType},M.id)).filter(M=>M.props.user.id!==r.id),e.jsxs("div",{className:"text-xs text-gray-500 text-center",children:[Math.max(0,h-I).toFixed(1)," ","hours remaining to reach Goal status"]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-gray-600 dark:text-gray-300",children:"Goal Progress"}),e.jsx("span",{className:"font-medium",children:H?e.jsx("span",{className:"text-gray-400 animate-pulse",children:"Loading..."}):`${A.toFixed(1)}% Complete`})]}),e.jsx(Aa,{materialHours:O,qualifiedHours:m,totalHours:S,materialGoal:C,qualifiedGoal:v,totalGoal:h,repType:r==null?void 0:r.repType,strSubType:r==null?void 0:r.strSubType}),e.jsxs("div",{className:"text-xs text-gray-500 text-center",children:[Math.max(0,h-I).toFixed(1)," ","hours remaining to reach Goal status"]})]})]}),e.jsx("div",{className:"flex flex-col justify-center items-end h-full",children:e.jsx("div",{className:"space-y-3 w-full",children:e.jsxs("div",{className:"grid grid-cols-1 gap-2 w-full",children:[e.jsxs(G,{onClick:l,className:"w-full bg-blue-600 hover:bg-blue-700 text-white touch-target hidden lg:flex",size:"sm",children:[e.jsx(Ee,{className:"h-4 w-4 mr-2"}),"Log Hours"]}),e.jsx(Qa,{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(G,{"data-tour":"stopwatch",onClick:()=>p(!x),variant:x?"secondary":"outline",className:"w-full touch-target hidden lg:flex",size:"sm",children:[e.jsx(ts,{className:"h-4 w-4 mr-2"}),x?"Hide Timer":"Start Timer"]})}),e.jsx("div",{className:"hidden lg:block",children:e.jsx(Da,{timeEntries:s,selectedYear:n,pendingCount:o})}),(r==null?void 0:r.repType)==="shortTerm"&&e.jsxs(G,{onClick:()=>u(!0),variant:"outline",className:"w-full touch-target",size:"sm","data-testid":"button-change-str-path",children:[e.jsx(ft,{className:"h-4 w-4 mr-2"}),"Change STR Path"]})]})})})]}),x&&(y||N||f)&&e.jsxs("div",{className:"mt-6 p-4 bg-blue-50 dark:bg-blue-900/20 rounded-lg border-2 border-blue-200 dark:border-blue-800",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(ge,{className:"h-4 w-4 mr-2 text-blue-600"}),e.jsx("span",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:"Timer Active"})]}),e.jsx(G,{onClick:()=>p(!1),variant:"ghost",size:"sm",className:"touch-target text-blue-600 hover:text-blue-800",children:"Ã"})]}),e.jsx(ja,{hideFloatingWidget:!0})]}),e.jsx(ms,{isOpen:b,onClose:()=>u(!1),onSelectionComplete:()=>{}})]})]})}function Dn(t){const{user:a}=$t(),{toast:s}=fe(),r=Pe(),i=(a==null?void 0:a.repType)==="shortTerm"&&((a==null?void 0:a.strSubType)==="path_500"||(a==null?void 0:a.strSubType)==="path_100"),l=(a==null?void 0:a.repType)==="shortTerm"?"Short-term Rental":"Long-term Rental",[n,o]=d.useState({date:Y(new Date,"yyyy-MM-dd"),hours:"",activityType:"",propertyId:"none",propertyType:l,description:"",isMaterialParticipation:i||!1,isQualifiedNonMaterial:!1}
31),[x,p]=d.useState([]),[b,u]=d.useState(!1),[y,N]=d.useState(!1),[f,c]=d.useState(!1),[P,h]=d.useState("idle"),[C,v]=d.useState(""),S=d.useRef(0),O=()=>{o({date:Y(new Date,"yyyy-MM-dd"),hours:"",activityType:"",propertyId:"none",propertyType:l,description:"",isMaterialParticipation:i||!1,isQualifiedNonMaterial:!1}),p([]),h("idle"),v("")},m=async _=>{if(p(_),_.length===0){h("idle"),v("");return}const q=S.current+1;S.current=q,h("scanning"),v("Scanning evidence for date, activity, and description...");try{const F=await Ua(_);if(q!==S.current)return;const T=F.mappedFields,E=[],D=.7,g=Y(new Date,"yyyy-MM-dd");o(w=>{var k;const M={...w};if(T.date.value&&T.date.confidence>=.65&&(!w.date||w.date===g)&&(M.date=T.date.value,E.push("date")),T.activityType.value&&T.activityType.confidence>=D&&!w.activityType){const R=ma(T.activityType.value),U=ue[T.activityType.value];M.activityType=T.activityType.value,M.hours=((k=R.defaultHours)==null?void 0:k.toString())||w.hours,M.isMaterialParticipation=(U==null?void 0:U.autoEnable)||w.isMaterialParticipation,E.push("activity")}return T.description.value&&T.description.confidence>=.6&&!w.description.trim()&&(M.description=T.description.value,E.push("description")),M}),h("applied"),v(E.length>0?`Filled ${E.join(", ")} from uploaded evidence.`:"Scan complete. Please fill the remaining fields manually.")}catch(F){if(q!==S.current)return;console.error("Evidence extraction failed:",F),h("failed"),v("We couldn't scan this evidence. You can still log the entry manually.")}},I=ce({mutationFn:async _=>await As.createTimeEntry(_,x),onSuccess:_=>{Us(void 0,{entry_method:"manual",hours_logged:parseFloat(n.hours),activity_type:n.activityType,has_evidence:x.length>0,is_material_participation:n.isMaterialParticipation,is_qualified_non_material:n.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"]}),O();const q=x.length>0?` with ${x.length} evidence file(s)`:"";s({title:"Success",description:`Time entry logged successfully${q}`})},onError:_=>{if(It(_)){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 _=>await As.enhanceDescription(_),onSuccess:_=>{_.success&&(o(q=>({...q,description:_.result.enhancedDescription})),N(!0),setTimeout(()=>N(!1),2e3),s({title:"Description Enhanced",description:`AI improvements applied with ${Math.round(_.result.confidence*100)}% confidence`}))},onError:_=>{if(It(_)){s({title:"Unauthorized",description:"You are logged out. Logging in again...",variant:"destructive"}),setTimeout(()=>{window.location.href="/api/login"},500);return}if(jn(_)){s({title:"Shield Advisor Required",description:rs(_),variant:"destructive"}),c(!0);return}s({title:"Enhancement Failed",description:_.message||"Failed to enhance description",variant:"destructive"})},onSettled:()=>{u(!1)}});return{formData:n,setFormData:o,selectedFiles:x,setSelectedFiles:p,handleFilesSelected:m,evidenceExtractionStatus:P,evidenceExtractionMessage:C,isEnhancingDescription:b,descriptionGlowing:y,showPaywallModal:f,setShowPaywallModal:c,handleSubmit:_=>{if(_.preventDefault(),!n.hours||!n.activityType){s({title:"Validation Error",description:"Please fill in all required fields",variant:"destructive"});return}const q=parseFloat(n.hours);if(q<.0167||q>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:T,isQualifiedNonMaterial:E}=n;if(!T&&!E){s({title:"Validation Error",description:"Please select Material Participation or Qualified Non-Material",variant:"destructive"});return}if(T&&E){s({title:"Validation Error",description:"You can only select one activity type",variant:"destructive"});return}}I.mutate(n)},handleEnhanceDescription:async()=>
31{if(!n.description.trim()){s({title:"No Description",description:"Please enter a description first",variant:"destructive"});return}Ka(void 0,{original_description_length:n.description.length,activity_type:n.activityType,has_property_selected:n.propertyId!=="none"}),u(!0);const _=t.find(q=>q.id.toString()===n.propertyId);A.mutate({originalDescription:n.description,activityType:n.activityType,propertyNickname:_==null?void 0:_.nickname})},handleVoiceTranscription:(_,q)=>{var T;let F=q;if(F||(F=(D=>{const g=D.toLowerCase();let w="",M="",k=Vt();const R=[/(\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 R){const K=g.match(V);if(K){w=K[1];break}}if(g.includes("today"))k=Vt();else if(g.includes("yesterday")){const V=new Date;V.setDate(V.getDate()-1),k=Vt(V)}const U=st;for(const V of U)if(V.label.toLowerCase().split(" ").filter(W=>W.length>2&&g.includes(W)).length>0){M=V.value;break}return{hours:w,date:k,activityType:M,description:D,confidence:.5,propertyType:void 0}})(_)),F.hours&&F.activityType&&F.date){const E={date:F.date,hours:F.hours.toString(),activityType:F.activityType,propertyId:"none",propertyType:F.propertyType||l,description:`Voice entry: ${_}`,isMaterialParticipation:!1,isQualifiedNonMaterial:!1};I.mutate(E),s({title:"Voice Entry Created!",description:`Automatically logged ${F.hours} hours for ${((T=st.find(D=>D.value===F.activityType))==null?void 0:T.label)||F.activityType}.`,duration:5e3})}else{o(D=>({...D,hours:F.hours?F.hours.toString():D.hours,date:F.date||D.date,activityType:F.activityType||D.activityType,description:_,propertyType:F.propertyType||D.propertyType}));const E=[];F.hours||E.push("hours"),F.activityType||E.push("activity type"),F.date||E.push("date"),s({title:"Form Pre-filled",description:`Missing: ${E.join(", ")}. Please complete and submit manually.`,variant:"default"})}},createTimeEntryMutation:I,enhanceDescriptionMutation:A,resetForm:O,isSubmitting:I.isPending}}function An({formData:t,setFormData:a,selectedFiles:s,setSelectedFiles:r,evidenceExtractionStatus:i="idle",evidenceExtractionMessage:l,properties:n,handleSubmit:o,handleEnhanceDescription:x,isEnhancingDescription:p,descriptionGlowing:b,navigateToProperties:u,isSubmitting:y=!1,selectedYear:N,scanEnabled:f=!0,evidenceFirst:c=!1}){var m,I;const{user:P}=$t(),{toast:h}=fe(),C=(P==null?void 0:P.repType)==="shortTerm"?"Short-term Rental":"Long-term Rental",v=new Date().getFullYear(),S=t.date?new Date(t.date).getFullYear()<v:!1;d.useEffect(()=>{S&&h({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"})},[S]);const O=e.jsxs("div",{children:[e.jsx(B,{className:"text-sm font-normal mb-2 block",children:"Evidence (Optional)"}),e.jsx(Ya,{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"]}),f&&i==="scanning"&&e.jsx("div",{className:"mt-3",children:e.jsx(Ba,{title:"Extracting evidence details",label:"Time entry evidence",description:l||"Reading your upload to suggest a date, activity type, and description. Hours and property stay ready for you to confirm."})}),f&&i==="applied"&&l&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-green-600",children:[e.jsx(at,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:l})]}),f&&i==="failed"&&l&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-amber-600",children:[e.jsx(Xt,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:l})]})]});return e.jsxs("form",{onSubmit:o,className:"space-y-4",children:[S&&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(Xt,{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."})]})]})}),c&&O,e.jsxs("div",{className:"form-mobile-stack",children:[e.jsxs("div",{className:"form-mobile-full",children:[e.jsxs(B,{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(L=>({...L,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(B,{htmlFor:"activityType",className:"text-sm font-normal",children:["Activity Type ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Bs,{value:t.activityType,onValueChange:A=>{const L=ma(A),H=ue[A];a($=>{var _;return{...$,activityType:A,hours:((_=L.defaultHours)==null?void 0:_.toString())||$.hours,isMaterialParticipation:(H==null?void 0:H.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(Le,{className:"h-4 w-4 inline mr-1"}),"Auto-filled with suggested hours. You can adjust as needed."]})]})]}),e.jsxs("div",{children:[e.jsx(Ys,{value:t.hours,onChange:A=>a(L=>({...L,hours:A})),label:"Hours",required:!0,suggestedHours:t.activityType?(I=(m=st.find(A=>A.value===t.activityType))==null?void 0:m.defaultHours)==null?void 0:I.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(Le,{className:"h-4 w-4 inline mr-1"}),"Select an activity to auto-fill suggested hours"]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"propertyId",className:"text-sm font-normal",children:"Property (Optional)"}),e.jsxs("div",{className:"form-mobile-stack","data-tour":"properties-section",children:[e.jsxs(ke,{value:t.propertyId,onValueChange:A=>{const L=n.find(H=>H.id.toString()===A);a(H=>({...H,propertyId:A,propertyType:(L==null?void 0:L.propertyType)||C}))},children:[e.jsx(Ce,{className:"flex-1 touch-target text-xs text-gray-600",children:e.jsx(Se,{placeholder:"Select property...",className:"mt-1 text-xs text-gray-600"})}),e.jsxs(Te,{children:[e.jsx(te,{value:"none",className:"touch-target text-xs text-gray-600",children:"No property"}),n.map(A=>e.jsxs(te,{value:A.id.toString(),className:"text-xs text-gray-600",children:[A.nickname," - ",A.address]},A.id))]})]}),e.jsxs(G,{type:"button",variant:"outline",size:"sm",onClick:()=>u(),className:"touch-target button-mobile-full",children:[e.jsx(Ee,{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(Me,{id:"materialParticipation",checked:t.isMaterialParticipation,onCheckedChange:A=>a(L=>({...L,isMaterialParticipation:A,isQualifiedNonMaterial:A?!1:L.isQualifiedNonMaterial}))}),e.jsx(B,{htmlFor:"materialParticipation",className:"text-sm font-normal",children:"Material Participation Activity"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Me,{id:"qualifiedNonMaterial",checked:t.isQualifiedNonMaterial,onCheckedChange:A=>a(L=>({...L,isQualifiedNonMaterial:A,isMaterialParticipation:A?!1:L.isMaterialParticipation}))}
31),e.jsx(B,{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(B,{htmlFor:"description",className:"text-sm font-normal",children:"Description"}),e.jsx(G,{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:x,disabled:p||!t.description,children:p?e.jsx("span",{className:"animate-pulse",children:"Enhancing..."}):e.jsxs(e.Fragment,{children:[e.jsx(Wa,{className:"h-3 w-3 mr-1"}),"AI Enhance"]})})]}),e.jsx(Lt,{id:"description",value:t.description,onChange:A=>a(L=>({...L,description:A.target.value})),placeholder:"Describe your activity...",className:z("touch-target text-sm transition-all duration-500",b&&"shadow-[0_0_15px_rgba(168,85,247,0.5)] border-purple-400")})]}),!c&&O,e.jsx(G,{type:"submit",className:"w-full touch-target",disabled:y,children:y?"Logging...":"Log Time"})]})}function Gs({properties:t}){const[a,s]=d.useState(!1),[r,i]=d.useState(null),{formData:l,setFormData:n,selectedFiles:o,setSelectedFiles:x,handleFilesSelected:p,evidenceExtractionStatus:b,evidenceExtractionMessage:u,isEnhancingDescription:y,descriptionGlowing:N,showPaywallModal:f,setShowPaywallModal:c,handleSubmit:P,handleEnhanceDescription:h,isSubmitting:C}=Dn(t),v=()=>{localStorage.setItem("add-property-from-dashboard","true"),window.location.href="/properties"};if(!r)return e.jsx(Ja,{onSelect:i});const S=r==="smart",O=S?p:x;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:S?"Smart Assistant":"Manual Entry"}),e.jsx(Xa,{onClick:()=>i(null)})]}),e.jsx(An,{formData:l,setFormData:n,selectedFiles:o,setSelectedFiles:O,evidenceExtractionStatus:b,evidenceExtractionMessage:u,properties:t,handleSubmit:P,handleEnhanceDescription:h,isEnhancingDescription:y,descriptionGlowing:N,navigateToProperties:v,isSubmitting:C,scanEnabled:S,evidenceFirst:S}),e.jsx(es,{open:f,onOpenChange:c,feature:"AI Description Enhancement"})]})}function Fn({isOpen:t,onClose:a,session:s}){const[r,i]=d.useState(!0),[l,n]=d.useState("chat"),o=s.isPremium,x=d.useRef(null);return d.useEffect(()=>{if(t&&x.current){const p=setTimeout(()=>{x.current&&(x.current.scrollTop=x.current.scrollHeight)},100);return()=>clearTimeout(p)}},[t]),d.useEffect(()=>{t&&i(!0)},[t]),e.jsx(ve,{open:t,onOpenChange:p=>!p&&a(),children:e.jsxs(Za,{children:[e.jsx(er,{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(tr,{className:"fixed inset-x-0 bottom-0 top-20 z-50 flex flex-col overflow-hidden rounded-t-[28px] border border-border bg-background shadow-xl outline-none md:inset-0 md:rounded-none md:border-0 md:bg-[linear-gradient(180deg,rgba(205,250,254,0.86)_0%,rgba(225,247,252,0.56)_10%,rgba(255,255,255,0.97)_28%,rgb(255,255,255)_100%)] md:shadow-none dark:md:bg-[linear-gradient(180deg,rgba(8,47,73,0.56)_0%,rgba(15,23,42,0.92)_28%,rgb(2,6,23)_100%)]",children:[e.jsxs("div",{className:"relative z-10 grid grid-cols-[2.25rem_minmax(0,auto)_2.25rem] items-center overflow-hidden px-5 pt-5 pb-3 shrink-0 bg-gradient-to-r from-cyan-50 via-sky-50 to-emerald-50 shadow-[0_22px_48px_-30px_rgba(34,211,238,0.70)] dark:from-cyan-950/40 dark:via-slate-950 dark:to-emerald-950/30 md:flex md:h-16 md:justify-between md:bg-none md:px-8 md:py-0 md:shadow-none",children:[e.jsx("div",{className:"pointer-events-none absolute left-1/2 top-2 h-1 w-12 -translate-x-1/2 rounded-full bg-slate-400/35 md:hidden"}),e.jsx("div",{className:"hidden md:block"}),e.jsx("div",{className:"col-start-2 flex items-center justify-center justify-self-center md:hidden",children:e.jsxs(sr,{children:[e.jsx(ar,{asChild:!0,children:e.jsxs("button",{type:"button",className:"inline-flex h-10 items-center gap-2 rounded-md px-3 text-lg font-semibold text-foreground transition-colors hover:bg-white/50",children:[l==="chat"?"Chat":"History",e.jsx(ea,{className:"h-5 w-5"})]})}),e.jsxs(rr,{align:"center",className:"w-36",children:[e.jsx(ks,{onClick:()=>n("chat"),children:"Chat"}),e.jsx(ks,{onClick:()=>n("history"),children:"History"})]})]})}),e.jsxs("div",{className:"col-start-3 flex items-center justify-self-end md:ml-auto md:gap-2",children:[o&&e.jsx("button",{type:"button","aria-label":r?"Hide chat history":"Show chat history",onClick:()=>i(p=>!p),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(Wr,{className:"h-4 w-4"}):e.jsx(Jr,{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(Br,{className:"h-4 w-4"})}),e.jsx(ir,{"aria-label":"Close chat",className:"inline-flex items-center justify-center h-9 w-9 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:x,className:"flex-1 min-h-0 w-full flex flex-col overflow-y-auto",children:e.jsx("div",{className:"w-full h-full flex flex-col px-6 py-4",children:e.jsx(At,{session:s,isExpanded:!0})})})}),e.jsx("div",{className:z("shrink-0 overflow-hidden transition-all duration-200",o&&r?"w-72 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(Ft,{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:l==="chat"?e.jsx("div",{className:"h-full px-4 pt-3 pb-4 flex flex-col overflow-hidden",children:e.jsx(At,{session:s,isExpanded:!0})}):e.jsx("div",{className:"h-full bg-muted/40",children:e.jsx(Ft,{isPremium:s.isPremium,activeConversationId:s.activeConversationId,onSelectConversation:p=>
31{s.setActiveConversationId(p),n("chat")},onNewChat:()=>{s.startNewConversation(),n("chat")}})})})]})]})})}function In(t){return t>=80?"bg-emerald-500":t>=50?"bg-amber-400":"bg-red-500"}function Rn(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 Ln({answered:t,total:a}){const s=t===a;return e.jsxs("span",{className:z("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(at,{className:"h-3.5 w-3.5"}):e.jsx("span",{className:z("h-2 w-2 rounded-full shrink-0",t===0?"bg-red-400":"bg-amber-400")}),t,"/",a]})}const _n=[{key:"filingStatus",fallback:"Filing status not set"},{key:"employmentType",fallback:"Employment not set"},{key:"involvementStyle",fallback:"Involvement not set"}],On={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-Managed",hybrid:"Hybrid",pm_runs_most:"PM-Led",mostly_passive:"Passive"};function Hn(t,a){if(a==null||a==="")return null;const s=String(a);return On[s]??s}function $n({field:t,value:a,onUpdate:s,onDebouncedUpdate:r,isUpdating:i,hint:l}){var n;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(B,{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"}),l&&a===null&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 leading-relaxed",children:l})]}),e.jsx(Me,{id:t.key,checked:a===!0,disabled:i,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(B,{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:i,onChange:o=>{const x=o.target.value;if(x==="")return;const p=parseInt(x,10);isNaN(p)||r(t.key,p)},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(B,{htmlFor:t.key,className:"text-sm font-medium",children:t.label}),e.jsxs(ke,{value:typeof a=="string"?a:"",disabled:i,onValueChange:o=>s(t.key,o),children:[e.jsx(Ce,{className:"max-w-[280px] h-8 text-sm",id:t.key,children:e.jsx(Se,{placeholder:"Not set"})}),e.jsx(Te,{children:(n=t.options)==null?void 0:n.map(o=>e.jsx(te,{value:o.value,children:o.label},o.value))})]})]})}function qn(){const{profile:t,isLoading:a,isError:s,refetch:r,updateField:i,debouncedUpdateField:l,isUpdating:n}=nr(),{suggestions:o}=lr(),x=(v,S)=>i(v,S),p=(v,S)=>l(v,S);if(a)return e.jsx(he,{children:e.jsxs(le,{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(he,{children:e.jsxs(le,{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(G,{variant:"outline",size:"sm",onClick:()=>r(),children:[e.jsx(Ze,{className:"h-4 w-4 mr-2"}),"Retry"]})]})});const b=t,u=Cs.map(v=>({...v,...Ss(v.key,b)})),y=u.reduce((v,S)=>v+S.answered,0),N=u.reduce((v,S)=>v+S.total,0),f=N>0?Math.round(y/N*100):0,c=Rn(f),P=u.filter(v=>v.answered<v.total).map(v=>v.key),h=(()=>{const v=o==null?void 0:o.priorYearRepsQualified;
31if(!(!v||!v.suggested))return`Based on your ${v.year} logged hours (${v.hours} hrs), you appear to have qualified. Please confirm.`})(),C=_n.map(({key:v,fallback:S})=>{const O=Hn(v,b[v]);return{key:v,label:O,fallback:S}});return e.jsxs(he,{className:"overflow-hidden",children:[e.jsxs(vt,{className:"pb-4",children:[e.jsxs(jt,{className:"flex items-center gap-2 text-lg sm:text-xl font-semibold",children:[e.jsx(zr,{className:"h-5 w-5 text-primary shrink-0"}),"AI Tax Profile"]}),e.jsx(or,{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(le,{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:[f,"%"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[y," of ",N," fields answered"]})]}),e.jsx(Z,{variant:"outline",className:c.className,children:c.label})]}),e.jsx("div",{className:"relative h-1.5 w-full overflow-hidden rounded-full bg-border",children:e.jsx("div",{className:z("h-full rounded-full transition-all duration-500",In(f)),style:{width:`${f}%`}})}),e.jsx("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pt-0.5",children:C.map(({key:v,label:S,fallback:O},m)=>e.jsxs("span",{className:"flex items-center gap-1.5 text-xs",children:[m>0&&e.jsx("span",{className:"text-border","aria-hidden":!0,children:"·"}),S?e.jsx("span",{className:"font-medium text-foreground",children:S}):e.jsx("span",{className:"text-muted-foreground italic",children:O})]},v))})]}),e.jsx(oa,{type:"multiple",defaultValue:P,className:"rounded-xl border divide-y overflow-hidden",children:Cs.map(v=>{const S=dr(v.key,b);if(S.length===0)return null;const{answered:O,total:m}=Ss(v.key,b),I=O===m;return e.jsxs(Mt,{value:v.key,className:"border-0",children:[e.jsx(Et,{className:z("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:z("h-1.5 w-1.5 rounded-full shrink-0",I?"bg-emerald-500":"bg-amber-400"),"aria-hidden":!0}),v.label,e.jsx(Ln,{answered:O,total:m})]})}),e.jsx(Pt,{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:S.map(A=>e.jsx($n,{field:A,value:b[A.key]??null,onUpdate:x,onDebouncedUpdate:p,isUpdating:n,hint:A.key==="priorYearRepsQualified"?h:void 0},A.key))})})]},v.key)})})]})]})}const zn={"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 Gn({onClose:t}){const{viewMode:a,setViewMode:s,isSaving:r}=xa(),[i,l]=d.useState(a),n=()=>{s(i,{onSuccess:()=>t()})};return d.useEffect(()=>{l(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(G,{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(qr,{type:"single",value:i,onValueChange:o=>o&&l(o),"aria-label":"View Mode",className:"flex w-full rounded-lg border border-slate-200 dark:border-slate-700",children:[e.jsx(Qt,{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(Qt,{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(Qt,{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:zn[i]})]}),e.jsx("section",{children:e.jsx("div",{className:"border-t border-slate-100 dar
31k:border-slate-800 pt-6",children:e.jsx(qn,{})})})]}),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(G,{onClick:n,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 Vn({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:z("shrink-0 border-r border-border/60 overflow-hidden transition-all duration-200",s?"w-48":"w-0"),children:s&&e.jsx(Ft,{isPremium:t.isPremium,activeConversationId:t.activeConversationId,onSelectConversation:t.setActiveConversationId,onNewChat:t.startNewConversation})}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden",children:e.jsx(At,{session:t})})]})}function Qn({properties:t}){const a=cr(),{viewMode:s}=xa(),[r,i]=d.useState(!1),[l,n]=d.useState(!1),[o,x]=d.useState("chat"),p=s!=="classic-only";return e.jsx(mr,{children:e.jsxs("div",{"data-tour":"time-logging-form",className:"dashboard-card",children:[e.jsx(he,{className:z("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:l?"rotateY(180deg)":"rotateY(0deg)"},children:[e.jsxs("div",{className:z("h-full flex flex-col overflow-hidden rounded-lg bg-card transition-[background-color,background-image] duration-200 group-focus-within:bg-[linear-gradient(180deg,rgba(202,250,254,0.94)_0%,rgba(220,247,252,0.62)_14%,rgba(255,255,255,0.98)_34%,rgb(255,255,255)_100%)] dark:group-focus-within:bg-[linear-gradient(180deg,rgba(8,47,73,0.58)_0%,rgba(15,23,42,0.90)_32%,rgb(2,6,23)_100%)]",l&&"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:[p&&e.jsx("button",{type:"button","aria-label":"Expand chat",onClick:()=>i(!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(Gr,{className:"h-4 w-4"})}),e.jsx("button",{type:"button","aria-label":"Chat settings",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(ft,{className:"h-4 w-4"})})]})}),s==="ai-only"&&e.jsx("div",{className:"relative flex-1 min-h-0",children:e.jsxs(le,{className:"absolute inset-0 p-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-2 bg-transparent",children:[e.jsx("button",{type:"button",onClick:()=>x("chat"),className:o==="chat"?"h-12 border-b-2 border-foreground text-sm font-medium text-foreground transition-colors":"h-12 text-sm font-medium text-muted-foreground transition-colors hover:text-foreground",children:"Chat"}),e.jsx("button",{type:"button",onClick:()=>x("history"),className:o==="history"?"h-12 border-b-2 border-foreground text-sm font-medium text-foreground transition-colors":"h-12 text-sm font-medium text-muted-foreground transition-colors hover:text-foreground",children:"History"})]}),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(At,{session:a})}):e.jsx("div",{className:"h-full bg-transparent",children:e.jsx(Ft,{isPremium:a.isPremium,activeConversationId:a.activeConversationId,onSelectConversation:b=>{a.setActiveConversationId(b),x("chat")},onNewChat:()=>{a.startNewConversation(),x("chat")}})})})]})}),s==="classic-only"&&e.jsx(le,{className:"p-6 pt-4",children:e.jsx(Gs,{properties:t})}),s==="hybrid"&&e.jsxs(ls,{defaultValue:"chat",className:"flex flex-col flex-1",children:[e.jsx("div",{className:"px-6 pt-4 pb-0",children:e.jsxs(os,{className:"w-full",children:[e.jsxs(pt,{value:"chat",className:"flex-1 gap-1.5",children:[e.jsx(xr,{className:"h-4 w-4"}),"AI Chat"]}),e.jsxs(pt,{value:"classic",className:"flex-1 gap-1.5",children:[e.jsx(Ee,{className:"h-4 w-4"}),"Classic"]})]})}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(gt,{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(le,{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(Vn,{session:a,sidebarOpen:!1})})})}),e.jsx(gt,{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(le,{className:"p-6 pt-4",children:e.jsx(Gs,{properties:t})})})]})]})]}),e.jsx("div",{className:`absolute inset-0 h-full w-full ${l?"":"pointer-events-none"}`,style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"},children:e.jsx(Gn,{onClose:()=>n(!1)})})]})}),e.jsx(Fn,{isOpen:r,onClose:()=>i(!1),session:a})]})})}const Kn={gmail:{name:"Gmail",icon:Qr,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:Vr,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:_e,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:pe,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 Tt({open:t,onOpenChange:a,integrationType:s,isConnected:r,isLoading:i,onConnect:l,onDisconnect:n}){const o=Kn[s],x=o.icon;return e.jsx(ve,{open:t,onOpenChange:a,children:e.jsxs(De,{className:"sm:max-w-[500px]",children:[e.jsxs(Ae,{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(x,{className:`w-6 h-6 ${o.color}`})}),e.jsxs("div",{children:[e.jsxs(Fe,{className:"text-xl",children:[r?"Disconnect":"Connect"," ",o.name]}),r&&e.jsxs(Z,{variant:"outline",className:"mt-1 bg-green-50 text-green-700 border-green-300",children:[e.jsx(at,{className:"w-3 h-3 mr-1"}),"Connected"]})]})]}),e.jsx(_t,{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(Ht,{className:"w-4 h-4 text-yellow-500"}),"What you'll get:"]}),e.jsx("ul",{className:"space-y-2",children:o.features.map((p,b)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(at,{className:"w-4 h-4 text-green-600 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:p})]},b))})]}),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-slate-100 dar
31k:bg-slate-800 flex items-center justify-center flex-shrink-0",children:e.jsx(ur,{className:"w-4 h-4 text-slate-600 dark:text-slate-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(hr,{className:"w-3 h-3"}),"Secure OAuth 2.0"]}),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("p",{className:"text-sm text-amber-800 dark:text-amber-200",children:[e.jsx("strong",{children:"Warning:"})," Disconnecting will stop automatic tracking from this integration. Your existing time entries will not be affected."]})})}),e.jsxs(pr,{children:[e.jsx(G,{variant:"outline",onClick:()=>a(!1),disabled:i,children:"Cancel"}),r?e.jsx(G,{variant:"destructive",onClick:n,disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(ut,{className:"w-4 h-4 mr-2 animate-spin"}),"Disconnecting..."]}):"Disconnect"}):e.jsx(G,{onClick:l,disabled:i,className:"bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800",children:i?e.jsxs(e.Fragment,{children:[e.jsx(ut,{className:"w-4 h-4 mr-2 animate-spin"}),"Connecting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"w-4 h-4 mr-2"}),"Connect ",o.name]})})]})]})})}const Vs=()=>{var u,y,N,f,c,P;const{startTour:t,hasCompletedOnboarding:a,setHasCompletedOnboarding:s}=ca(),r=ua(),i=new Date().getFullYear(),{data:l}=ne({queryKey:["/api/stats/rep-requirements/all",{year:i}]}),n=(l==null?void 0:l.requirements)||[],o=h=>{h&&localStorage.setItem("repshield_onboarding_completed","true"),s(!0)},x=()=>{localStorage.setItem("repshield_onboarding_completed","true"),t()},p=h=>{h&&o(!0)};if(sa()||r)return null;const b=[{icon:e.jsx(ge,{className:"h-5 w-5 text-blue-500"}),title:"Time Tracking",description:"Log hours for all your real estate activities"},{icon:e.jsx(Dt,{className:"h-5 w-5 text-green-500"}),title:"Evidence Upload",description:"Attach supporting documents for audit protection"},{icon:e.jsx(gr,{className:"h-5 w-5 text-purple-500"}),title:"Progress Tracking",description:"Monitor your REP status progress in real-time"},{icon:e.jsx(fr,{className:"h-5 w-5 text-orange-500"}),title:"AI Assistant",description:"Get expert guidance on REP requirements"},{icon:e.jsx(tt,{className:"h-5 w-5 text-red-500"}),title:"Property Management",description:"Organize and track all your rental properties"},{icon:e.jsx(hs,{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(ve,{open:!a,onOpenChange:h=>!h&&o(!1),children:e.jsxs(De,{className:"max-w-2xl w-[95vw] sm:w-auto max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ae,{children:[e.jsx(Fe,{className:"text-xl sm:text-2xl font-bold text-center",children:"Welcome to REPSShield! ð"}),e.jsxs(_t,{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:b.map((h,C)=>e.jsx(he,{className:"border-l-4 border-l-primary",children:e.jsx(le,{className:"p-4",children:e.jsxs("div",{className:"flex items-start space-x-3",children:[h.icon,e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:h.title}),e.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:h.description})]})]})})},C))}),e.jsx(he,{className:"bg-gradient-to-r from-blue-50 to-purple-50 dark:from-blue-900/20 dark:to-purple-900/20",children:e.jsxs(le,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center space-x-2 mb-3",children:[e.jsx(ds,{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(Z,{variant:"outline",className:"mb-2",children:"Long-Term Rental"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400",children:[((u=n==null?void 0:n.find(h=>h.repType==="longTerm"))==null?void 0:u.totalHoursRequired)||750," ","hours annually",((y=n==null?void 0:n.find(h=>h.repType==="longTerm"))==null?void 0:y.materialHoursRequired)&&` (${(N=n.find(h=>h.repType==="longTerm"))==null?void 0:N.materialHoursRequired} material + ${(f=n.find(h=>h.repType==="longTerm"))==null?void 0:f.qualifiedNonMaterialRequired} qualified)`]})]}),e.jsxs("div",{children:[e.jsx(Z,{variant:"outline",className:"mb-2",children:"Short-Term Rental"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400",children:[((c=n==null?void 0:n.find(h=>h.repType==="shortTerm"))==null?void 0:c.totalHoursRequired)||500," ","hour or"," ",((P=n==null?void 0:n.find(h=>h.repType==="shortTerm"))==null?void 0:P.materialHoursRequired)||100," ","hour material participation"]})]})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2 justify-center",children:[e.jsx(mt,{id:"do-not-show-again",onCheckedChange:p}),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(G,{variant:"outline",onClick:()=>o(!1),className:"flex items-center justify-center space-x-2",children:e.jsx("span",{children:"Skip for now"})}),e.jsxs(G,{onClick:x,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(ge,{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 Un({trigger:t,activityType:a,title:s="File Activity History"}
31){const[r,i]=d.useState(!1),{data:l=[],isLoading:n,refetch:o}=ne({queryKey:["/api/file-activities",a],queryFn:async()=>{const N=a?`/api/file-activities?type=${a}`:"/api/file-activities",f=await fetch(N,{credentials:"include"});if(!f.ok)throw new Error("Failed to fetch file activities");return f.json()},enabled:r});d.useEffect(()=>{r&&o()},[r,o]);const x=(N,f)=>f==="processing"?e.jsx(ge,{className:"w-4 h-4 text-yellow-500"}):f==="failed"?e.jsx(rt,{className:"w-4 h-4 text-red-500"}):N==="import"?e.jsx(ha,{className:"w-4 h-4 text-blue-500"}):N==="export"?e.jsx(Ts,{className:"w-4 h-4 text-green-500"}):e.jsx(Dt,{className:"w-4 h-4 text-gray-500"}),p=N=>{switch(N){case"completed":return e.jsxs(Z,{variant:"outline",className:"text-green-600 border-green-200 bg-green-50",children:[e.jsx(ds,{className:"w-3 h-3 mr-1"}),"Completed"]});case"failed":return e.jsxs(Z,{variant:"outline",className:"text-red-600 border-red-200 bg-red-50",children:[e.jsx(rt,{className:"w-3 h-3 mr-1"}),"Failed"]});case"processing":return e.jsxs(Z,{variant:"outline",className:"text-yellow-600 border-yellow-200 bg-yellow-50",children:[e.jsx(ge,{className:"w-3 h-3 mr-1"}),"Processing"]});default:return null}},b=N=>{if(!N)return"Unknown size";const f=["Bytes","KB","MB","GB"],c=Math.floor(Math.log(N)/Math.log(1024));return Math.round(N/Math.pow(1024,c)*100)/100+" "+f[c]},u=async N=>{if(N.canDownload)try{if(na(void 0,{report_type:N.activityType==="export"?"csv_export":"file_download",file_name:N.originalFileName,file_size_kb:Math.round(N.fileSize/1024),entries_count:N.recordCount}),N.downloadUrl){window.open(N.downloadUrl,"_blank");return}const f=await fetch(`/api/file-activities/download/${N.id}`,{credentials:"include"});if(!f.ok)throw new Error("Download failed");const c=await f.blob(),P=window.URL.createObjectURL(c),h=document.createElement("a");h.href=P,h.download=N.originalFileName,document.body.appendChild(h),h.click(),window.URL.revokeObjectURL(P),document.body.removeChild(h)}catch(f){console.error("Download error:",f)}},y=e.jsxs(G,{variant:"outline",size:"sm",children:[e.jsx(ss,{className:"w-4 h-4 mr-2"}),a==="import"?"Import History":a==="export"?"Export History":"File History"]});return e.jsxs(ve,{open:r,onOpenChange:i,children:[e.jsx(br,{asChild:!0,children:t||y}),e.jsxs(De,{className:"max-w-2xl max-h-[80vh]",children:[e.jsx(Ae,{children:e.jsxs(Fe,{className:"flex items-center",children:[e.jsx(ss,{className:"w-5 h-5 mr-2"}),s]})}),e.jsx(la,{className:"max-h-[60vh] pr-4",children:n?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 rounded-full"})}):l.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-500",children:[e.jsx(Dt,{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:l.map((N,f)=>e.jsx(he,{className:"relative",children:e.jsxs(le,{className:"p-4",children:[f<l.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:x(N.activityType,N.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:N.originalFileName}),p(N.status)]}),e.jsxs("div",{className:"flex items-center text-xs text-gray-500",children:[e.jsx(pe,{className:"w-3 h-3 mr-1"}),Y(new Date(N.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:N.activityType}),e.jsx("span",{children:b(N.fileSize)}),e.jsxs("span",{children:[N.recordCount," records"]}),e.jsxs("span",{className:"text-blue-600",children:[e.jsx(aa,{className:"w-3 h-3 inline mr-1"}),N.userName]})]}),N.canDownload&&e.jsxs(G,{variant:"ghost",size:"sm",onClick:()=>u(N),className:"h-6 px-2 text-xs",children:[e.jsx(Ts,{className:"w-3 h-3 mr-1"}),"Download"]})]}),N.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:[N.metadata.importType&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Import Type:"})," ",N.metadata.importType]}),N.metadata.exportType&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Export Type:"})," ",N.metadata.exportType]}),N.metadata.successfulImports!==void 0&&e.jsxs("div",{className:"text-green-600",children:[e.jsx("span",{className:"font-medium",children:"Successful:"})," ",N.metadata.successfulImports]}),N.metadata.errors>0&&e.jsxs("div",{className:"text-red-600",children:[e.jsx("span",{className:"font-medium",children:"Errors:"})," ",N.metadata.errors]}),N.metadata.duplicatesSkipped>0&&e.jsxs("div",{className:"text-orange-600",children:[e.jsx("span",{className:"font-medium",children:"Skipped:"})," ",N.metadata.duplicatesSkipped]})]})})]})]})]})},N.id))})}),e.jsx(yr,{}),e.jsxs("div",{className:"flex justify-between items-center text-xs text-gray-500",children:[e.jsxs("span",{children:[l.length," ",l.length===1?"activity":"activities"," total"]}),e.jsxs(G,{variant:"ghost",size:"sm",onClick:()=>o(),children:[e.jsx($r,{className:"w-3 h-3 mr-1"}),"Refresh"]})]})]})]})}function Qs({open:t,onOpenChange:a}){const[s,r]=d.useState("upload"),[i,l]=d.useState(null),[n,o]=d.useState([]),[x,p]=d.useState([]),[b,u]=d.useState({}
31),[y,N]=d.useState([]),[f,c]=d.useState([]),[P,h]=d.useState(0),{showDuring:C}=vr(),[v,S]=d.useState({success:0,errors:0,duplicates:0}),{toast:O}=fe(),m=Pe(),I=E=>{if(!E||!E.trim())return"";const D=E.toLowerCase().trim(),g=st.find(k=>k.value.toLowerCase()===D);if(g)return g.value;const w=st.find(k=>k.label.toLowerCase()===D);if(w)return w.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 k of M)if(k.keywords.some(R=>D.includes(R)))return k.activity;return"maintenance-repairs"},A=E=>{if(!E||!E.trim())return{isValid:!1,normalized:"",error:"Date is required"};const D=E.trim();if(/^\d{4}-\d{2}-\d{2}$/.test(D)){const M=new Date(D);if(!isNaN(M.getTime()))return{isValid:!0,normalized:D}}const g=/^(\d{1,2})\/(\d{1,2})\/(\d{2,4})$/,w=D.match(g);if(w){let[,M,k,R]=w;R.length===2&&(R=parseInt(R)<=30?`20${R}`:`19${R}`),M=M.padStart(2,"0"),k=k.padStart(2,"0");const U=`${R}-${M}-${k}`,V=new Date(U);if(!isNaN(V.getTime()))return{isValid:!0,normalized:U}}try{const M=new Date(D);if(!isNaN(M.getTime())){const k=M.getFullYear(),R=String(M.getMonth()+1).padStart(2,"0"),U=String(M.getDate()).padStart(2,"0");return{isValid:!0,normalized:`${k}-${R}-${U}`}}}catch{}return{isValid:!1,normalized:"",error:"Invalid date format. Use MM/DD/YY, MM/DD/YYYY, or YYYY-MM-DD"}},L=[{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}],H=d.useCallback(E=>{var g;const D=(g=E.target.files)==null?void 0:g[0];if(D){if(!D.name.toLowerCase().endsWith(".csv")){O({title:"Invalid File Type",description:"Please upload a CSV file (.csv)",variant:"destructive"});return}if(D.size>1024*1024){O({title:"File Too Large",description:"Please upload a file smaller than 1MB",variant:"destructive"});return}l(D);try{jr.parse(D,{header:!0,skipEmptyLines:!0,complete:w=>{if(w.errors&&w.errors.length>0){console.error("CSV Parsing Errors:",w.errors),O({title:"CSV Parse Error",description:`There was an error parsing your CSV file: ${w.errors[0].message}`,variant:"destructive"});return}const k=(w.meta.fields||[]).map(V=>V.replace(/^\uFEFF/,"").trim()).filter(V=>V),R=w.data;if(k.length===0){console.error("No headers found in CSV"),O({title:"CSV Parse Error",description:"No valid headers found in the CSV file",variant:"destructive"});return}p(k),o(R);const U={};k.forEach(V=>{const K=V.toLowerCase().trim();K==="date"||K==="day"||K.includes("date")||K.includes("day")?U[V]="date":K==="hours"||K==="hour"||K==="time"||K.includes("hour")||K.includes("time")?U[V]="hours":K==="activity"||K==="type"||K==="task"||K.includes("activity")||K.includes("type")||K.includes("task")?U[V]="activityType":K==="description"||K==="note"||K==="notes"||K.includes("description")||K.includes("note")||K.includes("comment")?U[V]="description":K.includes("property")||K.includes("rental")?U[V]="propertyType":(K.includes("material")||K.includes("participation"))&&(U[V]="isMaterialParticipation")}),u(U),r("mapping")},error:w=>{console.error("Papa.parse error:",w),O({title:"CSV Parse Error",description:w.message,variant:"destructive"})}})}catch(w){console.error("Exception during Papa.parse:",w),O({title:"CSV Parse Error",description:"An unexpected error occurred while parsing the CSV file",variant:"destructive"})}}},[O]),$=(E,D)=>{u(g=>({...g,[E]:D||""}))},_=()=>{const E=[],D=[],g=L.filter(M=>M.required),w=Object.values(b).filter(M=>M&&M!=="");for(const M of g)if(!w.includes(M.key)){O({title:"Missing Required Mapping",description:`Please map a column to ${M.label}`,variant:"destructive"});return}
31n.slice(0,5).forEach((M,k)=>{const R={};Object.entries(b).forEach(([U,V])=>{var ee;if(!V||V==="")return;const K=(ee=M[U])==null?void 0:ee.trim();if(R[V]=K,V==="date"){const W=A(K);W.isValid?R[V]=W.normalized:E.push({row:k+1,field:V,value:K||"",message:W.error||"Invalid date format"})}else if(V==="hours"){const W=parseFloat(K);(isNaN(W)||W<.0167||W>24)&&E.push({row:k+1,field:V,value:K||"",message:"Hours must be between 1 minute and 24 hours"})}else if(V==="activityType"&&K){const W=I(K);R[V]=W,W||E.push({row:k+1,field:V,value:K||"",message:"Could not match activity type"})}}),R.propertyType=R.propertyType||"Long-term Rental",R.isMaterialParticipation=R.isMaterialParticipation==="Yes"||R.isMaterialParticipation==="true"||R.isMaterialParticipation==="1",D.push(R)}),c(E),N(D),r("preview")},q=async()=>{Cr(void 0,{import_type:"csv",rows_to_import:n.length});try{await C((async()=>{const E=n.map(w=>{const M={};return Object.entries(b).forEach(([k,R])=>{var V;if(!R||R==="")return;const U=(V=w[k])==null?void 0:V.trim();if(R==="date"){const K=A(U);M[R]=K.isValid?K.normalized:U}else R==="activityType"?M[R]=U&&I(U):M[R]=U}),M.propertyType=M.propertyType||"Long-term Rental",M.isMaterialParticipation=M.isMaterialParticipation==="Yes"||M.isMaterialParticipation==="true"||M.isMaterialParticipation==="1",M}),g=await(await me("POST","/api/import/csv",{data:E})).json();Sr(void 0,{file_type:"csv",rows_imported:g.success||0,total_rows:E.length,success_rate:g.success?g.success/E.length:0}),S(g),h(100),r("complete"),m.invalidateQueries({queryKey:["/api/time-entries"]}),m.invalidateQueries({queryKey:["/api/stats/total-hours"]}),m.invalidateQueries({queryKey:["/api/stats/material-participation-hours"]}),m.invalidateQueries({queryKey:["/api/stats/activity-breakdown"]})})(),{message:"Importing your time entries...",subMessage:`Processing ${n.length} entries from your CSV file`})}catch(E){O({title:"Import Failed",description:E.message||"Failed to import CSV data",variant:"destructive"}),r("preview")}},F=()=>{r("upload"),l(null),o([]),p([]),u({}),N([]),c([]),h(0),S({success:0,errors:0,duplicates:0})},T=()=>{F(),a(!1)};return e.jsx(ve,{open:t,onOpenChange:a,children:e.jsxs(De,{className:"max-w-4xl max-h-[80vh] overflow-y-auto",children:[e.jsx(Ae,{children:e.jsxs(Fe,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(ha,{className:"h-5 w-5 mr-2"}),"Import Time Entries from CSV"]}),e.jsx(Un,{activityType:"import",title:"Import History",trigger:e.jsxs(G,{variant:"outline",size:"sm",children:[e.jsx(ss,{className:"w-4 h-4 mr-2"}),"History"]})})]})}),s==="upload"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(lt,{children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx(ot,{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(B,{htmlFor:"csv-file",children:"Select CSV File (Max 1MB)"}),e.jsx(ye,{id:"csv-file",type:"file",accept:".csv",onChange:H,className:"cursor-pointer"})]}),e.jsx("div",{className:"flex justify-end space-x-2",children:e.jsx(G,{variant:"outline",onClick:T,children:"Cancel"})})]}),s==="mapping"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(lt,{children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx(ot,{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:x.map(E=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs(B,{className:"text-sm font-medium",children:["Your Column: ",e.jsx("span",{className:"font-mono bg-gray-100 px-1 rounded",children:E})]}),e.jsxs(ke,{value:b[E]||"skip",onValueChange:D=>$(E,D==="skip"?"":D),children:[e.jsx(Ce,{children:e.jsx(Se,{placeholder:"Select target field..."})}),e.jsxs(Te,{children:[e.jsx(te,{value:"skip",children:"-- Skip this column --"}),L.map(D=>e.jsxs(te,{value:D.key,children:[D.label," ",D.required&&"*"]},D.key))]})]})]},E))}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(G,{variant:"outline",onClick:()=>r("upload"),children:"Back"}),e.jsx(G,{variant:"outline",onClick:T,children:"Cancel"}),e.jsx(G,{onClick:_,children:"Preview Import"})]})]}),s==="preview"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(lt,{children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx(ot,{children:"Preview of the first 5 rows. Review the data before importing."})]}),f.length>0&&e.jsxs(lt,{variant:"destructive",children:[e.jsx(rt,{className:"h-4 w-4"}),e.jsxs(ot,{children:["Found ",f.length," validation errors:",e.jsx("ul",{className:"mt-2 list-disc list-inside",children:f.slice(0,5).map((E,D)=>e.jsxs("li",{className:"text-sm",children:["Row ",E.row,", ",E.field,": ",E.message,' (value: "',E.value,'")']},D))})]})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(Nr,{children:[e.jsx(wr,{children:e.jsxs(Ms,{children:[e.jsx(Ve,{children:"Date"}),e.jsx(Ve,{children:"Hours"}),e.jsx(Ve,{children:"Activity Type"}),e.jsx(Ve,{children:"Description"}),e.jsx(Ve,{children:"Property Type"}),e.jsx(Ve,{children:"Material Participation"})]})}),e.jsx(kr,{children:y.map((E,D)=>e.jsxs(Ms,{children:[e.jsx(Qe,{className:"font-mono text-sm",children:E.date||"â"}),e.jsx(Qe,{children:E.hours||"â"}),e.jsx(Qe,{children:E.activityType||"â"}),e.jsx(Qe,{className:"max-w-xs truncate",children:E.description||"â"}
31),e.jsx(Qe,{children:E.propertyType||"Long-term Rental"}),e.jsx(Qe,{children:e.jsx(Z,{variant:E.isMaterialParticipation?"default":"secondary",children:E.isMaterialParticipation?"Yes":"No"})})]},D))})]})}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx(G,{variant:"outline",onClick:()=>r("mapping"),children:"Back to Mapping"}),e.jsx(G,{variant:"outline",onClick:T,children:"Cancel"}),e.jsxs(G,{onClick:q,disabled:f.length>0,children:["Import ",n.length," Entries"]})]})]}),s==="complete"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs(lt,{children:[e.jsx(ds,{className:"h-4 w-4"}),e.jsx(ot,{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:v.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:v.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:v.errors}),e.jsx("div",{className:"text-sm text-gray-600",children:"Errors"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(G,{onClick:T,children:"Close"})})]})]})})}const Yn=()=>null;function Ml(){var de,je,X,Ne,we,Oe,He;const{user:t,isLoading:a,isAuthenticated:s}=$t(),r=Pe(),i=ua(),{hasMounted:l}=fn();bn();const{subscription:n,hasActiveSubscription:o,subscribe:x,isSubscribing:p,isOnTrial:b}=da();yn({subscription:n,user:t});const u=!!(t!=null&&t.stripeSubscriptionId)&&((t==null?void 0:t.subscriptionStatus)==="active"||(t==null?void 0:t.subscriptionStatus)==="trialing");hn(),pn();const y=new Date().getFullYear(),[N,f]=d.useState(y),{totalHours:c,materialHours:P,properties:h,recentEntries:C,pendingCount:v,teamStats:S}=Tr(t==null?void 0:t.id,N),O=d.useMemo(()=>Array.isArray(h)?h:[],[h]),m=C||[],I=vn({user:t,totalHours:c,materialHours:P,selectedYear:N}),A=Nn(o),L=Pa(),{gmailStatusQuery:H,microsoftMailStatusQuery:$,imapStatusQuery:_,googleCalendarStatusQuery:q,microsoftCalendarStatusQuery:F,handleGoogleCalendarConnect:T,handleMicrosoftCalendarConnect:E,disconnectGoogleCalendarMutation:D,disconnectMicrosoftCalendarMutation:g,isGoogleCalendarConnecting:w,isMicrosoftCalendarConnecting:M}=bt(),k=((de=q.data)==null?void 0:de.connected)||!1,R=((je=F.data)==null?void 0:je.connected)||!1,[U,V]=d.useState(!1),[K,ee]=d.useState(!1),[W,xe]=d.useState(!1),Ie=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws`;if(gn({url:Ie,enabled:!!t&&s,delayMs:1500,onMessage:ae=>{ae.type==="time_entry_update"&&r.invalidateQueries({queryKey:["/api/time-entries/recent"]})},onError:ae=>console.warn("[WebSocket] Connection error:",ae)}),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(!l)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(i){const ae=!!((X=H.data)!=null&&X.connected||(Ne=$.data)!=null&&Ne.connected||(we=_.data)!=null&&we.connected),$e=!!($.error||_.error),it=!!((Oe=_.data)!=null&&Oe.connected&&((He=_.data)==null?void 0:He.credentialValid)===!1),qe=!!(k||R),nt=!!(q.error||F.error);return e.jsxs(e.Fragment,{children:[e.jsx(mn,{user:t,isSubscribed:u,isOnTrial:b,progress:{totalHours:I.totalHoursValue,goalHours:I.goalHours,percentComplete:I.progressPercentage,remainingHours:I.remainingHours,selectedYear:N,materialHours:I.materialHoursValue,materialGoalHours:I.materialGoal},pendingReviewCount:v,mailConnected:ae,mailHasError:$e,mailHasCredentialIssue:it,calendarConnected:qe,calendarHasError:nt,selectedYear:N,onYearChange:f}),e.jsx(Qs,{open:W,onOpenChange:xe}),e.jsx(qs,{open:L.showForm,onOpenChange:L.setShowForm}),e.jsx(Vs,{}),e.jsx(es,{open:A.showPaywallModal,onOpenChange:A.setShowPaywallModal,onSubscribe:x,isSubscribing:p}),e.jsx(Tt,{open:U,onOpenChange:V,integrationType:"google-calendar",isConnected:k,isLoading:w||D.isPending,onConnect:T,onDisconnect:()=>D.mutate()}),e.jsx(Tt,{open:K,onOpenChange:ee,integrationType:"microsoft-calendar",isConnected:R,isLoading:M||g.isPending,onConnect:E,onDisconnect:()=>g.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:[!i&&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(as,{selectedYear:N,onYearChange:f,currentYear:y,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(as,{selectedYear:N,onYearChange:f,currentYear:y})}),e.jsx("div",{"data-tour":"rep-type-selector",children:e.jsx(Mn,{user:t,timeEntries:m,selectedYear:N,pendingCount:v})})]})]}),e.jsx("div",{className:"mb-3",children:e.jsx(Ta,{userId:t.id,isSubscribed:u,isOnTrial:b,mobileInstallCompleted:t.mobileInstallCompleted})}),e.jsx("div",{className:"mb-3",children:e.jsx(Ma,{userId:t.id,isSubscribed:u})}),e.jsx("div",{className:"mb-3",children:e.jsx(Yn,{})}),e.jsx("div",{children:e.jsx(Pn,{totalHours:I.totalHoursValue,materialHours:I.materialHoursValue,timeEntries:m,user:t,teamStats:S,selectedYear:N,pendingCount:v,onAddTimeEntry:()=>{const ae=document.querySelector('[data-tour="time-logging-form"]');ae&&ae.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:[!i&&e.jsx(Qn,{properties:O}),e.jsx("div",{className:"dashboard-card",children:e.jsx(kn,{setGoogleCalendarDialogOpen:V,setMicrosoftCalendarDialogOpen:ee})}),i?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"dashboard-card",children:e.jsx(Ds,{})}),e.jsx("div",{"data-tour":"recent-activity",className:"dashboard-card",children:e.jsx($s,{})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{"data-tour":"recent-activity",className:"dashboard-card",children:e.jsx($s,{})}),e.jsx("div",{className:"dashboard-card",children:e.jsx(Ds,{})})]})]}),e.jsx(Qs,{open:W,onOpenChange:xe}),e.jsx(qs,{open:L.showForm,onOpenChange:L.setShowForm}),e.jsx(Vs,{}),e.jsx(es,{open:A.showPaywallModal,onOpenChange:A.setShowPaywallModal,onSubscribe:x,isSubscribing:p}),e.jsx(Tt,{open:U,onOpenChange:V,integrationType:"google-calendar",isConnected:k,isLoading:w||D.isPending,onConnect:T,onDisconnect:()=>D.mutate()}),e.jsx(Tt,{open:K,onOpenChange:ee,integrationType:"microsoft-calendar",isConnected:R,isLoading:M||g.isPending,onConnect:E,onDisconnect:()=>g.mutate()})]})}export{Ml 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.