// @bun
import{jsx as a,jsxs as b}from"react/jsx-runtime";function D({value:e,onChange:d,categories:m}){let t=(o,c)=>{d({...e,[o]: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:(o)=>t("status",o.target.value),children:[a("option",{value:"all",children:"All tasks"}),a("option",{value:"active",children:"Active"}),a("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:(o)=>t("priority",o.target.value),children:[a("option",{value:"all",children:"All"}),a("option",{value:"LOW",children:"Low"}),a("option",{value:"MEDIUM",children:"Medium"}),a("option",{value:"HIGH",children:"High"}),a("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:(o)=>t("categoryId",o.target.value),children:[a("option",{value:"all",children:"All categories"}),m.map((o)=>a("option",{value:o.id,children:o.name},o.id))]})]}),b("label",{className:"flex flex-col text-muted-foreground text-xs uppercase tracking-wide",children:["Search",a("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:(o)=>t("search",o.target.value)})]})]})}import{gql as W}from"@apollo/client";import{useMutation as B}from"@apollo/client/react";import{useTemplateRuntime as L}from"@contractspec/lib.example-shared-ui";import{useState as y}from"react";import{jsx as p,jsxs as u}from"react/jsx-runtime";var O=W`
  mutation CreateTask($input: CreateTaskInput!) {
    createTask(input: $input) {
      id
      title
    }
  }
`;function F({categories:e}){let{projectId:d}=L(),[m,t]=y(""),[o,c]=y(""),[h,f]=y("MEDIUM"),[g,v]=y("none"),[w,C]=y(""),[r,{loading:x}]=B(O);return u("form",{onSubmit:async(l)=>{if(l.preventDefault(),!m.trim())return;await r({variables:{input:{projectId:d,title:m.trim(),description:o.trim()||void 0,priority:h,categoryId:g==="none"?void 0:g,tags:z(w)}},refetchQueries:["Tasks"],awaitRefetchQueries:!0}),t(""),c(""),f("MEDIUM"),v("none"),C("")},className:"space-y-3 rounded-2xl border border-border bg-background/60 p-4",children:[p("div",{children:u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Title",p("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:m,onChange:(l)=>t(l.target.value),required:!0})]})}),p("div",{children:u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Description",p("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:o,onChange:(l)=>c(l.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:(l)=>f(l.target.value),children:[p("option",{value:"LOW",children:"Low"}),p("option",{value:"MEDIUM",children:"Medium"}),p("option",{value:"HIGH",children:"High"}),p("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:(l)=>v(l.target.value),children:[p("option",{value:"none",children:"None"}),e.map((l)=>p("option",{value:l.id,children:l.name},l.id))]})]}),u("label",{className:"font-semibold text-muted-foreground text-xs uppercase",children:["Tags",p("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:(l)=>C(l.target.value)})]})]}),p("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((d)=>d.trim()).filter(Boolean)}import{Check as J,Circle as X,Trash2 as Z}from"lucide-react";import{jsx as n,jsxs as N}from"react/jsx-runtime";function $({task:e,onToggle:d,onDelete:m}){let t=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:[n("button",{type:"button",className:"rounded-full border border-border p-2 text-muted-foreground hover:bg-muted/40","aria-pressed":e.completed,onClick:()=>d?.(e),children:e.completed?n(J,{className:"h-4 w-4 text-emerald-400"}):n(X,{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:[n("p",{className:`font-medium ${e.completed?"text-muted-foreground line-through":"text-foreground"}`,children:e.title}),n("span",{className:`rounded-full border px-2 py-0.5 text-xs ${t}`,children:e.priority.charAt(0)+e.priority.slice(1).toLowerCase()}),e.category?n("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?n("p",{className:"text-muted-foreground text-sm",children:e.description}):null,e.tags.length?n("div",{className:"flex flex-wrap gap-1",children:e.tags.map((o)=>N("span",{className:"rounded-full bg-muted/40 px-2 py-0.5 text-muted-foreground text-xs",children:["#",o]},o))}):null]}),n("button",{type:"button",className:"text-muted-foreground hover:text-destructive","aria-label":`Delete ${e.title}`,onClick:()=>m?.(e),children:n(Z,{className:"h-4 w-4"})})]})}import{gql as H}from"@apollo/client";import{useMutation as G,useQuery as A}from"@apollo/client/react";import{registerTemplateComponents as M,useTemplateRuntime as S}from"@contractspec/lib.example-shared-ui";import{useMemo as K,useState as Y}from"react";import{jsx as i,jsxs as q}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
      }
    }
  }
`,Q=H`
  mutation ToggleTask($id: ID!, $completed: Boolean!) {
    toggleTask(id: $id, completed: $completed) {
      id
      completed
    }
  }
`,R=H`
  mutation DeleteTask($id: ID!) {
    deleteTask(id: $id)
  }
`;function V(){let{projectId:e}=S(),[d,m]=Y({status:"all",priority:"all",categoryId:"all",search:""}),{data:t,loading:o}=A(U,{variables:{projectId:e},fetchPolicy:"cache-and-network"}),[c]=G(Q),[h]=G(R),f=t?.taskCategories??[],g=t?.tasks??[],v=K(()=>{return g.filter((r)=>{if(d.status==="active"&&r.completed)return!1;if(d.status==="completed"&&!r.completed)return!1;if(d.priority!=="all"&&r.priority!==d.priority)return!1;if(d.categoryId!=="all"&&r.category?.id!==d.categoryId)return!1;if(d.search&&!r.title.toLowerCase().includes(d.search.toLowerCase()))return!1;return!0})},[g,d]),w=async(r)=>{await c({variables:{id:r.id,completed:!r.completed},optimisticResponse:{toggleTask:{__typename:"Task",id:r.id,completed:!r.completed}},update(x){x.modify({fields:{tasks(P=[]){return P.map((l)=>l.__ref?.endsWith(r.id)?{...l,completed:!r.completed}:l)}}})}})},C=async(r)=>{await h({variables:{id:r.id},refetchQueries:[{query:U,variables:{projectId:e}}]})};return q("div",{className:"space-y-6",children:[i(D,{value:d,onChange:m,categories:f}),i(F,{categories:f}),o?i("p",{className:"text-muted-foreground text-sm",children:"Loading tasks\u2026"}):v.length?i("div",{className:"space-y-3",children:v.map((r)=>i($,{task:r,onToggle:w,onDelete:C},r.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."})})]})}M("todos-app",{list:V,detail:V,form:F});export{V as TaskList,$ as TaskItem,F as TaskForm,D as FilterBar};
