1import{b3 as Q,aA as A,r as w,j as e,G as M,B as d,D as I,z as E,V as K,W as L,I as v,bl as J,J as u,s as p}from"./index-C9PaTxeY.js";import{u as U}from"./useQuery-BKfreEzO.js";import{u as y}from"./useMutation-Bwz_zz0r.js";import{T as V}from"./textarea-BksBAy63.js";import{B as W}from"./badge-CWWJwCyL.js";import{S as $,a as G,b as H,c as X,d as o}from"./select-BRNBj1w3.js";import{t as Y}from"./en-US-X9VuEd91.js";import{c as S}from"./constructNow-TFwE9SEJ.js";import{i as T}from"./isSameDay-DGi-X-ji.js";import{a as _}from"./addDays-Bmv5VM-E.js";import{P as Z}from"./plus-BOcrEea7.js";import{T as ee}from"./triangle-alert-C8RCvR3M.js";import{C as te}from"./clock-B10wcrFX.js";import{C as se}from"./calendar-fxSVUhzJ.js";import{C as ae}from"./circle-check-BmjgrkcN.js";import{T as re}from"./trash-2-Bi1Uqapa.js";import{f as h}from"./format-CkXf5DVw.js";import"./index-BdQq_4o_.js";import"./chevron-up-Cc5dQZ79.js";function g(r){return+Y(r)<Date.now()}function i(r){return T(r,S(r))}function N(r){return T(r,_(S(r),1))}const be=()=>{const{user:r}=Q(),j=A(),[l,b]=w.useState("pending"),[B,c]=w.useState(!1),[a,n]=w.useState({lead_email:"",lead_name:"",lead_source:"quiz",note:"",due_date:h(_(new Date,2),"yyyy-MM-dd")}),{data:m=[],isLoading:k}=U({queryKey:["follow-ups"],queryFn:async()=>{const{data:t,error:s}=await p.from("follow_up_reminders").select("*").order("due_date",{ascending:!0});if(s)throw s;return t}}),f=y({mutationFn:async()=>{const{error:t}=await p.from("follow_up_reminders").insert({lead_email:a.lead_email,lead_name:a.lead_name||null,lead_source:a.lead_source,note:a.note||null,due_date:a.due_date,created_by:r.email});if(t)throw t},onSuccess:()=>{j.invalidateQueries({queryKey:["follow-ups"]}),c(!1),n({lead_email:"",lead_name:"",lead_source:"quiz",note:"",due_date:h(_(new Date,2),"yyyy-MM-dd")}),u.success("Follow-up reminder created")},onError:()=>u.error("Failed to create reminder")}),F=y({mutationFn:async t=>{const{error:s}=await p.from("follow_up_reminders").update({status:"completed",completed_at:new Date().toISOString()}).eq("id",t);if(s)throw s},onSuccess:()=>{j.invalidateQueries({queryKey:["follow-ups"]}),u.success("Marked as completed")}}),q=y({mutationFn:async t=>{const{error:s}=await p.from("follow_up_reminders").delete().eq("id",t);if(s)throw s},onSuccess:()=>{j.invalidateQueries({queryKey:["follow-ups"]}),u.success("Reminder deleted")}}),C=m.filter(t=>l==="completed"?t.status==="completed":l==="overdue"?t.status==="pending"&&g(new Date(t.due_date))&&!i(new Date(t.due_date)):l==="pending"?t.status==="pending":!0),D=m.filter(t=>t.status==="pending"&&g(new Date(t.due_date))&&!i(new Date(t.due_date))).length,z=m.filter(t=>t.status==="pending"&&i(new Date(t.due_date))).length,O=m.filter(t=>t.status==="pending"&&N(new Date(t.due_date))).length,R=t=>{const s=new Date(t);return i(s)?"Today":N(s)?"Tomorrow":g(s)?"Overdue":h(s,"dd MMM yyyy")},P=(t,s)=>{if(s==="completed")return"bg-green-100 text-green-800";const x=new Date(t);return g(x)&&!i(x)?"bg-red-100 text-red-800":i(x)?"bg-orange-100 text-orange-800":N(x)?"bg-yellow-100 text-yellow-800":"bg-slate-100 text-slate-800"};return k?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(M,{className:"h-8 w-8 animate-spin text-[#9B1B4D]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-semibold text-slate-900",children:"Follow-up Reminders"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"Track leads that need follow-up action."})]}),e.jsxs(d,{onClick:()=>c(!0),className:"bg-[#9B1B4D] hover:bg-[#7d1640] text-white",children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),"New Reminder"]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[D>0&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-4 flex items-center gap-3 cursor-pointer",onClick:()=>b("overdue"),children:[e.jsx(ee,{className:"h-5 w-5 text-red-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold text-red-900",children:D}),e.jsx("p",{className:"text-xs text-red-600",children:"Overdue"})]})]}),e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-xl p-4 flex items-center gap-3",children:[e.jsx(te,{className:"h-5 w-5 text-orange-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold text-orange-900",children:z}),e.jsx("p",{className:"text-xs text-orange-600",children:"Due Today"})]})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4 flex items-center gap-3",children:[e.jsx(se,{className:"h-5 w-5 text-blue-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-lg font-semibold text-blue-900",children:O}),e.jsx("p",{className:"text-xs text-blue-600",children:"Due Tomorrow"})]})]})]}),e.jsx("div",{className:"flex gap-2",children:["pending","overdue","completed","all"].map(t=>e.jsx(d,{variant:l===t?"default":"outline",size:"sm",onClick:()=>b(t),className:l===t?"bg-[#9B1B4D] hover:bg-[#7d1640]":"",children:t.charAt(0).toUpperCase()+t.slice(1)},t))}),e.jsxs("div",{className:"space-y-2",children:[C.map(t=>e.jsxs("div",{className:`bg-white rounded-xl shadow-sm border p-4 flex items-start gap-4 ${t.status==="completed"?"opacity-60 border-slate-100":"border-slate-200"}`,children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"font-medium text-slate-900",children:t.lead_name||t.lead_email}),e.jsx(W,{variant:"outline",className:"text-xs",children:t.lead_source}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${P(t.due_date,t.status)}`,children:t.status==="completed"?"Completed":R(t.due_date)})]}),e.jsx("p",{className:"text-xs text-slate-500 mt-1",children:t.lead_email}),t.note&&e.jsx("p",{className:"text-sm text-slate-600 mt-2",children:t.note}),e.jsxs("p",{className:"text-xs text-slate-400 mt-1",children:["Created by ",t.created_by," · ",h(new Date(t.created_at),"dd MMM yyyy")]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[t.status==="pending"&&e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>F.mutate(t.id),title:"Mark completed",children:e.jsx(ae,{className:"h-4 w-4 text-green-600"})}),e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>q.mutate(t.id),title:"Delete",children:e.jsx(re,{className:"h-4 w-4 text-red-500"})})]})]},t.id)),C.length===0&&e.jsx("div",{className:"text-center py-12 text-slate-500",children:l==="overdue"?"No overdue reminders ð":"No follow-up reminders yet."})]}),e.jsx(I,{open:B,onOpenChange:c,children:e.jsxs(E,{children:[e.jsx(K,{children:e.jsx(L,{children:"New Follow-up Reminder"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-700",children:"Email *"}),e.jsx(v,{value:a.lead_email,onChange:t=>n(s=>({...s,lead_email:t.target.value})),placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-700",children:"Name"}),e.jsx(v,{value:a.lead_name,onChange:t=>n(s=>({...s,lead_name:t.target.value})),placeholder:"Jane Smith"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-700",children:"Source"}),e.jsxs($,{value:a.lead_source,onValueChange:t=>n(s=>({...s,lead_source:t})),children:[e.jsx(G,{children:e.jsx(H,{})}
1),e.jsxs(X,{children:[e.jsx(o,{value:"quiz",children:"Quiz Lead"}),e.jsx(o,{value:"programme_finder",children:"Programme Finder"}),e.jsx(o,{value:"message",children:"Contact Message"}),e.jsx(o,{value:"download",children:"Brochure Download"}),e.jsx(o,{value:"registration",children:"Registration"}),e.jsx(o,{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-700",children:"Due Date *"}),e.jsx(v,{type:"date",value:a.due_date,onChange:t=>n(s=>({...s,due_date:t.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-slate-700",children:"Note"}),e.jsx(V,{value:a.note,onChange:t=>n(s=>({...s,note:t.target.value})),placeholder:"What needs to be done...",rows:3})]})]}),e.jsxs(J,{children:[e.jsx(d,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(d,{onClick:()=>f.mutate(),disabled:!a.lead_email||!a.due_date||f.isPending,className:"bg-[#9B1B4D] hover:bg-[#7d1640]",children:f.isPending?e.jsx(M,{className:"h-4 w-4 animate-spin"}):"Create Reminder"})]})]})})]})};export{be 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.