1import{r as C,j as e}from"./react-vendor-DUhHROXo.js";import{P as E}from"./PortalLayout-BUxGSFei.js";import{C as u,b as y,c as D,d as b,a as N}from"./card-9IoFUltb.js";import{w as A,_ as B,J as S,D as H,aN as V,o as d,q as z,s as J,t as R,aO as G}from"./index-BLtzf0SR.js";import{I as k}from"./input-RFokm5kN.js";import{L as x}from"./label-B2yiss_Q.js";import{T as U}from"./textarea-Da4-oaTC.js";import{C as W}from"./checkbox-BAHxXF7u.js";import{S as X,a as Y,b as Z,c as $,d as ee}from"./select-CMAo_7oa.js";import{P as se}from"./progress-DQIGmiuZ.js";import{u as j}from"./useMutation-BXp6BKyU.js";import{s as c}from"./client-DTel1CZI.js";import{u as m}from"./index-Cx0UdoxP.js";import{P as F}from"./plus-Db1qFqHY.js";import{L as te}from"./layout-template-IVbbK7ol.js";import{C as v}from"./clipboard-list-CQJ-vJ2y.js";import{C as ie}from"./circle-check-big-DjewDTKr.js";import{C as re}from"./calendar-BDETTnfZ.js";import{T as ae}from"./trash-2-cCh6Q5cl.js";import{f as le}from"./format-DGzj7MEM.js";import"./AdminLayout-4AAuHeAU.js";import"./router-vendor-Dz9PdDzH.js";import"./NavLink-CsyG-eHO.js";import"./badge-BsE4KYIf.js";import"./scroll-area-BdyOmc9o.js";import"./index-BdQq_4o_.js";import"./collapsible-BAD8kbtc.js";import"./index-CMI-ZfmW.js";import"./arrow-left-CRb8P6iH.js";import"./globe-CQ83QW2m.js";import"./users-CIwSfVhi.js";import"./activity-CwFToTs3.js";import"./list-todo-BR3jv1RJ.js";import"./users-round-CCw5yxW7.js";import"./radio-BQgeDg5T.js";import"./clapperboard-BvstouST.js";import"./image-arBWrt3y.js";import"./folder-open-CIWhCFhy.js";import"./pencil-C2cyk8cg.js";import"./message-square-BDdDilNB.js";import"./ticket-l9bl0kcm.js";import"./megaphone-DpQsxotQ.js";import"./package-DKB1lvtO.js";import"./circle-user-BeB3uaA1.js";import"./folder-kanban-B8jlMC6s.js";import"./settings-Baim_Eei.js";import"./briefcase-CdSp4ViD.js";import"./chart-line-ohAz7u_s.js";import"./HostOwnerLayout-PM2-LrXf.js";import"./layers-CvbkNa7J.js";import"./dollar-sign-D3lTBfQm.js";import"./index-O12prPmO.js";import"./chevron-up-B89bkR-F.js";import"./en-US-Bfz1jvxT.js";import"./differenceInCalendarDays-D4nmWE3G.js";import"./getTimezoneOffsetInMilliseconds-DsfBWtEI.js";function ds(){const{user:o}=A(),p=B(),[T,h]=C.useState(!1),[ce,q]=C.useState(null),[a,n]=C.useState({title:"",description:"",due_date:"",template_id:""}),{data:f,isLoading:I}=S({queryKey:["checklists"],queryFn:async()=>{const{data:s,error:t}=await c.from("checklists").select("*, checklist_items(*)").order("created_at",{ascending:!1});if(t)throw t;return s}}),{data:l}=S({queryKey:["checklist-templates"],queryFn:async()=>{const{data:s,error:t}=await c.from("checklist_templates").select("*").order("name");if(t)throw t;return s}}),w=j({mutationFn:async s=>{const{data:t,error:r}=await c.from("checklists").insert({title:s.title,description:s.description,due_date:s.due_date||null,template_id:s.template_id||null,user_id:o==null?void 0:o.id}).select().single();if(r)throw r;if(s.template_id){const i=l==null?void 0:l.find(g=>g.id===s.template_id);if(i&&i.items){const g=i.items.map((O,Q)=>({checklist_id:t.id,title:O.title,sort_order:Q}));await c.from("checklist_items").insert(g)}}return t},onSuccess:()=>{p.invalidateQueries({queryKey:["checklists"]}),m.success("Checklist created"),h(!1),_()},onError:()=>m.error("Failed to create checklist")}),P=j({mutationFn:async({id:s,completed:t})=>{const{error:r}=await c.from("checklist_items").update({completed:!t,completed_at:t?null:new Date().toISOString(),completed_by:t?null:o==null?void 0:o.id}).eq("id",s);if(r)throw r},onSuccess:()=>{p.invalidateQueries({queryKey:["checklists"]})}}),K=j({mutationFn:async({checklistId:s,title:t})=>{const{error:r}=await c.from("checklist_items").insert({checklist_id:s,title:t});if(r)throw r},onSuccess:()=>{p.invalidateQueries({queryKey:["checklists"]}),m.success("Item added")},onError:()=>m.error("Failed to add item")}),L=j({mutationFn:async s=>{const{error:t}=await c.from("checklists").delete().eq("id",s);if(t)throw t},onSuccess:()=>{p.invalidateQueries({queryKey:["checklists"]}),m.success("Checklist deleted")},onError:()=>m.error("Failed to delete checklist")}),_=()=>{n({title:"",description:"",due_date:"",template_id:""}),q(null)},M=s=>{if(!s||s.length===0)return 0;const t=s.filter(r=>r.completed).length;return Math.round(t/s.length*100)};return e.jsx(E,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold",children:"Checklists"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage tasks and workflows"})]}),e.jsxs(H,{open:T,onOpenChange:s=>{h(s),s||_()},children:[e.jsx(V,{asChild:!0,children:e.jsxs(d,{children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"New Checklist"]})}),e.jsxs(z,{children:[e.jsxs(J,{children:[e.jsx(R,{children:"Create Checklist"}),e.jsx(G,{children:"Create a new checklist from scratch or use a template"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"title",children:"Title *"}),e.jsx(k,{id:"title",value:a.title,onChange:s=>n({...a,title:s.target.value}),placeholder:"Checklist title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"template",children:"Template (Optional)"}),e.jsxs(X,{value:a.template_id,onValueChange:s=>n({...a,template_id:s}),children:[e.jsx(Y,{children:e.jsx(Z,{placeholder:"Select a template"})}),e.jsx($,{children:l==null?void 0:l.map(s=>e.jsx(ee,{value:s.id,children:s.name},s.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"description",children:"Description"}),e.jsx(U,{id:"description",value:a.description,onChange:s=>n({...a,description:s.target.value}),placeholder:"Optional description"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{htmlFor:"due_date",children:"Due Date"}),e.jsx(k,{id:"due_date",type:"date",value:a.due_date,onChange:s=>n({...a,due_date:s.target.value})})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(d,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsx(d,{onClick:()=>w.mutate(a),disabled:!a.title||w.isPending,children:"Create"})]})]})]})]})]}),e.jsxs(u,{children:[e.jsxs(y,{children:[e.jsxs(D,{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-5 w-5"}),"Templates"]}
1),e.jsx(b,{children:"Quick-start with pre-defined checklists"})]}),e.jsx(N,{children:e.jsx("div",{className:"flex flex-wrap gap-2",children:l==null?void 0:l.map(s=>e.jsxs(d,{variant:"outline",onClick:()=>{n({...a,template_id:s.id,title:s.name}),h(!0)},children:[e.jsx(v,{className:"h-4 w-4 mr-2"}),s.name]},s.id))})})]}),I?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:[1,2,3].map(s=>e.jsxs(u,{className:"animate-pulse",children:[e.jsx(y,{children:e.jsx("div",{className:"h-5 bg-muted rounded w-3/4"})}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 bg-muted rounded"}),e.jsx("div",{className:"h-4 bg-muted rounded w-2/3"})]})})]},s))}):f&&f.length>0?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:f.map(s=>{const t=M(s.checklist_items||[]),r=t===100;return e.jsxs(u,{className:r?"border-green-500/50":"",children:[e.jsx(y,{className:"pb-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs(D,{className:"text-lg flex items-center gap-2",children:[r?e.jsx(ie,{className:"h-5 w-5 text-green-500"}):e.jsx(v,{className:"h-5 w-5"}),s.title]}),s.due_date&&e.jsxs(b,{className:"flex items-center gap-1 mt-1",children:[e.jsx(re,{className:"h-3 w-3"}),"Due ",le(new Date(s.due_date),"MMM d, yyyy")]})]}),e.jsx(d,{variant:"ghost",size:"icon",onClick:()=>{confirm("Delete this checklist?")&&L.mutate(s.id)},children:e.jsx(ae,{className:"h-4 w-4 text-destructive"})})]})}),e.jsxs(N,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Progress"}),e.jsxs("span",{className:"font-medium",children:[t,"%"]})]}),e.jsx(se,{value:t,className:"h-2"})]}),e.jsx("div",{className:"space-y-2",children:(s.checklist_items||[]).map(i=>e.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",onClick:()=>P.mutate({id:i.id,completed:i.completed}),children:[e.jsx(W,{checked:i.completed,className:"pointer-events-none"}),e.jsx("span",{className:i.completed?"line-through text-muted-foreground":"",children:i.title})]},i.id))}),e.jsx("div",{className:"pt-2",children:e.jsx(k,{placeholder:"Add new item...",onKeyDown:i=>{i.key==="Enter"&&i.currentTarget.value&&(K.mutate({checklistId:s.id,title:i.currentTarget.value}),i.currentTarget.value="")}})})]})]},s.id)})}):e.jsxs(u,{className:"p-12 text-center",children:[e.jsx(v,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"No checklists yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Create a checklist to track your tasks"}),e.jsxs(d,{onClick:()=>h(!0),children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Create Checklist"]})]})]})})}export{ds 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.