1import{j as e,bB as Q,bp as Pe,bc as re,L as W,ag as X,u as E,bk as os,x as qe,ay as Te,au as le,X as Ps,cV as ds,c9 as Ds,v as ms,s as xs,dA as us,cR as Fs,cS as Rs,cF as zs,d4 as Ks,dr as Ls,a$ as $s,cT as hs,dB as Qe,Q as Os,d3 as Ge,T as Ee,cJ as Hs,dC as _s,aZ as ps,dD as Ws,aj as qs,dE as gs,z as Gs,bA as Bs,dF as Is,bd as Us}from"./vendor-ui-fc56ca80.js";import{r as x,e as he,i as Vs}from"./vendor-react-f9ccc48d.js";import{am as V,B as C,t as O,S as ie,o as ce,p as oe,q as de,r as Z,a1 as pe,aZ as ge,a2 as je,a3 as fe,a4 as Ne,a5 as ye,a6 as be,a7 as we,a8 as ve,K as De,aI as Be,M as Fe,N as Re,O as ze,Q as Ke,z as G,T as js,I,n as Le,az as $e,h as fs,ae as Ys,ag as Qs,ah as Xs,ai as xe}from"./index-90016d22.js";import{u as Js}from"./useCapability-421f7f8b.js";import{d as Zs,e as et,u as Me,s as st,f as Xe,v as Je,g as tt,h as Ze,i as Ce,p as at,D as Oe,j as Ns,k as nt,m as rt,n as lt,o as it,q as ct,r as ot,t as dt,w as mt,x as xt,y as ut,z as es,A as Ie,B as ht,C as pt,E as gt,F as jt,G as ys,H as ss,I as ft,J as He,K as Nt,L as yt,M as bt,N as ts,O as wt,P as vt,Q as kt,R as St,S as Ct,T as At,U as Tt,V as Et,W as as,X as Mt,Y as Pt}from"./counselingService-1621b37c.js";import{a as bs,s as ns,A as Dt,T as Ft,g as Rt,c as zt,t as Kt,C as Lt,b as ws,d as $t,e as Ot,f as Ht,R as rs,h as _t,j as Wt,k as qt,G as Gt,p as We,l as Bt}from"./counseling-c919741d.js";import{N as It,S as vs,a as ks}from"./RichEditor-c68f661f.js";import{c as Ut}from"./coerce-b1c83b65.js";import{u as K,L as Y,f as q}from"./vendor-utils-323b9898.js";import{E as J,D as Ss}from"./consentDefaults-ffeae16f.js";/* empty css */import{H as Vt,a as Yt}from"./HelpContent-45f5b35c.js";import{S as Qt,a as Xt,b as Jt,c as Zt}from"./sheet-4e135f28.js";import{t as ls}from"./civil-5f5e63de.js";import{P as ea,I as sa,d as ta}from"./intakeSections-fa0b4e53.js";import"./vendor-firebase-a557f106.js";import"./vendor-charts-9af8b7c0.js";import"./index-341e5179.js";const aa=4,na=1,ra=3,la=t=>{if(t.length===0)return 0;const s=[...t].sort((r,n)=>r-n),a=Math.floor(s.length/2);return s.length%2===0?(s[a-1]+s[a])/2:s[a]};function ia(t){if(t.length<aa)return{pattern:"unknown",entries:t.length,medianLagDays:0,sittings:t.length};const s=t.map(p=>{const g=ls(ca(p.createdAt));return Math.max(0,g-ls(p.date))}),a=t.map(p=>p.createdAt.getTime()).sort((p,g)=>p-g),r=ra*60*60*1e3;let n=1;for(let p=1;p<a.length;p++)a[p]-a[p-1]>r&&n++;const l=la(s),i=t.length/n;let h;return l<=na&&i<2?h="steady":i>=3||l>=4?h="last-minute":h="irregular",{pattern:h,entries:t.length,medianLagDays:l,sittings:n}}function ca(t){const s=t.getFullYear(),a=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${s}-${a}-${r}`}const oa="text",da=({churchId:t,caseId:s,assignmentId:a})=>{var m;const{t:r,i18n:n}=K("counseling"),l=(m=n.language)!=null&&m.startsWith("en")?Y:V,[i,h]=x.useState(!1),[p,g]=x.useState(!1),[y,d]=x.useState(null),A=async()=>{g(!0);try{d(await et(t,s,a))}catch(f){console.error("[entries]",f),E.error(r("common.loadError"))}finally{g(!1)}},k=()=>{const f=!i;h(f),f&&y===null&&A()},o=async f=>{try{await Zs(f),d(u=>(u==null?void 0:u.filter(N=>N.id!==f))??null)}catch(u){console.error(u),E.error(r("entry.deleteError"))}},b=f=>{var c;const u=Ut(f);if(!u)return f;const[N,P,w]=u.split("-").map(Number);return q(new Date(N,P-1,w),(c=n.language)!=null&&c.startsWith("en")?"MMM d":"d 'de' MMM",{locale:l})};return e.jsxs("div",{className:"mt-2",children:[e.jsxs("button",{type:"button",onClick:k,className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground",children:[i?e.jsx(Q,{className:"h-3.5 w-3.5"}):e.jsx(Pe,{className:"h-3.5 w-3.5"}),e.jsx(re,{className:"h-3.5 w-3.5"}),y===null?r("entry.show"):r("entry.count",{count:y.length})]}),i&&e.jsx("div",{className:"mt-1.5 pl-5",children:p?e.jsx(W,{className:"h-4 w-4 animate-spin text-muted-foreground"}):!y||y.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:r("entry.empty")}):e.jsx("ul",{className:"space-y-2",children:y.map(f=>e.jsxs("li",{className:"rounded-md bg-muted/60 p-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:b(f.date)}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-6 w-6 flex-shrink-0 text-muted-foreground",title:r("entry.delete"),onClick:()=>o(f.id),children:e.jsx(X,{className:"h-3 w-3"})})]}),Object.entries(f.values).map(([u,N])=>e.jsxs("p",{className:"text-xs mt-0.5",children:[u!==oa&&e.jsxs("span",{className:"text-muted-foreground",children:[u,": "]}),e.jsx("span",{className:"whitespace-pre-wrap",children:N})]},u))]},f.id))})})]})},ne=({caseId:t,doc:s,assignmentId:a,label:r=!0})=>{const{t:n}=K("counseling"),l=he(),i=()=>{const h=a?`?tarea=${a}`:"";l(`/app/consejeria/${t}/imprimir/${s}${h}`)};return e.jsxs(C,{variant:"ghost",size:"sm",className:r?"h-8 gap-1.5 text-muted-foreground":"h-8 w-8 p-0 text-muted-foreground",onClick:i,title:n("print.openHint"),children:[e.jsx(os,{className:"h-3.5 w-3.5"}),r&&e.jsx("span",{className:"hidden sm:inline",children:n("print.paper")})]})},ma=({churchId:t,caseId:s,topic:a,subjects:r,assignments:n,isClosed:l,onCreated:i,onStatus:h,onReview:p,onRecited:g,onDelete:y})=>{const{t:d,i18n:A}=K("counseling"),k=A.language.startsWith("en"),o=k?Y:V,b=k?"MMM d, yyyy":"d 'de' MMM yyyy";return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1",children:[e.jsx("h3",{className:"text-sm font-medium",children:d("assignment.title")}),t&&s&&e.jsx(It,{churchId:t,caseId:s,topic:a,subjects:r,onCreated:i})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:d("assignment.hint")}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:d("assignment.empty")}):e.jsx("ul",{className:"space-y-3",children:n.map(m=>{var u,N,P,w,c;const f=bs(m.status);return e.jsx("li",{className:"border-b border-border last:border-0 pb-3 last:pb-0",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"text-sm font-medium",children:m.title}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${f.badgeClass}`,children:d(f.labelKey)}),m.visibleToSubject&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded-full bg-muted text-muted-foreground",title:d("subject.visibleBadge"),children:[e.jsx(qe,{className:"h-3 w-3"}),d("subject.visibleBadge")]})]}
1),m.instructions&&e.jsx("p",{className:"text-sm text-foreground/90 whitespace-pre-wrap mt-1",children:m.instructions}),m.scriptureRefs&&m.scriptureRefs.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 inline-flex items-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"}),m.scriptureRefs.join(" · ")]}),ns(m.structure).length>0&&e.jsx("ul",{className:"mt-1.5 space-y-0.5",children:ns(m.structure).map((v,j)=>e.jsxs("li",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"text-foreground/70",children:d(v.labelKey)}),v.value!==void 0&&`: ${v.value}`]},j))}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[d("assignment.assignedOn",{date:q(m.assignedAt,b,{locale:o})}),m.dueAt&&` · ${d("assignment.dueOn",{date:q(m.dueAt,b,{locale:o})})}`]}),m.type==="memorization"&&e.jsx("div",{className:"mt-1.5",children:(N=(u=m.structure)==null?void 0:u.memorization)!=null&&N.recitedAt?e.jsxs("button",{type:"button",disabled:l,onClick:()=>g(m,void 0),className:"text-xs text-emerald-700 dark:text-emerald-300 inline-flex items-center gap-1 disabled:opacity-60",children:[e.jsx(Te,{className:"h-3.5 w-3.5"}),d("structure.recitedOn",{date:q(m.structure.memorization.recitedAt,b,{locale:o})})]}):e.jsxs(C,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",disabled:l,onClick:()=>g(m,new Date),children:[e.jsx(Te,{className:"h-3.5 w-3.5"}),d("structure.markRecited")]})}),t&&s&&((c=(w=(P=m.structure)==null?void 0:P.log)==null?void 0:w.columns)!=null&&c.length)?e.jsx(da,{churchId:t,caseId:s,assignmentId:m.id}):null,m.subjectResponse&&e.jsxs("div",{className:"mt-2 rounded-md bg-muted/60 p-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:d("subject.response")}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:m.subjectResponse})]}),e.jsxs("div",{className:"mt-2",children:[e.jsxs("p",{className:"text-xs font-medium text-muted-foreground",children:[d("assignment.review"),m.reviewedAt&&e.jsxs("span",{className:"font-normal",children:[" · ",q(m.reviewedAt,b,{locale:o})]})]}),e.jsx("div",{className:"mt-1",children:e.jsx(J,{value:m.review??"",onChange:v=>p(m,v),placeholder:d("assignment.reviewPlaceholder"),"aria-label":d("assignment.review"),minLines:2,className:"text-sm"})})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[s&&e.jsx(ne,{caseId:s,doc:"tarea",assignmentId:m.id,label:!1}),e.jsxs(ie,{value:m.status,onValueChange:v=>h(m.id,v),children:[e.jsx(ce,{className:"w-[140px] h-8 text-xs",children:e.jsx(oe,{})}),e.jsx(de,{children:Dt.map(v=>e.jsx(Z,{value:v.value,children:d(v.labelKey)},v.value))})]}),e.jsxs(pe,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",children:e.jsx(X,{className:"h-3.5 w-3.5"})})}),e.jsxs(je,{children:[e.jsxs(fe,{children:[e.jsx(Ne,{children:d("assignment.deleteTitle")}),e.jsx(ye,{children:d("session.deleteDesc")})]}),e.jsxs(be,{children:[e.jsx(we,{children:d("common.cancel")}),e.jsx(ve,{onClick:()=>y(m.id),children:d("common.delete")})]})]})]})]})]})},m.id)})})]})},ae=({html:t})=>/<[a-z][\s\S]*>/i.test(t)?e.jsx("dd",{className:"counseling-rich",dangerouslySetInnerHTML:{__html:t}}):e.jsx("dd",{className:"whitespace-pre-wrap",children:t}),xa=({caseId:t,sessions:s,consentBlocks:a,isClosed:r,onDelete:n})=>{const{t:l,i18n:i}=K("counseling"),h=he(),p=i.language.startsWith("en"),g=p?Y:V,y=p?"MMM d, yyyy":"d 'de' MMM yyyy";return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3",children:[e.jsxs("h3",{className:"text-sm font-medium",children:[l("session.title"),e.jsxs("span",{className:"text-muted-foreground font-normal",children:[" · ",l("case.sessionsCount",{count:s.length})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[t&&e.jsx(ne,{caseId:t,doc:"bosquejo"}),t&&e.jsxs(C,{size:"sm",variant:s.length?"outline":"default",onClick:()=>h(`/app/consejeria/${t}/sesion`),disabled:a||r,title:r?l("case.closedHint"):a?l("consent.blocked"):void 0,children:[e.jsx(le,{className:"h-4 w-4 mr-1.5"}),l("session.new")]})]})]}),s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:l("session.empty")}):e.jsx("ul",{children:s.map((d,A)=>e.jsxs("li",{className:"session-entry",children:[e.jsx("span",{"aria-hidden":!0,
1className:"session-number text-xs text-muted-foreground",children:s.length-A}),e.jsx("span",{"aria-hidden":!0,className:"session-rules"}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsxs("p",{className:"text-sm font-medium",children:[d.kind==="first"&&e.jsx("span",{className:"mr-2 text-xs px-2 py-0.5 rounded-full font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300",children:l("session.kind.first")}),q(d.occurredAt,y,{locale:g}),d.counselorName&&e.jsxs("span",{className:"text-muted-foreground font-normal",children:[" · ",d.counselorName]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(C,{variant:"ghost",size:"sm",className:"h-7 gap-1 text-xs text-muted-foreground",onClick:()=>h(`/app/consejeria/${t}/sesion/${d.id}/informe`),title:l("report.title"),children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),l("report.short")]}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",onClick:()=>h(`/app/consejeria/${t}/sesion/${d.id}`),title:l("editor.edit"),children:e.jsx(ds,{className:"h-3.5 w-3.5"})}),e.jsxs(pe,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",children:e.jsx(X,{className:"h-3.5 w-3.5"})})}),e.jsxs(je,{children:[e.jsxs(fe,{children:[e.jsx(Ne,{children:l("session.deleteTitle")}),e.jsx(ye,{children:l("session.deleteDesc")})]}),e.jsxs(be,{children:[e.jsx(we,{children:l("common.cancel")}),e.jsx(ve,{onClick:()=>n(d.id),children:l("common.delete")})]})]})]})]})]}),e.jsxs("dl",{className:"space-y-2 text-sm",children:[d.homeworkReview&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.step1")}),e.jsx(ae,{html:d.homeworkReview})]}),d.dataGathered&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.step2")}),e.jsx(ae,{html:d.dataGathered})]}),d.instruction&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.step3")}),e.jsx(ae,{html:d.instruction})]}),d.scriptureRefs&&d.scriptureRefs.length>0&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.step4")}),e.jsxs("dd",{className:"inline-flex items-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"}),d.scriptureRefs.join(" · ")]})]}),d.changeEvaluation&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.changeEval")}),e.jsx(ae,{html:d.changeEvaluation})]}),d.hope&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.step5")}),e.jsx(ae,{html:d.hope})]}),d.prayer&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.step7")}),e.jsx(ae,{html:d.prayer})]}),d.learnedToday&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.learnedToday")}),e.jsx("dd",{className:"whitespace-pre-wrap",children:d.learnedToday})]}),d.hopeReceived&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.hopeReceived")}),e.jsx("dd",{className:"whitespace-pre-wrap",children:d.hopeReceived})]}),d.nextSessionAt&&e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:l("session.nextSession")}),e.jsx("dd",{children:q(d.nextSessionAt,y,{locale:g})})]})]})]},d.id))})]})},is=t=>{if(!t)return"";const s=a=>String(a).padStart(2,"0");return`${t.getFullYear()}-${s(t.getMonth()+1)}-${s(t.getDate())}`},ua=t=>{const[s,a,r]=t.split("-").map(Number);return new Date(s,a-1,r,12,0,0)},ha=({kase:t,onSaved:s})=>{const{t:a}=K("counseling"),[r,n]=x.useState(!1),[l,i]=x.useState(t.topic),[h,p]=x.useState(t.presentingIssue??""),[g,y]=x.useState(!!t.confidential),[d,A]=x.useState(is(t.targetDate)),[k,o]=x.useState(!1),b=()=>{i(t.topic),p(t.presentingIssue??""),y(!!t.confidential),A(is(t.targetDate))},m=async()=>{o(!0);try{const f={topic:l,presentingIssue:h.trim()||void 0,confidential:g},u=d?ua(d):null;await Me(t.id,f),await st(t.id,u),s({...f,targetDate:u??void 0}),E.success(a("case.updated")),n(!1)}
1catch(f){console.error(f),E.error(a("case.updateError"))}finally{o(!1)}};return e.jsxs(De,{open:r,onOpenChange:f=>{n(f),f||b()},children:[e.jsx(Be,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",title:a("case.edit"),children:e.jsx(ds,{className:"h-3.5 w-3.5"})})}),e.jsxs(Fe,{className:"max-h-[90vh] overflow-y-auto",children:[e.jsxs(Re,{children:[e.jsx(ze,{children:a("case.edit")}),e.jsx(Ke,{children:a("case.editHint")})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{children:a("topic.label")}),e.jsxs(ie,{value:l,onValueChange:f=>i(f),children:[e.jsx(ce,{children:e.jsx(oe,{})}),e.jsx(de,{children:Ft.map(f=>e.jsx(Z,{value:f.value,children:a(f.labelKey)},f.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"e-issue",children:a("case.presentingIssue")}),e.jsx(js,{id:"e-issue",rows:3,placeholder:a("case.presentingIssuePlaceholder"),value:h,onChange:f=>p(f.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{htmlFor:"e-target",children:a("case.targetDateField")}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:a("case.targetDateHint")}),e.jsx(I,{id:"e-target",type:"date",value:d,onChange:f=>A(f.target.value)})]}),e.jsx("div",{className:"rounded-md bg-muted p-3",children:e.jsxs("label",{className:"flex items-start gap-2 text-sm cursor-pointer",children:[e.jsx(Le,{checked:g,onCheckedChange:f=>y(!!f),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium",children:a("case.confidential")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:a("case.confidentialHint")})]})]})})]}),e.jsxs($e,{children:[e.jsx(C,{variant:"outline",onClick:()=>n(!1),disabled:k,children:a("common.cancel")}),e.jsxs(C,{onClick:m,disabled:k,children:[k&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),a("common.save")]})]})]})]})},pa=({kase:t,caseId:s,consentBlocks:a,onStatus:r,onPatch:n,tabs:l,pulse:i})=>{var u;const{t:h,i18n:p}=K("counseling"),g=he(),y=p.language.startsWith("en"),d=y?Y:V,A=y?"MMM d, yyyy":"d 'de' MMM yyyy",k=Rt(t.status),o=zt(t.openedAt,t.targetDate),b=t.status==="closed",m=[h(Kt(t.topic)),t.counselorName,t.presentingIssue].filter(
1Boolean),f=o.totalWeeks?Math.min(100,Math.round(o.week/o.totalWeeks*100)):0;return e.jsxs(O,{className:"overflow-hidden",children:[e.jsxs("div",{className:"p-4 pb-3 flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("span",{className:`hidden sm:flex h-10 w-10 rounded-lg items-center justify-center flex-shrink-0 ${k.badgeClass}`,children:e.jsx(Ds,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h1",{className:"text-xl font-semibold leading-tight truncate",children:(u=t.subjectNames)!=null&&u.length?t.subjectNames.join(" · "):h("case.noSubjects")}),t.confidential&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs px-2 py-0.5 rounded-full font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/40 dark:text-purple-300",children:[e.jsx(ms,{className:"h-3 w-3"}),h("case.confidentialBadge")]})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5 line-clamp-2",children:m.join(" · ")})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs(C,{variant:"ghost",size:"sm",className:"h-9 text-muted-foreground",onClick:()=>g("/app/consejeria"),children:[e.jsx(xs,{className:"h-4 w-4 mr-1.5"}),h("case.back")]}),e.jsx(ha,{kase:t,onSaved:n}),e.jsxs(ie,{value:t.status,onValueChange:N=>r(N),children:[e.jsx(ce,{className:`w-[140px] h-9 border-0 font-medium ${k.badgeClass}`,children:e.jsx(oe,{})}),e.jsx(de,{children:Lt.map(N=>e.jsx(Z,{value:N.value,children:h(N.labelKey)},N.value))})]}),s&&e.jsxs(C,{size:"sm",className:"h-9",onClick:()=>g(`/app/consejeria/${s}/sesion`),disabled:a||b,title:b?h("case.closedHint"):a?h("consent.blocked"):void 0,children:[e.jsx(le,{className:"h-4 w-4 mr-1.5"}),h("session.new")]})]})]}),!b&&o.totalWeeks?e.jsxs("div",{className:"px-4 pb-3 flex items-center gap-3",children:[e.jsx("div",{className:"h-1.5 flex-1 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${o.overdue?"bg-amber-500":"bg-primary"}`,style:{width:`${f}%`}})}),e.jsxs("span",{className:`text-xs whitespace-nowrap ${o.overdue?"text-amber-700 dark:text-amber-500 font-medium":"text-muted-foreground"}`,children:[h("case.weekOf",{week:o.week,total:o.totalWeeks}),o.overdue&&` · ${h("case.targetPassed")}`]})]}):e.jsx("div",{className:"px-4 pb-3",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:b?t.closedAt&&h("case.closedAt",{date:q(t.closedAt,A,{locale:d})}):h("case.week",{week:o.week})})}),i&&e.jsx("div",{className:"px-4 pb-3",children:i}),t.closingNote&&e.jsxs("div",{className:"mx-4 mb-3 rounded-md bg-muted/60 p-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:h("case.closingNote")}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:t.closingNote})]}),l&&e.jsx("div",{className:"border-t border-border px-2",children:l})]})},ga=({section:t,caseId:s})=>{const{t:a}=K("counseling"),r=he(),n=Yt.indexOf(t),l=()=>{r(s?`/app/consejeria/guia?caso=${s}`:"/app/consejeria/guia")};return e.jsxs(Qt,{children:[e.jsx(Xt,{asChild:!0,children:e.jsxs(C,{variant:"ghost",size:"sm",className:"h-8 text-muted-foreground gap-1.5",title:a("help.openHint"),children:[e.jsx(us,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:a("help.short")})]})}),e.jsxs(Jt,{className:"w-full sm:max-w-2xl p-0 flex flex-col gap-0",children:[e.jsxs("header",{className:"flex-shrink-0 border-b border-border px-6 py-5 pr-14",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-primary",children:n===0?a("help.start"):a("help.stretch",{n})}),e.jsx(Zt,{className:"text-xl font-semibold tracking-tight mt-0.5",children:a(`phase.${t}`)}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a("help.sheetHint")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-6",children:e.jsx(Vt,{section:t})}),e.jsx("footer",{className:"flex-shrink-0 border-t border-border px-6 py-4",children:e.jsxs(C,{variant:"outline",size:"sm",className:"w-full",onClick:l,children:[e.jsx(re,{className:"h-4 w-4 mr-2"}),a("help.openFull")]})})]})]})},cs=4,_e=t=>{const s=t.filter(r=>r.status!=="assigned");if(s.length===0)return null;const a=s.reduce((r,n)=>r+(n.status==="done"?1:n.status==="partial"?.5:0),0);return Math.round(a/s.length*100)},ja={steady:"text-emerald-700 dark:text-emerald-400","last-minute":"text-amber-700 dark:text-amber-500",irregular:"text-amber-700 dark:text-amber-500",unknown:"text-muted-foreground"},fa=({assignments:t,entries:s})=>{const{t:a}=K("counseling"),r=x.useMemo(()=>{const l=[...t].sort((A,k)=>A.assignedAt.getTime()-k.assignedAt.getTime()),i=_e(l),h=l.slice(-cs),p=l.slice(0,-cs),g=_e(h),y=_e(p),d=g!==null&&y!==null&&p.length>=2?g-y:null;return{rate:i,trend:d,regularity:ia(s)}},[t,s]);if(r.rate===null)return null;const{pattern:n}=r.regularity;return e.jsxs("div",{className:"flex items-center gap-4 flex-wrap text-sm",children:[e.jsxs("span",{className:"inline-flex items-baseline gap-1.5",children:[e.jsxs("span",{className:"font-semibold",children:[r.rate,"%"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a("pulse.compliance")})]}),r.trend!==null&&Math.abs(r.trend)>=10&&e.jsxs("span",{className:`inline-flex items-center gap-1 text-xs font-medium ${r.trend>0?"text-emerald-700 dark:text-emerald-400":"text-amber-700 dark:text-amber-500"}`,children:[r.trend>0?e.jsx(Fs,{className:"h-3.5 w-3.5"}):e.jsx(Rs,{className:"h-3.5 w-3.5"}),a(r.trend>0?"pulse.improving":"pulse.declining")]}),n!=="unknown"&&e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs ${ja[n]}`,title:a(`pulse.regularity.${n}Hint`),children:[e.jsx(zs,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"font-medium",children:a(`pulse.regularity.${n}`)})]})]})},Ae="counseling.ministryPassphrase";function Na({salt:t,verifier:s}
1){const[a,r]=x.useState(null),[n,l]=x.useState("not-required"),i=!!t&&!!s,h=x.useCallback(async g=>{if(!t||!s)return!1;const y=await Xe(g,t);if(!await Je(y,s))return!1;r(y),l("unlocked");try{sessionStorage.setItem(Ae,g)}catch{}return!0},[t,s]),p=x.useCallback(()=>{r(null),l(i?"locked":"not-required");try{sessionStorage.removeItem(Ae)}catch{}},[i]);return x.useEffect(()=>{let g=!0;if(!i){l("not-required"),r(null);return}const y=(()=>{try{return sessionStorage.getItem(Ae)}catch{return null}})();if(!y){l("locked");return}return Xe(y,t).then(async d=>{if(g)if(await Je(d,s))r(d),l("unlocked");else{try{sessionStorage.removeItem(Ae)}catch{}l("locked")}}).catch(()=>{g&&l("locked")}),()=>{g=!1}},[i,t,s]),{key:a,state:n,encryptionOn:i,unlock:h,lock:p}}const ya=({settings:t,onUnlocked:s})=>{var k,o,b;const{t:a}=K("counseling"),{key:r,state:n,unlock:l}=Na({salt:(k=t==null?void 0:t.encryption)==null?void 0:k.salt,verifier:(o=t==null?void 0:t.encryption)==null?void 0:o.verifier}),[i,h]=x.useState(""),[p,g]=x.useState(!1),[y,d]=x.useState(!1);if(x.useEffect(()=>{var u;let m=!0;Ze(r);const f=(u=t==null?void 0:t.encryption)==null?void 0:u.privateKey;return r&&f?tt(r,f).then(N=>{m&&Ce(N)}).catch(()=>{m&&Ce(null)}):Ce(null),r&&s(),()=>{m=!1,Ze(null),Ce(null)}},[r,(b=t==null?void 0:t.encryption)==null?void 0:b.privateKey]),n!=="locked")return null;const A=async()=>{d(!0),g(!1);try{await l(i)?h(""):g(!0)}finally{d(!1)}};return e.jsx(O,{className:"p-4 border-amber-300 dark:border-amber-900 bg-amber-50/60 dark:bg-amber-950/20",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ms,{className:"h-4 w-4 text-amber-700 dark:text-amber-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:a("encryption.locked")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:a("encryption.lockedHint")}),e.jsxs("div",{className:"flex items-start gap-2 mt-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(I,{type:"password",autoComplete:"off",placeholder:a("encryption.phrase"),value:i,onChange:m=>{h(m.target.value),g(!1)},onKeyDown:m=>{m.key==="Enter"&&A()}}),p&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:a("encryption.wrongPhrase")})]}),e.jsxs(C,{onClick:A,disabled:!i.trim()||y,className:"gap-1.5",children:[y?e.jsx(W,{className:"h-4 w-4 animate-spin"}):e.jsx(Ks,{className:"h-4 w-4"}),a("encryption.unlock")]})]})]})]})})},ba=({kase:t,mode:s,onPurged:a})=>{var k;const{t:r}=K("counseling"),[n,l]=x.useState(!1),[i,h]=x.useState(""),[p,g]=x.useState(!1),y=((k=t.subjectNames)==null?void 0:k.join(" · "))??"",d=i.trim().toLowerCase()===y.trim().toLowerCase(),A=async()=>{if(d){g(!0);try{await at(t.churchId,t.id,s),E.success(r("retention.purged")),l(!1),h(""),a()}catch(o){console.error(o),E.error(r("retention.purgeError"))}finally{g(!1)}}};return e.jsxs(De,{open:n,onOpenChange:o=>{l(o),o||h("")},children:[e.jsx(Be,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"gap-1.5 text-destructive border-destructive/40 hover:bg-destructive/10",children:[e.jsx(Ls,{className:"h-4 w-4"}),r("retention.purgeAction")]})}),e.jsxs(Fe,{children:[e.jsxs(Re,{children:[e.jsx(ze,{children:r("retention.purgeTitle")}),e.jsx(Ke,{children:r(`retention.purgeDesc.${s}`)})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-md bg-muted p-3",children:[e.jsx("p",{className:"text-xs font-medium",children:r("retention.survives")}),e.jsxs("ul",{className:"text-xs text-muted-foreground mt-1 space-y-0.5 list-disc pl-4",children:[e.jsx("li",{children:r("retention.survivesLetter")}),e.jsx("li",{children:r("retention.survivesConsent")}),e.jsx("li",{children:r("retention.survivesCounts")})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{htmlFor:"purge-confirm",children:r("retention.typeName",{name:y})}),e.jsx(I,{id:"purge-confirm",value:i,onChange:o=>h(o.target.value),placeholder:y,autoComplete:"off"})]})]}),e.jsxs($e,{children:[e.jsx(C,{variant:"outline",onClick:()=>l(!1),children:r("common.cancel")}),e.jsxs(C,{variant:"destructive",onClick:A,disabled:!d||p,children:[p&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),r("retention.purgeConfirm")]})]})]})]})},wa=({summary:t})=>{const{t:s,i18n:a}=K("counseling"),r=a.language.startsWith("en"),n=r?"MMM d, yyyy":"d 'de' MMM yyyy",l=[{label:s("session.title"),value:t.sessions},{label:s("assignment.title"),value:t.assignments},{label:s("pulse.compliance"),value:t.complianceRate===null?"â":`${t.complianceRate}%`},{label:s("retention.journalEntries"),value:t.journalEntries}];return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground",children:e.jsx($s,{className:"h-4 w-4",strokeWidth:1.75})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("retention.purgedTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s(`retention.purgedOn.${t.mode}`,{date:q(t.purgedAt,n,{locale:r?Y:V})})})]})]}),e.jsx("dl",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mt-4",children:l.map(i=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:i.label}),e.jsx("dd",{className:"text-lg font-semibold tabular-nums",children:i.value})]},i.label))})]})},va=({caseId:t,value:s,onSaved:a,disabled:r})=>{const{t:n}=K("counseling"),[l,i]=x.useState(!1),[h,p]=x.useState(s??{}),[g,y]=x.useState(!1),d=(o,b)=>p(m=>({...m,[o]:{target:"",...m[o],...b}})),A=Oe.filter(o=>{var b;return(((b=s==null?void 0:s[o])==null?void 0:b.target)??"").trim()}).length,k=async()=>{y(!0);try{const o={};Oe.forEach(b=>{var u,N;const m=(((u=h[b])==null?void 0:u.target)??"").trim();if(!m)return;const f=(((N=h[b])==null?void 0:N.current)??"").trim();o[b]={target:m,current:f||void 0,updatedAt:new Date}}),await Me(t,{disciplineGoals:o}),a(o),E.success(n("discipline.saved"))}catch(o){console.error(o),E.error(n("discipline.error"))}finally{y(!1)}};return e.jsxs(O,{className:"p-4",children:[e.jsxs("button",{type:"button",onClick:()=>i(o=>!o),className:"w-full flex items-center justify-between gap-2 text-left",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(hs,{className:"h-4 w-4"}),n("discipline.title"),e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:n("discipline.definedCount",{count:A})})]}),l?e.jsx(Q,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Pe,{className:"h-4 w-4 text-muted-foreground"})]}),l&&e.jsxs("div",{className:"mt-3 space-y-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:n("discipline.hint")}),Oe.map(o=>{var b,m;return e.jsxs("div",{className:"space-y-2",children:[e.jsx(G,{className:"text-sm",children:n(`discipline.key.${o}`)}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:n("discipline.target")}),e.jsx(I,{disabled:r,value:((b=h[o])==null?void 0:b.target)??"",placeholder:n(`discipline.placeholder.${o}`),onChange:f=>d(o,{target:f.target.value})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:n("discipline.current")}),e.jsx(I,{disabled:r,value:((m=h[o])==null?void 0:m.current)??"",onChange:f=>d(o,{current:f.target.value})})]})]})]},o)}),!r&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(C,{size:"sm",onClick:k,disabled:g,children:[g&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),n("common.save")]})})]})]})},ka=({churchId:t,caseId:s,value:a,onSaved:r,subjects:n,disabled:l})=>{var ee;const{t:i,i18n:h}=K("counseling"),p=(ee=h.language)==null?void 0:ee.startsWith("en"),g=p?Y:V,y=p?"MMM d, yyyy":"d 'de' MMM yyyy",[d,A]=x.useState(!1),[k,o]=x.useState(!1),[b,m]=x.useState([]),[f,u]=x.useState((a==null?void 0:a.closingLetter)??""),N=x.useCallback(()=>{Ns(t,s).then(D=>m(D.filter($=>$.kind==="three-month-plan"))).catch(D=>console.error("[plan]",D))},[t,s]);x.useEffect(()=>{d&&N()},[d,N]);const P=ws(a==null?void 0:a.criteria),w=D=>q(D,y,{locale:g}),c=D=>`${D.getFullYear()}
1-${String(D.getMonth()+1).padStart(2,"0")}-${String(D.getDate()).padStart(2,"0")}`,v=D=>{const[$,U,me]=D.split("-").map(Number);return new Date($,U-1,me,12,0,0)},j=async D=>{o(!0);try{await Me(s,{closure:D}),r(D)}catch($){console.error($),E.error(i("closure.error"))}finally{o(!1)}},M=()=>j({startedAt:new Date,criteria:{}}),z=(D,$)=>{a&&j({...a,criteria:{...a.criteria,[D]:$}})},R=()=>{a&&j({...a,spacingStartedAt:new Date})},F=async(D,$)=>{o(!0);try{const U=await nt({churchId:t,caseId:s,personId:D,personName:$});a&&await Me(s,{closure:{...a,threeMonthPlanId:U}}),a&&r({...a,threeMonthPlanId:U}),N(),E.success(i("plan.sent"))}catch(U){console.error(U),E.error(i("plan.sendError"))}finally{o(!1)}};if(!a)return e.jsxs(O,{className:"p-4 flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(Qe,{className:"h-4 w-4"}),i("closure.title")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:i("closure.hint")})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:M,disabled:l||k,className:"flex-shrink-0",children:[k&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),i("closure.start")]})]});const H=$t(new Date),B=Ot(new Date);return e.jsxs(O,{className:"p-4",children:[e.jsxs("button",{type:"button",onClick:()=>A(D=>!D),className:"w-full flex items-center justify-between gap-2 text-left",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(Qe,{className:"h-4 w-4"}),i("closure.title"),e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:i("closure.progress",{done:P.done,total:P.total})})]}),d?e.jsx(Q,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Pe,{className:"h-4 w-4 text-muted-foreground"})]}),d&&e.jsxs("div",{className:"mt-3 space-y-5",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:i("closure.startedOn",{date:w(a.startedAt)})}),[{group:"adams",titleKey:"closure.adams",hintKey:"closure.adamsHint"},{group:"indicators",titleKey:"closure.indicators",hintKey:"closure.indicatorsHint"}].map(D=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i(D.titleKey)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i(D.hintKey)})]}),Ht(D.group).map($=>{var U;return e.jsxs("label",{className:"flex items-start gap-2 text-sm cursor-pointer",children:[e.jsx(Le,{className:"mt-0.5",disabled:l||k,checked:((U=a.criteria)==null?void 0:U[$.key])===!0,onCheckedChange:me=>z($.key,!!me)}),e.jsx("span",{children:i($.labelKey)})]},$.key)})]},D.group)),P.adamsComplete&&e.jsxs("p",{className:"text-xs text-emerald-700 dark:text-emerald-300 inline-flex items-center gap-1.5",children:[e.jsx(Os,{className:"h-3.5 w-3.5"}),i("closure.adamsComplete")]}),e.jsxs("div",{className:"rounded-md bg-muted p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i("plan.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("plan.hint")})]}),e.jsx(ne,{caseId:s,doc:"plan"})]}),b.length===0?n.map(D=>e.jsxs(C,{variant:"outline",size:"sm",className:"gap-1.5",disabled:l||k,onClick:()=>F(D.id,D.name),children:[e.jsx(Ge,{className:"h-3.5 w-3.5"}),n.length>1?i("plan.sendTo",{name:D.name}):i("plan.send")]},D.id)):e.jsx("ul",{className:"space-y-2",children:b.map(D=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-medium",children:D.personName??""})," · ",e.jsx("span",{className:D.status==="submitted"?"text-emerald-700 dark:text-emerald-300":"text-muted-foreground",children:i(`plan.status.${D.status}`)}),D.status==="submitted"&&e.jsx("ul",{className:"mt-1.5 space-y-1",children:ea.filter($=>D.sections[$.key]).map($=>e.jsxs("li",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[i($.labelKey),": "]}),e.jsx("span",{className:"whitespace-pre-wrap",children:D.sections[$.key]})]},$.key))})]},D.id))})]}),e.jsxs("div",{className:"rounded-md bg-muted p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i("closure.letter")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("closure.letterHint")})]}),e.jsx(ne,{caseId:s,doc:"carta"})]}),e.jsx(J,{value:f,onChange:D=>{u(D),D!==(a.closingLetter??"")&&j({...a,closingLetter:D||void 0})},disabled:l,placeholder:i("closure.letterPlaceholder"),"aria-label":i("closure.letter"),minLines:6,className:"text-sm"})]}),e.jsxs("div",{className:"rounded-md bg-muted p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i("closure.checkup")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("closure.checkupHint")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(I,{t
1ype:"date",className:"w-44",disabled:l,value:a.checkupAt?c(a.checkupAt):"",onChange:D=>j({...a,checkupAt:D.target.value?v(D.target.value):void 0})}),!a.checkupAt&&e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",size:"sm",className:"h-8 text-xs",disabled:l||k,onClick:()=>j({...a,checkupAt:B.twoMonths}),children:i("closure.inTwoMonths")}),e.jsx(C,{variant:"ghost",size:"sm",className:"h-8 text-xs",disabled:l||k,onClick:()=>j({...a,checkupAt:B.threeMonths}),children:i("closure.inThreeMonths")})]})]}),a.checkupAt&&e.jsx("p",{className:"text-xs text-muted-foreground",children:i("closure.checkupReminder")})]}),e.jsxs("div",{className:"rounded-md bg-muted p-3 space-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i("closure.spacing")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i("closure.spacingHint")})]}),a.spacingStartedAt?e.jsx("p",{className:"text-xs",children:i("closure.spacingStartedOn",{date:w(a.spacingStartedAt)})}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:i("closure.suggest",{two:w(H.twoWeeks),three:w(H.threeWeeks)})}),e.jsx(C,{variant:"outline",size:"sm",onClick:R,disabled:l||k,children:i("closure.spacingStart")})]})]})]})]})},Sa=({open:t,onOpenChange:s,onConfirm:a,closureCriteria:r})=>{const{t:n}=K("counseling"),[l,i]=x.useState(""),[h,p]=x.useState(!1),g=async()=>{p(!0);try{await a(l.trim()),i(""),s(!1)}finally{p(!1)}};return e.jsx(De,{open:t,onOpenChange:y=>{h||(s(y),y||i(""))},children:e.jsxs(Fe,{children:[e.jsxs(Re,{children:[e.jsx(ze,{children:n("case.closeTitle")}),e.jsx(Ke,{children:n("case.closeHint")})]}),e.jsxs("div",{className:"space-y-2 py-2",children:[(()=>{const y=ws(r);return y.done<y.total?e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-300 inline-flex items-start gap-1.5 mb-1",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}),n("closure.warnUnchecked",{done:y.done,total:y.total})]}):null})(),e.jsx(G,{htmlFor:"c-note",children:n("case.closingNote")}),e.jsx(js,{id:"c-note",rows:4,placeholder:n("case.closingNotePlaceholder"),value:l,onChange:y=>i(y.target.value)})]}),e.jsxs($e,{children:[e.jsx(C,{variant:"outline",onClick:()=>s(!1),disabled:h,children:n("common.cancel")}),e.jsxs(C,{onClick:g,disabled:h,children:[h&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),n("case.closeConfirm")]})]})]})})},ue=[{key:"familyBackground",labelKey:"intake.familyBackground"},{key:"physicalHealth",labelKey:"intake.physicalHealth"},{key:"whatTried",labelKey:"intake.whatTried"},{key:"expectations",labelKey:"intake.expectations"},{key:"faithBackground",labelKey:"intake.faithBackground"}],Ca=({caseId:t,intake:s,suggested:a,onSaved:r})=>{const{t:n}=K("counseling"),l=s&&ue.some(u=>{var N;return(N=s[u.key])==null?void 0:N.trim()}),[i,h]=x.useState(!l),[p,g]=x.useState(s??{}),[y,d]=x.useState(!1),[A,k]=x.useState(new Set),o=x.useRef(!1),b=x.useMemo(()=>ue.map(u=>(a==null?void 0:a[u.key])??"").join("|"),[a]);x.useEffect(()=>{if(o.current||!a)return;const u=ue.filter(N=>(a[N.key]??"").trim()&&!((s==null?void 0:s[N.key])??"").trim());u.length&&(o.current=!0,g(N=>{const P={...N};return u.forEach(w=>{(P[w.key]??"").trim()||(P[w.key]=a[w.key])}),P}),k(new Set(u.map(N=>N.key))),h(!0))},[a,b,s]);const m=(u,N)=>{g(P=>({...P,[u]:N})),k(P=>{if(!P.has(u))return P;const w=new Set(P);return w.delete(u),w})},f=async()=>{d(!0);try{const u={};ue.forEach(N=>{var w;const P=(w=p[N.key])==null?void 0:w.trim();P&&(u[N.key]=P)}),await rt(t,u),E.success(n("intake.saved")),k(new Set),r(u)}catch(u){console.error(u),E.error(n("intake.error"))}finally{d(!1)}};return e.jsxs(O,{className:"p-4",children:[e.jsxs("button",{type:"button",onClick:()=>h(u=>!u),className:"w-full flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Hs,{className:"h-4 w-4 text-muted-foreground"}),n("intake.title")]}),e.jsx(Q,{className:`h-4 w-4 text-muted-foreground transition-transform ${i?"rotate-180":""}`})]}),i&&e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:n("intake.hint")}),A.size>0&&e.jsx("p",{className:"text-xs text-muted-foreground rounded-md bg-muted/50 px-2.5 py-2",children:n("intake.prefilled")}),ue.map(u=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(G,{className:"text-xs flex items-center gap-1.5",children:[n(u.labelKey),A.has(u.key)&&e.jsx("span",{className:"font-normal text-[11px] text-muted-foreground",children:n("intake.fromForm")})]}),e.jsx(J,{value:p[u.key]??"",onChange:N=>m(u.key,N),"aria-label":n(u.labelKey),placeholder:n("intake.emptyField"),minLines:2,className:"text-sm"})]},u.key)),e.jsx("div",{className:"flex justify-end",children:e.jsxs(C,{size:"sm",onClick:f,disabled:y,children:[y&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),n("common.save")]})})]})]})},Aa=({caseId:t,notes:s,riskFlags:a,riskProtocolText:r,onSaved:n})=>{const{t:l}=K("counseling"),i=!!(s!=null&&s.did||s!=null&&s.doneTo||s!=null&&s.happened),h=a??[],[p,g]=x.use
1State(!(!i&&h.length===0)),[y,d]=x.useState({did:(s==null?void 0:s.did)??"",doneTo:(s==null?void 0:s.doneTo)??"",happened:(s==null?void 0:s.happened)??""}),[A,k]=x.useState(!1),o=async m=>{const f=h.includes(m)?h.filter(u=>u!==m):[...h,m];try{await lt(t,f),n({riskFlags:f})}catch(u){console.error(u),E.error(l("risk.error"))}},b=async()=>{k(!0);try{const m={};Object.keys(y).forEach(f=>{const u=y[f];typeof u=="string"&&u.trim()&&(m[f]=u.trim())}),await it(t,m),n({categoryNotes:m}),E.success(l("categories.saved"))}catch(m){console.error(m),E.error(l("categories.error"))}finally{k(!1)}};return e.jsxs(O,{className:"p-4",children:[h.length>0&&e.jsxs("div",{className:"mb-3 rounded-md border border-red-300 bg-red-50 p-3 dark:border-red-900 dark:bg-red-950/40",children:[e.jsxs("p",{className:"text-sm font-medium text-red-800 dark:text-red-300 inline-flex items-center gap-1.5",children:[e.jsx(Ee,{className:"h-4 w-4"}),l("risk.bannerTitle")]}),e.jsx("p",{className:"mt-1 text-xs text-red-800/90 dark:text-red-300/90 whitespace-pre-wrap",children:r||l("risk.bannerBody")}),e.jsx("p",{className:"mt-1.5 text-xs font-medium text-red-900 dark:text-red-200",children:h.map(m=>{var f;return l(((f=rs.find(u=>u.value===m))==null?void 0:f.labelKey)??m)}).join(" · ")})]}),e.jsxs("button",{type:"button",onClick:()=>g(m=>!m),className:"flex w-full items-center justify-between gap-2 text-left",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(_s,{className:"h-4 w-4"}),l("categories.title")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:l("categories.hint")})]}),e.jsx(Q,{className:`h-4 w-4 text-muted-foreground transition-transform ${p?"rotate-180":""}`})]}),p&&e.jsxs("div",{className:"mt-4 space-y-4",children:[_t.map(m=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{children:l(m.labelKey)}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:l(m.hintKey)}),e.jsx(J,{value:y[m.key]??"",onChange:f=>d(u=>({...u,[m.key]:f})),"aria-label":l(m.labelKey),placeholder:l("intake.emptyField"),minLines:2,className:"text-sm"})]},m.key)),e.jsx("div",{className:"flex justify-end",children:e.jsxs(C,{size:"sm",onClick:b,disabled:A,children:[A&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),l("common.save")]})}),e.jsxs("div",{className:"border-t border-border pt-3",children:[e.jsx("p",{className:"text-sm font-medium",children:l("risk.title")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 mb-2",children:l("risk.hint")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:rs.map(m=>{const f=h.includes(m.value);return e.jsx("button",{type:"button",onClick:()=>o(m.value),className:`text-xs px-2.5 py-1 rounded-full border transition-colors ${f?"border-red-400 bg-red-100 text-red-800 font-medium dark:border-red-800 dark:bg-red-900/50 dark:text-red-200":"border-border text-muted-foreground hover:bg-muted"}`,children:l(m.labelKey)},m.value)})})]})]})]})},Ta={sent:"bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300","in-progress":"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300",submitted:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/40 dark:text-emerald-300"},Ea=({churchId:t,caseId:s,subjects:a,onFormsChange:r})=>{const{t:n,i18n:l}=K("counseling"),i=l.language.startsWith("en"),h=i?Y:V,p=i?"MMM d, yyyy":"d 'de' MMM yyyy",[g,y]=x.useState([]),[d,A]=x.useState(!0),[k,o]=x.useState(null),[b,m]=x.useState(null),f=x.useRef(r);f.current=r;const u=x.useCallback(async()=>{var c;try{const j=(await Ns(t,s)).filter(M=>M.kind!=="three-month-plan");y(j),(c=f.current)==null||c.call(f,j)}catch(v){console.error(v)}finally{A(!1)}},[t,s]);x.useEffect(()=>{u()},[u]);const N=async c=>{o(c.id);try{await ct({churchId:t,caseId:s,personId:c.id,personName:c.name}),await u(),E.success(n("intakeForm.sent"))}catch(v){console.error(v),E.error(n("intakeForm.error"))}finally{o(null)}},P=async c=>{try{await ot(c),y(v=>v.filter(j=>j.id!==c)),E.success(n("intakeForm.deleted"))}catch(v){console.error(v),E.error(n("intakeForm.error"))}},w=a.filter(c=>!g.some(v=>v.personId===c.id));return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(qe,{className:"h-4 w-4"}),n("intakeForm.title")]}),e.jsx(ne,{caseId:s,doc:"pdi"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 mb-3",children:n("intakeForm.hint")}),d?e.jsx("p",{className:"text-sm text-muted-foreground py-2 text-center",children:"â¦"}):e.jsxs(e.Fragment,{children:[w.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:w.map(c=>e.jsxs(C,{variant:"outline",size:"sm",className:"gap-1.5",onClick:()=>N(c),disabled:k===c.id,children:[k===c.id?e.jsx(W,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ge,{className:"h-3.5 w-3.5"}),n("intakeForm.sendTo",{name:c.name})]},c.id))}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:n("intakeForm.empty")}):e.jsx("ul",{className:"space-y-2",children:g.map(c=>{const v=Object.values(c.sections).filter(M=>M==null?void 0:M.trim()).length,j=b===c.id;return e.jsxs("li",{className:"border-b border-border last:border-0 pb-2 last:pb-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("button",{type:"button",className:"min-w-0 text-left",onClick:()=>m(j?null:c.id),children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"text-sm font-medium",children:c.personName??c.personId}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${Ta[c.status]}`,children:n(`intakeForm.status.${c.status}`)}),e.jsx(Q,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${j?"rotate-180":""}`})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[c.submittedAt?n("intakeForm.submittedAt",{date:q(c.submittedAt,p,{locale:h})}):n("intakeForm.sentAt",{date:q(c.sentAt,p,{locale:h})})," · ",n("intakeForm.answered",{count:v})]})]}),e.jsxs(pe,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",children:e.jsx(X,{className:"h-3.5 w-3.5"})})}),e.jsxs(je,{children:[e.jsxs(fe,{children:[e.jsx(Ne,{children:n("intakeForm.deleteTitle")}),e.jsx(ye,{children:n("session.deleteDesc")})]}),e.jsxs(be,{children:[e.jsx(we,{children:n("common.cancel")}),e.jsx(ve,{onClick:()=>P(c.id),children:n("common.delete")})]})]})]})]}),j&&(v===0?e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:n("intakeForm.nothingYet")}):e.jsx("dl",{className:"mt-2 space-y-2",children:sa.filter(M=>{var z;return(z=c.sections[M.key])==null?void 0:z.trim()}).map(M=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs font-medium text-muted-foreground",children:n(M.labelKey)}),e.jsx("dd",{className:"text-sm whitespace-pre-wrap",children:c.sections[M.key]})]},M.key))}))]},c.id)})})]})]})},Ma=({churchId:t,caseId:s})=>{const{t:a}=K("counseling"),[r,n]=x.useState([]),[l,i]=x.useState(!0),[h,p]=x.useState(!1),[g,y]=x.useState(""),[d,A]=x.useState("to-ask"),k=x.useCallback(async()=>{try{n(await dt(t,s))}catch(N){console.error(N)}finally{i(!1)}},[t,s]);x.useEffect(()=>{k()},[k]);const o=async()=>
1{if(g.trim())try{await mt({churchId:t,caseId:s,kind:d,question:g.trim()}),y(""),p(!1),await k()}catch(N){console.error(N),E.error(a("question.error"))}},b=async(N,P)=>{if((N.answer??"")!==P)try{await xt(N.id,P||null),n(w=>w.map(c=>c.id===N.id?{...c,answer:P||void 0}:c))}catch(w){console.error(w),E.error(a("question.error"))}},m=async N=>{try{await ut(N),n(P=>P.filter(w=>w.id!==N))}catch(P){console.error(P)}},f=r.filter(N=>!N.answer),u=r.filter(N=>N.answer);return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1 flex-wrap",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(us,{className:"h-4 w-4"}),a("question.title"),f.length>0&&e.jsxs("span",{className:"text-muted-foreground font-normal",children:[" · ",a("question.pendingCount",{count:f.length})]})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>p(N=>!N),children:[e.jsx(le,{className:"h-4 w-4 mr-1"}),a("question.new")]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:a("question.hint")}),h&&e.jsxs("div",{className:"rounded-md border border-border p-3 mb-3 space-y-2",children:[e.jsxs(ie,{value:d,onValueChange:N=>A(N),children:[e.jsx(ce,{className:"w-full",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(Z,{value:"to-ask",children:a("question.kind.to-ask")}),e.jsx(Z,{value:"from-subject",children:a("question.kind.from-subject")})]})]}),e.jsx(I,{placeholder:a("question.placeholder"),value:g,onChange:N=>y(N.target.value),onKeyDown:N=>{N.key==="Enter"&&o()}}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>{p(!1),y("")},children:a("common.cancel")}),e.jsx(C,{size:"sm",onClick:o,disabled:!g.trim(),children:a("common.save")})]})]}),l?e.jsx("p",{className:"text-sm text-muted-foreground py-2 text-center",children:"â¦"}):r.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2 text-center",children:a("question.empty")}):e.jsx("ul",{className:"space-y-3",children:[...f,...u].map(N=>e.jsx("li",{className:`border-b border-border last:border-0 pb-3 last:pb-0 ${N.answer?"opacity-70":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-xs text-muted-foreground mr-1.5",children:a(`question.kind.${N.kind}`)}),N.question]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(J,{value:N.answer??"",onChange:P=>b(N,P),placeholder:a("question.answerPlaceholder"),"aria-label":a("question.answerPlaceholder"),className:"text-sm"})})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[N.answer&&e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",title:a("question.reopen"),onClick:()=>b(N,""),children:e.jsx(ps,{className:"h-3.5 w-3.5"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",onClick:()=>m(N.id),children:e.jsx(X,{className:"h-3.5 w-3.5"})})]})]})},N.id))})]})},Pa=({caseId:t,goals:s,plan:a,onSaved:r})=>{const{t:n}=K("counseling"),[l,i]=x.useState(!a),[h,p]=x.useState((a==null?void 0:a.goalIds)??[]),[g,y]=x.useState((a==null?void 0:a.notes)??""),[d,A]=x.useState((a==null?void 0:a.tentativeAssignments)??[]),[k,o]=x.useState(!1),b=s.filter(w=>w.status!=="covered"),m=w=>p(c=>c.includes(w)?c.filter(v=>v!==w):[...c,w]),f=()=>A(w=>[...w,{title:"",type:"log"}]),u=(w,c)=>A(v=>v.map((j,M)=>M===w?{...j,...c}:j)),N=async()=>{o(!0);try{const w={goalIds:h,notes:g.trim()||void 0,tentativeAssignments:d.filter(c=>c.title.trim()),preparedAt:new Date};await es(t,w),r(w),i(!1),E.success(n("nextSessionPlan.saved"))}catch(w){console.error(w),E.error(n("nextSessionPlan.error"))}finally{o(!1)}},P=async()=>{try{await es(t,null),r(void 0),p([]),y(""),A([]),i(!0)}catch(w){console.error(w),E.error(n("nextSessionPlan.error"))}};return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(Ws,{className:"h-4 w-4"}),n("nextSessionPlan.title")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:n("nextSessionPlan.hint")})]}),a&&!l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{variant:"ghost",size:"sm",onClick:P,children:n("nextSessionPlan.clear")}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>i(!0),children:n("nextSessionPlan.edit")})]})]}),!l&&a?e.jsxs("div",{className:"mt-3 space-y-2",children:[a.goalIds&&a.goalIds.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:n("nextSessionPlan.goalsToCover")}),e.jsx("p",{className:"text-sm",children:a.goalIds.map(w=>{var c;return(c=s.find(v=>v.id===w))==null?void 0:c.title}
1).filter(Boolean).join(" · ")||"â"})]}),a.notes&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:n("nextSessionPlan.notes")}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:a.notes})]}),a.tentativeAssignments&&a.tentativeAssignments.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:n("nextSessionPlan.tentative")}),e.jsx("ul",{className:"text-sm list-disc pl-4",children:a.tentativeAssignments.map((w,c)=>e.jsx("li",{children:w.title},c))})]})]}):e.jsxs("div",{className:"mt-3 space-y-4",children:[b.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{children:n("nextSessionPlan.goalsToCover")}),e.jsx("div",{className:"space-y-1.5",children:b.map(w=>e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(Le,{checked:h.includes(w.id),onCheckedChange:()=>m(w.id)}),w.title]},w.id))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{children:n("nextSessionPlan.notes")}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:n("nextSessionPlan.notesHint")}),e.jsx(J,{value:g,onChange:y,placeholder:n("nextSessionPlan.notesPlaceholder"),"aria-label":n("nextSessionPlan.notes"),minLines:3,className:"text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(G,{children:n("nextSessionPlan.tentative")}),e.jsxs(C,{variant:"ghost",size:"sm",onClick:f,className:"gap-1 text-xs",children:[e.jsx(le,{className:"h-3.5 w-3.5"}),n("nextSessionPlan.addTentative")]})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-1",children:n("nextSessionPlan.tentativeHint")}),d.map((w,c)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(I,{placeholder:n("assignment.titlePlaceholder"),value:w.title,onChange:v=>u(c,{title:v.target.value})}),e.jsxs(ie,{value:w.type,onValueChange:v=>u(c,{type:v}),children:[e.jsx(ce,{className:"h-8 text-xs",children:e.jsx(oe,{})}),e.jsx(de,{children:Wt.map(v=>e.jsx(Z,{value:v.value,children:n(v.labelKey)},v.value))})]})]}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",onClick:()=>A(v=>v.filter((j,M)=>M!==c)),children:e.jsx(qs,{className:"h-3.5 w-3.5"})})]},c))]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[a&&e.jsx(C,{variant:"outline",size:"sm",onClick:()=>i(!1),children:n("common.cancel")}),e.jsxs(C,{size:"sm",onClick:N,disabled:k,children:[k&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),n("common.save")]})]})]})]})},Da=({churchId:t,caseId:s,subjects:a,onRecorded:r})=>{const{t:n,i18n:l}=K("counseling"),{user:i}=fs(),h=l.language.startsWith("en")?"en":"es",[p,g]=x.useState(!1),[y,d]=x.useState(!1),[A,k]=x.useState(!1),[o,b]=x.useState(""),[m,f]=x.useState(1),[u,N]=x.useState([]);x.useEffect(()=>{p&&(d(!0),N(a.length===1?[a[0].id]:[]),Ie(t).then(c=>{b((c==null?void 0:c.consentText)||Ss[h]),f((c==null?void 0:c.consentVersion)??1)}).catch(c=>{console.error(c),E.error(n("common.loadError"))}).finally(()=>d(!1)))},[p,t,h]);const P=c=>N(v=>v.includes(c)?v.filter(j=>j!==c):[...v,c]),w=async()=>{if(!(!(i!=null&&i.uid)||u.length===0)){k(!0);try{const c={version:m,textSnapshot:o,acceptedAt:new Date,method:"in-person",recordedBy:i.uid,subjectPersonIds:u};await ht(s,c),r(c),E.success(n("consent.recorded")),g(!1)}catch(c){console.error(c),E.error(n("consent.error"))}finally{k(!1)}}};return e.jsxs(De,{open:p,onOpenChange:g,children:[e.jsx(Be,{asChild:!0,children:e.jsxs(C,{variant:"outline",size:"sm",className:"gap-1.5",children:[e.jsx(gs,{className:"h-4 w-4"}),n("consent.record")]})}),e.jsxs(Fe,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Re,{children:[e.jsx(ze,{children:n("consent.title")}),e.jsx(Ke,{children:n("consent.hint")})]}),y?e.jsx("div",{className:"flex justify-center py-8 text-muted-foreground",children:e.jsx(W,{className:"h-5 w-5 animate-spin"})}):e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsx("div",{className:"rounded-md border border-border bg-muted/40 p-3 max-h-72 overflow-y-auto",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:o})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:n("consent.whoAccepts")}
1),e.jsx("div",{className:"space-y-2",children:a.map(c=>e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(Le,{checked:u.includes(c.id),onCheckedChange:()=>P(c.id)}),c.name]},c.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("consent.inPersonNote")})]}),e.jsxs($e,{children:[e.jsx(C,{variant:"outline",onClick:()=>g(!1),disabled:A,children:n("common.cancel")}),e.jsxs(C,{onClick:w,disabled:A||y||u.length===0,children:[A&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),n("consent.confirm")]})]})]})]})},Fa=({churchId:t,caseId:s,subjects:a,consent:r,required:n,onRecorded:l,onSatisfiedChange:i})=>{const{t:h,i18n:p}=K("counseling"),g=p.language.startsWith("en"),y=g?Y:V,d=g?"MMM d, yyyy":"d 'de' MMM yyyy",A=g?"en":"es",[k,o]=x.useState([]),[b,m]=x.useState(null),[f,u]=x.useState(!0),[N,P]=x.useState(null),w=x.useCallback(async()=>{try{const[F,H]=await Promise.all([pt(t,s),Ie(t).catch(()=>null)]);o(F),m(H)}catch(F){console.error(F)}finally{u(!1)}},[t,s]);x.useEffect(()=>{w()},[w]);const c=new Set(k.filter(F=>F.status==="accepted").map(F=>F.personId)),v=a.length>0&&a.every(F=>c.has(F.id)),j=!!r||v;x.useEffect(()=>{i(j)},[j,i]);const M=async F=>{P(F.id);try{await gt({churchId:t,caseId:s,personId:F.id,personName:F.name,version:(b==null?void 0:b.consentVersion)??1,textSnapshot:(b==null?void 0:b.consentText)||Ss[A]}),await w(),E.success(h("consent.sent"))}catch(H){console.error(H),E.error(h("consent.error"))}finally{P(null)}},z=async F=>{try{await jt(F),o(H=>H.filter(B=>B.id!==F))}catch(H){console.error(H)}},R=a.filter(F=>!k.some(H=>H.personId===F.id));return e.jsxs(O,{className:`p-4 ${j?"":"border-amber-300 dark:border-amber-800"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(gs,{className:"h-4 w-4"}),h("consent.title")]}),r?e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:h("consent.recordedAt",{version:r.version,date:q(r.acceptedAt,d,{locale:y})})}):j?e.jsxs("p",{className:"text-xs text-emerald-700 dark:text-emerald-500 mt-1 inline-flex items-center gap-1",children:[e.jsx(Te,{className:"h-3 w-3"}),h("consent.allAccepted")]}):e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-500 mt-1",children:h(n?"consent.blocked":"consent.missing")})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[!r&&!v&&e.jsx(Da,{churchId:t,caseId:s,subjects:a,onRecorded:l}),e.jsx(ne,{caseId:s,doc:"acuerdo"})]})]}),!r&&e.jsxs("div",{className:"mt-3 border-t border-border pt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:h("consent.sendHint")}),f?e.jsx("p",{className:"text-sm text-muted-foreground",children:"â¦"}):e.jsxs(e.Fragment,{children:[R.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:R.map(F=>e.jsxs(C,{variant:"outline",size:"sm",className:"gap-1.5",onClick:()=>M(F),disabled:N===F.id,children:[N===F.id?e.jsx(W,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ge,{className:"h-3.5 w-3.5"}),h("consent.sendTo",{name:F.name})]},F.id))}),k.length>0&&e.jsx("ul",{className:"space-y-1.5",children:k.map(F=>e.jsxs("li",{className:"flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"text-sm inline-flex items-center gap-2 flex-wrap",children:[e.jsx(qe,{className:"h-3 w-3 text-muted-foreground"}),F.personName??F.personId,F.status==="accepted"?e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium bg-emerald-100 text-emerald-800 dark:bg-emerald-900/40 dark:text-emerald-300",children:h("consent.accepted",{date:F.acceptedAt?q(F.acceptedAt,d,{locale:y}):""})}):e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300",children:h("consent.waiting")})]}),F.status!=="accepted"&&e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",onClick:()=>z(F.id),children:e.jsx(X,{className:"h-3.5 w-3.5"})})]},F.id))})]})]})]})},Ra=[{key:"what-is-bc",labelKey:"goal.base.what-is-bc",scriptureRefs:["2 Ti 3:16-17","Ro 15:14"]},{key:"disciplines",labelKey:"goal.base.disciplines",scriptureRefs:["1 Ti 4:7-8"]},{key:"gods-glory",labelKey:"goal.base.gods-glory",scriptureRefs:["1 Co 10:31","Ro 11:36"]},{key:"gospel",labelKey:"goal.base.gospel",scriptureRefs:["Ef 2:1-10","1 Co 15:1-4"]},{key:"the-heart",labelKey:"goal.base.the-heart",scriptureRefs:["Mr 7:20-23","Pr 4:23"]},{key:"heart-idols",labelKey:"goal.base.heart-idols",scriptureRefs:["Ez 14:1-5","Stg 4:1-3"]},{key:"pride",labelKey:"goal.base.pride",scriptureRefs:["Stg 4:6-10","Pr 16:18"]},{key:"sanctification",labelKey:"goal.base.sanctification",scriptureRefs:["Ef 4:22-24","Fil 2:12-13"]}],za=({churchId:t,caseId:s,topic:a,goals:r,setGoals:n,loading:l})=>{const{t:i}=K("counseling"),[h,p]=x.useState(!1),[g,y]=x.useState(!1),[d,A]=x.useState(""),[k,o]=x.useState(""),b=x.useCallback(async()=>{try{n(await ys(t,s))}catch(j){console.error(j)}},[t,s,n]),m=()=>r.length?Math.max(...r.map(j=>j.order))+1:0,f=async()=>
1{if(d.trim())try{await ss({churchId:t,caseId:s,title:d.trim(),scriptureRefs:We(k),kind:"case",order:m()}),A(""),o(""),p(!1),await b(),E.success(i("goal.saved"))}catch(j){console.error(j),E.error(i("goal.error"))}},u=async()=>{y(!0);try{const j=new Set(r.filter(R=>R.kind==="base").map(R=>R.title));let M=m();const z=Ra.filter(R=>!j.has(i(R.labelKey)));for(const R of z)await ss({churchId:t,caseId:s,title:i(R.labelKey),scriptureRefs:R.scriptureRefs,kind:"base",order:M++});await b(),E.success(i("goal.seeded",{count:z.length}))}catch(j){console.error(j),E.error(i("goal.error"))}finally{y(!1)}},N=async(j,M)=>{try{await ft(j.id,M),n(z=>z.map(R=>R.id===j.id?{...R,status:M}:R))}catch(z){console.error(z),E.error(i("goal.error"))}},P=async(j,M)=>{if((j.notes??"")!==M)try{await He(j.id,{notes:M}),n(z=>z.map(R=>R.id===j.id?{...R,notes:M}:R))}catch(z){console.error(z)}},w=async(j,M)=>{const z=j+M;if(z<0||z>=r.length)return;const R=r[j],F=r[z],H=[...r];H[j]={...F,order:R.order},H[z]={...R,order:F.order},n(H.sort((B,ee)=>B.order-ee.order));try{await Promise.all([He(R.id,{order:F.order}),He(F.id,{order:R.order})])}catch(B){console.error(B),b()}},c=async j=>{try{await Nt(j),n(M=>M.filter(z=>z.id!==j)),E.success(i("goal.deleted"))}catch(M){console.error(M),E.error(i("goal.error"))}},v=r.filter(j=>j.status!=="covered").length;return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1 flex-wrap",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(hs,{className:"h-4 w-4"}),i("goal.title"),r.length>0&&e.jsxs("span",{className:"text-muted-foreground font-normal",children:[" · ",i("goal.pendingCount",{count:v})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(C,{variant:"ghost",size:"sm",onClick:u,disabled:g,className:"gap-1 text-xs",children:[g?e.jsx(W,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Gs,{className:"h-3.5 w-3.5"}),i("goal.seedBase")]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>p(j=>!j),children:[e.jsx(le,{className:"h-4 w-4 mr-1"}),i("goal.new")]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:i("goal.hint")}),h&&e.jsxs("div",{className:"rounded-md border border-border p-3 mb-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{htmlFor:"g-title",children:i("goal.titleField")}),e.jsx(I,{id:"g-title",placeholder:i("goal.titlePlaceholder"),value:d,onChange:j=>A(j.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(G,{htmlFor:"g-scr",children:i("goal.scripture")}),e.jsx(vs,{churchId:t,topic:a,onPick:j=>o(M=>ks(M,j))})]}),e.jsx(I,{id:"g-scr",placeholder:i("assignment.scripturePlaceholder"),value:k,onChange:j=>o(j.target.value)})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>{p(!1),A(""),o("")},children:i("common.cancel")}),e.jsx(C,{size:"sm",onClick:f,disabled:!d.trim(),children:i("common.save")})]})]}),l?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"â¦"}):r.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:i("goal.empty")}):e.jsx("ul",{className:"space-y-3",children:r.map((j,M)=>{const z=qt(j.status);return e.jsx("li",{className:`border-b border-border last:border-0 pb-3 last:pb-0 ${j.status==="covered"?"opacity-60":""}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"text-sm font-medium",children:j.title}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${z.badgeClass}`,children:i(z.labelKey)}),j.kind==="base"&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-muted text-muted-foreground",children:i("goal.baseBadge")})]}),j.scriptureRefs&&j.scriptureRefs.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 inline-flex items-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"}),j.scriptureRefs.join(" · ")]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(J,{value:j.notes??"",onChange:R=>P(j,R),placeholder:i("goal.notesPlaceholder"),"aria-label":i("goal.notesPlaceholder"),className:"text-sm"})})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx(C,{variant:"ghost",size:"icon",className:"h-5 w-6 text-muted-foreground",onClick:()=>w(M,-1),disabled:M===0,title:i("goal.moveUp"),children:e.jsx(Bs,{className:"h-3 w-3"})}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-5 w-6 text-muted-foreground",onClick:()=>w(M,1),disabled:M===r.length-1,title:i("goal.moveDown"),children:e.jsx(Q,{className:"h-3 w-3"})})]}),e.jsxs(ie,{value:j.status,onValueChange:R=>N(j,R),children:[e.jsx(ce,{className:"w-[130px] h-8 text-xs",children:e.jsx(oe,{})}),e.jsx(de,{children:Gt.map(R=>e.jsx(Z,{value:R.value,children:i(R.labelKey)},R.value))})]}),e.jsxs(pe,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground",children:e.jsx(X,{className:"h-3.5 w-3.5"})})}),e.jsxs(je,{children:[e.jsxs(fe,{children:[e.jsx(Ne,{children:i("goal.deleteTitle")}),e.jsx(ye,{children:i("session.deleteDesc")})]}),e.jsxs(be,{children:[e.jsx(we,{children:i("common.cancel")}),e.jsx(ve,{onClick:()=>c(j.id),children:i("common.delete")})]})]})]})]})]})},j.id)})}),r.some(j=>j.kind==="base")&&e.jsx("p",{className:"mt-3 text-xs text-muted-foreground border-t border-border pt-3",children:i("goal.baseWarning")})]})};const Ka={none:"text-muted-foreground",pending:"text-blue-700 dark:text-blue-300",done:"text-emerald-700 dark:text-emerald-300",partial:"text-amber-700 dark:text-amber-300","not-done":"text-red-700 dark:text-red-300 font-medium"},La=({items:t})=>t.length===0?e.jsx("span",{className:"text-muted-foreground",children:"â"}):e.jsx("ul",{className:"space-y-0.5",children:t.map((s,a)=>e.jsx("li",{children:s},a))}),$a=({sessions:t,assignments:s,goals:a})=>{var k;const{t:r,i18n:n}=K("counseling"),l=(k=n.language)==null?void 0:k.startsWith("en"),i=l?Y:V,[h,p]=x.useState(!1),g=x.useMemo(()=>Bt(t,s,a),[t,s,a]),y=g.some(o=>o.inStreak),d=()=>{const o=()=>{document.body.classList.remove("printing-session-log"),window.removeEventListener("afterprint",o)};window.addEventListener("afterprint",o),document.body.classList.add("printing-session-log"),window.print()},A=[{key:"reading",labelKey:"log.row.reading",get:o=>o.reading},{key:"memorization",labelKey:"log.row.memorization",get:o=>o.memorization},{key:"other",labelKey:"log.row.other",get:o=>o.other},{key:"recited",labelKey:"log.row.recited",get:o=>o.recited.map(b=>q(b,l?"MMM d":"d MMM",{locale:i}))},{key:"hope",labelKey:"log.row.hope",get:o=>o.hope?[o.hope]:[]},{key:"taught",labelKey:"log.row.taught",get:o=>o.taught}];return e.jsxs(O,{className:"p-4 session-log-card",children:[e.jsxs("button",{type:"button",onClick:()=>p(o=>!o),className:"w-full flex items-center justify-between gap-2 text-left",children:[e.jsxs("h3",{className:"text-sm font-medium inline-flex items-center gap-1.5",children:[e.jsx(Is,{className:"h-4 w-4"}),r("log.title"),e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:r("log.sessionsCount",{count:g.length})})]}),e.jsxs("span",{className:"inline-flex items-center gap-2",children:[y&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-red-700 dark:text-red-300",children:[e.jsx(Ee,{className:"h-3.5 w-3.5"}),r("log.streakBadge")]}),h?e.jsx(Q,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Pe,{className:"h-4 w-4 text-muted-foreground"})]})]}),h&&e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 print:hidden",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:r("log.hint")}),g.length>0&&e.jsxs(C,{variant:"outline",size:"sm",onClick:d,className:"gap-1.5 flex-shrink-0",children:[e.jsx(os,{className:"h-4 w-4"}),r("log.print")]})]}),y&&e.jsxs("p",{className:"text-xs text-red-700 dark:text-red-300 inline-flex items-start gap-1.5",children:[e.jsx(Ee,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}),r("log.streakHint")]}),g.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:r("log.empty")}):e.jsx("div",{className:"overflow-x-auto session-log-scroll",children:e.jsxs("table",{className:"text-xs border-collapse min-w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left font-medium p-2 align-bottom sticky left-0 bg-card z-10 border-b border-border",children:r("log.row.session")}),g.map((o,b)=>e.jsxs("th",{className:`text-left font-medium p-2 align-bottom border-b border-border min-w-[11rem] ${o.inStreak?"bg-red-50 dark:bg-red-950/30":""}`,children:[e.jsx("div",{children:r("log.sessionN",{n:b+1})}),e.jsxs("div",{className:"font-normal text-muted-foreground",children:[q(o.occurredAt,l?"MMM d":"d MMM",{locale:i}),o.kind!=="ordinary"&&` · ${r(`session.kind.${o.kind}`)}`]})]},o.sessionId))]})}),e.jsxs("tbody",{children:[A.map(o=>e.jsxs("tr",{className:"align-top",children:[e.jsx("th",{scope:"row",className:"text-left font-normal text-muted-foreground p-2 sticky left-0 bg-card z-10 border-b border-border whitespace-nowrap",children:r(o.labelKey)}),g.map(b=>e.jsx("td",{className:`p-2 border-b border-border ${b.inStreak?"bg-red-50 dark:bg-red-950/30":""}`,children:e.jsx(La,{items:o.get(b)})},b.sessionId))]},o.key)),e.jsxs("tr",{className:"align-top",children:[e.jsx("th",{scope:"row",className:"text-left font-normal text-muted-foreground p-2 sticky left-0 bg-card z-10 whitespace-nowrap",children:r("log.row.compliance")}),g.map(o=>e.jsx("td",{className:`p-2 ${o.inStreak?"bg-red-50 dark:bg-red-950/30":""} ${Ka[o.compliance]}`,children:r(`log.compliance.${o.compliance}`)},o.sessionId))]})]})]})})]})]})},Oa=({churchId:t,caseId:s,topic:a})=>{const{t:r}=K("counseling"),[n,l]=x.useState([]),[i,h]=x.useState(!0),[p,g]=x.use
1State(!1),[y,d]=x.useState(""),[A,k]=x.useState(""),[o,b]=x.useState(""),[m,f]=x.useState(!1);x.useEffect(()=>{yt(t,s).then(l).catch(c=>console.error("[patterns]",c)).finally(()=>h(!1))},[t,s]);const u=async()=>{if(!(!y.trim()||!A.trim())){f(!0);try{const c=await bt({churchId:t,caseId:s,putOff:y.trim(),putOn:A.trim(),scriptureRefs:We(o)});l(v=>[...v,{id:c,churchId:t,caseId:s,putOff:y.trim(),putOn:A.trim(),scriptureRefs:We(o),status:"active",createdAt:new Date}]),d(""),k(""),b(""),g(!1),E.success(r("pattern.saved"))}catch(c){console.error(c),E.error(r("pattern.error"))}finally{f(!1)}}},N=async c=>{const v=c.status==="active"?"achieved":"active";try{await ts(c.id,{status:v}),l(j=>j.map(M=>M.id===c.id?{...M,status:v}:M))}catch(j){console.error(j),E.error(r("pattern.error"))}},P=async(c,v)=>{try{await ts(c.id,{notes:v}),l(j=>j.map(M=>M.id===c.id?{...M,notes:v}:M))}catch(j){console.error(j)}},w=async c=>{try{await wt(c),l(v=>v.filter(j=>j.id!==c)),E.success(r("pattern.deleted"))}catch(v){console.error(v),E.error(r("pattern.error"))}};return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1",children:[e.jsx("h3",{className:"text-sm font-medium",children:r("pattern.title")}),!p&&e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),r("pattern.new")]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:r("pattern.hint")}),p&&e.jsxs("div",{className:"rounded-md border border-border p-3 mb-3 space-y-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{className:"text-xs",children:r("pattern.putOff")}),e.jsx(I,{value:y,onChange:c=>d(c.target.value),placeholder:r("pattern.putOffPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(G,{className:"text-xs",children:r("pattern.putOn")}),e.jsx(I,{value:A,onChange:c=>k(c.target.value),placeholder:r("pattern.putOnPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(G,{className:"text-xs",children:r("assignment.scripture")}),e.jsx(vs,{churchId:t,topic:a,onPick:c=>b(v=>ks(v,c))})]}),e.jsx(I,{value:o,onChange:c=>b(c.target.value),placeholder:r("assignment.scripturePlaceholder")})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>g(!1),disabled:m,children:r("common.cancel")}),e.jsxs(C,{size:"sm",onClick:u,disabled:m||!y.trim()||!A.trim(),children:[m&&e.jsx(W,{className:"h-4 w-4 mr-2 animate-spin"}),r("common.save")]})]})]}),i?e.jsx("div",{className:"py-4 text-center",children:e.jsx(W,{className:"h-4 w-4 animate-spin inline text-muted-foreground"})}):n.length===0&&!p?e.jsx("p",{className:"text-sm text-muted-foreground py-3 text-center",children:r("pattern.empty")}):e.jsx("ul",{className:"space-y-3",children:n.map(c=>e.jsxs("li",{className:`rounded-md border p-3 ${c.status==="achieved"?"border-emerald-300 bg-emerald-50/50 dark:bg-emerald-900/10":"border-border"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm min-w-0 flex-wrap",children:[e.jsx("span",{className:"line-through text-muted-foreground",children:c.putOff}),e.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"font-medium",children:c.putOn})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7",title:c.status==="active"?r("pattern.markAchieved"):r("pattern.reactivate"),onClick:()=>N(c),children:c.status==="active"?e.jsx(Te,{className:"h-4 w-4 text-emerald-600"}):e.jsx(ps,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs(pe,{children:[e.jsx(ge,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",children:e.jsx(X,{className:"h-3.5 w-3.5"})})}),e.jsxs(je,{children:[e.jsxs(fe,{children:[e.jsx(Ne,{children:r("pattern.deleteTitle")}),e.jsx(ye,{children:r("session.deleteDesc")})]}),e.jsxs(be,{children:[e.jsx(we,{children:r("common.cancel")}),e.jsx(ve,{onClick:()=>w(c.id),children:r("common.delete")})]})]})]})]})]}),c.scriptureRefs&&c.scriptureRefs.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 inline-flex items-center gap-1",children:[e.jsx(re,{className:"h-3 w-3"}),c.scriptureRefs.join(" · ")]}),e.jsx("div",{className:"mt-2",children:e.jsx(J,{value:c.notes??"",onChange:v=>P(c,v),placeholder:r("pattern.notesPlaceholder"),"aria-label":r("pattern.notesPlaceholder"),minLines:2,className:"text-sm"})})]},c.id))})]})},Ha={done:"bg-emerald-500",partial:"bg-amber-500","not-done":"bg-red-500",assigned:"bg-gray-300 dark:bg-gray-600"},_a=({assignments:t})=>{const{t:s}=K("counseling"),a=x.useMemo(()=>
1{const n={done:0,partial:0,"not-done":0,assigned:0};t.forEach(h=>{n[h.status]=(n[h.status]??0)+1});const l=n.done+n.partial+n["not-done"],i=l>0?Math.round((n.done+n.partial*.5)/l*100):null;return{c:n,reviewed:l,rate:i}},[t]);if(t.length===0)return null;const r=[...t].sort((n,l)=>n.assignedAt.getTime()-l.assignedAt.getTime());return e.jsxs(O,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:s("compliance.title")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:s("compliance.hint")})]}),a.rate!==null&&e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-2xl font-semibold leading-none",children:[a.rate,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("compliance.rate")})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-3",children:r.map(n=>{const l=bs(n.status);return e.jsx("span",{className:`h-3 w-3 rounded-full ${Ha[n.status]??"bg-gray-300"}`,title:`${n.title} â ${s(l.labelKey)}`},n.id)})}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-emerald-500 mr-1"}),s("assignment.status.done"),": ",e.jsx("strong",{children:a.c.done})]}),e.jsxs("span",{children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-amber-500 mr-1"}),s("assignment.status.partial"),": ",e.jsx("strong",{children:a.c.partial})]}),e.jsxs("span",{children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-red-500 mr-1"}),s("assignment.status.not-done"),": ",e.jsx("strong",{children:a.c["not-done"]})]}),e.jsxs("span",{children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-gray-400 mr-1"}),s("assignment.status.assigned"),": ",e.jsx("strong",{children:a.c.assigned})]})]})]})},Wa=["admission","plan","sessions","between","closure"],cn=()=>{var Ye;const{t}=K("counseling"),{caseId:s}=Vs(),{userData:a}=fs(),{can:r}=Js(),n=he(),l=a==null?void 0:a.churchId,i=r("counselingAdmin"),h=r("counseling")||i,[p,g]=x.useState(null),[y,d]=x.useState([]),[A,k]=x.useState([]),[o,b]=x.useState(!0),[m,f]=x.useState(!1),[u,N]=x.useState(null),[P,w]=x.useState([]),[c,v]=x.useState(!1),[j,M]=x.useState([]),[z,R]=x.useState([]),[F,H]=x.useState(null),B=x.useCallback(async()=>{if(!l||!s||!h){b(!1);return}b(!0);try{const[T,S]=await Promise.all([vt(l,s),Ie(l).catch(()=>null)]);if(g(T),N(S),T){const[L,_,Se,Ms]=await Promise.all([kt(l,s),St(l,s),ys(l,s),Ct(l,s).catch(()=>[])]);d(L),k(_),w(Se),R(Ms)}}catch(T){console.error(T),E.error(t("common.loadError"))}finally{b(!1)}},[l,s,h,t]);x.useEffect(()=>{B()},[B]);const ee=async(T,S)=>{try{await At(T,S),k(L=>L.map(_=>{var Se;return _.id===T.id?{..._,structure:{..._.structure,memorization:{...(Se=_.structure)==null?void 0:Se.memorization,recitedAt:S}}}:_}))}catch(L){console.error(L),E.error(t("common.error"))}},D=async T=>{if(s){if(T==="closed"){f(!0);return}try{await Tt(s,T),g(S=>S&&{...S,status:T,closedAt:void 0,closingNote:void 0}),E.success(t("case.statusUpdated"))}catch(S){console.error(S),E.error(t("case.statusError"))}}},$=async T=>{if(s)try{await Et(l,s,T||void 0),g(S=>S&&{...S,status:"closed",closedAt:new Date,closingNote:T||void 0}),E.success(t("case.statusUpdated"))}catch(S){console.error(S),E.error(t("case.statusError"))}},U=async(T,S)=>{try{await as(T,S),k(L=>L.map(_=>_.id===T?{..._,status:S}:_)),E.success(t("assignment.statusUpdated"))}catch(L){console.error(L),E.error(t("assignment.statusError"))}},me=async(T,S)=>{if((T.review??"")!==S)try{await as(T.id,T.status,S),k(L=>L.map(_=>_.id===T.id?{..._,review:S,reviewedAt:new Date}:_))}catch(L){console.error(L),E.error(t("assignment.statusError"))}},Cs=async T=>{try{await Mt(T),k(S=>S.filter(L=>L.id!==T)),E.success(t("assignment.deleted"))}catch(S){console.error(S),E.error(t("common.loadError"))}},As=async T=>{try{await Pt(l,s,T),d(S=>S.filter(L=>L.id!==T)),E.success(t("session.deleted"))}catch(S){console.error(S),E.error(t("session.deleteError"))}},se=[...j].filter(T=>T.status==="submitted").sort((T,S)=>{var L,_;return(((L=S.submittedAt)==null?void 0:L.getTime())??0)-(((_=T.submittedAt)==null?void 0:_.getTime())??0)})[0],Ts=(p==null?void 0:p.status)==="closed"?"closure":c?"sessions":"admission",Ue=F??Ts,Es=x.useMemo(()=>se?ta(se.sections,t):void 0,[se==null?void 0:se.id,se,t]);if(!h)return e.jsx("div",{className:"p-4 md:p-6",children:e.jsx(O,{className:"p-8 text-center text-muted-foreground",children:t("noAccess")})});if(o)return e.jsxs("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:[e.jsx(W,{className:"h-5 w-5 animate-spin mr-2"}),"â¦"]});if(!p)return e.jsxs("div",{className:"p-4 md:p-6",children:[e.jsxs(C,{variant:"ghost",onClick:()=>n("/app/consejeria"),children:[e.jsx(xs,{className:"h-4 w-4 mr-2"}),t("case.back")]}),e.jsx(O,{className:"p-8 text-center text-muted-foreground mt-4",children:t("case.notFound")})]});const ke=(p.subjectRefs??[]).map((T,S)=>{var L;return{id:T,name:((L=p.subjectNames)==null?void 0:L[S])??T}}),te=p.status==="closed",Ve=!c&&(u==null?void 0:u.requireConsent)===!0;return e.jsxs("div",{className:"p-4 md:p-6 space-y-4",children:[e.jsx(Sa,{closureCriteria:(Ye=p.closure)==null?void 0:Ye.criteria,open:m,onOpenChange:f,onConfirm:$}),e.jsx(ya,{settings:u,onUnlocked:B}),e.jsxs(Ys,{value:Ue,onValueChange:T=>
1H(T),className:"w-full",children:[e.jsx(pa,{kase:p,caseId:s,consentBlocks:Ve,onStatus:D,onPatch:T=>g(S=>S&&{...S,...T}),pulse:e.jsx(fa,{assignments:A,entries:z}),tabs:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Qs,{className:"h-auto justify-start gap-1 rounded-none bg-transparent p-0 flex-wrap",children:Wa.map(T=>e.jsx(Xs,{value:T,className:`relative rounded-none border-b-2 border-transparent bg-transparent px-3 py-2.5 2 text-sm font-medium text-muted-foreground shadow-none 3 data-[state=active]:border-primary data-[state=active]:bg-transparent 4 data-[state=active]:text-foreground data-[state=active]:shadow-none`,children:t(`phase.${T}`)},T))}),e.jsx(ga,{section:Ue,caseId:s})]})}),e.jsx("div",{className:"mt-4",children:e.jsxs("div",{className:"min-w-0 space-y-4",children:[e.jsxs(xe,{value:"admission",className:"mt-0 space-y-4",children:[s&&l&&e.jsx(Fa,{churchId:l,caseId:s,subjects:ke,consent:p.consent,required:(u==null?void 0:u.requireConsent)===!0,onRecorded:T=>g(S=>S&&{...S,consent:T}),onSatisfiedChange:v}),l&&s&&e.jsx(Ea,{churchId:l,caseId:s,subjects:ke,onFormsChange:M}),s&&e.jsx(Ca,{caseId:s,intake:p.intake,suggested:Es,onSaved:T=>g(S=>S&&{...S,intake:T})}),s&&e.jsx(Aa,{caseId:s,notes:p.categoryNotes,riskFlags:p.riskFlags,riskProtocolText:u==null?void 0:u.riskProtocolText,onSaved:T=>g(S=>S&&{...S,...T})})]}),e.jsxs(xe,{value:"plan",className:"mt-0 space-y-4",children:[l&&s&&e.jsx(za,{churchId:l,caseId:s,topic:p.topic,goals:P,setGoals:w,loading:o}),s&&e.jsx(va,{caseId:s,value:p.disciplineGoals,disabled:te,onSaved:T=>g(S=>S&&{...S,disciplineGoals:T})}),l&&s&&e.jsx(Oa,{churchId:l,caseId:s,topic:p.topic})]}),e.jsx(xe,{value:"sessions",className:"mt-0 space-y-4",children:e.jsx(xa,{caseId:s,sessions:y,consentBlocks:Ve,isClosed:te,onDelete:As})}),e.jsxs(xe,{value:"between",className:"mt-0 space-y-4",children:[s&&!te&&e.jsx(Pa,{caseId:s,goals:P,plan:p.nextSessionPlan,onSaved:T=>g(S=>S&&{...S,nextSessionPlan:T})}),l&&s&&e.jsx(Ma,{churchId:l,caseId:s}),e.jsx(ma,{churchId:l,caseId:s,topic:p.topic,subjects:ke,assignments:A,isClosed:te,onCreated:B,onStatus:U,onReview:me,onRecited:ee,onDelete:Cs}),e.jsx(_a,{assignments:A})]}),e.jsxs(xe,{value:"closure",className:"mt-0 space-y-4",children:[te&&!p.purgeSummary&&(u==null?void 0:u.retention)&&u.retention.mode!=="retain"&&e.jsxs(O,{className:"p-4 flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("retention.cardTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 max-w-xl",children:t("retention.cardHint",{days:u.retention.daysAfterClose})})]}),e.jsx(ba,{kase:p,mode:u.retention.mode,onPurged:B})]}),p.purgeSummary&&e.jsx(wa,{summary:p.purgeSummary}),s&&!te&&e.jsx(ka,{churchId:l,caseId:s,value:p.closure,subjects:ke,onSaved:T=>g(S=>S&&{...S,closure:T})}),y.length>0&&e.jsx($a,{sessions:y,assignments:A,goals:P})]})]})})]})]})};export{cn as CaseDetailPage,cn 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.