1import{r as w,u as I,s as C,j as e,C as m,d as _,f as q,a as g,c as j,b as f,T as A,h as B,i as D,k as b,a3 as M,e as S,S as H,B as P,l as $,a5 as O,a9 as Q}from"./index-CFGztFot.js";import{C as Y}from"./checkbox-CFos7zeK.js";import{T as z}from"./trash-2-BBVpPEZj.js";import{d as G,f as V}from"./format-DKgPYdD6.js";import{t as E}from"./toDate-qOSwr3PX.js";import"./en-US-DsfRGM9l.js";function J(s,a){const r=E(s),o=E(a),c=F(r,o),i=Math.abs(G(r,o));r.setDate(r.getDate()-c*i);const l=+(F(r,o)===-c),d=c*(i-l);return d===0?0:d}function F(s,a){const r=s.getFullYear()-a.getFullYear()||s.getMonth()-a.getMonth()||s.getDate()-a.getDate()||s.getHours()-a.getHours()||s.getMinutes()-a.getMinutes()||s.getSeconds()-a.getSeconds()||s.getMilliseconds()-a.getMilliseconds();return r<0?-1:r>0?1:r}const R=()=>{const[s,a]=w.useState([]),[r,o]=w.useState(!0),{toast:c}=I();w.useEffect(()=>{i()},[]);const i=async()=>{try{const{data:t,error:n}=await C.from("tasks").select("*").order("due_date",{ascending:!0,nullsFirst:!1}).order("priority",{ascending:!1});if(n)throw n;a(t||[])}catch(t){console.error("Error fetching tasks:",t),c({title:"Error",description:"Failed to load tasks",variant:"destructive"})}finally{o(!1)}},l=async(t,n)=>{const u=n==="completed"?"pending":"completed",T=u==="completed"?new Date().toISOString():null;try{const{error:h}=await C.from("tasks").update({status:u,completed_at:T}).eq("id",t);if(h)throw h;c({title:u==="completed"?"Task Completed":"Task Reopened",description:"Task status updated successfully"}),i()}catch(h){console.error("Error updating task:",h),c({title:"Error",description:"Failed to update task",variant:"destructive"})}},d=async t=>{try{const{error:n}=await C.from("tasks").delete().eq("id",t);if(n)throw n;c({title:"Task Deleted",description:"Task removed successfully"}),i()}catch(n){console.error("Error deleting task:",n),c({title:"Error",description:"Failed to delete task",variant:"destructive"})}},y=(t,n)=>{const u=n?new Date(n):new Date,T=new Date(t);return J(u,T)},N=t=>{switch(t){case"urgent":return"destructive";case"high":return"default";case"medium":return"secondary";default:return"outline"}},v=t=>{switch(t){case"cold_prospect_reminder":return e.jsx(Q,{className:"w-4 h-4"});case"follow_up":return e.jsx(O,{className:"w-4 h-4"});default:return e.jsx(M,{className:"w-4 h-4"})}},x=s.filter(t=>t.status==="pending"),p=s.filter(t=>t.status==="completed");return r?e.jsx(m,{children:e.jsx(_,{className:"flex items-center justify-center py-12",children:e.jsx(q,{className:"w-8 h-8 animate-spin text-muted-foreground"})})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(m,{children:e.jsxs(g,{className:"pb-3",children:[e.jsx(j,{children:"Pending Tasks"}),e.jsx(f,{className:"text-3xl",children:x.length})]})}),e.jsx(m,{children:e.jsxs(g,{className:"pb-3",children:[e.jsx(j,{children:"Completed Tasks"}),e.jsx(f,{className:"text-3xl",children:p.length})]})}),e.jsx(m,{children:e.jsxs(g,{className:"pb-3",children:[e.jsx(j,{children:"Total Tasks"}),e.jsx(f,{className:"text-3xl",children:s.length})]})})]}),e.jsxs(m,{children:[e.jsxs(g,{children:[e.jsx(f,{children:"Task Manager"}),e.jsx(j,{children:"Manage your tasks and track progress"})]}),e.jsx(_,{children:e.jsxs(A,{defaultValue:"pending",className:"space-y-4",children:[e.jsxs(B,{children:[e.jsxs(D,{value:"pending",children:["Pending (",x.length,")"]}),e.jsxs(D,{value:"completed",children:["Completed (",p.length,")"]}),e.jsxs(D,{value:"all",children:["All (",s.length,")"]})]}),e.jsx(b,{value:"pending",className:"space-y-3",children:x.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(M,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No pending tasks. Great work!"})]}):x.map(t=>e.jsx(k,{task:t,onToggle:l,onDelete:d,getDaysInQueue:y,getPriorityColor:N,getTypeIcon:v},t.id))}),e.jsx(b,{value:"completed",className:"space-y-3",children:p.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:e.jsx("p",{children:"No completed tasks yet"})}):p.map(t=>
1e.jsx(k,{task:t,onToggle:l,onDelete:d,getDaysInQueue:y,getPriorityColor:N,getTypeIcon:v},t.id))}),e.jsx(b,{value:"all",className:"space-y-3",children:s.map(t=>e.jsx(k,{task:t,onToggle:l,onDelete:d,getDaysInQueue:y,getPriorityColor:N,getTypeIcon:v},t.id))})]})})]})]})},k=({task:s,onToggle:a,onDelete:r,getDaysInQueue:o,getPriorityColor:c,getTypeIcon:i})=>{const l=s.due_date&&new Date(s.due_date)<new Date&&s.status!=="completed",d=o(s.created_at,s.completed_at);return e.jsxs("div",{className:`flex items-start gap-3 p-4 rounded-lg border ${s.status==="completed"?"bg-muted/50":l?"border-destructive/50 bg-destructive/5":"bg-background"}`,children:[e.jsx(Y,{checked:s.status==="completed",onCheckedChange:()=>a(s.id,s.status),className:"mt-1"}),e.jsx("div",{className:"flex-1 space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[i(s.task_type),e.jsx("h4",{className:`font-medium ${s.status==="completed"?"line-through text-muted-foreground":""}`,children:s.title}),s.auto_created&&e.jsxs(S,{variant:"outline",className:"text-xs",children:[e.jsx(H,{className:"w-3 h-3 mr-1"}),"Auto"]})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s.description}),s.suggested_action&&e.jsxs("p",{className:"text-sm text-primary mt-2",children:["ð¡ ",s.suggested_action]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:c(s.priority),children:s.priority}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>r(s.id),children:e.jsx(z,{className:"h-4 w-4 text-destructive"})})]}),s.due_date&&e.jsxs("span",{className:`text-xs ${l?"text-destructive font-medium":"text-muted-foreground"}`,children:[l&&"â ï¸ ","Due: ",V(new Date(s.due_date),"MMM d, yyyy")]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx($,{className:"h-3 w-3"}),d," ",d===1?"day":"days"," in queue"]})]})]})})]})};export{R as TaskDashboard};
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.