1import{j as e,h as I,a8 as T,q as M,a1 as $,b3 as E,b as L,X as R}from"./chunk-CgdxW11o.js";import{r as o}from"./chunk-Dmsukp28.js";import{b as q,B as c,s as d}from"../assets/index-BrW_aWiG.js";import{I as j}from"./chunk-BWNQH_6X.js";import"./chunk-BqJbJ7gK.js";import"./chunk-0KF9c2-o.js";const u=a=>{const i=new Date(a+"T00:00:00").getTime()-Date.now();return Math.ceil(i/864e5)},v=(a,i)=>i==="met"?"text-muted-foreground/50 line-through":i==="dismissed"?"text-muted-foreground/40 line-through":a<0||a<=14?"text-destructive":a<=30?"text-amber-600 dark:text-amber-400":"text-foreground";function X({caseId:a}){const[i,k]=o.useState([]),[C,S]=o.useState(!0),[N,b]=o.useState(!1),[y,x]=o.useState(!1),[t,l]=o.useState({title:"",due_date:"",category:"procedural",citation:""}),{toast:w}=q(),m=async()=>{const{data:s}=await d.from("counsel_deadlines").select("*").eq("case_id",a).order("due_date");k(s||[]),S(!1)};o.useEffect(()=>{m()},[a]);const D=async()=>{b(!0);try{const{data:s,error:r}=await d.functions.invoke("counsel-detect-deadlines",{body:{case_id:a}});if(r)throw r;if(s?.error)throw new Error(s.error);const n=s;w({title:`${n.proposed} deadline${n.proposed===1?"":"s"} proposed`,description:n.notes||"Review and confirm each one."}),await m()}catch(s){w({title:"Detection failed",description:s.message,variant:"destructive"})}finally{b(!1)}},p=async(s,r)=>{const n={status:r};if(r==="confirmed"){const{data:{user:A}}=await d.auth.getUser();n.confirmed_by=A?.id,n.confirmed_at=new Date().toISOString()}await d.from("counsel_deadlines").update(n).eq("id",s),await m()},z=async()=>{!t.title||!t.due_date||(await d.from("counsel_deadlines").insert({case_id:a,title:t.title,due_date:t.due_date,category:t.category,citation:t.citation||null,source:"user",status:"confirmed",confirmed_at:new Date().toISOString()}),l({title:"",due_date:"",category:"procedural",citation:""}),x(!1),await m())};if(C)return e.jsx("div",{className:"text-xs uppercase tracking-[0.2em] text-muted-foreground animate-pulse",children:"Loading deadlinesâ¦"});const _=i.filter(s=>s.status==="proposed"),h=i.filter(s=>s.status==="confirmed"||s.status==="met"),g=i.filter(s=>s.status==="dismissed"),f=h.filter(s=>s.status==="confirmed"&&u(s.due_date)<=30);return e.jsxs("div",{className:"space-y-10",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-6 border-b border-border/20",children:[e.jsx("div",{children:f.length>0&&e.jsxs("div",{className:"inline-flex items-center gap-2 text-xs text-destructive",children:[e.jsx(I,{className:"w-3.5 h-3.5"}),e.jsxs("span",{className:"uppercase tracking-[0.15em]",children:[f.length," confirmed deadline",f.length===1?"":"s"," within 30 days"]})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>x(!y),className:"gap-2",children:[e.jsx(T,{className:"w-3.5 h-3.5"})," Add"]}),e.jsxs(c,{onClick:D,disabled:N,size:"sm",className:"gap-2",children:[N?e.jsx(M,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx($,{className:"w-3.5 h-3.5"}),"AI propose"]})]})]}),y&&e.jsxs("div",{className:"border border-border/40 p-4 space-y-3",children:[e.jsx(j,{placeholder:"Title (e.g., File complaint)",value:t.title,onChange:s=>l({...t,title:s.target.value})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(j,{type:"date",value:t.due_date,onChange:s=>l({...t,due_date:s.target.value})}),e.jsxs("select",{value:t.category,onChange:s=>l({...t,category:s.target.value}),className:"bg-background border border-border/40 px-3 text-sm",children:[e.jsx("option",{value:"statute_of_limitations",children:"Statute of limitations"}),e.jsx("option",{value:"filing",children:"Filing"}),e.jsx("option",{value:"response",children:"Response"}),e.jsx("option",{value:"discovery",children:"Discovery"}),e.jsx("option",{value:"procedural",children:"Procedural"}),e.jsx("option",{value:"contractual",children:"Contractual"})]})]}),e.jsx(j,{placeholder:"Citation (optional)",value:t.citation,onChange:s=>l({...t,citation:s.target.value})}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>x(!1),children:"Cancel"}),e.jsx(c,{size:"sm",onClick:z,children:"Add"})]})]}),i.length===0&&e.jsxs("div",{className:"text-center py-20 border border-dashed border-border/40",children:[e.jsx(E,{className:"w-8 h-8 mx-auto text-muted-foreground
1/40 mb-4",strokeWidth:1.2}),e.jsx("p",{className:"editorial-body text-muted-foreground max-w-md mx-auto",children:"Missed deadlines kill cases. Let Counsel scan your intake and evidence to propose statute-of-limitations and procedural deadlines for your jurisdiction. You confirm each one before it goes on the calendar."})]}),_.length>0&&e.jsxs("section",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground mb-4",children:"Proposed by AI · review and confirm"}),e.jsx("div",{className:"space-y-3",children:_.map(s=>e.jsxs("div",{className:"border-l-2 border-amber-500/40 bg-amber-500/5 pl-4 pr-3 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4 mb-1",children:[e.jsx("p",{className:"text-sm font-medium",children:s.title}),e.jsxs("p",{className:`text-xs font-mono tabular-nums ${v(u(s.due_date),s.status)}`,children:[s.due_date," ",e.jsxs("span",{className:"opacity-60",children:["(",u(s.due_date),"d)"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] uppercase tracking-[0.15em] text-muted-foreground/70 mb-2",children:[e.jsx("span",{children:s.category.replace(/_/g," ")}),s.jurisdiction&&e.jsxs("span",{children:["· ",s.jurisdiction]}),s.citation&&e.jsxs("span",{className:"font-mono normal-case tracking-normal",children:["· ",s.citation]})]}),s.ai_rationale&&e.jsx("p",{className:"text-xs text-muted-foreground italic mb-3",children:s.ai_rationale}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{size:"sm",variant:"outline",onClick:()=>p(s.id,"confirmed"),className:"gap-1.5 h-7 text-xs",children:[e.jsx(L,{className:"w-3 h-3"})," Confirm"]}),e.jsxs(c,{size:"sm",variant:"ghost",onClick:()=>p(s.id,"dismissed"),className:"gap-1.5 h-7 text-xs text-muted-foreground",children:[e.jsx(R,{className:"w-3 h-3"})," Dismiss"]})]})]},s.id))})]}),h.length>0&&e.jsxs("section",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-[0.3em] text-muted-foreground mb-4",children:"Calendar"}),e.jsx("div",{className:"divide-y divide-border/20",children:h.map(s=>{const r=u(s.due_date);return e.jsxs("div",{className:"py-3 flex flex-col sm:flex-row sm:items-baseline justify-between gap-2 sm:gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-sm ${v(r,s.status)}`,children:s.title}),e.jsxs("p",{className:"text-[10px] uppercase tracking-[0.15em] text-muted-foreground/60 mt-0.5",children:[s.category.replace(/_/g," "),s.citation&&e.jsxs("span",{className:"font-mono normal-case tracking-normal ml-2",children:["· ",s.citation]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsxs("p",{className:`text-xs font-mono tabular-nums ${v(r,s.status)}`,children:[s.due_date," ",s.status==="confirmed"&&e.jsxs("span",{className:"opacity-60",children:["(",r,"d)"]})]}),s.status==="confirmed"&&e.jsx("button",{onClick:()=>p(s.id,"met"),className:"text-[10px] uppercase tracking-[0.2em] text-muted-foreground hover:text-foreground",children:"Mark met"})]})]},s.id)})})]}),g.length>0&&e.jsxs("details",{className:"text-xs",children:[e.jsxs("summary",{className:"text-[10px] uppercase tracking-[0.25em] text-muted-foreground/60 cursor-pointer",children:["Dismissed (",g.length,")"]}),e.jsx("ul",{className:"mt-3 space-y-1",children:g.map(s=>e.jsxs("li",{className:"text-muted-foreground/50",children:[s.title," · ",s.due_date]},s.id))})]})]})}export{X as DeadlinesModule};
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.