// @bun
var W=Object.defineProperty;var B=(e)=>e;function L(e,o){this[e]=B.bind(null,o)}var T=(e,o)=>{for(var t in o)W(e,t,{get:o[t],enumerable:!0,configurable:!0,set:L.bind(o,t)})};var k=(e,o)=>()=>(e&&(o=e(e=0)),o);import{jsx as n,jsxs as b}from"react/jsx-runtime";function D({value:e,onChange:o,categories:t}){let p=(r,c)=>{o({...e,[r]:c})};return b("div",{className:"grid gap-3 rounded-2xl border border-border bg-card p-4 md:grid-cols-4",children:[b("label",{className:"flex flex-col text-muted-foreground text-xs uppercase tracking-wide",children:["Status",b("select",{className:"mt-1 rounded-md border border-border bg-background px-3 py-2 text-foreground text-sm",value:e.status,onChange:(r)=>p("status",r.target.value),children:[n("option",{value:"all",children:"All tasks"}),n("option",{value:"active",children:"Active"}),n("option",{value:"completed",children:"Completed"})]})]}),b("label",{className:"flex flex-col text-muted-foreground text-xs uppercase tracking-wide",children:["Priority",b("select",{className:"mt-1 rounded-md border border-border bg-background px-3 py-2 text-foreground text-sm",value:e.priority,onChange:(r)=>p("priority",r.target.value),children:[n("option",{value:"all",children:"All"}),n("option",{value:"LOW",children:"Low"}),n("option",{value:"MEDIUM",children:"Medium"}),n("option",{value:"HIGH",children:"High"}),n("option",{value:"URGENT",children:"Urgent"})]})]}),b("label",{className:"flex flex-col text-muted-foreground text-xs uppercase tracking-wide",children:["Category",b("select",{className:"mt-1 rounded-md border border-border bg-background px-3 py-2 text-foreground text-sm",value:e.categoryId,onChange:(r)=>p("categoryId",r.target.value),children:[n("option",{value:"all",children:"All categories"}),t.map((r)=>n("option",{value:r.id,children:r.name},r.id))]})]}),b("label",{className:"flex flex-col text-muted-foreground text-xs uppercase tracking-wide",children:["Search",n("input",{type:"search",className:"mt-1 rounded-md border border-border bg-background px-3 py-2 text-foreground text-sm",placeholder:"Search by title",value:e.search,onChange:(r)=>p("search",r.target.value)})]})]})}import{gql as O}from"@apollo/client";import{useMutation as z}from"@apollo/client/react";import{useTemplateRuntime as J}from"@contractspec/lib.example-shared-ui";import{useState as y}from"react";import{jsx as a,jsxs as u}from"react/jsx-runtime";var X=O`
  mutation CreateTask($input: CreateTaskInput!) {
    createTask(input: $input) {
      id
      title
    }
  }
`;function F({categories:e}){let{projectId:o}=J(),[t,p]=y(""),[r,c]=y(""),[h,f]=y("MEDIUM"),[g,v]=y("none"),[w,C]=y(""),[l,{loading:x}]=z(X);return u("form",{onSubmit:async(d)=>{if(d.preventDefault(),!t.trim())return;await l({variables:{input:{projectId:o,title:t.trim(),description:r.trim()||void 0,priority:h,categoryId:g==="none"?void 0:g,tags:Z(w)}},refetchQueries:["Tasks"],awaitRefetchQueries:!0}),p(""),c(""),f("MEDIUM"),v("none"),C("")},className:"space-y-3 rounded-2xl border border-border bg-background/60 p-4",children:[a("div",{children:u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Title",a("input",{type:"text",className:"mt-1 w-full rounded-md border border-border bg-card px-3 py-2 text-sm",placeholder:"What needs to get done?",value:t,onChange:(d)=>p(d.target.value),required:!0})]})}),a("div",{children:u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Description",a("textarea",{className:"mt-1 w-full rounded-md border border-border bg-card px-3 py-2 text-sm",rows:3,placeholder:"Add context or policy notes",value:r,onChange:(d)=>c(d.target.value)})]})}),u("div",{className:"grid gap-3 md:grid-cols-3",children:[u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Priority",u("select",{className:"mt-1 w-full rounded-md border border-border bg-card px-3 py-2 text-sm",value:h,onChange:(d)=>f(d.target.value),children:[a("option",{value:"LOW",children:"Low"}),a("option",{value:"MEDIUM",children:"Medium"}),a("option",{value:"HIGH",children:"High"}),a("option",{value:"URGENT",children:"Urgent"})]})]}),u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Category",u("select",{className:"mt-1 w-full rounded-md border border-border bg-card px-3 py-2 text-sm",value:g,onChange:(d)=>v(d.target.value),children:[a("option",{value:"none",children:"None"}),e.map((d)=>a("option",{value:d.id,children:d.name},d.id))]})]}),u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Tags",a("input",{className:"mt-1 w-full rounded-md border border-border bg-card px-3 py-2 text-sm",placeholder:"Comma separated (optional)",value:w,onChange:(d)=>C(d.target.value)})]})]}),a("button",{type:"submit",className:"btn-primary w-full py-2 font-semibold text-sm",disabled:x,children:x?"Saving...":"Add task"})]})}function Z(e){return e.split(",").map((o)=>o.trim()).filter(Boolean)}import{Check as A,Circle as M,Trash2 as S}from"lucide-react";import{jsx as m,jsxs as N}from"react/jsx-runtime";function $({task:e,onToggle:o,onDelete:t}){let p=e.priority==="URGENT"?"text-red-200 bg-red-500/10 border-red-500/40":e.priority==="HIGH"?"text-amber-200 bg-amber-500/10 border-amber-500/40":e.priority==="LOW"?"text-emerald-200 bg-emerald-500/10 border-emerald-500/40":"text-violet-200 bg-violet-500/10 border-violet-500/40";return N("div",{className:"flex items-start gap-4 rounded-2xl border border-border/70 bg-card/60 p-4 transition hover:border-border",children:[m("button",{type:"button",className:"rounded-full border border-border p-2 text-muted-foreground hover:bg-muted/40","aria-pressed":e.completed,onClick:()=>o?.(e),children:e.completed?m(A,{className:"h-4 w-4 text-emerald-400"}):m(M,{className:"h-4 w-4"})}),N("div",{className:"flex-1 space-y-2",children:[N("div",{className:"flex flex-wrap items-center gap-2",children:[m("p",{className:`font-medium ${e.completed?"text-muted-foreground line-through":"text-foreground"}`,children:e.title}),m("span",{className:`rounded-full border px-2 py-0.5 text-xs ${p}`,children:e.priority.charAt(0)+e.priority.slice(1).toLowerCase()}),e.category?m("span",{className:"rounded-full bg-muted/40 px-2 py-0.5 text-muted-foreground text-xs",children:e.category.name}):null,e.dueDate?N("span",{className:"text-muted-foreground text-xs",children:["Due ",new Date(e.dueDate).toLocaleDateString()]}):null]}),e.description?m("p",{className:"text-muted-foreground text-sm",children:e.description}):null,e.tags.length?m("div",{className:"flex flex-wrap gap-1",children:e.tags.map((r)=>N("span",{className:"rounded-full bg-muted/40 px-2 py-0.5 text-muted-foreground text-xs",children:["#",r]},r))}):null]}),m("button",{type:"button",className:"text-muted-foreground hover:text-destructive","aria-label":`Delete ${e.title}`,onClick:()=>t?.(e),children:m(S,{className:"h-4 w-4"})})]})}import{gql as H}from"@apollo/client";import{useMutation as G,useQuery as K}from"@apollo/client/react";import{registerTemplateComponents as Y,useTemplateRuntime as Q}from"@contractspec/lib.example-shared-ui";import{useMemo as R,useState as q}from"react";import{jsx as i,jsxs as _}from"react/jsx-runtime";var U=H`
  query Tasks($projectId: ID!) {
    taskCategories(projectId: $projectId) {
      id
      name
      color
    }
    tasks(projectId: $projectId) {
      id
      title
      description
      completed
      priority
      dueDate
      tags
      category {
        id
        name
        color
      }
    }
  }
`,I=H`
  mutation ToggleTask($id: ID!, $completed: Boolean!) {
    toggleTask(id: $id, completed: $completed) {
      id
      completed
    }
  }
`,E=H`
  mutation DeleteTask($id: ID!) {
    deleteTask(id: $id)
  }
`;function V(){let{projectId:e}=Q(),[o,t]=q({status:"all",priority:"all",categoryId:"all",search:""}),{data:p,loading:r}=K(U,{variables:{projectId:e},fetchPolicy:"cache-and-network"}),[c]=G(I),[h]=G(E),f=p?.taskCategories??[],g=p?.tasks??[],v=R(()=>{return g.filter((l)=>{if(o.status==="active"&&l.completed)return!1;if(o.status==="completed"&&!l.completed)return!1;if(o.priority!=="all"&&l.priority!==o.priority)return!1;if(o.categoryId!=="all"&&l.category?.id!==o.categoryId)return!1;if(o.search&&!l.title.toLowerCase().includes(o.search.toLowerCase()))return!1;return!0})},[g,o]),w=async(l)=>{await c({variables:{id:l.id,completed:!l.completed},optimisticResponse:{toggleTask:{__typename:"Task",id:l.id,completed:!l.completed}},update(x){x.modify({fields:{tasks(P=[]){return P.map((d)=>d.__ref?.endsWith(l.id)?{...d,completed:!l.completed}:d)}}})}})},C=async(l)=>{await h({variables:{id:l.id},refetchQueries:[{query:U,variables:{projectId:e}}]})};return _("div",{className:"space-y-6",children:[i(D,{value:o,onChange:t,categories:f}),i(F,{categories:f}),r?i("p",{className:"text-muted-foreground text-sm",children:"Loading tasks\u2026"}):v.length?i("div",{className:"space-y-3",children:v.map((l)=>i($,{task:l,onToggle:w,onDelete:C},l.id))}):i("div",{className:"rounded-2xl border border-border border-dashed p-8 text-center",children:i("p",{className:"text-muted-foreground",children:"No tasks match your filters. Create one above."})})]})}Y("todos-app",{list:V,detail:V,form:F});export{V as TaskList,$ as TaskItem,F as TaskForm,D as FilterBar};
