1import{j as e,c8 as R,cf as D,L as _,be as $,bp as K,u as V}from"./vendor-ui-fc56ca80.js";import{e as W,r as d}from"./vendor-react-f9ccc48d.js";import{am as q,h as z,t as y,af as G,B as J,ae as Q,ag as X,ah as N,n as Y}from"./index-90016d22.js";import{u as Z}from"./useCapability-421f7f8b.js";import{g as ee}from"./familyService-10e68e34.js";import{g as b,l as te,D as se}from"./pulse-9968bf17.js";import{c as ae}from"./cadence-b1eebb81.js";import{u as L,L as ne,ac as re}from"./vendor-utils-323b9898.js";import"./vendor-firebase-a557f106.js";import"./vendor-charts-9af8b7c0.js";import"./userService-352fd3e3.js";const ie=new Set(["red","yellow","white"]),oe=({due:s})=>{const{t:m}=L("pastoralCare");if(s.state==="ok")return null;const i={overdue:{text:m("due.overdue",{days:s.daysOverdue}),cls:"bg-red-100 text-red-800 dark:bg-red-900/40 dark:text-red-300"},"due-soon":{text:m("due.dueSoon"),cls:"bg-amber-100 text-amber-800 dark:bg-amber-900/40 dark:text-amber-300"},never:{text:m("due.never"),cls:"bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300"}}[s.state];return e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${i.cls}`,children:i.text})},ye=()=>{const{t:s,i18n:m}=L("pastoralCare"),C=m.language.startsWith("en")?ne:q,{user:i,userData:o}=z(),{can:v}=Z(),k=W(),u=v("pastoralCareAdmin"),h=v("pastoralCare")||u,[x,B]=d.useState([]),[F,f]=d.useState(!0),[c,O]=d.useState(u?"all":"mine"),[g,P]=d.useState(!1);d.useEffect(()=>{(async()=>{if(!(o!=null&&o.churchId)||!h){f(!1);return}f(!0);try{const[t,r]=await Promise.all([ee(o.churchId),te(o.churchId)]),a=new Map(r.map(l=>[l.familyId,l]));B(t.map(l=>{const p=a.get(l.id);return{family:l,care:p,due:ae(p)}}))}catch(t){console.error(t),V.error(s("toast.loadFlockError"))}finally{f(!1)}})()},[o==null?void 0:o.churchId,h,s]);const U=n=>{var t;return n.due.rank>=2||ie.has(((t=n.care)==null?void 0:t.status)??se)},j=d.useMemo(()=>{const n=i==null?void 0:i.uid;let t=x;return c==="mine"?t=x.filter(r=>{var a;return((a=r.care)==null?void 0:a.careAssigneeId)===n}):c==="unassigned"&&(t=x.filter(r=>{var a;return!((a=r.care)!=null&&a.careAssigneeId)})),g&&(t=t.filter(U)),[...t].sort((r,a)=>{var w,A,T,S,I,E;if(r.due.rank!==a.due.rank)return a.due.rank-r.due.rank;const l=b((w=r.care)==null?void 0:w.status).priority,p=b((A=a.care)==null?void 0:A.status).priority;if(l!==p)return p-l;const H=((S=(T=r.care)==null?void 0:T.lastContactAt)==null?void 0:S.getTime())??0,M=((E=(I=a.care)==null?void 0:I.lastContactAt)==null?void 0:E.getTime())??0;return H-M})},[x,c,g,i==null?void 0:i.uid]);return h?e.jsxs("div",{className:"p-4 md:p-6 space-y-4",children:[e.jsx(G,{title:s("title"),description:s("subtitle"),icon:e.jsx(R,{className:"h-5 w-5"}),badge:s("familiesCount",{count:j.length}),action:u?e.jsxs(J,{variant:"outline",onClick:()=>k("/app/cuidado-pastoral/asignacion"),children:[e.jsx(D,{className:"h-4 w-4 mr-2"}),s("assignmentButton")]}):void 0}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx(Q,{value:c,onValueChange:n=>O(n),children:e.jsxs(X,{children:[e.jsx(N,{value:"mine",children:s("tabs.mine")}),u&&e.jsx(N,{value:"all",children:s("tabs.all")}),u&&e.jsx(N,{value:"unassigned",children:s("tabs.unassigned")})]})}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground cursor-pointer",children:[e.jsx(Y,{checked:g,onCheckedChange:n=>P(!!n)}),s("attentionOnly")]})]}),F?e.jsxs("div",{className:"flex items-center justify-center py-16 text-muted-foreground",children:[e.jsx(_,{className:"h-5 w-5 animate-spin mr-2"}),"â¦"]}):j.length===0?e.jsx(y,{className:"p-8 text-center text-muted-foreground",children:s(c==="mine"?"empty.mine":c==="unassigned"?"empty.unassigned":g?"empty.attention":"empty.none")}):e.jsx("div",{className:"space-y-2",children:j.map(({family:n,care:t,due:r})=>{const a=b(t==null?void 0:t.status);return e.jsxs(y,{className:"p-4 flex items-center justify-between cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>k(`/app/cuidado-pastoral/${n.id}`),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-lg",title:s(a.labelKey),children:a.emoji}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"font-medium truncate",children:n.name}),e.jsx(oe,{due:r})]}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-2 flex-wrap",children:[e.jsx("span",{children:t!=null&&t.lastContactAt?s("lastContact",{time:re(t.lastContactAt,{addSuffix:!0,locale:C})}):s("noContact")}),(t==null?void 0:t.careAssigneeName)&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx($,{className:"h-3 w-3"}),t.careAssigneeName]})]})]})]}),e.jsx(K,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"})]},n.id)})})]}):e.jsx("div",{className:"p-4 md:p-6",children:e.jsx(y,{className:"p-8 text-center text-muted-foreground",children:s("noAccess")})})};export{ye as MyFlockPage,ye 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.