1import{r as o,j as e,s as w,t as b}from"./index-DTEDcl9R.js";import{L as V,a as z}from"./list-BU4mwMCl.js";import{P as H}from"./plus-DKFCQNa_.js";import{S as R}from"./search-1Cclu_kb.js";import{L as $}from"./loader-circle-7g8dRLIH.js";import{M as U}from"./map-pin-DWV9aSL6.js";import{C as W}from"./calendar-B570_M8-.js";import{F as T}from"./folder-open-BxBPewRR.js";import{c as X}from"./createLucideIcon-DsPU5l8i.js";import{X as M}from"./x-Cr1eufIp.js";import{E as K}from"./external-link-ClAwynlk.js";const Q=[["path",{d:"M10 16c.5.3 1.2.5 2 .5s1.5-.2 2-.5",key:"1u7htd"}],["path",{d:"M15 12h.01",key:"1k8ypt"}],["path",{d:"M19.38 6.813A9 9 0 0 1 20.8 10.2a2 2 0 0 1 0 3.6 9 9 0 0 1-17.6 0 2 2 0 0 1 0-3.6A9 9 0 0 1 12 3c2 0 3.5 1.1 3.5 2.5s-.9 2.5-2 2.5c-.8 0-1.5-.4-1.5-1",key:"11xh7x"}],["path",{d:"M9 12h.01",key:"157uk2"}]],Y=X("baby",Q),Z="/assets/child-boy-AWILyB4y.png",ee="/assets/child-girl-DSzaPLps.png",L=s=>{const n=(s??"").toLowerCase();return n.includes("he")||n.includes("him")?"boy":n.includes("she")||n.includes("her")?"girl":"neutral"};function A({gender:s,size:n="md"}){const d=n==="lg"?"h-20 w-20":n==="sm"?"h-9 w-9":"h-14 w-14",a=s==="boy"?"ring-sage/30":s==="girl"?"ring-maroon/30":"ring-foreground/15";if(s==="neutral")return e.jsx("div",{className:`${d} bg-accent text-foreground ring-2 ${a} rounded-full flex items-center justify-center shrink-0`,children:e.jsx(Y,{className:n==="lg"?"h-10 w-10":n==="sm"?"h-5 w-5":"h-7 w-7",strokeWidth:2.2})});const l=s==="boy"?Z:ee;return e.jsx("img",{src:l,alt:s==="boy"?"Boy avatar":"Girl avatar",className:`${d} rounded-full object-cover ring-2 ${a} shrink-0 bg-sage-soft`})}const G=["Intake","Active","On Hold","Discharged"];function pe(){const[s,n]=o.useState([]),[d,a]=o.useState(!0),[l,f]=o.useState(""),[p,v]=o.useState("All"),[g,i]=o.useState(null),[N,C]=o.useState(null),[S,t]=o.useState(!1),[c,x]=o.useState(()=>typeof window>"u"?"cards":localStorage.getItem("clientsView")||"cards");o.useEffect(()=>{try{localStorage.setItem("clientsView",c)}catch{}},[c]);const _=r=>{i(r);try{r?localStorage.setItem("clientsOpen",JSON.stringify({mode:"profile",id:r.id})):localStorage.removeItem("clientsOpen")}catch{}},k=r=>{C(r);try{r?localStorage.setItem("clientsOpen",JSON.stringify({mode:"edit",id:r.id})):g||localStorage.removeItem("clientsOpen")}catch{}},O=async()=>{a(!0);const{data:r,error:m}=await w.from("clients").select("*").order("created_at",{ascending:!1});m&&b.error(m.message);const y=r??[];n(y),a(!1);try{const D=localStorage.getItem("clientsOpen");if(D){const{mode:q,id:B}=JSON.parse(D),I=y.find(J=>J.id===B);I&&(q==="edit"?C(I):i(I))}}catch{}};o.useEffect(()=>{O()},[]);const P=s.filter(r=>{if(p!=="All"&&r.status!==p)return!1;if(!l)return!0;const m=l.toLowerCase();return r.parent_name.toLowerCase().includes(m)||(r.child_initials?.toLowerCase().includes(m)??!1)||(r.parent_email?.toLowerCase().includes(m)??!1)});return e.jsxs("div",{className:"space-y-6 max-w-7xl",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl font-extrabold tracking-tight",children:"Active Clients"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Manage families currently receiving services."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"inline-flex items-center rounded-full border border-input bg-white p-0.5",children:[e.jsxs("button",{onClick:()=>x("cards"),className:`inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-semibold transition-colors ${c==="cards"?"bg-foreground text-primary-foreground":"text-foreground/70 hover:bg-muted"}`,children:[e.jsx(V,{className:"h-3.5 w-3.5"})," Cards"]}),e.jsxs("button",{onClick:()=>x("table"),className:`inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-semibold transition-colors ${c==="table"?"bg-foreground text-primary-foreground":"text-foreground/70 hover:bg-muted"}`,children:[e.jsx(z,{className:"h-3.5 w-3.5"})," Table"]})]}),e.jsxs("button",{onClick:()=>t(!0),className:"inline-flex items-center gap-2 rounded-full bg-sage text-primary-foreground px-5 py-2.5 text-sm font-semibold hover:bg-foreground transition-colors",children:[e.jsx(H,{className:"h-4 w-4"})," Add Client"]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[e.jsx(R,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}
1),e.jsx("input",{value:l,onChange:r=>f(r.target.value),placeholder:"Search by parent, initials, emailâ¦",className:"w-full rounded-xl border border-input bg-white pl-10 pr-3 py-2.5 text-sm"})]}),e.jsxs("select",{value:p,onChange:r=>v(r.target.value),className:"rounded-xl border border-input bg-white px-3 py-2.5 text-sm",children:[e.jsx("option",{children:"All"}),G.map(r=>e.jsx("option",{children:r},r))]})]}),d?e.jsx("div",{className:"rounded-2xl bg-white border border-border p-10 flex justify-center",children:e.jsx($,{className:"h-6 w-6 animate-spin text-sage"})}):P.length===0?e.jsx("div",{className:"rounded-2xl bg-white border border-border p-10 text-center text-sm text-muted-foreground",children:"No clients yet."}):c==="cards"?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:P.map(r=>{const m=L(r.child_pronouns);return e.jsxs("button",{onClick:()=>_(r),className:"group text-left rounded-2xl bg-white border border-border p-5 hover:shadow-md hover:border-foreground/20 transition-all",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(A,{gender:m}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"font-display text-lg font-extrabold truncate",children:r.child_initials||"â"}),e.jsx(E,{status:r.status})]}),e.jsx("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:r.parent_name}),r.city&&e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1 inline-flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3"})," ",r.city]})]})]}),r.services&&r.services.length>0&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1",children:[r.services.slice(0,3).map(y=>e.jsx("span",{className:"inline-flex rounded-full bg-cream text-foreground/80 px-2 py-0.5 text-[10px] font-semibold",children:y},y)),r.services.length>3&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",r.services.length-3]})]}),e.jsxs("div",{className:"mt-3 pt-3 border-t border-border/60 flex items-center justify-between text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"truncate",children:r.insurance??"No insurance"}),r.start_date&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(W,{className:"h-3 w-3"})," ",new Date(r.start_date).toLocaleDateString()]})]})]},r.id)})}):e.jsx("div",{className:"rounded-2xl bg-white border border-border overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-cream text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Child"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Parent"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Services"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Status"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Insurance"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"City"}),e.jsx("th",{className:"px-4 py-3 font-semibold",children:"Folder"})]})}),e.jsx("tbody",{children:P.map(r=>e.jsxs("tr",{onClick:()=>_(r),className:"border-t border-border cursor-pointer hover:bg-cream/50",children:[e.jsx("td",{className:"px-4 py-3 font-medium",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(A,{gender:L(r.child_pronouns),size:"sm"}),e.jsx("div",{className:"font-semibold",children:r.child_initials??"â"})]})}),e.jsxs("td",{className:"px-4 py-3",children:[r.parent_name,e.jsx("div",{className:"text-xs text-muted-foreground",children:r.parent_email})]}),e.jsx("td",{className:"px-4 py-3 text-xs",children:r.services?.join(", ")??"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(E,{status:r.status})}),e.jsx("td",{className:"px-4 py-3 text-xs",children:r.insurance??"â"}),e.jsx("td",{className:"px-4 py-3 text-xs",children:r.city??"â"}),e.jsx("td",{className:"px-4 py-3 text-xs",onClick:m=>m.stopPropagation(),children:r.folder_url?e.jsxs("a",{href:r.folder_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-sage hover:underline",children:[e.jsx(T,{className:"h-3.5 w-3.5"})," Open"]}):"â"})]},r.id))})]})})}),g&&!N&&e.jsx(se,{client:g,onClose:()=>_(null),onEdit:()=>{k(g)}}),(N||S)&&e.jsx(te,{client:N,onClose:()=>{k(null),t(!1)},onSaved:()=>{k(null),t(!1),_(null),O()}})]})}function se({client:s,onClose:n,onEdit:d}){const a=L(s.child_pronouns);return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex justify-end",onClick:n,children:e.jsxs("div",{onClick:l=>l.stopPropagation(),className:"w-full max-w-2xl bg-white h-full overflow-y-auto",children:[e.jsxs("div",{className:"p-6 border-b border-border bg-cream/40",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(A,{gender:a,size:"lg"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-display text-2xl font-extrabold",children:s.child_initials||"â"}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.parent_name," · Parent / Guardian"]}),e.jsx("div",{className:"mt-2",children:e.jsx(E,{status:s.status})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:d,className:"rounded-full bg-foreground text-primary-foreground px-4 py-2 text-xs font-semibold",children:"Edit"}),e.jsx("button",{onClick:n,children:e.jsx(M,{className:"h-5 w-5"})})]})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-2",children:[s.parent_phone&&e.jsxs("a",{href:`tel:${s.parent_phone}`,className:"inline-flex items-center justify-center gap-2 rounded-full bg-white border border-input px-4 py-2 text-sm font-semibold",children:["ð ",s.parent_phone]}),s.parent_email&&e.jsxs("a",{href:`mailto:${s.parent_email}`,className:"inline-flex items-center justify-center gap-2 rounded-full bg-white border border-input px-4 py-2 text-sm font-semibold truncate",children:["â ",s.parent_email]})]}),s.folder_url&&e.jsxs("a",{href:s.folder_url,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex items-center gap-2 rounded-full bg-sage text-primary-foreground px-4 py-2 text-sm font-semibold",children:[e.jsx(T,{className:"h-4 w-4"})," Open Client Folder ",e.jsx(K,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsx(j,{title:"Child",children:e.jsx(h,{label:"Initials",value:s.child_initials})}),e.jsxs(j,{title:"Services",children:[e.jsx(h,{label:"Services",value:s.services?.join(", ")??null}),e.jsx(h,{label:"Start date",value:s.start_date?new Date(s.start_date).toLocaleDateString():null})]}),e.jsx(j,{title:"Insurance",children:e.jsx(h,{label:"Provider",value:s.insurance})}),e.jsx(j,{title:"Location",children:e.jsx(h,{label:"City",value:s.city})}
1),e.jsxs(j,{title:"Transportation",children:[e.jsx(h,{label:"Company",value:s.transportation_company}),e.jsx(h,{label:"Phone",value:s.transportation_phone}),s.transportation_notifications&&e.jsxs("div",{className:"pt-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Notifications & Notes"}),e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:s.transportation_notifications})]})]}),s.notes&&e.jsx(j,{title:"Notes",children:e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:s.notes})})]})]})})}function j({title:s,children:n}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-2",children:s}),e.jsx("div",{className:"rounded-2xl border border-border bg-cream/30 p-4 space-y-2",children:n})]})}function h({label:s,value:n}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:s}),e.jsx("span",{className:"font-medium text-right",children:n||e.jsx("span",{className:"text-muted-foreground",children:"â"})})]})}function E({status:s}){const n=s==="Active"?"bg-sage-soft text-sage":s==="Intake"?"bg-accent text-foreground":s==="On Hold"?"bg-maroon-soft text-maroon":"bg-muted text-foreground/70";return e.jsx("span",{className:`inline-flex rounded-full px-2.5 py-1 text-xs font-semibold ${n}`,children:s})}function te({client:s,onClose:n,onSaved:d}){const[a,l]=o.useState(s??{status:"Intake"}
1),[f,p]=o.useState(!1),[v,g]=o.useState([]);o.useEffect(()=>{w.from("transportation_companies").select("id,name,phone").order("name").then(({data:t})=>{g(t??[])})},[]);const i=(t,c)=>l(x=>({...x,[t]:c})),N=t=>{const c=v.find(x=>x.name===t);l(x=>({...x,transportation_company:t||null,transportation_phone:c?.phone??x.transportation_phone??null}))},C=async()=>{if(!a.parent_name){b.error("Parent name is required");return}p(!0);const t={...a,services:typeof a.services=="string"?a.services.split(",").map(x=>x.trim()).filter(Boolean):a.services},c=s?await w.from("clients").update(t).eq("id",s.id):await w.from("clients").insert(t);if(p(!1),c.error){b.error(c.error.message);return}b.success(s?"Client updated":"Client added"),d()},S=async()=>{if(!s||!confirm("Delete this client? This cannot be undone."))return;const{error:t}=await w.from("clients").delete().eq("id",s.id);if(t){b.error(t.message);return}b.success("Client deleted"),d()};return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex justify-end",onClick:n,children:e.jsxs("div",{onClick:t=>t.stopPropagation(),className:"w-full max-w-xl bg-white h-full overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"font-display text-2xl font-extrabold",children:s?"Edit Client":"Add Client"}),e.jsx("button",{onClick:n,children:e.jsx(M,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsx(u,{label:"Parent / Guardian Name",required:!0,value:a.parent_name??"",onChange:t=>i("parent_name",t)}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(u,{label:"Parent Email",value:a.parent_email??"",onChange:t=>i("parent_email",t),type:"email"}),e.jsx(u,{label:"Parent Phone",value:a.parent_phone??"",onChange:t=>i("parent_phone",t)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(u,{label:"Child Initials",value:a.child_initials??"",onChange:t=>i("child_initials",t)}),e.jsx(F,{label:"Child Gender",value:a.child_pronouns??"",options:["","he/him","she/her"],onChange:t=>i("child_pronouns",t)})]}),e.jsx(u,{label:"Services (comma separated)",value:Array.isArray(a.services)?a.services.join(", "):a.services??"",onChange:t=>i("services",t)}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(F,{label:"Status",value:a.status??"Intake",options:G,onChange:t=>i("status",t)}),e.jsx(u,{label:"Insurance",value:a.insurance??"",onChange:t=>i("insurance",t)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(u,{label:"City",value:a.city??"",onChange:t=>i("city",t)}),e.jsx(u,{label:"Start Date",value:a.start_date??"",onChange:t=>i("start_date",t),type:"date"})]}),e.jsx(u,{label:"Client Folder URL",value:a.folder_url??"",onChange:t=>i("folder_url",t),placeholder:"https://drive.google.com/â¦"}),e.jsxs("div",{className:"pt-2 border-t border-border",children:[e.jsx("div",{className:"text-xs font-bold uppercase tracking-wider text-muted-foreground mb-3 mt-2",children:"Transportation"}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Transport Company"}),e.jsxs("select",{value:a.transportation_company??"",onChange:t=>N(t.target.value),className:"mt-1.5 w-full rounded-xl border border-input bg-white px-3 py-2 text-sm",children:[e.jsx("option",{value:"",children:"â Select â"}),v.map(t=>e.jsx("option",{value:t.name,children:t.name},t.id)),a.transportation_company&&!v.some(t=>t.name===a.transportation_company)&&e.jsx("option",{value:a.transportation_company,children:a.transportation_company})]})]}),e.jsx(u,{label:"Transport Phone",value:a.transportation_phone??"",onChange:t=>i("transportation_phone",t)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Notifications & Notes"}),e.jsx("textarea",{value:a.transportation_notifications??"",onChange:t=>i("transportation_notifications",t.target.value),rows:3,placeholder:"Pickup details, special instructions, alertsâ¦",className:"mt-1.5 w-full rounded-xl border border-input bg-white px-3 py-2 text-sm"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Internal notes"}),e.jsx("textarea",{value:a.notes??"",onChange:t=>i("notes",t.target.value),rows:4,className:"mt-1.5 w-full rounded-xl border border-input bg-white px-3 py-2 text-sm"})]})]}),e.jsxs("div",{className:"mt-6 flex items-center justify-between gap-3",children:[s&&e.jsx("button",{onClick:S,className:"text-sm text-maroon hover:underline",children:"Delete"}),e.jsxs("div",{className:"ml-auto flex gap-2",children:[e.jsx("button",{onClick:n,className:"rounded-full px-4 py-2 text-sm border border-input",children:"Cancel"}),e.jsxs("button",{onClick:C,disabled:f,className:"inline-flex items-center gap-2 rounded-full bg-sage text-primary-foreground px-5 py-2 text-sm font-semibold disabled:opacity-70",children:[f&&e.jsx($,{className:"h-4 w-4 animate-spin"})," Save"]})]})]})]})})}function u({label:s,value:n,onChange:d,type:a,required:l,placeholder:f}){return e.jsxs("div",{children:[e.jsxs("label",{className:"text-sm font-medium",children:[s,l&&" *"]}),e.jsx("input",{type:a??"text",value:n,onChange:p=>d(p.target.value),placeholder:f,className:"mt-1.5 w-full rounded-xl border border-input bg-white px-3 py-2 text-sm"})]})}function F({label:s,value:n,options:d,onChange:a}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:s}),e.jsx("select",{value:n,onChange:l=>a(l.target.value),className:"mt-1.5 w-full rounded-xl border border-input bg-white px-3 py-2 text-sm",children:d.map(l
1=>e.jsx("option",{children:l},l))})]})}export{pe as component};
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.