1import{c as zs,j as e,a as $,b$ as Fs,c0 as Is,l as ke,c1 as Es,c2 as yt,c3 as Je,c4 as Ne,h as Kt,e as kt,r as b,n as Te,a5 as Me,D as vt,f as Ct,bV as _t,g as St,a$ as Pt,B as K,i as J,b as pe,C as Mt,bW as Dt,bH as Rs,ab as At,a8 as Jt,Q as Ee,U as Re,V as Be,W as Oe,Y as je,aU as tt,v as Bs,F as va,t as es,M as $t,a7 as qn,X as Ca,T as _a,I as Ot,_ as Ps,R as Js,x as Os,aC as $s,d as Gn,aN as Kn,cr as Wt,cs as Ut,ct as Vt,cu as qt,k as Xn,s as Zn,aI as Qn,q as Jn,y as ea}from"./index-5a305ee0.js";import{A as ei,a as ti,b as si}from"./alert-ab0441db.js";import{P as ai}from"./PageHeader-b61fa5c1.js";import{u as ye}from"./AdminLanguageContext-1bc84678.js";import{u as Sa}from"./ConfirmDialog-ae4f6333.js";import{g as $e,p as ni,n as Hs,b as ta,f as ii,l as Pa,d as li,e as ps,s as oi,t as us,a as ri,h as ci,i as di,j as mi,k as pi,F as ui,N as Ma,m as Xt,o as sa,q as Da,C as Zt,S as Aa,r as gi,L as xi,u as hi,v as gs}from"./intentionTypeMapping-6da19a88.js";import{B as Qe}from"./badge-630f2f4b.js";import{n as aa}from"./massScheduling-1190a6bf.js";import{P as Ta}from"./pencil-d4008fb2.js";import{m as wt,h as La,b as Ge,c as qe,s as za,j as mt,e as Ht,d as Fa,P as Ys,k as Ia,g as fi,a as na,M as bi}from"./intentionsFinance-d7df555a.js";import{i as yi,t as ji,l as wi}from"./priestLedger-93064791.js";import{L as Ws}from"./layers-365992e0.js";import{C as lt,c as pt,d as Tt,a as ot}from"./card-67c4f3a7.js";import{p as Ea,e as Ra,f as Ba,i as Oa,T as ia,E as Ni,C as ki}from"./typeable-date-picker-9f7aab4b.js";import{f as be}from"./format-03d6161e.js";import{p as ts}from"./pl-98cf88ba.js";import{A as vi}from"./arrow-up-d4c2a096.js";import{A as Ci}from"./arrow-down-3bce4f4f.js";import{C as _i}from"./chart-pie-70d7190f.js";import{F as $a}from"./file-spreadsheet-6af62c9f.js";import{A as Si}from"./activity-53b668eb.js";import{C as Ha}from"./clock-d4570435.js";import{U as ss}from"./user-cog-d835f757.js";import{P as Pi,a as Mi,b as Di}from"./popover-d0cdc4f6.js";import{C as Ai,a as Ti,b as Li,c as zi,d as la,e as xs}from"./command-5336f159.js";import{C as Ya}from"./chevrons-up-down-5b5cd812.js";import{P as Wa}from"./pen-line-29d2a059.js";import{A as Ms}from"./arrow-right-left-d8ee8fbe.js";import{C as Ds}from"./chart-column-74653db0.js";import{F as Fi}from"./flask-conical-f14065bb.js";import{D as Ii}from"./download-93167685.js";import{S as Ei}from"./slider-2878d81c.js";import{F as Ri}from"./filter-1adf568b.js";import{C as as}from"./chevron-up-e1ce129b.js";import{W as oa}from"./wand-sparkles-24c42206.js";import{T as Ua,a as Va,b as qa,c as Ga}from"./tooltip-82e20162.js";import{T as Bi}from"./TemporalAnalysisChart-dbc2eb47.js";import{R as Oi,a as $i,T as Hi,L as Yi}from"./generateCategoricalChart-b3f26b6a.js";import{P as Wi,a as Ui}from"./PieChart-75ba57ef.js";import{I as Ka}from"./AnalyticsCardHelpers-6f706b75.js";import{C as Vi}from"./calculator-295b99c5.js";import{P as As}from"./plus-2e283f20.js";import{W as qi}from"./wallet-1d984e58.js";import{H as Xa}from"./hand-coins-69d4a30d.js";import{B as Za}from"./building-2-d31830fc.js";import{T as Gi}from"./trending-up-eca6bdaa.js";import{T as Ki}from"./trending-down-5e4e0a97.js";import{T as Xi,a as Zi,b as Yt,c as We,d as Qi,e as Ie}from"./table-089691b3.js";import{E as Ji}from"./ellipsis-fc07da14.js";import{R as el}from"./rotate-ccw-6eb9edc2.js";import{T as tl}from"./tag-97d55ef7.js";import{W as sl}from"./workflow-27b88237.js";import{U as al}from"./user-minus-2b276191.js";import{T as Qa}from"./trash-2-871b0090.js";import{R as nl,a as il}from"./radio-group-70f0fefd.js";import{B as ll}from"./banknote-ddbfe8a2.js";import{U as ol}from"./user-check-e2a1669b.js";import{U as rl}from"./user-round-36cab188.js";import"./sectionAccents-b2302496.js";import"./external-link-ec651111.js";import"./alert-dialog-b6315dbc.js";import"./calendar-1bdd3c72.js";import"./isBefore-3164bfb0.js";import"./calendar-clock-2105cc90.js";import"./circle-help-e181a303.js";import"./LineChart-92d88db4.js";import"./debounce-4607b49c.js";import"./hover-card-7a22e280.js";import"./arrow-up-a-z-9a30aba7.js";import"./arrow-down-a-z-e2afb104.js";/** 2 * @license lucide-react v0.469.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ra=zs("BadgeCheck",[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);/** 7 * @license lucide-react v0.469.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const cl=zs("CalendarRange",[["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M17 14h-6",key:"bkmgh3"}],["path",{d:"M13 18H7",key:"bb0bb7"}],["path",{d:"M7 14h.01",key:"1qa3f1"}],["path",{d:"M17 18h.01",key:"1bdyru"}]]);/** 12 * @license lucide-react v0.469.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Ja=zs("CheckCheck",[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]),bt=(s,n,a)=>typeof s=="function"?s(n,a):a;function et(s,n){return String(s).split(/(\{[a-zA-Z]+\})/g).map((a,o)=>{const i=/^\{([a-zA-Z]+)\}$/.exec(a);return i&&Object.prototype.hasOwnProperty.call(n,i[1])?e.jsx("strong",{children:n[i[1]]},o):a})}function ca(s,n){const a=(s||"pending").toLowerCase();return a==="awaiting_priest"?e.jsx(Qe,{variant:"outline",className:"whitespace-nowrap text-[11px] px-2 py-0.5 bg-orange-50 text-orange-700 border-orange-200",children:bt(n,"pages.intentions.status.awaitingPriest","Brak KapÅana")}):a==="succeeded"||a==="paid"||a==="zrealizowane"?e.jsx(Qe,{variant:"outline",className:"whitespace-nowrap text-[11px] px-2 py-0.5 bg-green-50 text-green-700 border-green-200",children:bt(n,"pages.intentions.status.succeeded","OpÅacona")}):a==="assigned"?e.jsx(Qe,{variant:"outline",className:"whitespace-nowrap text-[11px] px-2 py-0.5 bg-blue-50 text-blue-700 border-blue-200",children:bt(n,"pages.intentions.status.assigned","Przypisana")}
16):a==="cancelled"||a==="canceled"||a==="failed"||a==="anulowane"?e.jsx(Qe,{variant:"outline",className:"whitespace-nowrap text-[11px] px-2 py-0.5 bg-red-50 text-red-700 border-red-200",children:bt(n,"pages.intentions.status.cancelled","Anulowane")}):e.jsx(Qe,{variant:"outline",className:"whitespace-nowrap text-[11px] px-2 py-0.5 bg-slate-50 dark:bg-slate-900/40 text-slate-500 dark:text-slate-400 border-slate-200 dark:border-slate-800",children:bt(n,"common.pending","OczekujÄ
ce")})}function dl(s,n=!1,a,o){const i=$e(s,o);let c="bg-slate-50 dark:bg-slate-900/40 text-slate-600 dark:text-slate-300 border-slate-200 dark:border-slate-800";const t=(s||"").toLowerCase();return t==="dantis"?c="bg-teal-50 text-teal-700 border-teal-200":t.includes("mass")||t.includes("msza")?c="bg-indigo-50 text-indigo-700 border-indigo-200":t.includes("oil")||t.includes("olej")?c="bg-amber-50 text-amber-700 border-amber-200":t.includes("gregorian")?c="bg-purple-50 text-purple-700 border-purple-200":(t.includes("prayer")||t.includes("modlitwa"))&&(c="bg-sky-50 text-sky-700 border-sky-200"),e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[e.jsx(Qe,{variant:"outline",className:$("font-normal text-[10px] px-1.5 py-0.5 leading-tight whitespace-normal text-left",c),children:i}),n&&e.jsx(Qe,{variant:"outline",className:"font-semibold text-[9px] px-1.5 py-0 uppercase tracking-wide bg-rose-50 text-rose-700 border-rose-200",title:bt(a,"pages.intentions.formatting.mockTitle","Dane testowe (seed)"),children:"mock"})]})}const we=s=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN"}).format(s);function en(s){return s?String(s).replace(/^\s*Tre[Ås][Äc]\s+intencji\s*::\s*/i,"").trim():""}const ml=["succeeded","assigned","awaiting_priest","pending"],pl={succeeded:"pages.intentions.table.statusSucceeded",assigned:"pages.intentions.table.statusAssigned",awaiting_priest:"pages.intentions.table.statusAwaitingPriest",pending:"pages.intentions.table.statusPending"};function tn({status:s,onChange:n,t:a,align:o="center",saving:i=!1,className:c}){const t=(s||"pending").toLowerCase();return n?e.jsxs(Fs,{children:[e.jsx(Is,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:m=>m.stopPropagation(),title:a("pages.intentions.table.changeStatus"),"aria-label":a("pages.intentions.table.changeStatus"),className:$("group/status inline-flex items-center gap-1 rounded-full transition","focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-400 focus-visible:ring-offset-1","hover:brightness-95 disabled:opacity-60",c),disabled:i,children:[ca(s,a),i?e.jsx(ke,{className:"h-3 w-3 shrink-0 animate-spin text-slate-400"}):e.jsx(Ta,{className:"h-2.5 w-2.5 shrink-0 text-slate-400 opacity-0 transition-opacity group-hover/status:opacity-100 group-focus-visible/status:opacity-100","aria-hidden":!0})]})}),e.jsxs(Es,{align:o,className:"w-56",onClick:m=>m.stopPropagation(),children:[e.jsx(yt,{children:a("pages.intentions.table.changeStatus")}),e.jsx(Je,{}),ml.map(m=>e.jsxs(Ne,{onClick:r=>{r.stopPropagation(),m!==t&&n(m)},className:$(m===t&&"font-medium"),children:[e.jsx(Kt,{className:$("mr-2 h-4 w-4 shrink-0",m===t?"text-emerald-600":"opacity-0"),"aria-hidden":!0}),a(pl[m])]},m))]})]}):ca(s,a)}const ul=new Set(["succeeded","assigned"]),hs=1e3,gl=(s,n="PLN")=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:n}).format(Number.isFinite(s)?s:0);function da(s){return(s||"").toLowerCase().normalize("NFD").replace(/[Ì-ͯ]/g,"")}function xl({isOpen:s,onClose:n,intention:a,priests:o=[],onSuccess:i,onDuplicate:c,onSetStatus:t}){const{toast:m}=kt(),{t:r}=ye(),[y,N]=b.useState(!1),[d,v]=b.useState({priest_id:"",mass_date:"",mass_time:"",mass_city:"",mass_church:"",mass_priest_name:"",mass_count:"1"}),[k,g]=b.useState(null),[x,l]=b.useState(!1),p=k??(a==null?void 0:a.status),T=a?ul.has(p):!1;b.useEffect(()=>{g(null)},[a==null?void 0:a.id]);const R=async Y=>{if(!(!t||Y===p)){l(!0);try{const Q=await t(Y);(Q==null?void 0:Q.ok)!==!1&&g(Y)}finally{l(!1)}}},[A,P]=b.useState({cities:[],churches:[]}),[F,O]=b.useState(!1),[u,M]=b.useState([]),[h,L]=b.useState(!1),[H,w]=b.useState([]),[S,B]=b.useState(!1),[D,q]=b.useState([]),[f,W]=b.useState(!1),[te,ie]=b.useState(!1),[ae,De]=b.useState(!1),[ve,Ae]=b.useState(!1),z=b.useRef(null),ee=b.useRef(null),_e=b.useRef(null),ue=b.useCallback((Y,Q)=>
16{if(!Y.current)return;const X=Y.current.getBoundingClientRect(),se=window.innerHeight-X.bottom,ne=X.top;Q(se<280&&ne>se)},[]),[Le,rt]=b.useState(!1),He=T||Le;b.useEffect(()=>{rt(!1)},[a==null?void 0:a.id]),b.useEffect(()=>{a&&v({priest_id:a.priest_id||"",mass_date:a.mass_date||"",mass_time:a.mass_time||"",mass_city:a.mass_city||"Kraków",mass_church:a.mass_church||"",mass_priest_name:a.mass_priest_name||"",mass_count:String(wt(a))})},[a]),b.useEffect(()=>{if(!s||F)return;let Y=!1;return(async()=>{try{const[Q,X,se]=await Promise.all([Te.from("cities").select("id, name").order("name"),Te.from("churches").select("id, name, city_id").order("name"),Te.from("priest_churches").select("id, name, city_id").neq("name","")]);if(Y)return;const ne=new Map;for(const re of[...X.data??[],...se.data??[]]){const ge=(re.name||"").trim().toLowerCase();if(!ge)continue;const ce=ne.get(ge);(!ce||!ce.city_id&&re.city_id)&&ne.set(ge,re)}P({cities:Q.data??[],churches:[...ne.values()].sort((re,ge)=>re.name.localeCompare(ge.name))}),O(!0)}catch(Q){Me.error("[AssignIntentionModal] places load failed",Q)}})(),()=>{Y=!0}},[s,F]),b.useEffect(()=>{const Y=(d.mass_city||"").trim().toLowerCase();if(Y.length<3){M([]);return}const Q=A.cities.filter(X=>{var se;return(se=X.name)==null?void 0:se.toLowerCase().includes(Y)}).slice(0,10).map(X=>({id:X.id,label:X.name,value:X.name}));M(Q)},[d.mass_city,A.cities]),b.useEffect(()=>{const Y=(d.mass_priest_name||"").trim(),Q=[...o||[]].sort((se,ne)=>(se.name||"").localeCompare(ne.name||"","pl",{sensitivity:"base"}));if(Y.length<3){q(Q);return}const X=da(Y).split(/\s+/).filter(Boolean);q(Q.filter(se=>{const ne=da(se.name);return X.every(re=>ne.includes(re))}))},[d.mass_priest_name,o]),b.useEffect(()=>{const Y=(d.mass_church||"").trim().toLowerCase();if(Y.length<3){w([]);return}const Q=new Map(A.cities.map(ne=>[ne.id,ne.name])),X=(d.mass_city||"").trim().toLowerCase(),se=A.churches.filter(ne=>{var re;return(re=ne.name)==null?void 0:re.toLowerCase().includes(Y)}).map(ne=>{const re=ne.city_id?Q.get(ne.city_id):null,ge=!!(re&&X&&re.toLowerCase()===X);return{id:ne.id,cityName:re,sameCity:ge,label:re?`${ne.name} â ${re}`:ne.name,value:ne.name}});se.sort((ne,re)=>Number(re.sameCity)-Number(ne.sameCity)),w(se.slice(0,10))},[d.mass_church,d.mass_city,A.cities,A.churches]);const Lt=async Y=>{var Q;v(X=>({...X,priest_id:Y.id,mass_priest_name:Y.name})),W(!1);try{let X="",se="",ne="",re="";const ge=await aa(Y.id,a==null?void 0:a.id);if(ge)X=ge.city,se=ge.church,ne=ge.date,re=ge.time;else{const{data:ce}=await Te.from("priest_churches").select("name, is_primary, city:cities(name)").eq("priest_id",Y.id).order("is_primary",{ascending:!1}).limit(1),st=(ce||[])[0];st&&(se=st.name||"",X=((Q=st.city)==null?void 0:Q.name)||"")}X=X||Y.city||Y.parish_city||"",se=se||Y.parish_name||"",v(ce=>({...ce,mass_city:X||ce.mass_city,mass_church:se||ce.mass_church,mass_date:ne||ce.mass_date,mass_time:re||ce.mass_time}))}catch(X){Me.error("[AssignIntentionModal] priest_defaults_failed",X.message)}},U=Y=>{const Q=Y.target.value;v(X=>{const se=o.find(re=>re.id===X.priest_id),ne=se&&se.name===Q;return{...X,mass_priest_name:Q,priest_id:ne?X.priest_id:null}})},oe=Y=>{const{name:Q,value:X}=Y.target;v(se=>({...se,[Q]:X}))},le=La(a==null?void 0:a.type)||yi(a),de=wt(a),fe=le?de:Math.floor(Number(d.mass_count)),xe=Number.isFinite(fe)&&fe>=1&&fe<=hs,Se=async()=>{if(a){if(!He){m({title:r("components.assignModal.cannotSaveTitle"),description:r("components.assignModal.cannotSaveDesc").replace("{status}",p),variant:"destructive"});return}if(!xe){m({title:r("components.assignModal.cannotSaveTitle"),description:r("components.assignModal.massCountInvalid").replace("{max}",hs),variant:"destructive"});return}N(!0);try{let Y=d.mass_date,Q=d.mass_time,X=d.mass_city,se=d.mass_church;if(d.priest_id&&Y&&Q){const{data:he}=await Te.from("intentions").select("id, mass_time").eq("priest_id",d.priest_id).eq("mass_date",Y).not("mass_time","is",null);if((he||[]).some(Fe=>Fe.id!==a.id&&String(Fe.mass_time).slice(0,5)===String(Q).slice(0,5))){const Fe=await aa(d.priest_id,a.id);Fe&&(Y=Fe.date,Q=Fe.time,X=Fe.city||X,se=Fe.church||se,m({title:r("components.assignModal.timeAdjustedTitle"),description:r("components.assignModal.timeAdjustedDesc").replace("{date}",Fe.date).replace("{time}",Fe.time)}))}}const ne=(d.priest_id||null)!==(a.priest_id||null),re={priest_id:d.priest_id||null,mass_date:Y||null,mass_time:Q||null,mass_city:X,mass_church:se||null,mass_priest_name:d.mass_priest_name,status:["pending","awaiting_priest","canceled","failed"].includes(p)?"assigned":p,assigned_date:ne||!a.assigned_date?new Date().toISOString():a.assigned_date};le||(re.mass_count=fe);const{error:ge}=await Te.from("intentions").update(re).eq("id",a.id);if(ge)throw ge;const ce=o.find(he=>he.id===d.priest_id),st=!!(ce!=null&&ce.email),at=he=>{const Ye=(he??"").toString().trim();return Ye.length>0?Ye:"do uzgodnienia"},ns={mass_date:at(Y),mass_time:at(Q),mass_city:at(X),mass_location:at(se||X),mass_church:at(se),church_name:at(se)};let gt=!1,ct=!1;if(d.priest_id&&st){const he=await Hs([{intentionId:a.id,priestId:d.priest_id}]);(!he.ok||he.priestsNotified===0&&he.alreadyNotified===0)&&(gt=!0)}if(a.email)try{const{data:he,error:Ye}=await Te.functions.invoke("send-email",{body:{to:a.email,type:"user_assignment",donor_name:a.name,donor_email:a.email,priest_name:d.mass_priest_name,mass_priest_name:d.mass_priest_name,intention_content:a.content,content:a.content,...ns,order_date:new Date().toLocaleDateString("pl-PL")}});(Ye||(he==null?void 0:he.success)===!1)&&(ct=!0,Me.error("[AssignIntentionModal] donor_notification_failed",(Ye==null?void 0:Ye.message)||(he==null?void 0:he.error)))}catch(he){ct=!0,Me.error("[AssignIntentionModal] donor_notification_threw",he==null?void 0:he.message)}Te.functions.invoke("send-mass-intentions-to-sheets",{body:{data:new Date().toISOString(),id:a.id,typ:a.type,imie:a.name,email:a.email,telefon:a.phone||"",intencja:a.content,kwota:a.amount,waluta:a.currency||"PLN",data_mszy:Y||"",status:"assigned",kaplan:d.mass_priest_name||(ce==null?void 0:ce.name)||"",miasto:d.mass_city||(ce==null?void 0:ce.city)||"",kraj:(ce==null?void 0:ce.country)||"",godzina:Q||"",kosciol:d.mass_church||(ce==null?void 0:ce.parish_name)||""}}).catch(he=>Me.error("[AssignIntentionModal] sheet sync failed",he));const Ke=[];gt&&Ke.push(r("components.assignModal.recipientPriest")),ct&&Ke.pu
16sh(r("components.assignModal.recipientDonor")),Ke.length>0?m({title:r("components.assignModal.savedEmailFailedTitle"),description:r("components.assignModal.savedEmailFailedDesc").replace("{recipients}",Ke.join(", ")),variant:"destructive"}):m({title:r("components.assignModal.savedTitle"),description:r(st?"components.assignModal.savedDescEmailsSent":"components.assignModal.savedDescNoPriestEmail"),className:"bg-green-50 border-green-200 text-green-900"}),i&&i(),n()}catch(Y){Me.error("Error updating intention:",Y),m({title:r("components.assignModal.saveErrorTitle"),description:Y.message,variant:"destructive"})}finally{N(!1)}}},Pe=d.priest_id&&o.find(Y=>Y.id===d.priest_id)||null,ut=xe?ni(Pe,a,fe):null,V=Number(Pe==null?void 0:Pe.max_intentions)||0,zt=ut!=null&&V>0&&ut>V,Ft=a?Ge({...a,mass_count:le?a.mass_count:fe}):0;return a?e.jsx(vt,{open:s,onOpenChange:n,children:e.jsxs(Ct,{className:"sm:max-w-[640px]",children:[e.jsxs(_t,{children:[e.jsx(St,{children:r("components.assignModal.title")}),e.jsx(Pt,{children:r("components.assignModal.description")})]}),e.jsxs("div",{className:$("mb-4",!T&&"grid grid-cols-1 md:grid-cols-2 gap-3"),children:[e.jsxs("div",{className:"bg-slate-50 dark:bg-slate-900/40 p-3 rounded-md text-sm border border-slate-100 dark:border-slate-800",children:[e.jsxs("p",{children:[e.jsxs("strong",{children:[r("components.assignModal.requesterLabel"),":"]})," ",a.name]}),e.jsxs("p",{children:[e.jsxs("strong",{children:[r("components.assignModal.emailLabel"),":"]})," ",a.email?e.jsx("a",{href:`mailto:${a.email}`,className:"font-mono text-xs text-slate-700 dark:text-slate-300 underline decoration-dotted underline-offset-2",children:a.email}):e.jsx("span",{className:"text-xs text-amber-700 dark:text-amber-500",children:r("components.assignModal.noEmailLabel")})]}),e.jsxs("p",{children:[e.jsxs("strong",{children:[r("common.type"),":"]})," ",$e(a.type)]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("strong",{children:[r("common.status"),":"]}),e.jsx(tn,{status:p,t:r,align:"start",saving:x,onChange:t?R:void 0})]}),e.jsxs("p",{children:[e.jsxs("strong",{children:[r("components.assignModal.contentLabel"),":"]})," ",e.jsx("span",{className:"text-slate-600 dark:text-slate-300 italic",children:en(a.content)})]})]}),!T&&!Le&&e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3 text-sm text-amber-900",children:[e.jsxs("p",{className:"font-semibold mb-1",children:["â ï¸ ",r("components.assignModal.cannotAssignTitle")]}),e.jsxs("p",{className:"text-xs",children:[r("common.status"),": ",e.jsx("strong",{children:p}),". ",r("components.assignModal.requiredLabel"),": ",e.jsx("code",{children:"succeeded"})," ",r("components.assignModal.orWord")," ",e.jsx("code",{children:"assigned"}),"."]}),e.jsx("p",{className:"mt-1 text-xs text-amber-800",children:r("components.assignModal.donorAlreadyEmailed")}),e.jsx(K,{type:"button",variant:"outline",size:"sm",className:"mt-2 text-amber-900 border-amber-300 hover:bg-amber-100",onClick:()=>rt(!0),children:r("components.assignModal.forceAssignButton")})]}),!T&&Le&&e.jsxs("div",{className:"bg-orange-50 border border-orange-200 rounded-md p-3 text-sm text-orange-900",children:[e.jsxs("p",{className:"font-semibold mb-1",children:["â ",r("components.assignModal.forceModeTitle")]}),e.jsxs("p",{className:"text-xs",children:[r("components.assignModal.forceModeDescPrefix")," ",e.jsx("code",{children:p}),")."]}),e.jsx(K,{type:"button",variant:"outline",size:"sm",className:"mt-2 text-orange-900 border-orange-300 hover:bg-orange-100",onClick:()=>rt(!1),children:r("components.assignModal.undo")})]})]}),e.jsxs("div",{className:$("grid gap-3 py-2",!He&&"opacity-50 pointer-events-none"),children:[e.jsxs("div",{className:"grid gap-2 relative",children:[e.jsx(J,{htmlFor:"mass_priest_name",children:r("components.assignModal.selectPriestLabel")}),e.jsxs("div",{className:"relative",children:[e.jsx(pe,{id:"mass_priest_name",name:"mass_priest_name",ref:_e,value:d.mass_priest_name,onChange:U,onFocus:()=>{ue(_e,Ae),W(!0)},onBlur:()=>setTimeout(()=>W(!1),150),placeholder:r("components.assignModal.priestPlaceholder"),autoComplete:"off",disabled:!He,className:"pr-9"}),e.jsx("button",{type:"button",tabIndex:-1,"aria-label":r("components.assignModal.openPriestListAria"),disabled:!He,onMouseDown:Y=>{var Q;Y.preventDefault(),f?W(!1):(ue(_e,Ae),W(!0),(Q=_e.current)==null||Q.focus())},className:"absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 dar
16k:hover:text-slate-300 disabled:opacity-50",children:e.jsx(Mt,{className:$("h-4 w-4 transition-transform",f&&"rotate-180")})})]}),f&&D.length>0&&e.jsx("div",{className:$("absolute left-0 right-0 z-50 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-md shadow-lg max-h-72 overflow-y-auto",ve?"bottom-full mb-1":"top-full mt-1"),children:D.map(Y=>e.jsxs("button",{type:"button",className:$("w-full text-left px-3 py-2 text-sm hover:bg-slate-50 dark:hover:bg-slate-800 border-b border-slate-100 dark:border-slate-800 last:border-b-0 flex items-center gap-2",d.priest_id===Y.id&&"bg-slate-50 dark:bg-slate-800"),onMouseDown:Q=>{Q.preventDefault(),Lt(Y)},children:[e.jsxs("span",{className:"text-slate-800 dark:text-slate-100 flex-1 truncate",children:[Y.name,Y.city?e.jsxs("span",{className:"ml-2 text-xs text-slate-500 dark:text-slate-400",children:["â ",Y.city]}):null,Y.autoEligible===!1?e.jsx("span",{className:"ml-2 text-[10px] px-1.5 py-0.5 rounded bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-300 whitespace-nowrap",children:r("components.assignModal.manualOnlyBadge")}):null]}),Y.max_intentions?e.jsx("span",{className:"text-[10px] text-slate-500 dark:text-slate-400 whitespace-nowrap tabular-nums",children:typeof Y.intentionsThisYear=="number"?r("components.assignModal.yearLoadSuffix").replace("{n}",Y.intentionsThisYear).replace("{max}",Y.max_intentions):r("components.assignModal.maxSuffix").replace("{n}",Y.max_intentions)}):null]},Y.id))}),f&&(d.mass_priest_name||"").trim().length>=3&&D.length===0&&e.jsx("div",{className:$("absolute left-0 right-0 z-50 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-md shadow-lg px-3 py-2 text-sm text-slate-500 dark:text-slate-400",ve?"bottom-full mb-1":"top-full mt-1"),children:r("components.assignModal.noPriestsFound")}),Pe&&!Pe.email?e.jsxs("p",{className:"text-[10px] text-amber-700 dark:text-amber-500",children:["â ",r("components.assignModal.priestLinkedNoEmailHint")]}):e.jsx("p",{className:"text-[10px] text-slate-500 dark:text-slate-400",children:Pe?`â ${r("components.assignModal.priestLinkedHint")}`:r("components.assignModal.priestFreeTextHint")}),Pe&&Pe.autoEligible===!1?e.jsx("p",{className:"text-[10px] text-slate-500 dark:text-slate-400",children:r("components.assignModal.priestManualOnlyHint")}):null]}),e.jsx("div",{className:"rounded-md border border-slate-200 dark:border-slate-800 p-3",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[9rem,1fr] gap-3 items-start",children:[e.jsxs("div",{className:"grid gap-1.5",children:[e.jsxs(J,{htmlFor:"mass_count",className:"text-xs font-semibold flex items-center gap-1.5",children:[e.jsx(Ws,{className:"w-3.5 h-3.5 text-slate-400"}),r("components.assignModal.massCountLabel")]}),e.jsx(pe,{id:"mass_count",name:"mass_count",inputMode:"numeric",value:le?String(de):d.mass_count,onChange:oe,disabled:le,className:$("tabular-nums",!xe&&"border-rose-400")})]}),e.jsxs("div",{className:"space-y-1 sm:pt-6",children:[le?e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:r("components.assignModal.massCountFixed").replace("{n}",de)}):xe?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:r("components.assignModal.massCountHint")}),e.jsx("p",{className:"text-[11px] text-emerald-700 dark:text-emerald-400 tabular-nums",children:r("components.assignModal.massCountFee").replace("{count}",fe).replace("{amount}",gl(Ft))})]}
16):e.jsx("p",{className:"text-[11px] text-rose-600 dark:text-rose-400",children:r("components.assignModal.massCountInvalid").replace("{max}",hs)}),ut!=null&&e.jsxs("p",{className:$("text-[11px] tabular-nums",zt?"text-amber-700 dark:text-amber-500":"text-slate-500 dark:text-slate-400"),children:[r("components.assignModal.massCountYearLoad").replace("{priest}",Pe.name||"").replace("{n}",ut).replace("{max}",V||"â"),zt&&` ${r("components.assignModal.massCountYearOver")}`]})]})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(J,{htmlFor:"mass_date",children:r("components.assignModal.massDateLabel")}),e.jsx(pe,{id:"mass_date",name:"mass_date",type:"date",value:d.mass_date,onChange:oe})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(J,{htmlFor:"mass_time",children:r("common.time")}),e.jsx(pe,{id:"mass_time",name:"mass_time",type:"time",value:d.mass_time,onChange:oe})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"grid gap-2 relative",children:[e.jsx(J,{htmlFor:"mass_city",children:r("common.city")}),e.jsx(pe,{id:"mass_city",name:"mass_city",ref:z,value:d.mass_city,onChange:oe,onFocus:()=>{ue(z,ie),L(!0)},onBlur:()=>setTimeout(()=>L(!1),150),placeholder:r("components.assignModal.cityPlaceholder"),autoComplete:"off"}),h&&u.length>0&&e.jsx("div",{className:$("absolute left-0 right-0 z-50 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-md shadow-lg max-h-60 overflow-y-auto",te?"bottom-full mb-1":"top-full mt-1"),children:u.map(Y=>e.jsxs("button",{type:"button",className:"w-full text-left px-3 py-2 text-sm hover:bg-slate-50 dark:bg-slate-900/40 border-b border-slate-100 dark:border-slate-800 last:border-b-0 flex items-center gap-2",onMouseDown:Q=>{Q.preventDefault(),v(X=>({...X,mass_city:Y.value})),L(!1)},children:[e.jsx("span",{className:"text-[10px] uppercase font-semibold px-1.5 py-0.5 rounded bg-blue-100 text-blue-700",children:r("components.assignModal.cityTag")}),e.jsx("span",{className:"text-slate-800 dark:text-slate-100",children:Y.label})]},Y.id))}),h&&(d.mass_city||"").trim().length>=3&&u.length===0&&F&&e.jsx("div",{className:$("absolute left-0 right-0 z-50 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-md shadow-lg px-3 py-2 text-sm text-slate-500 dark:text-slate-400",te?"bottom-full mb-1":"top-full mt-1"),children:r("components.assignModal.noCitiesFound")})]}),e.jsxs("div",{className:"grid gap-2 relative",children:[e.jsx(J,{htmlFor:"mass_church",children:r("components.assignModal.churchLabel")}),e.jsx(pe,{id:"mass_church",name:"mass_church",ref:ee,value:d.mass_church,onChange:oe,onFocus:()=>{ue(ee,De),B(!0)},onBlur:()=>setTimeout(()=>B(!1),150),placeholder:r("components.assignModal.churchPlaceholder"),autoComplete:"off"}),S&&H.length>0&&e.jsx("div",{className:$("absolute left-0 right-0 z-50 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-md shadow-lg max-h-60 overflow-y-auto",ae?"bottom-full mb-1":"top-full mt-1"),children:H.map(Y=>e.jsxs("button",{type:"button",className:"w-full text-left px-3 py-2 text-sm hover:bg-slate-50 dark:bg-slate-900/40 border-b border-slate-100 dark:border-slate-800 last:border-b-0 flex items-center gap-2",onMouseDown:Q=>{Q.preventDefault(),v(X=>({...X,mass_church:Y.value,mass_city:X.mass_city||Y.cityName||X.mass_city})),B(!1)},children:[e.jsx("span",{className:$("text-[10px] uppercase font-semibold px-1.5 py-0.5 rounded",Y.sameCity?"bg-emerald-100 text-emerald-700":"bg-amber-100 text-amber-700"),children:Y.sameCity?r("components.assignModal.sameCityTag"):r("components.assignModal.churchTag")}),e.jsx("span",{className:"text-slate-800 dark:text-slate-100",children:Y.label})]},Y.id))}),S&&(d.mass_church||"").trim().length>=3&&H.length===0&&F&&e.jsx("div",{className:$("absolute left-0 right-0 z-50 bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-md shadow-lg px-3 py-2 text-sm text-slate-500 dark:text-slate-400",ae?"bottom-full mb-1":"top-full mt-1"),children:r("components.assignModal.noChurchesFound")})]})]})]}),e.jsxs(Dt,{className:"sm:justify-between gap-2",children:[c?e.jsxs(K,{variant:"outline",onClick:()=>c(a),disabled:y,className:"border-indigo-200 text-indigo-700 hover:bg-indigo-50 hover:text-indigo-800 dark:border-indigo-900 dark:!text-indigo-300",children:[e.jsx(Rs,{className:"w-4 h-4 mr-2"}),r("components.assignModal.duplicateButton")]}):e.jsx("span",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(K,{variant:"outline",onClick:n,disabled:y,children:r("common.cancel")}),e.jsx(K,{onClick:Se,disabled:y||!He||!xe,children:r(y?"common.saving":"components.assignModal.saveChanges")}
16)]})]})]})}):null}const hl={pl:ts,pt:Ea,en:Ra,fr:Ba,it:Oa},Nt=s=>hl[s]||ts,C=(s,n,a)=>typeof s=="function"?s(n,a):a,Ve=s=>String(s).replace("{fee}",qe),Qt=s=>{if(!s)return null;const n=new Date(s);return Number.isNaN(n.getTime())?null:n.getFullYear()};function sn(s){const n=new Set;return(s||[]).forEach(a=>{const o=Qt(a.created_at);o&&n.add(o)}),[...n].sort((a,o)=>o-a)}function Us(s,n){const a=be(n,"yyyy-MM-dd"),o={paidCount:0,entrusted:0,unassigned:0,notified:0,confirmed:0,scheduled:0,massPast:0,payoutDone:0,owed:0,payoutValue:0};return s.filter(Ht).forEach(i=>{o.paidCount+=1;const c=Fa(i)?Ge(i):0;o.owed+=c,i.priest_id?o.entrusted+=1:o.unassigned+=1,i.priest_notified_at&&(o.notified+=1),i.priest_confirmed_at&&(o.confirmed+=1),i.mass_date&&(o.scheduled+=1,String(i.mass_date).slice(0,10)<=a&&(o.massPast+=1)),i.priest_paid_at&&(o.payoutDone+=1,o.payoutValue+=c)}),o.payoutPending=o.owed-o.payoutValue,o}function fl(s,n=new Date,a=12,o="pl"){const i=[];for(let t=a-1;t>=0;t-=1){const m=new Date(n.getFullYear(),n.getMonth()-t,1);i.push({year:m.getFullYear(),month:m.getMonth(),date:m,count:0,toPriest:0})}const c=(t,m)=>{for(let r=0;r<i.length;r+=1)if(i[r].year===t&&i[r].month===m)return i[r];return null};return s.filter(Ht).forEach(t=>{if(!t.created_at)return;const m=new Date(t.created_at);if(Number.isNaN(m.getTime()))return;const r=c(m.getFullYear(),m.getMonth());r&&(r.count+=1,r.toPriest+=Ge(t))}),i.map(t=>({...t,label:be(t.date,"LLL yy",{locale:Nt(o)})}))}function bl(s,n,a){const o=Array.from({length:12},(i,c)=>({year:n,month:c,date:new Date(n,c,1),items:[]}));return s.forEach(i=>{Qt(i.created_at)===n&&o[new Date(i.created_at).getMonth()].items.push(i)}),o.map(i=>
16({...i,label:be(i.date,"LLLL",{locale:Nt(a)}),shortLabel:be(i.date,"LLL",{locale:Nt(a)})}))}function yl(s,n){const a={};return s.filter(Ht).forEach(o=>{const i=o.type||"unknown";a[i]||(a[i]={type:i,count:0,toPriest:0}),a[i].count+=1,a[i].toPriest+=Ge(o)}),Object.values(a).map(o=>({...o,label:$e(o.type,n)})).sort((o,i)=>i.count-o.count)}const Ce=s=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN"}).format(s||0);function xt(s,n,a){const o=mt(n,{onlyPaid:!0}),i=Us(n,a);return{label:s,intentions:n.length,paidCount:o.count,totalDonated:o.totalDonated,totalToPriests:o.totalToPriests,mercyFund:o.mercyFund,adminCost:o.adminCost,avg:o.avg,median:o.median,min:o.min,max:o.max,entrusted:i.entrusted,confirmed:i.confirmed,massPast:i.massPast}}function dt(s,n,a,o){const i=mt(a,{onlyPaid:!0}),c=Us(a,o);return{name:s,managerName:n,intentions:a.length,paidCount:i.count,totalDonated:i.totalDonated,toPriest:i.totalToPriests,mercyFund:i.mercyFund,adminCost:i.adminCost,entrusted:c.entrusted,notified:c.notified,confirmed:c.confirmed,scheduled:c.scheduled,massPast:c.massPast,payoutDone:c.payoutValue,payoutPending:c.payoutPending}}function jl(s,n,a,o,{priestId:i=null,managerId:c=null}={}){const t=new Map,m=[];s.forEach(k=>{if(!k.priest_id){m.push(k);return}t.has(k.priest_id)||t.set(k.priest_id,[]),t.get(k.priest_id).push(k)});const r=new Set,y=[],N=i?n.find(k=>k.id===i):null,d=k=>c?k.id===c:i?!!N&&(N.id===k.id||N.manager_priest_id===k.id):!0;n.filter(k=>k.is_intentions_manager).filter(d).sort((k,g)=>(k.name||"").localeCompare(g.name||"","pl")).forEach(k=>{const g=n.filter(p=>p.id===k.id||p.manager_priest_id===k.id).filter(p=>!i||p.id===i);g.forEach(p=>r.add(p.id));const x=g.map(p=>dt(p.name,k.name,t.get(p.id)||[],a)).sort((p,T)=>T.intentions-p.intentions),l=g.flatMap(p=>t.get(p.id)||[]);y.push({managerId:k.id,managerName:k.name,priestCount:g.length,rows:x,totals:dt(k.name,k.name,l,a)})});const v=n.filter(k=>!r.has(k.id)&&(t.get(k.id)||[]).length>0);if(v.length>0){const k=C(o,"pages.intentions.export.noManagerGroup","Bez gestora"),g=v.map(l=>dt(l.name,k,t.get(l.id)||[],a)).sort((l,p)=>p.intentions-l.intentions),x=v.flatMap(l=>t.get(l.id)||[]);y.push({managerId:null,managerName:k,priestCount:v.length,rows:g,totals:dt(k,k,x,a)})}if(m.length>0){const k=C(o,"pages.intentions.export.unassigned","â Nieprzypisane â");y.push({managerId:"__unassigned__",managerName:k,priestCount:0,rows:[dt(k,k,m,a)],totals:dt(k,k,m,a)})}return y}function an(s,n,{priestId:a=null,managerId:o=null,year:i=null,t:c=null,lang:t="pl"}={}){const m=!a&&o?n.filter(w=>w.id===o||w.manager_priest_id===o):null,r=m?new Set(m.map(w=>w.id)):null,y=a?s.filter(w=>w.priest_id===a):r?s.filter(w=>r.has(w.priest_id)):s,N=i?Number(i):null,d=N?y.filter(w=>Qt(w.created_at)===N):y,v=new Date,k=be(v,"LLLL yyyy",{locale:Nt(t)}),g=String(v.getFullYear()),x=N?bl(d,N,t):null,l=N?[...x.map(w=>xt(w.label,w.items,v)),xt(C(c,"pages.intentions.export.yearTotalRow","Rok {year} â razem").replace("{year}",N),d,v)]:(()=>{const w=za(d,v);return[xt(k,w.month,v),xt(g,w.year,v),xt(C(c,"temporalChart.allHistory","CaÅa historia"),w.all,v)]})(),T=sn(y).sort((w,S)=>w-S).map(w=>xt(String(w),y.filter(S=>Qt(S.created_at)===w),v)),R=new Map(n.map(w=>[w.id,w.name])),A=w=>w?w.is_intentions_manager?w.name:w.manager_priest_id?R.get(w.manager_priest_id)||"":C(c,"pages.intentions.export.noManagerGroup","Bez gestora"):"",P={};m&&m.forEach(w=>{P[w.id]={name:w.name,priest:w,items:[]}}),d.forEach(w=>{const S=w.priest_id||"__unassigned__";P[S]||(P[S]={name:R.get(w.priest_id)||C(c,"pages.intentions.export.unassigned","â Nieprzypisane â"),priest:n.find(B=>B.id===w.priest_id)||null,items:[]}),P[S].items.push(w)});const F=Object.values(P).map(({name:w,priest:S,items:B})=>dt(w,S?A(S):C(c,"pages.intentions.export.unassigned","â Nieprzypisane â"),B,v)).sort((w,S)=>S.intentions-w.intentions),O={};d.forEach(w=>{const S=w.type||"unknown";O[S]||(O[S]=[]),O[S].push(w)});const u=Object.entries(O).map(([w,S])=>{const B=mt(S,{onlyPaid:!0});return{type:$e(w,t),intentions:S.length,paidCount:B.count,totalDonated:B.totalDonated,avg:B.avg,toPriest:B.totalToPriests}}).sort((w,S)=>S.intentions-w.intentions),M=jl(d,n,v,c,{priestId:a,managerId:o}).sort((w,S)=>S.totals.intentions-w.totals.intentions),h=N?x.map(w=>{const S=w.items.filter(Ht);return{year:w.year,month:w.month,label:w.shortLabel,count:S.length,toPriest:S.reduce((B,D)=>B+Ge(D),0)}}):fl(d,v,12,t),L=yl(d,t),H=a?R.get(a)||C(c,"pages.intentions.export.selectedPriest","Wybrany kapÅan"):o?R.get(o)||C(c,"pages.intentions.export.selectedManager","Wybrany gestor"):null;return{generatedAt:v,year:N,periodRows:l,perYear:T,perPriest:F,perType:u,perManager:M,lifecycle:Us(d,v),monthlyChart:h,typeChart:L,subject:H,isGroup:!!m,priestId:a,managerId:o}}function nn(s,n){return s.subject?s.isGroup?C(n,"pages.intentions.export.headingManagerGroup","Raport dla grupy gestora: {name}").replace("{name}",s.subject):C(n,"pages.intentions.export.headingPriest","Raport dla {name}").replace("{name}",s.subject):C(n,"pages.intentions.export.headingAllPriests","Raport dla kapÅanów")}function ln(s,n){if(!s.subject)return C(n,"pages.intentions.export.fileSuffixPriests","_k
16aplani");const a=s.subject.replace(/\s+/g,"_");return s.isGroup?C(n,"pages.intentions.export.fileSuffixGroup","_grupa_{name}").replace("{name}",a):`_${a}`}const on=(s,n)=>s.year?String(s.year):C(n,"pages.intentions.export.yearAll","Wszystkie lata");function rn(s,n){const a=s.lifecycle;return[[C(n,"pages.intentions.export.lifePaid","Intencje opÅacone"),a.paidCount],[C(n,"pages.intentions.export.lifeEntrusted","Powierzone kapÅanowi"),a.entrusted],[C(n,"pages.intentions.export.lifeUnassigned","Bez kapÅana"),a.unassigned],[C(n,"pages.intentions.export.lifeScheduled","Z wyznaczonÄ
datÄ
mszy"),a.scheduled],[C(n,"pages.intentions.export.lifeMassPast","Po dacie mszy (odprawione wg terminu)"),a.massPast],[C(n,"pages.intentions.export.lifeNotified","WysÅane do kapÅana (powiadomienie)"),a.notified],[C(n,"pages.intentions.export.lifeConfirmed","Potwierdzone przez kapÅana"),a.confirmed],[C(n,"pages.intentions.export.lifePayoutDone","Honoraria wypÅacone (szt.)"),a.payoutDone]]}async function cn(s,n,{scope:a="all",priestId:o=null,managerId:i=null,year:c=null,t=null,lang:m="pl"}={}){const r=an(s,n,{priestId:o,managerId:i,year:c,t,lang:m}),y=await At(()=>import("./xlsx-6ed613d4.js"),[]),N=a==="priests",d=y.utils.book_new(),v=C(t,"pages.intentions.export.colPeriod","Okres"),k=C(t,"pages.intentions.export.colIntentionsAll","Intencji (wszystkie)"),g=C(t,"pages.intentions.export.colIntentionsPaid","Intencji (opÅacone)"),x=C(t,"pages.intentions.export.colTotalDonations","WpÅaty ÅÄ
cznie"),l=C(t,"pages.intentions.export.colMercyFund","Fundusz MiÅosierdzia"),p=C(t,"pages.intentions.export.colFoundationFund","Fundusz Fundacji"),T=C(t,"pages.intentions.export.colPaid","OpÅacone"),R=C(t,"pages.intentions.export.colType","Rodzaj Intencji"),A=C(t,"pages.intentions.export.colEntrusted","Powierzone"),P=C(t,"pages.intentions.export.colCelebrated","Odprawione (potwierdzone)"),F=C(t,"pages.intentions.export.colMassPast","Po dacie mszy"),O=C(t,"pages.intentions.export.colManager","Gestor"),u=C(t,"pages.intentions.export.colYear","Rok"),M=[A,P,F],h=U=>[U.entrusted,U.confirmed,U.massPast],L=N?[v,k,g,Ve(C(t,"pages.intentions.export.colToPriestsFee","Dla kapÅanów ({fee} zÅ Ã N)")),...M]:[v,k,g,x,C(t,"pages.intentions.export.colToPriests","Dla kapÅanów"),l,p,C(t,"pages.intentions.export.colAvg","Årednia"),C(t,"pages.intentions.export.colMedian","Mediana"),C(t,"pages.intentions.export.colMin","Minimum"),C(t,"pages.intentions.export.colMax","Maksimum"),...M],H=U=>N?[U.label,U.intentions,U.paidCount,U.totalToPriests,...h(U)]:[U.label,U.intentions,U.paidCount,U.totalDonated,U.totalToPriests,U.mercyFund,U.adminCost,U.avg,U.median,U.min,U.max,...h(U)],w=r.periodRows.map(H),S=L.length-1,B=Ve(N?C(t,"pages.intentions.export.rulePriests","ReguÅa: {fee} PLN dla kapÅana za każdÄ
opÅaconÄ
intencjÄ."):C(t,"pages.intentions.export.ruleFull","ReguÅa: {fee} PLN dla kapÅana, z reszty 25% Fundusz MiÅosierdzia, 75% Fundusz Fundacji")),D=be(r.generatedAt,"dd.MM.yyyy HH:mm",{locale:Nt(m)}),q=N?`${nn(r,t)} â ${D}`:`${C(t,"pages.intentions.export.xlsTitleFull","Raport intencji")} â ${D}`,f=C(t,"pages.intentions.export.yearScopeLine","Zakres czasowy: {scope}").replace("{scope}",on(r,t)),W=C(t,"pages.intentions.export.lifecycleNote","Powierzone = intencja ma przypisanego kapÅana. Odprawione = kapÅan potwierdziÅ odprawienie w panelu. Po dacie mszy = wyznaczony termin już minÄ
Å."),te=y.utils.aoa_to_sheet([[q],[f],[B],[],L,...w,[],[C(t,"pages.intentions.export.sectionLifecycle","Stan realizacji intencji")],[W],[C(t,"pages.intentions.export.colMetric","Wskaźnik"),C(t,"pages.intentions.export.colValue","WartoÅÄ")],...rn(r,t)]);te["!cols"]=N?[{wch:24},{wch:18},{wch:18},{wch:22},{wch:14},{wch:22},{wch:16}]:[{wch:24},{wch:14},{wch:14},{wch:16},{wch:14},{wch:20},{wch:16},{wch:12},{wch:12},{wch:10},{wch:12},{wch:14},{wch:22},{wch:16}],te["!merges"]=[{s:{r:0,c:0},e:{r:0,c:S}},{s:{r:1,c:0},e:{r:1,c:S}},{s:{r:2,c:0},e:{r:2,c:S}}];const ie=N?["D"]:["D","E","F","G","H","I","J","K"];if(r.periodRows.forEach((U,oe)=>{ie.forEach(le=>{const de=`${le}${6+oe}`;te[de]&&(te[de].z="#,##0.00 [$zÅ-415]")})}),y.utils.book_append_sheet(d,te,C(t,"pages.intentions.export.sheetSummary","Podsumowanie")),r.perYear.length>0){const U=[u,...L.slice(1)],oe=y.utils.aoa_to_sheet([U,...r.perYear.map(H)]);oe["!cols"]=te["!cols"],r.perYear.forEach((le,de)=>{ie.forEach(fe=>{const xe=`${fe}${2+de}`;oe[xe]&&(oe[xe].z="#,##0.00 [$zÅ-415]")})}),y.utils.book_append_sheet(d,oe,C(t,"pages.intentions.export.sheetPerYear","Wg roku"))}if(r.perManager.length>0){const U=[O,C(t,"pages.intentions.export.colPriestName","KapÅan"),C(t,"pages.intentions.export.colPriestsCount","KapÅanów"),k,T,A,P,F,Ve(C(t,"pages.intentions.export.colToPriestFee","Dla kapÅana ({fee} zÅ Ã N)")),C(t,"pages.intentions.export.colPayoutDone","WypÅacono"),C(t,"pages.intentions.export.colPayoutPending","Do wypÅaty")],oe=C(t,"pages.intentions.export.managerTotalRow","⸠RAZEM grupa"),le=[];r.perManager.forEach(fe=>{const xe=fe.totals;le.push([fe.managerName,oe,fe.priestCount,xe.intentions,xe.paidCount,xe.entrusted,xe.confirmed,xe.massPast,xe.toPriest,xe.payoutDone,xe.payoutPending]),fe.rows.forEach(Se=>le.push([fe.managerName,Se.name,"",Se.intentions,Se.paidCount,Se.entrusted,Se.confirmed,Se.massPast,Se.toPriest,Se.payoutDone,Se.payoutPending]))});const de=y.utils.aoa_to_sheet([U,...le]);de["!cols"]=[{wch:28},{wch:30},{wch:10},{wch:14},{wch:12},{wch:12},{wch:22},{wch:14},{wch:20},{wch:16},{wch:16}],le.forEach((fe,xe)=>{["I","J","K"].forEach(Se=>{const Pe=`${Se}${2+xe}`;de[Pe]&&(de[Pe].z="#,##0.00 [$zÅ-415]")})}),y.utils.book_append_sheet(d,de,C(t,"pages.intentions.export.sheetManagers","Gestorzy"))}const ae=C(t,"pages.intentions.export.colPriestName","KapÅan"),De=N?[ae,O,k,T,Ve(C(t,"pages.intentions.export.colWillReceiveFee","Otrzyma ({fee} zÅ Ã N)")),...M]:[ae,O,k,T,x,Ve(C(t,"pages.intentions.export.colToPriestFee","Dla kapÅana ({fee} zÅ Ã N)")),l,p,...M],ve=r.perPriest.map(U=>N?[U.name,U.managerName,U.intentions,U.paidCount,U.toPriest,...h(U)]:[U.name,U.managerName,U.intentions,U.paidCount,U.totalDonated,U.toPriest,U.mercyFund,U.adminCost,...h(U)]),Ae=y.utils.aoa_to_sheet([De,...ve]);Ae["!cols"]=N?[{wch:28},{wch:24},{wch:18},{wch:12},{wch:22},{wch:14},{wch:22},{wch:16}]:[{wch:28},{wch:24},{wch:18},{wch:12},{wch:16},{wch:22},{wch:20},{wch:16},{wch:14},{wch:22},{wch:16}];const z=N?["E"]:["E","F","G","H"];if(r.perPriest.forEach((U,oe)=>{z.forEach(le=>{const de=`${le}${2+oe}`;Ae[de]&&(Ae[de].z="#,##0.00 [$zÅ-415]")})}),y.utils.book_append_sheet(d,Ae,C(t,"pages.intentions.export.sheetPerPriest","Wg kapÅana")),!N){const U=y.utils.aoa_to_sheet([[R,k,T,x,C(t,"pages.intentions.export.colAvgDonation","Årednia wpÅata")],...r.perType.map(oe=>[oe.type,oe.intentions,oe.paidCount,oe.totalDonated,oe.avg])]);U["!cols"]=[{wch:28},{wch:18},{wch:12},{wch:16},{wch:14}],r.perType.forEach((oe,le)=>{["D","E"].forEach(de=>{const fe=`${de}${2+le}`;U[fe]&&(U[fe].z="#,##0.00 [$zÅ-415]")})}),y.utils.book_append_sheet(d,U,C(t,"pages.intentions.export.sheetPerType","Wg rodzaju"))}const ee=[C(t,"pages.intentions.export.colMonth","MiesiÄ
c"),g,Ve(C(t,"pages.intentions.export.colReceiveFee","Otrzymanie ({fee} zÅ Ã N)"))],_e=r.monthlyChart.map(U=>[U.label,U.count,U.toPriest]),ue=y.utils.aoa_to_sheet([ee,..._e]);if(ue["!cols"]=[{wch:14},{wch:20},{wch:22}],r.monthlyChart.forEach((U,oe)=>{const le=`C${2+oe}`;ue[le]&&(ue[le].z="#,##0.00 [$zÅ-415]")}),y.utils.book_append_sheet(d,ue,r.year?C(t,"pages.intentions.export.sheetMonths","MiesiÄ
ce"):C(t,"pages.intentions.export.sheetLast12Months","Ostatnie 12 m-cy")),N&&r.typeChart.length>0){const U=[R,C(t,"pages.intentions.export.colCount","Liczba"),Ve(C(t,"pages.intentions.export.colToPriestFee","Dla kapÅana ({fee} zÅ Ã N)"))],oe=r.typeChart.map(de=>[de.label,de.count,de.toPriest]),le=y.utils.aoa_to_sheet([U,...oe]);le["!cols"]=[{wch:28},{wch:12},{wch:22}],r.typeChart.forEach((de,fe)=>{const xe=`C${2+fe}`;le[xe]&&(le[xe].z="#,##0.00 [$zÅ-415]")}),y.utils.book_append_sheet(d,le,C(t,"pages.intentions.export.sheetPerType","Wg rodzaju"))}const Le=N?ln(r,t):"",rt=r.year?`_${r.year}`:"",Lt=`${C(t,"pages.intentions.export.fileBaseName","Raport_Intencji")}${Le}${rt}_${be(r.generatedAt,"yyyy-MM-dd_HHmm")}.xlsx`;y.writeFile(d,Lt)}let ma=!1;async function dn(){if(ma)return;const{Font:s}=await At(()=>import("./react-pdf.browser-058a6b7a.js"),["assets/react-pdf.browser-058a6b7a.js","assets/index-5a305ee
160.js","assets/index-33a9d0f1.css","assets/constants-c1f6ae8f.js"]);s.register({family:"Inter",fonts:[{src:"/fonts/Inter-Regular.ttf",fontWeight:"normal"},{src:"/fonts/Inter-SemiBold.ttf",fontWeight:600},{src:"/fonts/Inter-Bold.ttf",fontWeight:700}]}),ma=!0}async function mn(s,n,{scope:a="all",priestId:o=null,managerId:i=null,year:c=null,t=null,lang:m="pl"}={}){await dn();const r=an(s,n,{priestId:o,managerId:i,year:c,t,lang:m}),y=a==="priests",{pdf:N,Document:d,Page:v,Text:k,View:g,StyleSheet:x}=await At(()=>import("./react-pdf.browser-058a6b7a.js"),["assets/react-pdf.browser-058a6b7a.js","assets/index-5a305ee0.js","assets/index-33a9d0f1.css","assets/constants-c1f6ae8f.js"]),l=x.create({page:{padding:28,paddingBottom:40,fontSize:9,fontFamily:"Inter",color:"#1e293b"},h1:{fontSize:16,fontWeight:700,marginBottom:4,color:"#312e81"},sub:{fontSize:9,color:"#64748b",marginBottom:4},scopeLine:{fontSize:9,fontWeight:700,color:"#4f46e5",marginBottom:12},rule:{fontSize:8,color:"#475569",backgroundColor:"#eef2ff",padding:6,borderRadius:4,marginBottom:14},note:{fontSize:7.5,color:"#64748b",marginBottom:6,lineHeight:1.4},section:{marginBottom:14},sectionTitle:{fontSize:11,fontWeight:700,marginBottom:6,color:"#312e81"},table:{borderTop:"1pt solid #cbd5e1",borderLeft:"1pt solid #cbd5e1"},row:{flexDirection:"row",borderBottom:"1pt solid #cbd5e1"},headerRow:{backgroundColor:"#eef2ff"},groupRow:{backgroundColor:"#fef3c7"},totalRow:{backgroundColor:"#f1f5f9"},cell:{padding:3.5,fontSize:7.5,borderRight:"1pt solid #cbd5e1"},cellRight:{textAlign:"right"},cellHeader:{fontWeight:700,fontSize:6.8,color:"#312e81"},cellBold:{fontWeight:700},footer:{position:"absolute",bottom:16,left:28,right:28,textAlign:"center",color:"#94a3b8",fontSize:7},pageNum:{position:"absolute",bottom:26,left:28,right:28,textAlign:"center",color:"#94a3b8",fontSize:7},chartRow:{flexDirection:"row",alignItems:"center",marginBottom:3},chartLabel:{width:"14%",fontSize:8,color:"#475569"},chartTrack:{flex:1,height:12,backgroundColor:"#eef2ff",borderRadius:2,overflow:"hidden"},chartBar:{height:"100%",backgroundColor:"#4f46e5",borderRadius:2,justifyContent:"center",paddingHorizontal:4},chartValue:{width:"12%",textAlign:"right",fontSize:8,color:"#1e293b"},chartCount:{color:"#ffffff",fontSize:7,fontWeight:700},typeRow:{flexDirection:"row",alignItems:"center",marginBottom:4},typeLabel:{width:"34%",fontSize:8,color:"#1e293b"},typeTrack:{flex:1,height:10,backgroundColor:"#fef3c7",borderRadius:2,overflow:"hidden"},typeBar:{height:"100%",backgroundColor:"#d97706",borderRadius:2},typeMeta:{width:"24%",textAlign:"right",fontSize:8,color:"#475569"}}),p=({children:z,w:ee,align:_e="left",header:ue=!1,bold:Le=!1})=>e.jsx(g,{style:[l.cell,{width:ee},_e==="right"&&l.cellRight,ue&&l.cellHeader,Le&&l.cellBold],children:e.jsx(k,{children:z})}),T=Math.max(1,...r.monthlyChart.map(z=>z.count)),R=()=>e.jsxs(g,{style:l.section,children:[e.jsx(k,{style:l.sectionTitle,children:r.year?C(t,"pages.intentions.export.sectionMonthlyYear","MiesiÄ
ce roku {year} (opÅacone intencje)").replace("{year}",r.year):C(t,"pages.intentions.export.sectionMonthlyChart","Ostatnie 12 miesiÄcy (opÅacone intencje)")}),e.jsx(g,{children:r.monthlyChart.map(z=>{const ee=`${Math.max(2,Math.round(z.count/T*100))}%`;return e.jsxs(g,{style:l.chartRow,children:[e.jsx(k,{style:l.chartLabel,children:z.label}),e.jsx(g,{style:l.chartTrack,children:e.jsx(g,{style:[l.chartBar,{width:ee}],children:z.count>0&&e.jsx(k,{style:l.chartCount,children:z.count})})}),e.jsx(k,{style:l.chartValue,children:Ce(z.toPriest)})]},`${z.year}-${z.month}`)})})]}),A=r.typeChart.reduce((z,ee)=>z+ee.count,0),P=()=>e.jsxs(g,{style:l.section,children:[e.jsx(k,{style:l.sectionTitle,children:C(t,"pages.intentions.export.sectionTypeBreakdown","PodziaÅ wg rodzaju intencji")}),e.jsx(g,{children:r.typeChart.map(z=>{const ee=A>0?Math.round(z.count/A*100):0;return e.jsxs(g,{style:l.typeRow,children:[e.jsx(k,{style:l.typeLabel,children:z.label}),e.jsx(g,{style:l.typeTrack,children:e.jsx(g,{style:[l.typeBar,{width:`${Math.max(2,ee)}%`}]})}),e.jsxs(k,{style:l.typeMeta,children:[z.count," (",ee,"%) · ",Ce(z.toPriest)]})]},z.type)})})]}),F=["14%","8%","8%","11%","10%","11%","10%","9%","10%","9%"],O=["26%","12%","12%","16%","11%","12%","11%"],u=["19%","13%","7%","8%","10%","13%","11%","12%","7%"],M=["28%","20%","10%","10%","12%","11%","9%"],h=["24%","8%","8%","9%","9%","11%","9%","11%","11%"],L=y?O:F,H=y?M:u,w={entrusted:C(t,"pages.intentions.export.colEntrustedShort","Powierz."),celebrated:C(t,"pages.intentions.export.colCelebratedShort","Odprawione"),massPast:C(t,"pages.intentions.export.colMassPastShort","Po dacie")},S=({title:z,rows:ee,firstColLabel:_e})=>e.jsxs(g,{style:l.section,children:[e.jsx(k,{style:l.sectionTitle,children:z}),e.jsxs(g,{style:l.table,children:[e.jsxs(g,{style:[l.row,l.headerRow],fixed:!0,children:[e.jsx(p,{w:L[0],header:!0,children:_e}),e.jsx(p,{w:L[1],align:"right",header:!0,children:C(t,"pages.intentions.export.colIntentionsShort","Intencji")}),e.jsx(p,{w:L[2],align:"right",header:!0,children:C(t,"pages.intentions.export.colPaid","OpÅacone")}),y?e.jsx(p,{w:L[3],align:"right",header:!0,children:C(t,"pages.intentions.export.colReceiving","OtrzymujÄ
")}):e.jsxs(e.Fragment,{children:[e.jsx(p,{w:L[3],align:"right",header:!0,children:C(t,"pages.intentions.export.colDonations","WpÅaty")}),e.jsx(p,{w:L[4],align:"right",header:!0,children:C(t,"pages.intentions.export.colPriests","KapÅani")}),e.jsx(p,{w:L[5],align:"right",header:!0,children:C(t,"pages.intentions.export.colMercyShort","MiÅosierdzie")}),e.jsx(p,{w:L[6],align:"right",header:!0,children:C(t,"pages.intentions.export.colFoundationShort","Fundacja")})]}),e.jsx(p,{w:L[y?4:7],align:"right",header:!0,children:w.entrusted}
16),e.jsx(p,{w:L[y?5:8],align:"right",header:!0,children:w.celebrated}),e.jsx(p,{w:L[y?6:9],align:"right",header:!0,children:w.massPast})]}),ee.map((ue,Le)=>e.jsxs(g,{style:l.row,wrap:!1,children:[e.jsx(p,{w:L[0],children:ue.label}),e.jsx(p,{w:L[1],align:"right",children:String(ue.intentions)}),e.jsx(p,{w:L[2],align:"right",children:String(ue.paidCount)}),y?e.jsx(p,{w:L[3],align:"right",children:Ce(ue.totalToPriests)}):e.jsxs(e.Fragment,{children:[e.jsx(p,{w:L[3],align:"right",children:Ce(ue.totalDonated)}),e.jsx(p,{w:L[4],align:"right",children:Ce(ue.totalToPriests)}),e.jsx(p,{w:L[5],align:"right",children:Ce(ue.mercyFund)}),e.jsx(p,{w:L[6],align:"right",children:Ce(ue.adminCost)})]}),e.jsx(p,{w:L[y?4:7],align:"right",children:String(ue.entrusted)}),e.jsx(p,{w:L[y?5:8],align:"right",children:String(ue.confirmed)}),e.jsx(p,{w:L[y?6:9],align:"right",children:String(ue.massPast)})]},`${ue.label}-${Le}`))]})]}),B=()=>e.jsxs(g,{style:l.section,wrap:!1,children:[e.jsx(k,{style:l.sectionTitle,children:C(t,"pages.intentions.export.sectionLifecycle","Stan realizacji intencji")}),e.jsx(k,{style:l.note,children:C(t,"pages.intentions.export.lifecycleNote","Powierzone = intencja ma przypisanego kapÅana. Odprawione = kapÅan potwierdziÅ odprawienie w panelu. Po dacie mszy = wyznaczony termin już minÄ
Å.")}),e.jsxs(g,{style:l.table,children:[e.jsxs(g,{style:[l.row,l.headerRow],children:[e.jsx(p,{w:"70%",header:!0,children:C(t,"pages.intentions.export.colMetric","Wskaźnik")}),e.jsx(p,{w:"30%",align:"right",header:!0,children:C(t,"pages.intentions.export.colValue","WartoÅÄ")})]}),rn(r,t).map(([z,ee])=>e.jsxs(g,{style:l.row,children:[e.jsx(p,{w:"70%",children:z}),e.jsx(p,{w:"30%",align:"right",children:String(ee)})]},z))]})]}),D=r.perManager.flatMap(z=>[{key:`g-${z.managerId||z.managerName}`,isGroup:!0,priestCount:z.priestCount,data:{...z.totals,name:z.managerName}},...z.rows.map((ee,_e)=>({key:`p-${z.managerId}-${_e}`,isGroup:!1,data:ee}))]),q=()=>e.jsxs(g,{style:l.section,break:!0,children:[e.jsx(k,{style:l.sectionTitle,children:C(t,"pages.intentions.export.sectionManagers","Gestorzy i ich kapÅani")}),e.jsx(k,{style:l.note,children:C(t,"pages.intentions.export.managersNote","ŻóÅty wiersz = suma caÅej grupy gestora. Poniżej każdy kapÅan z tej grupy osobno.")}),e.jsxs(g,{style:l.table,children:[e.jsxs(g,{style:[l.row,l.headerRow],fixed:!0,children:[e.jsxs(p,{w:h[0],header:!0,children:[C(t,"pages.intentions.export.colManager","Gestor")," / ",C(t,"pages.intentions.export.colPriestName","KapÅan")]}),e.jsx(p,{w:h[1],align:"right",header:!0,children:C(t,"pages.intentions.export.colPriestsCount","KapÅanów")}),e.jsx(p,{w:h[2],align:"right",header:!0,children:C(t,"pages.intentions.export.colIntentionsShort","Intencji")}),e.jsx(p,{w:h[3],align:"right",header:!0,children:C(t,"pages.intentions.export.colPaid","OpÅacone")}),e.jsx(p,{w:h[4],align:"right",header:!0,children:w.entrusted}),e.jsx(p,{w:h[5],align:"right",header:!0,children:w.celebrated}),e.jsx(p,{w:h[6],align:"right",header:!0,children:w.massPast}),e.jsx(p,{w:h[7],align:"right",header:!0,children:C(t,"pages.intentions.export.colWillReceive","Otrzyma")}),e.jsx(p,{w:h[8],align:"right",header:!0,children:C(t,"pages.intentions.export.colPayoutPending","Do wypÅaty")})]}),D.map(z=>e.jsxs(g,{style:z.isGroup?[l.row,l.groupRow]:l.row,wrap:!1,children:[e.jsx(p,{w:h[0],bold:z.isGroup,children:z.isGroup?z.data.name:` ${z.data.name}`}),e.jsx(p,{w:h[1],align:"right",bold:z.isGroup,children:z.isGroup?String(z.priestCount):" "}),e.jsx(p,{w:h[2],align:"right",bold:z.isGroup,children:String(z.data.intentions)}),e.jsx(p,{w:h[3],align:"right",bold:z.isGroup,children:String(z.data.paidCount)}),e.jsx(p,{w:h[4],align:"right",bold:z.isGroup,children:String(z.data.entrusted)}),e.jsx(p,{w:h[5],align:"right",bold:z.isGroup,children:String(z.data.confirmed)}),e.jsx(p,{w:h[6],align:"right",bold:z.isGroup,children:String(z.data.massPast)}),e.jsx(p,{w:h[7],align:"right",bold:z.isGroup,children:Ce(z.data.toPriest)}),e.jsx(p,{w:h[8],align:"right",bold:z.isGroup,children:Ce(z.data.payoutPending)})]},z.key))]})]}),f=()=>e.jsxs(g,{style:l.section,children:[e.jsx(k,{style:l.sectionTitle,children:C(t,"pages.intentions.export.sectionPerTypeTable","Wg rodzaju intencji (peÅna lista)")}),e.jsxs(g,{style:l.table,children:[e.jsxs(g,{style:[l.row,l.headerRow],fixed:!0,children:[e.jsx(p,{w:"34%",header:!0,children:C(t,"pages.intentions.export.colType","Rodzaj Intencji")}),e.jsx(p,{w:"13%",align:"right",header:!0,children:C(t,"pages.intentions.export.colIntentionsShort","Intencji")}),e.jsx(p,{w:"13%",align:"right",header:!0,children:C(t,"pages.intentions.export.colPaid","OpÅacone")}),e.jsx(p,{w:"16%",align:"right",header:!0,children:C(t,"pages.intentions.export.colDonations","WpÅaty")}),e.jsx(p,{w:"12%",align:"right",header:!0,children:C(t,"pages.intentions.export.colAvg","Årednia")}),e.jsx(p,{w:"12%",align:"right",header:!0,children:C(t,"pages.intentions.export.colPriests","KapÅani")})]}),r.perType.map((z,ee)=>e.jsxs(g,{style:l.row,wrap:!1,children:[e.jsx(p,{w:"34%",children:z.type}),e.jsx(p,{w:"13%",align:"right",children:String(z.intentions)}),e.jsx(p,{w:"13%",align:"right",children:String(z.paidCount)}),e.jsx(p,{w:"16%",align:"right",children:Ce(z.totalDonated)}),e.jsx(p,{w:"12%",align:"right",children:Ce(z.avg)}),e.jsx(p,{w:"12%",align:"right",children:Ce(z.toPriest)})]},`${z.type}-${ee}`))]})]}),W=e.jsx(d,{children:e.jsxs(v,{size:"A4",style:l.page,children:[e.jsx(k,{style:l.h1,children:y?nn(r,t):C(t,"pages.intentions.export.pdfTitleFull","Raport finansowy intencji")}),e.jsx(k,{style:l.sub,children:C(t,"pages.intentions.export.generatedAt","Wygenerowano: {date}").replace("{date}",be(r.generatedAt,"dd MMMM yyyy, HH:mm",{locale:Nt(m)}))}),e.jsx(k,{style:l.scopeLine,children:C(t,"pages.intentions.export.yearScopeLine","Zakres czasowy: {scope}").replace("{scope}",on(r,t))}),e.jsx(k,{style:l.rule,children:Ve(y?C(t,"pages.intentions.export.rulePriests","ReguÅa: {fee} PLN dla kapÅana za każdÄ
opÅaconÄ
intencjÄ."):C(t,"pages.intentions.export.pdfRuleFull","ReguÅa podziaÅu: {fee} PLN dla kapÅana / intencjÄ, z reszty 25% Fundusz MiÅosierdzia, 75% Fu
16ndusz Fundacji."))}),e.jsx(B,{}),e.jsx(S,{title:r.year?C(t,"pages.intentions.export.sectionMonthsOfYear","Podsumowanie miesiÄczne â {year}").replace("{year}",r.year):C(t,"pages.intentions.export.sectionPeriodSummary","Podsumowanie wg okresu"),rows:r.periodRows,firstColLabel:C(t,"pages.intentions.export.colPeriod","Okres")}),r.perYear.length>0&&e.jsx(S,{title:C(t,"pages.intentions.export.sectionPerYear","Wg roku (peÅna historia)"),rows:r.perYear,firstColLabel:C(t,"pages.intentions.export.colYear","Rok")}),r.perManager.length>0&&e.jsx(q,{}),e.jsxs(g,{style:l.section,break:!0,children:[e.jsx(k,{style:l.sectionTitle,children:C(t,"pages.intentions.export.sectionPerPriestAllCount","Wg kapÅana â wszyscy ({n})").replace("{n}",r.perPriest.length)}),e.jsxs(g,{style:l.table,children:[e.jsxs(g,{style:[l.row,l.headerRow],fixed:!0,children:[e.jsx(p,{w:H[0],header:!0,children:C(t,"pages.intentions.export.colPriestName","KapÅan")}),e.jsx(p,{w:H[1],header:!0,children:C(t,"pages.intentions.export.colManager","Gestor")}),e.jsx(p,{w:H[2],align:"right",header:!0,children:C(t,"pages.intentions.export.colIntentionsShort","Intencji")}),e.jsx(p,{w:H[3],align:"right",header:!0,children:C(t,"pages.intentions.export.colPaid","OpÅacone")}),y?e.jsx(p,{w:H[4],align:"right",header:!0,children:C(t,"pages.intentions.export.colWillReceive","Otrzyma")}):e.jsxs(e.Fragment,{children:[e.jsx(p,{w:H[4],align:"right",header:!0,children:C(t,"pages.intentions.export.colDonations","WpÅaty")}),e.jsx(p,{w:H[5],align:"right",header:!0,children:C(t,"pages.intentions.export.colPriestReceives","KapÅan otrzyma")}),e.jsx(p,{w:H[6],align:"right",header:!0,children:C(t,"pages.intentions.export.colMercyShort","MiÅosierdzie")})]}),e.jsx(p,{w:H[y?5:7],align:"right",header:!0,children:w.celebrated}),e.jsx(p,{w:H[y?6:8],align:"right",header:!0,children:w.massPast})]}),r.perPriest.map((z,ee)=>e.jsxs(g,{style:l.row,wrap:!1,children:[e.jsx(p,{w:H[0],children:z.name}),e.jsx(p,{w:H[1],children:z.managerName}),e.jsx(p,{w:H[2],align:"right",children:String(z.intentions)}),e.jsx(p,{w:H[3],align:"right",children:String(z.paidCount)}),y?e.jsx(p,{w:H[4],align:"right",children:Ce(z.toPriest)}):e.jsxs(e.Fragment,{children:[e.jsx(p,{w:H[4],align:"right",children:Ce(z.totalDonated)}),e.jsx(p,{w:H[5],align:"right",children:Ce(z.toPriest)}),e.jsx(p,{w:H[6],align:"right",children:Ce(z.mercyFund)})]}),e.jsx(p,{w:H[y?5:7],align:"right",children:String(z.confirmed)}),e.jsx(p,{w:H[y?6:8],align:"right",children:String(z.massPast)})]},`${z.name}-${ee}`))]})]}),e.jsx(R,{}),r.typeChart.length>0&&e.jsx(P,{}),!y&&r.perType.length>0&&e.jsx(f,{}),e.jsx(k,{style:l.pageNum,fixed:!0,render:({pageNumber:z,totalPages:ee})=>C(t,"pages.intentions.export.pdfPageOf","Strona {n} z {total}").replace("{n}",z).replace("{total}",ee)}),e.jsx(k,{style:l.footer,fixed:!0,children:C(t,"pages.intentions.export.pdfFooter","Maronicka Fundacja Misyjna â raport wygenerowany automatycznie z panelu administracyjnego")})]})}),te=await N(W).toBlob(),ie=URL.createObjectURL(te),ae=document.createElement("a");ae.href=ie;const De=y?ln(r,t):"",ve=r.year?`_${r.year}`:"",Ae=C(t,"pages.intentions.export.fileBaseName","Raport_Intencji");ae.download=`${Ae}${De}${ve}_${be(r.generatedAt,"yyyy-MM-dd_HHmm")}.pdf`,document.body.appendChild(ae),ae.click(),ae.remove(),URL.revokeObjectURL(ie)}const Ze=s=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN"}).format(s||0),ze=s=>(s||0).toLocaleString("pl-PL"),wl=Ys.split("-").reverse().join("."),fs="__group__";function Nl({intentions:s=[],priests:n=[],onMarkPriestPaid:a}){const{t:o}=ye(),[i,c]=b.useState("masses"),[t,m]=b.useState("desc"),[r,y]=b.useState(null),[N,d]=b.useState("all"),[v,k]=b.useState("pending"),g=v==="pending",x=b.useMemo(()=>ta(s,n),[s,n]),l=b.useMemo(()=>ta(ii(s,n),n),[s,n]),p=b.useMemo(()=>Pa(s),[s]),T=b.useMemo(()=>li(x,n,g?l:x),[x,l,g,n]),R=b.useMemo(()=>T.find(S=>S.id===N)||null,[T,N]);b.useEffect(()=>{N!=="all"&&!T.some(S=>S.id===N)&&d("all")},[T,N]),b.useEffect(()=>{g&&(i==="capacityPct"||i==="masses")&&c("count"),!g&&i==="count"&&c("masses")},[g,i]);const A=b.useMemo(()=>ps(g?l:x,n,N),[g,l,x,n,N]),P=b.useMemo(()=>oi(A,i,t),[A,i,t]),F=b.useMemo(()=>us(A),[A]),O=b.useMemo(()=>us(ps(l,n,N)),[l,n,N]),u=b.useMemo(()=>us(ps(x,n,N)),[x,n,N]),M=S=>{S===i?m(B=>B==="asc"?"desc":"asc"):(c(S),m(S==="name"?"asc":"desc"))},h=async S=>{y(S.id);try{await(a==null?void 0:a({priestId:S.id,intentionIds:ri(s,S.id,n)}))}finally{y(null)}},L=async()=>
16{if(R){y(fs);try{await(a==null?void 0:a({managerId:R.id,intentionIds:ci(s,n,R.id)}))}finally{y(null)}}},H=S=>`${S.name||o("components.intentionAnalytics.table.managerNone")} (${S.priestCount})`,w=(S,B,D="right")=>e.jsx("th",{scope:"col",className:$("px-2 py-2 font-semibold text-[10px] uppercase tracking-wide whitespace-nowrap",D==="left"?"text-left":"text-right"),children:e.jsxs("button",{type:"button",onClick:()=>M(S),className:$("inline-flex items-center gap-1 hover:text-indigo-700 transition-colors",i===S?"text-indigo-700 dark:text-indigo-400":"text-slate-500 dark:text-slate-400"),children:[B,i===S&&(t==="asc"?e.jsx(vi,{className:"w-3 h-3"}):e.jsx(Ci,{className:"w-3 h-3"}))]})});return e.jsxs(lt,{className:"shadow-sm",children:[e.jsxs(pt,{className:"pb-3",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("div",{className:"flex items-center gap-2",children:[e.jsx(Jt,{className:"w-4 h-4 text-indigo-600"}),e.jsx(Tt,{className:"text-sm font-semibold text-slate-800 dark:text-slate-100",children:o("components.intentionAnalytics.table.title")})]}),e.jsxs("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 mt-1 tabular-nums",children:[g?o("components.intentionAnalytics.table.totalsPending").replace("{priests}",ze(F.priests)).replace("{intentions}",ze(F.intentions)).replace("{pending}",Ze(F.pending)):o("components.intentionAnalytics.table.totals").replace("{priests}",ze(F.priests)).replace("{intentions}",ze(F.intentions)).replace("{value}",Ze(F.totalValue)).replace("{pending}",Ze(F.pending)),g&&e.jsxs("span",{className:"text-slate-400 dark:text-slate-500",children:[" ",o("components.intentionAnalytics.table.payoutSince").replace("{date}",wl)]})]})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 flex-wrap justify-end",children:[e.jsx("div",{role:"group","aria-label":o("components.intentionAnalytics.table.modeLabel"),className:"inline-flex rounded-md border border-slate-200 dark:border-slate-800 overflow-hidden",children:[["pending",o("components.intentionAnalytics.table.modePending")],["all",o("components.intentionAnalytics.table.modeAll")]].map(([S,B])=>e.jsx("button",{type:"button",onClick:()=>k(S),"aria-pressed":v===S,className:$("px-2 py-1 text-[10px] font-semibold uppercase tracking-wide transition-colors",v===S?"bg-indigo-600 text-white":"bg-white dark:bg-slate-900 text-slate-500 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-slate-800"),children:B},S))}),T.length>1&&e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:o("components.intentionAnalytics.table.managerFilterLabel")}),e.jsxs(Ee,{value:N,onValueChange:d,children:[e.jsx(Re,{className:"h-7 w-[220px] text-[11px]","aria-label":o("components.intentionAnalytics.table.managerFilterLabel"),children:e.jsx(Be,{})}),e.jsxs(Oe,{children:[e.jsx(je,{value:"all",className:"text-[11px]",children:o("components.intentionAnalytics.table.managerAll")}),T.map(S=>e.jsx(je,{value:S.id,className:"text-[11px]",children:H(S)},S.id))]})]})]})]})]}),R&&e.jsxs("div",{className:$("mt-2 rounded-md border px-2.5 py-2 flex items-center justify-between gap-3 flex-wrap",O.pending>0?"border-amber-200 bg-amber-50/70 dark:bg-amber-950/20":u.paidOut>0?"border-emerald-200 bg-emerald-50/70 dark:bg-emerald-950/20":"border-slate-200 dark:border-slate-800 bg-slate-50 dark:bg-slate-900/40"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-semibold text-slate-800 dark:text-slate-100 truncate",children:R.name||o("components.intentionAnalytics.table.managerNone")}),e.jsx("p",{className:"text-[10px] text-slate-600 dark:text-slate-300 tabular-nums",children:o(g?"components.intentionAnalytics.table.managerGroupSummaryPending":"components.intentionAnalytics.table.managerGroupSummary").replace("{priests}",ze(F.priests)).replace("{intentions}",ze(F.intentions)).replace("{owed}",Ze(O.pending))})]}),O.pending>0?e.jsxs(K,{size:"sm",variant:"outline",onClick:L,disabled:r===fs,className:"h-7 px-2.5 text-[11px] bg-white dark:bg-slate-900 text-amber-800 border-amber-300 hover:bg-amber-100 hover:text-amber-900 tabular-nums font-semibold",title:o("components.intentionAnalytics.payouts.payGroupTitle").replace("{n}",O.pendingCount).replace("{name}",R.name||o("components.intentionAnalytics.table.managerNone")),children:[r===fs?e.jsx(ke,{className:"w-3.5 h-3.5 mr-1 animate-spin"}):e.jsx(ra,{className:"w-3.5 h-3.5 mr-1"}),o("components.intentionAnalytics.payouts.payGroup").replace("{amount}",Ze(O.pending))]}):u.paidOut>0?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-semibold text-emerald-700 dark:text-emerald-400 tabular-nums",children:[e.jsx(ra,{className:"w-4 h-4"}),o("components.intentionAnalytics.payouts.groupAllPaid"),e.jsx("span",{className:"font-normal text-emerald-600 dark:text-emerald-500",children:o("components.intentionAnalytics.payouts.groupAllPaidDetail").replace("{priests}",ze(u.priests)).replace("{n}",ze(u.paidCount)).replace("{amount}",Ze(u.paidOut))})]}):e.jsx("span",{className:"text-[10px] text-slate-400",children:o("components.intentionAnalytics.payouts.noData")})]})]}),e.jsx(ot,{className:"pt-0",children:P.length===0?e.jsx("p",{className:"text-sm text-slate-400 text-center py-6",children:o(g?"components.intentionAnalytics.payouts.nothingPending":"common.noData")}):e.jsx("div",{className:"overflow-x-auto max-h-[460px] overflow-y-auto scrollbar-thin rounded-md border border-slate-200 dark:border-slate-800",children:e.jsxs("table",{className:"w-full text-[12px] border-collapse",children:[e.jsx("thead",{className:"sticky top-0 bg-slate-50 dark:bg-slate-900 z-[1] border-b border-slate-200 dark:border-slate-800",children:e.jsxs("tr",{children:[w("name",o("components.intentionAnalytics.table.colPriest"),"left"),w(g?"count":"masses",o(g?"components.intentionAnalytics.table.colIntentionsPending":"components.intentionAnalytics.table.colIntentions")),!g&&w("capacityPct",o("components.intentionAnalytics.table.colCapacity")),w("totalValue",o("components.intentionAnalytics.table.colValue")),w("avgValue",o("components.intentionAnalytics.table.colAvg")),w("notified",o("components.intentionAnalytics.table.colNotified")),w("confirmed",o("components.intentionAnalytics.table.colConfirmed")),w("pending",o("components.intentionAnalytics.table.colPayout"))]})}),e.jsx("tbody",{children:P.map(S=>
16e.jsxs("tr",{className:"border-b border-slate-100 dark:border-slate-800 last:border-0 hover:bg-slate-50/70 dark:hover:bg-slate-900/40",children:[e.jsxs("td",{className:"px-2 py-1.5 max-w-[220px]",children:[e.jsx("p",{className:"font-medium text-slate-800 dark:text-slate-100 truncate",children:S.name}),!S.email&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-amber-700",children:[e.jsx(tt,{className:"w-2.5 h-2.5"}),o("components.intentionAnalytics.actions.noEmail")]}),g&&p.get(S.id)&&e.jsx("p",{className:"text-[10px] text-slate-400 tabular-nums",children:o("components.intentionAnalytics.table.lastPayout").replace("{date}",be(new Date(p.get(S.id)),"dd.MM.yyyy"))})]}),e.jsxs("td",{className:"px-2 py-1.5 text-right tabular-nums text-slate-800 dark:text-slate-100",children:[ze(g?S.count:S.masses),!g&&e.jsxs("span",{className:"text-slate-400",children:[" / ",S.maxIntentions||"â"]})]}),!g&&e.jsx("td",{className:"px-2 py-1.5 text-right tabular-nums",children:S.capacityPct==null?e.jsx("span",{className:"text-slate-400",children:"â"}):e.jsxs("span",{className:$("font-semibold",S.capacityPct>=100?"text-rose-700":S.capacityPct>=70?"text-amber-700":"text-emerald-700"),children:[S.capacityPct.toFixed(0),"%"]})}),e.jsx("td",{className:"px-2 py-1.5 text-right tabular-nums text-slate-800 dark:text-slate-100",children:Ze(S.totalValue)}),e.jsx("td",{className:"px-2 py-1.5 text-right tabular-nums text-slate-500 dark:text-slate-400",children:Ze(S.avgValue)}),e.jsxs("td",{className:"px-2 py-1.5 text-right tabular-nums",children:[e.jsx("span",{className:S.notified<S.count?"text-amber-700 font-semibold":"text-slate-600 dark:text-slate-300",children:ze(S.notified)}),e.jsxs("span",{className:"text-slate-400",children:[" / ",ze(S.count)]})]}),e.jsxs("td",{className:"px-2 py-1.5 text-right tabular-nums text-slate-600 dark:text-slate-300",children:[ze(S.confirmed),e.jsxs("span",{className:"text-slate-400",children:[" / ",ze(S.count)]})]}),e.jsx("td",{className:"px-2 py-1.5 text-right whitespace-nowrap",children:S.pending>0?e.jsxs(K,{size:"sm",variant:"outline",onClick:()=>h(S),disabled:!!r,className:"h-6 px-2 text-[10px] bg-amber-50 text-amber-800 border-amber-200 hover:bg-amber-100 hover:text-amber-900 tabular-nums",title:o("components.intentionAnalytics.payouts.markPaidTitle").replace("{n}",S.pendingCount),children:[r===S.id&&e.jsx(ke,{className:"w-3 h-3 mr-1 animate-spin"}),o("components.intentionAnalytics.payouts.payOutAmount").replace("{amount}",Ze(S.pending))]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-emerald-700",children:[e.jsx(Bs,{className:"w-3 h-3"}),o("components.intentionAnalytics.payouts.allPaid")]})})]},S.id))})]})})})]})}function kl({intentions:s=[],priests:n=[],onMarkPriestPaid:a}){return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4 items-start",children:[e.jsx("div",{className:"lg:col-span-8",children:e.jsx(Nl,{intentions:s,priests:n,onMarkPriestPaid:a})}),e.jsx("div",{className:"lg:col-span-4",children:e.jsx(Cl,{intentions:s,priests:n,formatCurrency:vl})})]})}const vl=s=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN"}).format(s);function Cl({intentions:s,priests:n,formatCurrency:a}){const{toast:o}=kt(),{t:i,lang:c}=ye(),[t,m]=b.useState(null),r=b.useMemo(()=>{const d=new Date,v=za(s,d);return[{key:"month",label:d.toLocaleDateString("pl-PL",{month:"long"}),hint:d.getFullYear(),data:mt(v.month,{onlyPaid:!0}),countAll:v.month.length},{key:"year",label:String(d.getFullYear()),hint:i("components.intentionAnalytics.summary.wholeYearHint"),data:mt(v.year,{onlyPaid:!0}),countAll:v.year.length},{key:"all",label:i("temporalChart.allHistory"),hint:i("components.intentionAnalytics.summary.allYearsHint"),data:mt(v.all,{onlyPaid:!0}),countAll:v.all.length}]},[s,i]),y=n.filter(d=>d.active).length,N=async d=>{m(d);try{d==="xls"?await cn(s,n,{t:i,lang:c}):await mn(s,n,{t:i,lang:c}),o({title:i("components.intentionAnalytics.summary.reportDownloadedTitle"),description:i(d==="xls"?"components.intentionAnalytics.summary.xlsSaved":"components.intentionAnalytics.summary.pdfSaved"),className:"bg-green-50 border-green-200 text-green-900"})}catch(v){o({title:i("components.intentionAnalytics.summary.exportErrorTitle"),description:(v==null?void 0:v.message)||i("components.intentionAnalytics.summary.exportErrorDesc"),variant:"destructive"})}finally{m(null)}};return e.jsxs(lt,{className:"shadow-sm bg-gradient-to-br from-indigo-50 to-blue-50 border-indigo-200",children:[e.jsxs(pt,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_i,{className:"w-4 h-4 text-indigo-600"}),e.jsx(Tt,{className:"text-sm font-semibold text-indigo-900",children:i("components.intentionAnalytics.cards.generalSummary")}
16)]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs(K,{variant:"outline",size:"sm",onClick:()=>N("xls"),disabled:!!t,className:"h-7 px-2 bg-white dark:bg-slate-900 text-emerald-700 border-emerald-200 hover:bg-emerald-50 text-[11px]","aria-label":i("components.intentionAnalytics.summary.downloadXlsAria"),children:[t==="xls"?e.jsx(ke,{className:"w-3 h-3 animate-spin"}):e.jsx($a,{className:"w-3 h-3"}),e.jsx("span",{className:"ml-1",children:"XLS"})]}),e.jsxs(K,{variant:"outline",size:"sm",onClick:()=>N("pdf"),disabled:!!t,className:"h-7 px-2 bg-white dark:bg-slate-900 text-rose-700 border-rose-200 hover:bg-rose-50 text-[11px]","aria-label":i("components.intentionAnalytics.summary.downloadPdfAria"),children:[t==="pdf"?e.jsx(ke,{className:"w-3 h-3 animate-spin"}):e.jsx(va,{className:"w-3 h-3"}),e.jsx("span",{className:"ml-1",children:"PDF"})]})]})]}),e.jsx("p",{className:"text-[10px] text-slate-500 dark:text-slate-400 mt-1",children:i("components.intentionAnalytics.summary.feeRule").replace("{n}",qe)})]}),e.jsxs(ot,{className:"space-y-3",children:[r.map(d=>e.jsx(Sl,{period:d,formatCurrency:a},d.key)),e.jsxs("div",{className:"pt-2 border-t border-indigo-200 flex justify-between items-center text-xs",children:[e.jsx("span",{className:"text-slate-600 dark:text-slate-300 font-medium",children:i("components.intentionAnalytics.summary.activePriests")}),e.jsx("span",{className:"font-bold text-indigo-900",children:y})]}),e.jsx(_l,{intentions:s,priests:n})]})]})}function _l({intentions:s,priests:n}){const{t:a}=ye(),o=b.useMemo(()=>{const i=new Map;s.forEach(d=>{d.priest_id&&i.set(d.priest_id,(i.get(d.priest_id)||0)+1)});let c=0,t=0,m=0,r=0,y=0;n.forEach(d=>{if(!d.active)return;const v=Number(d.max_intentions)||0,k=i.get(d.id)||0;if(c+=v,t+=k,v<=0)return;const g=k/v;g>=1?m+=1:g>=.5?r+=1:y+=1});const N=c>0?Math.min(t/c*100,999):0;return{totalLoad:t,totalMax:c,overallPct:N,overloaded:m,healthy:r,underused:y}},[s,n]);return e.jsxs("div",{className:"rounded-md border border-indigo-200 bg-white dark:bg-slate-900/70 p-2.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-1.5",children:[e.jsx("p",{className:"text-[11px] font-bold text-indigo-900",children:a("components.intentionAnalytics.capacity.title")}),e.jsxs("span",{className:"text-[10px] text-slate-500 dark:text-slate-400 tabular-nums",children:[o.totalLoad.toLocaleString("pl-PL")," / ",o.totalMax.toLocaleString("pl-PL")," (",o.overallPct.toFixed(0),"%)"]})]}),e.jsx("div",{className:"h-1.5 bg-indigo-50 rounded-full overflow-hidden mb-2",children:e.jsx("div",{className:$("h-full transition-all",o.overallPct>=90?"bg-rose-500":o.overallPct>=70?"bg-amber-500":"bg-emerald-500"),style:{width:`${Math.min(o.overallPct,100)}%`}})}),e.jsxs("div",{className:"grid grid-cols-3 gap-1.5 text-[10px]",children:[e.jsx(bs,{label:a("components.intentionAnalytics.capacity.overloaded"),value:o.overloaded,tone:"rose"}),e.jsx(bs,{label:a("components.intentionAnalytics.capacity.healthy"),value:o.healthy,tone:"emerald"}),e.jsx(bs,{label:a("components.intentionAnalytics.capacity.underused"),value:o.underused,tone:"slate"})]})]})}function bs({label:s,value:n,tone:a}){const o={rose:"bg-rose-50 text-rose-800 border-rose-200",emerald:"bg-emerald-50 text-emerald-800 border-emerald-200",slate:"bg-slate-50 dark:bg-slate-900/40 text-slate-700 dark:text-slate-200 border-slate-200 dark:border-slate-800"};return e.jsxs("div",{className:$("rounded border px-1.5 py-1 text-center",o[a]),children:[e.jsx("div",{className:"text-[9px] uppercase tracking-wide opacity-80 truncate",children:s}),e.jsx("div",{className:"text-xs font-bold tabular-nums",children:n})]})}function Sl({period:s,formatCurrency:n}){const{t:a}=ye(),{label:o,hint:i,data:c,countAll:t}=s,m=c.count>0;return e.jsxs("div",{className:"bg-white dark:bg-slate-900/70 ring-1 ring-indigo-100 rounded-md p-2.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-bold text-indigo-900 capitalize truncate",children:o}),e.jsx("p",{className:"text-[9px] text-slate-500 dark:text-slate-400",children:i})]}),e.jsx("span",{className:"text-[10px] text-slate-500 dark:text-slate-400 tabular-nums shrink-0",children:a("components.intentionAnalytics.summary.periodCount").replace("{total}
16",t.toLocaleString("pl-PL")).replace("{paid}",c.count.toLocaleString("pl-PL"))})]}),m?e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1 text-[10.5px]",children:[e.jsx(ht,{label:a("components.intentionAnalytics.summary.rowDonations"),value:n(c.totalDonated),bold:!0}),e.jsx(ht,{label:a("components.intentionAnalytics.summary.rowAvg"),value:n(c.avg),muted:!0}),e.jsx(ht,{label:a("components.intentionAnalytics.summary.rowPriests"),value:n(c.totalToPriests),accent:"emerald"}),e.jsx(ht,{label:a("components.intentionAnalytics.summary.rowMercy"),value:n(c.mercyFund),accent:"rose"}),e.jsx(ht,{label:a("components.intentionAnalytics.summary.rowFoundation"),value:n(c.adminCost),accent:"amber"}),e.jsx(ht,{label:a("components.intentionAnalytics.summary.rowMinMax"),value:`${n(c.min)} / ${n(c.max)}`,muted:!0})]}):e.jsx("p",{className:"text-[10px] text-slate-400 italic",children:a("components.intentionAnalytics.summary.noPaidInPeriod")})]})}function ht({label:s,value:n,bold:a=!1,muted:o=!1,accent:i}){const c={emerald:"text-emerald-700",rose:"text-rose-700",amber:"text-amber-700"}[i]||"text-slate-800 dark:text-slate-100";return e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsx("span",{className:`text-[10px] ${o?"text-slate-400":"text-slate-600 dark:text-slate-300"} font-medium truncate`,children:s}),e.jsx("span",{className:`tabular-nums ${a?"font-bold text-indigo-900":`font-semibold ${c}`} truncate`,children:n})]})}const jt=4,pa=24*60*60*1e3;function Pl(s){if(!s)return{phase:"none"};const n=s.priest_notified_at,a=s.priest_confirmed_at,o=s.donor_confirmation_sent_at;if(o)return{phase:"donor-notified",donorNotifiedAt:o,confirmedAt:a,notifiedAt:n};if(a)return{phase:"priest-confirmed",confirmedAt:a,notifiedAt:n,autoConfirmed:!!s.auto_confirmed};if(n){const i=new Date(n).getTime()+jt*pa,c=Date.now(),t=new Date(i).toISOString();return c>=i?{phase:"auto-confirm-due",notifiedAt:n,autoConfirmDueAt:t}:{phase:"priest-notified",notifiedAt:n,autoConfirmDueAt:t,daysUntilAutoConfirm:Math.ceil((i-c)/pa)}}return{phase:"none"}}function Ml(s=[]){return s.filter(n=>n.donor_confirmation_sent_at||!n.email?!1:Pl(n).phase==="priest-confirmed")}function Dl(s=[]){return s.filter(n=>n.priest_notified_at&&!n.priest_confirmed_at)}function Al(s,n){if(!s)return null;const a=new Date(s).getTime();if(!Number.isFinite(a))return null;const o=Math.round((Date.now()-a)/6e4);if(o<1)return n("pages.intentions.flow.justNow");if(o<60)return n("pages.intentions.flow.minutesAgo").replace("{n}",o);const i=Math.round(o/60);return i<24?n("pages.intentions.flow.hoursAgo").replace("{n}",i):n("pages.intentions.flow.daysAgo").replace("{n}",Math.round(i/24))}function Tl({intentions:s=[],priests:n=[],onAutoAssign:a,onConfirmPriests:o,onRefresh:i,assigning:c=!1}){var M;const{t}=ye(),{toast:m}=kt(),r=Sa(),[y,N]=b.useState("30d"),[d,v]=b.useState(null),k=b.useMemo(()=>di(s,{windowKey:y}),[s,y]),g=b.useMemo(()=>mi(s,n,{autoConfirmDays:jt}),[s,n]),x=b.useMemo(()=>pi(s,n),[s,n]),l=b.useMemo(()=>Ml(s),[s]),p=b.useMemo(()=>Dl(s),[s]),T=((M=k[0])==null?void 0:M.total)??0,R=async()=>{v("notify");try{const h={mode:"pending",sinceDays:Ma},{data:L,error:H}=await Te.functions.invoke("notify-priest-assignment",{body:{...h,dryRun:!0}});if(H||!(L!=null&&L.ok)){Me.error("[IntentionFlowPanel] preview_failed",(H==null?void 0:H.message)||(L==null?void 0:L.error)),m({title:t("pages.intentions.toasts.notifyFailedTitle"),description:t("pages.intentions.toasts.notifyFailedDesc"),variant:"destructive"});return}const w=L.wouldNotifyIntentions??0;if(w===0){m({title:t("pages.intentions.toasts.notifyAlreadyDoneTitle"),description:t("pages.intentions.flow.nothingToSend")});return}if(!await r({title:t("pages.intentions.flow.confirmTitle"),description:t("pages.intentions.flow.confirmBody").replace("{priests}",L.wouldNotifyPriests??0).replace("{intentions}",w)}))return;const{data:B,error:D}=await Te.functions.invoke("notify-priest-assignment",{body:h}),q=D||!(B!=null&&B.ok)?{ok:!1}:{ok:!0,...B},f=Xt(q,t);f&&m(f),i==null||i()}catch(h){Me.error("[IntentionFlowPanel] notify_threw",h==null?void 0:h.message),m({title:t("pages.intentions.toasts.notifyFailedTitle"),description:t("pages.intentions.toasts.networkErrorDesc"),variant:"destructive"})}finally{v(null)}},A=async()=>
16{if(!(!o||p.length===0||!await r({title:t("pages.intentions.flow.confirmPriestsTitle").replace("{n}",p.length),description:t("pages.intentions.flow.confirmPriestsBody").replace("{n}",p.length).replace("{days}",jt),confirmLabel:t("pages.intentions.flow.actions.confirmPriests")}))){v("confirm");try{await o(p.map(L=>L.id))}finally{v(null)}}},P=async()=>{if(l.length!==0){v("donors");try{const{data:h,error:L}=await Te.functions.invoke("notify-donor-of-confirmation",{body:{intentionIds:l.map(B=>B.id)}});if(L||!(h!=null&&h.ok)){Me.error("[IntentionFlowPanel] donor_notify_failed",(L==null?void 0:L.message)||(h==null?void 0:h.error)),m({title:t("components.intentionAnalytics.donor.sendFailedTitle"),description:t("components.intentionAnalytics.donor.partialSentDesc").replace("{sent}",0).replace("{failed}",l.length),variant:"destructive"}),i==null||i();return}const H=h.sent??0,w=(h.failed??0)+(h.missing??0)+(h.remaining??0),S=h.invalidEmail??0;if(H===0&&w===0&&S===0)m({title:t("pages.intentions.toasts.notifyAlreadyDoneTitle"),description:t("pages.intentions.flow.nothingToSend")});else if(w>0||S>0){Me.error("[IntentionFlowPanel] donor_notify_partial_fail",`failed=${w} invalidEmail=${S}`);const B=[w>0?t("components.intentionAnalytics.donor.partialSentDesc").replace("{sent}",H).replace("{failed}",w):t("components.intentionAnalytics.donor.sentDescMany").replace("{n}",H),S>0?t("components.intentionAnalytics.donor.invalidEmailDesc").replace("{n}",S):""].filter(Boolean).join(" ");m({title:H>0?t("components.intentionAnalytics.donor.partialSentTitle"):t("components.intentionAnalytics.donor.sendFailedTitle"),description:B,variant:H===0?"destructive":void 0})}else m({title:t("components.intentionAnalytics.donor.sentTitle"),description:t(H===1?"components.intentionAnalytics.donor.sentDescOne":"components.intentionAnalytics.donor.sentDescMany").replace("{n}",H),className:"bg-emerald-50 border-emerald-200 text-emerald-900"});i==null||i()}catch(h){Me.error("[IntentionFlowPanel] donor_notify_threw",h==null?void 0:h.message),m({title:t("components.intentionAnalytics.donor.sendFailedTitle"),description:t("components.intentionAnalytics.donor.networkErrorDesc"),variant:"destructive"})}finally{v(null)}}},F=Al(g.lastNotifiedAt,t),O=g.notifyHeldMassPassed-(g.notifyHeldArchive||0)+g.notifyHeldNoEmail+g.notifyHeldTooOld,u=g.forgotten||[];return e.jsxs(lt,{className:"shadow-sm border-slate-200 dark:border-slate-800",children:[e.jsx(pt,{className:"pb-3",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("div",{className:"flex items-center gap-2",children:[e.jsx(Si,{className:"w-4 h-4 text-indigo-600"}),e.jsx(Tt,{className:"text-sm font-semibold text-slate-800 dark:text-slate-100",children:t("pages.intentions.flow.title")})]}),e.jsxs("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 mt-1 flex items-center gap-1.5",children:[e.jsx(Ha,{className:"w-3 h-3 shrink-0"}),F?t("pages.intentions.flow.lastNotified").replace("{when}",F):t("pages.intentions.flow.lastNotifiedNever")]}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 mt-0.5",children:t("pages.intentions.flow.cohortNote").replace("{n}",T.toLocaleString("pl-PL"))})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:ui.map(h=>e.jsx("button",{type:"button",onClick:()=>N(h),className:$("px-2.5 py-1 rounded-full text-[11px] font-medium border transition-colors",y===h?"bg-indigo-600 border-indigo-600 text-white shadow-sm":"bg-white dark:bg-slate-900 border-slate-200 dark:border-slate-800 text-slate-600 dark:text-slate-300 hover:border-indigo-300 hover:text-indigo-700"),children:t(`pages.intentions.flow.windows.${h}`)},h))})]})}),e.jsxs(ot,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-8 gap-1.5",children:k.map(h=>e.jsxs("div",{className:"rounded-md border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900/60 px-2 py-1.5",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-1",children:[e.jsx("span",{className:"text-base font-bold text-slate-900 dark:text-slate-100 tabular-nums",children:h.count.toLocaleStr
16ing("pl-PL")}),h.key!=="received"&&T>0&&e.jsxs("span",{className:"text-[9px] text-slate-400 dark:text-slate-500 tabular-nums",children:[Math.round(h.count/T*100),"%"]})]}),e.jsx("p",{className:"text-[9.5px] leading-tight text-slate-500 dark:text-slate-400 mt-0.5 line-clamp-2",children:t(`pages.intentions.flow.stages.${h.key}`)}),e.jsx("div",{className:"h-1 bg-slate-100 dark:bg-slate-800 rounded-full mt-1 overflow-hidden",children:e.jsx("div",{className:"h-full bg-indigo-400",style:{width:`${T>0?Math.round(h.count/T*100):0}%`}})})]},h.key))}),e.jsxs("div",{className:"rounded-md border border-slate-200 dark:border-slate-800 divide-y divide-slate-100 dark:divide-slate-800",children:[e.jsx(Et,{tone:g.unassigned>0?"amber":"ok",count:g.unassigned,label:t("pages.intentions.flow.queue.unassigned"),action:a&&e.jsxs(K,{size:"sm",variant:"outline",onClick:a,disabled:c||g.unassigned===0,className:"h-7 px-2 text-[11px]",children:[c?e.jsx(ke,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(ss,{className:"w-3 h-3 mr-1"}),t("pages.intentions.flow.actions.autoAssign")]})}),e.jsx(Et,{tone:g.notifyReady>0?"rose":"ok",count:g.notifyReady,label:t("pages.intentions.flow.queue.notify"),hint:g.notifyReady>0?t("pages.intentions.flow.queue.notifyHint").replace("{priests}",g.notifyPriests):O>0?t("pages.intentions.flow.queue.heldNote").replace("{n}",O):null,action:e.jsxs(K,{size:"sm",onClick:R,disabled:d!==null||g.notifyReady===0,className:"h-7 px-2 text-[11px] bg-rose-600 hover:bg-rose-700 text-white",children:[d==="notify"?e.jsx(ke,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(es,{className:"w-3 h-3 mr-1"}),t("pages.intentions.flow.actions.notify")]})}),e.jsx(Et,{tone:g.confirmOverdue>0?"amber":"slate",count:g.awaitingConfirm,label:t("pages.intentions.flow.queue.awaitingConfirm").replace("{n}",jt),hint:g.confirmOverdue>0?t("pages.intentions.flow.queue.overdueHint").replace("{n}",g.confirmOverdue):null,action:o&&e.jsxs(K,{size:"sm",variant:"outline",onClick:A,disabled:d!==null||p.length===0,className:"h-7 px-2 text-[11px] bg-amber-50 text-amber-800 border-amber-200 hover:bg-amber-100",children:[d==="confirm"?e.jsx(ke,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(Ja,{className:"w-3 h-3 mr-1"}),t("pages.intentions.flow.actions.confirmPriests")]})}),e.jsx(Et,{tone:l.length>0?"emerald":"ok",count:l.length,label:t("pages.intentions.flow.queue.donorPending"),action:e.jsxs(K,{size:"sm",variant:"outline",onClick:P,disabled:d!==null||l.length===0,className:"h-7 px-2 text-[11px] bg-emerald-50 text-emerald-700 border-emerald-200 hover:bg-emerald-100",children:[d==="donors"?e.jsx(ke,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx($t,{className:"w-3 h-3 mr-1"}),t("pages.intentions.flow.actions.notifyDonors")]})}),e.jsx(Et,{tone:"slate",count:g.payoutPending,label:t("pages.intentions.flow.queue.payoutPending")})]}),(x.length>0||g.massPassedUnconfirmed>0||u.length>0)&&e.jsxs("div",{className:"space-y-1.5",children:[u.length>0&&e.jsx(ys,{tone:"rose",children:t("pages.intentions.flow.warnForgotten").replace("{n}",g.forgottenCount).replace("{priests}",u.slice(0,3).map(h=>`${h.name} (${h.count})`).join(", ")+(u.length>3?" â¦":""))}),x.length>0&&e.jsxs(ys,{children:[t("pages.intentions.flow.warnNoEmail").replace("{priests}",x.length).replace("{n}",x.reduce((h,L)=>h+L.count,0)),e.jsxs("span",{className:"text-slate-500 dark:text-slate-400",children:[" ",x.slice(0,4).map(h=>h.name).join(", "),x.length>4?" â¦":""]})]}),g.massPassedUnconfirmed>0&&e.jsx(ys,{children:t("pages.intentions.flow.warnMassPassed").replace("{n}",g.massPassedUnconfirmed)})]})]})]})}function Et({count:s,label:n,hint:a,action:o,tone:i="slate"}){const c={rose:"text-rose-700 dark:text-rose-400",amber:"text-amber-700 dark:text-amber-400",emerald:"text-emerald-700 dark:text-emerald-400",slate:"text-slate-800 dark:text-slate-100",ok:"text-slate-300 dark:text-slate-600"};return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsx("span",{className:$("text-lg font-bold tabular-nums w-12 shrink-0 text-right",c[i]),children:s.toLocaleString("pl-PL")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[12px] text-slate-700 dark:text-slate-200 leading-tight",children:n}),a&&e.jsx("p",{className:"text-[10.5px] text-slate-500 dark:text-slate-400 leading-tight mt-0.5",children:a})]}),o&&e.jsx("div",{className:"shrink-0",children:o})]})}function ys({children:s,tone:n="amber"}){const a={amber:{box:"border-amber-200 bg-amber-50 dark:border-amber-900/60 dark:bg-amber-950/30",icon:"text-amber-700 dark:text-amber-400",text:"text-amber-900 dark:text-amber-200"},rose:{box:"border-rose-300 bg-rose-50 dark:border-rose-900/60 dark:bg-rose-950/30",icon:"text-rose-700 dark:text-rose-400",text:"text-rose-900 dark:text-rose-200"}},o=a[n]||a.amber;return e.jsxs("div",{className:$("flex items-start gap-2 rounded-md border px-2.5 py-1.5",o.box),children:[e.jsx(tt,{className:$("w-3.5 h-3.5 mt-0.5 shrink-0",o.icon)}),e.jsx("p",{className:$("text-[11px] leading-relaxed",o.text),children:s})]})}const js=s=>String(s??"").toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu,""),ws="__none__";function pn({value:s,onChange:n,priests:a=[],labels:o={},disabled:i=!1,id:c,specialOptions:t=null}){const[m,r]=b.useState(!1),[y,N]=b.useState(""),d=a.find(l=>l.id===s)||null,v=(t==null?void 0:t.find(l=>l.value===s))||null,k=b.useMemo(()=>{const l=js(y.trim());return l?a.filter(p=>js(p.name).includes(l)||js(p.email).includes(l)):a},[a,y]),g=l=>{t?n==null||n(l):n==null||n(l===ws?"":l),N(""),r(!1)},x=d?d.name||d.email||d.id:(v==null?void 0:v.label)??o.none;return e.jsxs(Pi,{open:m,onOpenChange:l=>{r(l),l||N("")},modal:!0,children:[e.jsx(Mi,{asChild:!0,children:e.jsxs(K,{id:c,type:"button",variant:"outline",role:"combobox","aria-expanded":m,disabled:i,className:"w-full justify-between font-normal bg-white text-slate-900 dark:bg-slate-900 dark:!text-slate-100 dar
16k:border-slate-700 dark:hover:bg-slate-800",children:[e.jsxs("span",{className:"flex items-center gap-2 truncate",children:[e.jsx(qn,{className:"w-4 h-4 shrink-0 text-slate-400"}),e.jsx("span",{className:$("truncate",!d&&!v&&"text-slate-400"),children:x}),d&&d.active===!1&&e.jsx("span",{className:"shrink-0 rounded bg-slate-100 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-slate-600",children:o.inactiveBadge})]}),e.jsx(Ya,{className:"w-4 h-4 shrink-0 opacity-50"})]})}),e.jsx(Di,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(Ai,{shouldFilter:!1,children:[e.jsx(Ti,{value:y,onValueChange:N,placeholder:o.searchPlaceholder}),e.jsxs(Li,{children:[e.jsx(zi,{children:o.empty}),e.jsx(la,{children:t?t.map(l=>e.jsxs(xs,{value:l.value,onSelect:()=>g(l.value),children:[e.jsx(Kt,{className:$("mr-2 h-4 w-4 shrink-0",s===l.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"text-slate-600 dark:text-slate-300",children:l.label})]},l.value)):e.jsxs(xs,{value:ws,onSelect:()=>g(ws),children:[e.jsx(Ca,{className:$("mr-2 h-4 w-4",s?"opacity-60":"opacity-0")}),e.jsx("span",{className:"text-slate-500",children:o.none})]})}),k.length>0&&e.jsx(la,{children:k.map(l=>e.jsxs(xs,{value:l.id,onSelect:()=>g(l.id),children:[e.jsx(Kt,{className:$("mr-2 h-4 w-4 shrink-0",s===l.id?"opacity-100":"opacity-0")}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate",children:l.name||l.email||l.id}),e.jsxs("span",{className:"flex flex-wrap items-center gap-x-2 text-[10px] text-slate-500",children:[l.active===!1&&e.jsx("span",{className:"font-semibold uppercase tracking-wide text-slate-600",children:o.inactiveBadge}),l.autoEligible===!1&&l.active!==!1&&e.jsx("span",{children:o.outOfDistribution}),l.hasEmail===!1&&e.jsx("span",{className:"text-amber-700",children:o.noEmail}),l.intentionsThisYear>0&&e.jsx("span",{className:"tabular-nums",children:String(o.loadThisYear||"").replace("{n}",l.intentionsThisYear)})]})]})]},l.id))})]})]})})]})}const Ns=["individual","collective","gregorian","thirty_single","novena","triduum","heavenly_court","other"],Ll=()=>{const s=new Date;return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`},Ts={name:"",email:"",phone:"",type:"individual",content:"",amount:"",currency:"PLN",paid:!0,receivedOn:"",massDate:"",massTime:"",massCity:"",massChurch:"",priestId:"",copies:"1",massCount:"1",spreadSlots:!0},ua=500,zl=1e3,ks=(s,n)=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:n||"PLN"}).format(Number.isFinite(s)?s:0);function Fl(s){if(!s)return null;const n=c=>c?String(c).slice(0,10):"",a=Math.max(1,Math.floor(Number(s.mass_count)||1)),o=Number(s.amount),i=Number.isFinite(o)?o/a:null;return{...Ts,name:s.name||"",email:s.email||"",phone:s.phone||"",type:s.type||"individual",content:s.content||"",massCount:String(a),amount:i==null?"":String(Number(i.toFixed(2))),currency:s.currency||"PLN",paid:fi.has(String(s.status||"").toLowerCase()),receivedOn:n(s.paid_at||s.created_at),massDate:n(s.mass_date),massTime:(s.mass_time||"").slice(0,5),massCity:s.mass_city||"",massChurch:s.mass_church||"",priestId:s.priest_id||"",copies:"1"}}function ga(s){return s?{source:s.source||null,reportSource:Ia(s)&&s.report_source||null}:{}}function Il({open:s,onOpenChange:n,onSubmit:a,seed:o=null,priests:i=[]}){const{t:c,language:t}=ye(),[m,r]=b.useState(Ts),[y,N]=b.useState(!1),d=b.useRef(null);b.useEffect(()=>{s&&(r(Fl(o)||{...Ts,receivedOn:Ll()}),setTimeout(()=>{var B;return(B=d.current)==null?void 0:B.focus()},80))},[s]);const v=B=>D=>
16{const q=typeof D=="string"?D:D.target.value;r(f=>({...f,[B]:q}))},k=b.useMemo(()=>(Ns.includes(m.type)||!m.type?Ns:[m.type,...Ns]).map(D=>({key:D,label:$e(D,t)})),[t,m.type]),g=Math.floor(Number(m.copies)),x=Number.isFinite(g)&&g>=1&&g<=ua,l=i.find(B=>B.id===m.priestId)||null,p=!!o,T=p&&x&&g>1&&!!m.priestId,R=La(m.type),A=wt({type:m.type}),P=R?A:Math.floor(Number(m.massCount)),F=Number.isFinite(P)&&P>=1&&P<=zl,O=Number(String(m.amount).replace(",",".")),u=m.amount===""||Number.isFinite(O)&&O>=0,M=!R&&F&&P>1,h=M?P:1,L=u?(Number(O)||0)*h:0,H=Ge({amount:L,type:m.type,mass_count:R?null:P,report_source:ga(o).reportSource}),w=m.name.trim().length>0&&m.content.trim().length>0&&u&&x&&F&&!y,S=async()=>{if(!(!w||!a)){N(!0);try{await a({name:m.name.trim(),email:m.email.trim()||null,phone:m.phone.trim()||null,type:m.type,content:m.content.trim(),amount:m.amount===""?0:Number(L.toFixed(2)),massCount:R?null:P,currency:m.currency,paid:m.paid,receivedOn:m.receivedOn||null,massDate:m.massDate||null,massTime:m.massTime||null,massCity:m.massCity.trim()||null,massChurch:m.massChurch.trim()||null,priestId:m.priestId||null,priestName:(l==null?void 0:l.name)||null,copies:g,spreadSlots:T?m.spreadSlots:!1,...ga(o)})&&n(!1)}finally{N(!1)}}};return e.jsx(vt,{open:s,onOpenChange:B=>!y&&n(B),children:e.jsxs(Ct,{className:"sm:max-w-[620px] max-h-[90vh] overflow-y-auto",children:[e.jsxs(_t,{children:[e.jsxs(St,{className:"flex items-center gap-2 text-slate-900",children:[o?e.jsx(Rs,{className:"w-4 h-4 text-indigo-600"}):e.jsx(Wa,{className:"w-4 h-4 text-indigo-600"}),c(o?"pages.intentions.manual.duplicateTitle":"pages.intentions.manual.title")]}),e.jsx(Pt,{className:"text-slate-600",children:c(o?"pages.intentions.manual.duplicateDescription":"pages.intentions.manual.description")})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs("div",{className:"rounded-md border border-indigo-200 bg-indigo-50/60 dark:border-indigo-900 dark:bg-indigo-950/30 p-3 space-y-3",children:[e.jsxs("div",{className:$("grid grid-cols-1 gap-3",p&&"sm:grid-cols-2"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-priest",className:"text-xs font-semibold",children:c("pages.intentions.manual.priestLabel")}),e.jsx(pn,{id:"manual-priest",value:m.priestId,onChange:B=>r(D=>({...D,priestId:B})),priests:i,disabled:y,labels:{none:c("pages.intentions.manual.priestNone"),searchPlaceholder:c("pages.intentions.manual.priestSearchPlaceholder"),empty:c("pages.intentions.manual.priestEmpty"),inactiveBadge:c("pages.intentions.manual.priestInactiveBadge"),outOfDistribution:c("pages.intentions.manual.priestOutOfDistribution"),noEmail:c("pages.intentions.manual.priestNoEmailBadge"),loadThisYear:c("pages.intentions.manual.priestLoadThisYear")}})]}),p&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-copies",className:"text-xs font-semibold",children:c("pages.intentions.manual.copiesLabel")}),e.jsx(pe,{id:"manual-copies",inputMode:"numeric",value:m.copies,onChange:v("copies"),disabled:y,className:x?void 0:"border-rose-400"}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:c("pages.intentions.manual.copiesHint").replace("{max}",ua)})]})]}),(l==null?void 0:l.active)===!1?e.jsxs("p",{className:"text-[11px] text-amber-800 dark:text-amber-500 flex items-start gap-1",children:[e.jsx(tt,{className:"w-3 h-3 mt-0.5 shrink-0"}),c("pages.intentions.manual.priestInactiveHint")]}):m.priestId?e.jsx("p",{className:"text-[11px] text-indigo-800 dark:text-indigo-300",children:c(p?"pages.intentions.manual.priestKeepHint":"pages.intentions.manual.priestAssignedHint").replace("{priest}",(l==null?void 0:l.name)||c("pages.intentions.table.priestFallback"))}):null,T&&e.jsxs("label",{className:"flex items-start gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m.spreadSlots,disabled:y,onChange:B=>r(D=>({...D,spreadSlots:B.target.checked})),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium",children:c("pages.intentions.manual.spreadLabel")}
16),e.jsx("span",{className:"block text-[11px] text-slate-600 dark:text-slate-400",children:c("pages.intentions.manual.spreadHint")})]})]}),Ia(o)&&e.jsx("p",{className:"text-[11px] text-amber-800 dark:text-amber-500",children:c("pages.intentions.manual.dantisNote")})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"manual-name",className:"text-xs font-semibold",children:[c("pages.intentions.manual.nameLabel")," ",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(pe,{id:"manual-name",ref:d,value:m.name,onChange:v("name"),placeholder:c("pages.intentions.manual.namePlaceholder"),disabled:y})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-email",className:"text-xs font-semibold",children:c("pages.intentions.manual.emailLabel")}),e.jsx(pe,{id:"manual-email",type:"email",value:m.email,onChange:v("email"),placeholder:"[email protected]",disabled:y}),!m.email.trim()&&e.jsxs("p",{className:"text-[11px] text-amber-700 dark:text-amber-500 flex items-start gap-1",children:[e.jsx(tt,{className:"w-3 h-3 mt-0.5 shrink-0"}),c("pages.intentions.manual.noEmailWarning")]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-phone",className:"text-xs font-semibold",children:c("pages.intentions.manual.phoneLabel")}),e.jsx(pe,{id:"manual-phone",value:m.phone,onChange:v("phone"),disabled:y})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{className:"text-xs font-semibold",children:c("pages.intentions.manual.typeLabel")}),e.jsxs(Ee,{value:m.type,onValueChange:v("type"),disabled:y,children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Oe,{children:k.map(B=>e.jsx(je,{value:B.key,children:B.label},B.key))})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"manual-content",className:"text-xs font-semibold",children:[c("pages.intentions.manual.contentLabel")," ",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(_a,{id:"manual-content",value:m.content,onChange:v("content"),rows:3,placeholder:c("pages.intentions.manual.contentPlaceholder"),disabled:y})]}),e.jsx("div",{className:"rounded-md border border-slate-200 dark:border-slate-800 p-3 space-y-2",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[9rem,1fr] gap-3 items-start",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"manual-masscount",className:"text-xs font-semibold flex items-center gap-1.5",children:[e.jsx(Ws,{className:"w-3.5 h-3.5 text-slate-400"}),c("pages.intentions.manual.massCountLabel")]}),e.jsx(pe,{id:"manual-masscount",inputMode:"numeric",value:R?String(A):m.massCount,onChange:v("massCount"),disabled:y||R,className:F?void 0:"border-rose-400"})]}),e.jsx("div",{className:"space-y-1 sm:pt-6",children:R?e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:c("pages.intentions.manual.massCountFixed").replace("{n}",A)}):M?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] font-semibold text-slate-800 dark:text-slate-100 tabular-nums",children:c("pages.intentions.manual.massCountTotal").replace("{count}",P).replace("{unit}",ks(O||0,m.currency)).replace("{total}",ks(L,m.currency))}),e.jsx("p",{className:"text-[11px] text-emerald-700 dark:text-emerald-400 tabular-nums",children:c("pages.intentions.manual.massCountFee").replace("{amount}",ks(H,"PLN"))})]}):e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:c("pages.intentions.manual.massCountHint")})})]})}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"space-y-1.5 col-span-1",children:[e.jsx(J,{htmlFor:"manual-amount",className:"text-xs font-semibold",children:c(M?"pages.intentions.manual.amountPerMassLabel":"pages.intentions.manual.amountLabel")}),e.jsx(pe,{id:"manual-amount",inputMode:"decimal",value:m.amount,onChange:v("amount"),placeholder:"0,00",disabled:y,className:u?void 0:"border-rose-400"})]}),e.jsxs("div",{className:"space-y-1.5 col-span-1",children:[e.jsx(J,{className:"text-xs font-semibold",children:c("pages.intentions.manual.currencyLabel")}),e.jsxs(Ee,{value:m.currency,onValueChange:v("currency"),disabled:y,children:[e.jsx(Re,{children:e.jsx(Be,{})}),e.jsx(Oe,{children:["PLN","EUR","USD"].map(B=>e.jsx(je,{value:B,children:B},B))})]})]}),e.jsxs("div",{className:"space-y-1.5 col-span-1",children:[e.jsx(J,{htmlFor:"manual-received",className:"text-xs font-semibold",children:c("pages.intentions.manual.receivedOnLabel")}),e.jsx(pe,{id:"manual-received",type:"date",value:m.receivedOn,onChange:v("receivedOn"),disabled:y})]}),e.jsxs("div",{className:"space-y-1.5 col-span-1",children:[e.jsx(J,{htmlFor:"manual-massdate",className:"text-xs font-semibold",children:c("pages.intentions.manual.massDateLabel")}),e.jsx(pe,{id:"manual-massdate",type:"date",value:m.massDate,onChange:v("massDate"),disabled:y})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-masstime",className:"text-xs font-semibold",children:c("pages.intentions.manual.massTimeLabel")}),e.jsx(pe,{id:"manual-masstime",type:"time",value:m.massTime,onChange:v("massTime"),disabled:y})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-masscity",className:"text-xs font-semibold",children:c("pages.intentions.manual.massCityLabel")}),e.jsx(pe,{id:"manual-masscity",value:m.massCity,onChange:v("massCity"),disabled:y})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"manual-masschurch",className:"text-xs font-semibold",children:c("pages.intentions.manual.massChurchLabel")}),e.jsx(pe,{id:"manual-masschurch",value:m.massChurch,onChange:v("massChurch"),disabled:y})]})]}),e.jsxs("label",{className:"flex items-start gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m.paid,disabled:y,onChange:B=>r(D=>({...D,paid:B.target.checked})),className:"mt-0.5"}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium",children:c("pages.intentions.manual.paidLabel")}),e.jsx("span",{className:"block text-[11px] text-slate-500 dark:text-slate-400",children:c("pages.intentions.manual.paidHint")})]})]}),!m.priestId&&e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 border-l-2 border-slate-200 dark:border-slate-700 pl-2",children:c("pages.intentions.manual.assignHint")})]}),e.jsxs(Dt,{children:[e.jsx(K,{variant:"outline",onClick:()=>n(!1),disabled:y,children:c("common.cancel")}),e.jsxs(K,{onClick:S,disabled:!w,children:[y&&e.jsx(ke,{className:"w-4 h-4 mr-2 animate-spin"}),x&&g>1?c("pages.intentions.manual.submitCopies").replace("{n}",g):c("pages.intentions.manual.submitLabel")]})]})]})})}function El({open:s,onOpenChange:n,intentions:a=[],priests:o=[],onSubmit:i}){const{t:c}=ye(),[t,m]=b.useState(""),[r,y]=b.useState(""),[N,d]=b.useState([]),[v,k]=b.useState(!1);b.useEffect(()=>{s||(m(""),y(""),d([]),k(!1))},[s]);const g=b.useMemo(()=>{const h=new Map;return o.forEach(L=>{const H=sa(a,L.id).length;H>0&&h.set(L.id,H)}),h},[a,o]),x=b.useMemo(()=>o.filter(h=>g.has(h.id)).sort((h,L)=>(L.id===t)-(h.id===t)||String(h.name||"").localeCompare(String(L.name||""),"pl")),[o,g,t]),l=b.useMemo(()=>t?sa(a,t):[],[a,t]),p=b.useMemo(()=>o.filter(h=>h.id!==t&&h.active!==!1&&!h.is_mock).sort((h,L)=>String(h.name||"").localeCompare(String(L.name||""),"pl")),[o,t]),T=
16Math.min(Math.max(0,Math.floor(Number(r)||0)),l.length),R=N.filter(h=>p.some(L=>L.id===h)),A=l.slice(0,T),P=p.filter(h=>R.includes(h.id)&&!h.email),F=!v&&t&&T>0&&R.length>0,O=h=>d(L=>L.includes(h)?L.filter(H=>H!==h):[...L,h]),u=async()=>{if(!(!F||!i)){k(!0);try{const h=await i({fromPriestId:t,count:T,toPriestIds:R});h!=null&&h.ok&&n(!1)}finally{k(!1)}}},M=h=>h?String(h).slice(0,10):"â";return e.jsx(vt,{open:s,onOpenChange:n,children:e.jsxs(Ct,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",children:[e.jsxs(_t,{children:[e.jsxs(St,{className:"flex items-center gap-2 text-slate-900",children:[e.jsx(Ms,{className:"h-5 w-5 text-indigo-600"}),c("pages.intentions.redistribute.title")]}),e.jsx(Pt,{className:"text-slate-600",children:c("pages.intentions.redistribute.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-[1fr_auto]",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{className:"text-xs uppercase tracking-wide text-slate-500",children:c("pages.intentions.redistribute.fromLabel")}),e.jsxs(Ee,{value:t,onValueChange:h=>{m(h),y("")},children:[e.jsx(Re,{className:"text-slate-900",children:e.jsx(Be,{placeholder:c("pages.intentions.redistribute.fromPlaceholder")})}),e.jsx(Oe,{children:x.map(h=>e.jsxs(je,{value:h.id,children:[h.name," · ",g.get(h.id)]},h.id))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{className:"text-xs uppercase tracking-wide text-slate-500",children:c("pages.intentions.redistribute.countLabel")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{type:"number",min:"1",max:l.length||1,value:r,disabled:!t,onChange:h=>y(h.target.value),className:"w-24"}),e.jsx(K,{type:"button",variant:"outline",size:"sm",disabled:!t||l.length===0,onClick:()=>y(String(l.length)),children:c("pages.intentions.redistribute.allButton")})]})]})]}),t&&e.jsx("p",{className:$("text-sm",l.length>0?"text-slate-600":"text-amber-700"),children:l.length>0?c("pages.intentions.redistribute.movable").replace("{n}",l.length):c("pages.intentions.redistribute.movableNone")}),e.jsxs("p",{className:"flex items-start gap-2 rounded-md bg-slate-50 p-3 text-xs text-slate-600",children:[e.jsx(Ot,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0","aria-hidden":"true"}),c("pages.intentions.redistribute.lockedHint")]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx(J,{className:"text-xs uppercase tracking-wide text-slate-500",children:c("pages.intentions.redistribute.toLabel")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-slate-500",children:c("pages.intentions.redistribute.selectedCount").replace("{n}",R.length)}),e.jsx(K,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs text-slate-700 hover:text-slate-900",onClick:()=>d(p.filter(h=>h.distribution_authorized&&h.email).map(h=>h.id)),children:c("pages.intentions.redistribute.selectAuthorized")}),e.jsx(K,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs text-slate-700 hover:text-slate-900",onClick:()=>d([]),children:c("pages.intentions.redistribute.clearSelection")})]})]}),e.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto rounded-md border border-slate-200 p-2",children:p.map(h=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-sm hover:bg-slate-50",children:[e.jsx(Ps,{checked:R.includes(h.id),onCheckedChange:()=>O(h.id)}),e.jsx("span",{className:"flex-1 truncate text-slate-800",children:h.name}),!h.email&&e.jsx("span",{className:"text-[11px] text-amber-600",children:c("pages.intentions.redistribute.noEmail")})]},h.id))}),R.length>1&&e.jsx("p",{className:"text-xs text-slate-500",children:c("pages.intentions.redistribute.splitInfo")}),P.length>0&&e.jsxs("p",{className:"flex items-start gap-2 text-xs text-amber-700",children:[e.jsx(tt,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0","aria-hidden":"true"}),c("pages.intentions.redistribute.noEmailWarning")]})]}),A.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-xs uppercase tracking-wide text-slate-500",children:c("pages.intentions.redistribute.previewTitle")}),e.jsx("ul",{className:"max-h-40 overflow-y-auto rounded-md border border-slate-200 text-sm",children:A.slice(0,12).map(h=>e.jsxs("li",{className:"flex items-center gap-3 border-b border-slate-100 px-3 py-1.5 last:border-0",children:[e.jsx("span",{className:"w-24 flex-shrink-0 tabular-nums text-slate-500",children:M(h.mass_date)}),e.jsx("span",{className:"truncate text-slate-800",children:h.name||"â"})]}
16,h.id))}),A.length>12&&e.jsx("p",{className:"text-xs text-slate-500",children:c("pages.intentions.redistribute.previewMore").replace("{n}",A.length-12)})]})]}),e.jsxs(Dt,{children:[e.jsx(K,{type:"button",variant:"outline",onClick:()=>n(!1),children:c("pages.intentions.redistribute.cancel")}),e.jsx(K,{type:"button",onClick:u,disabled:!F,children:v?e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"mr-2 h-4 w-4 animate-spin"}),c("pages.intentions.redistribute.submitting")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ms,{className:"mr-2 h-4 w-4"}),c("pages.intentions.redistribute.submit")]})})]})]})})}function Rl({loading:s,assigning:n,hasPriests:a,onAutoAssign:o,onRedistribute:i,onAddMock:c,onRefresh:t,onExport:m,onOpenAnalysisReport:r}){const{t:y}=ye();return e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsxs(K,{variant:"secondary",size:"sm",onClick:N=>{N.stopPropagation(),o()},disabled:s||n||!a,className:"bg-indigo-50 text-indigo-700 hover:bg-indigo-100 border border-indigo-200",children:[n?e.jsx(Js,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(ss,{className:"w-4 h-4 mr-2"}),y("pages.intentions.autoAssign")]}),i&&e.jsxs(K,{variant:"outline",size:"sm",onClick:i,disabled:s||!a,className:"border-amber-200 bg-amber-50 text-amber-700 hover:bg-amber-100 hover:text-amber-800",children:[e.jsx(Ms,{className:"w-4 h-4 mr-2"}),y("pages.intentions.toolbar.redistribute")]}),e.jsxs(K,{variant:"outline",size:"sm",onClick:t,disabled:s,children:[e.jsx(Js,{className:$("w-4 h-4 mr-2",s&&"animate-spin")})," ",y("pages.intentions.refresh")]}),r&&e.jsxs(K,{size:"sm",onClick:r,variant:"outline",className:"bg-indigo-50 text-indigo-700 hover:bg-indigo-100 border-indigo-200 hover:text-indigo-800",children:[e.jsx(Ds,{className:"w-4 h-4 mr-2"}),y("pages.intentions.toolbar.analysisReport")]}),c&&e.jsxs(K,{variant:"outline",size:"sm",onClick:c,disabled:s,title:y("pages.intentions.toolbar.mockIntentionTooltip"),className:"border-slate-200 text-slate-600 hover:bg-slate-100 hover:text-slate-800 dark:!text-slate-300 dark:hover:!text-slate-900",children:[e.jsx(Fi,{className:"w-4 h-4 mr-2"}),y("pages.intentions.toolbar.mockIntention")]}),e.jsxs(K,{size:"sm",onClick:m,className:"bg-green-600 hover:bg-green-700 text-white",children:[e.jsx(Ii,{className:"w-4 h-4 mr-2"})," ",y("pages.intentions.exportXls")]})]})}const Bl=[{value:"all",labelKey:"pages.intentions.filters.allPriests"},{value:"assigned",labelKey:"pages.intentions.filters.onlyAssigned"},{value:"unassigned",labelKey:"pages.intentions.filters.onlyUnassigned"}],Ol={pending:"common.pending",assigned:"pages.intentions.status.assigned",awaiting_priest:"pages.intentions.status.awaitingPriest",succeeded:"pages.intentions.status.succeeded",paid:"pages.intentions.status.succeeded",zrealizowane:"pages.intentions.status.succeeded",cancelled:"pages.intentions.status.cancelled",canceled:"pages.intentions.status.cancelled",anulowane:"pages.intentions.status.cancelled",failed:"common.failed"},$l={pending:"bg-slate-400",assigned:"bg-blue-500",awaiting_priest:"bg-orange-500",succeeded:"bg-emerald-500",paid:"bg-emerald-500",zrealizowane:"bg-emerald-500",cancelled:"bg-red-500",canceled:"bg-red-500",anulowane:"bg-red-500",failed:"bg-red-500"},Hl=(s,n)=>{const a=Ol[(s||"").toLowerCase()];return a?n(a):s},Yl=s=>$l[(s||"").toLowerCase()]||"bg-slate-300",Wl=b.forwardRef(function({filters:n,setFilters:a,availableStatuses:o,availableTypes:i,availableYears:c=[],priests:t,activeFiltersCount:m,onClear:r,onSmartAssign:y,smartAssigning:N=!1,unassignedCount:d=0,highlight:v=!1,autoCollapseKey:k,actions:g=null},x){const{t:l}=ye(),[p,T]=b.useState(!1),R=b.useRef(null),A=b.useRef(!1),P=b.useRef(!0);b.useEffect(()=>{if(P.current){P.current=!1;return}T(!0),A.current=!1},[k]);const F=u=>{R.current=u,typeof x=="function"?x(u):x&&(x.current=u)};b.useEffect(()=>{const u=()=>{if(A.current)return;const M=R.current;if(!M)return;M.getBoundingClientRect().top<=12?T(!0):window.scrollY<80&&T(!1)};return u(),window.addEventListener("scroll",u,{passive:!0}),()=>window.removeEventListener("scroll",u)},[]);const O=()=>{A.current=!0,T(u=>!u)};return e.jsx("div",{ref:F,className:$("sticky top-0 z-30 -mx-1 px-1 pt-1 transition-all duration-500",v&&"rounded-lg ring-4 ring-blue-400 ring-offset-2 shadow-lg shadow-blue-200"),children:e.jsxs(lt,{className:`border-blue-200 bg-blue-50/95 backdrop-blur-sm shadow-sm ${p?"":"shadow-md"}`,children:[e.jsx(pt,{className:"pb-3",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:flex-nowrap",children:[e.jsxs("div",{className:"relative w-full min-w-0 sm:w-1/2",children:[e.jsx(Os,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx(pe,{className:"pl-9 bg-white dark:bg-slate-900",placeholder:l("pages.intentions.filters.quickSearchPlaceholder"),title:l("pages.intentions.searchPlaceholder"),value:n.search,onChange:u=>a(M=>({...M,search:u.target.value}))})]}),e.jsxs("div",{className:"flex w-full min-w-0 flex-1 flex-wrap items-center justify-end gap-2",children:[e.jsxs("button",{type:"button",onClick:O,className:"flex items-center gap-2 group shrink-0","aria-expanded":!p,"aria-label":l(p?"pages.intentions.filters.expandFilters":"pages.intentions.filters.collapseFilters"),children:[e.jsx(Ri,{className:"w-4 h-4 text-blue-600"}),e.jsx("h3",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200 group-hover:text-slate-900 dark:text-slate-100 whitespace-nowrap",children:l("pages.intentions.filtersTitle")}),m>0&&e.jsx(Qe,{variant:"secondary",className:"bg-blue-100 text-blue-700",children:l("pages.intentions.filters.activeCount").replace("{count}",m)}),p?e.jsx(Mt,{className:"w-4 h-4 text-slate-500 dark:text-slate-400 group-hover:text-slate-700 dark:text-slate-200","aria-hidden":!0}):e.jsx(as,{className:"w-4 h-4 text-slate-500 dark:text-slate-400 group-hover:text-slate-700 dark:text-slate-200","aria-hidden":!0}),e.jsx("span",{className:"hidden text-[11px] font-medium text-slate-500 dark:text-slate-400 group-hover:text-slate-700 dark:text-slate-200 lg:inline",children:l(p?"pages.intentions.filtersExpand":"pages.intentions.filtersCollapse")})]}),m>0&&e.jsxs(K,{variant:"ghost",size:"sm",onClick:r,className:"text-slate-600 dar
16k:text-slate-300 hover:text-slate-900 dark:text-slate-100",children:[e.jsx(Ca,{className:"w-3.5 h-3.5 mr-1.5"}),l("pages.intentions.filtersClear")]}),g]})]})}),!p&&e.jsx(ot,{className:"pt-0 space-y-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.statusLabel")}),e.jsxs(Ee,{value:n.status,onValueChange:u=>a(M=>({...M,status:u})),children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900",children:e.jsx(Be,{placeholder:l("common.status")})}),e.jsxs(Oe,{children:[e.jsx(je,{value:"all",children:l("pages.intentions.filters.allStatuses")}),o.map(u=>e.jsx(je,{value:u,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:$("w-2 h-2 rounded-full",Yl(u))}),Hl(u,l)]})},u))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.typeLabel")}),e.jsxs(Ee,{value:n.type,onValueChange:u=>a(M=>({...M,type:u})),children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900",children:e.jsx(Be,{placeholder:l("common.type")})}),e.jsxs(Oe,{children:[e.jsx(je,{value:"all",children:l("pages.intentions.filters.allTypes")}),i.map(u=>e.jsx(je,{value:u,children:$e(u)},u))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.priestLabel")}),e.jsx(pn,{value:n.priestId,onChange:u=>a(M=>({...M,priestId:u})),priests:t,specialOptions:Bl.map(u=>({value:u.value,label:l(u.labelKey)})),labels:{none:l("pages.intentions.filters.priestPlaceholder"),searchPlaceholder:l("pages.intentions.manual.priestSearchPlaceholder"),empty:l("pages.intentions.manual.priestEmpty"),inactiveBadge:l("pages.intentions.manual.priestInactiveBadge"),outOfDistribution:l("pages.intentions.manual.priestOutOfDistribution"),noEmail:l("pages.intentions.manual.priestNoEmailBadge"),loadThisYear:l("pages.intentions.manual.priestLoadThisYear")}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.emailLabel")}),e.jsxs("div",{className:"relative",children:[e.jsx($t,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx(pe,{className:"pl-9 bg-white dark:bg-slate-900",placeholder:l("pages.intentions.filters.emailPlaceholder"),value:n.email||"",onChange:u=>a(M=>({...M,email:u.target.value}))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.locationLabel")}),e.jsxs("div",{className:"relative",children:[e.jsx($s,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx(pe,{className:"pl-9 bg-white dark:bg-slate-900",placeholder:l("pages.intentions.filters.locationPlaceholder"),value:n.location||"",onChange:u=>a(M=>({...M,location:u.target.value}))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.dateRangeLabel")}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ia,{value:n.dateFrom,onChange:u=>a(M=>({...M,dateFrom:u})),placeholder:l("pages.intentions.filters.dateFromPlaceholder"),ariaLabel:l("pages.intentions.filters.dateFromAria")}),e.jsx(ia,{value:n.dateTo,onChange:u=>a(M=>({...M,dateTo:u})),placeholder:l("pages.intentions.filters.dateToPlaceholder"),ariaLabel:l("pages.intentions.filters.dateToAria")})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.yearLabel")}),e.jsxs(Ee,{value:n.year||"all",onValueChange:u=>a(M=>({...M,year:u})),children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900",children:e.jsx(Be,{placeholder:l("pages.intentions.filters.yearPlaceholder")})}),e.jsxs(Oe,{children:[e.jsx(je,{value:"all",children:l("pages.intentions.filters.allYears")}),c.map(u=>e.jsx(je,{value:String(u),children:u},u))]})]})]}),y&&e.jsxs("div",{className:"md:col-span-2 space-y-1.5",children:[e.jsxs("label",{className:"text-xs font-medium text-slate-600 dar
16k:text-slate-300 flex items-center gap-1.5",children:[e.jsx(oa,{className:"w-3 h-3 text-indigo-600"}),l("pages.intentions.filters.smartAssignLabel")]}),e.jsxs(K,{type:"button",onClick:y,disabled:N||d===0,className:"w-full justify-start bg-indigo-600 hover:bg-indigo-700 text-white shadow-sm",title:l("pages.intentions.filters.smartAssignTooltip"),children:[N?e.jsx(ke,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(oa,{className:"w-4 h-4 mr-2"}),e.jsx("span",{className:"flex-1 text-left",children:l(N?"pages.intentions.filters.assigning":"pages.intentions.filters.smartAssignButton")}),!N&&d>0&&e.jsx("span",{className:"text-[10px] bg-indigo-800/40 px-1.5 py-0.5 rounded ml-2 tabular-nums",children:l("pages.intentions.filters.pendingCount").replace("{count}",d)})]})]}),e.jsxs("div",{className:"md:col-span-3 space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:l("pages.intentions.filters.amountRangeLabel")}),e.jsxs("span",{className:"text-xs text-slate-500 dark:text-slate-400 font-mono",children:[n.amountMin," PLN â ",n.amountMax>=1e3?"1000+":n.amountMax," PLN"]})]}),e.jsx(Ei,{min:0,max:1e3,step:10,value:[n.amountMin,n.amountMax],onValueChange:([u,M])=>a(h=>({...h,amountMin:u,amountMax:M})),className:"w-full"})]})]})})]})})}),Ul=Wl,vs=10,xa=[{bar:"bg-indigo-500",light:"bg-indigo-50",text:"text-indigo-700",ring:"ring-indigo-200"},{bar:"bg-purple-500",light:"bg-purple-50",text:"text-purple-700",ring:"ring-purple-200"},{bar:"bg-emerald-500",light:"bg-emerald-50",text:"text-emerald-700",ring:"ring-emerald-200"},{bar:"bg-amber-500",light:"bg-amber-50",text:"text-amber-700",ring:"ring-amber-200"},{bar:"bg-sky-500",light:"bg-sky-50",text:"text-sky-700",ring:"ring-sky-200"},{bar:"bg-rose-500",light:"bg-rose-50",text:"text-rose-700",ring:"ring-rose-200"},{bar:"bg-cyan-500",light:"bg-cyan-50",text:"text-cyan-700",ring:"ring-cyan-200"},{bar:"bg-lime-500",light:"bg-lime-50",text:"text-lime-700",ring:"ring-lime-200"},{bar:"bg-fuchsia-500",light:"bg-fuchsia-50",text:"text-fuchsia-700",ring:"ring-fuchsia-200"},{bar:"bg-orange-500",light:"bg-orange-50",text:"text-orange-700",ring:"ring-orange-200"}];function Vl({intentions:s}){const{t:n,lang:a}=ye(),o=b.useMemo(()=>{const d=s.length,v={};return s.forEach(g=>{const x=g.type||"unknown";v[x]||(v[x]={type:x,count:0,paidCount:0,sum:0}),v[x].count+=1,Ht(g)&&(v[x].paidCount+=1,v[x].sum+=Number(g.amount)||0)}),Object.values(v).sort((g,x)=>x.count-g.count).map((g,x)=>({...g,label:$e(g.type,a),pct:d>0?g.count/d*100:0,avgAmount:g.paidCount>0?g.sum/g.paidCount:0,color:xa[x%xa.length]}))},[s,a]),i=o.reduce((d,v)=>d+v.count,0),c=o.reduce((d,v)=>d+v.sum,0),[t,m]=b.useState(!1),r=o.length>vs,y=t||!r?o:o.slice(0,vs),N=o.length-vs;return e.jsxs(lt,{className:"shadow-sm",children:[e.jsx(pt,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ws,{className:"w-4 h-4 text-indigo-600"}),e.jsx(Tt,{className:"text-sm font-semibold",children:n("pages.intentions.analytics.typeDistributionTitle")})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-slate-600 dark:text-slate-300",children:[e.jsx("span",{children:et(n("pages.intentions.analytics.intentionsCount"),{n:i.toLocaleString("pl-PL")})}),e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx("span",{children:et(n("pages.intentions.analytics.totalPaidAmount"),{amount:we(c)})}),r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-slate-300",children:"·"}),e.jsx(K,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-indigo-600 hover:text-indigo-800 hover:bg-indigo-50",onClick:()=>m(d=>!d),"aria-expanded":t,children:t?e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-3 h-3 mr-0.5"})," ",n("pages.intentions.filtersCollapse")]}):e.jsxs(e.Fragment,{children:[e.jsx(Mt,{className:"w-3 h-3 mr-0.5"})," ",n("pages.intentions.analytics.expandMore").replace("{n}",N)]})})]})]})]})}),e.jsx(ot,{className:"pt-0",children:o.length===0?e.jsx("div",{className:"h-32 flex items-center justify-center text-sm text-slate-400",children:n("common.noData")}):e.jsx(Ua,{children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2.5",children:y.map(d=>e.jsxs(Va,{children:[e.jsx(qa,{asChild:!0,children:e.jsxs("div",{className:$("group rounded-md p-2.5 cursor-default ring-1 transition-all hover:shadow-sm",d.
16color.light,d.color.ring),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:$("w-2.5 h-2.5 rounded-full shrink-0",d.color.bar)}),e.jsx("span",{className:$("text-sm font-semibold truncate",d.color.text),children:d.label})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0 text-xs",children:[e.jsxs("span",{className:"text-slate-600 dark:text-slate-300 tabular-nums",children:[e.jsx("strong",{className:"text-slate-900 dark:text-slate-100",children:d.count.toLocaleString("pl-PL")}),e.jsxs("span",{className:"text-slate-400",children:[" ",n("pages.intentions.financial.intentionPlural")]})]}),e.jsxs("span",{className:$("font-bold tabular-nums w-12 text-right",d.color.text),children:[d.pct.toFixed(1),"%"]})]})]}),e.jsx("div",{className:"h-2 bg-white dark:bg-slate-900/60 rounded-full overflow-hidden ring-1 ring-white/50",children:e.jsx("div",{className:$("h-full transition-all duration-300",d.color.bar),style:{width:`${Math.max(d.pct,1.5)}%`}})}),e.jsxs("div",{className:"flex items-center justify-between mt-1.5 text-[10px] text-slate-500 dark:text-slate-400",children:[e.jsxs("span",{children:[n("pages.intentions.analytics.totalPaidShort"),": ",e.jsx("strong",{className:"tabular-nums text-slate-700 dark:text-slate-200",children:we(d.sum)})]}),e.jsxs("span",{className:"flex items-center gap-1",children:[n("pages.intentions.analytics.avgShort"),e.jsx(Gn,{className:"w-2.5 h-2.5"}),e.jsx("strong",{className:"tabular-nums text-slate-700 dark:text-slate-200",children:we(d.avgAmount)})]})]})]})}),e.jsx(Ga,{side:"left",className:"text-xs",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-semibold",children:d.label}),e.jsx("p",{children:n("pages.intentions.analytics.tooltipCount").replace("{n}",d.count.toLocaleString("pl-PL")).replace("{pct}",d.pct.toFixed(2))}),e.jsx("p",{children:n("pages.intentions.analytics.tooltipPaidCount").replace("{n}",d.paidCount.toLocaleString("pl-PL"))}),e.jsxs("p",{children:[n("pages.intentions.analytics.tooltipSum"),": ",we(d.sum)]}),e.jsxs("p",{children:[n("pages.intentions.financial.avgLabel"),": ",we(d.avgAmount)]})]})})]},d.type))})})})]})}const ha=["#6366f1","#8b5cf6","#ec4899","#f59e0b","#10b981","#06b6d4","#3b82f6","#ef4444","#84cc16","#f97316"];function fa(s){if(!s)return null;let n=String(s).trim();return n=n.replace(/\s*[â\-]\s*\([^)]*\).*$/,""),n=n.replace(/\s*[â\-]\s*(Cyprus|Keserwan|Paphos).*$/i,""),n=n.replace(/\*/g,"").trim(),{"Deir el-Qamar":"Deir el Qamar",Qleiaat:"Kleiat","El Mansouria":"Mansourieh",Rome:"Roma","Collegio Maronita a Roma":"Roma"}[n]||n}const ql={Larnaca:"Cypr",Polemidia:"Cypr",Limassol:"Cypr",Nicosia:"Cypr",Chloraka:"Cypr",Paphos:"Cypr",Roma:"WÅochy"};function Gl(s){return s?ql[s]||"Liban":null}const ba={Liban:"bg-rose-500",Cypr:"bg-sky-500",WÅochy:"bg-emerald-500",Polska:"bg-indigo-500"},ya={Liban:"pages.intentions.analytics.countryLebanon",Cypr:"pages.intentions.analytics.countryCyprus",WÅochy:"pages.intentions.analytics.countryItaly",Polska:"pages.intentions.analytics.countryPoland"};function Kl({intentions:s=[]}){const{t:n}=ye(),a=t=>ya[t]?n(ya[t]):t,o=b.useMemo(()=>{const t={};return s.forEach(m=>{const r=fa(m.mass_city);r&&(t[r]=(t[r]||0)+1)}),Object.entries(t).map(([m,r])=>({name:m,value:r})).sort((m,r)=>r.value-m.value).slice(0,10)},[s]),i=b.useMemo(()=>{const t={};let m=0;return s.forEach(r=>{const y=fa(r.mass_city),N=Gl(y);
16N&&(t[N]=(t[N]||0)+1,m+=1)}),Object.entries(t).map(([r,y])=>({name:r,count:y,pct:m>0?y/m*100:0})).sort((r,y)=>y.count-r.count)},[s]),c=i.reduce((t,m)=>t+m.count,0);return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[e.jsxs(lt,{className:"shadow-sm",children:[e.jsx(pt,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Tt,{className:"text-sm font-medium",children:n("pages.intentions.analytics.topCitiesTitle")}),e.jsx($s,{className:"w-4 h-4 text-slate-400"})]})}),e.jsxs(ot,{className:"space-y-4",children:[e.jsx("div",{className:"h-[230px]",children:o.length>0?e.jsx(Oi,{width:"100%",height:"100%",children:e.jsxs(Wi,{children:[e.jsx(Ui,{data:o,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",innerRadius:40,outerRadius:80,paddingAngle:2,children:o.map((t,m)=>e.jsx($i,{fill:ha[m%ha.length]},t.name))}),e.jsx(Hi,{}),e.jsx(Yi,{layout:"vertical",verticalAlign:"middle",align:"right",wrapperStyle:{fontSize:"11px"}})]})}):e.jsx("div",{className:"h-full flex items-center justify-center text-sm text-slate-400",children:n("pages.intentions.analytics.noLocationData")})}),i.length>0&&e.jsxs("div",{className:"border-t border-slate-100 dark:border-slate-800 pt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:n("pages.intentions.analytics.byCountry")}),e.jsx("span",{className:"text-[10px] text-slate-400 tabular-nums",children:n("pages.intentions.analytics.intentionsCount").replace("{n}",c.toLocaleString("pl-PL"))})]}),e.jsx("div",{className:"flex h-2.5 rounded-full overflow-hidden ring-1 ring-slate-200 bg-slate-100 dark:bg-slate-800 mb-2",children:i.map(t=>e.jsx("div",{className:$("transition-all",ba[t.name]||"bg-slate-400"),style:{width:`${t.pct}%`},title:`${a(t.name)}: ${t.count} (${t.pct.toFixed(1)}%)`},t.name))}),e.jsx("div",{className:"space-y-1.5",children:i.map(t=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:$("w-2 h-2 rounded-full",ba[t.name]||"bg-slate-400")}),e.jsx("span",{className:"font-medium text-slate-700 dark:text-slate-200",children:a(t.name)})]}),e.jsxs("div",{className:"flex items-center gap-2 text-slate-600 dark:text-slate-300 tabular-nums",children:[e.jsx("span",{children:t.count.toLocaleString("pl-PL")}),e.jsxs("span",{className:"text-slate-400 w-12 text-right",children:[t.pct.toFixed(1),"%"]})]})]},t.name))})]})]})]}),e.jsx(Bi,{items:s,nounKey:"intentions",className:"lg:col-span-2"})]})}const Ls=5,Xl=(s,n)=>String(s).replace(/\{(\w+)\}/g,(a,o)=>n[o]!=null?n[o]:`{${o}}`);function Zl({value:s,onChange:n,currentYear:a}){const{t:o}=ye(),i=b.useMemo(()=>{const c=a||new Date().getFullYear();return`${c-Ls+1}â${c}`},[a]);return e.jsxs("div",{className:"inline-flex rounded-md border border-slate-200 dark:border-slate-800 bg-slate-50 dark:bg-slate-900/40 p-0.5",children:[e.jsxs("button",{type:"button",onClick:()=>n("current"),className:$("px-2.5 py-1 text-xs font-medium rounded transition-colors flex items-center gap-1.5",s==="current"?"bg-indigo-600 text-white shadow-sm":"text-slate-600 dark:text-slate-300 hover:bg-white dark:bg-slate-900"),title:o("temporalChart.currentYearTitle"),children:[e.jsx("span",{className:$("tabular-nums font-bold px-1 rounded",s==="current"?"bg-indigo-800/40 text-white":"bg-indigo-100 text-indigo-700"),children:a}),o("temporalChart.currentYear")]}),e.jsx("button",{type:"button",onClick:()=>n("last5"),className:$("px-2.5 py-1 text-xs font-medium rounded transition-colors",s==="last5"?"bg-indigo-600 text-white shadow-sm":"text-slate-600 dark:text-slate-300 hover:bg-white dark:bg-slate-900"),title:i,children:Xl(o("temporalChart.lastNYears"),{n:Ls})}),e.jsx("button",{type:"button",onClick:()=>n("all"),className:$("px-2.5 py-1 text-xs font-medium rounded transition-colors",s==="all"?"bg-indigo-600 text-white shadow-sm":"text-slate-600 dark:text-slate-300 hover:bg-white dark:bg-slate-900"),children:o("temporalChart.allHistory")})]})}function Ql(s,n,a=new Date){if(!s||s.length===0)return[];if(n==="all")return s;const o=a.getFullYear();if(n==="current")return s.filter(i=>i.created_at?new Date(i.created_at).getFullYear()===o:!1);if(n==="last5"){const i=o-Ls+1;return s.filter(c=>{if(!c.created_at)return!1;const t=new Date(c.created_at).getFullYear();return t>=i&&t<=o})}return s}function nt({icon:s,label:n,value:a,sublabel:o,accent:i="slate",children:c,infoKey:t,t:m}){const r={slate:{bg:"bg-slate-50 dark:bg-slate-900/40",text:"text-slate-700 dark:text-slate-200",ring:"ring-slate-200",iconBg:"bg-slate-100 dar
16k:bg-slate-800",iconText:"text-slate-600 dark:text-slate-300"},indigo:{bg:"bg-indigo-50",text:"text-indigo-900",ring:"ring-indigo-200",iconBg:"bg-indigo-100",iconText:"text-indigo-700"},emerald:{bg:"bg-emerald-50",text:"text-emerald-900",ring:"ring-emerald-200",iconBg:"bg-emerald-100",iconText:"text-emerald-700"},rose:{bg:"bg-rose-50",text:"text-rose-900",ring:"ring-rose-200",iconBg:"bg-rose-100",iconText:"text-rose-700"},amber:{bg:"bg-amber-50",text:"text-amber-900",ring:"ring-amber-200",iconBg:"bg-amber-100",iconText:"text-amber-700"},sky:{bg:"bg-sky-50",text:"text-sky-900",ring:"ring-sky-200",iconBg:"bg-sky-100",iconText:"text-sky-700"}},y=r[i]||r.slate;return e.jsx(lt,{className:$("shadow-sm ring-1",y.ring,y.bg),children:e.jsxs(ot,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400",children:n}),e.jsx("p",{className:$("text-xl font-bold mt-0.5 tabular-nums truncate",y.text),children:a}),o&&e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 mt-0.5",children:o})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t&&m&&e.jsx(Ka,{icon:Ot,iconClass:"w-4 h-4 text-slate-400",title:m(`${t}.title`),description:m(`${t}.description`),calculation:m(`${t}.calculation`),example:m(`${t}.example`)}),e.jsx("div",{className:$("p-2 rounded-md",y.iconBg),children:e.jsx(s,{className:$("w-4 h-4",y.iconText)})})]})]}),c]})})}function Jl({intentions:s=[],yearScope:n,onYearScopeChange:a,currentYear:o,onAddDantis:i,onAddManual:c,collapsed:t,onToggleCollapsed:m}){const{t:r}=ye(),[y,N]=b.useState(!1),[d,v]=b.useState(!1),k=typeof t=="boolean",g=k?t:d,x=()=>{k?m==null||m():v(A=>!A)},l=b.useMemo(()=>{const A=mt(s,{onlyPaid:!y}),F=(y?s:s.filter(O=>["succeeded","paid","assigned","awaiting_priest"].includes((O.status||"").toLowerCase()))).filter(O=>{const u=Number(O.amount)||0;return u>0&&u<=Ge(O)}).length;return{...A,smallDonationCount:F}},[s,y]),p=l.totalDonated>0?Math.round(l.remainder/l.totalDonated*100):0,T=l.totalDonated>0?Math.round(l.totalToPriests/l.totalDonated*100):0,R=l.count>0?Math.round(l.smallDonationCount/l.count*100):0;return e.jsxs(lt,{className:"shadow-sm",children:[e.jsxs(pt,{className:"pb-3 cursor-pointer select-none hover:bg-slate-50 dark:bg-slate-900/40/60 transition-colors rounded-t-lg",onClick:()=>x(),role:"button",tabIndex:0,"aria-expanded":!g,onKeyDown:A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),x())},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap md:flex-nowrap",children:[e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(Vi,{className:"w-4 h-4 text-indigo-600"}),e.jsx(Tt,{className:"text-sm font-semibold whitespace-nowrap",children:r("pages.intentions.financial.title")}),e.jsx("span",{onClick:A=>A.stopPropagation(),children:e.jsx(Ka,{icon:Ot,iconClass:"w-4 h-4 text-slate-400",title:r("pages.intentions.infoCardsBreakdown.header.title"),description:r("pages.intentions.infoCardsBreakdown.header.description"),calculation:r("pages.intentions.infoCardsBreakdown.header.calculation"),example:r("pages.intentions.infoCardsBreakdown.header.example")})}),e.jsxs("span",{className:"text-[11px] text-slate-500 dark:text-slate-400 whitespace-nowrap",children:[l.count.toLocaleString("pl-PL")," ",l.count===1?r("pages.intentions.financial.intentionSingular"):r("pages.intentions.financial.intentionPlural")]})]}),a&&!g&&e.jsx("div",{className:"flex-1 flex justify-center md:justify-start min-w-0 overflow-x-auto",onClick:A=>A.stopPropagation(),children:e.jsx(Zl,{value:n,onChange:a,currentYear:o})}),i&&!g&&e.jsxs(K,{type:"button",size:"sm",onClick:A=>{A.stopPropagation(),i()},className:"bg-teal-600 hover:bg-teal-700 text-white shrink-0 whitespace-nowrap",title:r("pages.intentions.financial.addDantisTooltip"),children:[e.jsx(As,{className:"w-3.5 h-3.5 mr-1.5"}),r("pages.intentions.financial.addDantisButton")]}),c&&!g&&e.jsxs(K,{type:"button",size:"sm",variant:"outline",onClick:A=>{A.stopPropagation(),c()},className:"shrink-0 whitespace-nowrap",title:r("pages.intentions.financial.addManualTooltip"),children:[e.jsx(Wa,{className:"w-3.5 h-3.5 mr-1.5"}),r("pages.intentions.financial.addManualButton")]}),!g&&e.jsxs("label",{className:"flex items-center gap-1.5 text-[11px] text-slate-600 dar
16k:text-slate-300 cursor-pointer whitespace-nowrap shrink-0",onClick:A=>A.stopPropagation(),children:[e.jsx("input",{type:"checkbox",checked:y,onChange:A=>N(A.target.checked),className:"rounded border-slate-300"}),r("pages.intentions.financial.includeUnpaid")]}),e.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),x()},className:"p-1.5 rounded-md hover:bg-slate-100 dark:bg-slate-800 text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:text-slate-200 transition-colors shrink-0","aria-label":r(g?"pages.intentions.financial.expandAnalytics":"pages.intentions.financial.collapseAnalytics"),title:r(g?"pages.intentions.financial.expandAnalytics":"pages.intentions.financial.collapseAnalytics"),children:g?e.jsx(Mt,{className:"w-4 h-4"}):e.jsx(as,{className:"w-4 h-4"})})]}),!g&&e.jsxs("p",{className:"text-[11px] text-slate-500 dark:text-slate-400 leading-relaxed flex items-start gap-1.5 mt-1",children:[e.jsx(Ot,{className:"w-3 h-3 mt-0.5 shrink-0"}),r("pages.intentions.financial.ruleIntro").replace("{fee}",qe),e.jsx("strong",{className:"text-slate-700 dark:text-slate-200",children:r("pages.intentions.financial.ruleMercy")}),",",e.jsx("strong",{className:"text-slate-700 dark:text-slate-200",children:r("pages.intentions.financial.ruleFoundation")}),"."]})]}),!g&&e.jsxs(ot,{className:"pt-0",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(nt,{icon:qi,label:r("pages.intentions.infoCardsBreakdown.totalDonated.title"),value:we(l.totalDonated),sublabel:r("pages.intentions.financial.donationsCount").replace("{count}",l.count.toLocaleString("pl-PL")),accent:"indigo",infoKey:"pages.intentions.infoCardsBreakdown.totalDonated",t:r}),e.jsx(nt,{icon:Xa,label:r("pages.intentions.financial.toPriestsLabel").replace("{fee}",qe),value:we(l.totalToPriests),sublabel:r("pages.intentions.financial.pctOfTotal").replace("{pct}",T),accent:"emerald",infoKey:"pages.intentions.infoCardsBreakdown.toPriests",t:r}),e.jsx(nt,{icon:Kn,label:r("pages.intentions.infoCardsBreakdown.mercyFund.title"),value:we(l.mercyFund),sublabel:r("pages.intentions.financial.ofRemainder").replace("{amount}",we(l.remainder)),accent:"rose",infoKey:"pages.intentions.infoCardsBreakdown.mercyFund",t:r}),e.jsx(nt,{icon:Za,label:r("pages.intentions.infoCardsBreakdown.foundationFund.title"),value:we(l.adminCost),sublabel:r("pages.intentions.financial.pctOfTotal").replace("{pct}",p),accent:"amber",infoKey:"pages.intentions.infoCardsBreakdown.foundationFund",t:r})]}),l.totalDonated>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] uppercase tracking-wide text-slate-500 dark:text-slate-400 font-semibold mb-1",children:[e.jsx("span",{children:r("pages.intentions.financial.distributionTitle")}),e.jsxs("span",{className:"font-mono normal-case text-slate-400",children:[we(l.totalDonated)," = 100%"]})]}),e.jsxs("div",{className:"flex h-3 rounded-full overflow-hidden ring-1 ring-slate-200 bg-slate-100 dark:bg-slate-800",children:[e.jsx("div",{className:"bg-emerald-500 transition-all",style:{width:`${T}%`},title:r("pages.intentions.financial.barPriestsTooltip").replace("{amount}",we(l.totalToPriests)).replace("{pct}",T)}),e.jsx("div",{className:"bg-rose-400 transition-all",style:{width:`${Math.round(l.mercyFund/l.totalDonated*100)}%`},title:r("pages.intentions.financial.barMercyTooltip").replace("{amount}",we(l.mercyFund))}),e.jsx("div",{className:"bg-amber-400 transition-all",style:{width:`${Math.round(l.adminCost/l.totalDonated*100)}%`},title:r("pages.intentions.financial.barFoundationTooltip").replace("{amount}",we(l.adminCost))})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-1.5 text-[10px] text-slate-600 dark:text-slate-300",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-emerald-500"})," ",r("pages.intentions.financial.legendPriests")," ",T,"%"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-rose-400"})," ",r("pages.intentions.financial.legendMercy")," ",Math.round(l.mercyFund/l.totalDonated*100),"%"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-400"})," ",r("pages.intentions.financial.legendFoundation")," ",Math.round(l.adminCost/l.totalDonated*100),"%"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mt-4",children:[e.jsx(nt,{icon:Gi,label:r("pages.intentions.infoCardsBreakdown.maxDonation.title"),value:we(l.max),accent:"sky",infoKey:"pages.intentions.infoCardsBreakdown.maxDonation",t:r}),e.jsx(nt,{icon:Ki,label:r("pages.intentions.infoCardsBreakdown.minDonation.title"),value:we(l.min),accent:"slate",infoKey:"pages.intentions.infoCardsBreakdown.minDonation",t:r}),e.jsx(nt,{icon:Ni,label:r("pages.intentions.financial.avgLabel"),value:we(l.avg),sublabel:r("pages.intentions.financial.medianLabel").replace("{amount}",we(l.median)),accent:"slate",infoKey:"pages.intentions.infoCardsBreakdown.avgDonation",t:r}),e.jsx(nt,{icon:Ot,label:r("pages.intentions.financial.smallDonationsLabel"),value:`${l.smallDonationCount.toLocaleStr
16ing("pl-PL")}`,sublabel:r("pages.intentions.financial.smallPctNote").replace("{pct}",R),accent:"slate",infoKey:"pages.intentions.infoCardsBreakdown.smallDonations",t:r})]})]})]})}const eo={notPaid:"bg-slate-100 text-slate-500 border-slate-200",toAssign:"bg-amber-50 text-amber-800 border-amber-200",toNotify:"bg-rose-50 text-rose-800 border-rose-200",toConfirm:"bg-indigo-50 text-indigo-800 border-indigo-200",toInformDonor:"bg-sky-50 text-sky-800 border-sky-200",done:"bg-emerald-50 text-emerald-800 border-emerald-200"};function to(s,n){return gi(s).map(a=>{const o=n(`pages.intentions.flow.stages.${a.key}`);if(a.notApplicable)return`â ${o}`;if(a.unscheduled)return`â ${o}: ${n("pages.intentions.flow.noMassDate")}`;const i=a.at?` (${be(new Date(a.at),"dd.MM.yyyy")})`:"";return a.done?`â ${o}${i}`:`· ${o}${i}`}).join(` 17`)}function ja({item:s,t:n,className:a}){const o=Da(s);return e.jsx("span",{title:to(s,n),className:$("inline-block rounded-full border px-2 py-0.5 text-[10px] font-medium whitespace-nowrap",eo[o],a),children:n(`pages.intentions.flow.row.${o}`)})}function so({item:s,t:n,onSetStage:a,onNotifyPriest:o,onNotifyDonor:i,onSetStatus:c,onAssignPriest:t,assignablePriests:m=[],saving:r=!1,align:y="center"}){if(!a)return e.jsx(ja,{item:s,t:n});const N=Da(s),d=!!s.priest_id,v=d,k=!!s.priest_confirmed_at&&!!s.email,g=N==="notPaid",x=g||!d;return e.jsxs(Fs,{children:[e.jsx(Is,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:l=>l.stopPropagation(),title:n("pages.intentions.table.changeStage"),"aria-label":n("pages.intentions.table.changeStage"),className:$("group/stage inline-flex items-center gap-1 rounded-full transition","focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-400 focus-visible:ring-offset-1","hover:brightness-95 disabled:opacity-60"),disabled:r,children:[e.jsx(ja,{item:s,t:n}),r?e.jsx(ke,{className:"h-3 w-3 shrink-0 animate-spin text-slate-400"}):e.jsx(Ta,{className:"h-2.5 w-2.5 shrink-0 text-slate-400 opacity-0 transition-opacity group-hover/stage:opacity-100 group-focus-visible/stage:opacity-100","aria-hidden":!0})]})}),e.jsxs(Es,{align:y,className:"w-64",onClick:l=>l.stopPropagation(),children:[x&&e.jsxs(e.Fragment,{children:[e.jsx(yt,{children:n("pages.intentions.table.stageFixGroup")}),e.jsx(Je,{}),g&&c&&e.jsxs(Ne,{onClick:l=>{l.stopPropagation(),c(s,"succeeded")},children:[e.jsx(Zt,{className:"mr-2 h-4 w-4 shrink-0 text-emerald-600","aria-hidden":!0}),n("pages.intentions.table.stageMarkPaid")]}),!d&&t&&m.length>0&&e.jsxs(Wt,{children:[e.jsxs(Ut,{children:[e.jsx(ss,{className:"mr-2 h-4 w-4 shrink-0 text-indigo-600","aria-hidden":!0}),n("pages.intentions.assignPriest")]}),e.jsx(Vt,{children:e.jsx(qt,{className:"max-h-72 overflow-y-auto",children:m.map(l=>e.jsx(Ne,{onClick:p=>{p.stopPropagation(),t(s,l.id)},children:l.name||l.email||l.id},l.id))})})]}),e.jsx(Je,{})]}),e.jsx(yt,{children:n("pages.intentions.table.stageMarkGroup")}),e.jsx(Je,{}),Aa.map(l=>e.jsxs(Ne,{disabled:!d||l===N,onClick:p=>{p.stopPropagation(),!(!d||l===N)&&a(s,l)},className:$(l===N&&"font-medium"),children:[e.jsx(Kt,{className:$("mr-2 h-4 w-4 shrink-0",l===N?"text-emerald-600":"opacity-0"),"aria-hidden":!0}),n(`pages.intentions.flow.row.${l}`)]},l)),(o||i)&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{}),e.jsx(yt,{children:n("pages.intentions.table.stageRunGroup")}),o&&e.jsxs(Ne,{disabled:!v,onClick:l=>{l.stopPropagation(),v&&o(s)},children:[e.jsx(es,{className:"mr-2 h-4 w-4 shrink-0 text-rose-600","aria-hidden":!0}),n("pages.intentions.table.stageNotifyPriest")]}),i&&e.jsxs(Ne,{disabled:!k,onClick:l=>{l.stopPropagation(),k&&i(s)},children:[e.jsx($t,{className:"mr-2 h-4 w-4 shrink-0 text-emerald-600","aria-hidden":!0}),n("pages.intentions.table.stageNotifyDonor")]})]})]})]})}const Cs=50,Rt=500;function ao(s,n){if(!s)return{truncated:"",isLong:!1};let a=0,o=s.length;for(let i=0;i<s.length;i+=1)if(s[i]!==" "&&(a+=1,a>n)){o=i;break}return o>=s.length?{truncated:s,isLong:!1}:{truncated:`${s.slice(0,o).trimEnd()}...`,isLong:!0}}function Bt(s,n){return n.key!==s?e.jsx(Ya,{className:"w-3 h-3 ml-1 text-slate-400"}):n.direction==="asc"?e.jsx(as,{className:"w-3 h-3 ml-1 text-blue-600"}):e.jsx(Mt,{className:"w-3 h-3 ml-1 text-blue-600"})}function no({items:s,totalResults:n,priests:a,loading:o,sortConfig:i,onSort:c,selectedIds:t,onSelectAll:m,onSelectRow:r,expandedRows:y,onToggleRow:N,onRowClick:d,onDuplicate:v,activeFiltersCount:k,onClearFilters:g,onTogglePriestPaid:x,onSetStatus:l,onSetStage:p,onNotifyPriest:T,onNotifyDonor:R,onAssignPriest:A,assignablePriests:P,savingStageId:F,savingStatusId:O=null}){const{t:u,lang:M}=ye(),[h,L]=b.useState(Rt),[H,w]=b.useState(Cs),S=b.useRef(null);b.useEffect(()=>{w(Cs),L(Rt)},[s.length,i.key,i.direction]),b.useEffect(()=>{if(o||H>=s.length||H>=h)return;const f=S.current;if(!f)return;const W=new IntersectionObserver(te=>
17{te[0].isIntersecting&&w(ie=>Math.min(ie+Cs,h,s.length))},{rootMargin:"200px"});return W.observe(f),()=>W.disconnect()},[H,h,s.length,o]);const B=b.useMemo(()=>s.slice(0,H),[s,H]),D=H>=h&&s.length>h,q=H<s.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-center justify-between bg-white dark:bg-slate-900 p-4 rounded-lg border border-slate-200 dark:border-slate-800",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm text-slate-600 dark:text-slate-300",children:et(u("pages.intentions.table.showingResults"),{shown:B.length,total:n})}),k>0&&e.jsx(Qe,{variant:"secondary",className:"text-xs",children:u(k===1?"pages.intentions.table.filterCountOne":"pages.intentions.table.filterCountMany").replace("{n}",k)})]}),t.size>0&&e.jsx("span",{className:"text-sm font-medium text-indigo-700 dark:text-indigo-300",children:u("pages.intentions.table.selectedCount").replace("{n}",t.size)})]}),e.jsx("div",{className:"bg-white dark:bg-slate-900 rounded-lg border border-slate-200 dark:border-slate-800 shadow-sm overflow-x-auto",children:e.jsxs(Xi,{className:"w-full table-fixed min-w-[880px]",children:[e.jsx(Zi,{className:"bg-slate-50 dark:bg-slate-900/40",children:e.jsxs(Yt,{children:[e.jsx(We,{className:"w-[36px] px-1 text-center",children:e.jsx(Ps,{checked:n>0&&t.size===n,onCheckedChange:m})}),e.jsx(We,{className:"w-[86px] px-2 cursor-pointer hover:bg-slate-100 dark:bg-slate-800",onClick:()=>c("created_at"),children:e.jsxs("div",{className:"flex items-center whitespace-nowrap",children:[u("common.date")," ",Bt("created_at",i)]})}),e.jsx(We,{className:"w-[17%] px-2 cursor-pointer hover:bg-slate-100 dark:bg-slate-800",onClick:()=>c("name"),children:e.jsxs("div",{className:"flex items-center min-w-0",children:[e.jsx("span",{className:"truncate",children:u("pages.intentions.table.colOrderer")})," ",Bt("name",i)]})}),e.jsx(We,{className:"w-[12%] px-2 cursor-pointer hover:bg-slate-100 dark:bg-slate-800",onClick:()=>c("type"),children:e.jsxs("div",{className:"flex items-center min-w-0",children:[e.jsx("span",{className:"truncate",children:u("common.type")})," ",Bt("type",i)]})}),e.jsx(We,{className:"w-[23%] px-2",children:u("pages.intentions.export.colContent")}),e.jsx(We,{className:"w-[10%] px-2 text-right cursor-pointer hover:bg-slate-100 dark:bg-slate-800",onClick:()=>c("amount"),children:e.jsxs("div",{className:"flex items-center justify-end min-w-0",children:[e.jsx("span",{className:"truncate",children:u("common.amount")})," ",Bt("amount",i)]})}),e.jsxs(We,{className:"w-[34px] px-1 text-center",title:u("pages.intentions.table.payoutColTitle"),children:[e.jsx("span",{className:"sr-only",children:u("pages.intentions.table.payoutColSr")}),e.jsx("span",{"aria-hidden":!0,className:"text-[10px] text-slate-400",children:u("pages.intentions.table.payoutColAbbr")})]}),e.jsx(We,{className:"w-[12%] px-2 text-center cursor-pointer hover:bg-slate-100 dark:bg-slate-800",onClick:()=>c("status"),children:e.jsxs("div",{className:"flex items-center justify-center min-w-0",children:[e.jsx("span",{className:"truncate",children:u("common.status")})," ",Bt("status",i)]})}),e.jsx(We,{className:"w-[13%] px-2 text-center",title:u("pages.intentions.flow.colStateHint"),children:u("pages.intentions.flow.colState")}),e.jsx(We,{className:"w-[34px] px-1","aria-label":u("pages.intentions.table.duplicateTitle")})]})}),e.jsx(Qi,{children:o?e.jsx(Yt,{children:e.jsx(Ie,{colSpan:10,className:"h-24 text-center",children:u("common.loading")})}):B.length===0?e.jsx(Yt,{children:e.jsx(Ie,{colSpan:10,className:"h-48 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Os,{className:"w-12 h-12 text-slate-300"}),e.jsx("p",{className:"text-slate-500 dark:text-slate-400 font-medium",children:u("common.noResults")}),e.jsx("p",{className:"text-sm text-slate-400",children:u("pages.intentions.table.emptyHint")}),k>0&&e.jsx(K,{variant:"outline",size:"sm",onClick:g,className:"mt-2",children:u("pages.intentions.table.clearFilters")})]})})}):B.map(f=>{const W=en(f.content),{truncated:te}=ao(W,60),ie=t.has(f.id);return e.jsxs(Yt,{className:$("group transition-colors text-sm cursor-pointer",ie?"bg-indigo-50/50 hover:bg-indigo-50":"hover:bg-slate-50 dark:bg-slate-900/40"),onClick:()=>d(f),children:[e.jsx(Ie,{className:"px-1 text-center align-top pt-3",children:e.jsx("div",{onClick:ae=>ae.stopPropagation(),children:e.jsx(Ps,{checked:ie,onCheckedChange:ae=>r(f.id,ae)})})}),e.jsx(Ie,{className:"text-slate-500 dark:text-slate-400 font-mono text-[11px] whitespace-nowrap align-top pt-3 px-2",children:be(new Date(f.created_at),"dd.MM.yyyy")}),e.jsxs(Ie,{className:"align-top pt-3 px-2 min-w-0",children:[e.jsx("div",{className:"font-medium text-slate-900 dark:text-slate-100 leading-tight truncate",title:f.name,children:f.name}),e.jsx("div",{className:"text-[11px] text-slate-500 dark:text-slate-400 truncate",title:f.email,children:f.email}),f.priest_id&&(()=>{var De;const ae=((De=a.find(ve=>ve.id===f.priest_id))==null?void 0:De.name)||u("pages.intentions.table.priestFallback");return e.jsxs("div",{className:"flex items-center gap-1 mt-1 text-[10px] text-blue-600 bg-blue-50 px-1.5 py-0.5 rounded w-fit max-w-full",title:ae,children:[e.jsx(Bs,{className:"w-3 h-3 shrink-0"}),e.jsx("span",{className:"truncate",children:ae})]})})()]}),e.jsx(Ie,{className:"align-top pt-3 px-2",children:dl(f.type,f.is_mock,u,M)}),e.jsx(Ie,{className:"align-top pt-3 px-2",children:e.jsx(Ua,{children:e.jsxs(Va,{children:[e.jsx(qa,{asChild:!0,children:e.jsx("div",{className:"text-[13px] text-slate-700 dark:text-slate-200 leading-snug line-clamp-2 break-words",children:te})}),W&&e.jsx(Ga,{className:"max-w-md",children:e.jsx("p",{className:"text-sm",children:W})})]})})}),e.jsxs(Ie,{className:"align-top pt-3 px-2 text-right font-medium text-slate-900 dark:text-slate-100",children:[e.jsxs("div",{className:"text-[13px] whitespace-nowrap",children:[f.amount," ",f.currency]}),Number(f.mass_count)>1&&e.jsx("div",{className:"text-[10px] font-normal text-slate-500 dark:text-slate-400 whitespace-nowrap",children:u("pages.intentions.table.massCountBadge").replace("{n}",f.mass_count)}),e.jsx(io,{item:f,t:u})]}),e.jsx(Ie,{className:"align-top pt-3 px-1 text-center",children:f.priest_id?e.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),x==null||x(f)},className:$("inline-flex items-center justify-center w-5 h-5 rounded-full transition-transform hover:scale-110 focus:outline-none focus:ring-2 focus:ring-offset-1",f.priest_paid_at?"bg-emerald-500 ring-emerald-300 hover:bg-emerald-600":"bg-rose-500 ring-rose-300 hover:bg-rose-600"),title:f.priest_paid_at?u("pages.intentions.table.paidTitle").replace("{date}",be(new Date(f.priest_paid_at),"dd.MM.yyyy")):u("pages.intentions.table.overdueTitle"),"aria-label":f.priest_paid_at?u("pages.intentions.payoutsBadgePaid"):u("pages.intentions.table.overdueAria"),children:f.priest_paid_at?e.jsx(Ja,{className:"w-3 h-3 text-white"}):e.jsx(Zt,{className:"w-3 h-3 text-white"})}):e.jsx("span",{className:"inline-block w-5 h-5 rounded-full bg-slate-200",title:u("pages.intentions.table.noPriestTitle"),"aria-label":u("pages.intentions.table.noPriestAria")})}),e.jsx(Ie,{className:"align-top pt-3 px-2 text-center",children:e.jsx(tn,{status:f.status,t:u,saving:O===f.id,onChange:l?ae=>l(f,ae):void 0})}),e.jsx(Ie,{className:"align-top pt-3 px-2 text-center",children:e.jsx(so,{item:f,t:u,saving:F===f.id,onSetStage:p,onNotifyPriest:T,onNotifyDonor:R,onSetStatus:l,onAssignPriest:A,assignablePriests:P})}),e.jsx(Ie,{className:"align-top pt-3 px-1 text-center",children:v&&e.jsx("button",{type:"button",onClick:ae=>{ae.stopPropagation(),v(f)},title:u("pages.intentions.table.duplicateTitle"),"aria-label":u("pages.intentions.table.duplicateTitle"),className:"inline-flex h-6 w-6 items-center justify-center rounded text-slate-400 opacity-60 transition hover:bg-slate-100 hover:text-slate-700 focus:opacity-100 focus:outline-none focus:ring-2 focus:ring-indigo-400 group-hover:opacity-100 group-hover:text-slate-600",children:e.jsx(Rs,{className:"h-3.5 w-3.5"})})})]},f.id)})})]})}),q&&e.jsx("div",{className:"flex flex-col items-center justify-center py-6 gap-3",children:D?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:et(u("pages.intentions.table.capNotice").replace("{cap}",Rt),{shown:B.length,total:s.length})}),e.jsxs(K,{variant:"default",onClick:()=>L(f=>f+Rt),className:"gap-2",children:[e.jsx(ki,{className:"w-4 h-4"}),u("pages.intentions.table.loadMore").replace("{n}",Math.min(Rt,s.length-B.length))]})]}):e.jsxs("div",{ref:S,className:"flex items-center gap-2 text-sm text-slate-400",children:[e.jsx(ke,{className:"w-4 h-4 animate-spin"}),u("pages.intentions.table.loadingMore")]})}),!q&&B.length>0&&e.jsx("p",{className:"text-center text-xs text-slate-400 py-4",children:u("pages.intentions.table.endOfList").replace("{n}",s.length)})]})}function io({item:s,t:n}){const a=(s.payment_status_raw||"").toUpperCase();if(a==="COMPLETED"){const o=s.paid_at?be(new Date(s.paid_at),"dd.MM.yyyy"):null;return e.jsxs("div",{className:"text-[10px] font-normal text-emerald-700 whitespace-nowrap",title:n("pages.intentions.table.payConfirmedTitle"),children:["â ",o||n("pages.intentions.table.payConfirmed")]})}return a==="CANCELED"||a==="CANCELLED"||a==="FAILED"||a==="ERROR"?e.jsxs("div",{className:"text-[10px] font-normal text-rose-700
17whitespace-nowrap",title:n("pages.intentions.table.payRefusedTitle"),children:["â ",n("pages.intentions.table.payRefused")]}):e.jsxs("div",{className:"text-[10px] font-normal text-slate-400 whitespace-nowrap",title:n("pages.intentions.table.payNoRecordTitle"),children:["â ",n("pages.intentions.table.payNoRecord")]})}function lo({selectedCount:s,priests:n,assignablePriests:a,onBulkMarkPaid:o,onBulkSetStatus:i,onBulkSetStage:c,onBulkNotifyPriests:t,onBulkNotifyDonors:m,onBulkAssignPriest:r,onBulkUnassignPriest:y,onBulkDelete:N}){var v;const{t:d}=ye();return s?e.jsxs("div",{className:"flex items-center gap-2 animate-in fade-in zoom-in duration-200",children:[o&&e.jsxs(K,{size:"sm",onClick:()=>o(!0),className:"bg-emerald-600 hover:bg-emerald-700 text-white",children:[e.jsx(Zt,{className:"w-4 h-4 mr-2"}),d("pages.intentions.table.bulkMarkPaid")]}),e.jsxs(Fs,{children:[e.jsx(Is,{asChild:!0,children:e.jsxs(K,{size:"sm",variant:"outline",className:"gap-1.5 bg-white dark:bg-slate-900",children:[e.jsx(Ji,{className:"w-4 h-4"}),d("pages.intentions.table.actionsCount").replace("{n}",s),e.jsx(Mt,{className:"w-3.5 h-3.5 opacity-70"})]})}),e.jsxs(Es,{align:"end",className:"w-60",children:[e.jsx(yt,{children:d("pages.intentions.table.payoutGroupLabel")}),o&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{onClick:()=>o(!0),children:[e.jsx(Zt,{className:"w-4 h-4 mr-2 text-emerald-600"}),d("pages.intentions.table.bulkMarkPaid")]}),e.jsxs(Ne,{onClick:()=>o(!1),children:[e.jsx(el,{className:"w-4 h-4 mr-2 text-slate-500 dark:text-slate-400"}),d("pages.intentions.table.bulkUnmarkPaid")]})]}),i&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{}),e.jsxs(Wt,{children:[e.jsxs(Ut,{children:[e.jsx(tl,{className:"w-4 h-4 mr-2 text-slate-500 dark:text-slate-400"}),d("pages.intentions.table.changeStatus")]}),e.jsx(Vt,{children:e.jsxs(qt,{children:[e.jsx(Ne,{onClick:()=>i("succeeded"),children:d("pages.intentions.table.statusSucceeded")}),e.jsx(Ne,{onClick:()=>i("assigned"),children:d("pages.intentions.table.statusAssigned")}),e.jsx(Ne,{onClick:()=>i("awaiting_priest"),children:d("pages.intentions.table.statusAwaitingPriest")}),e.jsx(Ne,{onClick:()=>i("pending"),children:d("pages.intentions.table.statusPending")})]})})]})]}),(t||m)&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{}),e.jsx(yt,{children:d("pages.intentions.table.stageRunGroup")}),t&&e.jsxs(Ne,{onClick:t,children:[e.jsx(es,{className:"w-4 h-4 mr-2 text-rose-600"}),d("pages.intentions.table.stageNotifyPriest")]}),m&&e.jsxs(Ne,{onClick:m,children:[e.jsx($t,{className:"w-4 h-4 mr-2 text-emerald-600"}),d("pages.intentions.table.stageNotifyDonor")]})]}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{}),e.jsxs(Wt,{children:[e.jsxs(Ut,{children:[e.jsx(sl,{className:"w-4 h-4 mr-2 text-slate-500 dark:text-slate-400"}),d("pages.intentions.table.stageMarkGroup")]}),e.jsx(Vt,{children:e.jsx(qt,{children:Aa.map(k=>e.jsx(Ne,{onClick:()=>c(k),children:d(`pages.intentions.flow.row.${k}`)},k))})})]})]}),r&&((v=a??n)==null?void 0:v.length)>0&&e.jsxs(Wt,{children:[e.jsxs(Ut,{children:[e.jsx(ss,{className:"w-4 h-4 mr-2 text-indigo-600"}),d("pages.intentions.assignPriest")]}),e.jsx(Vt,{children:e.jsx(qt,{className:"max-h-72 overflow-y-auto",children:(a??n).map(k=>e.jsx(Ne,{onClick:()=>r(k.id),children:k.name||k.email||k.id},k.id))})})]}),y&&e.jsxs(Ne,{onClick:y,children:[e.jsx(al,{className:"w-4 h-4 mr-2 text-slate-500 dark:text-slate-400"}),d("pages.intentions.table.unassignPriest")]}),N&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{}),e.jsxs(Ne,{onClick:N,className:"text-rose-600 focus:text-rose-700 focus:bg-rose-50",children:[e.jsx(Qa,{className:"w-4 h-4 mr-2"}),d("pages.intentions.table.deleteSelected")]})]})]})]})]}):null}const oo=["due","celebrating","awaiting"],ro=(s,n,a)=>typeof s=="function"?s(n,a):a,ft=()=>({orders:0,masses:0,amount:0}),co=(s,n)=>{s.orders+=1,s.masses+=wt(n),s.amount+=Ge(n)};function wa(s){const n=((s==null?void 0:s.account_number)||"").trim();return{holder:((s==null?void 0:s.account_holder_name)||"").trim()||((s==null?void 0:s.name)||"").trim(),iban:n,swift:((s==null?void 0:s.swift_code)||(s==null?void 0:s.bic)||"").trim(),address:((s==null?void 0:s.bank_address)||"").trim(),email:((s==null?void 0:s.email)||"").trim(),hasData:!!n}}function mo(s,{priestId:n,managerId:a}){return n?new Set([n]):a?new Set(s.filter(o=>o.id===a||o.manager_priest_id===a).map(o=>o.id)):null}function Vs(s=[],n=[],{priestId:a=null,managerId:o=null,t:i=null,lang:c="pl",now:t=new Date}={}){const m=ji(t),r=new Map(n.map(P=>[P.id,P])),y=new Map(n.map(P=>[P.id,P.name])),N=mo(n,{priestId:a,managerId:o}),d=Pa(s),v=ro(i,"pages.intentions.export.noManagerGroup","Bez gestora"),k=P=>P?P.is_intentions_manager?P.name||v:P.manager_priest_id&&y.get(P.manager_priest_id)||v:v,g=new Map,x=P=>(g.has(P.id)||g.set(P.id,{id:P.id,name:P.name||"â",managerName:k(P),email:P.email||null,cutoff:na(P),lastPaidAt:d.get(P.id)||null,bank:wa(P),due:ft(),celebrating:ft(),awaiting:ft(),orders:0,masses:0,amount:0,multiplesByKey:new Map,multipleOrders:0,multipleMasses:0,items:[]}
17),g.get(P.id));s.forEach(P=>{if(!(P!=null&&P.priest_id)||N&&!N.has(P.priest_id))return;const F=r.get(P.priest_id);if(!F)return;const O=wi(P,m);if(!O||O==="paid"||!Fa(P,na(F)))return;const u=x(F),M=wt(P);if(co(u[O],P),u.orders+=1,u.masses+=M,u.amount+=Ge(P),M>1){const h=`${P.type||"unknown"}|${M}`,L=u.multiplesByKey.get(h);L?(L.count+=1,L.totalMasses+=M):u.multiplesByKey.set(h,{type:P.type||null,typeLabel:$e(P.type,c),masses:M,count:1,totalMasses:M}),u.multipleOrders+=1,u.multipleMasses+=M}u.items.push({id:P.id,phase:O,massDate:P.mass_date?String(P.mass_date).slice(0,10):null,createdAt:P.created_at||null,type:P.type||null,typeLabel:$e(P.type,c),masses:wt(P),fee:Ge(P),donor:P.name||"",content:P.content||""})});const l=[...g.values()].sort((P,F)=>F.amount-P.amount||P.name.localeCompare(F.name,"pl")),p={due:0,celebrating:1,awaiting:2};l.forEach(P=>{P.items.sort((F,O)=>p[F.phase]-p[O.phase]||String(F.massDate||"9999").localeCompare(String(O.massDate||"9999"))),P.multiples=[...P.multiplesByKey.values()].sort((F,O)=>O.totalMasses-F.totalMasses),delete P.multiplesByKey});const T={priests:l.length,orders:0,masses:0,amount:0,multipleOrders:0,multipleMasses:0,due:ft(),celebrating:ft(),awaiting:ft()};l.forEach(P=>{T.orders+=P.orders,T.masses+=P.masses,T.amount+=P.amount,T.multipleOrders+=P.multipleOrders,T.multipleMasses+=P.multipleMasses,oo.forEach(F=>{T[F].orders+=P[F].orders,T[F].masses+=P[F].masses,T[F].amount+=P[F].amount})});const R=a?y.get(a)||null:o&&y.get(o)||null,A=o&&!a?r.get(o):null;return{generatedAt:t,today:m,cutoff:Ys,priestId:a,managerId:o,subject:R,isGroup:!!(o&&!a),rows:l,totals:T,manager:A?{id:A.id,name:A.name||"â",bank:wa(A),amount:T.amount}:null,missingBankData:l.filter(P=>!P.bank.hasData).length}}const po={pl:ts,pt:Ea,en:Ra,fr:Ba,it:Oa},un=s=>po[s]||ts,E=(s,n,a)=>typeof s=="function"?s(n,a):a,gn=s=>String(s).replace("{fee}",qe),Ue=s=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN"}).format(s||0),Gt=s=>{if(!s)return null;const n=new Date(s);return Number.isNaN(n.getTime())?null:be(n,"dd.MM.yyyy")},xn=(s,n)=>s.multiples.map(a=>E(n,"pages.intentions.payout.multipleItem","{count} à {type} ({masses} Mszy)").replace("{count}",a.count).replace("{type}",a.typeLabel).replace("{masses}",a.masses)).join(" + "),hn=s=>({due:E(s,"pages.intentions.payout.phaseDue","Odprawione (wymagalne)"),celebrating:E(s,"pages.intentions.payout.phaseCelebrating","W toku"),awaiting:E(s,"pages.intentions.payout.phaseAwaiting","Oczekuje na akceptacjÄ")});function fn(s,n){return s.subject?s.isGroup?E(n,"pages.intentions.payout.titleGroup","Lista wypÅat â grupa gestora: {name}").replace("{name}",s.subject):E(n,"pages.intentions.payout.titleFor","Lista wypÅat â {name}").replace("{name}",s.subject):E(n,"pages.intentions.payout.title","Lista wypÅat dla kapÅanów")}function bn(s,n,a){const o=E(n,"pages.intentions.payout.fileBaseName","Wyplaty_kaplanom"),i=s.subject?`_${s.subject.replace(/\s+/g,"_")}`:"";return`${o}${i}_${be(s.generatedAt,"yyyy-MM-dd_HHmm")}.${a}`}function yn(s,n,a){return E(n,"pages.intentions.payout.asOf","Stan na dzieÅ {date} · honoraria za Msze od {from}").replace("{date}",be(s.generatedAt,"dd MMMM yyyy",{locale:un(a)})).replace("{from}",be(new Date(`${s.cutoff}T00:00:00`),"dd.MM.yyyy"))}async function uo(s,n,{priestId:a=null,managerId:o=null,t:i=null,lang:c="pl"}={}){const t=Vs(s,n,{priestId:a,managerId:o,t:i,lang:c}),m=await At(()=>import("./xlsx-6ed613d4.js"),[]),r=m.utils.book_new(),y=hn(i),N=E(i,"pages.intentions.payout.colPriest","KapÅan"),d=E(i,"pages.intentions.export.colManager","Gestor"),v=E(i,"pages.intentions.payout.colOrders","Intencji"),k=E(i,"pages.intentions.payout.colMasses","Mszy"),g=E(i,"pages.intentions.payout.colDue","Wymagalne"),x=E(i,"pages.intentions.payout.colUpcoming","W toku"),l=E(i,"pages.intentions.payout.colTotal","Do wypÅaty"),p=E(i,"pages.intentions.payout.colLastPayout","Ostatnia wypÅata"),T=E(i,"pages.intentions.payout.rowTotal","RAZEM"),R="â",A=E(i,"pages.intentions.payout.colMultiples","W tym intencje wielokrotne"),P=[N,d,v,k,A,g,x,l,p],F=t.rows.map(f=>[f.name,f.managerName,f.orders,f.masses,f.multiples.length?xn(f,i):"",f.due.amount,f.celebrating.amount+f.awaiting.amount,f.amount,Gt(f.lastPaidAt)||R]),O=[T,"",t.totals.orders,t.totals.masses,"",t.totals.due.amount,t.totals.celebrating.amount+t.totals.awaiting.amount,t.totals.amount,""],u=m.utils.aoa_to_sheet([[fn(t,i)],[yn(t,i,c)],[gn(E(i,"pages.intentions.payout.rule","Kwota = {fee} zÅ za każdÄ
MszÄ. Pozycje oznaczone w systemie jako wypÅacone nie pojawiajÄ
siÄ na tej liÅcie."))],[],P,...F,O]);u["!cols"]=[{wch:30},{wch:26},{wch:10},{wch:8},{wch:46},{wch:16},{wch:16},{wch:16},{wch:16}],u["!merges"]=[0,1,2].map(f=>({s:{r:f,c:0},e:{r:f,c:P.length-1}}
17)),F.concat([O]).forEach((f,W)=>{["F","G","H"].forEach(te=>{const ie=`${te}${6+W}`;u[ie]&&(u[ie].z="#,##0.00 [$zÅ-415]")})}),m.utils.book_append_sheet(r,u,E(i,"pages.intentions.payout.sheetPayout","Do wypÅaty"));const M=[N,l,E(i,"pages.intentions.payout.bankHolder","Odbiorca"),E(i,"pages.intentions.payout.bankIban","Numer konta (IBAN)"),E(i,"pages.intentions.payout.bankSwift","SWIFT / BIC"),E(i,"pages.intentions.payout.bankAddress","Bank"),E(i,"pages.intentions.payout.bankEmail","E-mail")],h=E(i,"pages.intentions.payout.bankMissing","BRAK DANYCH DO PRZELEWU"),L=t.manager?[[`${E(i,"pages.intentions.payout.managerRowLabel","GESTOR â caÅa grupa")}: ${t.manager.name}`,t.manager.amount,t.manager.bank.holder||R,t.manager.bank.iban||h,t.manager.bank.swift||R,t.manager.bank.address||R,t.manager.bank.email||R]]:[],H=t.rows.map(f=>[f.name,f.amount,f.bank.holder||R,f.bank.iban||h,f.bank.swift||R,f.bank.address||R,f.bank.email||R]),w=m.utils.aoa_to_sheet([M,...L,...H]);w["!cols"]=[{wch:30},{wch:16},{wch:28},{wch:34},{wch:14},{wch:30},{wch:28}],[...L,...H].forEach((f,W)=>{const te=`B${2+W}`;w[te]&&(w[te].z="#,##0.00 [$zÅ-415]")}),m.utils.book_append_sheet(r,w,E(i,"pages.intentions.payout.sheetBank","Dane do przelewu"));const S=[N,E(i,"pages.intentions.payout.colStatus","Status"),E(i,"pages.intentions.payout.colMassDate","Data Mszy"),E(i,"pages.intentions.export.colType","Rodzaj Intencji"),E(i,"pages.intentions.payout.colIntentionText","Intencja"),k,E(i,"pages.intentions.payout.colAmount","Kwota"),E(i,"pages.intentions.payout.colCreated","Data zgÅoszenia")],B=E(i,"pages.intentions.payout.noMassDate","Bez daty"),D=t.rows.flatMap(f=>f.items.map(W=>[f.name,y[W.phase],W.massDate?Gt(W.massDate):B,W.typeLabel,W.content||R,W.masses,W.fee,Gt(W.createdAt)||R])),q=m.utils.aoa_to_sheet([S,...D]);return q["!cols"]=[{wch:30},{wch:22},{wch:14},{wch:24},{wch:44},{wch:8},{wch:14},{wch:16}],D.forEach((f,W)=>{const te=`G${2+W}`;q[te]&&(q[te].z="#,##0.00 [$zÅ-415]")}),m.utils.book_append_sheet(r,q,E(i,"pages.intentions.payout.sheetDetails","SzczegóÅy")),m.writeFile(r,bn(t,i,"xlsx")),t}async function go(s,n,{priestId:a=null,managerId:o=null,t:i=null,lang:c="pl"}={}){await dn();const t=Vs(s,n,{priestId:a,managerId:o,t:i,lang:c}),{pdf:m,Document:r,Page:y,Text:N,View:d,StyleSheet:v}=await At(()=>import("./react-pdf.browser-058a6b7a.js"),["assets/react-pdf.browser-058a6b7a.js","assets/index-5a305ee0.js","assets/index-33a9d0f1.css","assets/constants-c1f6ae8f.js"]),k=hn(i),g="â",x=v.create({page:{padding:28,paddingBottom:40,fontSize:9,fontFamily:"Inter",color:"#1e293b"},h1:{fontSize:16,fontWeight:700,marginBottom:4,color:"#312e81"},sub:{fontSize:9,color:"#64748b",marginBottom:2},scopeLine:{fontSize:9,fontWeight:700,color:"#4f46e5",marginBottom:10},rule:{fontSize:8,color:"#475569",backgroundColor:"#eef2ff",padding:6,borderRadius:4,marginBottom:12},warn:{fontSize:8,color:"#9f1239",backgroundColor:"#ffe4e6",padding:6,borderRadius:4,marginBottom:12},section:{marginBottom:14},sectionTitle:{fontSize:11,fontWeight:700,marginBottom:6,color:"#312e81"},note:{fontSize:7.5,color:"#64748b",marginBottom:6,lineHeight:1.4},cards:{flexDirection:"row",gap:6,marginBottom:14},card:{flex:1,padding:8,borderRadius:4,backgroundColor:"#f8fafc",border:"1pt solid #e2e8f0"},cardTotal:{backgroundColor:"#eef2ff",border:"1pt solid #c7d2fe"},cardLabel:{fontSize:6.8,color:"#64748b",marginBottom:3},cardValue:{fontSize:12,fontWeight:700,color:"#1e293b"},cardValueTotal:{color:"#312e81"},cardHint:{fontSize:6.5,color:"#64748b",marginTop:2},table:{borderTop:"1pt solid #cbd5e1",borderLeft:"1pt solid #cbd5e1"},row:{flexDirection:"row",borderBottom:"1pt solid #cbd5e1"},headerRow:{backgroundColor:"#eef2ff"},totalRow:{backgroundColor:"#f1f5f9"},cell:{padding:3.5,fontSize:7.5,borderRight:"1pt solid #cbd5e1"},cellRight:{textAlign:"right"},cellHeader:{fontWeight:700,fontSize:6.8,color:"#312e81"},cellBold:{fontWeight:700},bankCard:{border:"1pt solid #cbd5e1",borderRadius:4,padding:8,marginBottom:6},bankCardMissing:{border:"1pt solid #fda4af",backgroundColor:"#fff1f2"},bankCardManager:{border:"1.5pt solid #818cf8",backgroundColor:"#eef2ff",marginBottom:10},managerBadge:{fontSize:6.8,fontWeight:700,color:"#4338ca",textTransform:"uppercase",letterSpacing:.4,marginBottom:3},managerNote:{fontSize:7.5,color:"#4338ca",marginTop:3,lineHeight:1.35},bankHead:{flexDirection:"row",justifyContent:"space-between",marginBottom:4},bankName:{fontSize:9.5,fontWeight:700,color:"#1e293b"},bankAmount:{fontSize:9.5,fontWeight:700,color:"#312e81"},bankLine:{flexDirection:"row",marginBottom:1.5},bankLabel:{width:"26%",fontSize:7.5,color:"#64748b"},bankValue:{flex:1,fontSize:7.5,color:"#1e293b"},bankMissing:{fontSize:7.5,fontWeight:700,color:"#9f1239"},footer:{position:"absolute",bottom:16,left:28,right:28,textAlign:"center",color:"#94a3b8",fontSize:7}
17,pageNum:{position:"absolute",bottom:26,left:28,right:28,textAlign:"center",color:"#94a3b8",fontSize:7},empty:{fontSize:10,color:"#475569",padding:12,textAlign:"center"},footnote:{marginTop:5,padding:6,borderRadius:3,backgroundColor:"#fffbeb",border:"1pt solid #fde68a"},footnoteTitle:{fontSize:7.5,fontWeight:700,color:"#92400e",marginBottom:2.5},footnoteLine:{fontSize:7.5,color:"#78350f",marginBottom:1.5,lineHeight:1.35}}),l=({children:M,w:h,align:L="left",header:H=!1,bold:w=!1})=>e.jsx(d,{style:[x.cell,{width:h},L==="right"&&x.cellRight,H&&x.cellHeader,w&&x.cellBold],children:e.jsx(N,{children:M})}),p=["4%","26%","21%","8%","5%","12%","12%","12%"],T=M=>M.celebrating.amount+M.awaiting.amount,R=t.rows.filter(M=>M.multiples.length>0),A=({label:M,value:h})=>e.jsxs(d,{style:x.bankLine,children:[e.jsx(N,{style:x.bankLabel,children:M}),e.jsx(N,{style:x.bankValue,children:h})]}),P=e.jsx(r,{children:e.jsxs(y,{size:"A4",style:x.page,children:[e.jsx(N,{style:x.h1,children:fn(t,i)}),e.jsx(N,{style:x.sub,children:E(i,"pages.intentions.export.generatedAt","Wygenerowano: {date}").replace("{date}",be(t.generatedAt,"dd MMMM yyyy, HH:mm",{locale:un(c)}))}),e.jsx(N,{style:x.scopeLine,children:yn(t,i,c)}),e.jsx(N,{style:x.rule,children:gn(E(i,"pages.intentions.payout.rule","Kwota = {fee} zÅ za każdÄ
MszÄ. Pozycje oznaczone w systemie jako wypÅacone nie pojawiajÄ
siÄ na tej liÅcie."))}),t.missingBankData>0&&e.jsx(N,{style:x.warn,children:E(i,"pages.intentions.payout.bankMissingCount","Brak danych do przelewu: {n} z {total} kapÅanów â tych pozycji nie da siÄ dziÅ wysÅaÄ.").replace("{n}",t.missingBankData).replace("{total}",t.totals.priests)}),e.jsxs(d,{style:x.cards,children:[e.jsxs(d,{style:x.card,children:[e.jsx(N,{style:x.cardLabel,children:E(i,"pages.intentions.payout.sumPriests","KapÅanów")}),e.jsx(N,{style:x.cardValue,children:String(t.totals.priests)})]}),e.jsxs(d,{style:x.card,children:[e.jsx(N,{style:x.cardLabel,children:E(i,"pages.intentions.payout.sumOrders","Intencji")}),e.jsx(N,{style:x.cardValue,children:String(t.totals.orders)}),e.jsxs(N,{style:x.cardHint,children:[E(i,"pages.intentions.payout.sumMasses","Mszy"),": ",String(t.totals.masses)]})]}),e.jsxs(d,{style:x.card,children:[e.jsx(N,{style:x.cardLabel,children:E(i,"pages.intentions.payout.colDue","Wymagalne")}),e.jsx(N,{style:x.cardValue,children:Ue(t.totals.due.amount)}),e.jsx(N,{style:x.cardHint,children:k.due})]}),e.jsxs(d,{style:[x.card,x.cardTotal],children:[e.jsx(N,{style:x.cardLabel,children:E(i,"pages.intentions.payout.sumTotal","Razem do wypÅaty")}),e.jsx(N,{style:[x.cardValue,x.cardValueTotal],children:Ue(t.totals.amount)})]})]}),e.jsxs(d,{style:x.section,children:[e.jsx(N,{style:x.sectionTitle,children:E(i,"pages.intentions.payout.sectionList","Komu i ile â lista przelewów")}),e.jsx(N,{style:x.note,children:E(i,"pages.intentions.payout.phaseNote","Wymagalne = Msza już odprawiona i potwierdzona przez kapÅana. W toku = intencja przyjÄta, termin jeszcze przed nami lub kapÅan jeszcze nie potwierdziÅ. Suma obu kolumn to caÅoÅÄ, którÄ
system uzna za wypÅaconÄ
po klikniÄciu «Oznacz jako wypÅacone».")}),t.rows.length===0?e.jsx(N,{style:x.empty,children:E(i,"pages.intentions.payout.empty","Brak pozycji do wypÅaty â wszystko rozliczone.")}):e.jsxs(d,{style:x.table,children:[e.jsxs(d,{style:[x.row,x.headerRow],fixed:!0,children:[e.jsx(l,{w:p[0],header:!0,children:E(i,"pages.intentions.payout.colNo","Lp.")}),e.jsx(l,{w:p[1],header:!0,children:E(i,"pages.intentions.payout.colPriest","KapÅan")}),e.jsx(l,{w:p[2],header:!0,children:E(i,"pages.intentions.export.colManager","Gestor")}),e.jsx(l,{w:p[3],align:"right",header:!0,children:E(i,"pages.intentions.payout.colOrders","Intencji")}),e.jsx(l,{w:p[4],align:"right",header:!0,children:E(i,"pages.intentions.payout.colMasses","Mszy")}),e.jsx(l,{w:p[5],align:"right",header:!0,children:E(i,"pages.intentions.payout.colDue","Wymagalne")}),e.jsx(l,{w:p[6],align:"right",header:!0,children:E(i,"pages.intentions.payout.colUpcoming","W toku")}),e.jsx(l,{w:p[7],align:"right",header:!0,children:E(i,"pages.intentions.payout.colTotal","Do wypÅaty")})]}),t.rows.map((M,h)=>e.jsxs(d,{style:x.row,wrap:!1,children:[e.jsx(l,{w:p[0],children:String(h+1)}),e.jsx(l,{w:p[1],children:M.name}),e.jsx(l,{w:p[2],children:M.managerName}),e.jsx(l,{w:p[3],align:"right",children:String(M.orders)}),e.jsx(l,{w:p[4],align:"right",children:M.multipleOrders>0?`${M.masses}*`:String(M.masses)}),e.jsx(l,{w:p[5],align:"right",children:Ue(M.due.amount)}),e.jsx(l,{w:p[6],align:"right",children:Ue(T(M))}),e.jsx(l,{w:p[7],align:"right",bold:!0,children:Ue(M.amount)})]},M.id)),e.jsxs(d,{style:[x.row,x.totalRow],wrap:!1,children:[e.jsx(l,{w:p[0],bold:!0,children:" "}),e.jsx(l,{w:p[1],bold:!0,children:E(i,"pages.intentions.payout.rowTotal","RAZEM")}),e.jsx(l,{w:p[2],children:" "}),e.jsx(l,{w:p[3],align:"right",bold:!0,children:String(t.totals.orders)}),e.jsx(l,{w:p[4],align:"right",bold:!0,children:t.totals.multipleOrders>0?`${t.totals.masses}*`:String(t.totals.masses)}),e.jsx(l,{w:p[5],align:"right",bold:!0,children:Ue(t.totals.due.amount)}),e.jsx(l,{w:p[6],align:"right",bold:!0,children:Ue(T(t.totals))}),e.jsx(l,{w:p[7],align:"right",bold:!0,children:Ue(t.totals.amount)})]})]}),R.length>0&&e.jsxs(d,{style:x.footnote,children:[e.jsx(N,{style:x.footnoteTitle,children:E(i,"pages.intentions.payout.multiplesNoteTitle","* Jedna intencja to wiÄcej niż jedna Msza â honorarium liczy siÄ za każdÄ
odprawionÄ
MszÄ:")}),R.map(M=>e.jsx(N,{style:x.footnoteLine,children:`${M.name}: ${xn(M,i)}`},`m-${M.id}`))]})]}),t.rows.length>0&&e.jsxs(d,{style:x.section,children:[e.jsx(N,{style:x.sectionTitle,children:E(i,"pages.intentions.payout.sectionBank","Dane do przelewu")}),e.jsx(N,{style:x.note,children:E(i,"pages.intentions.payout.bankNote","Dane podane przez kapÅana w jego panelu. BrakujÄ
ce trzeba uzupeÅniÄ przed wysÅaniem pieniÄdzy.")}),!!t.manager&&e.jsxs(d,{style:[x.bankCard,x.bankCardManager],wrap:!1,children:[e.jsx(N,{style:x.managerBadge,children:E(i,"pages.intentions.payout.managerTransferTitle","Przelew dla gestora â caÅa grupa")}),e.jsxs(d,{style:x.bankHead,children:[e.jsx(N,{style:x.bankName,children:t.manager.name}),e.jsx(N,{style:x.bankAmount,children:Ue(t.manager.amount)})]}),t.manager.bank.hasData?e.jsxs(e.Fragment,{children:[e.jsx(A,{label:E(i,"pages.intentions.payout.bankHolder","Odbiorca"),value:t.manager.bank.holder||g}),e.jsx(A,{label:E(i,"pages.intentions.payout.bankIban","Numer konta (IBAN)"),value:t.manager.bank.iban}),!!t.manager.bank.swift&&e.jsx(A,{label:E(i,"pages.intentions.payout.bankSwift","SWIFT / BIC"),value:t.manager.bank.swift}),!!t.manager.bank.address&&e.jsx(A,{label:E(i,"pages.intentions.payout.bankAddress","Bank"),value:t.manager.bank.address}),!!t.manager.bank.email&&e.jsx(A,{label:E(i,"pages.intentions.payout.bankEmail","E-mail"),value:t.manager.bank.email})]}):e.jsxs(e.Fragment,{children:[e.jsx(N,{style:x.bankMissing,children:E(i,"pages.intentions.payout.bankMissing","BRAK DANYCH DO PRZELEWU")}),e.jsx(A,{label:E(i,"pages.intentions.payout.bankEmail","E-mail"),value:t.manager.bank.email||g})]}),e.jsx(N,{style:x.managerNote,children:E(i,"pages.intentions.payout.managerTransferNote","Fundacja przelewa caÅÄ
kwotÄ gestorowi, a on rozdziela jÄ
miÄdzy kapÅanów wymienionych poniżej.")})]}),t.rows.map(M=>e.jsxs(d,{style:M.bank.hasData?x.bankCard:[x.bankCard,x.bankCardMissing],wrap:!1,children:[e.jsxs(d,{style:x.bankHead,children:[e.jsx(N,{style:x.bankName,children:M.name}),e.jsx(N,{style:x.bankAmount,children:Ue(M.amount)})]}),M.bank.hasData?e.jsxs(e.Fragment,{children:[e.jsx(A,{label:E(i,"pages.intentions.payout.bankHolder","Odbiorca"),value:M.bank.holder||g}),e.jsx(A,{label:E(i,"pages.intentions.payout.bankIban","Numer konta (IBAN)"),value:M.bank.iban}),!!M.bank.swift&&e.jsx(A,{label:E(i,"pages.intentions.payout.bankSwift","SWIFT / BIC"),value:M.bank.swift}),!!M.bank.address&&e.jsx(A,{label:E(i,"pages.intentions.payout.bankAddress","Bank"),value:M.bank.address}),!!M.bank.email&&e.jsx(A,{label:E(i,"pages.intentions.payout.bankEmail","E-mail"),value:M.bank.email}),!!M.lastPaidAt&&e.jsx(A,{label:E(i,"pages.intentions.payout.colLastPayout","Ostatnia wypÅata"),value:Gt(M.lastPaidAt)})]}):e.jsxs(e.Fragment,{children:[e.jsx(N,{style:x.bankMissing,children:E(i,"pages.intentions.payout.bankMissing","BRAK DANYCH DO PRZELEWU")}),e.jsx(A,{label:E(i,"pages.intentions.payout.bankEmail","E-mail"),value:M.bank.email||g})]})]},`bank-${M.id}`))]}),e.jsx(N,{style:x.pageNum,fixed:!0,render:({pageNumber:M,totalPages:h})=>E(i,"pages.intentions.export.pdfPageOf","Strona {n} z {total}").replace("{n}",M).replace("{total}",h)}),e.jsx(N,{style:x.footer,fixed:!0,children:E(i,"pages.intentions.export.pdfFooter","Maronicka Fundacja Misyjna â raport wygenerowany automatycznie z panelu administracyjnego")})]})}),F=await m(P).toBlob(),O=URL.createObjectURL(F),u=document.createElement("a");return u.href=O,u.download=bn(t,i,"pdf"),document.body.appendChild(u),u.click(),u.remove(),URL.revokeObjectURL(O),t}function xo({open:s,onOpenChange:n,intentions:a,priests:o,allIntentions:i}){const{toast:c}=kt(),{t,lang:m}=ye(),[r,y]=b.useState("all"),[N,d]=b.useState("full"),[v,k]=b.useState("all"),[g,x]=b.useState("all"),[l,p]=b.useState("all"),[T,R]=b.useState(""),[A,P]=b.useState(null),F=r==="priests"&&N==="payout",O=i||a,u=b.useMemo(()=>sn(a),[a]);b.useEffect(()=>{s||(k("all"),x("all"),p("all"),R(""),d("full"))},[s]),b.useEffect(()=>{r!=="priests"&&(k("all"),x("all"),R(""),d("full"))},[r]);const M=b.useMemo(()=>[...o].sort((f,W)=>(f.name||"").localeCompare(W.name||"","pl")),[o]),h=b.useMemo(()=>{const f=T.trim().toLowerCase();return f?M.filter(W=>(W.name||"").toLowerCase().includes(f)):M},[M,T]),L=b.useMemo(()=>M.filter(f=>f.is_intentions_manager),[M]),H=b.useMemo(()=>g==="all"?0:o.filter(f=>f.id===g||f.manager_priest_id===g).length,[o,g]),w=b.useMemo(()=>
17{if(!s||!F)return null;const f=g!=="all"?g:null;return Vs(O,o,{priestId:!f&&v!=="all"?v:null,managerId:f,t,lang:m})},[s,F,O,o,v,g,t,m]),S=f=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN",maximumFractionDigits:0}).format(f||0),B=f=>{k(f),f!=="all"&&x("all")},D=f=>{x(f),f!=="all"&&k("all")},q=async f=>{var W,te;P(f);try{const ie=r==="priests"&&g!=="all"?g:null,ae=r==="priests"&&!ie&&v!=="all"?v:null,De=F||l==="all"?null:Number(l);if(F){const ee={priestId:ae,managerId:ie,t,lang:m};f==="xls"?await uo(O,o,ee):await go(O,o,ee)}else{const ee={scope:r,priestId:ae,managerId:ie,year:De,t,lang:m};f==="xls"?await cn(a,o,ee):await mn(a,o,ee)}const ve=ae?((W=M.find(ee=>ee.id===ae))==null?void 0:W.name)||"":ie&&((te=M.find(ee=>ee.id===ie))==null?void 0:te.name)||"",Ae=F?ve?`${t("pages.intentions.reportDialog.scopeLabelPayout")} · ${ve}`:t("pages.intentions.reportDialog.scopeLabelPayout"):r==="priests"?ae?t("pages.intentions.reportDialog.scopeLabelOnlyPriest").replace("{name}",ve):ie?t("pages.intentions.reportDialog.scopeLabelManagerGroup").replace("{name}",ve):t("pages.intentions.reportDialog.scopeLabelAllPriests"):t("pages.intentions.reportDialog.scopeLabelFull"),z=De?`${Ae} · ${De}`:Ae;c({title:t("components.intentionAnalytics.summary.reportDownloadedTitle"),description:t("pages.intentions.reportDialog.toastSavedDesc").replace("{format}",f.toUpperCase()).replace("{scope}",z),className:"bg-green-50 border-green-200 text-green-900"}),n(!1)}catch(ie){c({title:t("components.intentionAnalytics.summary.exportErrorTitle"),description:(ie==null?void 0:ie.message)||t("components.intentionAnalytics.summary.exportErrorDesc"),variant:"destructive"})}finally{P(null)}};return e.jsx(vt,{open:s,onOpenChange:n,children:e.jsxs(Ct,{className:"sm:max-w-[480px] max-h-[88vh] overflow-y-auto",children:[e.jsxs(_t,{children:[e.jsxs(St,{className:"flex items-center gap-2",children:[e.jsx(Ds,{className:"w-5 h-5 text-indigo-600"}),t("pages.intentions.reportDialog.title")]}),e.jsx(Pt,{children:t("pages.intentions.reportDialog.description")})]}),e.jsxs(nl,{value:r,onValueChange:y,className:"space-y-2 my-2",children:[e.jsx(ka,{value:"all",current:r,icon:Ds,title:t("pages.intentions.reportDialog.scopeAllTitle"),badge:t("pages.intentions.reportDialog.scopeAllBadge"),badgeClass:"bg-indigo-100 text-indigo-700",description:t("pages.intentions.reportDialog.scopeAllDesc")}),e.jsx(ka,{value:"priests",current:r,icon:Jt,title:t("pages.intentions.reportDialog.scopePriestsTitle"),badge:t("pages.intentions.reportDialog.scopePriestsBadge"),badgeClass:"bg-amber-100 text-amber-700",description:t("pages.intentions.reportDialog.scopePriestsDesc").replace("{fee}",qe)})]}),e.jsxs("div",{className:"space-y-2 rounded-md border border-indigo-200 bg-indigo-50/40 p-3",children:[e.jsxs(J,{className:"flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-indigo-800",children:[e.jsx(cl,{className:"w-3.5 h-3.5"}),t("pages.intentions.reportDialog.yearFilterLabel")]}),e.jsxs(Ee,{value:l,onValueChange:p,disabled:F,children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900 disabled:opacity-60",children:e.jsx(Be,{placeholder:t("pages.intentions.reportDialog.yearAll")})}),e.jsxs(Oe,{className:"max-h-[280px]",children:[e.jsx(je,{value:"all",children:t("pages.intentions.reportDialog.yearAll")}),u.map(f=>e.jsx(je,{value:String(f),children:f},f))]})]}),e.jsx("p",{className:"text-[11px] text-slate-600 dark:text-slate-300 leading-relaxed",children:F?t("pages.intentions.reportDialog.yearHelperPayout").replace("{date}",Ys.split("-").reverse().join(".")):l==="all"?t("pages.intentions.reportDialog.yearHelperAll"):t("pages.intentions.reportDialog.yearHelperSingle").replace("{year}",l)})]}),r==="priests"&&e.jsxs("div",{className:"space-y-2 rounded-md border border-amber-200 bg-amber-50/40 p-3",children:[e.jsx(J,{className:"text-xs font-semibold uppercase tracking-wide text-amber-800",children:t("pages.intentions.reportDialog.kindLabel")}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Na,{active:N==="full",icon:xi,title:t("pages.intentions.reportDialog.kindFullTitle"),description:t("pages.intentions.reportDialog.kindFullDesc"),onClick:()=>d("full")}),e.jsx(Na,{active:F,icon:ll,title:t("pages.intentions.reportDialog.kindPayoutTitle"),description:t("pages.intentions.reportDialog.kindPayoutDesc"),onClick:()=>d("payout")})]}),F&&e.jsxs("div",{className:"rounded-md border border-emerald-200 bg-emerald-50 dark:bg-emerald-950/30 px-3 py-2",children:[e.jsx("p",{className:"text-[11px] font-semibold text-emerald-900 dark:text-emerald-200",children:w&&w.totals.priests>0?t("pages.intentions.reportDialog.payoutPreview").replace("{priests}",w.totals.priests).replace("{orders}",w.totals.orders).replace("{amount}",S(w.totals.amount)):t("pages.intentions.reportDialog.payoutPreviewEmpty")}),!!w&&w.totals.priests>0&&e.jsx("p",{className:"text-[11px] text-emerald-800 dark:text-emerald-300",children:t("pages.intentions.reportDialog.payoutPreviewDue").replace("{amount}",S(w.totals.due.amount))}),!!w&&w.totals.multipleOrders>0&&e.jsx("p",{className:"text-[11px] text-emerald-800 dark:text-emerald-300",children:t("pages.intentions.reportDialog.payoutPreviewMultiples").replace("{orders}",w.totals.multipleOrders).replace("{masses}",w.totals.multipleMasses)}),!!w&&w.missingBankData>0&&e.jsx("p",{className:"text-[11px] text-rose-700 dark:text-rose-300 mt-1",children:t("pages.intentions.reportDialog.payoutPreviewNoBank").replace("{n}",w.missingBankData)})]}),L.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs(J,{className:"flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-amber-800",children:[e.jsx(Xn,{className:"w-3.5 h-3.5"}),t("pages.intentions.reportDialog.managerFilterLabel")]}),e.jsxs(Ee,{value:g,onValueChange:D,children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900",children:e.jsx(Be,{placeholder:t("pages.intentions.reportDialog.noManagerFilter")})}),e.jsxs(Oe,{className:"max-h-[280px]",children:[e.jsx(je,{value:"all",children:t("pages.intentions.reportDialog.noManagerFilter")}),L.map(f=>e.jsx(je,{value:f.id,children:f.name},f.id))]})]})]}),e.jsx(J,{className:"text-xs font-semibold uppercase tracking-wide text-amber-800",children:t("pages.intentions.reportDialog.priestFilterLabel")}),e.jsxs(Ee,{value:v,onValueChange:B,children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900",children:e.jsx(Be,{placeholder:t("pages.intentions.filters.allPriests")})}),e.jsxs(Oe,{className:"max-h-[280px]",children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white dark:bg-slate-900 p-2 border-b border-slate-200 dark:border-slate-800",children:e.jsxs("div",{className:"relative",children:[e.jsx(Os,{className:"absolute left-2.5 top-2 h-3.5 w-3.5 text-slate-400"}),e.jsx(pe,{placeholder:t("pages.intentions.reportDialog.priestSearchPlaceholder"),className:"pl-8 h-8 text-sm",value:T,onChange:f=>R(f.target.value),onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation()})]})}),e.jsx(je,{value:"all",children:t("pages.intentions.reportDialog.allPriestsCount").replace("{n}",M.length)}),h.map(f=>e.jsx(je,{value:f.id,children:f.name},f.id)),h.length===0&&T&&e.jsx("div",{className:"px-2 py-3 text-xs text-slate-500 dark:text-slate-400 text-center",children:t("pages.intentions.reportDialog.noMatches").replace("{query}",T)})]})]}
17),e.jsx("p",{className:"text-[11px] text-slate-600 dark:text-slate-300 leading-relaxed",children:F?t("pages.intentions.reportDialog.helperPayout"):g!=="all"?t("pages.intentions.reportDialog.helperManagerGroup").replace("{n}",H):t(v==="all"?"pages.intentions.reportDialog.helperAllPriests":"pages.intentions.reportDialog.helperSinglePriest")})]}),e.jsxs(Dt,{className:"gap-2 sm:gap-2 flex-col-reverse sm:flex-row",children:[e.jsx(K,{variant:"ghost",onClick:()=>n(!1),disabled:!!A,children:t("common.cancel")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(K,{variant:"outline",onClick:()=>q("xls"),disabled:!!A,className:"bg-white dark:bg-slate-900 text-emerald-700 border-emerald-200 hover:bg-emerald-50",children:[A==="xls"?e.jsx(ke,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx($a,{className:"w-4 h-4 mr-2"}),t("pages.intentions.exportXls")]}),e.jsxs(K,{onClick:()=>q("pdf"),disabled:!!A,className:"bg-rose-600 hover:bg-rose-700 text-white",children:[A==="pdf"?e.jsx(ke,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(va,{className:"w-4 h-4 mr-2"}),t("pages.intentions.reportDialog.downloadPdf")]})]})]})]})})}function Na({active:s,icon:n,title:a,description:o,onClick:i}){return e.jsxs("button",{type:"button",onClick:i,"aria-pressed":s,className:$("text-left p-2.5 rounded-md border transition-all",s?"border-amber-400 bg-white dark:bg-slate-900 ring-1 ring-amber-300":"border-slate-200 dark:border-slate-800 bg-white/60 dark:bg-slate-900/60 hover:border-slate-300"),children:[e.jsxs("span",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx(n,{className:$("w-3.5 h-3.5",s?"text-amber-600":"text-slate-500 dark:text-slate-400")}),e.jsx("span",{className:"text-xs font-semibold text-slate-900 dark:text-slate-100",children:a})]}),e.jsx("span",{className:"block text-[11px] text-slate-600 dark:text-slate-300 leading-snug",children:o})]})}function ka({value:s,current:n,icon:a,title:o,badge:i,badgeClass:c,description:t}){const m=n===s;return e.jsxs(J,{htmlFor:`scope-${s}`,className:$("flex items-start gap-3 p-3 rounded-md border cursor-pointer transition-all",m?"border-indigo-400 bg-indigo-50/60 ring-1 ring-indigo-200":"border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-slate-300"),children:[e.jsx(il,{id:`scope-${s}`,value:s,className:"mt-1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(a,{className:$("w-4 h-4",m?"text-indigo-600":"text-slate-500 dark:text-slate-400")}),e.jsx("span",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100",children:o}),e.jsx("span",{className:$("text-[10px] font-bold uppercase tracking-wide px-1.5 py-0.5 rounded",c),children:i})]}),e.jsx("p",{className:"text-xs text-slate-600 dark:text-slate-300 leading-relaxed",children:t})]})]})}function ho({open:s,onOpenChange:n,summary:a,onNotified:o}){const{toast:i}=kt(),{t:c}=ye(),[t,m]=b.useState(!1),[r,y]=b.useState(null),N=b.useMemo(()=>{if(!(a!=null&&a.assigned))return[];const p=new Map;return a.assigned.forEach(T=>{p.has(T.priestId)||p.set(T.priestId,{priestId:T.priestId,priestName:T.priestName,items:[]}),p.get(T.priestId).items.push(T)}),Array.from(p.values()).sort((T,R)=>R.items.length-T.items.length)},[a]),d=async()=>{var R;if(!((R=a==null?void 0:a.assigned)!=null&&R.length))return;m(!0);const p=await Hs(a.assigned);y(p);const T=Xt(p,c);T&&i(T),p.ok&&(o==null||o()),m(!1)};if(!a)return null;const{assignmentsByCriterion:v={},totalAssigned:k=0,overflow:g=0}=a,x=r||a.notified||null,l=((x==null?void 0:x.skipped)||[]).reduce((p,T)=>p+(T.count??1),0);return e.jsx(vt,{open:s,onOpenChange:n,children:e.jsxs(Ct,{className:"sm:max-w-[560px]",children:[e.jsxs(_t,{children:[e.jsxs(St,{className:"flex items-center gap-2",children:[e.jsx(Bs,{className:"w-5 h-5 text-emerald-600"}),c("pages.intentions.smartAssign.title")]}),e.jsxs(Pt,{children:[et(c("pages.intentions.smartAssign.description"),{n:k}),g>0&&e.jsxs(e.Fragment,{children:[" ",et(c("pages.intentions.smartAssign.overflowNote"),{n:g})]})]})]}),e.jsxs("div",{className:"space-y-4 my-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(_s,{icon:ol,tone:"indigo",count:v.byName||0,label:c("pages.intentions.smartAssign.byNameLabel"),hint:c("pages.intentions.smartAssign.byNameHint")}),e.jsx(_s,{icon:$s,tone:"emerald",count:v.byCity||0,label:c("pages.intentions.smartAssign.byCityLabel"),hint:c("pages.intentions.smartAssign.byCityHint")}),e.jsx(_s,{icon:Jt,tone:"slate",count:v.byCapacity||0,label:c("pages.intentions.smartAssign.byCapacityLabel"),hint:c("pages.intentions.smartAssign.byCapacityHint")})]}),g>0&&e.jsxs("div",{className:"rounded-md border border-amber-200 bg-amber-50 p-3 flex items-start gap-2",children:[e.jsx(tt,{className:"w-4 h-4 text-amber-700 mt-0.5 shrink-0"}),e.jsx("div",{className:"text-xs text-amber-900 leading-relaxed",children:et(c("pages.intentions.smartAssign.overflowWarning"),{count:g})})]}),N.length>0&&e.jsxs("div",{className:"rounded-md border border-slate-200 dark:border-slate-800 bg-slate-50 dark:bg-slate-900/40 p-3 max-h-[180px] overflow-y-auto scrollbar-thin",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-slate-500 dark:text-slate-400 font-semibold mb-2",children:c("pages.intentions.smartAssign.distributionLabel")}),e.jsx("div",{className:"space-y-1.5",children:N.map(p=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"font-medium text-slate-800 dark:text-slate-100 truncate",children:p.priestName}),e.jsx("span",{className:"text-slate-500 dark:text-slate-400 tabular-nums",children:c("pages.intentions.smartAssign.perPriestCount").replace("{n}",p.items.length)})]},p.priestId))})]}),x&&e.jsxs("div",{className:$("rounded-md border p-3 flex items-start gap-2",!x.ok&&"border-red-200 bg-red-50",x.ok&&l>0&&"border-amber-200 bg-amber-50",x.ok&&l===0&&"border-emerald-200 bg-emerald-50"),children:[x.ok?e.jsx($t,{className:"w-4 h-4 text-emerald-700 mt-0.5 shrink-0"}):e.jsx(tt,{className:"w-4 h-4 text-red-700 mt-0.5 shrink-0"}),e.jsx("div",{className:$("text-xs leading-relaxed",x.ok?"text-emerald-900":"text-red-900"),children:x.ok?e.jsxs(e.Fragment,{children:[c("pages.intentions.smartAssign.sentBanner").replace("{priests}",x.priestsNotified??0).replace("{intentions}",x.intentionsNotified??0),l>0&&e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{className:"text-amber-900",children:c("pages.intentions.smartAssign.sentBannerSkipped").replace("{skipped}",l)})]})]}):c("pages.intentions.smartAssign.sendFailedBanner")})]}),e.jsxs("div",{className:"rounded-md border border-indigo-200 bg-indigo-50/60 p-3 flex items-start gap-2",children:[e.jsx(Ha,{className:"w-4 h-4 text-indigo-700 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-indigo-900 leading-relaxed",children:[e.jsx("strong",{children:c("pages.intentions.smartAssign.ruleTitle").replace("{n}",jt)})," ",c("pages.intentions.smartAssign.ruleBody").replace("{n}",jt)]})]})]}),e.jsxs(Dt,{className:"gap-2 sm:gap-2 flex-col-reverse sm:flex-row",children:[e.jsxs(K,{variant:"outline",onClick:d,disabled:t||k===0,children:[t?e.jsx(ke,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(es,{className:"w-4 h-4 mr-2"}),c("pages.intentions.smartAssign.resendButton")]}),e.jsx(K,{onClick:()=>n(!1),disabled:t,children:c("common.close")})]})]})})}function _s({icon:s,tone:n,count:a,label:o,hint:i}){const c={indigo:{ring:"ring-indigo-200",bg:"bg-indigo-50",text:"text-indigo-900",iconBg:"bg-indigo-100",iconText:"text-indigo-700"},emerald:{ring:"ring-emerald-200",bg:"bg-emerald-50",text:"text-emerald-900",iconBg:"bg-emerald-100",iconText:"text-emerald-700"},slate:{ring:"ring-slate-200",bg:"bg-slate-50 dark:bg-slate-900/40",text:"text-slate-800 dark:text-slate-100",iconBg:"bg-slate-100 dar
17k:bg-slate-800",iconText:"text-slate-600 dark:text-slate-300"}},t=c[n]||c.slate;return e.jsxs("div",{className:$("rounded-md ring-1 p-2",t.ring,t.bg),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:$("p-1 rounded",t.iconBg),children:e.jsx(s,{className:$("w-3 h-3",t.iconText)})}),e.jsx("span",{className:$("text-lg font-bold tabular-nums",t.text),children:a})]}),e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wide text-slate-600 dark:text-slate-300 mt-1",children:o}),e.jsx("p",{className:"text-[10px] text-slate-500 dark:text-slate-400 leading-tight",children:i})]})}const fo=["dantis","individual","collective"].filter(s=>!bi[s]);function bo(s){return new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN"}).format(s||0)}function Ss(){return{id:Zn(),priestId:"",quantity:"",totalValue:"",valueDirty:!1}}function yo({open:s,onOpenChange:n,priests:a=[],onSubmit:o}){const{t:i}=ye(),[c,t]=b.useState(""),[m,r]=b.useState(""),[y,N]=b.useState(""),[d,v]=b.useState(""),[k,g]=b.useState("dantis"),[x,l]=b.useState([Ss()]),[p,T]=b.useState(!1),R=b.useRef(null);b.useEffect(()=>{s&&(t(""),r(""),N(""),v(""),g("dantis"),l([Ss()]),T(!1),setTimeout(()=>{var D;return(D=R.current)==null?void 0:D.focus()},50))},[s]);const A=b.useMemo(()=>a.filter(D=>D.active!==!1),[a]),P=b.useMemo(()=>new Map(A.map(D=>[D.id,D])),[A]),F=(D,q)=>{l(f=>f.map(W=>W.id===D?{...W,...q}:W))},O=(D,q)=>{l(f=>f.map(W=>{if(W.id!==D)return W;const te=q===""?"":Math.max(0,Math.floor(Number(q)||0)),ie=W.valueDirty?W.totalValue:te===""?"":te*qe;return{...W,quantity:te,totalValue:ie}}))},u=(D,q)=>{l(f=>f.map(W=>{if(W.id!==D)return W;const te=q===""?"":Math.max(0,Number(q)||0);return{...W,totalValue:te,valueDirty:!0}}))},M=D=>{l(q=>q.map(f=>{if(f.id!==D)return f;const W=Number(f.quantity)||0;return{...f,totalValue:W*qe,valueDirty:!1}}))},h=()=>l(D=>[...D,Ss()]),L=D=>l(q=>q.length>1?q.filter(f=>f.id!==D):q),H=b.useMemo(()=>{const D=new Map;return x.forEach(q=>{q.priestId&&D.set(q.priestId,(D.get(q.priestId)||0)+1)}),D},[x]),w=b.useMemo(()=>{let D=0,q=0;return x.forEach(f=>{D+=Number(f.quantity)||0,q+=Number(f.totalValue)||0}),{qty:D,value:q}},[x]),S=c.trim().length>0&&x.some(D=>D.priestId&&Number(D.quantity)>0)&&!p,B=async()=>{if(!(!S||!o)){T(!0);try{const D=x.filter(f=>f.priestId&&Number(f.quantity)>0).map(f=>({priestId:f.priestId,quantity:Number(f.quantity),totalValue:Number(f.totalValue)||0}));await o({provenance:c.trim(),note:m.trim(),requesterName:y.trim(),requesterEmail:d.trim(),type:k,rows:D})&&n(!1)}finally{T(!1)}}};return e.jsx(vt,{open:s,onOpenChange:D=>!p&&n(D),children:e.jsxs(Ct,{className:"sm:max-w-[640px]",children:[e.jsxs(_t,{children:[e.jsxs(St,{className:"flex items-center gap-2",children:[e.jsx(Xa,{className:"w-5 h-5 text-teal-600"}),i("pages.intentions.financial.addDantisButton")]}),e.jsx(Pt,{children:i("pages.intentions.dantis.description")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"dantis-provenance",className:"text-xs font-semibold text-slate-700 dark:text-slate-200 flex items-center gap-1.5",children:[e.jsx(Za,{className:"w-3.5 h-3.5 text-slate-500 dark:text-slate-400"}),i("pages.intentions.dantis.provenanceLabel")," ",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx(pe,{id:"dantis-provenance",ref:R,value:c,onChange:D=>t(D.target.value),placeholder:i("pages.intentions.dantis.provenancePlaceholder"),className:"bg-white dark:bg-slate-900"}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.provenanceHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"dantis-note",className:"text-xs font-semibold text-slate-700 dark:text-slate-200",children:i("pages.intentions.dantis.noteLabel")}),e.jsx(_a,{id:"dantis-note",value:m,onChange:D=>r(D.target.value),placeholder:i("pages.intentions.dantis.notePlaceholder"),rows:2,className:"bg-white dark:bg-slate-900 resize-none"})]}),e.jsxs("div",{className:"space-y-2 rounded-md border border-slate-200 dark:border-slate-800 p-3",children:[e.jsxs(J,{className:"text-xs font-semibold text-slate-700 dark:text-slate-200 flex items-center gap-1.5",children:[e.jsx(rl,{className:"w-3.5 h-3.5 text-slate-500 dark:text-slate-400"}),i("pages.intentions.dantis.requesterLabel")]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[e.jsx(pe,{id:"dantis-requester-name",value:y,onChange:D=>N(D.target.value),placeholder:i("pages.intentions.dantis.requesterNamePlaceholder"),className:"bg-white dark:bg-slate-900"}),e.jsx(pe,{id:"dantis-requester-email",type:"email",value:d,onChange:D=>v(D.target.value),placeholder:i("pages.intentions.dantis.requesterEmailPlaceholder"),className:"bg-white dark:bg-slate-900"})]}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.requesterHint")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{className:"text-xs font-semibold text-slate-700 dark:text-slate-200",children:i("pages.intentions.dantis.typeLabel")}),e.jsxs(Ee,{value:k,onValueChange:g,children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900",children:e.jsx(Be,{})}),e.jsx(Oe,{children:fo.map(D=>e.jsx(je,{value:D,children:$e(D)},D))})]}),e.jsx("p",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.typeHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(J,{className:"text-xs font-semibold text-slate-700 dark:text-slate-200 flex items-center gap-1.5",children:[e.jsx(Jt,{className:"w-3.5 h-3.5 text-slate-500 dark:text-slate-400"}),i("pages.intentions.smartAssign.distributionLabel")," ",e.jsx("span",{className:"text-rose-500",children:"*"})]}),e.jsx("span",{className:"text-[11px] text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.valueHint").replace("{fee}",qe)})]}),e.jsx("div",{className:"space-y-2 max-h-[280px] overflow-y-auto pr-0.5",children:x.map(D=>{const q=D.priestId&&H.get(D.priestId)>1,f=D.priestId?P.get(D.priestId):null;return e.jsxs("div",{className:$("grid grid-cols-[1fr_120px_140px_auto] gap-2 items-end p-2.5 rounded-md border",q?"bg-amber-50/70 border-amber-200":"bg-slate-50 dark:bg-slate-900/40 border-slate-200 dark:border-slate-800"),children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[10px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.priestColumn")}),e.jsxs(Ee,{value:D.priestId,onValueChange:W=>F(D.id,{priestId:W}),children:[e.jsx(Re,{className:"bg-white dark:bg-slate-900 h-9",children:e.jsx(Be,{placeholder:i("pages.intentions.filters.priestPlaceholder")})}),e.jsx(Oe,{children:A.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.noActivePriests")}):A.map(W=>e.jsx(je,{value:W.id,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate",children:W.name}),W.autoEligible===!1?e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-slate-100 dar
17k:bg-slate-800 text-slate-600 dark:text-slate-300 whitespace-nowrap",children:i("pages.intentions.dantis.manualOnlyBadge")}):null]})},W.id))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{className:"text-[10px] uppercase tracking-wide text-slate-500 dark:text-slate-400",children:i("pages.intentions.dantis.quantityColumn")}),e.jsx(pe,{type:"number",min:"1",step:"1",value:D.quantity,onChange:W=>O(D.id,W.target.value),placeholder:i("pages.intentions.dantis.quantityPlaceholder"),className:"bg-white dark:bg-slate-900 h-9 tabular-nums"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(J,{className:"text-[10px] uppercase tracking-wide text-slate-500 dark:text-slate-400 flex items-center justify-between",children:[i("pages.intentions.dantis.valueColumn"),D.valueDirty&&Number(D.quantity)>0&&e.jsx("button",{type:"button",onClick:()=>M(D.id),className:"text-[9px] text-indigo-600 hover:text-indigo-800 normal-case tracking-normal",title:i("pages.intentions.dantis.resetTitle").replace("{fee}",qe),children:i("pages.intentions.dantis.resetLabel")})]}),e.jsx(pe,{type:"number",min:"0",step:"1",value:D.totalValue,onChange:W=>u(D.id,W.target.value),placeholder:i("pages.intentions.dantis.autoPlaceholder"),className:"bg-white dark:bg-slate-900 h-9 tabular-nums"})]}),e.jsx(K,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 text-rose-500 hover:bg-rose-50 hover:text-rose-700 self-end",onClick:()=>L(D.id),disabled:x.length===1,"aria-label":i("pages.intentions.dantis.removeRowAria"),children:e.jsx(Qa,{className:"w-4 h-4"})}),(f==null?void 0:f.max_intentions)>0&&Number(D.quantity)>0&&e.jsxs("div",{className:"col-span-4 -mt-1 text-[10px] text-slate-500 dark:text-slate-400",children:[i("pages.intentions.dantis.priestLimit").replace("{n}",f.max_intentions),typeof f.intentionsThisYear=="number"&&e.jsxs(e.Fragment,{children:[" ",i("pages.intentions.dantis.yearLoad").replace("{n}",f.intentionsThisYear).replace("{after}",f.intentionsThisYear+Number(D.quantity))]}),(typeof f.intentionsThisYear=="number"?f.intentionsThisYear+Number(D.quantity):Number(D.quantity))>f.max_intentions?e.jsxs("span",{className:"text-amber-700 font-medium",children:[" ",i("pages.intentions.dantis.limitExceeded")]}):null]}),q&&e.jsxs("div",{className:"col-span-4 -mt-1 text-[10px] text-amber-700 flex items-center gap-1",children:[e.jsx(tt,{className:"w-3 h-3"}),i("pages.intentions.dantis.duplicatePriest")]})]},D.id)})}),e.jsxs(K,{type:"button",variant:"outline",size:"sm",onClick:h,className:"w-full border-dashed",children:[e.jsx(As,{className:"w-3.5 h-3.5 mr-1.5"})," ",i("pages.intentions.dantis.addPriestRow")]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t border-slate-200 dark:border-slate-800 text-sm",children:[e.jsx("span",{className:"text-slate-600 dark:text-slate-300",children:et(i(w.qty===1?"pages.intentions.dantis.totalCountOne":"pages.intentions.dantis.totalCountMany"),{n:w.qty})}),e.jsx("span",{className:"text-slate-600 dark:text-slate-300",children:et(i("pages.intentions.dantis.totalValueLabel"),{amount:bo(w.value)})})]})]}),e.jsxs(Dt,{className:"gap-2 sm:gap-2 flex-col-reverse sm:flex-row",children:[e.jsx(K,{variant:"ghost",onClick:()=>n(!1),disabled:p,children:i("common.cancel")}),e.jsxs(K,{onClick:B,disabled:!S,className:"bg-teal-600 hover:bg-teal-700 text-white",children:[p?e.jsx(ke,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(As,{className:"w-4 h-4 mr-2"}),w.qty>0?i(w.qty===1?"pages.intentions.dantis.submitOne":"pages.intentions.dantis.submitMany").replace("{n}",w.qty):i("pages.intentions.dantis.submitEmpty")]})]})]})})}const jo=1e3;function wo(s,n,a){const o=Number(s)||0;return o<n?!1:a>=jo||o<=a}const it={search:"",email:"",status:"all",type:"all",priestId:"all",location:"",year:"all",dateFrom:null,dateTo:null,amountMin:0,amountMax:1e3};function Or({managerPriestId:s=null}){const n=!!s,{intentions:a,priests:o,assignablePriests:i,selectablePriests:c,loading:t,assigning:m,fetchData:r,autoAssign:y,smartAutoAssign:N,addDantisIntentions:d,bulkDelete:v,redistributeIntentions:k,addMockIntention:g,markPriestPaid:x,confirmPriestIntentions:l,addManualIntention:p,bulkUpdateStatus:T,bulkSetStage:R,bulkUnassignPriest:A,bulkAssignPriest:P}=hi({managerPriestId:s}),F=Sa(),{toast:O}=kt(),{t:u}=ye(),M=async({intentionIds:j})=>{!j||j.length===0||!await F({title:u(j.length===1?"pages.intentions.bulk.markPaidConfirmTitleOne":"pages.intentions.bulk.markPaidConfirmTitleMany").replace("{count}",j.length),description:u("pages.intentions.bulk.markPaidConfirmDesc"),confirmLabel:u("pages.intentions.bulk.markPaidConfirmLabel")})||await x(j,!0)},[h]=Qn(),[L,H]=b.useState(new Set),[w,S]=b.useState(new Set),[B,D]=b.useState(null),[q,f]=b.useState(null),[W,te]=b.useState(!1),[ie,ae]=b.useState(null),[De,ve]=b.useState(!1),[Ae,z]=b.useState(null),[ee,_e]=b.useState(!1),[ue,Le]=b.useState(!1),[rt,He]=b.useState(!1),[Lt,U]=b.useState(!1),[oe,le]=b.useState(null),[de,fe]=b.useState("current"),[xe,Se]=b.useState(!1),Pe=new Date().getFullYear(),ut=b.useMemo(()=>{const j=h.get("priest");if(j)return{...it,priestId:j};const _=h.get("filter");return _?_==="pending"?{...it,status:"pending"}:_==="paid"?{...it,status:"succeeded"}:_==="assigned"?{...it,priestId:"assigned"}:_==="unassigned"?{...it,priestId:"unassigned"}:it:it},[]),[V,zt]=b.useState(ut),[Ft,Y]=b.useState(""),Q=b.useRef(null),[X,se]=b.useState(!1);b.useEffect(()=>{if(!h.get("filter"))return;const j=setTimeout(()=>{var I;(I=Q.current)==null||I.scrollIntoView({behavior:"smooth",block:"start"}),se(!0)},250),_=setTimeout(()=>se(!1),2750);return()=>{clearTimeout(j),clearTimeout(_)}},[h]),b.useEffect(()=>{const j=setTimeout(()=>Y(V.search),300);return()=>clearTimeout(j)},[V.search]);const ne=b.useRef(!0),re=[Ft,V.email,V.status,V.type,V.priestId,V.location,V.year,V.dateFrom?V.dateFrom.toISOString():"",V.dateTo?V.dateTo.toISOString():"",V.amountMin,V.amountMax].join("|");b.useEffect(()=>{if(ne.current){ne.current=!1;return}requestAnimationFrame(()=>{var j;(j=Q.current)==null||j.scrollIntoView({behavior:"smooth",block:"start"})})},[re]);const[ge,ce]=b.useState({key:"created_at",direction:"desc"}),st=b.useMemo(()=>Array.from(new Set(a.map(j=>
17j.type).filter(Boolean))),[a]),at=b.useMemo(()=>Array.from(new Set(a.map(j=>j.status||"pending").filter(Boolean))),[a]),ns=b.useMemo(()=>{const j=new Set;return a.forEach(_=>{const I=new Date(_.created_at).getFullYear();Number.isNaN(I)||j.add(I)}),Array.from(j).sort((_,I)=>I-_)},[a]),gt=b.useMemo(()=>{const j=new Map(o.map(_=>[_.id,(_.name||"").toLowerCase()]));return a.filter(_=>{const I=Ft.trim().toLowerCase();let G=!I;if(!G){if([_.name,_.email,_.phone,_.content,_.mass_city,_.mass_location,_.mass_priest_name,_.mass_priest,j.get(_.priest_id),_.amount!=null?String(_.amount):"",_.amount!=null?`${_.amount} pln`:""].filter(Boolean).join(" � ").toLowerCase().includes(I))G=!0;else if(_.created_at){const rs=new Date(_.created_at),cs=String(rs.getDate()).padStart(2,"0"),ds=String(rs.getMonth()+1).padStart(2,"0"),ms=rs.getFullYear();[`${cs}.${ds}.${ms}`,`${ms}-${ds}-${cs}`,`${cs}/${ds}/${ms}`].some(Vn=>Vn.includes(I))&&(G=!0)}}const Z=V.status==="all"||(_.status||"pending")===V.status,me=V.type==="all"||_.type===V.type,Xe=V.priestId==="assigned"?!!_.priest_id:V.priestId==="unassigned"?!_.priest_id:V.priestId==="all"||_.priest_id===V.priestId,It=!V.location||_.mass_city&&_.mass_city.toLowerCase().includes(V.location.toLowerCase()),$n=!V.email||_.email&&_.email.toLowerCase().includes(V.email.toLowerCase()),os=new Date(_.created_at),Hn=!V.year||V.year==="all"||os.getFullYear().toString()===V.year,Yn=!V.dateFrom||os>=V.dateFrom,Wn=!V.dateTo||os<=V.dateTo,Un=wo(_.amount,V.amountMin,V.amountMax);return G&&Z&&me&&Xe&&It&&$n&&Hn&&Yn&&Wn&&Un})},[a,o,Ft,V]),ct=b.useMemo(()=>Ql(a,de),[a,de]),Ke=b.useMemo(()=>{const j=[...gt];return j.sort((_,I)=>{let G=_[ge.key],Z=I[ge.key];if(ge.key==="priest_name"){const me=o.find(It=>It.id===_.priest_id),Xe=o.find(It=>It.id===I.priest_id);G=(me==null?void 0:me.name)||"",Z=(Xe==null?void 0:Xe.name)||""}return ge.key==="created_at"&&(G=new Date(G),Z=new Date(Z)),ge.key==="amount"&&(G=Number(G)||0,Z=Number(Z)||0),typeof G=="string"&&typeof Z=="string"&&(G=G.toLowerCase(),Z=Z.toLowerCase()),G<Z?ge.direction==="asc"?-1:1:G>Z?ge.direction==="asc"?1:-1:0}),j},[gt,ge,o]),he=b.useMemo(()=>{let j=0;return V.search&&j++,V.email&&j++,V.status!=="all"&&j++,V.type!=="all"&&j++,V.priestId!=="all"&&j++,V.location&&j++,V.year&&V.year!=="all"&&j++,V.dateFrom&&j++,V.dateTo&&j++,(V.amountMin>0||V.amountMax<1e3)&&j++,j},[V]),Ye=b.useMemo(()=>{if(o.length===0)return null;let j=0,_=0;return o.forEach(I=>{I.active&&(j+=I.max_intentions||0)}),a.forEach(I=>{I.priest_id&&_++}),_>=j?e.jsxs(ei,{variant:"destructive",className:"mb-6 bg-red-50 border-red-200 text-red-900",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx(ti,{children:u("pages.intentions.capacity.warningTitle")}),e.jsx(si,{children:u("pages.intentions.capacity.warningDesc").replace("{current}",_).replace("{total}",j)})]}):null},[o,a,u]),Fe=j=>{ce(_=>({key:j,direction:_.key===j&&_.direction==="asc"?"desc":"asc"}))},jn=j=>{S(j?new Set(Ke.map(_=>_.id)):new Set)},wn=(j,_)=>{const I=new Set(w);_?I.add(j):I.delete(j),S(I)},Nn=async()=>{const j=await v(Array.from(w));!(j!=null&&j.cancelled)&&!(j!=null&&j.error)&&S(new Set)},kn=async j=>{w.size!==0&&(await x(Array.from(w),j),S(new Set))},vn=async j=>{if(w.size===0)return;const _=await T(Array.from(w),j);_!=null&&_.ok&&S(new Set)},Cn=async()=>{if(w.size===0)return;const j=await A(Array.from(w));j!=null&&j.ok&&S(new Set)},_n=async j=>{if(w.size===0||!j)return;const _=await P(Array.from(w),j);_!=null&&_.ok&&S(new Set)},qs=async j=>{const _=j.filter(G=>G.direction==="back");if(_.length===0)return!0;const I=[u("pages.intentions.table.stageBackBody").replace("{from}",u(`pages.intentions.flow.row.${_[0].from}`)).replace("{to}",u(`pages.intentions.flow.row.${_[0].target}`))];return _.some(G=>G.resendsNotice)&&I.push(u("pages.intentions.table.stageBackResend")),_.some(G=>G.clearsAcceptance)&&I.push(u("pages.intentions.table.stageBackAcceptance")),F({title:u("pages.intentions.table.stageBackTitle"),description:I.join(` 18 19`)})},Sn=async(j,_)=>{!(j!=null&&j.id)||!_||await P([j.id],_)},Gs=async(j,_)=>{if(_!=="toNotify"&&_!=="toConfirm")return;const I=j.filter(Z=>Z==null?void 0:Z.priest_id);I.length===0||!await F({title:u("pages.intentions.table.stageSendNowTitle"),description:u("pages.intentions.table.stageSendNowBody").replace("{n}",I.length).replace("{priests}",new Set(I.map(Z=>Z.priest_id)).size)})||await is(I.map(Z=>({intentionId:Z.id,priestId:Z.priest_id})))},Pn=async(j,_)=>{const I=gs(j,_);if(!I)return{ok:!0};if(!await qs([I]))return{ok:!1};f(j.id);let G;try{G=await R([j.id],_)}finally{f(null)}return G!=null&&G.ok&&await Gs([j],_),G},Mn=async j=>{if(w.size===0)return;const _=Array.from(w),I=new Map(a.map(me=>[me.id,me])),G=_.map(me=>I.get(me)).filter(me=>me&&gs(me,j));if(G.length===0||!await qs(G.map(me=>gs(me,j))))return;const Z=await R(_,j);Z!=null&&Z.ok&&(S(new Set),await Gs(G,j))},is=async j=>{if(j.length===0)return;const _=await Hs(j),I=Xt(_,u);I&&O(I),await r()},Dn=async j=>{try{const{data:_,error:I}=await Te.functions.invoke("notify-priest-assignment",{body:{mode:"recap",priestIds:[j],sinceDays:Ma}}),G=I||!(_!=null&&_.ok)?{ok:!1}:{ok:!0,..._},Z=Xt(G,u);Z&&O(Z),await r()}catch(_){Me.error("[AdminIntentionsPage] recap_threw",_==null?void 0:_.message),O({title:u("common.error"),variant:"destructive"})}},An=async j=>{if(!(j!=null&&j.priest_id))return;if(!j.priest_confirmed_at){await is([{intentionId:j.id,priestId:j.priest_id}]);return}await F({title:u("pages.intentions.table.priestRecapTitle"),description:u("pages.intentions.table.priestRecapBody")})&&await Dn(j.priest_id)},Tn=async()=>{const j=Array.from(w).map(I=>a.find(G=>
19G.id===I)).filter(I=>(I==null?void 0:I.priest_id)&&!I.priest_confirmed_at).map(I=>({intentionId:I.id,priestId:I.priest_id}));if(j.length===0){O({title:u("pages.intentions.toasts.notifyAlreadyDoneTitle")});return}await F({title:u("pages.intentions.flow.confirmTitle"),description:u("pages.intentions.flow.confirmBody").replace("{priests}",new Set(j.map(I=>I.priestId)).size).replace("{intentions}",j.length)})&&(await is(j),S(new Set))},ls=async(j,{force:_=!1}={})=>{if(j.length===0){O({title:u("pages.intentions.toasts.notifyAlreadyDoneTitle")});return}try{if(_){const{error:Z}=await Te.from("intentions").update({donor_confirmation_sent_at:null}).in("id",j);if(Z){Me.error("[AdminIntentionsPage] donor_rearm_failed",Z.message),O({title:u("common.error"),variant:"destructive"});return}}const{data:I,error:G}=await Te.functions.invoke("notify-donor-of-confirmation",{body:{intentionIds:j}});if(G||!(I!=null&&I.ok)){Me.error("[AdminIntentionsPage] donor_notify_failed",(G==null?void 0:G.message)||(I==null?void 0:I.error)),O({title:u("components.intentionAnalytics.donor.sendFailedTitle"),variant:"destructive"});return}O({title:u("components.intentionAnalytics.donor.sentTitle"),description:u("components.intentionAnalytics.donor.partialSentDesc").replace("{sent}",I.sent??0).replace("{failed}",I.failed??0),className:"bg-green-50 border-green-200 text-green-900"}),await r()}catch(I){Me.error("[AdminIntentionsPage] donor_notify_threw",I==null?void 0:I.message),O({title:u("common.error"),variant:"destructive"})}},Ln=j=>j.filter(_=>(_==null?void 0:_.priest_confirmed_at)&&_.email).map(_=>_.id),zn=async j=>{const _=Ln([j]);if(_.length===0){O({title:u("pages.intentions.table.donorNeedsAcceptance")});return}if(j.donor_confirmation_sent_at){if(!await F({title:u("pages.intentions.table.donorResendTitle"),description:u("pages.intentions.table.donorResendBody")}))return;await ls(_,{force:!0});return}await ls(_)},Fn=async()=>{const _=Array.from(w).map(me=>a.find(Xe=>Xe.id===me)).filter(Boolean).filter(me=>me.priest_confirmed_at&&me.email);if(_.length===0){O({title:u("pages.intentions.table.donorNeedsAcceptance")});return}const I=_.filter(me=>me.donor_confirmation_sent_at).length,G=[u("pages.intentions.table.donorBulkBody").replace("{n}",_.length)];I>0&&G.push(u("pages.intentions.table.donorBulkResendNote").replace("{r}",I)),await F({title:u("pages.intentions.table.stageNotifyDonor"),description:G.join(` 20 21`)})&&(await ls(_.map(me=>me.id),{force:I>0}),S(new Set))},Ks=async(j,_)=>{if(!(j!=null&&j.id)||!_||_===j.status)return{ok:!0};D(j.id);try{return await T([j.id],_)}finally{D(null)}},Xs=j=>{le(j),He(!0)},In=j=>{ae(j),te(!0)},Zs=()=>{te(!1),ae(null)},En=(j,_)=>{_.stopPropagation();const I=new Set(L);I.has(j)?I.delete(j):I.add(j),H(I)},Qs=()=>{zt(it)},Rn=b.useMemo(()=>a.filter(j=>!j.priest_id&&(j.status||"pending")!=="awaiting_priest").length,[a]),Bn=async()=>{const j=await N();j&&(z(j),_e(!0))},On=async()=>{const j=Ke.map(Z=>{var me;return{[u("common.date")]:be(new Date(Z.created_at),"dd.MM.yyyy HH:mm"),[u("pages.intentions.export.colName")]:Z.name,[u("common.email")]:Z.email,[u("common.phone")]:Z.phone||"",[u("pages.intentions.export.colType")]:$e(Z.type),[u("pages.intentions.export.colContent")]:Z.content||"",[u("common.amount")]:Z.amount,[u("pages.intentions.export.colCurrency")]:Z.currency,[u("common.status")]:Z.status,[u("pages.intentions.export.colPriest")]:((me=o.find(Xe=>Xe.id===Z.priest_id))==null?void 0:me.name)||u("pages.intentions.export.none"),[u("pages.intentions.export.colAssignedDate")]:Z.assigned_date?be(new Date(Z.assigned_date),"dd.MM.yyyy"):"-"}}),_=await At(()=>import("./xlsx-6ed613d4.js"),[]),I=_.utils.json_to_sheet(j),G=_.utils.book_new();_.utils.book_append_sheet(G,I,u("pages.intentions.export.sheetName")),_.writeFile(G,`${u("pages.intentions.export.filePrefix")}_${be(new Date,"yyyy-MM-dd")}.xlsx`)};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Jn,{children:e.jsx("title",{children:`${u("pages.intentions.title")} | Admin Panel`})}),e.jsx(ai,{icon:ea,frontendHref:"/intencje",title:u("pages.intentions.title"),subtitle:u(n?"pages.intentions.managerSubtitle":"pages.intentions.subtitle"),actions:e.jsx(Rl,{loading:t,assigning:m,hasPriests:o.length>0,onAutoAssign:y,onRedistribute:n?void 0:()=>U(!0),onAddMock:n?void 0:g,onRefresh:r,onExport:On,onOpenAnalysisReport:n?void 0:()=>ve(!0)})}),Ye,e.jsx(xo,{open:De,onOpenChange:ve,intentions:gt,allIntentions:a,priests:o}),e.jsx(ho,{open:ee,onOpenChange:_e,summary:Ae,onNotified:r}),e.jsx(yo,{open:ue,onOpenChange:Le,priests:i,onSubmit:d}),e.jsx(El,{open:Lt,onOpenChange:U,intentions:a,priests:i,onSubmit:k}),e.jsx(Il,{open:rt,onOpenChange:j=>{He(j),j||le(null)},seed:oe,priests:c,onSubmit:p}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(K,{size:"sm",variant:"outline",onClick:()=>Le(!0),className:"bg-emerald-50 text-emerald-700 hover:bg-emerald-100 border-emerald-200",children:[e.jsx(ea,{className:"w-4 h-4 mr-2"}),u("pages.intentions.addDantis")]})}),e.jsx(Tl,{intentions:a,priests:o,onAutoAssign:y,onConfirmPriests:l,onRefresh:r,assigning:m}),!n&&e.jsxs(e.Fragment,{children:[e.jsx(Jl,{intentions:ct,yearScope:de,onYearScopeChange:fe,currentYear:Pe,onAddDantis:()=>Le(!0),onAddManual:()=>{le(null),He(!0)},collapsed:xe,onToggleCollapsed:()=>Se(j=>!j)}),!xe&&e.jsxs(e.Fragment,{children:[e.jsx(Kl,{intentions:a}),e.jsx(kl,{intentions:ct,priests:o,onMarkPriestPaid:M}),e.jsx(Vl,{intentions:ct})]})]}),e.jsx(Ul,{ref:Q,highlight:X,filters:V,setFilters:zt,availableStatuses:at,availableTypes:st,availableYears:ns,priests:c,activeFiltersCount:he,onClear:Qs,onSmartAssign:Bn,smartAssigning:m,unassignedCount:Rn,autoCollapseKey:re,actions:e.jsx(lo,{selectedCount:w.size,priests:o,assignablePriests:i,onBulkMarkPaid:n?void 0:kn,onBulkSetStatus:vn,onBulkSetStage:Mn,onBulkNotifyPriests:Tn,onBulkNotifyDonors:Fn,onBulkAssignPriest:_n,onBulkUnassignPriest:Cn,onBulkDelete:n?void 0:Nn})}),e.jsx(no,{items:Ke,totalResults:Ke.length,priests:o,loading:t,sortConfig:ge,onSort:Fe,selectedIds:w,onSelectAll:jn,onSelectRow:wn,exp
21andedRows:L,onToggleRow:En,onRowClick:In,onDuplicate:n?void 0:Xs,activeFiltersCount:he,onClearFilters:Qs,onTogglePriestPaid:n?void 0:j=>x(j.id,!j.priest_paid_at),onSetStatus:Ks,savingStatusId:B,onSetStage:Pn,savingStageId:q,onNotifyPriest:An,onNotifyDonor:zn,onAssignPriest:Sn,assignablePriests:i}),e.jsx(xl,{isOpen:W,onClose:Zs,intention:ie,priests:i,onSuccess:r,onSetStatus:j=>Ks(ie,j),onDuplicate:n?void 0:j=>{Zs(),Xs(j)}})]})}export{jo as AMOUNT_SLIDER_MAX,Or as default,wo as matchesAmountRange};
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.