1import{y as Kr,j as t,dj as Er,m as Yr,as as Qn,i as Xr,bT as vt,bU as wt,bV as jt,bW as bt,bX as Nt,dz as St,bY as Ct,bZ as kt,b_ as Rt,ac as ae,bi as Xe,a as ye,aC as Ft,az as ge,dA as Mr,aZ as cr,a_ as ur,a$ as gr,b0 as pr,F as Ye,B as L,Y as ft,D as xt,W as Mt,Q as ut,R as gt,aI as re,A as Gt,V as rr,L as Ie,_ as be,$ as Ne,a0 as _e,a1 as Se,a2 as te,e as ne,aP as Jr,aQ as Zr,aR as Ee,aS as Fe,aT as en,aU as ce,K as ve,bk as Kn,h as tn,ae as Yn,f as mr,aK as fr,aG as rn,aH as mt,cq as nn,d1 as Xn,a5 as Ae,a3 as Pr,C as Pe,b as Pt,d as De,d2 as Jn,cj as Zn,b6 as sn,af as an,dB as nr,aY as Dr,bh as es,bI as ts,b1 as rs,ab as Ir,dq as ln,dr as on,dC as $r,ds as dn,dD as ns,aF as sr,bH as ss,E as is,G as as,I as _r,cY as ls,dE as os,bG as ds,dF as Dt,dG as cn,bO as cs,bP as us,bQ as gs,cR as ps,cL as ms,cl as Ar,aJ as fs,cX as hs,dp as xe,bq as Ut,cQ as xs,w as ys,dH as vs,n as ws,X as js,l as bs,dt as It,dI as Ns,dJ as Tr}from"./index-Byg2HWAE.js";import{r as v,c as un}from"./vendor-Qgthw7N1.js";import{C as yt}from"./checkbox-Cqr9jids.js";import{F as Ss}from"./file-spreadsheet-BmInesC3.js";import{A as Vr}from"./archive-DwAjs2Bp.js";import{F as Lr}from"./filter-ejjrE0l5.js";import{S as gn,t as Ke,A as Hr}from"./timeEntryService-DBf_VWTS.js";import{c as Cs,F as Or,D as ks}from"./useFileAccessUrl-6aqd6eyh.js";import{B as Rs}from"./building-Bc-otC-f.js";import{C as zr}from"./circle-x-C3yul9_R.js";import{u as Fs,a as qt}from"./use-transform-CXyDomQV.js";import{S as Es}from"./square-pen-D8PHEJvM.js";import{C as Ms}from"./copy-DV8e8Olv.js";import"./file-image-Er1ZOYVg.js";import"./hard-drive-436CTEuo.js";import"./share-2-BwzmsqEz.js";import"./maximize-2-D7IQEluU.js";/** 2 * @license lucide-react v0.453.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ps=Kr("Ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]);/** 7 * @license lucide-react v0.453.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Br=Kr("Package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["path",{d:"m3.3 7 7.703 4.734a2 2 0 0 0 1.994 0L20.7 7",key:"yx3hmr"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]);function pn(e){switch((e==null?void 0:e.toLowerCase().trim())||""){case"manual":return"Manual Entry";case"stopwatch":return"Stopwatch";case"gmail":return"Gmail";case"calendar":case"calendar_rules":case"rules":return"Calendar";case"geofence":return"Location Visit";default:return e||"Unknown"}}function mn(e){switch((e==null?void 0:e.toLowerCase().trim())||""){case"manual":return t.jsx(Er,{className:"h-4 w-4 text-gray-400 dark:text-gray-400"});case"stopwatch":return t.jsx(Xr,{className:"h-4 w-4 text-gray-400 dark:text-gray-400"});case"gmail":return t.jsx(Qn,{className:"h-4 w-4 text-gray-400 dark:text-gray-400"});case"calendar":case"calendar_rules":case"rules":return t.jsx(Yr,{className:"h-4 w-4 text-gray-400 dark:text-gray-400"});case"geofence":return t.jsx("span",{className:"text-base leading-none",role:"img","aria-label":"Location Visit",children:"ð§ââï¸"});default:return t.jsx(Er,{className:"h-4 w-4 text-gray-400 dark:text-gray-400"})}}function Lt(e){switch(e.toLowerCase().split(".").pop()){case"pdf":return"application/pdf";case"jpg":case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";case"doc":return"application/msword";case"webp":return"image/webp";case"docx":return"application/vnd.openxmlformats-officedocument.wordprocessingml.document";default:return"application/octet-stream"}}const Gr={select:{weight:3,minWidth:"50px"},date:{weight:7,minWidth:"110px"},hours:{weight:6,minWidth:"90px"},activityType:{weight:12,minWidth:"120px"},description:{weight:22,minWidth:"140px"},property:{weight:13,minWidth:"140px"}
11,evidences:{weight:7,minWidth:"80px"},source:{weight:6,minWidth:"80px"},propertyType:{weight:12,minWidth:"120px"},approval:{weight:7,minWidth:"80px"},restore:{weight:7,minWidth:"80px"}};function Ds(e,s){const r=Gr[e];if(!r)return{};const n=s.reduce((a,l)=>{var o;return a+(((o=Gr[l])==null?void 0:o.weight)||0)},0);return{width:`${(n>0?r.weight/n*100:0).toFixed(2)}%`,minWidth:r.minWidth}}function $t(e,s,r=""){const n=Ds(e,s),i=!["select","evidences","approval","description","source"].includes(e);let a=r.replace(/px-6/g,"px-3").replace(/py-3/g,"py-4").replace(/py-1/g,"py-3").replace(/align-middle/g,"align-top");e==="select"&&(a=a.replace(/px-3/g,"px-2").replace(/text-left/g,"text-center flex items-center justify-center")),["evidences","approval"].includes(e)&&(a=a.replace(/text-left/g,"text-center flex items-center justify-center")),e==="source"&&(a=a.replace(/text-left/g,"text-left flex items-center justify-start"));const m=`${a} ${i?"truncate":""} ${e==="description"?"overflow-hidden":""} min-w-0 align-top`.trim(),p={width:n.width,minWidth:n.minWidth};return{className:m,style:p}}function Is({open:e,onOpenChange:s,entry:r,onConfirm:n,isDeleting:i}){return t.jsx(vt,{open:e,onOpenChange:s,children:t.jsxs(wt,{className:"rounded-xl shadow-lg border border-gray-200",children:[t.jsxs(jt,{children:[t.jsx(bt,{className:"text-lg font-semibold text-gray-900",children:"Delete Time Entry"}),t.jsxs(Nt,{className:"text-sm text-gray-600 leading-relaxed",children:["This action"," ",t.jsx("span",{className:"font-medium text-red-600",children:"cannot be undone"}),". Are you sure you want to delete this time entry?",r&&t.jsxs("div",{className:"mt-3 p-3 bg-gray-50 border border-gray-200 rounded-lg text-sm text-gray-700",children:[t.jsx("div",{className:"font-medium text-gray-900",children:r.activityType}),t.jsxs("div",{className:"text-xs text-gray-500",children:[r.hours,"h ⢠",St(r.date,"MMM d, yyyy")]})]}),t.jsx("p",{className:"mt-3 text-xs italic",children:'Note: Deleted entries can be restored from the "Show Deleted" view.'})]})]}),t.jsxs(Ct,{className:"flex justify-end space-x-2",children:[t.jsx(kt,{disabled:i,className:"px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-100 transition",children:"Cancel"}),t.jsx(Rt,{onClick:n,disabled:i,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition flex items-center",children:i?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{className:"mr-2 h-4 w-4"}),"Delete Entry"]})})]})]})})}function $s({open:e,onOpenChange:s,selectedCount:r,onConfirm:n,isDeleting:i}){return t.jsx(vt,{open:e,onOpenChange:s,children:t.jsxs(wt,{className:"rounded-xl shadow-lg border border-gray-200",children:[t.jsxs(jt,{children:[t.jsx(bt,{className:"text-lg font-semibold text-gray-900",children:"Delete Multiple Entries"}),t.jsxs(Nt,{className:"text-sm text-gray-600 leading-relaxed",children:["Are you sure you want to delete"," ",t.jsx("span",{className:"font-medium text-gray-900",children:r})," ","selected time entries?",t.jsx("p",{className:"mt-3 text-xs italic",children:'Note: Deleted entries can be restored from the "Show Deleted" view.'})]})]}),t.jsxs(Ct,{className:"flex justify-end space-x-2",children:[t.jsx(kt,{disabled:i,className:"px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-100 transition",children:"Cancel"}),t.jsx(Rt,{onClick:n,disabled:i,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition flex items-center",children:i?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{className:"mr-2 h-4 w-4"}),"Delete ",r," Entries"]})})]})]})})}function _s({steps:e,currentIndex:s}){var r;return t.jsxs("div",{className:"mt-4",children:[t.jsx("div",{className:"flex items-center justify-center gap-1 sm:gap-2",children:e.map((n,i)=>{const a=i<s,l=i===s;return t.jsxs(un.Fragment,{children:[i>0&&t.jsx("div",{className:re("h-px flex-1 max-w-6 sm:max-w-12 transition-colors",a?"bg-green-500":"bg-muted-foreground
11/20")}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:re("w-6 h-6 rounded-full flex items-center justify-center text-xs font-medium shrink-0 transition-colors",a&&"bg-green-500 text-white",l&&"bg-primary text-primary-foreground ring-2 ring-primary/20",!a&&!l&&"bg-muted text-muted-foreground"),children:a?t.jsx(mr,{className:"w-3 h-3"}):i+1}),t.jsx("span",{className:re("text-xs font-medium hidden sm:inline",l?"text-foreground":"text-muted-foreground"),children:n.label})]})]},n.key)})}),t.jsx("p",{className:"text-xs text-center text-muted-foreground mt-2 sm:hidden",children:(r=e[s])==null?void 0:r.label})]})}const Wt=["date","hours","activityType","description","propertyName","isMaterialParticipation","approvalStatus"],Qt={date:{required:!0,alternatives:["date","entry_date","activity_date","timestamp","when"],validation:e=>{if(!(e!=null&&e.trim()))return{valid:!1,error:"Date is required"};const s=new Date(e);return{valid:!isNaN(s.getTime()),error:"Invalid date format"}}},hours:{required:!0,alternatives:["hours","time","duration","hours_worked","time_spent"],validation:e=>{const s=parseFloat(e);return isNaN(s)?{valid:!1,error:"Hours must be a number"}:s<.0167||s>24?{valid:!1,error:"Hours must be between 1 minute and 24 hours"}:{valid:!0}}},activityType:{required:!0,alternatives:["activityType","activity_type","activity","type","task_type"],validation:e=>e!=null&&e.trim()?{valid:!0}:{valid:!1,error:"Activity type is required"}},description:{required:!1,alternatives:["description","notes","details","comments","summary"],validation:()=>({valid:!0})},propertyName:{required:!1,alternatives:["propertyName","property_name","property","location","address"],validation:()=>({valid:!0})},isMaterialParticipation:{required:!1,alternatives:["isMaterialParticipation","material_participation","material","mp"],validation:e=>{if(!(e!=null&&e.trim()))return{valid:!0};const s=e.toLowerCase();return{valid:["true","false","yes","no","1","0"].includes(s)}}},approvalStatus:{required:!1,alternatives:["approvalStatus","approval_status","status","approved"],validation:e=>{if(!(e!=null&&e.trim()))return{valid:!0};const s=e.toLowerCase();return{valid:["pending","approved"].includes(s)}}}};function As({open:e,onClose:s,onImportComplete:r,properties:n}){const[i,a]=v.useState("select"),[l,o]=v.useState("upload"),[c,g]=v.useState(null),[m,p]=v.useState([]),[u,d]=v.useState([]),[f,x]=v.useState({}),[C,y]=v.useState([]),[w,S]=v.useState([]),[h,b]=v.useState(0),[k,M]=v.useState(null),[D,T]=v.useState({success:0,errors:0,duplicates:0}),[I,U]=v.useState(!1),[q,Q]=v.useState(null),[Z,de]=v.useState(!1),{toast:J}=ye(),Ve=v.useRef(null),Je=()=>{if(i==="select")return"sm:max-w-lg";switch(l){case"upload":return"sm:max-w-lg";case"mapping":return"sm:max-w-2xl";case"preview":return"sm:max-w-5xl";case"importing":return"sm:max-w-md";case"complete":return"sm:max-w-md";default:return"sm:max-w-lg"}},Le=()=>i==="template"?[{key:"upload",label:"Upload"},{key:"preview",label:"Preview"},{key:"complete",label:"Import"}]:[{key:"upload",label:"Upload"},{key:"mapping",label:"Map"},{key:"preview",label:"Preview"},{key:"complete",label:"Import"}],Ze=()=>{const N=Le(),R=l==="importing"?"complete":l;return Math.max(0,N.findIndex(P=>P.key===R))},et=Le(),tt=Ze(),rt=i!=="select"&&l!=="importing",le=w.filter(N=>N.severity==="error"),je=w.filter(N=>N.severity==="warning"),Be=Ft({mutationFn:async N=>(await ge("POST","/api/ai/map-csv",N)).json(),onSuccess:N=>{N.success&&(Q(N.result),y(N.result.mappedData),S([]),o("preview"),J({title:"AI Mapping Complete",description:`Mapped ${N.result.mappedData.length} rows with ${Math.round(N.result.overallConfidence*100)}% confidence`}))},onError:N=>{J({title:"AI Mapping Failed",description:N.message||"Failed to map CSV data with AI",variant:"destructive"});const R=ue(u);x(R),o("mapping")},onSettled:()=>{U(!1)}}),nt=v.useCallback(()=>{const N=Wt,R=["2024-01-15","2.5","property-management","Conducted property inspection and tenant screening",n.length>0?n[0].nickname||n[0].address:"","true","pending"],P=[N.join(","),R.map(F=>`"${F}"`).join(",")].join(` 12`),$=new Blob([P],{type:"text/csv;charset=utf-8;"}),O=document.createElement("a"),z=URL.createObjectURL($);O.setAttribute("href",z),O.setAttribute("download","time-entries-template.csv"),O.style.visibility="hidden",document.body.appendChild(O),O.click(),document.body.removeChild(O),J({title:"Template Downloaded",description:"Fill out the template and upload it for guaranteed compatibility."})},[n,J]),ue=v.useCallback(N=>{const R={};return Object.entries(Qt).forEach(([P,$])=>{const O=N.find(z=>{const F=z.toLowerCase().trim();return $.alternatives.some(B=>B.toLowerCase()===F||F.includes(B.toLowerCase())||B.toLowerCase().includes(F))});O&&(R[O]=P)}),R},[]),Ge=v.useCallback((N,R)=>{const P=[],$=[];
12return N.forEach((O,z)=>{const F={};if(Object.entries(R).forEach(([B,H])=>{var fe;const X=((fe=O[B])==null?void 0:fe.trim())||"";F[H]=X;const Ce=Qt[H];if(Ce){const qe=Ce.validation(X);qe.valid||P.push({row:z+1,field:H,value:X,message:qe.error||"Invalid value",severity:"error"})}}),F.propertyName&&F.propertyName.trim()){const B=F.propertyName.trim(),H=n.find(X=>{var Ce,fe;return((Ce=X.nickname)==null?void 0:Ce.toLowerCase())===B.toLowerCase()||((fe=X.address)==null?void 0:fe.toLowerCase())===B.toLowerCase()||`${X.nickname} - ${X.address}`.toLowerCase()===B.toLowerCase()});H?(F.propertyId=H.id,F.propertyDisplayName=H.nickname||H.address):n.length===0?F.propertyDisplayName=B:(F.propertyDisplayName=B,P.push({row:z+1,field:"propertyName",value:B,message:`Property '${B}' not found â select one from the dropdown or import without it.`,severity:"warning"}))}if(F.isMaterialParticipation){const B=F.isMaterialParticipation.toLowerCase();F.isMaterialParticipation=["true","yes","1"].includes(B)}F.approvalStatus&&!["pending","approved"].includes(F.approvalStatus)&&(F.approvalStatus="pending"),$.push(F)}),S(P),y($),P.length===0},[n]),me=v.useCallback(N=>{const R=[],P=N.map(F=>F.trim()),$=[...Wt],O=$.filter(F=>!P.includes(F));O.length>0&&R.push(`Missing required columns: ${O.join(", ")}`);const z=P.filter(F=>!$.includes(F)&&F.trim()!=="");return z.length>0&&R.push(`Unexpected columns found: ${z.join(", ")}`),R.length===0&&(P.length!==$.length?R.push(`Expected ${$.length} columns, but found ${P.length}.`):P.every((B,H)=>B===$[H])||R.push("Column order does not match template. Please ensure columns are in the exact order: "+$.join(", "))),{isValid:R.length===0,errors:R}},[]),He=v.useCallback(N=>{if(!N.name.toLowerCase().endsWith(".csv")){J({title:"Invalid File Type",description:"Please upload a CSV file (.csv)",variant:"destructive"});return}if(N.size>5*1024*1024){J({title:"File Too Large",description:"Please upload a file smaller than 5MB",variant:"destructive"});return}g(N),Mr.parse(N,{header:!0,skipEmptyLines:!0,complete:R=>{if(R.errors&&R.errors.length>0){console.error("Parse errors:",R.errors),J({title:"Parse Error",description:`Failed to parse CSV file: ${R.errors[0].message}`,variant:"destructive"});return}const P=R.meta.fields||[];if(P.length===0){console.error("No headers found"),J({title:"Parse Error",description:"No valid headers found in the CSV file",variant:"destructive"});return}if(d(P),p(R.data),i==="template"){const $=me(P);if(!$.isValid){console.error("Template format validation failed:",$.errors),M($.errors.join(` 13`));return}M(null);const O={};P.forEach(z=>{Wt.includes(z)&&(O[z]=z)}),x(O),Ge(R.data,O),o("preview")}else{U(!0),o("mapping");const $=R.data.slice(0,10);Be.mutate({csvHeaders:P,csvRows:$})}},error:R=>{console.error("Papa.parse error:",R),J({title:"Upload Error",description:R.message,variant:"destructive"})}})},[i,ue,Ge,me,J]),st=v.useCallback(async()=>{if(!C.length)return;o("importing"),b(0);const N={success:0,errors:0,duplicates:0};try{for(let R=0;R<C.length;R++){const P=C[R];b((R+1)/C.length*100);try{const $=new FormData;$.append("date",P.date||""),$.append("hours",P.hours||""),$.append("activityType",P.activityType||""),$.append("description",P.description||""),$.append("isMaterialParticipation",(P.isMaterialParticipation||!1).toString()),$.append("isQualifiedNonMaterial",(P.isQualifiedNonMaterial||!1).toString()),$.append("source","manual"),P.propertyId&&P.propertyId!==""&&$.append("propertyId",P.propertyId.toString()),(await ge("POST","/api/time-entries",$)).ok?N.success++:N.errors++,await new Promise(z=>setTimeout(z,50))}catch{N.errors++}}T(N),o("complete"),J({title:"Import Complete",description:`Successfully imported ${N.success} entries${N.errors>0?` (${N.errors} errors)`:""}.`}),r()}catch{J({title:"Import Failed",description:"An error occurred during import. Please try again.",variant:"destructive"}),o("preview")}},[C,r,J]),Oe=v.useCallback(()=>{a("select"),o("upload"),g(null),p([]),d([]),x({}),y([]),S([]),b(0),T({success:0,errors:0,duplicates:0}),M(null),de(!1),U(!1),Q(null)},[]),Ue=v.useCallback(()=>{Oe(),s()},[Oe,s]),it=v.useCallback(()=>{l==="upload"?(a("select"),g(null),M(null)):l==="mapping"?(o("upload"),g(null),p([]),d([]),Q(null),U(!1),x({})):l==="preview"&&(i==="smart"?o("mapping"):(o("upload"),g(null),p([]),d([]),y([]),S([]),x({})))},[l,i]),at=v.useCallback(N=>{N.preventDefault(),N.stopPropagation()},[]),lt=v.useCallback(N=>{N.preventDefault(),N.stopPropagation(),de(!0)},[]),ot=v.useCallback(N=>{N.preventDefault(),N.stopPropagation(),de(!1)},[]),dt=v.useCallback(N=>{var P;N.preventDefault(),N.stopPropagation(),de(!1);const R=(P=N.dataTransfer.files)==null?void 0:P[0];R&&(M(null),He(R))},[He]),se=v.useCallback((N,R,P)=>{const $=[...C];$[N]={...$[N],[R]:P},y($)},[C]);return t.jsx(cr,{open:e,onOpenChange:Ue,children:t.jsxs(ur,{className:re("p-0 gap-0 flex flex-col overflow-hidden transition-[max-width] duration-300 ease-in-out",Je()),children:[t.jsxs("div",{className:"shrink-0 px-6 pt-6 pb-3 border-b",children:[t.jsx(gr,{children:t.jsx(pr,{className:"text-base font-semibold",children:"Import Time Entries"})}),i!=="select"&&t.jsx(_s,{steps:et,currentIndex:tt})]}),t.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:t.jsxs("div",{className:"animate-in fade-in-0 duration-200",children:[i==="select"&&t.jsxs("div",{className:"space-y-5 py-2",children:[t.jsxs("div",{className:"text-center space-y-1.5",children:[t.jsx(Ye,{className:"w-10 h-10 mx-auto text-muted-foreground"}),t.jsx("h3",{className:"font-semibold",children:"Upload CSV File"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Import time entries from a spreadsheet"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsxs(L,{onClick:()=>{a("template"),o("upload")},className:"w-full bg-green-600 hover:bg-green-700 text-white",size:"lg",children:[t.jsx(ft,{className:"w-4 h-4 mr-2"}),"Upload Template CSV"]}),t.jsxs("button",{onClick:nt,className:"w-full text-sm text-muted-foreground hover:text-foreground underline underline-offset-4 transition-colors py-1",children:[t.jsx(xt,{className:"w-3.5 h-3.5 inline mr-1"}),"Download template first"]})]}),t.jsxs("div",{className:"relative",children:[t.jsx("div",{className:"absolute inset-0 flex items-center",children:t.jsx("div",{className:"w-full border-t"})}),t.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:t.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or"})})]}),t.jsxs(L,{onClick:()=>{a("smart"),o("upload")},variant:"outline",className:"w-full",children:[t.jsx(Mt,{className:"w-4 h-4 mr-2"}),"Smart Import (AI Column Mapping)"]})]}),i!=="select"&&l==="upload"&&t.jsxs("div",{className:"space-y-4",children:[i==="template"&&k&&t.jsxs(ut,{variant:"destructive",children:[t.jsx(zr,{className:"h-4 w-4"}),t.jsxs(gt,{children:[t.jsx("div",{className:"font-medium mb-1",children:"Template Format Error"}),t.jsx("div",{className:"whitespace-pre-line text-sm",children:k}),t.jsxs(L,{variant:"outline",size:"sm",className:"mt-3 border-purple-300 text-purple-700 hover:bg-purple-50 dark:border-purple-600 dar
13k:text-purple-300 dark:hover:bg-purple-900/30",onClick:()=>{M(null),a("smart"),c&&(g(null),setTimeout(()=>{a("smart"),g(c),Mr.parse(c,{header:!0,skipEmptyLines:!0,complete:N=>{const R=N.meta.fields||[];d(R),p(N.data),U(!0),o("mapping");const P=N.data.slice(0,10);Be.mutate({csvHeaders:R,csvRows:P})}})},0))},children:[t.jsx(Mt,{className:"w-3.5 h-3.5 mr-1.5"}),"Try Smart Import instead"]})]})]}),c?t.jsxs("div",{className:"border rounded-lg p-6 text-center space-y-3",children:[t.jsx(Ye,{className:"w-10 h-10 mx-auto text-green-600"}),t.jsxs("div",{children:[t.jsx("p",{className:"font-medium",children:c.name}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:[(c.size/1024).toFixed(1)," KB"]})]}),t.jsx("button",{onClick:()=>{g(null),M(null),Ve.current&&(Ve.current.value="")},className:"text-sm text-muted-foreground hover:text-foreground underline underline-offset-4 transition-colors",children:"Choose a different file"})]}):t.jsxs("div",{onDragOver:at,onDragEnter:lt,onDragLeave:ot,onDrop:dt,onClick:()=>{var N;M(null),(N=Ve.current)==null||N.click()},className:re("border-2 border-dashed rounded-lg p-8 text-center transition-colors cursor-pointer",Z?"border-primary bg-primary/5":"border-muted-foreground/25 hover:border-muted-foreground/50"),children:[t.jsx(ft,{className:re("w-10 h-10 mx-auto mb-3 transition-colors",Z?"text-primary":"text-muted-foreground")}),t.jsx("p",{className:"font-medium",children:Z?"Drop your file here":"Drag & drop your CSV file"}),t.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:i==="template"?"or click to browse â use the template format":"or click to browse â any CSV format"})]}),t.jsx("input",{ref:Ve,type:"file",accept:".csv",onChange:N=>{var P;const R=(P=N.target.files)==null?void 0:P[0];R&&(M(null),He(R))},className:"hidden"})]}),i==="smart"&&l==="mapping"&&t.jsx("div",{className:"space-y-4",children:I?t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Mt,{className:"w-4 h-4 text-primary animate-pulse"}),t.jsx("p",{className:"text-sm font-medium",children:"AI is analyzing your columns..."})]}),t.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(N=>t.jsxs("div",{className:"flex items-center gap-3 animate-pulse",children:[t.jsx("div",{className:"w-1/3 h-9 bg-muted rounded"}),t.jsx(Gt,{className:"w-4 h-4 text-muted-foreground/40 shrink-0"}),t.jsx("div",{className:"flex-1 h-9 bg-muted rounded"})]},N))})]}):t.jsxs("div",{className:"space-y-4",children:[q?t.jsxs(ut,{children:[t.jsx(Mt,{className:"h-4 w-4"}),t.jsxs(gt,{children:["AI mapped your columns with"," ",Math.round(q.overallConfidence*100),"% confidence. Review and adjust if needed."]})]}):t.jsxs(ut,{children:[t.jsx(rr,{className:"h-4 w-4"}),t.jsx(gt,{children:"AI mapping failed. We've generated basic mappings â please review."})]}),t.jsx("div",{className:"space-y-3",children:Object.entries(Qt).map(([N,R])=>{var $;const P=(($=Object.entries(f).find(([,O])=>O===N))==null?void 0:$[0])||"unmapped";return t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-1/3",children:t.jsxs(Ie,{className:"text-sm",children:[N,R.required&&t.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})}),t.jsx(Gt,{className:"w-4 h-4 text-muted-foreground shrink-0"}),t.jsx("div",{className:"flex-1",children:t.jsxs(be,{value:P,onValueChange:O=>{if(O==="unmapped"){const z={...f};Object.keys(z).forEach(F=>{z[F]===N&&delete z[F]}),x(z)}else{const z={...f};Object.keys(z).forEach(F=>{z[F]===N&&delete z[F]}),z[O]=N,x(z)}},children:[t.jsx(Ne,{className:"h-9",children:t.jsx(_e,{placeholder:"Select column..."})}),t.jsxs(Se,{children:[t.jsx(te,{value:"unmapped",children:"No mapping"}),u.map(O=>t.jsx(te,{value:O,children:O},O))]})]})})]},N)})})]})}),l==="preview"&&t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"flex items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("p",{className:"text-sm text-muted-foreground",children:[C.length," ",C.length===1?"entry":"entries"," to import"]}
13),i==="smart"&&q&&t.jsxs(ne,{variant:"outline",className:re("text-xs",q.overallConfidence>.8?"bg-green-50 text-green-700 border-green-200":q.overallConfidence>=.5?"bg-amber-50 text-amber-700 border-amber-200":"bg-red-50 text-red-700 border-red-200"),children:["AI ",Math.round(q.overallConfidence*100),"% confidence"]})]})}),le.length>0&&t.jsxs(ut,{variant:"destructive",children:[t.jsx(zr,{className:"h-4 w-4"}),t.jsxs(gt,{children:[t.jsxs("p",{className:"font-medium",children:[le.length," ",le.length===1?"error":"errors"," must be fixed before importing"]}),t.jsxs("ul",{className:"mt-1.5 text-xs space-y-0.5 opacity-80",children:[le.slice(0,3).map((N,R)=>t.jsxs("li",{children:["Row ",N.row,": ",N.field," â ",N.message]},R)),le.length>3&&t.jsxs("li",{children:["...and ",le.length-3," more"]})]})]})]}),je.length>0&&t.jsxs(ut,{children:[t.jsx(rr,{className:"h-4 w-4"}),t.jsxs(gt,{children:[t.jsxs("p",{className:"font-medium",children:[je.length," ",je.length===1?"warning":"warnings"," â you can still import"]}),t.jsxs("ul",{className:"mt-1.5 text-xs space-y-0.5 opacity-80",children:[je.slice(0,3).map((N,R)=>t.jsxs("li",{children:["Row ",N.row,": ",N.field," â ",N.message]},R)),je.length>3&&t.jsxs("li",{children:["...and ",je.length-3," more"]})]})]})]}),t.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[t.jsxs("span",{children:[t.jsx("strong",{children:"MP"})," = Material Participation"]}),t.jsxs("span",{children:[t.jsx("strong",{children:"QNM"})," = Qualified Non-Material"]})]}),t.jsx("div",{className:"hidden sm:block border rounded-lg overflow-auto max-h-[50vh]",children:t.jsxs(Jr,{children:[t.jsx(Zr,{children:t.jsxs(Ee,{className:"bg-muted/50",children:[t.jsx(Fe,{className:"w-10 text-center",children:"#"}),t.jsx(Fe,{className:"w-[120px]",children:"Date"}),t.jsx(Fe,{className:"w-[80px]",children:"Hours"}),t.jsx(Fe,{className:"w-[180px]",children:"Activity"}),t.jsx(Fe,{children:"Description"}),t.jsx(Fe,{className:"w-[140px]",children:"Property"}),t.jsx(Fe,{className:"w-[60px] text-center",children:"MP"}),t.jsx(Fe,{className:"w-[60px] text-center",children:"QNM"})]})}),t.jsx(en,{children:C.map((N,R)=>{var z;const P=w.filter(F=>F.row===R+1),$=P.some(F=>F.severity==="error"),O=P.some(F=>F.severity==="warning");return t.jsxs(Ee,{className:re(R%2===0?"bg-background":"bg-muted/30",$&&"border-l-2 border-l-red-500 bg-red-50/50",!$&&O&&"border-l-2 border-l-amber-400 bg-amber-50/40"),children:[t.jsx(ce,{className:"text-center text-xs text-muted-foreground",children:R+1}),t.jsx(ce,{children:t.jsx(ve,{type:"date",value:N.date||"",onChange:F=>se(R,"date",F.target.value),className:"h-8 text-sm"})}),t.jsx(ce,{children:t.jsx(ve,{type:"number",step:"0.25",min:"0",max:"24",value:N.hours||"",onChange:F=>se(R,"hours",F.target.value),className:"h-8 text-sm w-20"})}),t.jsx(ce,{children:t.jsx(ve,{value:N.activityType||"",onChange:F=>se(R,"activityType",F.target.value),className:"h-8 text-sm"})}),t.jsx(ce,{children:t.jsx(ve,{value:N.description||"",onChange:F=>se(R,"description",F.target.value),className:"h-8 text-sm",placeholder:"Description..."})}),t.jsx(ce,{children:t.jsxs(be,{value:((z=N.propertyId)==null?void 0:z.toString())||"none",onValueChange:F=>{const B=[...C];if(F==="none")B[R]={...B[R],propertyId:null,propertyDisplayName:null,propertyName:null};else{const H=n.find(X=>X.id.toString()===F);B[R]={...B[R],propertyId:parseInt(F),propertyDisplayName:(H==null?void 0:H.nickname)||(H==null?void 0:H.address),propertyName:H==null?void 0:H.nickname}}y(B),S(H=>H.filter(X=>!(X.row===R+1&&X.field==="propertyName")))},children:[t.jsx(Ne,{className:"h-8 text-sm",children:t.jsx(_e,{placeholder:"None"})}),t.jsxs(Se,{children:[t.jsx(te,{value:"none",children:"None"}),n.map(F=>t.jsx(te,{value:F.id.toString(),children:F.nickname||F.address},F.id))]})]})}),t.jsx(ce,{className:"text-center",children:t.jsx("button",{onClick:()=>se(R,"isMaterialParticipation",!N.isMaterialParticipation),className:re("w-7 h-7 rounded-full flex items-center justify-center text-xs font-medium transition-colors mx-auto",N.isMaterialParticipation?"bg-green-100 text-green-700 hover:bg-green-200":"bg-gray-100 text-gray-400 hover:bg-gray-200"),children:N.isMaterialParticipation?"Y":"N"})}),t.jsx(ce,{className:"text-center",children:t.jsx("button",{onClick:()=>se(R,"isQualifiedNonMaterial",!N.isQualifiedNonMaterial),className:re("w-7 h-7 rounded-full flex items-center justify-center text-xs font-medium transition-colors mx-auto",N.isQualifiedNonMaterial?"bg-blue-100 text-blue-700 hover:bg-blue-200":"bg-gray-100 text-gray-400 hover:bg-gray-200"),children:N.isQualifiedNonMaterial?"Y":"N"})})]},R)})})]})}),t.jsx("div",{className:"sm:hidden space-y-3 max-h-[50vh] overflow-y-auto",children:C.map((N,R)=>{var z;const P=w.filter(F=>F.row===R+1),$=P.some(F=>F.severity==="error"),O=P.some(F=>F.severity==="warning");return t.jsxs("div",{className:re("border rounded-lg p-4 space-y-3",$&&"border-red-300 bg-red-50/50",!$&&O&&"border-amber-300 bg-amber-50/40"),children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Entry ",R+1]}),$&&t.jsx(ne,{variant:"destructive",className:"text-xs h-5",children:"Error"}),!$&&O&&t.jsx(ne,{variant:"outline",className:"text-xs h-5 bg-amber-50 text-amber-700 border-amber-300",children:"Warning"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Date"}),t.jsx(ve,{type:"date",value:N.date||"",onChange:F=>se(R,"date",F.target.value),className:"h-9 text-sm"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Hours"}),t.jsx(ve,{type:"number",step:"0.25",min:"0",max:"24",value:N.hours||"",onChange:F=>se(R,"hours",F.target.value),className:"h-9 text-sm"})]})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Activity Type"}),t.jsx(ve,{value:N.activityType||"",onChange:F=>se(R,"activityType",F.target.value),className:"h-9 text-sm"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Description"}),t.jsx(ve,{value:N.description||"",onChange:F=>se(R,"description",F.target.value),className:"h-9 text-sm",placeholder:"Description..."})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Property"}),t.jsxs(be,{value:((z=N.propertyId)==null?void 0:z.toString())||"none",onValueChange:F=>{const B=[...C];if(F==="none")B[R]={...B[R],propertyId:null,propertyDisplayName:null,propertyName:null};else{const H=n.find(X=>X.id.toString()===F);B[R]={...B[R],propertyId:parseInt(F),propertyDisplayName:(H==null?void 0:H.nickname)||(H==null?void 0:H.address),propertyName:H==null?void 0:H.nickname}}y(B),S(H=>H.filter(X=>!(X.row===R+1&&X.field==="propertyName")))},children:[t.jsx(Ne,{className:"h-9 text-sm",children:t.jsx(_e,{placeholder:"None"})}),t.jsxs(Se,{children:[t.jsx(te,{value:"none",children:"None"}),n.map(F=>t.jsx(te,{value:F.id.toString(),children:F.nickname||F.address},F.id))]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Material Participation"}),t.jsx("button",{onClick:()=>se(R,"isMaterialParticipation",!N.isMaterialParticipation),className:re("w-full h-9 rounded-md text-sm font-medium transition-colors border",N.isMaterialParticipation?"bg-green-50 text-green-700 border-green-200":"bg-gray-50 text-gray-500 border-gray-200"),children:N.isMaterialParticipation?"Yes":"No"})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsx(Ie,{className:"text-xs text-muted-foreground",children:"Qualified Non-Material"}),t.jsx("button",{onClick:()=>se(R,"isQualifiedNonMaterial",!N.isQualifiedNonMaterial),className:re("w-full h-9 rounded-md text-sm font-medium transition-colors border",N.isQualifiedNonMaterial?"bg-blue-50 text-blue-700 border-blue-200":"bg-gray-50 text-gray-500 border-gray-200"),children:N.isQualifiedNonMaterial?"Yes":"No"})]})]}),P.length>0&&t.jsx("div",{className:re("text-xs space-y-0.5 pt-1 border-t",$?"text-red-600 border-red-200":"text-amber-600 border-amber-200"),children:P.map((F,B)=>t.jsxs("p",{children:[F.field,": ",F.message]},B))})]},R)})})]}),l==="importing"&&t.jsxs("div",{className:"py-8 text-center space-y-4",children:[t.jsx("div",{className:"w-14 h-14 mx-auto rounded-full bg-primary/10 flex items-center justify-center",children:t.jsx(ft,{className:"w-7 h-7 text-primary animate-pulse"})}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("h3",{className:"font-semibold",children:"Importing entries..."}),t.jsx(Kn,{value:h,className:"w-full max-w-xs mx-auto"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:[Math.round(h),"% complete"]})]})]}),l==="complete"&&t.jsxs("div",{className:"py-8 text-center space-y-6",children:[t.jsx("div",{className:"w-16 h-16 mx-auto rounded-full bg-green-100 flex items-center justify-center",children:t.jsx(tn,{className:"w-9 h-9 text-green-600"})}),t.jsxs("div",{className:"space-y-1",children:[t.jsx("h3",{className:"text-lg font-semibold text-green-700",children:"Import Complete"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Your time entries have been imported."})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-3 max-w-sm mx-auto",children:[t.jsxs("div",{className:"p-4 bg-green-50 rounded-xl",children:[t.jsx("div",{className:"text-2xl font-bold text-green-600",children:D.success}),t.jsx("div",{className:"text-xs text-green-700 mt-0.5",children:"Imported"})]}),t.jsxs("div",{className:"p-4 bg-amber-50 rounded-xl",children:[t.jsx("div",{className:"text-2xl font-bold text-amber-600",children:D.duplicates}),t.jsx("div",{className:"text-xs text-amber-700 mt-0.5",children:"Duplicates"})]}),t.jsxs("div",{className:"p-4 bg-red-50 rounded-xl",children:[t.jsx("div",{className:"text-2xl font-bold text-red-600",children:D.errors}),t.jsx("div",{className:"text-xs text-red-700 mt-0.5",children:"Errors"})]})]})]})]},`${i}-${l}`)}),rt&&t.jsxs("div",{className:"shrink-0 px-6 py-3 border-t flex items-center justify-between bg-background",children:[t.jsx("div",{children:l!=="complete"&&t.jsxs(L,{variant:"ghost",size:"sm",onClick:it,children:[t.jsx(Yn,{className:"w-4 h-4 mr-1.5"}),"Back"]})}),t.jsxs("div",{children:[l==="mapping"&&!I&&t.jsxs(L,{onClick:()=>{(q||Ge(m,f))&&o("preview")}
13,disabled:!q&&Object.keys(f).length===0,children:["Continue",t.jsx(Gt,{className:"w-4 h-4 ml-1.5"})]}),l==="preview"&&t.jsxs(L,{onClick:st,disabled:le.length>0,className:"bg-green-600 hover:bg-green-700 text-white",children:["Import ",C.length," Entries"]}),l==="complete"&&t.jsx(L,{onClick:Ue,children:"Done"})]})]})]})})}function Ts({open:e,onOpenChange:s,entry:r}){const n=fr();return r?n?t.jsx(rn,{children:e&&t.jsxs(mt.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",damping:30,stiffness:300,mass:.8},className:"fixed inset-0 z-[60] bg-white dark:bg-gray-950 overflow-hidden flex flex-col",children:[t.jsx(nn,{title:"Entry Details",showBack:!0,onBack:()=>s(!1),className:"bg-white/80 dark:bg-gray-950/80 backdrop-blur-md border-b border-gray-100 dark:border-gray-800"}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-safe-bottom pt-[calc(env(safe-area-inset-top)+64px)]",children:t.jsx(Ur,{entry:r})})]})}):t.jsx(cr,{open:e,onOpenChange:s,children:t.jsxs(ur,{className:"max-w-2xl max-h-[80vh] overflow-y-auto rounded-xl border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 shadow-lg",children:[t.jsx(gr,{children:t.jsx(pr,{className:"text-lg font-semibold text-gray-900 dark:text-gray-100",children:"Time Entry Details"})}),t.jsx(Ur,{entry:r})]})}):null}function Ur({entry:e}){return t.jsxs("div",{className:"space-y-6",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Date"}),t.jsx("p",{className:"mt-1 text-sm text-gray-900 dark:text-gray-100",children:St(e.date,"MMMM d, yyyy")})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Hours"}),t.jsxs("p",{className:"mt-1 text-sm font-semibold text-gray-900 dark:text-gray-100",children:[e.hours,"h"]})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Activity Types"}),t.jsx("div",{className:"mt-2",children:t.jsx(ne,{variant:"outline",className:"bg-green-50 text-green-700 border border-green-200 text-xs font-medium px-3 py-0.5 rounded-full",children:e.activityType})})]}),e.description&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Description"}),t.jsx("p",{className:"mt-2 text-sm leading-relaxed text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border border-gray-200 dark:border-gray-700",children:e.description})]}),e.property&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Property"}),t.jsxs("div",{className:"mt-2 p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[t.jsx("p",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:e.property.nickname}),t.jsxs("p",{className:"text-xs text-gray-600 dark:text-gray-400 mt-1",children:[e.property.address,", ",e.property.city,","," ",e.property.state," ",e.property.zipCode]})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Material Participation"}),t.jsx("div",{className:"mt-2",children:t.jsx(ne,{variant:e.isMaterialParticipation?"default":"secondary",className:"text-xs px-2 py-0.5",children:e.isMaterialParticipation?"Yes":"No"})})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Approval Status"}),t.jsx("div",{className:"mt-2",children:t.jsx(ne,{variant:(e.approvalStatus||"pending")==="approved"?"default":"secondary",className:"text-xs px-2 py-0.5",children:e.approvalStatus||"Pending"})})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Entry Source"}),t.jsx("div",{className:"mt-2",children:t.jsx(ne,{variant:"outline",className:"bg-green-50 text-green-700 border border-green-200 text-xs font-medium px-3 py-0.5 rounded-full",children:pn(e.source||"")})})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Evidence Files"}),t.jsx("div",{className:"mt-2 space-y-2",children:e.evidenceFiles&&e.evidenceFiles.length>0?e.evidenceFiles.map((s,r)=>t.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:s.fileName}),t.jsxs("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Uploaded:"," ",s.uploadedAt&&Xn(new Date(s.uploadedAt))?Ae(new Date(s.uploadedAt),"MMM d, yyyy HH:mm"):"Unknown date"]})]}),t.jsx(L,{variant:"ghost",size:"sm",className:"text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white",onClick:()=>window.open(s.fileUrl,"_blank"),children:t.jsx(Pr,{className:"h-4 w-4"})})]},r)):e.evidenceUrl?t.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:e.evidenceFileName||"Evidence File"}),t.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:"Legacy evidence file"})]}),t.jsx(L,{variant:"ghost",size:"sm",className:"text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white",onClick:()=>window.open(e.evidenceUrl,"_blank"),children:t.jsx(Pr,{className:"h-4 w-4"})})]}):t.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 italic",children:"No evidence files attached"})})]}),e.aiSummary&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"AI Summary"}),t.jsx("p",{className:"mt-2 text-sm leading-relaxed text-gray-800 dark:text-gray-200 bg-gray-50 dark:bg-gray-800 p-3 rounded-lg border border-gray-200 dark:border-gray-700",children:typeof e.aiSummary=="string"?e.aiSummary:JSON.stringify(e.aiSummary)})]}),e.aiTags&&e.aiTags.length>0&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"AI Tags"}),t.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:e.aiTags.map((s,r)=>{const n=typeof s=="string"?s:(s==null?void 0:s.name)||(s==null?void 0:s.category)||JSON.stringify(s);return t.jsx(ne,{variant:"outline",className:"text-xs px-2 py-0.5",children:n},r)})})]}),t.jsx("div",{className:"pt-6 border-t border-gray-200 dark:border-gray-700",children:t.jsxs("div",{className:"grid grid-cols-2 gap-6 text-xs text-gray-500 dark:text-gray-400",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block font-medium text-gray-600 dark:text-gray-300",children:"Created"}),t.jsx("p",{className:"mt-1",children:Ae(new Date(e.createdAt),"MMM d, yyyy HH:mm")}
13)]}),t.jsxs("div",{children:[t.jsx("label",{className:"block font-medium text-gray-600 dark:text-gray-300",children:"Last Updated"}),t.jsx("p",{className:"mt-1",children:Ae(new Date(e.updatedAt),"MMM d, yyyy HH:mm")})]})]})})]})}function Vs({open:e,onOpenChange:s,selectedCount:r,confirmBulkApprove:n,isApprovingBulk:i,table:a}){return t.jsx(vt,{open:e,onOpenChange:s,children:t.jsxs(wt,{className:"rounded-xl shadow-lg border border-gray-200",children:[t.jsxs(jt,{children:[t.jsx(bt,{className:"text-lg font-semibold text-gray-900",children:"Approve Multiple Entries"}),t.jsxs(Nt,{className:"text-sm text-gray-600 leading-relaxed",children:[". Are you sure you want to approve"," ",t.jsx("span",{className:"font-medium text-gray-900",children:a.getFilteredSelectedRowModel().rows.filter(l=>{const o=l.original;return!o.isNew&&o.approvalStatus!=="approved"}).length})," ","selected time entries?"]})]}),t.jsxs(Ct,{className:"flex justify-end space-x-2",children:[t.jsx(kt,{disabled:i,className:"px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-100 transition",children:"Cancel"}),t.jsx(Rt,{onClick:n,disabled:i,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition flex items-center",children:i?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin"}),"Approving..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{className:"mr-2 h-4 w-4"}),"Approve"," ",a.getFilteredSelectedRowModel().rows.filter(l=>{const o=l.original;return!o.isNew&&o.approvalStatus!=="approved"}).length," ","Entries"]})})]})]})})}function Ls({open:e,onOpenChange:s,selectedCount:r,confirmBulkUnapprove:n,isUnapprovingBulk:i,table:a}){return t.jsx(vt,{open:e,onOpenChange:s,children:t.jsxs(wt,{className:"rounded-xl shadow-lg border border-gray-200",children:[t.jsxs(jt,{children:[t.jsx(bt,{className:"text-lg font-semibold text-gray-900",children:"Unapprove Multiple Entries"}),t.jsxs(Nt,{className:"text-sm text-gray-600 leading-relaxed",children:[". Are you sure you want to unapprove"," ",t.jsx("span",{className:"font-medium text-gray-900",children:a.getFilteredSelectedRowModel().rows.filter(l=>{const o=l.original;return!o.isNew&&o.approvalStatus!=="pending"}).length})," ","selected time entries?"]})]}),t.jsxs(Ct,{className:"flex justify-end space-x-2",children:[t.jsx(kt,{disabled:i,className:"px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-100 transition",children:"Cancel"}),t.jsx(Rt,{onClick:n,disabled:i,className:"px-4 py-2 rounded-lg bg-red-600 text-white text-sm font-medium hover:bg-red-700 transition flex items-center",children:i?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin"}),"Unapproving..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Xe,{className:"mr-2 h-4 w-4"}),"Unapprove"," ",a.getFilteredSelectedRowModel().rows.filter(l=>{const o=l.original;return!o.isNew&&o.approvalStatus!=="pending"}).length," ","Entries"]})})]})]})})}/** 14 * table-core 15 * 16 * Copyright (c) TanStack 17 * 18 * This source code is licensed under the MIT license found in the 19 * LICENSE.md file in the root directory of this source tree. 20 * 21 * @license MIT 22 */function $e(e,s){return typeof e=="function"?e(s):e}function pe(e,s){return r=>{s.setState(n=>({...n,[e]:$e(r,n[e])}))}}function Ht(e){return e instanceof Function}function Hs(e){return Array.isArray(e)&&e.every(s=>typeof s=="number")}function Os(e,s){const r=[],n=i=>{i.forEach(a=>{r.push(a);const l=s(a);l!=null&&l.length&&n(l)})};return n(e),r}function _(e,s,r){let n=[],i;return a=>{let l;r.key&&r.debug&&(l=Date.now());const o=e(a);if(!(o.length!==n.length||o.some((m,p)=>n[p]!==m)))return i;n=o;let g;if(r.key&&r.debug&&(g=Date.now()),i=s(...o),r==null||r.onChange==null||r.onChange(i),r.key&&r.debug&&r!=null&&r.debug()){const m=Math.round((Date.now()-l)*100)/100,p=Math.round((Date.now()-g)*100)/100,u=p/16,d=(f,x)=>{for(f=String(f);f.length<x;)f=" "+f;return f};console.info(`%câ± ${d(p,5)} /${d(m,5)} ms`,` 23 font-size: .6rem; 24 font-weight: bold; 25 color: hsl(${Math.max(0,Math.min(120-120*u,120))}deg 100% 31%);`,r==null?void 0:r.key)}return i}}function A(e,s,r,n){return{debug:()=>{var i;return(i=e==null?void 0:e.debugAll)!=null?i:e[s]},key:!1,onChange:n}}function zs(e,s,r,n){const i=()=>{var l;return(l=a.getValue())!=null?l:e.options.renderFallbackValue},a={id:`${s.id}_${r.id}`,row:s,column:r,getValue:()=>s.getValue(n),renderValue:i,getContext:_(()=>[e,r,s,a],(l,o,c,g)=>({table:l,column:o,row:c,cell:g,getValue:g.getValue,renderValue:g.renderValue}),A(e.options,"debugCells"))};
25return e._features.forEach(l=>{l.createCell==null||l.createCell(a,r,s,e)},{}),a}function Bs(e,s,r,n){var i,a;const o={...e._getDefaultColumnDef(),...s},c=o.accessorKey;let g=(i=(a=o.id)!=null?a:c?typeof String.prototype.replaceAll=="function"?c.replaceAll(".","_"):c.replace(/\./g,"_"):void 0)!=null?i:typeof o.header=="string"?o.header:void 0,m;if(o.accessorFn?m=o.accessorFn:c&&(c.includes(".")?m=u=>{let d=u;for(const x of c.split(".")){var f;d=(f=d)==null?void 0:f[x]}return d}:m=u=>u[o.accessorKey]),!g)throw new Error;let p={id:`${String(g)}`,accessorFn:m,parent:n,depth:r,columnDef:o,columns:[],getFlatColumns:_(()=>[!0],()=>{var u;return[p,...(u=p.columns)==null?void 0:u.flatMap(d=>d.getFlatColumns())]},A(e.options,"debugColumns")),getLeafColumns:_(()=>[e._getOrderColumnsFn()],u=>{var d;if((d=p.columns)!=null&&d.length){let f=p.columns.flatMap(x=>x.getLeafColumns());return u(f)}return[p]},A(e.options,"debugColumns"))};for(const u of e._features)u.createColumn==null||u.createColumn(p,e);return p}const oe="debugHeaders";function qr(e,s,r){var n;let a={id:(n=r.id)!=null?n:s.id,column:s,index:r.index,isPlaceholder:!!r.isPlaceholder,placeholderId:r.placeholderId,depth:r.depth,subHeaders:[],colSpan:0,rowSpan:0,headerGroup:null,getLeafHeaders:()=>{const l=[],o=c=>{c.subHeaders&&c.subHeaders.length&&c.subHeaders.map(o),l.push(c)};return o(a),l},getContext:()=>({table:e,header:a,column:s})};return e._features.forEach(l=>{l.createHeader==null||l.createHeader(a,e)}),a}const Gs={createTable:e=>{e.getHeaderGroups=_(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(s,r,n,i)=>{var a,l;const o=(a=n==null?void 0:n.map(p=>r.find(u=>u.id===p)).filter(Boolean))!=null?a:[],c=(l=i==null?void 0:i.map(p=>r.find(u=>u.id===p)).filter(Boolean))!=null?l:[],g=r.filter(p=>!(n!=null&&n.includes(p.id))&&!(i!=null&&i.includes(p.id)));return _t(s,[...o,...g,...c],e)},A(e.options,oe)),e.getCenterHeaderGroups=_(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(s,r,n,i)=>(r=r.filter(a=>!(n!=null&&n.includes(a.id))&&!(i!=null&&i.includes(a.id))),_t(s,r,e,"center")),A(e.options,oe)),e.getLeftHeaderGroups=_(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.left],(s,r,n)=>{var i;const a=(i=n==null?void 0:n.map(l=>r.find(o=>o.id===l)).filter(Boolean))!=null?i:[];return _t(s,a,e,"left")},A(e.options,oe)),e.getRightHeaderGroups=_(()=>[e.getAllColumns(),e.getVisibleLeafColumns(),e.getState().columnPinning.right],(s,r,n)=>{var i;const a=(i=n==null?void 0:n.map(l=>r.find(o=>o.id===l)).filter(Boolean))!=null?i:[];return _t(s,a,e,"right")},A(e.options,oe)),e.getFooterGroups=_(()=>[e.getHeaderGroups()],s=>[...s].reverse(),A(e.options,oe)),e.getLeftFooterGroups=_(()=>[e.getLeftHeaderGroups()],s=>[...s].reverse(),A(e.options,oe)),e.getCenterFooterGroups=_(()=>[e.getCenterHeaderGroups()],s=>[...s].reverse(),A(e.options,oe)),e.getRightFooterGroups=_(()=>[e.getRightHeaderGroups()],s=>[...s].reverse(),A(e.options,oe)),e.getFlatHeaders=_(()=>[e.getHeaderGroups()],s=>s.map(r=>r.headers).flat(),A(e.options,oe)),e.getLeftFlatHeaders=_(()=>[e.getLeftHeaderGroups()],s=>s.map(r=>r.headers).flat(),A(e.options,oe)),e.getCenterFlatHeaders=_(()=>[e.getCenterHeaderGroups()],s=>s.map(r=>r.headers).flat(),A(e.options,oe)),e.getRightFlatHeaders=_(()=>[e.getRightHeaderGroups()],s=>s.map(r=>r.headers).flat(),A(e.options,oe)),e.getCenterLeafHeaders=_(()=>[e.getCenterFlatHeaders()],s=>s.filter(r=>{var n;return!((n=r.subHeaders)!=null&&n.length)}),A(e.options,oe)),e.getLeftLeafHeaders=_(()=>[e.getLeftFlatHeaders()],s=>s.filter(r=>{var n;return!((n=r.subHeaders)!=null&&n.length)}),A(e.options,oe)),e.getRightLeafHeaders=_(()=>[e.getRightFlatHeaders()],s=>s.filter(r=>{var n;return!((n=r.subHeaders)!=null&&n.length)}),A(e.options,oe)),e.getLeafHeaders=_(()=>[e.getLeftHeaderGroups(),e.getCenterHeaderGroups(),e.getRightHeaderGroups()],(s,r,n)=>{var i,a,l,o,c,g;return[...(i=(a=s[0])==null?void 0:a.headers)!=null?i:[],...(l=(o=r[0])==null?void 0:o.headers)!=null?l:[],...(c=(g=n[0])==null?void 0:g.headers)!=null?c:[]].map(m=>m.getLeafHeaders()).flat()},A(e.options,oe))}};function _t(e,s,r,n){var i,a;let l=0;const o=function(u,d){d===void 0&&(d=1),l=Math.max(l,d),u.filter(f=>
25f.getIsVisible()).forEach(f=>{var x;(x=f.columns)!=null&&x.length&&o(f.columns,d+1)},0)};o(e);let c=[];const g=(u,d)=>{const f={depth:d,id:[n,`${d}`].filter(Boolean).join("_"),headers:[]},x=[];u.forEach(C=>{const y=[...x].reverse()[0],w=C.column.depth===f.depth;let S,h=!1;if(w&&C.column.parent?S=C.column.parent:(S=C.column,h=!0),y&&(y==null?void 0:y.column)===S)y.subHeaders.push(C);else{const b=qr(r,S,{id:[n,d,S.id,C==null?void 0:C.id].filter(Boolean).join("_"),isPlaceholder:h,placeholderId:h?`${x.filter(k=>k.column===S).length}`:void 0,depth:d,index:x.length});b.subHeaders.push(C),x.push(b)}f.headers.push(C),C.headerGroup=f}),c.push(f),d>0&&g(x,d-1)},m=s.map((u,d)=>qr(r,u,{depth:l,index:d}));g(m,l-1),c.reverse();const p=u=>u.filter(f=>f.column.getIsVisible()).map(f=>{let x=0,C=0,y=[0];f.subHeaders&&f.subHeaders.length?(y=[],p(f.subHeaders).forEach(S=>{let{colSpan:h,rowSpan:b}=S;x+=h,y.push(b)})):x=1;const w=Math.min(...y);return C=C+w,f.colSpan=x,f.rowSpan=C,{colSpan:x,rowSpan:C}});return p((i=(a=c[0])==null?void 0:a.headers)!=null?i:[]),c}const hr=(e,s,r,n,i,a,l)=>{let o={id:s,index:n,original:r,depth:i,parentId:l,_valuesCache:{},_uniqueValuesCache:{},getValue:c=>{if(o._valuesCache.hasOwnProperty(c))return o._valuesCache[c];const g=e.getColumn(c);if(g!=null&&g.accessorFn)return o._valuesCache[c]=g.accessorFn(o.original,n),o._valuesCache[c]},getUniqueValues:c=>{if(o._uniqueValuesCache.hasOwnProperty(c))return o._uniqueValuesCache[c];const g=e.getColumn(c);if(g!=null&&g.accessorFn)return g.columnDef.getUniqueValues?(o._uniqueValuesCache[c]=g.columnDef.getUniqueValues(o.original,n),o._uniqueValuesCache[c]):(o._uniqueValuesCache[c]=[o.getValue(c)],o._uniqueValuesCache[c])},renderValue:c=>{var g;return(g=o.getValue(c))!=null?g:e.options.renderFallbackValue},subRows:[],getLeafRows:()=>Os(o.subRows,c=>c.subRows),getParentRow:()=>o.parentId?e.getRow(o.parentId,!0):void 0,getParentRows:()=>{let c=[],g=o;for(;;){const m=g.getParentRow();if(!m)break;c.push(m),g=m}return c.reverse()},getAllCells:_(()=>[e.getAllLeafColumns()],c=>c.map(g=>zs(e,o,g,g.id)),A(e.options,"debugRows")),_getAllCellsByColumnId:_(()=>[o.getAllCells()],c=>c.reduce((g,m)=>(g[m.column.id]=m,g),{}),A(e.options,"debugRows"))};for(let c=0;c<e._features.length;c++){const g=e._features[c];g==null||g.createRow==null||g.createRow(o,e)}return o},Us={createColumn:(e,s)=>{e._getFacetedRowModel=s.options.getFacetedRowModel&&s.options.getFacetedRowModel(s,e.id),e.getFacetedRowModel=()=>e._getFacetedRowModel?e._getFacetedRowModel():s.getPreFilteredRowModel(),e._getFacetedUniqueValues=s.options.getFacetedUniqueValues&&s.options.getFacetedUniqueValues(s,e.id),e.getFacetedUniqueValues=()=>e._getFacetedUniqueValues?e._getFacetedUniqueValues():new Map,e._getFacetedMinMaxValues=s.options.getFacetedMinMaxValues&&s.options.getFacetedMinMaxValues(s,e.id),e.getFacetedMinMaxValues=()=>{if(e._getFacetedMinMaxValues)return e._getFacetedMinMaxValues()}}},fn=(e,s,r)=>{var n,i;const a=r==null||(n=r.toString())==null?void 0:n.toLowerCase();return!!(!((i=e.getValue(s))==null||(i=i.toString())==null||(i=i.toLowerCase())==null)&&i.includes(a))};fn.autoRemove=e=>we(e);const hn=(e,s,r)=>{var n;return!!(!((n=e.getValue(s))==null||(n=n.toString())==null)&&n.includes(r))};hn.autoRemove=e=>we(e);const xn=(e,s,r)=>{var n;return((n=e.getValue(s))==null||(n=n.toString())==null?void 0:n.toLowerCase())===(r==null?void 0:r.toLowerCase())};xn.autoRemove=e=>we(e);const yn=(e,s,r)=>{var n;return(n=e.getValue(s))==null?void 0:n.includes(r)};yn.autoRemove=e=>we(e);const vn=(e,s,r)=>!r.some(n=>{var i;return!((i=e.getValue(s))!=null&&i.includes(n))});vn.autoRemove=e=>we(e)||!(e!=null&&e.length);const wn=(e,s,r)=>r.some(n=>{var i;return(i=e.getValue(s))==null?void 0:i.includes(n)});wn.autoRemove=e=>we(e)||!(e!=null&&e.length);const jn=(e,s,r)=>e.getValue(s)===r;jn.autoRemove=e=>we(e);const bn=(e,s,r)=>e.getValue(s)==r;bn.autoRemove=e=>we(e);const xr=(e,s,r)=>{let[n,i]=r;const a=e.getValue(s);return a>=n&&a<=i};xr.resolveFilterValue=e=>{let[s,r]=e,n=typeof s!="number"?parseFloat(s):s,i=typeof r!="number"?parseFloat(r):r,a=s===null||Number.isNaN(n)?-1/0:n,l=r===null||Number.isNaN(i)?1/0:i;if(a>l){const o=a;a=l,l=o}return[a,l]};xr.autoRemove=e=>we(e)||we(e[0])&&we(e[1]);const Me={includesString:fn,includesStringSensitive:hn,equalsString:xn,arrIncludes:yn,arrIncludesAll:vn,arrIncludesSome:wn,equals:jn,weakEquals:bn,inNumberRange:xr};function we(e){return e==null||e===""}const qs={getDefaultColumnDef:()=>({filterFn:"auto"}),getInitialState:e=>({columnFilters:[],...e}),getDefaultOptions:e=>({onColumnFiltersChange:pe("columnFilters",e),filterFromLeafRows:!1,maxLeafRowFilterDepth:100}),createColumn:(e,s)=>{e.getAutoFilterFn=()=>{const r=s.getCoreRowModel().flatRows[0],n=r==null?void 0:r.getValue(e.id);return typeof n=="string"?Me.includesString:typeof n=="number"?Me.inNumberRange:typeof n=="boolean"||n!==null&&typeof n=="object"?Me.equals:Array.isArray(n)?Me.arrIncludes:Me.weakEquals},e.getFilterFn=()=>{var r,n;
25return Ht(e.columnDef.filterFn)?e.columnDef.filterFn:e.columnDef.filterFn==="auto"?e.getAutoFilterFn():(r=(n=s.options.filterFns)==null?void 0:n[e.columnDef.filterFn])!=null?r:Me[e.columnDef.filterFn]},e.getCanFilter=()=>{var r,n,i;return((r=e.columnDef.enableColumnFilter)!=null?r:!0)&&((n=s.options.enableColumnFilters)!=null?n:!0)&&((i=s.options.enableFilters)!=null?i:!0)&&!!e.accessorFn},e.getIsFiltered=()=>e.getFilterIndex()>-1,e.getFilterValue=()=>{var r;return(r=s.getState().columnFilters)==null||(r=r.find(n=>n.id===e.id))==null?void 0:r.value},e.getFilterIndex=()=>{var r,n;return(r=(n=s.getState().columnFilters)==null?void 0:n.findIndex(i=>i.id===e.id))!=null?r:-1},e.setFilterValue=r=>{s.setColumnFilters(n=>{const i=e.getFilterFn(),a=n==null?void 0:n.find(m=>m.id===e.id),l=$e(r,a?a.value:void 0);if(Wr(i,l,e)){var o;return(o=n==null?void 0:n.filter(m=>m.id!==e.id))!=null?o:[]}const c={id:e.id,value:l};if(a){var g;return(g=n==null?void 0:n.map(m=>m.id===e.id?c:m))!=null?g:[]}return n!=null&&n.length?[...n,c]:[c]})}},createRow:(e,s)=>{e.columnFilters={},e.columnFiltersMeta={}},createTable:e=>{e.setColumnFilters=s=>{const r=e.getAllLeafColumns(),n=i=>{var a;return(a=$e(s,i))==null?void 0:a.filter(l=>{const o=r.find(c=>c.id===l.id);if(o){const c=o.getFilterFn();if(Wr(c,l.value,o))return!1}return!0})};e.options.onColumnFiltersChange==null||e.options.onColumnFiltersChange(n)},e.resetColumnFilters=s=>{var r,n;e.setColumnFilters(s?[]:(r=(n=e.initialState)==null?void 0:n.columnFilters)!=null?r:[])},e.getPreFilteredRowModel=()=>e.getCoreRowModel(),e.getFilteredRowModel=()=>(!e._getFilteredRowModel&&e.options.getFilteredRowModel&&(e._getFilteredRowModel=e.options.getFilteredRowModel(e)),e.options.manualFiltering||!e._getFilteredRowModel?e.getPreFilteredRowModel():e._getFilteredRowModel())}};function Wr(e,s,r){return(e&&e.autoRemove?e.autoRemove(s,r):!1)||typeof s>"u"||typeof s=="string"&&!s}const Ws=(e,s,r)=>r.reduce((n,i)=>{const a=i.getValue(e);return n+(typeof a=="number"?a:0)},0),Qs=(e,s,r)=>{let n;return r.forEach(i=>{const a=i.getValue(e);a!=null&&(n>a||n===void 0&&a>=a)&&(n=a)}),n},Ks=(e,s,r)=>{let n;return r.forEach(i=>{const a=i.getValue(e);a!=null&&(n<a||n===void 0&&a>=a)&&(n=a)}),n},Ys=(e,s,r)=>{let n,i;return r.forEach(a=>{const l=a.getValue(e);l!=null&&(n===void 0?l>=l&&(n=i=l):(n>l&&(n=l),i<l&&(i=l)))}),[n,i]},Xs=(e,s)=>{let r=0,n=0;if(s.forEach(i=>{let a=i.getValue(e);a!=null&&(a=+a)>=a&&(++r,n+=a)}),r)return n/r},Js=(e,s)=>{if(!s.length)return;const r=s.map(a=>a.getValue(e));if(!Hs(r))return;if(r.length===1)return r[0];const n=Math.floor(r.length/2),i=r.sort((a,l)=>a-l);return r.length%2!==0?i[n]:(i[n-1]+i[n])/2},Zs=(e,s)=>Array.from(new Set(s.map(r=>r.getValue(e))).values()),ei=(e,s)=>new Set(s.map(r=>r.getValue(e))).size,ti=(e,s)=>s.length,Kt={sum:Ws,min:Qs,max:Ks,extent:Ys,mean:Xs,median:Js,unique:Zs,uniqueCount:ei,count:ti},ri={getDefaultColumnDef:()=>({aggregatedCell:e=>{var s,r;return(s=(r=e.getValue())==null||r.toString==null?void 0:r.toString())!=null?s:null},aggregationFn:"auto"}),getInitialState:e=>({grouping:[],...e}),getDefaultOptions:e=>({onGroupingChange:pe("grouping",e),groupedColumnMode:"reorder"}),createColumn:(e,s)=>{e.toggleGrouping=()=>{s.setGrouping(r=>r!=null&&r.includes(e.id)?r.filter(n=>n!==e.id):[...r??[],e.id])},e.getCanGroup=()=>{var r,n;return((r=e.columnDef.enableGrouping)!=null?r:!0)&&((n=s.options.enableGrouping)!=null?n:!0)&&(!!e.accessorFn||!!e.columnDef.getGroupingValue)},e.getIsGrouped=()=>{var r;return(r=s.getState().grouping)==null?void 0:r.includes(e.id)},e.getGroupedIndex=()=>{var r;return(r=s.getState().grouping)==null?void 0:r.indexOf(e.id)},e.getToggleGroupingHandler=()=>{const r=e.getCanGroup();return()=>{r&&e.toggleGrouping()}},e.getAutoAggregationFn=()=>{const r=s.getCoreRowModel().flatRows[0],n=r==null?void 0:r.getValue(e.id);if(typeof n=="number")return Kt.sum;if(Object.prototype.toString.call(n)==="[object Date]")return Kt.extent},e.getAggregationFn=()=>{var r,n;if(!e)throw new Error;return Ht(e.columnDef.aggregationFn)?e.columnDef.aggregationFn:e.columnDef.aggregationFn==="auto"?e.getAutoAggregationFn():(r=(n=s.options.aggregationFns)==null?void 0:n[e.columnDef.aggregationFn])!=null?r:Kt[e.columnDef.aggregationFn]}},createTable:e=>{e.setGrouping=s=>e.options.onGroupingChange==null?void 0:e.options.onGroupingChange(s),e.resetGrouping=s=>{var r,n;e.setGrouping(s?[]:(r=(n=e.initialState)==null?void 0:n.grouping)!=null?r:[])},e.getPreGroupedRowModel=()=>e.getFilteredRowModel(),e.getGroupedRowModel=()=>(!e._getGroupedRowModel&&e.options.getGroupedRowModel&&(e._getGroupedRowModel=e.options.getGroupedRowModel(e)),e.options.manualGrouping||!e._getGroupedRowModel?e.getPreGroupedRowModel():e._getGroupedRowModel())},createRow:(e,s)=>{e.getIsGrouped=()=>!!e.groupingColumnId,e.getGroupingValue=r=>{if(e._groupingValuesCache.hasOwnProperty(r))return e._groupingValuesCache[r];const n=s.getColumn(r);return n!=null&&n.columnDef.getGroupingValue?(e._groupingValuesCache[r]=n.columnDef.getGroupingValue(e.original),e._groupingValuesCache[r]):e.getValue(r)},e._groupingValuesCache={}},createCell:(e,s,r,n)=>{e.getIsGrouped=()=>s.getIsGrouped()&&s.id===r.groupingColumnId,e.getIsPlaceholder=()=>!e.getIsGrouped()&&s.getIsGrouped(),e.getIsAggregated=()=>{var i;return!e.getIsGrouped()&&!e.getIsPlaceholder()&&!!((i=r.subRows)!=null&&i.length)}}};function ni(e,s,r){if(!(s!=null&&s.length)||!r)return e;const n=e.filter(a=>!s.includes(a.id));return r==="remove"?n:[...s.map(a=>e.find(l=>
25l.id===a)).filter(Boolean),...n]}const si={getInitialState:e=>({columnOrder:[],...e}),getDefaultOptions:e=>({onColumnOrderChange:pe("columnOrder",e)}),createColumn:(e,s)=>{e.getIndex=_(r=>[ht(s,r)],r=>r.findIndex(n=>n.id===e.id),A(s.options,"debugColumns")),e.getIsFirstColumn=r=>{var n;return((n=ht(s,r)[0])==null?void 0:n.id)===e.id},e.getIsLastColumn=r=>{var n;const i=ht(s,r);return((n=i[i.length-1])==null?void 0:n.id)===e.id}},createTable:e=>{e.setColumnOrder=s=>e.options.onColumnOrderChange==null?void 0:e.options.onColumnOrderChange(s),e.resetColumnOrder=s=>{var r;e.setColumnOrder(s?[]:(r=e.initialState.columnOrder)!=null?r:[])},e._getOrderColumnsFn=_(()=>[e.getState().columnOrder,e.getState().grouping,e.options.groupedColumnMode],(s,r,n)=>i=>{let a=[];if(!(s!=null&&s.length))a=i;else{const l=[...s],o=[...i];for(;o.length&&l.length;){const c=l.shift(),g=o.findIndex(m=>m.id===c);g>-1&&a.push(o.splice(g,1)[0])}a=[...a,...o]}return ni(a,r,n)},A(e.options,"debugTable"))}},Yt=()=>({left:[],right:[]}),ii={getInitialState:e=>({columnPinning:Yt(),...e}),getDefaultOptions:e=>({onColumnPinningChange:pe("columnPinning",e)}),createColumn:(e,s)=>{e.pin=r=>{const n=e.getLeafColumns().map(i=>i.id).filter(Boolean);s.setColumnPinning(i=>{var a,l;if(r==="right"){var o,c;return{left:((o=i==null?void 0:i.left)!=null?o:[]).filter(p=>!(n!=null&&n.includes(p))),right:[...((c=i==null?void 0:i.right)!=null?c:[]).filter(p=>!(n!=null&&n.includes(p))),...n]}}if(r==="left"){var g,m;return{left:[...((g=i==null?void 0:i.left)!=null?g:[]).filter(p=>!(n!=null&&n.includes(p))),...n],right:((m=i==null?void 0:i.right)!=null?m:[]).filter(p=>!(n!=null&&n.includes(p)))}}return{left:((a=i==null?void 0:i.left)!=null?a:[]).filter(p=>!(n!=null&&n.includes(p))),right:((l=i==null?void 0:i.right)!=null?l:[]).filter(p=>!(n!=null&&n.includes(p)))}})},e.getCanPin=()=>e.getLeafColumns().some(n=>{var i,a,l;return((i=n.columnDef.enablePinning)!=null?i:!0)&&((a=(l=s.options.enableColumnPinning)!=null?l:s.options.enablePinning)!=null?a:!0)}),e.getIsPinned=()=>{const r=e.getLeafColumns().map(o=>o.id),{left:n,right:i}=s.getState().columnPinning,a=r.some(o=>n==null?void 0:n.includes(o)),l=r.some(o=>i==null?void 0:i.includes(o));return a?"left":l?"right":!1},e.getPinnedIndex=()=>{var r,n;const i=e.getIsPinned();return i?(r=(n=s.getState().columnPinning)==null||(n=n[i])==null?void 0:n.indexOf(e.id))!=null?r:-1:0}},createRow:(e,s)=>{e.getCenterVisibleCells=_(()=>[e._getAllVisibleCells(),s.getState().columnPinning.left,s.getState().columnPinning.right],(r,n,i)=>{const a=[...n??[],...i??[]];return r.filter(l=>!a.includes(l.column.id))},A(s.options,"debugRows")),e.getLeftVisibleCells=_(()=>[e._getAllVisibleCells(),s.getState().columnPinning.left],(r,n)=>(n??[]).map(a=>r.find(l=>l.column.id===a)).filter(Boolean).map(a=>({...a,position:"left"})),A(s.options,"debugRows")),e.getRightVisibleCells=_(()=>[e._getAllVisibleCells(),s.getState().columnPinning.right],(r,n)=>(n??[]).map(a=>r.find(l=>l.column.id===a)).filter(Boolean).map(a=>({...a,position:"right"})),A(s.options,"debugRows"))},createTable:e=>{e.setColumnPinning=s=>e.options.onColumnPinningChange==null?void 0:e.options.onColumnPinningChange(s),e.resetColumnPinning=s=>{var r,n;return e.setColumnPinning(s?Yt():(r=(n=e.initialState)==null?void 0:n.columnPinning)!=null?r:Yt())},e.getIsSomeColumnsPinned=s=>{var r;const n=e.getState().columnPinning;if(!s){var i,a;return!!((i=n.left)!=null&&i.length||(a=n.right)!=null&&a.length)}return!!((r=n[s])!=null&&r.length)},e.getLeftLeafColumns=_(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left],(s,r)=>(r??[]).map(n=>s.find(i=>i.id===n)).filter(Boolean),A(e.options,"debugColumns")),e.getRightLeafColumns=_(()=>[e.getAllLeafColumns(),e.getState().columnPinning.right],(s,r)=>(r??[]).map(n=>s.find(i=>i.id===n)).filter(Boolean),A(e.options,"debugColumns")),e.getCenterLeafColumns=_(()=>[e.getAllLeafColumns(),e.getState().columnPinning.left,e.getState().columnPinning.right],(s,r,n)=>{const i=[...r??[],...n??[]];return s.filter(a=>!i.includes(a.id))},A(e.options,"debugColumns"))}};function ai(e){return e||(typeof document<"u"?document:null)}const At={size:150,minSize:20,maxSize:Number.MAX_SAFE_INTEGER},Xt=()=>({startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,isResizingColumn:!1,columnSizingStart:[]}),li={getDefaultColumnDef:()=>At,getInitialState:e=>({columnSizing:{},columnSizingInfo:Xt(),...e}),getDefaultOptions:e=>({columnResizeMode:"onEnd",columnResizeDirection:"ltr",onColumnSizingChange:pe("columnSizing",e),onColumnSizingInfoChange:pe("columnSizingInfo",e)}),createColumn:(e,s)=>{e.getSize=()=>{var r,n,i;
25const a=s.getState().columnSizing[e.id];return Math.min(Math.max((r=e.columnDef.minSize)!=null?r:At.minSize,(n=a??e.columnDef.size)!=null?n:At.size),(i=e.columnDef.maxSize)!=null?i:At.maxSize)},e.getStart=_(r=>[r,ht(s,r),s.getState().columnSizing],(r,n)=>n.slice(0,e.getIndex(r)).reduce((i,a)=>i+a.getSize(),0),A(s.options,"debugColumns")),e.getAfter=_(r=>[r,ht(s,r),s.getState().columnSizing],(r,n)=>n.slice(e.getIndex(r)+1).reduce((i,a)=>i+a.getSize(),0),A(s.options,"debugColumns")),e.resetSize=()=>{s.setColumnSizing(r=>{let{[e.id]:n,...i}=r;return i})},e.getCanResize=()=>{var r,n;return((r=e.columnDef.enableResizing)!=null?r:!0)&&((n=s.options.enableColumnResizing)!=null?n:!0)},e.getIsResizing=()=>s.getState().columnSizingInfo.isResizingColumn===e.id},createHeader:(e,s)=>{e.getSize=()=>{let r=0;const n=i=>{if(i.subHeaders.length)i.subHeaders.forEach(n);else{var a;r+=(a=i.column.getSize())!=null?a:0}};return n(e),r},e.getStart=()=>{if(e.index>0){const r=e.headerGroup.headers[e.index-1];return r.getStart()+r.getSize()}return 0},e.getResizeHandler=r=>{const n=s.getColumn(e.column.id),i=n==null?void 0:n.getCanResize();return a=>{if(!n||!i||(a.persist==null||a.persist(),Jt(a)&&a.touches&&a.touches.length>1))return;const l=e.getSize(),o=e?e.getLeafHeaders().map(y=>[y.column.id,y.column.getSize()]):[[n.id,n.getSize()]],c=Jt(a)?Math.round(a.touches[0].clientX):a.clientX,g={},m=(y,w)=>{typeof w=="number"&&(s.setColumnSizingInfo(S=>{var h,b;const k=s.options.columnResizeDirection==="rtl"?-1:1,M=(w-((h=S==null?void 0:S.startOffset)!=null?h:0))*k,D=Math.max(M/((b=S==null?void 0:S.startSize)!=null?b:0),-.999999);return S.columnSizingStart.forEach(T=>{let[I,U]=T;g[I]=Math.round(Math.max(U+U*D,0)*100)/100}),{...S,deltaOffset:M,deltaPercentage:D}}),(s.options.columnResizeMode==="onChange"||y==="end")&&s.setColumnSizing(S=>({...S,...g})))},p=y=>m("move",y),u=y=>{m("end",y),s.setColumnSizingInfo(w=>({...w,isResizingColumn:!1,startOffset:null,startSize:null,deltaOffset:null,deltaPercentage:null,columnSizingStart:[]}))},d=ai(r),f={moveHandler:y=>p(y.clientX),upHandler:y=>{d==null||d.removeEventListener("mousemove",f.moveHandler),d==null||d.removeEventListener("mouseup",f.upHandler),u(y.clientX)}},x={moveHandler:y=>(y.cancelable&&(y.preventDefault(),y.stopPropagation()),p(y.touches[0].clientX),!1),upHandler:y=>{var w;d==null||d.removeEventListener("touchmove",x.moveHandler),d==null||d.removeEventListener("touchend",x.upHandler),y.cancelable&&(y.preventDefault(),y.stopPropagation()),u((w=y.touches[0])==null?void 0:w.clientX)}},C=oi()?{passive:!1}:!1;Jt(a)?(d==null||d.addEventListener("touchmove",x.moveHandler,C),d==null||d.addEventListener("touchend",x.upHandler,C)):(d==null||d.addEventListener("mousemove",f.moveHandler,C),d==null||d.addEventListener("mouseup",f.upHandler,C)),s.setColumnSizingInfo(y=>({...y,startOffset:c,startSize:l,deltaOffset:0,deltaPercentage:0,columnSizingStart:o,isResizingColumn:n.id}))}}},createTable:e=>{e.setColumnSizing=s=>e.options.onColumnSizingChange==null?void 0:e.options.onColumnSizingChange(s),e.setColumnSizingInfo=s=>e.options.onColumnSizingInfoChange==null?void 0:e.options.onColumnSizingInfoChange(s),e.resetColumnSizing=s=>{var r;e.setColumnSizing(s?{}:(r=e.initialState.columnSizing)!=null?r:{})},e.resetHeaderSizeInfo=s=>{var r;e.setColumnSizingInfo(s?Xt():(r=e.initialState.columnSizingInfo)!=null?r:Xt())},e.getTotalSize=()=>{var s,r;return(s=(r=e.getHeaderGroups()[0])==null?void 0:r.headers.reduce((n,i)=>n+i.getSize(),0))!=null?s:0},e.getLeftTotalSize=()=>{var s,r;return(s=(r=e.getLeftHeaderGroups()[0])==null?void 0:r.headers.reduce((n,i)=>n+i.getSize(),0))!=null?s:0},e.getCenterTotalSize=()=>{var s,r;return(s=(r=e.getCenterHeaderGroups()[0])==null?void 0:r.headers.reduce((n,i)=>n+i.getSize(),0))!=null?s:0},e.getRightTotalSize=()=>{var s,r;return(s=(r=e.getRightHeaderGroups()[0])==null?void 0:r.headers.reduce((n,i)=>n+i.getSize(),0))!=null?s:0}}};let Tt=null;function oi(){if(typeof Tt=="boolean")return Tt;let e=!1;try{const s={get passive(){return e=!0,!1}},r=()=>{};window.addEventListener("test",r,s),window.removeEventListener("test",r)}catch{e=!1}return Tt=e,Tt}function Jt(e){return e.type==="touchstart"}const di={getInitialState:e=>({columnVisibility:{},...e}),getDefaultOptions:e=>({onColumnVisibilityChange:pe("columnVisibility",e)}),createColumn:(e,s)=>{e.toggleVisibility=r=>{e.getCanHide()&&s.setColumnVisibility(n=>({...n,[e.id]:r??!e.getIsVisible()}))},e.getIsVisible=()=>{var r,n;const i=e.columns;return(r=i.length?i.some(a=>a.getIsVisible()):(n=s.getState().columnVisibility)==null?void 0:n[e.id])!=null?r:!0},e.getCanHide=()=>{var r,n;return((r=e.columnDef.enableHiding)!=null?r:!0)&&((n=s.options.enableHiding)!=null?n:!0)},e.getToggleVisibilityHandler=()=>r=>{e.toggleVisibility==null||e.toggleVisibility(r.target.checked)}},createRow:(e,s)=>{e._getAllVisibleCells=_(()=>[e.getAllCells(),s.getState().columnVisibility],r=>r.filter(n=>n.column.getIsVisible()),A(s.options,"debugRows")),e.getVisibleCells=_(()=>[e.getLeftVisibleCells(),e.getCenterVisibleCells(),e.getRightVisibleCells()],(r,n,i)=>[...r,...n,...i],A(s.options,"debugRows"))},createTable:e=>{const s=(r,n)=>_(()=>[n(),n().filter(i=>i.getIsVisible()).map(i=>i.id).join("_")],i=>i.filter(a=>a.getIsVisible==null?void 0:a.getIsVisible()),A(e.options,"debugColumns"));e.getVisibleFlatColumns=s("getVisibleFlatColumns",()=>e.getAllFlatColumns()),e.getVisibleLeafColumns=s("getVisibleLeafColumns",()=>e.getAllLeafColumns()),e.getLeftVisibleLeafColumns=s("getLeftVisibleLeafColumns",()=>e.getLeftLeafColumns()),e.getRightVisibleLeafColumns=s("getRightVisibleLeafColumns",()=>e.getRightLeafColumns()),e.getCenterVisibleLeafColumns=s("getCenterVisibleLeafColumns",()=>e.getCenterLeafColumns()),e.setColumnVisibility=r=>e.options.onColumnVisibilityChange==null?void 0:e.options.onColumnVisibilityChange(r),e.resetColumnVisibility=r=>{var n;e.setColumnVisibility(r?{}:(n=e.initialState.columnVisibility)!=null?n:{})},e.toggleAllColumnsVisible=r=>{var n;r=(n=r)!=null?n:!e.getIsAllColumnsVisible(),e.setColumnVisibility(e.getAllLeafColumns().reduce((i,a)=>({...i,[a.id]:r||!(a.getCanHide!=null&&a.getCanHide())}),{}))},e.getIsAllColumnsVisible=()=>!e.getAllLeafColumns().some(r=>!(r.getIsVisible!=null&&r.getIsVisible())),e.getIsSomeColumnsVisible=()=>e.getAllLeafColumns().some(r=>r.getIsVisible==null?void 0:r.getIsVisible()),e.getToggleAllColumnsVisibilityHandler=()=>r=>{var n;e.toggleAllColumnsVisible((n=r.target)==null?void 0:n.checked)}}};function ht(e,s){return s?s==="center"?e.getCenterVisibleLeafColumns():s==="left"?e.getLeftVisibleLeafColumns():e.getRightVisibleLeafColumns():e.getVisibleLeafColumns()}const ci={createTable:e=>{e._getGlobalFacetedRowModel=e.options.getFacetedRowModel&&e.options.getFacetedRowModel(e,"__global__"),e.getGlobalFacetedRowModel=()=>e.options.manualFiltering||!e._getGlobalFacetedRowModel?e.getPreFilteredRowModel():e._getGlobalFacetedRowModel(),e._getGlobalFacetedUniqueValues=e.options.getFacetedUniqueValues&&e.options.getFacetedUniqueValues(e,"__global__"),e.getGlobalFacetedUniqueValues=()=>e._getGlobalFacetedUniqueValues?e._getGlobalFacetedUniqueValues():new Map,e._getGlobalFacetedMinMaxValues=e.options.getFacetedMinMaxValues&&e.options.getFacetedMinMaxValues(e,"__global__"),e.getGlobalFacetedMinMaxValues=()=>
25{if(e._getGlobalFacetedMinMaxValues)return e._getGlobalFacetedMinMaxValues()}}},ui={getInitialState:e=>({globalFilter:void 0,...e}),getDefaultOptions:e=>({onGlobalFilterChange:pe("globalFilter",e),globalFilterFn:"auto",getColumnCanGlobalFilter:s=>{var r;const n=(r=e.getCoreRowModel().flatRows[0])==null||(r=r._getAllCellsByColumnId()[s.id])==null?void 0:r.getValue();return typeof n=="string"||typeof n=="number"}}),createColumn:(e,s)=>{e.getCanGlobalFilter=()=>{var r,n,i,a;return((r=e.columnDef.enableGlobalFilter)!=null?r:!0)&&((n=s.options.enableGlobalFilter)!=null?n:!0)&&((i=s.options.enableFilters)!=null?i:!0)&&((a=s.options.getColumnCanGlobalFilter==null?void 0:s.options.getColumnCanGlobalFilter(e))!=null?a:!0)&&!!e.accessorFn}},createTable:e=>{e.getGlobalAutoFilterFn=()=>Me.includesString,e.getGlobalFilterFn=()=>{var s,r;const{globalFilterFn:n}=e.options;return Ht(n)?n:n==="auto"?e.getGlobalAutoFilterFn():(s=(r=e.options.filterFns)==null?void 0:r[n])!=null?s:Me[n]},e.setGlobalFilter=s=>{e.options.onGlobalFilterChange==null||e.options.onGlobalFilterChange(s)},e.resetGlobalFilter=s=>{e.setGlobalFilter(s?void 0:e.initialState.globalFilter)}}},gi={getInitialState:e=>({expanded:{},...e}),getDefaultOptions:e=>({onExpandedChange:pe("expanded",e),paginateExpandedRows:!0}),createTable:e=>{let s=!1,r=!1;e._autoResetExpanded=()=>{var n,i;if(!s){e._queue(()=>{s=!0});return}if((n=(i=e.options.autoResetAll)!=null?i:e.options.autoResetExpanded)!=null?n:!e.options.manualExpanding){if(r)return;r=!0,e._queue(()=>{e.resetExpanded(),r=!1})}},e.setExpanded=n=>e.options.onExpandedChange==null?void 0:e.options.onExpandedChange(n),e.toggleAllRowsExpanded=n=>{n??!e.getIsAllRowsExpanded()?e.setExpanded(!0):e.setExpanded({})},e.resetExpanded=n=>{var i,a;e.setExpanded(n?{}:(i=(a=e.initialState)==null?void 0:a.expanded)!=null?i:{})},e.getCanSomeRowsExpand=()=>e.getPrePaginationRowModel().flatRows.some(n=>n.getCanExpand()),e.getToggleAllRowsExpandedHandler=()=>n=>{n.persist==null||n.persist(),e.toggleAllRowsExpanded()},e.getIsSomeRowsExpanded=()=>{const n=e.getState().expanded;return n===!0||Object.values(n).some(Boolean)},e.getIsAllRowsExpanded=()=>{const n=e.getState().expanded;return typeof n=="boolean"?n===!0:!(!Object.keys(n).length||e.getRowModel().flatRows.some(i=>!i.getIsExpanded()))},e.getExpandedDepth=()=>{let n=0;return(e.getState().expanded===!0?Object.keys(e.getRowModel().rowsById):Object.keys(e.getState().expanded)).forEach(a=>{const l=a.split(".");n=Math.max(n,l.length)}),n},e.getPreExpandedRowModel=()=>e.getSortedRowModel(),e.getExpandedRowModel=()=>(!e._getExpandedRowModel&&e.options.getExpandedRowModel&&(e._getExpandedRowModel=e.options.getExpandedRowModel(e)),e.options.manualExpanding||!e._getExpandedRowModel?e.getPreExpandedRowModel():e._getExpandedRowModel())},createRow:(e,s)=>{e.toggleExpanded=r=>{s.setExpanded(n=>{var i;const a=n===!0?!0:!!(n!=null&&n[e.id]);let l={};if(n===!0?Object.keys(s.getRowModel().rowsById).forEach(o=>{l[o]=!0}):l=n,r=(i=r)!=null?i:!a,!a&&r)return{...l,[e.id]:!0};if(a&&!r){const{[e.id]:o,...c}=l;return c}return n})},e.getIsExpanded=()=>{var r;const n=s.getState().expanded;return!!((r=s.options.getIsRowExpanded==null?void 0:s.options.getIsRowExpanded(e))!=null?r:n===!0||n!=null&&n[e.id])},e.getCanExpand=()=>{var r,n,i;return(r=s.options.getRowCanExpand==null?void 0:s.options.getRowCanExpand(e))!=null?r:((n=s.options.enableExpanding)!=null?n:!0)&&!!((i=e.subRows)!=null&&i.length)},e.getIsAllParentsExpanded=()=>{let r=!0,n=e;for(;r&&n.parentId;)n=s.getRow(n.parentId,!0),r=n.getIsExpanded();return r},e.getToggleExpandedHandler=()=>{const r=e.getCanExpand();return()=>{r&&e.toggleExpanded()}}}},ir=0,ar=10,Zt=()=>({pageIndex:ir,pageSize:ar}),pi={getInitialState:e=>({...e,pagination:{...Zt(),...e==null?void 0:e.pagination}}),getDefaultOptions:e=>({onPaginationChange:pe("pagination",e)}),createTable:e=>{let s=!1,r=!1;e._autoResetPageIndex=()=>{var n,i;if(!s){e._queue(()=>{s=!0});return}if((n=(i=e.options.autoResetAll)!=null?i:e.options.autoResetPageIndex)!=null?n:!e.options.manualPagination){if(r)return;r=!0,e._queue(()=>{e.resetPageIndex(),r=!1})}},e.setPagination=n=>{const i=a=>$e(n,a);return e.options.onPaginationChange==null?void 0:e.options.onPaginationChange(i)},e.resetPagination=n=>{var i;e.setPagination(n?Zt():(i=e.initialState.pagination)!=null?i:Zt())},e.setPageIndex=n=>{e.setPagination(i=>{let a=$e(n,i.pageIndex);
25const l=typeof e.options.pageCount>"u"||e.options.pageCount===-1?Number.MAX_SAFE_INTEGER:e.options.pageCount-1;return a=Math.max(0,Math.min(a,l)),{...i,pageIndex:a}})},e.resetPageIndex=n=>{var i,a;e.setPageIndex(n?ir:(i=(a=e.initialState)==null||(a=a.pagination)==null?void 0:a.pageIndex)!=null?i:ir)},e.resetPageSize=n=>{var i,a;e.setPageSize(n?ar:(i=(a=e.initialState)==null||(a=a.pagination)==null?void 0:a.pageSize)!=null?i:ar)},e.setPageSize=n=>{e.setPagination(i=>{const a=Math.max(1,$e(n,i.pageSize)),l=i.pageSize*i.pageIndex,o=Math.floor(l/a);return{...i,pageIndex:o,pageSize:a}})},e.setPageCount=n=>e.setPagination(i=>{var a;let l=$e(n,(a=e.options.pageCount)!=null?a:-1);return typeof l=="number"&&(l=Math.max(-1,l)),{...i,pageCount:l}}),e.getPageOptions=_(()=>[e.getPageCount()],n=>{let i=[];return n&&n>0&&(i=[...new Array(n)].fill(null).map((a,l)=>l)),i},A(e.options,"debugTable")),e.getCanPreviousPage=()=>e.getState().pagination.pageIndex>0,e.getCanNextPage=()=>{const{pageIndex:n}=e.getState().pagination,i=e.getPageCount();return i===-1?!0:i===0?!1:n<i-1},e.previousPage=()=>e.setPageIndex(n=>n-1),e.nextPage=()=>e.setPageIndex(n=>n+1),e.firstPage=()=>e.setPageIndex(0),e.lastPage=()=>e.setPageIndex(e.getPageCount()-1),e.getPrePaginationRowModel=()=>e.getExpandedRowModel(),e.getPaginationRowModel=()=>(!e._getPaginationRowModel&&e.options.getPaginationRowModel&&(e._getPaginationRowModel=e.options.getPaginationRowModel(e)),e.options.manualPagination||!e._getPaginationRowModel?e.getPrePaginationRowModel():e._getPaginationRowModel()),e.getPageCount=()=>{var n;return(n=e.options.pageCount)!=null?n:Math.ceil(e.getRowCount()/e.getState().pagination.pageSize)},e.getRowCount=()=>{var n;return(n=e.options.rowCount)!=null?n:e.getPrePaginationRowModel().rows.length}}},er=()=>({top:[],bottom:[]}),mi={getInitialState:e=>({rowPinning:er(),...e}),getDefaultOptions:e=>({onRowPinningChange:pe("rowPinning",e)}),createRow:(e,s)=>{e.pin=(r,n,i)=>{const a=n?e.getLeafRows().map(c=>{let{id:g}=c;return g}):[],l=i?e.getParentRows().map(c=>{let{id:g}=c;return g}):[],o=new Set([...l,e.id,...a]);s.setRowPinning(c=>{var g,m;if(r==="bottom"){var p,u;return{top:((p=c==null?void 0:c.top)!=null?p:[]).filter(x=>!(o!=null&&o.has(x))),bottom:[...((u=c==null?void 0:c.bottom)!=null?u:[]).filter(x=>!(o!=null&&o.has(x))),...Array.from(o)]}}if(r==="top"){var d,f;return{top:[...((d=c==null?void 0:c.top)!=null?d:[]).filter(x=>!(o!=null&&o.has(x))),...Array.from(o)],bottom:((f=c==null?void 0:c.bottom)!=null?f:[]).filter(x=>!(o!=null&&o.has(x)))}}return{top:((g=c==null?void 0:c.top)!=null?g:[]).filter(x=>!(o!=null&&o.has(x))),bottom:((m=c==null?void 0:c.bottom)!=null?m:[]).filter(x=>!(o!=null&&o.has(x)))}})},e.getCanPin=()=>{var r;const{enableRowPinning:n,enablePinning:i}=s.options;return typeof n=="function"?n(e):(r=n??i)!=null?r:!0},e.getIsPinned=()=>{const r=[e.id],{top:n,bottom:i}=s.getState().rowPinning,a=r.some(o=>n==null?void 0:n.includes(o)),l=r.some(o=>i==null?void 0:i.includes(o));return a?"top":l?"bottom":!1},e.getPinnedIndex=()=>{var r,n;const i=e.getIsPinned();if(!i)return-1;const a=(r=i==="top"?s.getTopRows():s.getBottomRows())==null?void 0:r.map(l=>{let{id:o}=l;return o});return(n=a==null?void 0:a.indexOf(e.id))!=null?n:-1}},createTable:e=>{e.setRowPinning=s=>e.options.onRowPinningChange==null?void 0:e.options.onRowPinningChange(s),e.resetRowPinning=s=>{var r,n;return e.setRowPinning(s?er():(r=(n=e.initialState)==null?void 0:n.rowPinning)!=null?r:er())},e.getIsSomeRowsPinned=s=>{var r;const n=e.getState().rowPinning;if(!s){var i,a;return!!((i=n.top)!=null&&i.length||(a=n.bottom)!=null&&a.length)}return!!((r=n[s])!=null&&r.length)},e._getPinnedRows=(s,r,n)=>{var i;
25return((i=e.options.keepPinnedRows)==null||i?(r??[]).map(l=>{const o=e.getRow(l,!0);return o.getIsAllParentsExpanded()?o:null}):(r??[]).map(l=>s.find(o=>o.id===l))).filter(Boolean).map(l=>({...l,position:n}))},e.getTopRows=_(()=>[e.getRowModel().rows,e.getState().rowPinning.top],(s,r)=>e._getPinnedRows(s,r,"top"),A(e.options,"debugRows")),e.getBottomRows=_(()=>[e.getRowModel().rows,e.getState().rowPinning.bottom],(s,r)=>e._getPinnedRows(s,r,"bottom"),A(e.options,"debugRows")),e.getCenterRows=_(()=>[e.getRowModel().rows,e.getState().rowPinning.top,e.getState().rowPinning.bottom],(s,r,n)=>{const i=new Set([...r??[],...n??[]]);return s.filter(a=>!i.has(a.id))},A(e.options,"debugRows"))}},fi={getInitialState:e=>({rowSelection:{},...e}),getDefaultOptions:e=>({onRowSelectionChange:pe("rowSelection",e),enableRowSelection:!0,enableMultiRowSelection:!0,enableSubRowSelection:!0}),createTable:e=>{e.setRowSelection=s=>e.options.onRowSelectionChange==null?void 0:e.options.onRowSelectionChange(s),e.resetRowSelection=s=>{var r;return e.setRowSelection(s?{}:(r=e.initialState.rowSelection)!=null?r:{})},e.toggleAllRowsSelected=s=>{e.setRowSelection(r=>{s=typeof s<"u"?s:!e.getIsAllRowsSelected();const n={...r},i=e.getPreGroupedRowModel().flatRows;return s?i.forEach(a=>{a.getCanSelect()&&(n[a.id]=!0)}):i.forEach(a=>{delete n[a.id]}),n})},e.toggleAllPageRowsSelected=s=>e.setRowSelection(r=>{const n=typeof s<"u"?s:!e.getIsAllPageRowsSelected(),i={...r};return e.getRowModel().rows.forEach(a=>{lr(i,a.id,n,!0,e)}),i}),e.getPreSelectedRowModel=()=>e.getCoreRowModel(),e.getSelectedRowModel=_(()=>[e.getState().rowSelection,e.getCoreRowModel()],(s,r)=>Object.keys(s).length?tr(e,r):{rows:[],flatRows:[],rowsById:{}},A(e.options,"debugTable")),e.getFilteredSelectedRowModel=_(()=>[e.getState().rowSelection,e.getFilteredRowModel()],(s,r)=>Object.keys(s).length?tr(e,r):{rows:[],flatRows:[],rowsById:{}},A(e.options,"debugTable")),e.getGroupedSelectedRowModel=_(()=>[e.getState().rowSelection,e.getSortedRowModel()],(s,r)=>Object.keys(s).length?tr(e,r):{rows:[],flatRows:[],rowsById:{}},A(e.options,"debugTable")),e.getIsAllRowsSelected=()=>{const s=e.getFilteredRowModel().flatRows,{rowSelection:r}=e.getState();let n=!!(s.length&&Object.keys(r).length);return n&&s.some(i=>i.getCanSelect()&&!r[i.id])&&(n=!1),n},e.getIsAllPageRowsSelected=()=>{const s=e.getPaginationRowModel().flatRows.filter(i=>i.getCanSelect()),{rowSelection:r}=e.getState();let n=!!s.length;return n&&s.some(i=>!r[i.id])&&(n=!1),n},e.getIsSomeRowsSelected=()=>{var s;const r=Object.keys((s=e.getState().rowSelection)!=null?s:{}).length;return r>0&&r<e.getFilteredRowModel().flatRows.length},e.getIsSomePageRowsSelected=()=>{const s=e.getPaginationRowModel().flatRows;return e.getIsAllPageRowsSelected()?!1:s.filter(r=>r.getCanSelect()).some(r=>r.getIsSelected()||r.getIsSomeSelected())},e.getToggleAllRowsSelectedHandler=()=>s=>{e.toggleAllRowsSelected(s.target.checked)},e.getToggleAllPageRowsSelectedHandler=()=>s=>{e.toggleAllPageRowsSelected(s.target.checked)}},createRow:(e,s)=>{e.toggleSelected=(r,n)=>{const i=e.getIsSelected();s.setRowSelection(a=>{var l;if(r=typeof r<"u"?r:!i,e.getCanSelect()&&i===r)return a;const o={...a};return lr(o,e.id,r,(l=n==null?void 0:n.selectChildren)!=null?l:!0,s),o})},e.getIsSelected=()=>{const{rowSelection:r}=s.getState();return yr(e,r)},e.getIsSomeSelected=()=>{const{rowSelection:r}=s.getState();return or(e,r)==="some"},e.getIsAllSubRowsSelected=()=>{const{rowSelection:r}=s.getState();return or(e,r)==="all"},e.getCanSelect=()=>{var r;return typeof s.options.enableRowSelection=="function"?s.options.enableRowSelection(e):(r=s.options.enableRowSelection)!=null?r:!0},e.getCanSelectSubRows=()=>{var r;return typeof s.options.enableSubRowSelection=="function"?s.options.enableSubRowSelection(e):(r=s.options.enableSubRowSelection)!=null?r:!0},e.getCanMultiSelect=()=>{var r;return typeof s.options.enableMultiRowSelection=="function"?s.options.enableMultiRowSelection(e):(r=s.options.enableMultiRowSelection)!=null?r:!0},e.getToggleSelectedHandler=()=>{const r=e.getCanSelect();return n=>{var i;r&&e.toggleSelected((i=n.target)==null?void 0:i.checked)}}}},lr=(e,s,r,n,i)=>{var a;const l=i.getRow(s,!0);r?(l.getCanMultiSelect()||Object.keys(e).forEach(o=>delete e[o]),l.getCanSelect()&&(e[s]=!0)):delete e[s],n&&(a=l.subRows)!=null&&a.length&&l.getCanSelectSubRows()&&l.subRows.forEach(o=>lr(e,o.id,r,n,i))};function tr(e,s){const r=e.getState().rowSelection,n=[],i={},a=function(l,o){return l.map(c=>{var g;const m=yr(c,r);if(m&&(n.push(c),i[c.id]=c),(g=c.subRows)!=null&&g.length&&(c={...c,subRows:a(c.subRows)}),m)return c}
25).filter(Boolean)};return{rows:a(s.rows),flatRows:n,rowsById:i}}function yr(e,s){var r;return(r=s[e.id])!=null?r:!1}function or(e,s,r){var n;if(!((n=e.subRows)!=null&&n.length))return!1;let i=!0,a=!1;return e.subRows.forEach(l=>{if(!(a&&!i)&&(l.getCanSelect()&&(yr(l,s)?a=!0:i=!1),l.subRows&&l.subRows.length)){const o=or(l,s);o==="all"?a=!0:(o==="some"&&(a=!0),i=!1)}}),i?"all":a?"some":!1}const dr=/([0-9]+)/gm,hi=(e,s,r)=>Nn(Te(e.getValue(r)).toLowerCase(),Te(s.getValue(r)).toLowerCase()),xi=(e,s,r)=>Nn(Te(e.getValue(r)),Te(s.getValue(r))),yi=(e,s,r)=>vr(Te(e.getValue(r)).toLowerCase(),Te(s.getValue(r)).toLowerCase()),vi=(e,s,r)=>vr(Te(e.getValue(r)),Te(s.getValue(r))),wi=(e,s,r)=>{const n=e.getValue(r),i=s.getValue(r);return n>i?1:n<i?-1:0},ji=(e,s,r)=>vr(e.getValue(r),s.getValue(r));function vr(e,s){return e===s?0:e>s?1:-1}function Te(e){return typeof e=="number"?isNaN(e)||e===1/0||e===-1/0?"":String(e):typeof e=="string"?e:""}function Nn(e,s){const r=e.split(dr).filter(Boolean),n=s.split(dr).filter(Boolean);for(;r.length&&n.length;){const i=r.shift(),a=n.shift(),l=parseInt(i,10),o=parseInt(a,10),c=[l,o].sort();if(isNaN(c[0])){if(i>a)return 1;if(a>i)return-1;continue}if(isNaN(c[1]))return isNaN(l)?-1:1;if(l>o)return 1;if(o>l)return-1}return r.length-n.length}const pt={alphanumeric:hi,alphanumericCaseSensitive:xi,text:yi,textCaseSensitive:vi,datetime:wi,basic:ji},bi={getInitialState:e=>({sorting:[],...e}),getDefaultColumnDef:()=>({sortingFn:"auto",sortUndefined:1}),getDefaultOptions:e=>({onSortingChange:pe("sorting",e),isMultiSortEvent:s=>s.shiftKey}),createColumn:(e,s)=>{e.getAutoSortingFn=()=>{const r=s.getFilteredRowModel().flatRows.slice(10);let n=!1;for(const i of r){const a=i==null?void 0:i.getValue(e.id);if(Object.prototype.toString.call(a)==="[object Date]")return pt.datetime;if(typeof a=="string"&&(n=!0,a.split(dr).length>1))return pt.alphanumeric}return n?pt.text:pt.basic},e.getAutoSortDir=()=>{const r=s.getFilteredRowModel().flatRows[0];return typeof(r==null?void 0:r.getValue(e.id))=="string"?"asc":"desc"},e.getSortingFn=()=>{var r,n;if(!e)throw new Error;return Ht(e.columnDef.sortingFn)?e.columnDef.sortingFn:e.columnDef.sortingFn==="auto"?e.getAutoSortingFn():(r=(n=s.options.sortingFns)==null?void 0:n[e.columnDef.sortingFn])!=null?r:pt[e.columnDef.sortingFn]},e.toggleSorting=(r,n)=>{const i=e.getNextSortingOrder(),a=typeof r<"u"&&r!==null;s.setSorting(l=>{const o=l==null?void 0:l.find(d=>d.id===e.id),c=l==null?void 0:l.findIndex(d=>d.id===e.id);let g=[],m,p=a?r:i==="desc";if(l!=null&&l.length&&e.getCanMultiSort()&&n?o?m="toggle":m="add":l!=null&&l.length&&c!==l.length-1?m="replace":o?m="toggle":m="replace",m==="toggle"&&(a||i||(m="remove")),m==="add"){var u;g=[...l,{id:e.id,desc:p}],g.splice(0,g.length-((u=s.options.maxMultiSortColCount)!=null?u:Number.MAX_SAFE_INTEGER))}else m==="toggle"?g=l.map(d=>d.id===e.id?{...d,desc:p}:d):m==="remove"?g=l.filter(d=>d.id!==e.id):g=[{id:e.id,desc:p}];return g})},e.getFirstSortDir=()=>{var r,n;return((r=(n=e.columnDef.sortDescFirst)!=null?n:s.options.sortDescFirst)!=null?r:e.getAutoSortDir()==="desc")?"desc":"asc"},e.getNextSortingOrder=r=>{var n,i;const a=e.getFirstSortDir(),l=e.getIsSorted();return l?l!==a&&((n=s.options.enableSortingRemoval)==null||n)&&(!(r&&(i=s.options.enableMultiRemove)!=null)||i)?!1:l
25==="desc"?"asc":"desc":a},e.getCanSort=()=>{var r,n;return((r=e.columnDef.enableSorting)!=null?r:!0)&&((n=s.options.enableSorting)!=null?n:!0)&&!!e.accessorFn},e.getCanMultiSort=()=>{var r,n;return(r=(n=e.columnDef.enableMultiSort)!=null?n:s.options.enableMultiSort)!=null?r:!!e.accessorFn},e.getIsSorted=()=>{var r;const n=(r=s.getState().sorting)==null?void 0:r.find(i=>i.id===e.id);return n?n.desc?"desc":"asc":!1},e.getSortIndex=()=>{var r,n;return(r=(n=s.getState().sorting)==null?void 0:n.findIndex(i=>i.id===e.id))!=null?r:-1},e.clearSorting=()=>{s.setSorting(r=>r!=null&&r.length?r.filter(n=>n.id!==e.id):[])},e.getToggleSortingHandler=()=>{const r=e.getCanSort();return n=>{r&&(n.persist==null||n.persist(),e.toggleSorting==null||e.toggleSorting(void 0,e.getCanMultiSort()?s.options.isMultiSortEvent==null?void 0:s.options.isMultiSortEvent(n):!1))}}},createTable:e=>{e.setSorting=s=>e.options.onSortingChange==null?void 0:e.options.onSortingChange(s),e.resetSorting=s=>{var r,n;e.setSorting(s?[]:(r=(n=e.initialState)==null?void 0:n.sorting)!=null?r:[])},e.getPreSortedRowModel=()=>e.getGroupedRowModel(),e.getSortedRowModel=()=>(!e._getSortedRowModel&&e.options.getSortedRowModel&&(e._getSortedRowModel=e.options.getSortedRowModel(e)),e.options.manualSorting||!e._getSortedRowModel?e.getPreSortedRowModel():e._getSortedRowModel())}},Ni=[Gs,di,si,ii,Us,qs,ci,ui,bi,ri,gi,pi,mi,fi,li];function Si(e){var s,r;const n=[...Ni,...(s=e._features)!=null?s:[]];let i={_features:n};const a=i._features.reduce((u,d)=>Object.assign(u,d.getDefaultOptions==null?void 0:d.getDefaultOptions(i)),{}),l=u=>i.options.mergeOptions?i.options.mergeOptions(a,u):{...a,...u};let c={...{},...(r=e.initialState)!=null?r:{}};i._features.forEach(u=>{var d;c=(d=u.getInitialState==null?void 0:u.getInitialState(c))!=null?d:c});const g=[];let m=!1;const p={_features:n,options:{...a,...e},initialState:c,_queue:u=>{g.push(u),m||(m=!0,Promise.resolve().then(()=>{for(;g.length;)g.shift()();m=!1}).catch(d=>setTimeout(()=>{throw d})))},reset:()=>{i.setState(i.initialState)},setOptions:u=>{const d=$e(u,i.options);i.options=l(d)},getState:()=>i.options.state,setState:u=>{i.options.onStateChange==null||i.options.onStateChange(u)},_getRowId:(u,d,f)=>{var x;return(x=i.options.getRowId==null?void 0:i.options.getRowId(u,d,f))!=null?x:`${f?[f.id,d].join("."):d}`},getCoreRowModel:()=>(i._getCoreRowModel||(i._getCoreRowModel=i.options.getCoreRowModel(i)),i._getCoreRowModel()),getRowModel:()=>i.getPaginationRowModel(),getRow:(u,d)=>{let f=(d?i.getPrePaginationRowModel():i.getRowModel()).rowsById[u];if(!f&&(f=i.getCoreRowModel().rowsById[u],!f))throw new Error;return f},_getDefaultColumnDef:_(()=>[i.options.defaultColumn],u=>{var d;return u=(d=u)!=null?d:{},{header:f=>{const x=f.header.column.columnDef;return x.accessorKey?x.accessorKey:x.accessorFn?x.id:null},cell:f=>{var x,C;return(x=(C=f.renderValue())==null||C.toString==null?void 0:C.toString())!=null?x:null},...i._features.reduce((f,x)=>Object.assign(f,x.getDefaultColumnDef==null?void 0:x.getDefaultColumnDef()),{}),...u}},A(e,"debugColumns")),_getColumnDefs:()=>i.options.columns,getAllColumns:_(()=>[i._getColumnDefs()],u=>{const d=function(f,x,C){return C===void 0&&(C=0),f.map(y=>{const w=Bs(i,y,C,x),S=y;return w.columns=S.columns?d(S.columns,w,C+1):[],w})};return d(u)},A(e,"debugColumns")),getAllFlatColumns:_(()=>[i.getAllColumns()],u=>u.flatMap(d=>d.getFlatColumns()),A(e,"debugColumns")),_getAllFlatColumnsById:_(()=>[i.getAllFlatColumns()],u=>u.reduce((d,f)=>(d[f.id]=f,d),{}),A(e,"debugColumns")),getAllLeafColumns:_(()=>[i.getAllColumns(),i._getOrderColumnsFn()],(u,d)=>{let f=u.flatMap(x=>x.getLeafColumns());return d(f)},A(e,"debugColumns")),getColumn:u=>i._getAllFlatColumnsById()[u]};Object.assign(i,p);for(let u=0;u<i._features.length;u++){const d=i._features[u];d==null||d.createTable==null||d.createTable(i)}return i}function Ci(){return e=>_(()=>[e.options.data],s=>{const r={rows:[],flatRows:[],rowsById:{}},n=function(i,a,l){a===void 0&&(a=0);const o=[];for(let g=0;g<i.length;g++){const m=hr(e,e._getRowId(i[g],g,l),i[g],g,a,void 0,l==null?void 0:l.id);if(r.flatRows.push(m),r.rowsById[m.id]=m,o.push(m),e.options.getSubRows){var c;m.originalSubRows=e.options.getSubRows(i[g],g),(c=m.originalSubRows)!=null&&c.length&&(m.subRows=n(m.originalSubRows,a+1,m))}}return o};return r.rows=n(s),r},A(e.options,"debugTable","getRowModel",()=>e._autoResetPageIndex()))}function ki(e){const s=[],r=n=>{var i;s.push(n),(i=n.subRows)!=null&&i.length&&n.getIsExpanded()&&n.subRows.forEach(r)};return e.rows.forEach(r),{rows:s,flatRows:e.flatRows,rowsById:e.rowsById}}function Ri(e,s,r){return r.options.filterFromLeafRows?Fi(e,s,r):Ei(e,s,r)}function Fi(e,s,r){var n;const i=[],a={},l=(n=r.options.maxLeafRowFilterDepth)!=null?n:100,o=function(c,g){g===void 0&&(g=0);const m=[];for(let u=0;u<c.length;u++){var p;let d=c[u];const f=hr(r,d.id,d.original,d.index,d.depth,void 0,d.parentId);if(f.columnFilters=d.columnFilters,(p=d.subRows)!=null&&p.length&&g<l){if(f.subRows=o(d.subRows,g+1),d=f,s(d)&&!f.subRows.length){m.push(d),a[d.id]=d,i.push(d);continue}if(s(d)||f.subRows.length){m.push(d),a[d.id]=d,i.push(d);continue}}else d=f,s(d)&&(m.push(d),a[d.id]=d,i.push(d))}return m};return{rows:o(e),flatRows:i,rowsById:a}}function Ei(e,s,r){var n;const i=[],a={},l=(n=r.options.maxLeafRowFilterDepth)!=null?n:100,o=function(c,g){g===void 0&&(g=0);const m=[];for(let u=0;u<c.length;u++){let d=c[u];if(s(d)){var p;if((p=d.subRows)!=null&&p.length&&g<l){const x=hr(r,d.id,d.original,d.index,d.depth,void 0,d.parentId);x.subRows=o(d.subRows,g+1),d=x}m.push(d),i.push(d),a[d.id]=d}}return m};return{rows:o(e),flatRows:i,rowsById:a}}function Mi(){return e=>_(()=>[e.getPreFilteredRowModel(),e.getState().columnFilters,e.getState().globalFilter],(s,r,n)=>{if(!s.rows.length||!(r!=null&&r.length)&&!n){for(let u=0;u<s.flatRows.length;u++)s.flatRows[u].columnFilters={},s.flatRows[u].columnFiltersMeta={};return s}const i=[],a=[];
25(r??[]).forEach(u=>{var d;const f=e.getColumn(u.id);if(!f)return;const x=f.getFilterFn();x&&i.push({id:u.id,filterFn:x,resolvedValue:(d=x.resolveFilterValue==null?void 0:x.resolveFilterValue(u.value))!=null?d:u.value})});const l=(r??[]).map(u=>u.id),o=e.getGlobalFilterFn(),c=e.getAllLeafColumns().filter(u=>u.getCanGlobalFilter());n&&o&&c.length&&(l.push("__global__"),c.forEach(u=>{var d;a.push({id:u.id,filterFn:o,resolvedValue:(d=o.resolveFilterValue==null?void 0:o.resolveFilterValue(n))!=null?d:n})}));let g,m;for(let u=0;u<s.flatRows.length;u++){const d=s.flatRows[u];if(d.columnFilters={},i.length)for(let f=0;f<i.length;f++){g=i[f];const x=g.id;d.columnFilters[x]=g.filterFn(d,x,g.resolvedValue,C=>{d.columnFiltersMeta[x]=C})}if(a.length){for(let f=0;f<a.length;f++){m=a[f];const x=m.id;if(m.filterFn(d,x,m.resolvedValue,C=>{d.columnFiltersMeta[x]=C})){d.columnFilters.__global__=!0;break}}d.columnFilters.__global__!==!0&&(d.columnFilters.__global__=!1)}}const p=u=>{for(let d=0;d<l.length;d++)if(u.columnFilters[l[d]]===!1)return!1;return!0};return Ri(s.rows,p,e)},A(e.options,"debugTable","getFilteredRowModel",()=>e._autoResetPageIndex()))}function Pi(e){return s=>_(()=>[s.getState().pagination,s.getPrePaginationRowModel(),s.options.paginateExpandedRows?void 0:s.getState().expanded],(r,n)=>{if(!n.rows.length)return n;const{pageSize:i,pageIndex:a}=r;let{rows:l,flatRows:o,rowsById:c}=n;const g=i*a,m=g+i;l=l.slice(g,m);let p;s.options.paginateExpandedRows?p={rows:l,flatRows:o,rowsById:c}:p=ki({rows:l,flatRows:o,rowsById:c}),p.flatRows=[];const u=d=>{p.flatRows.push(d),d.subRows.length&&d.subRows.forEach(u)};return p.rows.forEach(u),p},A(s.options,"debugTable"))}function Di(){return e=>_(()=>[e.getState().sorting,e.getPreSortedRowModel()],(s,r)=>{if(!r.rows.length||!(s!=null&&s.length))return r;const n=e.getState().sorting,i=[],a=n.filter(c=>{var g;return(g=e.getColumn(c.id))==null?void 0:g.getCanSort()}),l={};a.forEach(c=>{const g=e.getColumn(c.id);g&&(l[c.id]={sortUndefined:g.columnDef.sortUndefined,invertSorting:g.columnDef.invertSorting,sortingFn:g.getSortingFn()})});const o=c=>{const g=c.map(m=>({...m}));return g.sort((m,p)=>{for(let d=0;d<a.length;d+=1){var u;const f=a[d],x=l[f.id],C=x.sortUndefined,y=(u=f==null?void 0:f.desc)!=null?u:!1;let w=0;if(C){const S=m.getValue(f.id),h=p.getValue(f.id),b=S===void 0,k=h===void 0;if(b||k){if(C==="first")return b?-1:1;if(C==="last")return b?1:-1;w=b&&k?0:b?C:-C}}if(w===0&&(w=x.sortingFn(m,p,f.id)),w!==0)return y&&(w*=-1),x.invertSorting&&(w*=-1),w}return m.index-p.index}),g.forEach(m=>{var p;i.push(m),(p=m.subRows)!=null&&p.length&&(m.subRows=o(m.subRows))}),g};return{rows:o(r.rows),flatRows:i,rowsById:r.rowsById}},A(e.options,"debugTable","getSortedRowModel",()=>e._autoResetPageIndex()))}/** 26 * react-table 27 * 28 * Copyright (c) TanStack 29 * 30 * This source code is licensed under the MIT license found in the 31 * LICENSE.md file in the root directory of this source tree. 32 * 33 * @license MIT 34 */function Vt(e,s){return e?Ii(e)?v.createElement(e,s):e:null}function Ii(e){return $i(e)||typeof e=="function"||_i(e)}function $i(e){return typeof e=="function"&&(()=>{const s=Object.getPrototypeOf(e);return s.prototype&&s.prototype.isReactComponent})()}function _i(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Ai(e){const s={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[r]=v.useState(()=>({current:Si(s)})),[n,i]=v.useState(()=>r.current.initialState);return r.current.setOptions(a=>({...a,...e,state:{...n,...e.state},onStateChange:l=>{i(l),e.onStateChange==null||e.onStateChange(l)}})),r.current}function Ti({stats:e,selectedCount:s,onStatusFilterChange:r}){return t.jsxs("div",{className:"flex flex-nowrap overflow-x-auto pb-4 gap-3 -mx-4 px-4 snap-x snap-mandatory scrollbar-hide md:grid md:grid-cols-4 md:gap-4 md:mx-0 md:px-0 md:pb-0",children:[t.jsxs(Pe,{className:"min-w-[160px] md:min-w-0 flex-shrink-0 snap-center border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:border-green-500 transition-all duration-200 touch-manipulation active:scale-[0.98]",style:{cursor:"pointer"},onClick:()=>r("all"),children:[t.jsxs(Pt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[t.jsx("div",{className:"text-sm font-medium",children:"Total Entries"}),t.jsx(Ye,{className:"h-4 w-4 text-green-600"})]}),t.jsxs(De,{className:"py-2",children:[t.jsx("div",{className:"text-2xl font-extrabold text-gray-900 dark:text-gray-100",children:e.totalEntries}),t.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[e.totalHours.toFixed(2),"h total logged"]})]})]}),t.jsxs(Pe,{className:"min-w-[160px] md:min-w-0 flex-shrink-0 snap-center border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:border-amber-500 transition-all duration-200 touch-manipulation active:scale-[0.98]",style:{cursor:"pointer"},onClick:()=>r("pending"),children:[t.jsxs(Pt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[t.jsx("div",{className:"text-sm font-medium",children:"Pending"}),t.jsx(Xr,{className:"h-4 w-4 text-amber-600"})]}),t.jsxs(De,{className:"py-2",children:[t.jsx("div",{className:"text-2xl font-extrabold text-amber-600",children:e.pendingEntries}),t.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Awaiting approval"})]})]}),t.jsxs(Pe,{className:"min-w-[160px] md:min-w-0 flex-shrink-0 snap-center border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:border-green-500 transition-all duration-200 touch-manipulation active:scale-[0.98]",style:{cursor:"pointer"},onClick:()=>r("approved"),children:[t.jsxs(Pt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[t.jsx("div",{className:"text-sm font-medium",children:"Approved"}),t.jsx(mr,{className:"h-4 w-4 text-green-600"})]}),t.jsxs(De,{className:"py-2",children:[t.jsx("div",{className:"text-2xl font-extrabold text-green-600",children:e.approvedEntries}),t.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Ready for reporting"})]})]}),t.jsxs(Pe,{className:"min-w-[160px] md:min-w-0 flex-shrink-0 snap-center border border-gray-200 dark:border-gray-700 rounded-xl shadow-sm hover:border-green-500 transition-all duration-200 touch-manipulation active:scale-[0.98]",children:[t.jsxs(Pt,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[t.jsx("div",{className:"text-sm font-medium",children:"Selected"}),t.jsx(yt,{className:"h-4 w-4"})]}),t.jsxs(De,{className:"py-2",children:[t.jsx("div",{className:"text-2xl font-extrabold text-gray-900 dark:text-gray-100",children:s}),t.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Rows selected"})]})]})]})}function Sn({selectedMonth:e,goToPreviousMonth:s,goToNextMonth:r,isAtCurrentMonth:n}){const i=Jn(e),a=Zn(e),l=`${Ae(i,"MMM d").toUpperCase()} - ${Ae(a,"d yyyy")}`;return t.jsxs("div",{className:"flex items-center gap-2 w-full","data-testid":"monthly-filter-container",children:[t.jsxs("div",{className:"flex-1 flex items-center bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg px-3 py-2 h-10 shadow-sm",children:[t.jsx(Yr,{className:"w-4 h-4 text-gray-400 mr-2"}),t.jsx("span",{className:"text-sm font-semibold text-gray-700 dark:text-gray-200",children:l})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(L,{variant:"outline",size:"icon",onClick:s,className:"h-10 w-10 border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-500",title:"Previous month",children:t.jsx(sn,{className:"h-4 w-4"})}),t.jsx(L,{variant:"outline",size:"icon",onClick:r,disabled:n,className:"h-10 w-10 border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-500 disabled:opacity-50",title:"Next month",children:t.jsx(an,{className:"h-4 w-4"})})]})]})}function Vi({table:e,handleAddNewEntry:s,handleBulkEnhancement:r,handleBulkDelete:n,handleBulkApprove:i,handleBulkUnapprove:a,isApprovingBulk:l,isUnapprovingBulk:o,isBulkEnhancing:c,isDeletingBulk:g,showDeleted:m}){const p=e.getFilteredSelectedRowModel().rows.length;return t.jsx("div",{className:"flex items-center gap-3",children:p>0?t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(L,{variant:"outline",size:"default",onClick:r,disabled:c,title:`AI Enhance (${p})`,className:"h-11 text-purple-700 border-purple-300 hover:bg-purple-50 dark:text-purple-400 dark:border-purple-600 dar
34k:hover:bg-purple-900/20 flex items-center justify-center px-4 text-sm font-medium rounded-full shadow-sm",children:c?t.jsx(ae,{className:"h-5 w-5 animate-spin"}):t.jsx(nr,{className:"h-5 w-5 text-purple-600"})}),!m&&t.jsx(L,{variant:"destructive",size:"default",onClick:n,disabled:g,title:`Delete (${p})`,className:"h-11 flex items-center justify-center px-4 text-sm font-medium rounded-full shadow-sm",children:g?t.jsx(ae,{className:"h-5 w-5 animate-spin"}):t.jsx(Xe,{className:"h-5 w-5"})}),t.jsx(L,{variant:"default",size:"default",onClick:i,disabled:l,title:`Approve (${e.getFilteredSelectedRowModel().rows.filter(u=>{const d=u.original;return!d.isNew&&d.approvalStatus!=="approved"}).length})`,className:"h-11 bg-[#10B981] flex items-center justify-center px-4 text-sm font-medium rounded-full shadow-md hover:shadow-lg transition-shadow",children:l?t.jsx(ae,{className:"h-5 w-5 animate-spin"}):t.jsx(Dr,{className:"h-5 w-5"})}),t.jsx(L,{variant:"default",size:"default",onClick:a,disabled:o,title:`Unapprove (${e.getFilteredSelectedRowModel().rows.filter(u=>{const d=u.original;return!d.isNew&&d.approvalStatus!=="pending"}).length})`,className:"h-11 bg-[#6B7280] text-white flex items-center justify-center px-4 text-sm font-medium rounded-full shadow-md hover:shadow-lg transition-shadow",children:o?t.jsx(ae,{className:"h-5 w-5 animate-spin"}):t.jsx(Dr,{className:"h-5 w-5"})})]}):t.jsx(L,{onClick:s,title:"Add Entry",className:"h-11 flex items-center justify-center bg-green-600 hover:bg-green-700 text-white dark:bg-green-600 dark:hover:bg-green-700 px-6 py-2 text-sm font-medium rounded-full shadow-md hover:shadow-lg transition-all duration-200 active:scale-95",children:t.jsx(es,{className:"w-5 h-5"})})})}function Li(e,s){if(!e||e.length===0)throw new Error("No data to export");const n=[["Date","Hours","Activity Type","Category","Description","Property","Recorded By","Evidence File Name","Source","Approval Status","AI Summary","Created","Property Type"].map(o=>`"${o}"`).join(","),...e.map(o=>{var u,d;const c=((u=o.evidenceFiles)==null?void 0:u.map(f=>f.originalName||f.fileName).join("; "))||"None",g=((d=o.evidenceFiles)==null?void 0:d.filter(f=>f.aiSummary).map((f,x)=>`File ${x+1} (${f.originalName||f.fileName}): ${f.aiSummary}`).join(` 35 36`))||"No AI analysis available",m=o.recordedBy?o.recordedBy.firstName&&o.recordedBy.lastName?`${o.recordedBy.firstName} ${o.recordedBy.lastName}`:o.recordedBy.email:"";return[`"${Ae(new Date(o.date),"yyyy-MM-dd")}"`,`"${o.hours}"`,`"${o.activityType||""}"`,`"${o.isMaterialParticipation?"Material Participation Activity":"Qualified Non-Material"}"`,`"${(o.description||"").replace(/"/g,'""')}"`,`"${o.property?[o.property.nickname,o.property.address,o.property.city,o.property.state,o.property.zipCode].filter(Boolean).join(", "):""}"`,`"${m}"`,`"${c.replace(/"/g,'""')}"`,`"${o.source||"manual"}"`,`"${o.approvalStatus||"pending"}"`,`"${g.replace(/"/g,'""')}"`,`"${Ae(new Date(o.createdAt),"yyyy-MM-dd HH:mm:ss")}"`,`"${o.propertyType||"Long-term Rental"}"`].join(",")})].join(` 37`),i=new Blob([n],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),l=URL.createObjectURL(i);a.setAttribute("href",l),a.setAttribute("download",s),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(l)}function Qr({data:e,selectedRowsCount:s=0,trigger:r}){const[n,i]=v.useState(!1),[a,l]=v.useState(!1),{toast:o}=ye(),c=e.length,g=e.filter(h=>h.evidenceFiles&&h.evidenceFiles.length>0).length,m=e.reduce((h,b)=>{var k;return h+(((k=b.evidenceFiles)==null?void 0:k.length)||0)},0),p=e.reduce((h,b)=>{var k;return h+(((k=b.evidenceFiles)==null?void 0:k.filter(M=>M.aiSummary).length)||0)},0),u=e.filter(h=>{var b;return((b=h.source)==null?void 0:b.includes("gmail"))||h.emailThreadId}).length,d=e.filter(h=>h.emailSubject).length,f=e.reduce((h,b)=>h+(b.emailMessageCount||0),0),x=e.reduce((h,b)=>h+(b.emailWordCount||0),0),C=s>0?`${s} selected entries`:`${c} entries`,y=async()=>{l(!0);try{const h=`enhanced-entries-${Ae(new Date,"yyyy-MM-dd-HHmm")}.csv`;Li(e,h),o({title:"Enhanced CSV Export Complete",description:`Exported ${c} entries with file names and AI summaries to ${h}`}),i(!1)}catch{o({title:"Export Failed",description:"Failed to export enhanced CSV. Please try again.",variant:"destructive"})}finally{l(!1)}},w=async()=>
37{l(!0);try{const h=await fetch("/api/export/evidence-files",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timeEntryIds:e.map(k=>k.id)})});if(!h.ok){const k=await h.text();throw console.error("â Export error response:",k),new Error(`Export failed: ${h.status} ${h.statusText}`)}const b=await h.json();if(!b.success||!b.downloadUrl)throw new Error("Export failed: No download URL received");window.location.href=b.downloadUrl,o({title:"Evidence Files Export Complete",description:`Export ready: ${b.fileCount} files. Download will start automatically.`}),i(!1)}catch(h){console.error("ð¥ Export error:",h),o({title:"Export Failed",description:h instanceof Error?h.message:"Failed to export evidence files. Please try again.",variant:"destructive"})}finally{l(!1)}},S=async()=>{l(!0);try{const h=await fetch("/api/export/combined",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timeEntryIds:e.map(k=>k.id)})});if(!h.ok){const k=await h.text();throw console.error("â Combined export error response:",k),new Error(`Combined export failed: ${h.status} ${h.statusText}`)}const b=await h.json();if(!b.success||!b.downloadUrl)throw new Error("Combined export failed: No download URL received");window.location.href=b.downloadUrl,o({title:"Combined Export Complete",description:`Export ready: ${b.entryCount} entries with ${b.fileCount} files. Download will start automatically.`}),i(!1)}catch{o({title:"Export Failed",description:"Failed to create combined export. Please try again.",variant:"destructive"})}finally{l(!1)}};return t.jsxs(cr,{open:n,onOpenChange:i,children:[t.jsx(ts,{asChild:!0,children:r||t.jsxs(L,{variant:"outline",children:[t.jsx(xt,{className:"mr-2 h-4 w-4"}),"Export"]})}),t.jsxs(ur,{className:"max-w-lg",children:[t.jsxs(gr,{children:[t.jsxs(pr,{className:"flex items-center gap-2",children:[t.jsx(Br,{className:"h-5 w-5"}),"Enhanced Export Options"]}),t.jsxs(rs,{children:["Choose how you want to export your activity data and evidence files. Exporting ",C," from the current view."]})]}),t.jsxs("div",{className:"grid grid-cols-4 gap-2 mb-4",children:[t.jsxs("div",{className:"text-center p-1.5 bg-muted rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:c}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"Entries"})]}),t.jsxs("div",{className:"text-center p-1.5 bg-muted rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:g}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"With Files"})]}),t.jsxs("div",{className:"text-center p-1.5 bg-muted rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:m}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"Total Files"})]}),t.jsxs("div",{className:"text-center p-1.5 bg-muted rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:p}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"AI Analyzed"})]})]}),u>0&&t.jsxs("div",{className:"mb-4",children:[t.jsxs("h4",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:["ð§ Gmail Metadata Included",t.jsxs(ne,{variant:"secondary",className:"text-xs",children:[u," Gmail entries"]})]}),t.jsxs("div",{className:"grid grid-cols-4 gap-2",children:[t.jsxs("div",{className:"text-center p-1.5 bg-blue-50 dark:bg-blue-950 rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:u}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"Gmail Entries"})]}),t.jsxs("div",{className:"text-center p-1.5 bg-blue-50 dark:bg-blue-950 rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:d}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"With Subjects"})]}),t.jsxs("div",{className:"text-center p-1.5 bg-blue-50 dark:bg-blue-950 rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:f}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"Total Messages"})]}),t.jsxs("div",{className:"text-center p-1.5 bg-blue-50 dark:bg-blue-950 rounded",children:[t.jsx("div",{className:"text-sm font-semibold",children:x.toLocaleStr
37ing()}),t.jsx("div",{className:"text-xs text-muted-foreground",children:"Total Words"})]})]})]}),t.jsxs("div",{className:"space-y-3",children:[t.jsx(Pe,{className:"hover:bg-muted/30 transition-colors",children:t.jsxs(De,{className:"p-4",children:[t.jsx("div",{className:"flex items-center justify-between mb-2",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Ss,{className:"h-4 w-4 text-green-600"}),t.jsx("span",{className:"font-medium",children:"Enhanced CSV"}),t.jsx(ne,{variant:"secondary",className:"text-xs",children:"Entries Only"})]})}),t.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Enhanced data with file names and AI summaries"}),t.jsx(L,{onClick:y,disabled:a,className:"w-full",variant:"outline",size:"sm",children:a?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-3 w-3 animate-spin"}),"Exporting..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Ye,{className:"mr-2 h-3 w-3"}),"Export CSV"]})})]})}),t.jsx(Pe,{className:"hover:bg-muted/30 transition-colors",children:t.jsxs(De,{className:"p-4",children:[t.jsx("div",{className:"flex items-center justify-between mb-2",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Vr,{className:"h-4 w-4 text-blue-600"}),t.jsx("span",{className:"font-medium",children:"Evidence Files"}),t.jsx(ne,{variant:"secondary",className:"text-xs",children:"ZIP Archive"})]})}),t.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Organized folders with entry metadata"}),t.jsx(L,{onClick:w,disabled:a||m===0,className:"w-full",variant:"outline",size:"sm",children:a?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-3 w-3 animate-spin"}),"Preparing..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Vr,{className:"mr-2 h-3 w-3"}),"Download (",m," files)"]})})]})}),t.jsx(Pe,{className:"hover:bg-muted/30 transition-colors border border-primary/40",children:t.jsxs(De,{className:"p-4",children:[t.jsx("div",{className:"flex items-center justify-between mb-2",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Br,{className:"h-4 w-4 text-purple-600"}),t.jsx("span",{className:"font-medium",children:"Complete Package"}),t.jsx(ne,{variant:"default",className:"text-xs",children:"Recommended"})]})}),t.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"Single ZIP with enhanced CSV + organized evidence files"}),t.jsx(L,{onClick:S,disabled:a,className:"w-full",size:"sm",children:a?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-3 w-3 animate-spin"}),"Creating Package..."]}):t.jsxs(t.Fragment,{children:[t.jsx(xt,{className:"mr-2 h-3 w-3"}),"Export Everything"]})})]})})]}),m===0&&t.jsx("div",{className:"text-center p-4 bg-muted/50 rounded-lg text-sm text-muted-foreground",children:"No evidence files found in the selected entries. File export options will download an empty archive."})]})]})}function Cn({globalFilter:e,setGlobalFilter:s,statusFilter:r,setStatusFilter:n,table:i,allData:a,onImportClick:l,onRefresh:o,isLoading:c,showDeleted:g,setShowDeleted:m,showMobileFilters:p,setShowMobileFilters:u}){const d=fr(),f=p!==void 0?p:!1,x=u||(()=>{}),C=t.jsxs("div",{className:"hidden sm:flex flex-col sm:flex-row items-start sm:items-center gap-4",children:[t.jsxs("div",{className:"flex items-center space-x-3 w-72 flex-shrink-0",children:[t.jsx(Ir,{className:"h-5 w-5 text-green-600 dark:text-green-400 flex-shrink-0"}),t.jsx(ve,{placeholder:"Search entries...",value:e??"",onChange:y=>s(y.target.value),className:`w-full h-10 text-base rounded-lg border border-gray-300 dark:border-gray-700 38 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 39 placeholder-gray-400 dark:placeholder-gray-500 40 focus:outline-none focus:ring-2 focus:ring-green-500 dark:focus:ring-green-400`})]}),t.jsxs("div",{className:"w-full sm:w-auto flex items-center gap-3 overflow-x-auto scrollbar-hide pb-2 -mx-4 px-4 sm:mx-0 sm:px-0 sm:pb-0 sm:overflow-visible sm:flex-wrap",children:[t.jsxs(be,{value:r,onValueChange:n,children:[t.jsx(Ne,{className:"w-[50px] h-11 text-sm rounded-full border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 dark:focus:ring-green-400 shadow-sm flex-shrink-0",title:"Status",children:t.jsx("div",{className:"flex items-center gap-2",children:t.jsx(Lr,{className:"h-4 w-4 text-green-600 dark:text-green-400"})})}),t.jsxs(Se,{children:[t.jsx(te,{value:"all",children:"All Status"}),t.jsx(te,{value:"pending",children:"Pending"}),t.jsx(te,{value:"approved",children:"Approved"})]})]}),m&&t.jsx("div",{className:"flex items-center space-x-2 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-full px-4 h-11 flex-shrink-0 shadow-sm cursor-pointer active:scale-95 transition-transform",onClick:()=>m(!g),title:"Show Deleted",children:t.jsx(yt,{id:"show-deleted",checked:g,onCheckedChange:y=>m(!!y),className:"data-[state=checked]:bg-green-600 data-[state=checked]:border-green-600"})}),t.jsxs(ln,{children:[t.jsx(on,{asChild:!0,children:t.jsx(L,{variant:"outline",title:"Columns",className:"h-11 text-sm flex items-center justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 px-4 flex-shrink-0 shadow-sm",children:t.jsx($r,{className:"h-4 w-4 text-green-600 dark:text-green-400"})})}),t.jsx(dn,{align:"end",className:"bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-700 shadow-lg rounded-md",children:i.getAllColumns().filter(y=>y.getCanHide()).map(y=>t.jsx(ns,{className:"capitalize text-sm text-gray-700 dark:text-gray-300",checked:y.getIsVisible(),onCheckedChange:w=>y.toggleVisibility(!!w),children:y.id},y.id))})]}),t.jsx(L,{variant:"outline",onClick:l,title:"Import CSV",className:"h-11 text-sm flex items-center justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 px-4 flex-shrink-0 shadow-sm",children:t.jsx(ft,{className:"h-4 w-4 text-green-600 dark:text-green-400"})}),t.jsx(Qr,{data:a,selectedRowsCount:a.length,trigger:t.jsx(L,{variant:"outline",title:"Export",className:"h-11 text-sm flex items-center justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 px-4 flex-shrink-0 shadow-sm",children:t.jsx(xt,{className:"h-4 w-4 text-green-600 dark:text-green-400"})})}),t.jsx(L,{onClick:o,variant:"outline",disabled:c,title:"Refresh",className:"h-11 text-sm flex items-center justify-center rounded-full border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50 px-4 flex-shrink-0 shadow-sm",children:t.jsx(sr,{className:`h-4 w-4 text-green-600 dark:text-green-400 ${c?"animate-spin":""}`})})]})]});return t.jsxs("div",{className:"pb-6 border-b border-gray-300 dark:border-gray-600 mb-6",children:[p===void 0&&t.jsxs("div",{className:"sm:hidden flex items-center gap-3 w-full mb-2",children:[t.jsxs("div",{className:"relative flex-[8.5] min-w-0",children:[t.jsx(Ir,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-green-600 dark:text-green-400"}),t.jsx(ve,{placeholder:"Search entries...",value:e??"",onChange:y=>s(y.target.value),className:`w-full h-12 pl-10 text-base rounded-2xl border border-gray-300 dark:border-gray-700 41 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 42 placeholder-gray-400 dark:placeholder-gray-500 43 focus:outline-none focus:ring-2 focus:ring-green-500 dark:focus:ring-green-400 shadow-sm`})]}),t.jsx(L,{variant:"outline",onClick:()=>x(!0),className:"flex-[1.5] h-12 rounded-2xl border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 shadow-sm flex items-center justify-center p-0",children:t.jsx(gn,{className:"h-6 w-6 text-green-600 dark:text-green-400"})})]}),t.jsx(ss,{open:f,onOpenChange:x,title:"Table Actions & Filters",children:t.jsxs("div",{className:"p-4 space-y-6",children:[t.jsxs("div",{className:"space-y-4",children:[t.jsx("h3",{className:"text-sm font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Filters"}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-sm font-medium",children:"Approval Status"}),t.jsxs(be,{value:r,onValueChange:n,children:[t.jsx(Ne,{className:"w-full h-12 rounded-xl",children:t.jsxs("div",{className:"flex items-center gap-2 text-base",children:[t.jsx(Lr,{className:"h-4 w-4 text-green-600"}),t.jsx("span",{children:r==="all"?"All Statuses":r.charAt(0).toUpperCase()+r.slice(1)})]})}),t.jsxs(Se,{children:[t.jsx(te,{value:"all",children:"All Status"}),t.jsx(te,{value:"pending",children:"Pending"}),t.jsx(te,{value:"approved",children:"Approved"})]})]})]}),m&&t.jsx("div",{className:"flex items-center justify-between bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 rounded-xl p-4 cursor-pointer",onClick:()=>m(!g),children:t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx(yt,{id:"mobile-show-deleted",checked:g,onCheckedChange:y=>m(!!y),className:"h-5 w-5 data-[state=checked]:bg-green-600 data-[state=checked]:border-green-600"}),t.jsx("label",{htmlFor:"mobile-show-deleted",className:"text-base font-medium",children:"Show Deleted
43Entries"})]})})]}),t.jsxs("div",{className:"space-y-4",children:[t.jsx("h3",{className:"text-sm font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Columns Visibility"}),t.jsx("div",{className:"grid grid-cols-2 gap-2",children:i.getAllColumns().filter(y=>y.getCanHide()).map(y=>t.jsxs(L,{variant:y.getIsVisible()?"default":"outline",className:re("justify-start text-sm h-10 rounded-lg capitalize truncate",y.getIsVisible()?"bg-green-600 hover:bg-green-700 text-white":"border-gray-200"),onClick:()=>y.toggleVisibility(!y.getIsVisible()),children:[t.jsx($r,{className:"h-3.5 w-3.5 mr-2 opacity-70"}),y.id]},y.id))})]}),t.jsxs("div",{className:"space-y-4 pt-4 border-t border-gray-100 dark:border-gray-800",children:[t.jsx("h3",{className:"text-sm font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wider",children:"Actions"}),t.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[t.jsxs(L,{variant:"outline",onClick:()=>{x(!1),l()},className:"w-full h-12 justify-start text-base rounded-xl border-gray-200",children:[t.jsx(ft,{className:"h-5 w-5 mr-3 text-green-600"}),"Import CSV"]}),t.jsx(Qr,{data:a,selectedRowsCount:a.length,trigger:t.jsxs(L,{variant:"outline",className:"w-full h-12 justify-start text-base rounded-xl border-gray-200 text-gray-900 dark:text-gray-100",children:[t.jsx(xt,{className:"h-5 w-5 mr-3 text-green-600"}),"Export to Excel/CSV"]})}),t.jsxs(L,{onClick:()=>{o(),x(!1)},variant:"outline",disabled:c,className:"w-full h-12 justify-start text-base rounded-xl border-gray-200",children:[t.jsx(sr,{className:`h-5 w-5 mr-3 text-green-600 ${c?"animate-spin":""}`}),"Refresh Data"]})]})]})]})}),!d&&C]})}function Hi({stats:e,table:s,rowSelection:r,selectedMonth:n,goToNextMonth:i,goToPreviousMonth:a,isAtCurrentMonth:l,viewMode:o,setViewMode:c,globalFilter:g,setGlobalFilter:m,statusFilter:p,setStatusFilter:u,groupedData:d,loading:f,entries:x,newEntries:C,fetchData:y,filteredData:w,properties:S,handleAddNewEntry:h,handleBulkEnhancement:b,handleBulkDelete:k,handleBulkApprove:M,handleBulkUnapprove:D,isBulkEnhancing:T,isDeletingBulk:I,isApprovingBulk:U,isUnapprovingBulk:q,showDeleted:Q,setShowDeleted:Z,showImportDialog:de,setShowImportDialog:J,selectedEntry:Ve,setSelectedEntry:Je,showDetailsDialog:Le,setShowDetailsDialog:Ze,entryToModify:et,setEntryToModify:tt,showModifyEntryDialog:rt,setShowModifyEntryDialog:le,showDuplicateDialog:je,setShowDuplicateDialog:Be,entryToDuplicate:nt,setEntryToDuplicate:ue,showDeleteDialog:Ge,setShowDeleteDialog:me,entryToDelete:He,handleDeleteEntry:st,confirmDeleteEntry:Oe,isDeletingEntry:Ue,showNewEntryDialog:it,setShowNewEntryDialog:at,isCreating:lt,setIsCreating:ot,showFilePreview:dt,setShowFilePreview:se,selectedFile:N,setSelectedFile:R,previewFile:P,setPreviewFile:$,isFilePreviewOpen:O,currentFileIndex:z,setCurrentFileIndex:F,handleOpenFilePreview:B,downloadFile:H,deleteFileDialogOpen:X,setDeleteFileDialogOpen:Ce,fileToDelete:fe,handleFileDeleteClick:qe,confirmFileDelete:We,deleteFileMutation:Ot,sharedDialogs:Qe,onCreateEntry:he,glowingDescriptions:Et,setGlowingDescriptions:zt}){var ct;return t.jsx(t.Fragment,{children:t.jsxs("div",{className:"container-mobile py-12 space-y-12",children:[t.jsx("div",{className:"mb-6 sm:mb-8",children:t.jsxs("div",{className:"flex flex-col",children:[t.jsx("h1",{className:"text-3xl md:text-4xl font-extrabold tracking-tight text-gray-900 dark:text-gray-100",children:"Activity Ledger"}),t.jsxs("p",{className:"text-gray-500 dark:text-gray-400 mt-1 text-sm md:text-base",children:["Advanced table with sorting, filtering, and bulk operations â"," ",t.jsxs("span",{className:"text-green-600 font-semibold",children:[e.totalEntries," total entries"]})]})]})}),t.jsx(Ti,{stats:e,selectedCount:Object.keys(r).length,onStatusFilterChange:G=>{u(G),c("all-entries")}}),t.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[t.jsxs("div",{className:"flex flex-col sm:flex-row items-center sm:items-center gap-3 w-full sm:w-auto",children:[t.jsx(is,{value:o,onValueChange:G=>c(G),className:"w-full sm:w-[300px]",children:t.jsxs(as,{className:"grid w-full grid-cols-2 h-11 bg-muted/50 p-1 rounded-xl",children:[t.jsx(_r,{value:"monthly",className:"text-sm rounded-lg data-[state=active]:bg-white dark:data-[state=active]:bg-gray-700",children:"Monthly View"}),t.jsx(_r,{value:"all-entries",className:"text-sm rounded-lg data-[state=active]:bg-white dark:data-[state=active]:bg-gray-700",children:"All Entries"})]})}),o==="monthly"&&t.jsx("div",{className:"w-full sm:w-auto flex justify-center py-1",children:t.jsx(Sn,{selectedMonth:n,goToPreviousMonth:a,goToNextMonth:i,isAtCurrentMonth:l})})]}),t.jsx("div",{className:"flex items-center justify-end flex-1 w-full sm:w-auto",children:t.jsx(Vi,{table:s,handleAddNewEntry:()=>h(),handleBulkEnhancement:b,handleBulkDelete:k,isBulkEnhancing:T,isDeletingBulk:I,showDeleted:Q,handleBulkApprove:M,handleBulkUnapprove:D,isApprovingBulk:U,isUnapprovingBulk:q})})]}),t.jsx(Pe,{className:"border border-gray-300 dark:border-gray-600 rounded-xl bg-white dark:bg-gray-900",children:t.jsxs(De,{className:"pt-6 px-6",children:[t.jsx(Cn,{globalFilter:g,setGlobalFilter:m,statusFilter:p,setStatusFilter:u,table:s,allData:[...C,...x],onImportClick:()=>J(!0),onRefresh:y,isLoading:f,showDeleted:Q,setShowDeleted:Z}),t.jsx("div",{"data-tour":"activity-ledger-datatable",className:"rounded-lg border border-gray-300 dark:border-gray-600 overflow-auto max-h-[calc(100vh-280px)] bg-white dark:bg-gray-900",children:t.jsxs(Jr,{className:"w-full divide-y divide-gray-200 dark:divide-gray-700",children:[t.jsx(Zr,{className:"bg-gray-100 dark:bg-gray-800/80 sticky top-0 z-10",children:s.getHeaderGroups().map(G=>{const ee=s.getVisibleLeafColumns().map(ie=>ie.id);return t.jsx(Ee,{children:G.headers.map(ie=>{const K=$t(ie.id,ee);return t.jsx(Fe,{className:`${K.className} align-middle`,style:K.style,children:ie.isPlaceholder?null:t.jsx("div",{className:ie.id==="select"?"flex justify-center items-center w-full":"text-left font-semibold text-sm text-gray-800 dark:text-gray-200 tracking-wide select-none",style:{lineHeight:"1.5rem"},children:Vt(ie.column.columnDef.header,ie.getContext())})},ie.id)})},G.id)})}),t.jsx(en,{className:"divide-y divide-gray-200 dark:divide-gray-700",children:f?t.jsx(Ee,{children:t.jsx(ce,{colSpan:s.getVisibleLeafColumns().length,className:"h-28 text-center text-gray-600 dark:text-gray-400",children:t.jsxs("div",{className:"flex items-center justify-center space-x-3 text-sm",children:[t.jsx(ae,{className:"h-5 w-5 animate-spin text-green-600 dark:text-green-400"}
43),t.jsx("span",{children:"Loading entries..."})]})})}):(ct=s.getRowModel().rows)!=null&&ct.length?t.jsx(t.Fragment,{children:p==="all"&&(d.pending.length>0||d.approved.length>0)?t.jsxs(t.Fragment,{children:[d.pending.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ee,{className:"bg-red-100/70 dark:bg-red-900/50",children:t.jsxs(ce,{colSpan:s.getVisibleLeafColumns().length,className:"px-6 py-3 font-semibold text-red-800 dark:text-red-400 text-sm select-none",children:["ð Pending Entries (",d.pending.length,")"]})}),s.getRowModel().rows.filter(G=>{const ee=G.original;return ee.isNew||(ee.approvalStatus||"pending")==="pending"}).map(G=>{const ee=G.original,ie=s.getVisibleLeafColumns().map(K=>K.id);return t.jsx(Ee,{"data-state":G.getIsSelected()&&"selected",className:`text-sm transition-colors ${ee.deletedAt?"bg-gray-100 dark:bg-gray-800 opacity-60 line-through":ee.isNew?"bg-blue-50 dark:bg-blue-900 hover:bg-blue-100 dark:hover:bg-blue-800 border-l-4 border-blue-400 dark:border-blue-600":"bg-red-50 dark:bg-red-900 hover:bg-red-100 dark:hover:bg-red-800 border-l-4 border-red-400 dark:border-red-600"} data-[state=selected]:bg-blue-100 dark:data-[state=selected]:bg-blue-900`,children:G.getVisibleCells().map(K=>{const ke=$t(K.column.id,ie,"px-3 py-4 text-gray-900 dark:text-gray-200");return t.jsx(ce,{className:ke.className,style:ke.style,children:Vt(K.column.columnDef.cell,K.getContext())},K.id)})},G.id)})]}),d.approved.length>0&&t.jsx(t.Fragment,{children:s.getRowModel().rows.filter(G=>{const ee=G.original;return!ee.isNew&&ee.approvalStatus==="approved"}).map(G=>{const ee=G.original,ie=s.getVisibleLeafColumns().map(K=>K.id);return t.jsx(Ee,{"data-state":G.getIsSelected()&&"selected",className:`text-sm transition-colors ${ee.deletedAt?"bg-gray-100 dark:bg-gray-800 opacity-60 line-through":"bg-green-50 dark:bg-green-900 hover:bg-green-100 dark:hover:bg-green-800"} data-[state=selected]:bg-blue-100 dark:data-[state=selected]:bg-blue-900`,children:G.getVisibleCells().map(K=>{const ke=$t(K.column.id,ie,"px-6 py-3 text-gray-900 dark:text-gray-200");return t.jsx(ce,{className:ke.className,style:ke.style,children:Vt(K.column.columnDef.cell,K.getContext())},K.id)})},G.id)})})]}):s.getRowModel().rows.map(G=>{const ee=G.original,ie=ee.isNew;return t.jsx(Ee,{"data-state":G.getIsSelected()&&"selected",className:`text-sm transition-colors ${ee.deletedAt?"bg-gray-100 dark:bg-gray-800 opacity-60 line-through":ie?"bg-blue-50 dark:bg-blue-900 hover:bg-blue-100 dark:hover:bg-blue-800 border-l-4 border-blue-400 dark:border-blue-600":ee.approvalStatus==="approved"?"bg-green-50 dark:bg-green-900 hover:bg-green-100 dark:hover:bg-green-800":"bg-red-50 dark:bg-red-900 hover:bg-red-100 dark:hover:bg-red-800 border-l-4 border-red-400 dark:border-red-600"} data-[state=selected]:bg-blue-100 dark:data-[state=selected]:bg-blue-900`,children:G.getVisibleCells().map(K=>{const ke=$t(K.column.id,s.getVisibleLeafColumns().map(wr=>wr.id),"px-6 py-3 text-gray-900 dark:text-gray-200");return t.jsx(ce,{className:ke.className,style:ke.style,children:Vt(K.column.columnDef.cell,K.getContext())},K.id)})},G.id)})}):t.jsx(Ee,{children:t.jsx(ce,{colSpan:s.getVisibleLeafColumns().length,className:"h-28 text-center text-gray-600 dark:text-gray-400",children:"No entries found"})})})]})}),t.jsxs("div",{className:"flex flex-col lg:flex-row items-center justify-between gap-4 py-4 px-2",children:[t.jsx("div",{className:"flex-1 flex flex-col lg:flex-row items-center space-y-2 lg:space-y-0 lg:space-x-5 text-sm text-gray-600 dark:text-gray-400 select-none",children:t.jsxs("span",{children:[s.getFilteredSelectedRowModel().rows.length," of"," ",s.getFilteredRowModel().rows.length," row(s) selected."]})}),t.jsxs("div",{className:"flex items-center space-x-6",children:[t.jsxs("div",{className:"flex items-center space-x-3 text-sm font-light text-gray-700 dark:text-gray-300 select-none",children:[t.jsx("span",{children:"Rows per page"}),t.jsxs(be,{value:`${s.getState().pagination.pageSize}`,onValueChange:G=>s.setPageSize(Number(G)),children:[t.jsx(Ne,{className:"h-9 w-[75px] text-sm font-light rounded-md border border-gray-300 dark:border-gray-700 bg-gray-50 dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-green-500 dark:focus:ring-green-400",children:t.jsx(_e,{placeholder:s.getState().pagination.pageSize})}),t.jsx(Se,{side:"top",className:"bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-md shadow-lg",children:[25,50,100,250].map(G=>t.jsx(te,{value:`${G}`,className:"font-light text-gray-900 dark:text-gray-100",children:G},G))})]})]}),t.jsxs("div",{className:"flex w-[110px] justify-center text-sm font-light text-gray-700 dark:text-gray-300 select-none",children:["Page ",s.getState().pagination.pageIndex+1," of"," ",s.getPageCount()]}),t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx(L,{variant:"outline",className:"h-9 w-9 p-0 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50",onClick:()=>s.previousPage(),disabled:!s.getCanPreviousPage(),"aria-label":"Previous Page",children:t.jsx(sn,{className:"h-5 w-5 text-green-600 dark:text-green-400"})}),t.jsx(L,{variant:"outline",className:"h-9 w-9 p-0 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50",onClick:()=>s.nextPage(),disabled:!s.getCanNextPage(),"aria-label":"Next Page",children:t.jsx(an,{className:"h-5 w-5 text-green-600 dark:text-green-400"})})]})]})]})]})}),Qe]})})}function Oi({entry:e,onUpdate:s,isEditing:r,onStartEdit:n,onCancelEdit:i}){var C;const[a,l]=v.useState(((C=e.date)==null?void 0:C.substring(0,10))||""),[o,c]=v.useState(!1),[g,m]=v.useState(!1),{toast:p}=ye(),u=new Date().getFullYear();v.useEffect(()=>{r&&a&&(new Date(a).getFullYear()<u?m(!0):m(!1))},[a,r,u]);const d=async()=>{var y;if(a===((y=e.date)==null?void 0:y.split("T")[0])){i();return}c(!0);try{await s(e.id,"date",a),i()}catch(w){console.error("Error updating date:",w)}finally{c(!1)}},f=()=>{d()},x=y=>{var w;y.key==="Enter"?d():y.key==="Escape"&&(l(((w=e.date)==null?void 0:w.split("T")[0])||""),i())};return r?t.jsxs("div",{className:"flex flex-col gap-2 w-full",children:[g&&t.jsxs("div",{className:"flex items-start gap-2 p-2 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-md",children:[t.jsx(rr,{className:"h-4 w-4 text-amber-600 dar
43k:text-amber-400 flex-shrink-0 mt-0.5"}),t.jsxs("div",{className:"flex-1 text-xs text-amber-800 dark:text-amber-200",children:[t.jsx("span",{className:"font-semibold",children:"Previous Tax Year:"})," You are logging hours for a previous tax year. These will not count toward your current goals."]})]}),t.jsx(ve,{type:"date",value:a,onChange:y=>{l(y.target.value),new Date(y.target.value).getFullYear()<u&&p({title:"Previous Tax Year Selected",description:"You are logging hours for a previous tax year. These will not count toward your current goals.",variant:"default"})},onBlur:f,onKeyDown:x,className:"w-full",autoFocus:!0})]}):t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded",onClick:n,children:e.date?St(e.date):"Click to set date"})}function zi({entry:e,onUpdate:s,isEditing:r,onStartEdit:n,onCancelEdit:i}){var u;const[a,l]=v.useState(((u=e.hours)==null?void 0:u.toString())||""),[o,c]=v.useState(!1),g=async()=>{var d;if(a===((d=e.hours)==null?void 0:d.toString())){i();return}c(!0);try{await s(e.id,"hours",a),i()}catch(f){console.error("Error updating hours:",f),i()}finally{c(!1)}},m=()=>{setTimeout(()=>{g()},250)},p=d=>{var f;d.key==="Enter"?g():d.key==="Escape"&&(l(((f=e.hours)==null?void 0:f.toString())||""),i())};return r?t.jsx("div",{className:"flex items-center gap-1 w-full",children:t.jsx("div",{className:"flex-1",children:t.jsx(ls,{value:a,onChange:l,onBlur:m,onKeyDown:p,showQuickButtons:!1,showConversion:!1,className:"w-full",autoFocus:!0})})}):t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded",onClick:n,children:e.hours?os(Number(e.hours)):"Click to set hours"})}function Bi({entry:e,onUpdate:s,isEditing:r,onStartEdit:n,onCancelEdit:i}){const[a,l]=v.useState(e.activityType||""),[o,c]=v.useState(!1),g=async m=>{l(m);try{await s(e.id,"activityType",m),i()}catch(p){console.error("Error updating activity type:",p)}};return r?t.jsx("div",{className:"flex items-center gap-2 w-full",children:t.jsx(ds,{value:a,onValueChange:g,className:"flex-1"})}):t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded",onClick:n,children:e.activityType?t.jsx(ne,{variant:"secondary",className:"whitespace-nowrap",children:e.activityType}):"Click to set activity"})}function Gi({entry:e,onUpdate:s,isEditing:r,onStartEdit:n,onCancelEdit:i,glowingDescriptions:a,setGlowingDescriptions:l}){const[o,c]=v.useState(Dt(e.description||"")),[g,m]=v.useState(!1),[p,u]=v.useState(!1),{toast:d}=ye(),f=Ft({mutationFn:async h=>(await ge("POST","/api/ai/enhance-description",h)).json(),onSuccess:async h=>{if(h.success){const b=h.result.enhancedDescription||o;if(c(b),l&&a){const k=new Set(a);k.add(e.id),l(k),setTimeout(()=>{const M=new Set(a);M.delete(e.id),l(M)},2e3)}try{await s(e.id,"description",b),d({title:"Description Enhanced & Saved",description:`AI improvements applied with ${Math.round(h.result.confidence*100)}% confidence`})}catch{d({title:"Enhancement Applied",description:"Enhanced description applied. Please save manually.",variant:"default"})}}u(!1)},onError:h=>{u(!1),d({title:"Enhancement Failed",description:"Failed to enhance description. Please try again.",variant:"destructive"})}}),x=async()=>{var h;if(!(o!=null&&o.trim())){d({title:"No Description",description:"Please enter a description first",variant:"destructive"});return}u(!0),f.mutate({originalDescription:o,timeEntryId:e.id,activityType:e.activityType||"",propertyNickname:(h=e.property)==null?void 0:h.nickname})},C=async()=>{if(o===Dt(e.description||"")){i();return}m(!0);try{await s(e.id,"description",o),i()}catch(h){console.error("Error updating description:",h)}finally{m(!1)}},y=h=>{if(p)return;const b=h==null?void 0:h.relatedTarget;b!=null&&b.closest('button[title="Enhance with AI"]')||C()},w=h=>{h.key==="Enter"&&!h.shiftKey?(h.preventDefault(),C()):h.key==="Escape"&&(c(Dt(e.description||"")),i())};if(r){const b=o.split(` 44`).length,k=Math.ceil(o.length/45),M=Math.max(b,k),D=Math.max(2,Math.min(8,M)),T=D*1.5+1;return t.jsxs("div",{className:"flex items-start gap-2 w-full p-1",style:{minHeight:`${T}rem`},children:[t.jsx("textarea",{value:o,onChange:I=>c(I.target.value),onBlur:I=>y(I),onKeyDown:w,className:`flex-1 break-words bg-transparent border border-gray-300 dark:border-gray-600 rounded outline-none resize-none overflow-y-auto text-current transition-all duration-300 !text-[13px] !leading-[1.5] font-normal focus:border-blue-500 dark:focus:border-blue-400 ${a!=null&&a.has(e.id)?"shadow-[0_0_15px_rgba(168,85,247,0.6)] animate-pulse bg-purple-50 dark:bg-purple-900/20":"bg-white dark:bg-gray-800"}`,style:{minHeight:`${D*1.5}rem`,height:`${D*1.5}rem`,lineHeight:"1.5",fontSize:"13px",fontFamily:"inherit",fontWeight:"normal",padding:"4px 8px",margin:"0"},placeholder:"Enter description...",autoFocus:!0,rows:D}),t.jsx("div",{className:"flex flex-col gap-1 flex-shrink-0 mt-1",children:t.jsx(L,{size:"sm",variant:"ghost",onClick:x,onMouseDown:I=>{I.preventDefault()},disabled:g||p||!(o!=null&&o.trim()),title:"Enhance with AI",className:"text-purple-600 hover:text-purple-700 hover:bg-purple-50 h-7 w-7 p-1",children:p?t.jsx("div",{className:"h-3 w-3 animate-spin rounded-full border border-purple-600 border-t-transparent"}):t.jsx(nr,{className:"h-3 w-3"})})})]})}const S=e.description?Dt(e.description):"";return t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded transition-all duration-200",onClick:n,title:S||void 0,children:t.jsxs("div",{className:"flex items-start space-x-1",children:[t.jsx("div",{className:"flex-1 line-clamp-3 !text-[13px] !leading-[1.5] font-normal",style:{fontSize:"13px",lineHeight:"1.5",fontWeight:"normal"},children:S||t.jsx("span",{className:"text-muted-foreground italic",children:"Click to add description"})}),t.jsxs("div",{className:"relative group flex-shrink-0 mt-0.5",children:[t.jsx(nr,{className:"h-3 w-3 text-purple-600"}),t.jsx("div",{className:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-1 px-2 py-1 bg-black text-white text-xs rounded opacity-0 group-hover:opacity-100 transition-opacity duration-200 whitespace-nowrap z-10",children:"Click to edit · AI enhancement available"})]})]})})}function Ui({entry:e,onUpdate:s,isEditing:r,onStartEdit:n,onCancelEdit:i,properties:a=[]}){var u;const[l,o]=v.useState(((u=e.propertyId)==null?void 0:u.toString())||"none"),[c,g]=v.useState(!1),m=async d=>{o(d);try{await s(e.id,"propertyId",d==="none"?null:d),i()}catch(f){console.error("Error updating property:",f)}};if(r)return t.jsx("div",{className:"flex items-center gap-2 w-full",children:t.jsxs(be,{value:l,onValueChange:m,children:[t.jsx(Ne,{className:"flex-1",children:t.jsx(_e,{placeholder:"Select property"})}),t.jsxs(Se,{children:[t.jsx(te,{value:"none",children:"No Property"}),a.map(d=>t.jsx(te,{value:d.id.toString(),children:d.nickname||d.address},d.id))]})]})});const p=e.property||a.find(d=>d.id===e.propertyId);return t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded",onClick:n,children:p?t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx(Rs,{className:"h-4 w-4 text-muted-foreground"}),t.jsx("div",{className:"max-w-[150px] truncate",title:`${p.nickname} - ${p.address}`,children:p.nickname})]}):t.jsx("span",{className:"text-muted-foreground italic",children:"Click to select property"})})}function qi({entry:e,onUpdate:s,onUpdateMultiple:r,isEditing:n,onStartEdit:i,onCancelEdit:a,categories:l=[]}){const[o,c]=v.useState(e.isMaterialParticipation===void 0||e.isMaterialParticipation===null?"":String(e.isMaterialParticipation)),[g,m]=v.useState(!1),p=async d=>{c(d);try{const f=d==="true",x=d==="false";await r(e.id,{isMaterialParticipation:f,isQualifiedNonMaterial:x}),a()}catch(f){console.error("Error updating category:",f)}};if(n)return t.jsx("div",{className:"flex items-center gap-2 w-full",children:t.jsxs(be,{value:o,onValueChange:p,children:[t.jsx(Ne,{className:"flex-1",children:t.jsx(_e,{placeholder:"Select Category"})}),t.jsx(Se,{children:cn.map(d=>t.jsx(te,{value:d.state.toString(),children:d.name},d.id))})]})});const u=l.find(d=>d.state===String(e.isMaterialParticipation));return t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded",onClick:i,children:u?t.jsx("div",{className:"flex items-center space-x-2",children:t.jsx("div",{title:`${u.name}`,children:u.name})}):t.jsx("span",{className:"text-muted-foreground italic",children:"Click to select category"})})}function Wi({entry:e}){const s=e.source||"manual",r=pn(s),n=mn(s);return s.toLowerCase()==="geofence"&&e.approvalStatus==="pending"?t.jsxs(cs,{children:[t.jsx(us,{asChild:!0,children:t.jsx("div",{className:"flex items-center justify-center cursor-default",children:n})}),t.jsx(gs,{side:"top",className:"max-w-[220px] text-center text-xs",children:"Detected visit via location â awaiting your review"})]}):t.jsx("div",{className:"flex items-center justify-center",title:r,children:n})}function Qi({entry:e,onUpdate:s,isEditing:r,onStartEdit:n,onCancelEdit:i}){const[a,l]=v.useState(e.propertyType||""),[o,c]=v.useState(!1),g=[{value:"Long-term Rental",label:"Long-term Rental"},{value:"Short-term Rental",label:"Short-term Rental"}],m=async p=>{l(p);try{await s(e.id,"propertyType",p),i()}catch(u){console.error("Error updating REP status type:",u)}};return r?t.jsxs("div",{className:"flex items-center gap-2 w-full",children:[t.jsxs(be,{value:a,onValueChange:m,disabled:o,children:[t.jsx(Ne,{className:"h-8 text-xs",children:t.jsx(_e,{})}),t.jsx(Se,{children:g.map(p=>t.jsx(te,{value:p.value,className:"text-xs",children:p.label},p.value))})]}),o&&t.jsx(ae,{className:"h-4 w-4 animate-spin"})]}):t.jsx("div",{className:"cursor-pointer hover:bg-muted/50 p-1 rounded",onClick:n,"data-testid":"text-rep-status-type",children:t.jsx(ne,{variant:"outline",className:`text-xs ${e.propertyType?(e.propertyType||"L
44ong-term Rental")==="Long-term Rental"?"bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-950 dark:text-blue-300 dark:border-blue-800":"bg-green-50 text-green-700 border-green-200 dark:bg-green-950 dark:text-green-300 dark:border-green-800":"text-muted-foreground border-dashed"}`,children:e.propertyType||"Select Type"})})}function Ki({entry:e,onUpdate:s,onOpenFilePreview:r}){var f,x,C;const[n,i]=v.useState(0),{toast:a}=ye(),l=un.useRef(null),o=((f=e.evidenceFiles)==null?void 0:f.filter(y=>!y.isDeleted))&&((x=e.evidenceFiles)==null?void 0:x.filter(y=>!y.isDeleted).length)>0||e.evidenceUrl,c=(((C=e.evidenceFiles)==null?void 0:C.filter(y=>!y.isDeleted).length)||0)+(e.evidenceUrl?1:0),g=Ft({mutationFn:async y=>{const w=new FormData;return w.append("files",y),(await ge("POST",`/api/evidence-files/${e.id}`,w)).json()},onSuccess:async()=>{i(100),a({title:"File Uploaded",description:"Evidence file uploaded successfully. AI analysis in progress..."}),await s()},onError:y=>{a({title:"Upload Failed",description:"Failed to upload evidence file. Please try again.",variant:"destructive"})}}),m=async y=>{var b;if(!y)return;const w=[".pdf",".doc",".docx",".jpg",".jpeg",".png",".gif"],S="."+((b=y.name.split(".").pop())==null?void 0:b.toLowerCase());if(!w.includes(S)){a({title:"Invalid file type",description:"Please upload PDF, DOC, DOCX, JPG, PNG, or GIF files.",variant:"destructive"});return}if(y.size>5*1024*1024){a({title:"File too large",description:"Please upload files smaller than 5MB.",variant:"destructive"});return}i(0);const h=setInterval(()=>{i(k=>Math.min(k+10,90))},200);try{await g.mutateAsync(y),clearInterval(h)}
44catch(k){clearInterval(h),console.error("Error uploading file:",k)}finally{i(0),l.current&&(l.current.value="")}},p=y=>{var S;const w=(S=y.target.files)==null?void 0:S[0];w&&m(w)},u=g.isPending,d=o?`${c} evidence file${c>1?"s":""} attached - click to upload more`:"No evidence files - click to upload";return t.jsxs("div",{className:"flex items-center justify-center gap-1","data-testid":"evidence-icon-only",children:[t.jsx(L,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",onClick:()=>{var y;return!e.deletedAt&&((y=l.current)==null?void 0:y.click())},disabled:u||!!e.deletedAt,title:d,children:u?t.jsx(ae,{className:"h-4 w-4 animate-spin text-blue-500"}):t.jsx(ps,{className:`h-4 w-4 ${o?"text-green-600 dark:text-green-400":"text-gray-400 dark:text-gray-500"}`})}),o&&t.jsx(L,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 hover:bg-blue-100 dark:hover:bg-blue-800 transition-colors",onClick:()=>r==null?void 0:r(e),title:"View evidence files","data-testid":`button-file-vault-${e.id}`,children:t.jsx(Ye,{className:"h-4 w-4 text-blue-600 dark:text-blue-400"})}),t.jsx("input",{ref:l,type:"file",accept:".pdf,.doc,.docx,.jpg,.jpeg,.png",onChange:p,className:"hidden"})]})}function kn({entry:e,onUpdate:s}){const{toast:r}=ye(),n=Ft({mutationFn:async c=>{const g=c?`/api/time-entries/${e.id}/approve`:`/api/time-entries/${e.id}/unapprove`;return(await ge("PATCH",g,{})).json()},onSuccess:(c,g)=>{r({title:g?"Entry approved":"Entry unapproved",description:`Time entry ${g?"approved":"unapproved"} successfully`}),s()},onError:c=>{r({title:"Error",description:"Failed to update approval status",variant:"destructive"})}}),i=v.useCallback(c=>{n.isPending||n.mutate(c)},[n]),a=e.approvalStatus==="approved",l=n.isPending,o=a?"Approved - click to unapprove":"Pending approval - click to approve";return t.jsx("div",{className:"flex items-center justify-center",children:t.jsx("button",{className:` 45 h-4 w-4 rounded-full border-2 transition-all duration-200 flex items-center justify-center 46 ${a?"bg-green-500 border-green-500 hover:bg-green-600 hover:border-green-600":"bg-gray-200 dark:bg-gray-700 border-gray-300 dark:border-gray-600 hover:border-green-400 dark:hover:border-green-400"} 47 ${l||e.deletedAt?"cursor-not-allowed opacity-50":"cursor-pointer"} 48 `,onClick:()=>!e.deletedAt&&i(!a),disabled:l||!!e.deletedAt,title:o,children:l?t.jsx(ae,{className:"h-2.5 w-2.5 animate-spin text-gray-400"}):a?t.jsx(mr,{className:"h-2.5 w-2.5 text-white stroke-[2.5]"}):null})})}function Yi({entry:e,onUpdate:s}){const[r,n]=v.useState(!1),[i,a]=v.useState(!1),{toast:l}=ye(),o=v.useCallback(async()=>{if(!r){n(!0);try{await Ke.restoreTimeEntry(e.id),l({title:"Entry restored",description:"Time entry restored successfully"}),s(),a(!1)}catch(c){console.error("Error restoring entry:",c),l({title:"Error",description:"Failed to restore entry",variant:"destructive"})}finally{n(!1)}}},[e.id,r,l,s]);return e.deletedAt?t.jsx("div",{className:"flex items-center justify-center",children:t.jsxs(vt,{open:i,onOpenChange:a,children:[t.jsx(ms,{asChild:!0,children:t.jsx("button",{className:` 49 h-6 w-6 rounded-full border transition-all duration-200 flex items-center justify-center 50 `,disabled:r,title:"Restore deleted entry",children:r?t.jsx(ae,{className:"h-4 w-4 animate-spin text-blue-600 dark:text-blue-400"}):t.jsx(Ar,{className:"h-4 w-4 text-green-600"})})}),t.jsxs(wt,{className:"rounded-xl shadow-lg border border-gray-200",children:[t.jsxs(jt,{children:[t.jsx(bt,{className:"text-lg font-semibold text-gray-900",children:"Restore Time Entry"}),t.jsxs(Nt,{className:"text-sm text-gray-600 leading-relaxed",children:["Are you sure you want to restore this time entry? It will be moved back to your active ledger.",t.jsxs("div",{className:"mt-3 p-3 bg-blue-50 border border-blue-100 rounded-lg text-sm text-gray-700",children:[t.jsx("div",{className:"font-medium text-gray-900",children:e.description}),t.jsxs("div",{className:"text-xs text-gray-500",children:[e.hours,"h â¢"," ",St(e.date,"MMM d, yyyy")]})]})]})]}),t.jsxs(Ct,{className:"flex justify-end space-x-2",children:[t.jsx(kt,{disabled:r,className:"px-4 py-2 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-100 transition",children:"Cancel"}),t.jsx(Rt,{onClick:c=>{c.preventDefault(),o()},disabled:r,className:"px-4 py-2 rounded-lg bg-blue-600 text-white text-sm font-medium hover:bg-blue-700 transition flex items-center",children:r?t.jsxs(t.Fragment,{children:[t.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin"}),"Restoring..."]}):t.jsxs(t.Fragment,{children:[t.jsx(Ar,{className:"mr-2 h-4 w-4"}),"Restore Entry"]})})]})]})]})}):null}function Xi(){const[e,s]=v.useState(()=>{const a=new Date;return new Date(a.getFullYear(),a.getMonth(),1)}),r=v.useCallback(()=>{s(a=>{const l=new Date(a);return l.setMonth(l.getMonth()-1),l})},[]),n=v.useCallback(()=>{s(a=>{const l=new Date(a);return l.setMonth(l.getMonth()+1),l})},[]),i=v.useMemo(()=>{const a=new Date,l=new Date(a.getFullYear(),a.getMonth(),1);return e.getTime()===l.getTime()},[e]);return{selectedMonth:e,setSelectedMonth:s,goToPreviousMonth:r,goToNextMonth:n,isAtCurrentMonth:i}}function Ji(){const[e,s]=v.useState({}),r=v.useCallback((a,l)=>{const o=`${a}-${l}`;s(c=>({...c,[o]:{isEditing:!0,field:l,originalValue:null}}))},[]),n=v.useCallback((a,l)=>{const o=`${a}-${l}`;s(c=>{const g={...c};return delete g[o],g})},[]),i=v.useCallback((a,l)=>{var c;const o=`${a}-${l}`;return((c=e[o])==null?void 0:c.isEditing)||!1},[e]);return{editingState:e,startEdit:r,cancelEdit:n,isEditing:i}}function Zi(e=!1){const[s,r]=v.useState(!0),[n,i]=v.useState([]),[a,l]=v.useState([]),[o,c]=v.useState(null),g=v.useCallback(async()=>{try{r(!0);const p=await fetch(`/api/time-entries?includeDeleted=${e}&limit=1000`,{cache:"no-cache",headers:{"Cache-Control":"no-cache"}});if(!p.ok)throw new Error("Failed to fetch time entries");const u=await p.json();i(u||[]),c(null)}
50catch(p){console.error("Error fetching entries:",p),c(p instanceof Error?p.message:"Failed to fetch data")}finally{r(!1)}},[e]);v.useEffect(()=>{g()},[g]),v.useEffect(()=>{const p=()=>g();return window.addEventListener("ledger:refresh",p),()=>window.removeEventListener("ledger:refresh",p)},[g]);const m=v.useMemo(()=>{const p=n.length,u=n.filter(x=>(x.approvalStatus||"pending")==="pending").length,d=n.filter(x=>x.approvalStatus==="approved").length,f=n.reduce((x,C)=>x+(Number(C.hours)||0),0);return{totalEntries:p,pendingEntries:u,approvedEntries:d,totalHours:f}},[n]);return{loading:s,entries:n,setEntries:i,newEntries:a,setNewEntries:l,error:o,fetchData:g,stats:m}}function ea(e){const{toast:s}=ye(),r=fs(),[n,i]=v.useState(null),[a,l]=v.useState(!1),[o,c]=v.useState(0),[g,m]=v.useState(!1),[p,u]=v.useState(null),d=async(w,S)=>{try{let h=w;const b=w.includes(".r2.cloudflarestorage.com")||w.includes(".cloudflare")||w.startsWith("https://"),k=w.includes("/api/public/evidence/");if(!b&&!k)throw new Error("Invalid file URL - Legacy downloads not supported");const M=await fetch(h,{credentials:k?"include":"omit"});if(!M.ok)throw new Error("Download failed");const D=await M.blob(),T=window.URL.createObjectURL(D),I=document.createElement("a");I.href=T,I.download=S,document.body.appendChild(I),I.click(),document.body.removeChild(I),window.URL.revokeObjectURL(T)}catch{s({title:"Download Error",description:"Failed to download file. Please try again.",variant:"destructive"})}},f=w=>{if(w.evidenceFiles&&w.evidenceFiles.length>0){const S=w.evidenceFiles.filter(k=>!k.isDeleted),h=S[0],b=S.map(k=>({id:`evidence-${w.id}-${k.fileName}`,numericId:k.id,originalName:k.originalName,fileName:k.fileName,fileUrl:k.fileUrl,mimeType:k.mimeType||Lt(k.fileName),uploadedAt:k.uploadedAt||k.createdAt,fileSize:k.fileSize,aiSummary:k.aiSummary||w.aiSummary,aiAnalysisStatus:k.aiAnalysisStatus||w.evidenceAiAnalysisStatus||"pending",timeEntryId:w.id,isLegacy:!1,r2Key:k.r2Key,storageType:k.storageType,publicToken:k.publicToken}));i({id:h.id,numericId:h.id,originalName:h.originalName,fileName:h.fileName,fileUrl:h.fileUrl,mimeType:h.mimeType||Lt(h.fileName),uploadedAt:h.uploadedAt||h.createdAt,fileSize:h.fileSize,aiSummary:h.aiSummary||w.aiSummary,aiAnalysisStatus:h.aiAnalysisStatus||w.evidenceAiAnalysisStatus||"pending",timeEntryId:w.id,allFiles:b,r2Key:h.r2Key,storageType:h.storageType,publicToken:h.publicToken}),c(0),l(!0)}},x=Ft({mutationFn:async w=>{const S=await fetch(`/api/evidence-files/${w}`,{method:"DELETE",credentials:"include"});if(!S.ok){const h=await S.json().catch(()=>({}));throw new Error(h.message||"Failed to delete file")}return S.json()},onSuccess:async w=>{if(await r.invalidateQueries({queryKey:["/api/evidence-files"]}),await r.invalidateQueries({queryKey:["/api/time-entries"]}),Cs(p==null?void 0:p.numericId),s({title:"File Deleted",description:`"${(p==null?void 0:p.originalName)||(p==null?void 0:p.fileName)}" has been moved to deleted files.`}),m(!1),a&&n&&n.allFiles){const S=n.allFiles.filter(h=>h.numericId!==(p==null?void 0:p.numericId));if(S.length===0)l(!1),i(null);else if(n.numericId===(p==null?void 0:p.numericId)){const h=S[0];i({...h,allFiles:S}),c(0)}else{i(b=>({...b,allFiles:S}));const h=S.findIndex(b=>b.numericId===n.numericId);h!==-1&&c(h)}}u(null),await e()},onError:w=>{s({title:"Delete Failed",description:w.message,variant:"destructive"})}});return{previewFile:n,setPreviewFile:i,isFilePreviewOpen:a,setIsFilePreviewOpen:l,currentFileIndex:o,setCurrentFileIndex:c,handleOpenFilePreview:f,downloadFile:d,deleteFileDialogOpen:g,setDeleteFileDialogOpen:m,fileToDelete:p,handleFileDeleteClick:w=>{u(w),m(!0)},confirmFileDelete:()=>{p!=null&&p.numericId&&x.mutate(p.numericId)},deleteFileMutation:x}}function ta({entries:e,newEntries:s,selectedMonth:r}){const n=typeof window<"u"?new URLSearchParams(window.location.search):null,i=n==null?void 0:n.get("status"),[a,l]=v.useState(""),[o,c]=v.useState(i==="pending"?"pending":"all"),[g,m]=v.useState(i==="pending"?"all-entries":"monthly"),p=v.useMemo(()=>{const d=[...s,...e];let f=d;return o==="pending"?f=d.filter(x=>x.isNew||(x.approvalStatus||"pending")==="pending"):o==="approved"&&(f=d.filter(x=>!x.isNew&&x.approvalStatus==="approved")),g==="monthly"&&(f=f.filter(x=>{if(!x.date)return!1;const C=new Date(x.date),y=C.getFullYear(),w=C.getMonth(),S=r.getFullYear(),h=r.getMonth();return y===S&&w===h})),f.sort((x,C)=>{const y=x.isNew,w=C.isNew;if(y&&!w)return-1;if(!y&&w)return 1;if(y&&w)return 0;const S=x.approvalStatus||"pending",h=C.approvalStatus||"pending";return S==="pending"&&h!=="pending"?-1:S!=="pending"&&h==="pending"?1:C.id-x.id})},[e,s,o,r,g]),u=v.useMemo(()=>{const d=p.filter(x=>x.isNew||(x.approvalStatus||"pending")==="pending"),f=p.filter(x=>!x.isNew&&x.approvalStatus==="approved");return{pending:d,approved:f}},[p]);return{globalFilter:a,setGlobalFilter:l,statusFilter:o,setStatusFilter:c,viewMode:g,setViewMode:m,filteredData:p,groupedData:u}}function ra({entries:e,setEntries:s,newEntries:r,setNewEntries:n,startEdit:i,properties:a=[]}){const{toast:l}=ye(),[o,c]=v.useState(null),[g,m]=v.useState(!1),[p,u]=v.useState(!1),d=v.useCallback(()=>{const h=`new-${Date.now()}`,b={id:h,date:hs(),hours:"0.25",activityType:"",description:"",isMaterialParticipation:null,isQualifiedNonMaterial:!1,source:"manual",propertyType:null,isNew:!0};n(k=>[b,...k]),setTimeout(()=>
50{i(h,"activityType")},100),l({title:"New Entry Added",description:"Fill in the details in the blue highlighted row. Entry will save automatically when date, hours, and activity type are complete."})},[n,i,l]),f=v.useCallback(async(h,b,k,M)=>{try{if(typeof h=="string"&&h.startsWith("new-")){let D=null;n(T=>T.map(I=>{if(I.id===h){const U={...I,[b]:k};return U.date&&U.hours&&U.activityType&&(D=U),U}return I})),D&&setTimeout(()=>{C(h,D)},100)}else{const D=M||e.find(U=>U.id===h);if(!D)throw new Error("Entry not found");const T={...D,[b]:k},I={date:T.date||"",hours:(T.hours||0).toString(),activityType:T.activityType||"",description:T.description||"",isMaterialParticipation:T.isMaterialParticipation,isQualifiedNonMaterial:T.isQualifiedNonMaterial,source:T.source||"manual",propertyType:T.propertyType,propertyId:T.propertyId?T.propertyId.toString():void 0};await Ke.updateTimeEntry(h,I),s(U=>U.map(q=>{if(q.id===h){let Q={...q,[b]:k};if(b==="propertyId")if(k===null||k==="none")Q.property=void 0,Q.propertyId=void 0;else{const Z=typeof k=="string"?parseInt(k,10):k,de=a.find(J=>J.id===Z);de&&(Q.property=de,Q.propertyId=Z)}return q.isNew&&Q.activityType&&Q.hours&&Q.description&&delete Q.isNew,Q}return q})),l({title:"Entry updated",description:"Time entry has been successfully updated."})}}catch(D){throw console.error("Error updating entry:",D),l({title:"Error",description:D instanceof Error?D.message:"Failed to update entry. Please try again.",variant:"destructive"}),D}},[e,r,s,n,l,a]),x=v.useCallback(async(h,b,k)=>{try{if(typeof h=="string"&&h.startsWith("new-")){let M=null;n(D=>D.map(T=>{if(T.id===h){const I={...T,...b};return I.date&&I.hours&&I.activityType&&(M=I),I}return T})),M&&setTimeout(()=>{C(h,M)},100)}else{const M=k||e.find(I=>I.id===h);if(!M)throw new Error("Entry not found");const D={...M,...b},T={date:D.date||"",hours:(D.hours||0).toString(),activityType:D.activityType||"",description:D.description||"",isMaterialParticipation:D.isMaterialParticipation,isQualifiedNonMaterial:D.isQualifiedNonMaterial,source:D.source||"manual",propertyType:D.propertyType,propertyId:D.propertyId?D.propertyId.toString():void 0};await Ke.updateTimeEntry(h,T),s(I=>I.map(U=>{if(U.id===h){let q={...U,...b};if("propertyId"in b){const Q=b.propertyId;if(Q===null||Q==="none")q.property=void 0,q.propertyId=void 0;else{const Z=typeof Q=="string"?parseInt(Q,10):Q,de=a.find(J=>J.id===Z);de&&(q.property=de,q.propertyId=Z)}}return U.isNew&&q.activityType&&q.hours&&q.description&&delete q.isNew,q}return U})),l({title:"Entry updated",description:"Time entry has been successfully updated."})}}catch(M){throw console.error("Error updating entry:",M),l({title:"Error",description:M instanceof Error?M.message:"Failed to update entry. Please try again.",variant:"destructive"}),M}},[e,r,s,n,l,a]),C=v.useCallback(async(h,b)=>{if(!b){console.error("â saveNewEntry: No entry data provided");return}try{const k={date:b.date,hours:b.hours,activityType:b.activityType,description:b.description||"",isMaterialParticipation:b.isMaterialParticipation??null,isQualifiedNonMaterial:b.isQualifiedNonMaterial??!1,source:b.source,propertyType:b.propertyType,propertyId:b.propertyId&&b.propertyId!=="none"?b.propertyId:void 0},M=await Ke.createTimeEntry(k,[]);l({title:"Entry created",description:"Time entry has been successfully created."}),n(D=>D.filter(T=>T.id!==h)),s(D=>[M,...D])}catch(k){console.error("Error saving new entry:",k),l({title:"Error",description:"Failed to save entry. Please try again.",variant:"destructive"})}},[n,s,l]),y=v.useCallback(async h=>{if(typeof h=="string"&&h.startsWith("new-")){n(b=>b.filter(k=>k.id!==h));return}try{await Ke.deleteTimeEntry(h),s(b=>b.filter(k=>k.id!==h)),l({title:"Entry deleted",description:"New entry has been successfully deleted."})}catch(b){console.error("Error deleting new entry:",b),l({title:"Error",description:"Failed to delete entry. Please try again.",variant:"destructive"})}},[n,s,l]),w=v.useCallback(async h=>{if(typeof h.id=="string"&&h.id.startsWith("new-")){y(h.id);return}c(h),m(!0)},[y]),S=v.useCallback(async()=>{if(o)try{u(!0),await Ke.deleteTimeEntry(o.id),l({title:"Entry deleted",description:"Time entry has been successfully deleted."}),m(!1),s(h=>h.filter(b=>b.id!==o.id)),c(null)}catch{l({title:"Error",description:"Failed to delete entry. Please try again.",variant:"destructive"})}finally{u(!1)}},[o,s,l]);return{handleAddNewEntry:d,handleUpdateEntry:f,handleUpdateMultipleFields:x,deleteNewEntry:y,handleDeleteEntry:w,confirmDeleteEntry:S,entryToDelete:o,setEntryToDelete:c,showDeleteDialog:g,setShowDeleteDialog:m,isDeletingEntry:p}}function na({table:e,entries:s,setEntries:r,setRowSelection:n,fetchData:i}){const{toast:a}=ye(),[l,o]=v.useState(!1),[c,g]=v.useState(!1),[m,p]=v.useState(!1),u=v.useCallback(()=>
50{if(e.getFilteredSelectedRowModel().rows.length===0){a({title:"No entries selected",description:"Please select entries to delete.",variant:"destructive"});return}o(!0)},[e,a]),d=v.useCallback(async()=>{const y=e.getFilteredSelectedRowModel().rows.map(w=>w.original).filter(w=>!w.deletedAt);if(y.length===0){o(!1);return}try{g(!0);const w=y.map(k=>ge("DELETE",`/api/time-entries/${k.id}`)),S=await Promise.allSettled(w),h=S.filter(k=>k.status==="rejected"),b=S.filter(k=>k.status==="fulfilled"&&k.value.ok);h.length>0?a({title:"Partial deletion",description:`${b.length} entries deleted, ${h.length} failed.`,variant:"destructive"}):a({title:"Entries deleted",description:`${b.length} entries have been successfully deleted.`}),o(!1),n({}),i()}catch{a({title:"Error",description:"Failed to delete entries. Please try again.",variant:"destructive"})}finally{g(!1)}},[e,n,i,a]),f=v.useCallback(async()=>{const C=e.getFilteredSelectedRowModel().rows.map(w=>w.original);if(C.length===0){a({title:"No entries selected",description:"Please select entries to enhance.",variant:"destructive"});return}const y=C.filter(w=>typeof w.id=="number");if(y.length===0){a({title:"No valid entries",description:"Please save new entries first before enhancing.",variant:"destructive"});return}if(y.length>50){a({title:"Too many entries",description:"Maximum 50 entries allowed for bulk enhancement.",variant:"destructive"});return}p(!0);try{const w=y.map(b=>b.id),S=await ge("POST","/api/ai/enhance-descriptions-bulk",{timeEntryIds:w});if(!S.ok)throw new Error("Failed to enhance descriptions");const h=await S.json();if(h.success&&h.results){let b=0,k=0;const M=h.results.map(async T=>{if(T.enhancement.enhancedDescription!==T.originalDescription)try{const I=y.find(U=>U.id===T.timeEntryId);return I?(await ge("PATCH",`/api/time-entries/${T.timeEntryId}`,{date:I.date,hours:I.hours,activityType:I.activityType,description:T.enhancement.enhancedDescription,isMaterialParticipation:I.isMaterialParticipation}),b++,{id:T.timeEntryId,description:T.enhancement.enhancedDescription}):(k++,null)}catch(I){return console.error(`Failed to save enhanced description for entry ${T.timeEntryId}:`,I),k++,null}return null}),D=await Promise.all(M);r(T=>T.map(I=>{const U=D.find(q=>(q==null?void 0:q.id)===I.id);return U?{...I,description:U.description}:I})),n({}),a({title:"Bulk Enhancement Complete",description:`Enhanced ${b} entries${k>0?`, ${k} failed`:""}`})}}catch(w){console.error("Bulk enhancement error:",w),a({title:"Enhancement Failed",description:"Failed to enhance descriptions. Please try again.",variant:"destructive"})}finally{p(!1)}},[e,s,r,n,a]);return{handleBulkDelete:u,confirmBulkDelete:d,showBulkDeleteDialog:l,setShowBulkDeleteDialog:o,isDeletingBulk:c,handleBulkEnhancement:f,isBulkEnhancing:m}}function sa({data:e,columns:s,globalFilter:r,setGlobalFilter:n}){const[i,a]=v.useState([]),[l,o]=v.useState([]),[c,g]=v.useState({propertyType:!1,category:!1}),[m,p]=v.useState({}),[u,d]=v.useState({pageIndex:0,pageSize:50});return{table:Ai({data:e,columns:s,onSortingChange:a,onColumnFiltersChange:o,getCoreRowModel:Ci(),getPaginationRowModel:Pi(),getSortedRowModel:Di(),getFilteredRowModel:Mi(),onColumnVisibilityChange:g,onRowSelectionChange:p,onPaginationChange:d,onGlobalFilterChange:n,globalFilterFn:"includesString",state:{sorting:i,columnFilters:l,columnVisibility:c,rowSelection:m,globalFilter:r,pagination:u}}),sorting:i,setSorting:a,columnFilters:l,setColumnFilters:o,columnVisibility:c,setColumnVisibility:g,rowSelection:m,setRowSelection:p,pagination:u,setPagination:d}}function ia({entries:e,setEntries:s,setShowNewEntryDialog:r,setShowModifyEntryDialog:n,setEntryToModify:i}){const{toast:a}=ye(),[l,o]=v.useState(!1);return{handleNewEntrySubmit:async m=>{var p;o(!0);try{const u=new FormData;u.append("date",m.date),u.append("hours",m.hours),u.append("activityType",m.activityType),u.append("description",m.description||""),u.append("propertyId",m.propertyId==="none"||!m.propertyId?"":m.propertyId),u.append("isMaterialParticipation",m.isMaterialParticipation.toString()),u.append("isQualifiedNonMaterial",((p=m.isQualifiedNonMaterial)==null?void 0:p.toString())||"false"),u.append("source","manual");const f=await(await ge("POST","/api/time-entries",u)).json();s(x=>[f,...x]),a({title:"Success",description:"Time entry created successfully"}),r==null||r(!1)}catch(u){throw a({title:"Error",description:u.message||"Failed to create entry",variant:"destructive"}),u}finally{o(!1)}},handleModifyEntrySubmit:async(m,p,u)=>{var d;o(!0);try{const f=new FormData;f.append("date",p.date),f.append("hours",p.hours),f.append("activityType",p.activityType),f.append("description",p.description||""),f.append("propertyId",p.propertyId==="none"||!p.propertyId?"":p.propertyId),f.append("isMaterialParticipation",p.isMaterialParticipation.toString()),f.append("isQualifiedNonMaterial",((d=p.isQualifiedNonMaterial)==null?void 0:d.toString())||"false");const C=await(await ge("PATCH",`/api/time-entries/${m}`,f)).json();if(u&&u.length>0)try{const y=new FormData;u.forEach(w=>{y.append("files",w)}),await ge("POST",`/api/evidence-files/${m}`,y),a({title:"Evidence Attached",description:`${u.length} file(s) uploaded successfully`})}catch(y){console.error("File upload failed",y),a({title:"Evidence Upload Failed",description:(y==null?void 0:y.message)||"Entry updated but files failed to upload",variant:"destructive"})}s(y=>y.map(w=>w.id===m?C:w)),a({title:"Success",description:"Time entry updated successfully"}),n(!1),i(null)}catch(f){throw a({title:"Error",description:f.message||"Failed to update entry",variant:"destructive"}),f}finally{o(!1)}},isSubmitting:l}}function aa({children:e,headerTitle:s,showBack:r,rightAction:n,className:i,fullWidth:a=!1}){return t.jsxs("div",{className:"bg-background md:pb-0",children:[s&&t.jsx(nn,{title:s,showBack:r,rightAction:n}),t.jsx("main",{className:re("w-full container-mobile mx-auto",s?"pt-[60px]":"pt-4",!a&&"","safe-area-left safe-area-right",i),children:e})]})}function la({table:e,entries:s,setEntries:r,setRowSelection:n,fetchData:i}){const[a,l]=v.useState(!1),[o,c]=v.useState(!1),[g,m]=v.useState(!1),[p,u]=v.useState(!1),d=v.useCallback(async()=>
50{if(e.getFilteredSelectedRowModel().rows.filter(w=>{const S=w.original;return!S.isNew&&S.approvalStatus!=="approved"}).length===0){xe({title:"No entries selected",description:"Please select entries to approve.",variant:"destructive"});return}m(!0)},[e,n,i,xe]),f=v.useCallback(async()=>{if(e.getFilteredSelectedRowModel().rows.filter(w=>{const S=w.original;return!S.isNew&&S.approvalStatus!=="pending"}).length===0){xe({title:"No entries selected",description:"Please select entries to unapprove.",variant:"destructive"});return}u(!0)},[e,n,i,xe]),x=v.useCallback(async()=>{const w=e.getFilteredSelectedRowModel().rows.filter(S=>{const h=S.original;return!h.isNew&&h.approvalStatus!=="approved"}).map(S=>S.original);try{l(!0);const S=w.map(M=>fetch(`/api/time-entries/${M.id}/approve`,{method:"PATCH"})),h=await Promise.allSettled(S),b=h.filter(M=>M.status==="rejected"),k=h.filter(M=>M.status==="fulfilled"&&M.value.ok);b.length>0?xe({title:"Partial approval",description:`${k.length} entries approved, ${b.length} failed.`,variant:"destructive"}):xe({title:"Entries approved",description:`${k.length} entries have been successfully approved.`}),m(!1),n({}),i()}catch{xe({title:"Error",description:"Failed to approve entries. Please try again.",variant:"destructive"})}finally{l(!1)}},[e,xe,n,i]),C=v.useCallback(async()=>{const w=e.getFilteredSelectedRowModel().rows.filter(S=>{const h=S.original;return!h.isNew&&h.approvalStatus!=="pending"}).map(S=>S.original);try{c(!0);const S=w.map(M=>fetch(`/api/time-entries/${M.id}/unapprove`,{method:"PATCH"})),h=await Promise.allSettled(S),b=h.filter(M=>M.status==="rejected"),k=h.filter(M=>M.status==="fulfilled"&&M.value.ok);b.length>0?xe({title:"Partial unapproval",description:`${k.length} entries unapproved, ${b.length} failed.`,variant:"destructive"}):xe({title:"Entries unapproved",description:`${k.length} entries have been successfully unapproved.`}),u(!1),n({}),i()}catch{xe({title:"Error",description:"Failed to unapprove entries. Please try again.",variant:"destructive"})}finally{c(!1)}},[e,xe,n,i]);return{isApprovingBulk:a,isUnapprovingBulk:o,showBulkApproveDialog:g,showBulkUnapproveDialog:p,handleBulkApprove:d,handleBulkUnapprove:f,confirmBulkApprove:x,confirmBulkUnapprove:C,setShowBulkApproveDialog:m,setShowBulkUnapproveDialog:u}}function oa({entry:e,onEdit:s,onDelete:r,onView:n,onUpdate:i,properties:a=[]}){const{impactMedium:l}=xs(),o=Fs(0),c=qt(o,[-100,0,100],["#ef4444","#ffffff","#22c55e"]),g=qt(o,[-100,-50,0],[1,.5,0]),m=qt(o,[0,50,100],[0,.5,1]),p=(x,C)=>{C.offset.x<-100&&r?(l(),r(e)):C.offset.x>100&&s&&(l(),s(e))},u=(x,C)=>{const y=Math.floor(x),w=C||Math.round((x-y)*60);return y===0?`${w}m`:w===0?`${y}h`:`${y}h ${w}m`},d=()=>{if(e.property&&typeof e.property=="object"&&"nickname"in e.property)return e.property.nickname;if(e.property&&typeof e.property=="object"&&"name"in e.property)return e.property.name;if(typeof e.property=="string")return e.property;if(e.propertyId&&a.length>0){const x=a.find(C=>C.id===e.propertyId);if(x)return x.nickname||x.address}return"Unknown Property"},f=e.approvalStatus==="approved";return t.jsxs("div",{className:"relative overflow-hidden bg-white dark:bg-gray-900 rounded-xl border border-gray-100 dark:border-gray-800 shadow-sm mb-2.5",children:[t.jsxs(mt.div,{className:"absolute inset-0 flex items-center justify-between px-6",style:{background:c},children:[t.jsx(mt.div,{className:"flex items-center text-white",style:{opacity:g},children:t.jsx(Xe,{className:"w-4 h-4 mr-2"})}),t.jsx(mt.div,{className:"flex items-center text-white",style:{opacity:m},children:t.jsx(Es,{className:"w-4 h-4 ml-2"})})]}),t.jsxs(mt.div,{drag:"x",dragConstraints:{left:0,right:0},dragElastic:.1,onDragEnd:p,style:{x:o},className:re("relative bg-white dark:bg-gray-900 px-4 py-3.5 cursor-pointer active:bg-gray-50 dark:active:bg-gray-800 flex items-start gap-3 z-10",e.deletedAt&&"opacity-50"),whileTap:{scale:.995},onClick:x=>{x.target.closest("button")||s==null||s(e)},children:[t.jsx("div",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full bg-gray-100 dark:bg-gray-800",children:t.jsx(ys,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"})}),t.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[t.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100 text-[13px] truncate",children:d()}),t.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400 truncate lowercase",children:e.category||e.activityType}),e.description&&t.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 line-clamp-2",children:e.description}),e.source==="geofence"&&e.approvalStatus==="pending"&&t.jsxs("span",{className:"flex items-center gap-1 mt-0.5",children:[mn("geofence"),t.jsx("span",{className:"text-[10px] text-blue-500 dark:text-blue-400 font-medium",children:"Detected visit â awaiting review"})]})]}),t.jsxs("div",{className:"flex flex-col items-end gap-1.5 shrink-0",children:[t.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100 text-[13px] whitespace-nowrap",children:u(e.hours,e.minutes)}),t.jsx("div",{onClick:x=>x.stopPropagation(),children:i?t.jsx(kn,{entry:e,onUpdate:i}):t.jsx(tn,{className:re("w-4 h-4",f?"text-green-500 fill-green-50":"text-gray-300 dark:text-gray-600")})})]})]})]})}function da({entries:e,onEdit:s,onDelete:r,onView:n,isLoading:i=!1,emptyMessage:a="No activity entries found",properties:l=[],onUpdate:o}){if(i)return t.jsx("div",{className:"space-y-4 px-4 py-4",children:[1,2,3,4,5].map(g=>t.jsxs("div",{className:"flex justify-between items-center py-4 border-b border-gray-100",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(Ut,{className:"h-4 w-32 rounded-md"}),t.jsx(Ut,{className:"h-3 w-20 rounded-md"})]}),t.jsx(Ut,{className:"h-4 w-16 rounded-md"})]},g))});if(e.length===0)return t.jsxs("div",{className:"text-center py-12",children:[t.jsx(Ye,{className:"w-12 h-12 text-gray-300 dark:text-gray-600 mx-auto mb-4"}),t.jsx("p",{className:"text-gray-500 dark:text-gray-400",children:a})]});const c=v.useMemo(()=>{const g=[];return[...e].sort((p,u)=>{const d=new Date(p.date).getTime();return new Date(u.date).getTime()-d}
50).forEach(p=>{let u="Unknown Date";try{u=St(p.date,"EEE, MMM d")}catch{}const d=g[g.length-1];d&&d.date===u?d.items.push(p):g.push({date:u,items:[p]})}),g},[e]);return t.jsx("div",{children:t.jsx(rn,{children:c.map(g=>t.jsxs("div",{className:"mb-2",children:[t.jsx("div",{className:"bg-gray-200 dark:bg-gray-800 px-4 pt-2 pb-3 text-xs font-semibold text-gray-600 dark:text-gray-400 uppercase tracking-wide sticky top-0 z-10 w-full",children:g.date}),t.jsx("div",{className:"bg-transparent pt-2",children:g.items.map(m=>t.jsx(oa,{entry:m,onEdit:s,onDelete:r,onView:n,onUpdate:o,properties:l},m.id))})]},g.date))})})}function Ra(){var kr,Rr;const[e,s]=v.useState(!1),r=fr(),[n,i]=v.useState(!1);v.useEffect(()=>{i(!0)},[]);const{toast:a}=ye(),{selectedMonth:l,goToPreviousMonth:o,goToNextMonth:c,isAtCurrentMonth:g}=Xi(),{startEdit:m,cancelEdit:p,isEditing:u}=Ji(),{loading:d,entries:f,setEntries:x,newEntries:C,setNewEntries:y,error:w,fetchData:S,stats:h}=Zi(e),{registerRefreshCallback:b}=vs();v.useEffect(()=>{b(S)},[S,b]);const{globalFilter:k,setGlobalFilter:M,statusFilter:D,setStatusFilter:T,filteredData:I,groupedData:U,viewMode:q,setViewMode:Q}=ta({entries:f,newEntries:C,selectedMonth:l}),{previewFile:Z,setPreviewFile:de,isFilePreviewOpen:J,setIsFilePreviewOpen:Ve,currentFileIndex:Je,setCurrentFileIndex:Le,handleOpenFilePreview:Ze,downloadFile:et,deleteFileDialogOpen:tt,setDeleteFileDialogOpen:rt,fileToDelete:le,handleFileDeleteClick:je,confirmFileDelete:Be,deleteFileMutation:nt}=ea(S),{data:ue=[]}=ws({queryKey:["/api/properties"],retry:!1}),{handleAddNewEntry:Ge,handleUpdateEntry:me,handleUpdateMultipleFields:He,deleteNewEntry:st,handleDeleteEntry:Oe,confirmDeleteEntry:Ue,entryToDelete:it,showDeleteDialog:at,setShowDeleteDialog:lt,isDeletingEntry:ot}=ra({entries:f,setEntries:x,newEntries:C,setNewEntries:y,startEdit:m,properties:ue}),[dt,se]=v.useState(!1),[N,R]=v.useState(null),[P,$]=v.useState(!1),[O,z]=v.useState(null),[F,B]=v.useState(!1),[H,X]=v.useState(!1),[Ce,fe]=v.useState(!1),[qe,We]=v.useState(null),[Ot,Qe]=v.useState(!1),[he,Et]=v.useState(null),[zt,ct]=v.useState(new Set),[G,ee]=v.useState(!1),[ie,K]=v.useState(!1),[ke,wr]=v.useState(!1),Bt=async(E,j)=>{ee(!0);try{const V=new FormData;
50Object.keys(E).forEach(W=>{E[W]!==null&&E[W]!==void 0&&V.append(W,String(E[W]))}),V.has("source")||V.append("source","manual");const Y=await ge("POST","/api/time-entries",V);if(Y.ok){const W=await Y.json();if(j&&j.length>0&&W.id)try{const ze=new FormData;j.forEach(Fr=>{ze.append("files",Fr)}),await ge("POST",`/api/evidence-files/${W.id}`,ze),a({title:"Evidence Attached",description:`${j.length} file(s) uploaded successfully`})}catch(ze){console.error("File upload failed",ze),a({title:"Evidence Upload Failed",description:"Entry created but files failed to upload",variant:"destructive"})}a({title:"Entry Created",description:"Time entry has been successfully created"}),X(!1),Qe(!1),S()}else throw new Error("Failed to create entry")}catch(V){throw a({title:"Error",description:"Failed to create time entry",variant:"destructive"}),V}finally{ee(!1)}},Rn=E=>{Et(E),Qe(!0)},Fn=v.useMemo(()=>[{id:"select",header:({table:E})=>t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx(yt,{checked:E.getIsAllPageRowsSelected(),onCheckedChange:j=>E.toggleAllPageRowsSelected(!!j),"aria-label":"Select all"})}),cell:({row:E})=>{const j=E.original,V=j.isNew;return t.jsxs("div",{className:"flex items-center justify-center gap-1 w-full h-full",children:[t.jsx(yt,{checked:E.getIsSelected(),onCheckedChange:Y=>E.toggleSelected(!!Y),"aria-label":"Select row",disabled:V}),V&&t.jsx(L,{size:"sm",variant:"ghost",onClick:()=>st(j.id),className:"h-5 w-5 p-0 text-red-500 hover:text-red-700 flex items-center justify-center",title:"Delete new entry",children:t.jsx(js,{className:"h-3 w-3"})})]})},enableSorting:!1,enableHiding:!1},{accessorKey:"date",header:({column:E})=>t.jsxs(L,{variant:"ghost",onClick:()=>E.toggleSorting(E.getIsSorted()==="asc"),className:"h-8 p-0 hover:bg-transparent text-left justify-start w-full font-semibold",children:["DATE",t.jsx(Hr,{className:"ml-2 h-4 w-4"})]}),cell:({row:E})=>{const j=E.original;return t.jsx(Oi,{entry:j,onUpdate:(V,Y,W)=>me(V,Y,W,j),isEditing:u(j.id,"date"),onStartEdit:()=>!j.deletedAt&&m(j.id,"date"),onCancelEdit:()=>p(j.id,"date")})}},{accessorKey:"hours",header:({column:E})=>t.jsxs(L,{variant:"ghost",onClick:()=>E.toggleSorting(E.getIsSorted()==="asc"),className:"h-8 p-0 hover:bg-transparent text-left justify-start w-full font-semibold",children:["DURATION",t.jsx(Hr,{className:"ml-2 h-4 w-4"})]}),cell:({row:E})=>{const j=E.original;return t.jsx(zi,{entry:j,onUpdate:(V,Y,W)=>me(V,Y,W,j),isEditing:u(j.id,"hours"),onStartEdit:()=>!j.deletedAt&&m(j.id,"hours"),onCancelEdit:()=>p(j.id,"hours")})}},{accessorKey:"activityType",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Activity Type"})}),cell:({row:E})=>{const j=E.original;return t.jsx(Bi,{entry:j,onUpdate:(V,Y,W)=>me(V,Y,W,j),isEditing:u(j.id,"activityType"),onStartEdit:()=>!j.deletedAt&&m(j.id,"activityType"),onCancelEdit:()=>p(j.id,"activityType")})}},{accessorKey:"category",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Category"})}),cell:({row:E})=>{const j=E.original;return t.jsx(qi,{entry:j,onUpdate:(V,Y,W)=>me(V,Y,W,j),onUpdateMultiple:(V,Y)=>He(V,Y,j),isEditing:u(j.id,"isMaterialParticipation"),onStartEdit:()=>!j.deletedAt&&m(j.id,"isMaterialParticipation"),onCancelEdit:()=>p(j.id,"isMaterialParticipation"),categories:cn})},enableHiding:!0,enableSorting:!0},{accessorKey:"description",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Description"})}),cell:({row:E})=>{const j=E.original;return t.jsx(Gi,{entry:j,onUpdate:(V,Y,W)=>me(V,Y,W,j),isEditing:u(j.id,"description"),onStartEdit:()=>!j.deletedAt&&m(j.id,"description"),onCancelEdit:()=>p(j.id,"description"),glowingDescriptions:zt,setGlowingDescriptions:ct})}},{accessorKey:"property",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Property"})}),cell:({row:E})=>{const j=E.original;return t.jsx(Ui,{entry:j,onUpdate:(V,Y,W)=>
50me(V,Y,W,j),isEditing:u(j.id,"property"),onStartEdit:()=>!j.deletedAt&&m(j.id,"property"),onCancelEdit:()=>p(j.id,"property"),properties:ue})}},{accessorKey:"recordedBy",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Recorded By"})}),cell:({row:E})=>{const j=E.original;if(j.isNew)return t.jsx("span",{className:"text-xs text-muted-foreground",children:"You"});const{user:Y}=bs(),W=j.recordedBy,ze=j.recordedByUserId;if(!W&&!ze)return t.jsx("span",{className:"text-xs text-muted-foreground",children:"â"});if((Y==null?void 0:Y.id)===ze)return t.jsx(ne,{variant:"secondary",className:"text-xs bg-blue-100 text-blue-800",children:"You"});const Wn=W?W&&W?`${W}`:W:"Team Member";return t.jsx(ne,{variant:"outline",className:"text-xs",children:Wn})},enableSorting:!0,enableHiding:!0},{accessorKey:"evidenceFiles",header:()=>t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-center",children:"Evidence"})}),cell:({row:E})=>{const j=E.original;return j.isNew?t.jsx("span",{className:"text-muted-foreground italic text-xs",children:"Save entry first"}):t.jsx(Ki,{entry:j,onUpdate:S,onOpenFilePreview:Ze})}},{accessorKey:"source",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Source"})}),cell:({row:E})=>{const j=E.original;return t.jsx(Wi,{entry:j})}},{accessorKey:"propertyType",header:()=>t.jsx("div",{className:"flex items-center justify-start w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-left",children:"Property Type"})}),cell:({row:E})=>{const j=E.original;return t.jsx(Qi,{entry:j,onUpdate:(V,Y,W)=>me(V,Y,W,j),isEditing:u(j.id,"propertyType"),onStartEdit:()=>!j.deletedAt&&m(j.id,"propertyType"),onCancelEdit:()=>p(j.id,"propertyType")})},enableSorting:!0,enableHiding:!0},{accessorKey:"approvalStatus",header:()=>t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-center",children:"Approval"})}),cell:({row:E})=>{const j=E.original;return j.isNew?t.jsx(ne,{variant:"secondary",className:"text-xs",children:"New"}):t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx(kn,{entry:j,onUpdate:S})})}},...e?[{accessorKey:"restore",header:()=>t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-center",children:"Restore"})}),cell:({row:E})=>{const j=E.original;return j.isNew?t.jsx(ne,{variant:"secondary",className:"text-xs",children:"New"}):t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx(Yi,{entry:j,onUpdate:S})})},enableHiding:!0}]:[],{id:"actions",header:()=>t.jsx("div",{className:"flex items-center justify-center w-full h-full",children:t.jsx("span",{className:"text-sm font-semibold tracking-wide text-center",children:"Actions"})}),cell:({row:E})=>{const j=E.original,V="isNew"in j&&j.isNew===!0;return t.jsx("div",{className:"flex items-center justify-center gap-2",children:t.jsxs(ln,{children:[t.jsx(on,{asChild:!0,children:t.jsxs(L,{variant:"ghost",className:"h-8 w-8 p-0",children:[t.jsx("span",{className:"sr-only",children:"Open menu"}),t.jsx(Ps,{className:"h-4 w-4"})]})}),t.jsxs(dn,{align:"end",children:[t.jsxs(It,{onClick:()=>{V||Rn(j)},disabled:V,children:[t.jsx(Ms,{className:"mr-2 h-4 w-4"}),"Duplicate Entry"]}),t.jsx(It,{onClick:()=>{V||(We(j),fe(!0))},disabled:V,children:"Edit Entry"}),t.jsx(It,{onClick:()=>{V||(z(j),B(!0))},disabled:V,children:"View Details"}),!j.deletedAt&&t.jsx(It,{onClick:()=>{V||Oe(j)},className:"text-red-600",disabled:V,children:"Delete Entry"})]})]})})}}],[S,me,He,st,u,m,p,ue]),{table:Re,rowSelection:En,setRowSelection:jr}=sa({data:I,columns:Fn,globalFilter:k,setGlobalFilter:M}),{handleBulkDelete:Mn,confirmBulkDelete:Pn,showBulkDeleteDialog:Dn,setShowBulkDeleteDialog:In,isDeletingBulk:br,handleBulkEnhancement:$n,isBulkEnhancing:_n}=na({table:Re,entries:f,setEntries:x,setRowSelection:jr,fetchData:S}),{isApprovingBulk:Nr,isUnapprovingBulk:Sr,showBulkApproveDialog:An,showBulkUnapproveDialog:Tn,handleBulkApprove:Vn,handleBulkUnapprove:Ln,confirmBulkApprove:Hn,confirmBulkUnapprove:On,setShowBulkApproveDialog:zn,setShowBulkUnapproveDialog:Bn}=la({table:Re,entries:f,setEntries:x,setRowSelection:jr,fetchData:S}),{handleModifyEntrySubmit:Gn,isSubmitting:Un}=ia({entries:f,setEntries:x,setShowModifyEntryDialog:fe,setEntryToModify:We}),Cr=t.jsxs(t.Fragment,{children:[N&&t.jsx(Or,{file:N,isOpen:P,onClose:()=>{$(!1),R(null)},hasActiveSubscription:!0}
50),t.jsx(Ts,{open:F,onOpenChange:B,entry:O}),t.jsx(Is,{open:at,onOpenChange:lt,entry:it,onConfirm:Ue,isDeleting:ot}),t.jsx($s,{open:Dn,onOpenChange:In,selectedCount:Re.getFilteredSelectedRowModel().rows.length,onConfirm:Pn,isDeleting:br}),t.jsx(Vs,{open:An,onOpenChange:zn,selectedCount:Re.getFilteredSelectedRowModel().rows.length,confirmBulkApprove:Hn,isApprovingBulk:Nr,table:Re}),t.jsx(Ls,{open:Tn,onOpenChange:Bn,selectedCount:Re.getFilteredSelectedRowModel().rows.length,confirmBulkUnapprove:On,isUnapprovingBulk:Sr,table:Re}),t.jsx(As,{open:dt,onClose:()=>se(!1),onImportComplete:S,properties:ue}),t.jsx(Ns,{open:Ce,onClose:()=>{fe(!1),We(null)},onSubmit:Gn,properties:ue,entry:qe,isSubmitting:Un}),Z&&t.jsx(Or,{file:Z,isOpen:J,onClose:()=>{Ve(!1),de(null),Le(0)},hasActiveSubscription:!0,allFiles:Z.allFiles||[],currentFileIndex:Je,onFileChange:E=>{if(Z.allFiles&&Z.allFiles[E]){const j=Z.allFiles[E];Le(E),de({...Z,id:j.numericId||j.id,numericId:j.numericId||j.id,originalName:j.originalName||j.fileName,fileName:j.fileName,fileUrl:j.fileUrl,mimeType:j.mimeType||Lt(j.fileName),uploadedAt:j.uploadedAt||j.createdAt,fileSize:j.fileSize,aiSummary:j.aiSummary,aiAnalysisStatus:j.aiAnalysisStatus,r2Key:j.r2Key,storageType:j.storageType,publicToken:j.publicToken})}},downloadFile:et,getMimeTypeFromFileName:Lt,onDelete:je}),t.jsx(ks,{open:tt,onOpenChange:rt,fileName:(le==null?void 0:le.originalName)||(le==null?void 0:le.fileName)||"",onConfirm:Be,isDeleting:nt.isPending}),t.jsx(Tr,{open:H,onClose:()=>X(!1),onSubmit:Bt,properties:ue,isSubmitting:G}),t.jsx(Tr,{open:Ot,onClose:()=>{Qe(!1),Et(null)}
50,onSubmit:Bt,properties:ue,isSubmitting:G,initialValues:he?{date:((kr=he.date)==null?void 0:kr.substring(0,10))||new Date().toISOString().substring(0,10),hours:he.hours.toString(),activityType:he.activityType,description:he.description,propertyId:((Rr=he.propertyId)==null?void 0:Rr.toString())||"none",isMaterialParticipation:he.isMaterialParticipation??!1,isQualifiedNonMaterial:he.isQualifiedNonMaterial??!1,category:he.isMaterialParticipation?"material":he.isQualifiedNonMaterial?"qualified":"passive"}:void 0,isDuplicate:!0})]}),qn=h;return w?t.jsx("div",{className:"container mx-auto p-6",children:t.jsx(Pe,{children:t.jsx(De,{className:"pt-6",children:t.jsxs("div",{className:"text-center text-red-600",children:[t.jsxs("p",{children:["Error loading activity ledger: ",w]}),t.jsxs(L,{onClick:S,variant:"outline",className:"mt-4",children:[t.jsx(sr,{className:"mr-2 h-4 w-4"}),"Retry"]})]})})})}):r?t.jsxs(aa,{fullWidth:!0,children:[t.jsxs("div",{className:"space-y-3 pt-3 pb-2",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100 tracking-tight",children:"Activity Ledger"}),t.jsx(L,{variant:"ghost",size:"icon",className:"h-9 w-9",onClick:()=>K(!ie),children:t.jsx(gn,{className:"h-5 w-5 stroke-[2.5]"})})]}),t.jsx("div",{className:"w-full",children:t.jsx(Sn,{selectedMonth:l,goToPreviousMonth:o,goToNextMonth:c,isAtCurrentMonth:g})}),t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs(be,{value:D,onValueChange:T,children:[t.jsx(Ne,{className:"h-10 text-sm font-semibold flex-1 rounded-xl",children:t.jsx(_e,{placeholder:"ALL STATUS"})}),t.jsxs(Se,{children:[t.jsx(te,{value:"all",children:"ALL STATUS"}),t.jsx(te,{value:"pending",children:"PENDING"}),t.jsx(te,{value:"approved",children:"APPROVED"})]})]})}),t.jsx(Cn,{globalFilter:k,setGlobalFilter:M,statusFilter:D,setStatusFilter:T,table:Re,allData:[...C,...f],onImportClick:()=>se(!0),onRefresh:S,isLoading:d,showDeleted:e,setShowDeleted:s,showMobileFilters:ie,setShowMobileFilters:K})]}),t.jsx(da,{entries:I.map(E=>({id:E.id,date:E.date,hours:typeof E.hours=="string"?parseFloat(E.hours):E.hours,minutes:E.minutes,activityType:E.activityType,description:E.description,property:E.property,propertyId:E.propertyId,approvalStatus:E.approvalStatus,category:E.category,source:E.source,isNew:E.isNew,deletedAt:E.deletedAt})),properties:ue,onUpdate:S,isLoading:d,onView:E=>{const j=[...C,...f].find(V=>V.id===E.id);j&&!("isNew"in j&&j.isNew)&&(z(j),B(!0))},onEdit:E=>{const j=[...C,...f].find(V=>V.id===E.id);j&&!("isNew"in j&&j.isNew)&&(We(j),fe(!0))},onDelete:E=>{const j=[...C,...f].find(V=>V.id===E.id);j&&!("isNew"in j&&j.isNew)&&Oe(j)},emptyMessage:"No entries for this period"}),Cr]}):n?t.jsx(t.Fragment,{children:t.jsx(Hi,{stats:qn,table:Re,rowSelection:En,selectedMonth:l,goToNextMonth:c,goToPreviousMonth:o,isAtCurrentMonth:g,viewMode:q,setViewMode:Q,globalFilter:k,setGlobalFilter:M,statusFilter:D,setStatusFilter:T,groupedData:U,loading:d,entries:f,newEntries:C,fetchData:S,filteredData:I,properties:ue,handleAddNewEntry:Ge,handleBulkEnhancement:$n,handleBulkDelete:Mn,handleBulkApprove:Vn,handleBulkUnapprove:Ln,isBulkEnhancing:_n,isDeletingBulk:br,isApprovingBulk:Nr,isUnapprovingBulk:Sr,showDeleted:e,setShowDeleted:s,showImportDialog:dt,setShowImportDialog:se,selectedEntry:O,setSelectedEntry:z,showDetailsDialog:F,setShowDetailsDialog:B,entryToModify:qe,setEntryToModify:We,showModifyEntryDialog:Ce,setShowModifyEntryDialog:fe,showDuplicateDialog:Ot,setShowDuplicateDialog:Qe,entryToDuplicate:he,setEntryToDuplicate:Et,showDeleteDialog:at,setShowDeleteDialog:lt,entryToDelete:it,handleDeleteEntry:Oe,confirmDeleteEntry:Ue,isDeletingEntry:ot,showNewEntryDialog:H,setShowNewEntryDialog:X,isCreating:G,setIsCreating:ee,showFilePreview:P,setShowFilePreview:$,selectedFile:N,setSelectedFile:R,previewFile:Z,setPreviewFile:de,isFilePreviewOpen:J,currentFileIndex:Je,setCurrentFileIndex:Le,handleOpenFilePreview:Ze,downloadFile:et,deleteFileDialogOpen:tt,setDeleteFileDialogOpen:rt,fileToDelete:le,handleFileDeleteClick:je,confirmFileDelete:Be,deleteFileMutation:nt,sharedDialogs:Cr,onCreateEntry:Bt,glowingDescriptions:zt,setGlowingDescriptions:ct})}):t.jsx("div",{className:"skeleton-loader"})}export{Ra 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.