PageSourceSearch

https://tsofit.org.il/assets/CouncilBudgetPage-DoV9GtdI.js

js tsofit.org.il collected 2026-10-02 14:24:17 UTC 82,894 bytes, 65 lines download raw bytes

1import{r as n,d as S,j as e,b as Z,T as X,l as se,c5 as ft,m as ae,n as le,o as ne,p as re,z as k,at as Ue,a9 as gt,w as Ge,Z as Ee,C as me,aP as jt,aH as vt,P as de,c1 as Nt,aW as xe,ac as yt,c3 as wt,aL as _t,y as He,c7 as kt,aC as Ct}from"./index-BH8Hq4fF.js";import{K as St}from"./KibbutzModuleGuard-BrSTzYkw.js";import{P as Bt}from"./PageTitleMenu-CMXtRh6s.js";import{i as _,P as Ce,p as qe,a as lt,C as Ve,s as fe,u as ce,b as We,S as $t,B as Oe}from"./SupplierManager-DWGu-E18.js";import{P as Mt}from"./pen-line-BUNE0323.js";import{P as nt}from"./printer-EDa6zP4x.js";import{E as zt}from"./eraser-CLQXmIV-.js";import{B as Tt}from"./banknote-D2Q77xlP.js";import{F as rt}from"./file-chart-column-DObFjTy-.js";import{T as Qe}from"./truck-Btvrvfzs.js";import{L as Pt}from"./landmark-CnHOESNE.js";import{C as Be}from"./chevron-left-DaNP-hnR.js";import{P as it}from"./pencil-DlA_FTEn.js";import{F as Rt}from"./file-plus-2-DyRs57bM.js";import{C as ot}from"./clipboard-paste-9hEC__C5.js";import{G as At}from"./grip-vertical-Bettc5f-.js";import"./refresh-cw-kjmzcQOe.js";import"./useActionVisibility-oACH4aDh.js";import"./money-CmD9E_V-.js";import"./hash-B7li3sKZ.js";import"./save-B5tADMHo.js";const q=t=>String(t??"").replace(/[&<>"]/g,s=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[s]),Fe=t=>t?new Date(t).toLocaleString("he-IL",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"",Dt=t=>t?new Date(t).toLocaleDateString("he-IL"):"";function Lt({charge:t,councilName:s,settlementName:l,basketTitle:r,approvals:o=[],payments:m=[]}){var g;const h=u=>u.map(x=>`<tr><td>${q(x[0])}</td><td>${q(x[1])}</td></tr>`).join(""),b=m.reduce((u,x)=>u+(Number(x.amount)||0),0),w=[...o].sort((u,x)=>String(u.signed_at||"").localeCompare(String(x.signed_at||""))).map(u=>`<tr>
2      <td>${q(u.role_title||"אישור")}</td>
3      <td>${q(u.approver_name||"")}</td>
4      <td>${q({approved:"אישור",override_approved:"אישור חריגה",returned:"החזרה",rejected:"דחייה"}[u.action]||u.action)}</td>
5      <td>${q(Fe(u.signed_at))}</td>
6      <td>${u.signature_data?`<img src="${q(u.signature_data)}" style="height:34px"/>`:u.signature_hash?"נחתם דיגיטלית":""}</td>
7      <td>${q(u.note||"")}</td>
8    </tr>`).join(""),c=m.map(u=>`<tr>
9      <td>${q(_(u.amount))}</td>
10      <td>${q(Dt(u.credit_date))}</td>
11      <td>${q(u.reference||"")}</td>
12      <td>${q(u.method||"")}</td>
13      <td>${q(u.paid_by_name||"")}</td>
14    </tr>`).join("");return`<!doctype html><html lang="he" dir="rtl"><head><meta charset="utf-8">
15<title>פרוטוקול בקשת חיוב ${q(t.request_no||((g=t.id)==null?void 0:g.slice(0,8))||"")}</title>
16<style>
17  *{box-sizing:border-box;font-family:"Segoe UI",Arial,sans-serif}
18  body{margin:32px;color:#0f172a}
19  h1{font-size:20px;margin:0 0 2px} .sub{color:#64748b;font-size:13px;margin-bottom:18px}
20  h2{font-size:14px;margin:22px 0 8px;color:#1e3a8a;border-bottom:2px solid #e6ebf1;padding-bottom:4px}
21  table{width:100%;border-collapse:collapse;font-size:13px}
22  th,td{border:1px solid #e6ebf1;padding:7px 9px;text-align:right;vertical-align:top}
23  th{background:#f4f7fb;color:#475569;font-size:12px}
24  .kv td:first-child{color:#64748b;width:34%}
25  .tot{font-weight:800}
26  .foot{margin-top:26px;color:#94a3b8;font-size:11px;text-align:center}
27  @media print{body{margin:12mm}}
28</style></head><body>
29  <h1>פרוטוקול בקשת חיוב מסל תקציב</h1>
30  <div class="sub">${q(s)} · יישוב ${q(l)} · סל ${q(r)}</div>
31
32  <h2>פרטי הבקשה</h2>
33  <table class="kv">${h([["מספר בקשה",t.request_no||t.id],["מטרת החיוב",t.purpose],["ספק / מוטב",[t.vendor_name,t.vendor_taxid].filter(Boolean).join(" · ")],["סכום",_(t.amount)],["הוגש",Fe(t.submitted_at||t.created_date)],["סטטוס",{approved:"אושר — ממתין לתשלום",partially_paid:"שולם חלקית",paid:"שולם",rejected:"נדחה",cancelled:"בוטל"}[t.status]||t.status],["הערות",t.notes]])}</table>
34
35  <h2>שרשרת אישורים חתומה</h2>
36  ${w?`<table><thead><tr><th>תפקיד</th><th>מאשר</th><th>פעולה</th><th>מועד</th><th>חתימה</th><th>הערה</th></tr></thead><tbody>${w}</tbody></table>`:'<div class="sub">טרם נרשמו אישורים.</div>'}
37
38  <h2>תשלומים</h2>
39  ${c?`<table><thead><tr><th>
39סכום</th><th>מועד זיכוי</th><th>אסמכתא</th><th>אמצעי</th><th>שולם ע"י</th></tr></thead><tbody>${c}
40    <tr class="tot"><td>${q(_(b))}</td><td colspan="4">סה"כ שולם${t.amount?` מתוך ${q(_(t.amount))}`:""}</td></tr></tbody></table>`:'<div class="sub">טרם נרשמו תשלומים.</div>'}
41
42  <div class="foot">הופק ${q(Fe(new Date().toISOString()))} · מסמך זה מתעד את מסלול האישור והתשלום הדיגיטלי</div>
43</body></html>`}function Ft(t){const s=Lt(t),l=window.open("","_blank");return l?(l.document.write(s),l.document.close(),l.focus(),setTimeout(()=>{try{l.print()}catch{}},350),!0):!1}const Et={slate:"bg-slate-100 text-slate-600",blue:"bg-blue-50 text-blue-700",amber:"bg-amber-50 text-amber-700",emerald:"bg-emerald-50 text-emerald-700",rose:"bg-rose-50 text-rose-700"},Xe=t=>t?new Date(t).toLocaleString("he-IL",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"}):"";function Ze({status:t}){const s=Ve[t]||Ve.draft;return e.jsx("span",{className:`text-[0.6875rem] font-bold rounded-full px-2.5 py-1 ${Et[s.tone]}`,children:s.label})}function qt({onChange:t}){const s=n.useRef(null),l=n.useRef(!1),r=n.useRef(!1);n.useEffect(()=>{const c=s.current;if(!c)return;const g=c.getContext("2d");g.lineWidth=2.2,g.lineCap="round",g.strokeStyle="#1e3a8a"},[]);const o=c=>{var p;const u=s.current.getBoundingClientRect(),x=(p=c.touches)==null?void 0:p[0];return{x:(x?x.clientX:c.clientX)-u.left,y:(x?x.clientY:c.clientY)-u.top}},m=c=>{c.preventDefault(),l.current=!0;const g=s.current.getContext("2d"),{x:u,y:x}=o(c);g.beginPath(),g.moveTo(u,x)},h=c=>{if(!l.current)return;c.preventDefault();const g=s.current.getContext("2d"),{x:u,y:x}=o(c);g.lineTo(u,x),g.stroke(),r.current=!0},b=()=>{l.current&&(l.current=!1,r.current&&t(s.current.toDataURL("image/png")))},w=()=>{const c=s.current;c.getContext("2d").clearRect(0,0,c.width,c.height),r.current=!1,t("")};return e.jsx("div",{children:e.jsxs("div",{className:"relative rounded-xl border-[1.5px] border-dashed border-slate-300 bg-white overflow-hidden",style:{height:96},children:[e.jsx("canvas",{ref:s,width:520,height:96,className:"w-full h-full touch-none cursor-crosshair",onMouseDown:m,onMouseMove:h,onMouseUp:b,onMouseLeave:b,onTouchStart:m,onTouchMove:h,onTouchEnd:b}),e.jsx("span",{className:"absolute inset-0 grid place-items-center text-slate-300 text-sm pointer-events-none select-none italic",style:{zIndex:-0},children:"חתמו כאן"}),e.jsxs("button",{onClick:w,type:"button",className:"absolute top-1.5 left-1.5 inline-flex items-center gap-1 text-[0.6875rem] text-slate-400 hover:text-rose-500 bg-white/80 rounded px-1.5 py-0.5",children:[e.jsx(zt,{className:"w-3 h-3"})," ניקוי"]})]})})}function Ot({councilId:t,councilName:s,settlements:l,onDataChanged:r}){const[o,m]=n.useState([]),[h,b]=n.useState([]),[w,c]=n.useState([]),[g,u]=n.useState([]),[x,p]=n.useState([]),[a,i]=n.useState([]),[B,f]=n.useState([]),[y,N]=n.useState([]),[A,j]=n.useState(!0),[z,R]=n.useState(null),[L,D]=n.useState(null),[T,H]=n.useState("pending"),E=n.useCallback(v=>{var M;return((M=l==null?void 0:l.find(O=>O.id===v))==null?void 0:M.name)||"יישוב"},[l]),I=n.useCallback(async()=>{j(!0);try{const[v,M,O,ee,ye,Me,we,ze]=await Promise.all([S.entities.MoatzaBudgetCharge.filter({council_id:t},"-created_date",3e3).catch(()=>[]),S.entities.MoatzaBudgetChargeDoc.filter({council_id:t},"-created_date",5e3).catch(()=>[]),S.entities.MoatzaBudgetApproval.filter({council_id:t},"step_order",5e3).catch(()=>[]),S.entities.MoatzaBudgetBasket.filter({kibbutz_id:t},"order",500).catch(()=>[]),S.entities.MoatzaBudgetStep.filter({kibbutz_id:t},"step_order",2e3).catch(()=>[]),S.entities.MoatzaBudgetRole.filter({kibbutz_id:t},"order",200).catch(()=>[]),S.entities.MoatzaBudgetAllocation.filter({council_id:t},"-created_date",2e3).catch(()=>[]),S.entities.MoatzaBudgetPayment.filter({council_id:t},"-created_date",5e3).catch(()=>[])]);m(v||[]),b(M||[]),c(O||[]),u(ee||[]),p(ye||[]),i(Me||[]),f(we||[]),N(ze||[])}finally{j(!1)}},[t]);n.useEffect(()=>{I()},[I]);const J=n.useCallback(v=>{var M;return((M=g.find(O=>O.id===v))==null?void 0:M.title)||"סל"},[g]),P=n.useCallback(v=>{var M;return((M=a.find(O=>O.id===v))==null?void 0:M.title)||"תפקיד"},[a]),G=n.useCallback(v=>x.filter(M=>M.basket_id===v).sort((M,O)=>(M.step_order||0)-(O.step_order||0)),[x]),Q=n.useMemo(()=>o.filter(v=>v.source!=="manager_expense"),[o]),je=n.useMemo(()=>Q.filter(v=>Ce.includes(v.status)),[Q]),ve=n.useMemo(()=>Q.filter(v=>!Ce.includes(v.status)&&v.status!=="draft"),[Q]),ie=T==="pending"?je:ve;async function oe(v,M,O,ee){await S.functions.invoke("moatzaBudgetAction",{charge_id:v.id,action:M,note:O,signature_data:ee}),k.success(M==="approve"?"הבקשה אושרה ונחתמה":M==="return"?"הבקשה הוחזרה לתיקון":"הבקשה נדחתה"),await I(),r==null||r()}async function De(v,M){await S.functions.invoke("moatzaBudgetPayment",{charge_id:v.id,...M}),k.success("התשלום נרשם"),await I(),r==null||r()}async function Ne(v){await S.functions.invoke("moatzaBudgetPayment",{action:"delete_payment",payment_id:v}),k.success("התשלום הוסר"),await I(),r==null||r()}async function Le(v,M){await S.functions.invoke("moatzaBudgetAction",{charge_id:v.id,action:"cancel",note:M}),k.success("הבקשה בוטלה"),D(null),R(null),await I(),r==null||r()}const U=n.useMemo(()=>o.find(v=>v.id===z)||null,[o,z]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{active:T==="pending",onClick:()=>H("pending"),label:`ממתינות לאישור${je.length?` (${je.length})`:""}`}),e.jsx(Je,{active:T==="decided",onClick:()=>H("decided"),label:"היסטוריה"})]}),A?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(Z,{className:"w-7 h-7 animate-spin text-slate-400"})}):ie.length===0?e.jsx("div",{className:"card-float p-10 text-center text-sm text-slate-400",children:T==="pending"?"אין בקשות חיוב הממתינות לאישור":"אין בקשות שטופלו עדיין"}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 items-stretch",children:ie.map(v=>
43{const M=G(v.basket_id),O=Math.floor(Number(v.current_step)||0),ee=Ce.includes(v.status)&&M[O]?P(M[O].council_role_id):null,ye=["submitted","in_review","returned","approved"].includes(v.status)&&qe(v.id,y)===0;return e.jsxs("div",{className:"card-float p-4 flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Ze,{status:v.status}),e.jsxs("div",{className:"flex items-center gap-1",children:[v.is_override&&e.jsx("span",{className:"text-[0.625rem] font-bold rounded-full px-2 py-0.5 bg-rose-50 text-rose-600",children:"חריגה"}),ye&&e.jsx("button",{onClick:()=>D(v),title:"ביטול הבקשה",className:"w-7 h-7 rounded-lg hover:bg-rose-50 text-slate-300 hover:text-rose-500 flex items-center justify-center flex-none",children:e.jsx(X,{className:"w-4 h-4"})})]})]}),e.jsxs("button",{onClick:()=>R(v.id),className:"text-right mt-2 flex-1 flex flex-col",children:[e.jsx("h3",{className:"text-sm font-extrabold text-slate-900 line-clamp-2 leading-snug",children:v.purpose||"בקשת חיוב"}),e.jsxs("div",{className:"text-xs text-slate-500 mt-1 flex items-center gap-1 truncate",children:[e.jsx(se,{className:"w-3.5 h-3.5 flex-none"})," ",e.jsxs("span",{className:"truncate",children:[E(v.settlement_id)," · ",J(v.basket_id)]})]}),ee&&e.jsxs("div",{className:"text-[0.6875rem] text-amber-600 mt-1 truncate",children:["ממתין ל",ee]}),e.jsxs("div",{className:"mt-auto pt-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-base font-extrabold text-slate-900 tabular-nums",children:_(v.amount)}),e.jsxs("span",{className:"text-[0.6875rem] text-primary font-bold inline-flex items-center gap-0.5",children:["פתיחה ",e.jsx(ft,{className:"w-3.5 h-3.5 rotate-180"})]})]})]})]},v.id)})}),U&&e.jsx(ae,{open:!0,onOpenChange:v=>!v&&R(null),children:e.jsxs(le,{dir:"rtl",className:"max-w-4xl max-h-[92vh] overflow-y-auto p-0",children:[e.jsx(ne,{className:"p-4 pb-0",children:e.jsxs(re,{className:"flex items-center gap-2 text-right",children:[e.jsx(Ze,{status:U.status})," ",e.jsx("span",{className:"truncate",children:U.purpose||"בקשת חיוב"})]})}),e.jsx(Ut,{charge:U,chain:G(U.basket_id),chargeApprovals:w.filter(v=>v.request_id===U.id),roleTitle:P,docs:h.filter(v=>v.request_id===U.id),balance:(()=>{const v=B.find(M=>M.id===U.allocation_id);return v?lt(v,o,y):null})(),payments:y.filter(v=>v.request_id===U.id),settlementName:E(U.settlement_id),councilName:s,basketTitle:J(U.basket_id),canCancel:["submitted","in_review","returned","approved"].includes(U.status)&&qe(U.id,y)===0,onAct:oe,onPay:De,onDeletePayment:Ne,onCancel:()=>D(U)})]})}),L&&e.jsx(It,{charge:L,settlementName:E(L.settlement_id),basketTitle:J(L.basket_id),onClose:()=>D(null),onConfirm:Le})]})}function It({charge:t,settlementName:s,basketTitle:l,onClose:r,onConfirm:o}){const[m,h]=n.useState(""),[b,w]=n.useState(!1);async function c(){if(!m.trim()){k.error("נא לציין סיבת ביטול");return}w(!0);try{await o(t,m.trim())}catch(g){k.error((g==null?void 0:g.message)||"שגיאה בביטול")}finally{w(!1)}}return e.jsx(ae,{open:!0,onOpenChange:g=>!g&&r(),children:e.jsxs(le,{dir:"rtl",className:"max-w-md",children:[e.jsx(ne,{children:e.jsxs(re,{className:"flex items-center gap-2 text-rose-600",children:[e.jsx(Ue,{className:"w-5 h-5"})," ביטול בקשת החיוב"]})}),e.jsxs("p",{className:"text-sm text-slate-600",children:["פעולה זו תבטל את הבקשה ",e.jsxs("b",{children:['"',t.purpose||"בקשת חיוב",'"']})," של ",s," · ",l," (",_(t.amount),"). הבקשה תוסר מרשימת הממתינות והתקציב השמור ישוחרר. הפעולה מתועדת עם הסיבה."]}),e.jsxs("label",{className:"block mt-3",children:[e.jsx("span",{className:"text-xs font-bold text-slate-500 mb-1 block",children:"סיבת הביטול (חובה)"}),e.jsx("textarea",{value:m,onChange:g=>h(g.target.value),rows:3,autoFocus:!0,placeholder:"לדוגמה: כפילות · הוגש בטעות · הסכום שגוי…",className:"w-full border border-slate-200 rounded-xl px-3 py-2 text-sm bg-slate-50/60 focus:bg-white focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/15 resize-none"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-4",children:[e.jsx("button",{onClick:r,className:"h-10 px-4 roun
43ded-full bg-white border border-slate-200 text-slate-700 text-sm font-semibold hover:bg-slate-50",children:"חזרה"}),e.jsxs("button",{onClick:c,disabled:b,className:"h-10 px-5 rounded-full bg-rose-600 text-white text-sm font-bold inline-flex items-center gap-1.5 hover:bg-rose-700 disabled:opacity-50",children:[b?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(X,{className:"w-4 h-4"})," ביטול הבקשה"]})]})]})})}function Je({active:t,onClick:s,label:l}){return e.jsx("button",{onClick:s,className:`h-9 px-4 rounded-full text-sm font-bold transition ${t?"bg-primary text-white":"bg-white border border-slate-200 text-slate-600 hover:border-slate-300"}`,children:l})}function Ut({charge:t,chain:s,chargeApprovals:l,roleTitle:r,docs:o,balance:m,payments:h,settlementName:b,councilName:w,basketTitle:c,canCancel:g,onAct:u,onPay:x,onDeletePayment:p,onCancel:a}){const[i,B]=n.useState(""),[f,y]=n.useState(""),[N,A]=n.useState(null),j=Math.floor(Number(t.current_step)||0),z=["submitted","in_review","returned"].includes(t.status),R=["approved","partially_paid"].includes(t.status),L=n.useMemo(()=>{const T={};return l.forEach(H=>{T[Math.round(Number(H.step_order)||0)]=H}),T},[l]);async function D(T){if(T==="approve"&&!f){k.error("נדרשת חתימה דיגיטלית לאישור");return}if(T==="reject"&&!i.trim()){k.error("נדרשת סיבת דחייה");return}A(T);try{await u(t,T,i,f)}catch(H){k.error((H==null?void 0:H.message)||"שגיאה בביצוע הפעולה")}finally{A(null)}}return e.jsxs("div",{className:"border-t border-slate-100 bg-slate-50/50 p-4",children:[t.is_override&&m&&e.jsxs("div",{className:"mb-3 rounded-xl bg-rose-50 border border-rose-100 text-rose-700 px-3 py-2 text-[0.8125rem] flex items-start gap-1.5",children:[e.jsx(Ue,{className:"w-4 h-4 flex-none mt-0.5"}),e.jsxs("span",{children:[e.jsx("b",{children:"חריגה מיתרת הסל:"})," יתרה זמינה ",_(m.available)," · הבקשה ",_(t.amount),". נדרש אישור חריגה של בעל תפקיד מורשה."]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-4",children:[e.jsx("h4",{className:"text-sm font-extrabold text-slate-800 mb-2",children:"פרטי הבקשה"}),e.jsx(he,{k:"יישוב מבקש",v:b}),e.jsx(he,{k:"מטרה",v:t.purpose}),e.jsx(he,{k:"ספק / מוטב",v:[t.vendor_name,t.vendor_taxid].filter(Boolean).join(" · ")}),e.jsx(he,{k:"סכום",v:_(t.amount),strong:!0}),t.notes&&e.jsx(he,{k:"הערות",v:t.notes}),e.jsx(he,{k:"הוגש",v:Xe(t.submitted_at||t.created_date)}),e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"text-xs font-bold text-slate-500 mb-1.5",children:"מסמכים מצורפים"}),o.length===0?e.jsx("div",{className:"text-xs text-slate-400",children:"אין מסמכים"}):e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map(T=>e.jsxs("a",{href:T.file_url,target:"_blank",rel:"noopener noreferrer",title:[T.file_name,T.description].filter(Boolean).join(" — "),className:"inline-flex items-center gap-1.5 text-[0.75rem] bg-slate-50 border border-slate-200 rounded-lg px-2 py-1 hover:bg-white",children:[e.jsx(gt,{className:"w-3.5 h-3.5 text-rose-500"})," ",e.jsx("span",{className:"truncate max-w-[180px]",children:T.title||T.file_name||"מסמך"})]},T.id))})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 p-4",children:[e.jsxs("h4",{className:"text-sm font-extrabold text-slate-800 mb-2 flex items-center gap-1.5",children:[e.jsx(Ge,{className:"w-4 h-4 text-violet-500"})," שרשרת אישורים"]}),e.jsxs("div",{className:"space-y-0 mb-3",children:[s.length===0&&e.jsx("div",{className:"text-xs text-amber-600",children:"לא הוגדרה שרשרת אישורים לסל זה."}),s.map((T,H)=>{const E=L[Math.round(Number(T.step_order)||0)],I=z&&H===j,J=E&&E.action==="rejected";return e.jsxs("div",{className:"flex gap-3 py-1.5",children:[e.jsx("span",{className:`w-7 h-7 rounded-full grid place-items-center text-xs font-extrabold flex-none ${J?"bg-rose-100 text-rose-600":E?"bg-emerald-100 text-emerald-700 border-2 border-emerald-500":I?"bg-blue-600 text-white":"bg-slate-100 text-slate-400"}`,children:E?J?e.jsx(Ee,{className:"w-3.5 h-3.5"}):e.jsx(me,{className:"w-3.5 h-3.5"}):H+1}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-bold text-slate-800",children:[r(T.council_role_id),T.is_override_step?" · אישור חריגה":""]}),E?e.jsxs("div",{className:"text-xs text-slate-500",children:[E.approver_name," · ",Xe(E.signed_at),E.note?` · "${E.note}"`:"",E.signature_data&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[0.6875rem] text-emerald-700 mr-1",children:[e.jsx(Mt,{className:"w-3 h-3"})," נחתם"]})]}):I?e.jsx("div",{className:"text-xs text-blue-600 font-semibold",children:"ממתין לחתימתך"}):e.jsx("div",{className:"text-xs text-slate-400",children:"ממתין"})]})]},T.id)})]}),z?e.jsxs("div",{className:"border-t border-slate-100 pt-3",children:[e.jsx("div",{className:"text-xs font-bold text-slate-500 mb-1.5",children:"חתימה דיגיטלית"}),e.jsx(qt,{onChange:y}),e.jsx("textarea",{value:i,onChange:T=>B(T.target.value),rows:2,placeholder:"הערה לאישור / סיבת החזרה או דחייה…",className:"w-full mt-2 border border-slate-200 rounded-xl px-3 py-2 text-sm bg-slate-50/60 focus:bg-white focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/15 resize-none"}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs("button",{onClick:()=>D("approve"),disabled:!!N,className:"flex-1 h-10 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center justify-center gap-1.5 hover:bg-emerald-700 disabled:opacity-50",children:[N==="approve"?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(me,{className:"w-4 h-4"})," מאשר וחותם"]}),e.jsxs("button",{onClick:()=>
43D("return"),disabled:!!N,className:"h-10 px-4 rounded-full bg-white border border-slate-200 text-amber-600 text-sm font-semibold inline-flex items-center gap-1.5 hover:bg-amber-50 disabled:opacity-50",children:[N==="return"?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(jt,{className:"w-4 h-4"})," החזרה"]}),e.jsxs("button",{onClick:()=>D("reject"),disabled:!!N,className:"h-10 px-4 rounded-full bg-white border border-slate-200 text-rose-600 text-sm font-semibold inline-flex items-center gap-1.5 hover:bg-rose-50 disabled:opacity-50",children:[N==="reject"?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(Ee,{className:"w-4 h-4"})," דחייה"]})]})]}):e.jsxs("div",{className:"border-t border-slate-100 pt-3 space-y-3",children:[R||t.status==="paid"?e.jsx(Gt,{charge:t,payments:h,canPay:R,onPay:x,onDeletePayment:p}):e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(vt,{className:"w-4 h-4"})," הבקשה אינה בשלב אישור."]}),e.jsxs("button",{onClick:()=>Ft({charge:t,councilName:w,settlementName:b,basketTitle:c,approvals:l,payments:h}),className:"inline-flex items-center gap-1.5 text-sm font-bold text-primary hover:underline",children:[e.jsx(nt,{className:"w-4 h-4"})," הפקת פרוטוקול"]})]})]})]}),g&&e.jsx("div",{className:"mt-3 flex justify-end",children:e.jsxs("button",{onClick:a,className:"inline-flex items-center gap-1.5 text-sm font-bold text-rose-600 hover:bg-rose-50 rounded-full px-3 h-9",children:[e.jsx(X,{className:"w-4 h-4"})," ביטול הבקשה"]})})]})}function Gt({charge:t,payments:s,canPay:l,onPay:r,onDeletePayment:o}){const m=qe(t.id,s),h=Math.max(Number(t.amount||0)-m,0),[b,w]=n.useState({amount:"",credit_date:"",reference:"",method:"העברה בנקאית"}),[c,g]=n.useState(!1),[u,x]=n.useState(null),p=f=>y=>w(N=>({...N,[f]:y.target.value})),a="w-full border border-slate-200 rounded-xl px-3 py-2 text-sm bg-slate-50/60 focus:bg-white focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/15";async function i(){const f=Number(b.amount);if(!(f>0)){k.error("הזינו סכום תשלום");return}if(f>h+1e-6){k.error(`הסכום חורג מהיתרה לתשלום (${_(h)})`);return}g(!0);try{await r(t,{amount:f,credit_date:b.credit_date||null,reference:b.reference,method:b.method}),w({amount:"",credit_date:"",reference:"",method:"העברה בנקאית"})}catch(y){k.error((y==null?void 0:y.message)||"שגיאה ברישום התשלום")}finally{g(!1)}}async function B(f){x(f);try{await o(f)}catch(y){k.error((y==null?void 0:y.message)||"שגיאה")}finally{x(null)}}return e.jsxs("div",{className:"rounded-2xl border border-slate-100 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("h4",{className:"text-sm font-extrabold text-slate-800 flex items-center gap-1.5",children:[e.jsx(Tt,{className:"w-4 h-4 text-emerald-600"})," תשלום וקיזוז מהסל"]}),e.jsxs("div",{className:"text-xs text-slate-500",children:["שולם ",_(m)," / ",_(t.amount)," · נותר ",e.jsx("b",{className:h>0?"text-amber-600":"text-emerald-600",children:_(h)})]})]}),s.length>0&&e.jsx("div",{className:"space-y-1.5 mb-3",children:s.map(f=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm bg-slate-50 rounded-xl px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("b",{className:"tabular-nums",children:_(f.amount)}),e.jsxs("span",{className:"text-xs text-slate-500 mr-2",children:[f.credit_date?`זוכה ${new Date(f.credit_date).toLocaleDateString("he-IL")}`:"",f.reference?` · אסמכתא ${f.reference}`:"",f.paid_by_name?` · ${f.paid_by_name}`:""]})]}),e.jsx("button",{onClick:()=>B(f.id),disabled:u===f.id,className:"w-7 h-7 rounded-lg hover:bg-rose-50 text-rose-500 flex items-center justify-center flex-none",children:u===f.id?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(X,{className:"w-4 h-4"})})]},f.id))}),l?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 items-end",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-[0.6875rem] font-bold text-slate-500 mb-1",children:"סכום (₪)"}),e.jsx("input",{inputMode:"numeric",value:b.amount,onChange:p("amount"),className:a,placeholder:String(h)})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-[0.6875rem] font-bold text-slate-500 mb-1",children:"מועד זיכוי"}),e.jsx("input",{type:"date",value:b.credit_date,onChange:p("credit_date"),className:a})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-[0.6875rem] font-bold text-slate-500 mb-1",children:"אסמכתא"}),e.jsx("input",{value:b.reference,onChange:p("reference"),className:a})]}
43),e.jsxs("button",{onClick:i,disabled:c,className:"h-10 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center justify-center gap-1.5 hover:bg-emerald-700 disabled:opacity-50",children:[c?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(de,{className:"w-4 h-4"})," רישום תשלום"]})]}):e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-700",children:[e.jsx(me,{className:"w-4 h-4"})," שולם במלואו — היתרה קוזזה מהסל."]})]})}function he({k:t,v:s,strong:l}){return s==null||s===""?null:e.jsxs("div",{className:"flex items-start justify-between gap-3 py-1.5 border-b border-dashed border-slate-100 last:border-0 text-sm",children:[e.jsx("span",{className:"text-slate-500 flex-none",children:t}),e.jsx("span",{className:`text-left ${l?"font-extrabold text-slate-900":"font-medium text-slate-800"}`,children:s})]})}const Ht={emerald:"bg-emerald-500",amber:"bg-amber-500",rose:"bg-rose-500"};function Wt(t){const s=String(t??"");return/[",\n]/.test(s)?`"${s.replace(/"/g,'""')}"`:s}function Yt(t,s){const l=s.map(h=>h.map(Wt).join(",")).join(`
44`),r=new Blob(["\uFEFF"+l],{type:"text/csv;charset=utf-8"}),o=URL.createObjectURL(r),m=document.createElement("a");m.href=o,m.download=t,document.body.appendChild(m),m.click(),m.remove(),setTimeout(()=>URL.revokeObjectURL(o),1e3)}function Kt({categories:t,baskets:s,allocations:l,charges:r,payments:o,settlements:m,councilName:h}){const b=n.useMemo(()=>fe(l,r,o),[l,r,o]),w=n.useMemo(()=>r.filter(a=>Ce.includes(a.status)).length,[r]),c=n.useMemo(()=>{const a={};for(const i of l)(a[i.settlement_id]=a[i.settlement_id]||[]).push(i);return Object.entries(a).map(([i,B])=>{var f;return{id:i,name:((f=m.find(y=>y.id===i))==null?void 0:f.name)||"יישוב",...fe(B,r,o),baskets:B.length}}).sort((i,B)=>B.allocated-i.allocated)},[l,r,o,m]),g=n.useMemo(()=>s.map(a=>{var B;const i=l.filter(f=>f.basket_id===a.id);return{id:a.id,title:a.title,category:((B=t.find(f=>f.id===a.category_id))==null?void 0:B.title)||"—",fiscal_year:a.fiscal_year,settlements:i.length,...fe(i,r,o)}}).filter(a=>a.allocated>0||a.settlements>0).sort((a,i)=>i.allocated-a.allocated),[s,l,r,o,t]);function u(){const a=[["דוח סלי תקציב",h||""],[],["לפי יישוב"],["יישוב","תקציב שנתי","שולם","שמור","יתרה זמינה","ניצול %"],...c.map(i=>[i.name,i.allocated,i.paid,i.reserved,i.available,ce(i)]),[],["לפי סל"],["סל","קטגוריה","שנה","יישובים","תקציב שנתי","שולם","שמור","יתרה זמינה","ניצול %"],...g.map(i=>[i.title,i.category,i.fiscal_year,i.settlements,i.allocated,i.paid,i.reserved,i.available,ce(i)])];Yt(`budget-report-${new Date().toISOString().slice(0,10)}.csv`,a)}function x(){const a=y=>String(y??"").replace(/[&<>]/g,N=>({"&":"&amp;","<":"&lt;",">":"&gt;"})[N]),i=y=>y.map(N=>`<tr>${N.map((A,j)=>`<td${j===0?"":' class="n"'}>${a(A)}</td>`).join("")}</tr>`).join(""),B=`<!doctype html><html lang="he" dir="rtl"><head><meta charset="utf-8"><title>דוח סלי תקציב</title>
45<style>*{font-family:"Segoe UI",Arial,sans-serif}body{margin:28px;color:#0f172a}h1{font-size:20px;margin:0 0 2px}.sub{color:#64748b;font-size:13px;margin-bottom:18px}
46h2{font-size:14px;margin:20px 0 8px;color:#1e3a8a;border-bottom:2px solid #e6ebf1;padding-bottom:4px}
47table{width:100%;border-collapse:collapse;font-size:12px}th,td{border:1px solid #e6ebf1;padding:6px 8px;text-align:right}
48th{background:#f4f7fb;color:#475569}td.n{font-variant-numeric:tabular-nums}.tot td{font-weight:800;background:#fafbfe}
49.foot{margin-top:22px;color:#94a3b8;font-size:11px;text-align:center}@media print{body{margin:12mm}}</style></head><body>
50<h1>דוח סלי תקציב</h1><div class="sub">${a(h||"")} · הופק ${a(new Date().toLocaleString("he-IL"))}</div>
51<h2>סיכום</h2><table><tr><th>תקציב שנתי כולל</th><th>שולם</th><th>שמור</th><th>יתרה זמינה</th><th>בקשות ממתינות</th></tr>
52<tr class="tot"><td class="n">${a(_(b.allocated))}</td><td class="n">${a(_(b.paid))}</td><td class="n">${a(_(b.reserved))}</td><td class="n">${a(_(b.available))}</td><td class="n">${w}</td></tr></table>
53<h2>לפי יישוב</h2><table><thead><tr><th>
53יישוב</th><th>תקציב שנתי</th><th>שולם</th><th>שמור</th><th>יתרה זמינה</th><th>ניצול</th></tr></thead><tbody>
54${i(c.map(y=>[y.name,_(y.allocated),_(y.paid),_(y.reserved),_(y.available),ce(y)+"%"]))}</tbody></table>
55<h2>לפי סל</h2><table><thead><tr><th>סל</th><th>קטגוריה</th><th>שנה</th><th>יישובים</th><th>תקציב שנתי</th><th>שולם</th><th>יתרה זמינה</th><th>ניצול</th></tr></thead><tbody>
56${i(g.map(y=>[y.title,y.category,y.fiscal_year,y.settlements,_(y.allocated),_(y.paid),_(y.available),ce(y)+"%"]))}</tbody></table>
57<div class="foot">מסמך דוח · מבוסס נתוני זמן אמת</div></body></html>`,f=window.open("","_blank");f&&(f.document.write(B),f.document.close(),f.focus(),setTimeout(()=>{try{f.print()}catch{}},300))}const p=l.length===0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("h3",{className:"text-sm font-extrabold text-slate-700 flex items-center gap-1.5",children:[e.jsx(rt,{className:"w-4 h-4 text-primary"})," דוחות תקציב"]}
57),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:u,disabled:p,className:"inline-flex items-center gap-1.5 h-9 px-4 rounded-full bg-white border border-slate-200 text-slate-700 text-sm font-semibold hover:border-slate-300 disabled:opacity-40",children:[e.jsx(Nt,{className:"w-4 h-4"})," ייצוא CSV"]}),e.jsxs("button",{onClick:x,disabled:p,className:"inline-flex items-center gap-1.5 h-9 px-4 rounded-full bg-primary text-white text-sm font-bold hover:brightness-110 disabled:opacity-40",children:[e.jsx(nt,{className:"w-4 h-4"})," הדפסה / PDF"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(Te,{icon:xe,tone:"blue",value:_(b.allocated),label:"תקציב שנתי כולל"}),e.jsx(Te,{icon:me,tone:"emerald",value:_(b.paid),label:"שולם"}),e.jsx(Te,{icon:xe,tone:"amber",value:_(b.reserved),label:"שמור (בקשות פתוחות)"}),e.jsx(Te,{icon:Ue,tone:"rose",value:_(b.available),label:"יתרה זמינה"})]}),p?e.jsx("div",{className:"card-float p-12 text-center text-sm text-slate-400",children:"אין נתונים להצגה — הקצו תקציב ליישובים כדי לראות דוחות."}):e.jsxs(e.Fragment,{children:[e.jsx(et,{title:"לפי יישוב",icon:se,head:["יישוב","תקציב שנתי","שולם","שמור","יתרה זמינה","ניצול"],rows:c.map(a=>({key:a.id,name:a.name,sub:`${a.baskets} סלים`,cells:a}))}),e.jsx(et,{title:"לפי סל",icon:xe,head:["סל","תקציב שנתי","שולם","שמור","יתרה זמינה","ניצול"],rows:g.map(a=>({key:a.id,name:a.title,sub:`${a.category} · ${a.settlements} יישובים`,cells:a}))})]})]})}function Te({icon:t,tone:s,value:l,label:r}){const o={blue:"bg-blue-50 text-blue-600",emerald:"bg-emerald-50 text-emerald-600",amber:"bg-amber-50 text-amber-600",rose:"bg-rose-50 text-rose-600"}[s];return e.jsxs("div",{className:"card-float p-4",children:[e.jsx("span",{className:`w-9 h-9 rounded-xl flex items-center justify-center mb-2 ${o}`,children:e.jsx(t,{className:"w-5 h-5"})}),e.jsx("div",{className:"text-2xl font-extrabold text-slate-900 tabular-nums leading-none",children:l}),e.jsx("div",{className:"text-xs text-slate-500 mt-1",children:r})]})}function et({title:t,icon:s,head:l,rows:r}){return e.jsxs("div",{className:"card-float overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-slate-100",children:[e.jsx("span",{className:"w-8 h-8 rounded-lg bg-slate-100 text-slate-600 flex items-center justify-center",children:e.jsx(s,{className:"w-4 h-4"})}),e.jsx("h4",{className:"text-sm font-extrabold text-slate-800",children:t})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{className:"text-slate-500 text-xs bg-slate-50/70",children:l.map((o,m)=>e.jsx("th",{className:"font-bold px-4 py-3 text-right",children:o},o))})}),e.jsx("tbody",{children:r.map(o=>{const m=ce(o.cells),h=Ht[We(m)];return e.jsxs("tr",{className:"border-t border-slate-50 hover:bg-slate-50/40",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-bold text-slate-800",children:o.name}),e.jsx("div",{className:"text-[0.6875rem] text-slate-400",children:o.sub})]}),e.jsx("td",{className:"px-4 py-3 font-bold tabular-nums",children:_(o.cells.allocated)}),e.jsx("td",{className:"px-4 py-3 tabular-nums",children:_(o.cells.paid)}),e.jsx("td",{className:"px-4 py-3 tabular-nums text-slate-500",children:_(o.cells.reserved)}),e.jsx("td",{className:`px-4 py-3 font-bold tabular-nums ${o.cells.available<0?"text-rose-600":"text-emerald-600"}`,children:_(o.cells.available)}),e.jsxs("td",{className:"px-4 py-3 w-40",children:[e.jsx("div",{className:"h-2 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${h}`,style:{width:`${m}%`}})}),e.jsxs("div",{className:"text-[0.6875rem] text-slate-400 mt-1",children:[m,"%"]})]})]},o.key)})})]})})]})}const pe=new Date().getFullYear(),tt={blue:{badge:"bg-blue-50 text-blue-600",bar:"bg-blue-500",ring:"ring-blue-100 border-blue-300",text:"text-blue-700"},emerald:{badge:"bg-emerald-50 text-emerald-600",bar:"bg-emerald-500",ring:"ring-emerald-100 border-emerald-300",text:"text-emerald-700"}
57,amber:{badge:"bg-amber-50 text-amber-600",bar:"bg-amber-500",ring:"ring-amber-100 border-amber-300",text:"text-amber-700"},purple:{badge:"bg-purple-50 text-purple-600",bar:"bg-purple-500",ring:"ring-purple-100 border-purple-300",text:"text-purple-700"},rose:{badge:"bg-rose-50 text-rose-600",bar:"bg-rose-500",ring:"ring-rose-100 border-rose-300",text:"text-rose-700"},sky:{badge:"bg-sky-50 text-sky-600",bar:"bg-sky-500",ring:"ring-sky-100 border-sky-300",text:"text-sky-700"},indigo:{badge:"bg-indigo-50 text-indigo-600",bar:"bg-indigo-500",ring:"ring-indigo-100 border-indigo-300",text:"text-indigo-700"},slate:{badge:"bg-slate-100 text-slate-600",bar:"bg-slate-400",ring:"ring-slate-100 border-slate-300",text:"text-slate-700"}},ge=t=>tt[t]||tt.blue;function K({label:t,children:s,hint:l}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-bold text-slate-500 mb-1.5",children:t}),s,l&&e.jsx("span",{className:"block text-[0.6875rem] text-slate-400 mt-1",children:l})]})}const ue="w-full border border-slate-200 rounded-xl px-3 py-2.5 text-sm bg-slate-50/60 focus:bg-white focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/15 transition";function Pe(t){return e.jsx("input",{...t,className:ue})}function Ie(t){return e.jsx("input",{inputMode:"numeric",...t,className:ue})}function $e(t){return e.jsx("textarea",{...t,className:`${ue} resize-none`})}function Se({children:t,...s}){return e.jsx("select",{...s,className:ue,children:t})}function Ye({children:t,className:s="",...l}){return e.jsx("button",{...l,className:`inline-flex items-center justify-center gap-1.5 h-10 px-4 rounded-full bg-primary text-white text-sm font-bold hover:brightness-110 disabled:opacity-50 transition ${s}`,children:t})}function Re({children:t,className:s="",...l}){return e.jsx("button",{...l,className:`inline-flex items-center justify-center gap-1.5 h-10 px-4 rounded-full bg-white border border-slate-200 text-slate-700 text-sm font-semibold hover:border-slate-300 hover:bg-slate-50 disabled:opacity-50 transition ${s}`,children:t})}function be({active:t,onClick:s,icon:l,tone:r,value:o,label:m,sub:h}){const b=ge(r),w=o!=null&&o!=="";return e.jsxs("button",{onClick:s,className:`text-right card-float p-4 transition ${t?`ring-2 ${b.ring} border`:"hover:border-slate-300"}`,children:[e.jsx("span",{className:`w-9 h-9 rounded-xl flex items-center justify-center mb-2 ${b.badge}`,children:e.jsx(l,{className:"w-5 h-5"})}),w&&e.jsx("div",{className:"text-xl font-extrabold text-slate-900 tabular-nums leading-none",children:o}),e.jsx("div",{className:`text-xs font-bold ${w?"text-slate-500 mt-1":"text-slate-800"}`,children:m}),h&&e.jsx("div",{className:"text-[0.6875rem] text-slate-400 mt-0.5",children:h})]})}function Vt(){var Ke;const{id:t}=yt(),{kibbutz:s}=((Ke=wt)==null?void 0:Ke())||{},[l,r]=n.useState([]),[o,m]=n.useState([]),[h,b]=n.useState([]),[w,c]=n.useState([]),[g,u]=n.useState([]),[x,p]=n.useState([]),[a,i]=n.useState([]),[B,f]=n.useState([]),[y,N]=n.useState(!0),[A,j]=n.useState("baskets"),[z,R]=n.useState("all"),[L,D]=n.useState(null),[T,H]=n.useState(""),[E,I]=n.useState(null),[J,P]=n.useState(!1),[G,Q]=n.useState(null),[je,ve]=n.useState(!1),[ie,oe]=n.useState(null),[De,Ne]=n.useState(!1),[Le,U]=n.useState(!1),v=n.useCallback(async()=>{var d;try{const C=await S.functions.invoke("moatzaSettlements",{kibbutz_id:t});r(((d=C==null?void 0:C.data)==null?void 0:d.settlements)||[])}catch{r([])}},[t]),M=n.useCallback(async()=>{const[d,C,$,W,Y,V,F]=await Promise.all([S.entities.MoatzaBudgetRole.filter({kibbutz_id:t},"order",200).catch(()=>[]),S.entities.MoatzaBudgetCategory.filter({kibbutz_id:t},"order",200).catch(()=>[]),S.entities.MoatzaBudgetBasket.filter({kibbutz_id:t},"order",500).catch(()=>[]),S.entities.MoatzaBudgetStep.filter({kibbutz_id:t},"step_order",2e3).catch(()=>[]),S.entities.MoatzaBudgetAllocation.filter({council_id:t},"-created_date",2e3).catch(()=>[]),S.entities.MoatzaBudgetCharge.filter({council_id:t},"-created_date",5e3).catch(()=>[]),S.entities.MoatzaBudgetPayment.filter({council_id:t},"-created_date",5e3).catch(()=>[])]);m(d||[]),b(C||[]),c($||[]),u(W||[]),p(Y||[]),i(V||[]),f(F||[])}
57,[t]),O=n.useCallback(async()=>{N(!0);try{await Promise.all([v(),M()])}finally{N(!1)}},[v,M]);n.useEffect(()=>{O()},[O]);const ee=n.useMemo(()=>fe(x,a,B),[x,a,B]),ye=n.useMemo(()=>a.filter(d=>d.source!=="manager_expense"&&Ce.includes(d.status)).length,[a]),Me=n.useCallback(d=>w.find(C=>C.id===d),[w]),we=n.useMemo(()=>x.filter(d=>{var C;return z==="all"||((C=Me(d.basket_id))==null?void 0:C.category_id)===z}),[x,z,Me]),ze=n.useMemo(()=>{const d=T.trim();return l.filter(C=>!d||(C.name||"").includes(d)).map(C=>{const $=we.filter(W=>W.settlement_id===C.id);return{...C,allocs:$,...fe($,a,B),basketCount:$.length}}).sort((C,$)=>$.allocated-C.allocated||(C.name||"").localeCompare($.name||""))},[l,T,we,a,B]);async function ct(d,C){const $={kibbutz_id:t,title:d.title,description:d.description,color:d.color,icon:"Wallet",order:C?C.order:h.length};C?await S.entities.MoatzaBudgetCategory.update(C.id,$):await S.entities.MoatzaBudgetCategory.create($),k.success("הקטגוריה נשמרה"),I(null),await M()}async function dt(d){const C=w.filter($=>$.category_id===d.id);if(C.length){if(!window.confirm(`בקטגוריה "${d.title}" יש ${C.length} סלים.
58מחיקת הקטגוריה תמחק גם את כל הסלים שבה, ההקצאות ליישובים והחיובים שלהם.
59פעולה בלתי הפיכה — להמשיך?`))return;try{await S.functions.invoke("moatzaBudgetBulkDelete",{action:"delete_category",category_id:d.id}),k.success("הקטגוריה והסלים שבה נמחקו")}catch($){k.error(($==null?void 0:$.message)||"שגיאה במחיקת הקטגוריה");return}}else{if(!window.confirm(`למחוק את הקטגוריה "${d.title}"?`))return;try{await S.entities.MoatzaBudgetCategory.delete(d.id),k.success("הקטגוריה נמחקה")}catch($){k.error(($==null?void 0:$.message)||"שגיאה במחיקה");return}}z===d.id&&R("all"),D(null),await O()}async function xt(d,C,$){const W={kibbutz_id:t,category_id:d.category_id,title:d.title,emphasis:d.emphasis,fiscal_year:Number(d.fiscal_year)||pe,require_two_quotes_over:d.require_two_quotes_over?Number(d.require_two_quotes_over):null,status:d.status||"active",order:$?$.order:w.length};let Y;$?(await S.entities.MoatzaBudgetBasket.update($.id,W),Y=$.id):Y=(await S.entities.MoatzaBudgetBasket.create(W)).id;const V=g.filter(F=>F.basket_id===Y);await Promise.all(V.map(F=>S.entities.MoatzaBudgetStep.delete(F.id).catch(()=>{}))),await Promise.all(C.map((F,te)=>S.entities.MoatzaBudgetStep.create({kibbutz_id:t,basket_id:Y,council_role_id:F.council_role_id,step_order:te,is_override_step:!!F.is_override_step}))),k.success("הסל ושרשרת האישורים נשמרו"),Q(null),await M()}async function mt(d){return x.some(C=>C.basket_id===d.id)?(k.error("יש הקצאות ליישובים בסל זה — יש להסירן קודם"),!1):window.confirm(`למחוק את הסל "${d.title}"?`)?(await S.entities.MoatzaBudgetStep.filter({basket_id:d.id}).then(C=>Promise.all((C||[]).map($=>S.entities.MoatzaBudgetStep.delete($.id).catch(()=>{})))).catch(()=>{}),await S.entities.MoatzaBudgetBasket.delete(d.id),k.success("הסל נמחק"),await M(),!0):!1}async function ut(d,C){let $=h;const W=F=>$.find(te=>(te.title||"").trim()===(F||"").trim());let Y=w.length,V=0;for(const F of d){let te=C||null;if(F.category){const _e=W(F.category);if(_e)te=_e.id;
59else{const ke=await S.entities.MoatzaBudgetCategory.create({kibbutz_id:t,title:F.category.trim(),color:Oe[$.length%Oe.length],icon:"Wallet",order:$.length});$=[...$,ke],te=ke.id}}await S.entities.MoatzaBudgetBasket.create({kibbutz_id:t,category_id:te,title:F.name.trim(),fiscal_year:pe,status:"active",order:Y++}),V+=1}k.success(`נוצרו ${V} סלים`),ve(!1),await M()}async function ht(d,C,$){const W=w.find(V=>V.id===C),Y={council_id:t,settlement_id:d.settlement_id,basket_id:C,fiscal_year:(W==null?void 0:W.fiscal_year)||pe,amount:Number(d.amount)||0,notes:d.notes};$?await S.entities.MoatzaBudgetAllocation.update($.id,Y):await S.entities.MoatzaBudgetAllocation.create(Y),k.success("ההקצאה נשמרה"),oe(null),await M()}async function bt(d,C){const $=V=>w.find(F=>(F.title||"").trim()===(V||"").trim());let W=0;const Y=[];for(const V of C){const F=$(V.name);if(!F){Y.push(V.name);continue}const te=x.find(ke=>ke.basket_id===F.id&&ke.settlement_id===d),_e={council_id:t,settlement_id:d,basket_id:F.id,fiscal_year:F.fiscal_year||pe,amount:Number(V.amount)||0};te?await S.entities.MoatzaBudgetAllocation.update(te.id,_e):await S.entities.MoatzaBudgetAllocation.create(_e),W+=1}Y.length&&k.error(`לא נמצאו סלים: ${Y.join(", ")}`),W&&k.success(`הוקצו ${W} סלים ליישוב`),oe(null),await M()}async function pt(d){if(a.some(C=>C.allocation_id===d.id)){k.error("קיימות בקשות חיוב על הקצאה זו — לא ניתן למחוק");return}window.confirm("למחוק את ההקצאה ליישוב זה?")&&(await S.entities.MoatzaBudgetAllocation.delete(d.id),k.success("ההקצאה הוסרה"),await M())}return y?e.jsx("div",{className:"flex justify-center py-24",children:e.jsx(Z,{className:"w-8 h-8 animate-spin text-slate-400"})}):e.jsxs("div",{dir:"rtl",className:"space-y-4",children:[e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsx(Bt,{title:"ניהול סלי תקציב",items:[{label:"הוספת קטגוריה",icon:de,iconBg:"bg-blue-50",iconColor:"text-blue-600",onClick:()=>I({})},{label:"בעלי תפקידים לאישורים",icon:Ge,iconBg:"bg-violet-50",iconColor:"text-violet-600",onClick:()=>Ne(!0),separatorBefore:!0},{label:"ניהול ספקים",icon:Qe,iconBg:"bg-emerald-50",iconColor:"text-emerald-600",onClick:()=>j("suppliers")},{label:"מחיקת סלים",icon:X,iconBg:"bg-rose-50",iconColor:"text-rose-600",onClick:()=>U(!0),separatorBefore:!0}]})}),e.jsx("div",{className:"card-float overflow-hidden",children:e.jsxs("div",{className:"relative bg-gradient-to-l from-primary/10 via-primary/5 to-transparent p-6 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-5 min-w-0",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-white shadow-sm border border-slate-100 flex items-center justify-center flex-shrink-0",children:e.jsx(Pt,{className:"w-8 h-8 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[0.6875rem] font-bold text-primary bg-primary/10 rounded-full px-3 py-1 mb-1.5",children:[e.jsx(se,{className:"w-3.5 h-3.5"})," מועצה אזורית"]}),e.jsxs("h1",{className:"text-2xl font-extrabold text-foreground leading-tight truncate",children:[(s==null?void 0:s.name)||"המועצה"," · ניהול סלי תקציב"]}
59),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"ניהול קטגוריות, סלים והקצאות ליישובים · מעקב חיובים ואישורים עד תשלום"})]})]}),e.jsxs("button",{onClick:()=>P(!0),className:"flex-none inline-flex items-center gap-1.5 h-11 px-5 rounded-full bg-emerald-600 text-white text-sm font-bold hover:bg-emerald-700 shadow-sm transition",children:[e.jsx(de,{className:"w-4 h-4"})," סל תקציב חדש"]})]})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(be,{active:A==="baskets",onClick:()=>j("baskets"),icon:xe,tone:"blue",value:_(ee.allocated),label:`תקציב שנתי · ${pe}`}),e.jsx(be,{active:A==="baskets",onClick:()=>j("baskets"),icon:xe,tone:"amber",value:_(ee.available),label:"יתרה זמינה"}),e.jsx(be,{active:A==="baskets",onClick:()=>j("baskets"),icon:me,tone:"emerald",value:_(ee.paid),label:"שולם"}),e.jsx(be,{active:A==="inbox",onClick:()=>j("inbox"),icon:_t,tone:"rose",value:ye,label:"בקשות לאישור"}),e.jsx(be,{active:A==="suppliers",onClick:()=>j("suppliers"),icon:Qe,tone:"emerald",label:"ספקים",sub:"ניהול ספקים"}),e.jsx(be,{active:A==="reports",onClick:()=>j("reports"),icon:rt,tone:"indigo",label:"דוחות",sub:"דוחות ותובנות"})]}),A==="inbox"?e.jsx(Ot,{councilId:t,councilName:s==null?void 0:s.name,settlements:l,onDataChanged:M}):A==="suppliers"?e.jsx($t,{mode:"council",councilId:t,categories:h}):A==="reports"?e.jsx(Kt,{categories:h,baskets:w,allocations:x,charges:a,payments:B,settlements:l,councilName:s==null?void 0:s.name}):e.jsx(e.Fragment,{children:L?e.jsx(Zt,{settlement:l.find(d=>d.id===L),allocations:we.filter(d=>d.settlement_id===L),baskets:w,categories:h,charges:a,payments:B,onBack:()=>D(null),onAdd:()=>oe({lockedSettlement:L}),onEditAllocation:d=>oe({lockedSettlement:L,allocation:d}),onDeleteAllocation:pt,onEditBasket:d=>Q({basket:d,categoryId:d.category_id})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(st,{active:z==="all",onClick:()=>R("all"),label:"כל הקטגוריות"}),h.map(d=>e.jsx(st,{active:z===d.id,onClick:()=>R(d.id),tone:d.color,label:d.title,onEdit:()=>I({category:d}),onDelete:()=>dt(d)},d.id)),e.jsxs("button",{onClick:()=>I({}),className:"inline-flex items-center gap-1 h-9 px-4 rounded-full bg-white border border-dashed border-slate-300 text-slate-500 text-sm font-semibold hover:border-primary hover:text-primary transition",children:[e.jsx(de,{className:"w-4 h-4"})," קטגוריה"]}),e.jsxs("div",{className:"relative ms-auto w-full sm:w-64",children:[e.jsx(He,{className:"w-4 h-4 text-slate-400 absolute top-1/2 -translate-y-1/2 right-3 pointer-events-none"}),e.jsx("input",{value:T,onChange:d=>H(d.target.value),placeholder:"חיפוש יישוב…",className:"w-full h-9 border border-slate-200 rounded-full pr-9 pl-3 text-sm bg-white focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/15"})]})]}),ze.length===0?e.jsxs("div",{className:"card-float p-12 text-center",children:[e.jsx("span",{className:"w-14 h-14 rounded-2xl bg-slate-100 text-slate-400 flex items-center justify-center mx-auto mb-3",children:e.jsx(se,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-500 font-medium",children:T?"לא נמצא יישוב תואם":"אין יישובים מקושרים למועצה"})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:ze.map(d=>e.jsx(Xt,{data:d,onClick:()=>D(d.id)},d.id))})]})}),E&&e.jsx(Jt,{initial:E.category,onClose:()=>I(null),onSave:ct}),J&&e.jsx(ls,{onClose:()=>P(!1),onSingle:()=>{var d;P(!1),Q({categoryId:z!=="all"?z:(d=h[0])==null?void 0:d.id})},onBulk:()=>{P(!1),ve(!0)},hasCategories:h.length>0}),je&&e.jsx(ns,{categories:h,onClose:()=>ve(!1),onSave:ut}),G&&e.jsx(es,{initial:G.basket,defaultCategoryId:G.categoryId,categories:h,roles:o,chain:G.basket?g.filter(d=>d.basket_id===G.basket.id).sort((d,C)=>d.step_order-C.step_order):[],onClose:()=>Q(null),onSave:xt,onManageRoles:()=>Ne(!0),onDelete:G.basket?async()=>{await mt(G.basket)&&Q(null)}:null}),ie&&e.jsx(rs,{defaultBasket:ie.defaultBasket,initial:ie.allocation,lockedSettlementId:ie.lockedSettlement,settlements:l,baskets:w,allocations:x,onClose:()=>oe(null),onSave:ht,onBulk:bt}),De&&e.jsx(is,{councilId:t,roles:o,onClose:()=>Ne(!1),onChanged:M}),Le&&e.jsx(Qt,{settlements:l,allocations:x,onClose:()=>U(!1),onDone:async()=>{U(!1),D(null),await O()}})]})}function Qt({settlements:t,allocations:s,onClose:l,onDone:r}){const[o,m]=n.useState(null),[h,b]=n.useState({}),[w,c]=n.useState(""),[g,u]=n.useState(!1),x=n.useMemo(()=>{const N={};for(const A of s)N[A.settlement_id]=(N[A.settlement_id]||0)+1;return N},[s]),p=n.useMemo(()=>t.filter(N=>x[N.id]),[t,x]),a=n.useMemo(()=>{const N=w.trim();return p.filter(A=>!N||(A.name||"").includes(N))},[p,w]),i=Object.keys(h).filter(N=>h[N]),B=s.length,f=i.reduce((N,A)=>N+(x[A]||0),0);async function y(N){const A=N?`${N.length} יישובים`:"כל היישובים";if(window.confirm(`אזהרה: פעולה בלתי הפיכה!
60יימחקו כל הסלים שהוקצו ל${A}, כולל כל בקשות החיוב וההוצאות שלהם.
61הגדרות הסלים ושרשראות האישורים יישמרו. להמשיך?`)){u(!0);try{const j=await S.functions.invoke("moatzaBudgetBulkDelete",{action:"clear_allocations",settlement_ids:N||null}),z=(j==null?void 0:j.data)||j||{};k.success(`נמחקו ${z.allocations??0}
61 סלים ב‑${z.settlements??0} יישובים`),await r()}catch(j){k.error((j==null?void 0:j.message)||"שגיאה במחיקה")}finally{u(!1)}}}return e.jsx(ae,{open:!0,onOpenChange:N=>!N&&l(),children:e.jsxs(le,{dir:"rtl",className:"max-w-lg max-h-[92vh] overflow-y-auto",children:[e.jsx(ne,{children:e.jsxs(re,{className:"flex items-center gap-2 text-rose-600",children:[e.jsx(X,{className:"w-5 h-5"})," מחיקת סלים מהיישובים"]})}),o===null?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>m("all"),className:"rounded-2xl border border-slate-200 bg-white p-5 text-center hover:border-rose-300 hover:shadow-sm transition",children:[e.jsx("span",{className:"w-12 h-12 rounded-2xl bg-rose-50 text-rose-600 flex items-center justify-center mx-auto mb-2",children:e.jsx(X,{className:"w-6 h-6"})}),e.jsx("div",{className:"text-sm font-extrabold text-slate-800",children:"כל היישובים"}),e.jsxs("div",{className:"text-[0.6875rem] text-slate-400 mt-0.5",children:["מחיקת כל הסלים מכל היישובים (",B,")"]})]}),e.jsxs("button",{onClick:()=>m("select"),className:"rounded-2xl border border-slate-200 bg-white p-5 text-center hover:border-primary hover:shadow-sm transition",children:[e.jsx("span",{className:"w-12 h-12 rounded-2xl bg-blue-50 text-blue-600 flex items-center justify-center mx-auto mb-2",children:e.jsx(se,{className:"w-6 h-6"})}),e.jsx("div",{className:"text-sm font-extrabold text-slate-800",children:"בחירת יישובים"}),e.jsx("div",{className:"text-[0.6875rem] text-slate-400 mt-0.5",children:"סימון יישובים ומחיקת הסלים שלהם בלבד"})]})]}):o==="all"?e.jsxs("div",{children:[e.jsxs("div",{className:"rounded-xl bg-rose-50 border border-rose-100 text-rose-700 px-3 py-3 text-sm",children:["פעולה זו תמחק את ",e.jsxs("b",{children:["כל ",B," הסלים"]})," שהוקצו לכל היישובים, כולל בקשות החיוב וההוצאות שלהם. הגדרות הסלים ושרשראות האישורים יישמרו."]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-4",children:[e.jsxs(Re,{onClick:()=>m(null),children:[e.jsx(Be,{className:"w-4 h-4"})," חזרה"]}),e.jsxs("button",{onClick:()=>y(null),disabled:g||!B,className:"h-10 px-5 rounded-full bg-rose-600 text-white text-sm font-bold inline-flex items-center gap-1.5 hover:bg-rose-700 disabled:opacity-50",children:[g?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(X,{className:"w-4 h-4"})," מחיקת כל הסלים"]})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs font-bold text-slate-500",children:"סמנו יישובים למחיקת הסלים שלהם"}),e.jsx("button",{onClick:()=>{const N={};a.forEach(A=>{N[A.id]=!0}),b(N)},className:"text-xs font-bold text-primary hover:underline",children:"בחר הכל"})]}),e.jsxs("div",{className:"relative mb-2",children:[e.jsx(He,{className:"w-4 h-4 text-slate-400 absolute top-1/2 -translate-y-1/2 right-3 pointer-events-none"}),e.jsx("input",{value:w,onChange:N=>c(N.target.value),placeholder:"חיפוש יישוב…",className:`${ue} pr-9`})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto rounded-xl border border-slate-200 divide-y divide-slate-50",children:a.length===0?e.jsx("div",{className:"px-3 py-4 text-sm text-slate-400 text-center",children:"אין יישובים עם סלים מוקצים"}):a.map(N=>e.jsxs("label",{className:"flex items-center gap-2.5 px-3 py-2.5 cursor-pointer hover:bg-slate-50",children:[e.jsx("input",{type:"checkbox",checked:!!h[N.id],onChange:A=>b(j=>({...j,[N.id]:A.target.checked}))}),e.jsx(se,{className:"w-4 h-4 text-slate-400 flex-none"}),e.jsx("span",{className:"text-sm font-medium text-slate-800 flex-1 truncate",children:N.name}),e.jsxs("span",{className:"text-[0.6875rem] text-slate-400",children:[x[N.id]," סלים"]})]},N.id))}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-4",children:[e.jsxs(Re,{onClick:()=>m(null),children:[e.jsx(Be,{className:"w-4 h-4"})," חזרה"]}),e.jsxs("button",{onClick:()=>y(i),disabled:g||!i.length,className:"h-10 px-5 rounded-full bg-rose-600 text-white text-sm font-bold inline-flex items-center gap-1.5 hover:bg-rose-700 disabled:opacity-50",children:[g?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(X,{className:"w-4 h-4"})," מחיקת ",f," סלים ב‑",i.length," יישובים"]})]})]})]})})}function st({active:t,onClick:s,label:l,tone:r,onEdit:o,onDelete:m}){const h=ge(r);return e.jsxs("span",{className:`group inline-flex items-center rounded-full border text-sm font-semibold transition ${t?`${h.badge} ${h.ring} ring-2`:"bg-white border-slate-200 text-slate-600 hover:border-slate-300"}`,children:[e.jsx("button",{onClick:s,className:"pr-4 pl-3 h-9 inline-flex items-center",children:l}),(o||m)&&e.jsxs("span",{className:`flex items-center gap-0.5 pl-2 ${t?"":"op
61acity-0 group-hover:opacity-100"} transition`,children:[o&&e.jsx("button",{onClick:o,title:"עריכה",className:"w-6 h-6 rounded-full hover:bg-black/5 flex items-center justify-center",children:e.jsx(it,{className:"w-3.5 h-3.5"})}),m&&e.jsx("button",{onClick:m,title:"מחיקה",className:"w-6 h-6 rounded-full hover:bg-rose-50 text-rose-500 flex items-center justify-center",children:e.jsx(X,{className:"w-3.5 h-3.5"})})]})]})}function Xt({data:t,onClick:s}){const l=ce(t),r=ge(We(l));return e.jsxs("button",{onClick:s,className:"text-right card-float p-4 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl bg-blue-50 text-blue-600 flex items-center justify-center",children:e.jsx(se,{className:"w-5 h-5"})}),e.jsxs("span",{className:"text-[0.6875rem] text-slate-400 font-semibold",children:[t.basketCount," סלים"]})]}),e.jsx("h3",{className:"text-base font-extrabold text-slate-900 truncate",children:t.name}),e.jsxs("div",{className:"mt-2 space-y-1 text-[0.8125rem]",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"תקציב"}),e.jsx("b",{className:"tabular-nums",children:_(t.allocated)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-slate-500",children:"יתרה"}),e.jsx("b",{className:`tabular-nums ${t.available<0?"text-rose-600":"text-emerald-600"}`,children:_(t.available)})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"h-2 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${r.bar}`,style:{width:`${l}%`}})}),e.jsxs("div",{className:"text-[0.6875rem] text-slate-400 mt-1",children:["ניצול ",l,"%"]})]})]})}function Zt({settlement:t,allocations:s,baskets:l,categories:r,charges:o,payments:m,onBack:h,onAdd:b,onEditAllocation:w,onDeleteAllocation:c,onEditBasket:g}){const u=n.useMemo(()=>fe(s,o,m),[s,o,m]),x=a=>l.find(i=>i.id===a),p=a=>r.find(i=>i.id===(a==null?void 0:a.category_id));return e.jsxs("div",{className:"card-float overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 p-4 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("button",{onClick:h,title:"חזרה ליישובים",className:"w-9 h-9 rounded-full border border-slate-200 flex items-center justify-center hover:bg-slate-50",children:e.jsx(Be,{className:"w-5 h-5 text-slate-500 rotate-180"})}),e.jsx("span",{className:"w-11 h-11 rounded-xl bg-blue-50 text-blue-600 flex items-center justify-center flex-none",children:e.jsx(se,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-lg font-extrabold text-slate-900 truncate",children:(t==null?void 0:t.name)||"יישוב"}),e.jsxs("div",{className:"text-xs text-slate-500 mt-0.5",children:["תקציב ",_(u.allocated)," · שולם ",_(u.paid)," · יתרה ",_(u.available)]})]})]}),e.jsxs(Ye,{onClick:b,children:[e.jsx(de,{className:"w-4 h-4"})," הקצאה לסל"]})]}),s.length===0?e.jsx("div",{className:"p-10 text-center text-sm text-slate-400",children:"אין עדיין הקצאות ליישוב זה — הקצו תקציב שנתי לסל"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-slate-500 text-xs bg-slate-50/70",children:[e.jsx("th",{className:"text-right font-bold px-4 py-3",children:"סל"}),e.jsx("th",{className:"text-right font-bold px-4 py-3",children:"תקציב שנתי"}),e.jsx("th",{className:"text-right font-bold px-4 py-3",children:"שולם"}),e.jsx("th",{className:"text-right font-bold px-4 py-3",children:"שמור"}),e.jsx("th",{className:"text-right font-bold px-4 py-3",children:"יתרה זמינה"}),e.jsx("th",{className:"text-right font-bold px-4 py-3 w-40",children:"ניצול"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsx("tbody",{children:s.map(a=>{const i=x(a.basket_id),B=p(i),f=lt(a,o,m),y=ce(f),N=ge(We(y));return e.jsxs("tr",{className:"border-t border-slate-50 hover:bg-slate-50/40",children:[e.jsx("td",{className:"px-4 py-3",children:e.jsxs("button",{onClick:()=>i&&g(i),className:"text-right group",children:[e.jsxs("div",{className:"font-bold text-slate-800 group-hover:text-primary flex items-center gap-2",children:[e.jsx(xe,{className:"w-4 h-4 text-slate-400"})," ",(i==null?void 0:i.title)||"סל"]}),B&&e.jsxs("div",{className:"text-[0.6875rem] text-slate-400 mt-0.5",children:[B.title," · הגדרות סל ›"]})]})}),e.jsx("td",{className:"px-4 py-3 font-bold tabular-nums",children:_(f.allocated)}),e.jsx("td",{className:"px-4 py-3 tabular-nums",children:_(f.paid)}),e.jsx("td",{className:"px-4 py-3 tabular-nums text-slate-500",children:_(f.reserved)}),e.jsx("td",{className:`px-4 py-3 font-bold tabular-nums ${f.available<0?"text-rose-600":"text-emerald-600"}`,children:_(f.available)}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"h-2 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${N.bar}`,style:{width:`${y}%`}})}),e.jsxs("div",{className:"text-[0.6875rem] text-slate-400 mt-1",children:[y,"%",f.openCount?` · ${f.openCount} פתוחות`:""]})]}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[e.jsx("button",{onClick:()=>w(a),title:"עריכת הקצאה",className:"w-8 h-8 rounded-full hover:bg-slate-100 flex items-center justify-center text-slate-500",children:e.jsx(it,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>c(a),title:"מחיקה",className:"w-8 h-8 rounded-full hover:bg-rose-50 text-rose-500 flex items-center justify-center",children:e.jsx(X,{className:"w-4 h-4"})})]})})]},a.id)})})]})})]})}function Jt({initial:t,onClose:s,onSave:l}
61){const[r,o]=n.useState({title:(t==null?void 0:t.title)||"",description:(t==null?void 0:t.description)||"",color:(t==null?void 0:t.color)||"blue"}),[m,h]=n.useState(!1),b=c=>g=>o(u=>({...u,[c]:g.target.value}));async function w(){if(!r.title.trim()){k.error("נדרשת כותרת לקטגוריה");return}h(!0);try{await l(r,t)}catch(c){k.error((c==null?void 0:c.message)||"שגיאה בשמירה")}finally{h(!1)}}return e.jsx(ae,{open:!0,onOpenChange:c=>!c&&s(),children:e.jsxs(le,{dir:"rtl",className:"max-w-md",children:[e.jsx(ne,{children:e.jsx(re,{children:t?"עריכת קטגוריה":"קטגוריית תקציב חדשה"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(K,{label:"שם הקטגוריה",children:e.jsx(Pe,{value:r.title,onChange:b("title"),placeholder:"לדוגמה: תרבות ופנאי",autoFocus:!0})}),e.jsx(K,{label:"תיאור (רשות)",children:e.jsx($e,{rows:2,value:r.description,onChange:b("description")})}),e.jsx(K,{label:"צבע",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:Oe.map(c=>e.jsx("button",{onClick:()=>o(g=>({...g,color:c})),className:`w-8 h-8 rounded-full ${ge(c).bar} ${r.color===c?"ring-2 ring-offset-2 ring-slate-400":""}`},c))})})]}),e.jsx(Ae,{onClose:s,onSubmit:w,saving:m})]})})}function es({initial:t,defaultCategoryId:s,categories:l,roles:r,chain:o,onClose:m,onSave:h,onManageRoles:b,onDelete:w}){var A;const[c,g]=n.useState({category_id:(t==null?void 0:t.category_id)||s||((A=l[0])==null?void 0:A.id)||"",title:(t==null?void 0:t.title)||"",emp
61hasis:(t==null?void 0:t.emphasis)||"",fiscal_year:(t==null?void 0:t.fiscal_year)||pe,require_two_quotes_over:(t==null?void 0:t.require_two_quotes_over)||"",status:(t==null?void 0:t.status)||"active"}),[u,x]=n.useState(o.length?o.map(j=>({council_role_id:j.council_role_id,is_override_step:j.is_override_step})):[]),[p,a]=n.useState(!1),i=j=>z=>g(R=>({...R,[j]:z.target.value})),B=j=>{var z;return((z=r.find(R=>R.id===j))==null?void 0:z.title)||"תפקיד"},f=()=>{const j=new Set(u.map(R=>R.council_role_id)),z=r.find(R=>!j.has(R.id))||r[0];if(!z){k.error("הוסיפו קודם בעלי תפקידים לאישורים");return}x(R=>[...R,{council_role_id:z.id,is_override_step:!1}])},y=(j,z)=>x(R=>{const L=j+z;if(L<0||L>=R.length)return R;const D=[...R];return[D[j],D[L]]=[D[L],D[j]],D});async function N(){if(!c.title.trim()){k.error("נדרשת כותרת לסל");return}if(!c.category_id){k.error("בחרו קטגוריה");return}a(!0);try{await h(c,u,t)}catch(j){k.error((j==null?void 0:j.message)||"שגיאה בשמירה")}finally{a(!1)}}return e.jsx(ae,{open:!0,onOpenChange:j=>!j&&m(),children:e.jsxs(le,{dir:"rtl",className:"max-w-3xl max-h-[92vh] overflow-y-auto",children:[e.jsx(ne,{children:e.jsx(re,{children:t?"הגדרות הסל ושרשרת האישורים":"סל תקציב חדש"})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 items-start",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"w-8 h-8 rounded-lg bg-blue-50 text-blue-600 flex items-center justify-center",children:e.jsx(xe,{className:"w-4 h-4"})}),e.jsx("h4",{className:"text-sm font-extrabold text-slate-800",children:"פרטי הסל"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(K,{label:"שם הסל",children:e.jsx(Pe,{value:c.title,onChange:i("title"),placeholder:"לדוגמה: אירועים וחוגי נוער",autoFocus:!0})}),e.jsx(K,{label:"קטגוריה",children:e.jsx(Se,{value:c.category_id,onChange:i("category_id"),children:l.map(j=>e.jsx("option",{value:j.id,children:j.title},j.id))})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(K,{label:"שנת תקציב",children:e.jsx(Ie,{value:c.fiscal_year,onChange:i("fiscal_year")})}),e.jsx(K,{label:"סטטוס",children:e.jsxs(Se,{value:c.status,onChange:i("status"),children:[e.jsx("option",{value:"active",children:"פעיל"}),e.jsx("option",{value:"draft",children:"טיוטה"}),e.jsx("option",{value:"closed",children:"סגור"})]})})]}),e.jsx(K,{label:"חובת 2 הצעות מחיר מעל (₪)",hint:"רשות — ערך מנחה שיוצג ליישוב",children:e.jsx(Ie,{value:c.require_two_quotes_over,onChange:i("require_two_quotes_over"),placeholder:"לדוגמה 5000"})}),e.jsx(K,{label:"דגשים לסל (יוצגו ליישובים)",children:e.jsx($e,{rows:3,value:c.emphasis,onChange:i("emphasis"),placeholder:"לדוגמה: ניצול עד סוף Q3 · לא כולל שכר"})})]})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/40 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h4",{className:"text-sm font-extrabold text-slate-800 flex items-center gap-1.5",children:[e.jsx(Ge,{className:"w-4 h-4 text-violet-500"})," שרשרת אישורים"]}),e.jsx("button",{onClick:b,className:"text-xs font-bold text-primary hover:underline",children:"ניהול בעלי תפקידים"})]}),u.length===0&&e.jsx("p",{className:"text-xs text-slate-400 mb-3",children:"הוסיפו שלבי אישור לפי הסדר — כל בקשת חיוב בסל תעבור בשלבים אלה עד לאישור סופי."}),e.jsx("div",{className:"space-y-2",children:u.map((j,z)=>e.jsxs("div",{className:"flex items-center gap-2 bg-white rounded-xl border border-slate-200 p-2",children:[e.jsx("span",{className:"w-7 h-7 rounded-full bg-violet-50 text-violet-600 text-xs font-extrabold flex items-center justify-center flex-none",children:z+1}),e.jsx(Se,{value:j.council_role_id,onChange:R=>x(L=>L.map((D,T)=>T===z?{...D,council_role_id:R.target.value}:D)),children:r.map(R=>e.jsx("option",{value:R.id,children:R.title},R.id))}),e.jsxs("label",{className:"flex items-center gap-1 text-[0.6875rem] text-slate-600 whitespace-nowrap px-0.5",title:"שלב זה מוסמך לאשר חריגה מיתרת הסל",children:[e.jsx("input",{type:"checkbox",checked:j.is_override_step,onChange:R=>x(L=>L.map((D,T)=>T===z?{...D,is_override_step:R.target.checked}:D))}),"חריגה"]}),e.jsxs("div",{className:"flex items-center gap-0.5 flex-none",children:[e.jsx("button",{onClick:()=>y(z,-1),disabled:z===0,title:"הזז מעלה",className:"w-7 h-7 rounded-lg hover:bg-slate-100 disabled:opacity-30 flex items-center justify-center",children:e.jsx(At,{className:"w-4 h-4 text-slate-400 rotate-90"})}),e.jsx("button",{onClick:()=>x(R=>R.filter((L,D)=>D!==z)),title:"הסר שלב",className:"w-7 h-7 rounded-lg hover:bg-rose-50 text-rose-500 flex items-center justify-center",children:e.jsx(Ee,{className:"w-4 h-4"})})]})]},z))}),e.jsxs("button",{onClick:f,className:"mt-3 inline-flex items-center gap-1 text-sm font-bold text-primary hover:underline",children:[e.jsx(de,{className:"w-4 h-4"})," הוספת שלב אישור"]}),u.length>0&&e.jsxs("p",{className:"text-[0.6875rem] text-slate-400 mt-2",children:[B(u[u.length-1].council_role_id)," — שלב האישור האחרון בשרשרת."]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-5",children:[t&&w?e.jsxs("button",{onClick:w,className:"inline-flex items-center gap-1.5 h-10 px-4 roun
61ded-full text-rose-600 text-sm font-bold hover:bg-rose-50 transition",children:[e.jsx(X,{className:"w-4 h-4"})," מחיקת הסל"]}):e.jsx("span",{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Re,{onClick:m,children:[e.jsx(Be,{className:"w-4 h-4"})," ביטול"]}),e.jsxs(Ye,{onClick:N,disabled:p,children:[p?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(me,{className:"w-4 h-4"})," שמירה"]})]})]})]})})}function ts({options:t,value:s,onChange:l}){const[r,o]=n.useState(""),m=r.trim(),h=m?t.filter(b=>(b.name||"").includes(m)):t;return e.jsxs("div",{children:[e.jsxs("div",{className:"relative",children:[e.jsx(He,{className:"w-4 h-4 text-slate-400 absolute top-1/2 -translate-y-1/2 right-3 pointer-events-none"}),e.jsx("input",{value:r,onChange:b=>o(b.target.value),placeholder:"הקלידו שם יישוב…",className:`${ue} pr-9`,autoFocus:!0})]}),e.jsx("div",{className:"mt-2 max-h-44 overflow-y-auto rounded-xl border border-slate-200 divide-y divide-slate-100 bg-white",children:h.length===0?e.jsx("div",{className:"px-3 py-3 text-sm text-slate-400",children:"לא נמצא יישוב תואם"}):h.map(b=>e.jsxs("button",{type:"button",onClick:()=>l(b.id),className:`w-full text-right px-3 py-2.5 text-sm flex items-center justify-between transition ${s===b.id?"bg-blue-50/70 text-blue-700 font-bold":"hover:bg-slate-50 text-slate-700"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(se,{className:"w-4 h-4 text-slate-400 flex-none"})," ",e.jsx("span",{className:"truncate",children:b.name})]}),s===b.id&&e.jsx(Ct,{className:"w-4 h-4 text-blue-600 flex-none"})]},b.id))})]})}function ss(t){return String(t||"").split(/\r?\n/).map(s=>s.trim()).filter(Boolean).map(s=>{const l=s.split(/\t|,/).map(r=>r.trim());return{name:l[0]||"",category:(l[1]||"").trim()}}).filter(s=>s.name)}function as(t){return String(t||"").split(/\r?\n/).map(s=>s.trim()).filter(Boolean).map(s=>{const l=s.match(/^(.+?)[\t,\s]+([\d.,]+)\s*$/);return l?{name:l[1].trim(),amount:Number(l[2].replace(/,/g,""))||0}:{name:s,amount:0}}).filter(s=>s.name)}function ls({onClose:t,onSingle:s,onBulk:l,hasCategories:r}){return e.jsx(ae,{open:!0,onOpenChange:o=>!o&&t(),children:e.jsxs(le,{dir:"rtl",className:"max-w-md",children:[e.jsx(ne,{children:e.jsx(re,{children:"הוספת סל תקציב"})}),!r&&e.jsx("p",{className:"text-xs text-amber-700 bg-amber-50 rounded-xl px-3 py-2 mb-2",children:"אפשר גם להוסיף קטגוריות תוך כדי ההדבקה."}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(at,{icon:Rt,tone:"blue",title:"סל בודד",sub:"יצירת סל אחד + שרשרת אישורים",onClick:s}),e.jsx(at,{icon:ot,tone:"emerald",title:"הדבקה מקובץ",sub:"רשימת סלים מאקסל",onClick:l})]})]})})}function at({icon:t,tone:s,title:l,sub:r,onClick:o}){const m=ge(s);return e.jsxs("button",{onClick:o,className:"rounded-2xl border border-slate-200 bg-white p-5 text-center hover:border-primary hover:shadow-sm transition",children:[e.jsx("span",{className:`w-12 h-12 rounded-2xl flex items-center justify-center mx-auto mb-2 ${m.badge}`,children:e.jsx(t,{className:"w-6 h-6"})}),e.jsx("div",{className:"text-sm font-extrabold text-slate-800",children:l}),e.jsx("div",{className:"text-[0.6875rem] text-slate-400 mt-0.5",children:r})]})}function ns({categories:t,onClose:s,onSave:l}){var p;const[r,o]=n.useState(""),[m,h]=n.useState(((p=t[0])==null?void 0:p.id)||""),[b,w]=n.useState(!1),c=n.useMemo(()=>ss(r),[r]),g=a=>{var i;return(i=t.find(B=>B.id===a))==null?void 0:i.title},u=a=>{if(a.category){const i=t.find(B=>(B.title||"").trim()===a.category);return i?i.title:`תיווצר: ${a.category}`}return g(m)||"ללא קטגוריה"};async function x(){if(!c.length){k.error("הדביקו רשימת סלים");return}w(!0);try{await l(c,m||null)}catch(a){k.error((a==null?void 0:a.message)||"שגיאה")}finally{w(!1)}}return e.jsx(ae,{open:!0,onOpenChange:a=>!a&&s(),children:e.jsxs(le,{dir:"rtl",className:"max-w-2xl max-h-[92vh] overflow-y-auto",children:[e.jsx(ne,{children:e.jsx(re,{children:"הדבקת סלים מקובץ"})}),e.jsxs("p",{className:"text-xs text-slate-500 mb-3",children:["הדביקו שתי עמודות מאקסל — ",e.jsx("b",{children:"שם הסל"})," ו",e.jsx("b",{children:"קטגוריה"})," (רשות). שורה לכל סל."]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:e.jsx(K,{label:"קטגוריית ברירת מחדל (לשורות ללא קטגוריה)",children:e.jsxs(Se,{value:m,onChange:a=>h(a.target.value),children:[e.jsx("option",{value:"",children:"— ללא —"}),t.map(a=>e.jsx("option",{value:a.id,children:a.title},a.id))]})})}),e.jsx(K,{label:"הדבקה",children:e.jsx($e,{rows:7,value:r,onChange:a=>o(a.target.value),placeholder:`גינון	תחזוקה
62מזכיר
63תרבות	תרבות ופנאי`,className:"font-mono"})}),c.length>0&&e.jsxs("div",{className:"mt-2 rounded-xl border border-slate-200 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 bg-slate-50 text-xs font-bold text-slate-500 flex justify-between",children:[e.jsx("span",{children:"שם הסל"}),e.jsx("span",{children:"קטגוריה"})]}),e.jsx("div",{className:"max-h-44 overflow-y-auto divide-y divide-slate-50",children:c.map((a,i)=>e.jsxs("div",{className:"px-3 py-2 text-sm flex justify-between",children:[e.jsx("span",{className:"font-medium text-slate-800",children:a.name}),e.jsx("span",{className:"text-slate-500",children:u(a)})]},i))})]}),e.jsx(Ae,{onClose:s,onSubmit:x,saving:b,submitLabel:c.length?`צור ${c.length} סלים`:"צור סלים"})]})})}function rs({defaultBasket:t,initial:s,lockedSettlementId:l,settlements:r,baskets:o,allocations:m,onClose:h,onSave:b,onBulk:w}){var E,I,J;const c=!!s,g=!c&&!!l,[u,x]=n.useState((s==null?void 0:s.settlement_id)||l||""),[p,a]=n.useState("single"),[i,B]=n.useState((t==null?void 0:t.id)||(s==null?void 0:s.basket_id)||((E=o[0])==null?void 0:E.id)||""),[f,y]=n.useState((s==null?void 0:s.amount)??""),[N,A]=n.useState((s==null?void 0:s.notes)||""),[j,z]=n.useState(""),[R,L]=n.useState(!1),D=n.useMemo(()=>as(j),[j]),T=P=>o.find(G=>(G.title||"").trim()===(P||"").trim());async function H(){if(!u){k.error("בחרו יישוב");return}L(!0);try{if(p==="paste"&&!c){if(!D.length){k.error("הדביקו הקצאות"),L(!1);return}await w(u,D)}else{if(!i){k.error("בחרו סל"),L(!1);return}if(!(Number(f)>0)){k.error("הזינו סכום תקציב חוקי"),L(!1);return}const P=s||m.find(G=>G.basket_id===i&&G.settlement_id===u);await b({settlement_id:u,amount:f,notes:N},i,P||null)}}catch(P){k.error((P==null?void 0:P.message)||"שגיאה בשמירה")}finally{L(!1)}}return e.jsx(ae,{open:!0,onOpenChange:P=>!P&&h(),children:e.jsxs(le,{dir:"rtl",className:"max-w-lg max-h-[92vh] overflow-y-auto",children:[e.jsx(ne,{children:e.jsx(re,{children:c?"עריכת הקצאה":"הקצאת תקציב ליישוב"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(K,{label:"יישוב",children:c||g?e.jsx(Pe,{value:((I=r.find(P=>P.id===u))==null?void 0:I.name)||"",disabled:!0}):e.jsx(ts,{options:r,value:u,onChange:x})}),!c&&e.jsxs("div",{className:"inline-flex items-center gap-1 p-1 rounded-full bg-slate-100/80 border border-slate-200",children:[e.jsx("button",{onClick:()=>
63a("single"),className:`h-8 px-4 rounded-full text-sm font-bold ${p==="single"?"bg-white text-primary shadow-sm":"text-slate-500"}`,children:"הקצאה לסל"}),e.jsxs("button",{onClick:()=>a("paste"),className:`h-8 px-4 rounded-full text-sm font-bold inline-flex items-center gap-1 ${p==="paste"?"bg-white text-primary shadow-sm":"text-slate-500"}`,children:[e.jsx(ot,{className:"w-3.5 h-3.5"})," הדבקת הקצאות"]})]}),c||p==="single"?e.jsxs(e.Fragment,{children:[e.jsx(K,{label:"סל",children:c?e.jsx(Pe,{value:((J=o.find(P=>P.id===i))==null?void 0:J.title)||"",disabled:!0}):e.jsx(Se,{value:i,onChange:P=>B(P.target.value),children:o.map(P=>e.jsx("option",{value:P.id,children:P.title},P.id))})}),e.jsx(K,{label:"תקציב שנתי (₪)",children:e.jsx(Ie,{value:f,onChange:P=>y(P.target.value),placeholder:"0"})}),e.jsx(K,{label:"הערה ליישוב (רשות)",children:e.jsx($e,{rows:2,value:N,onChange:P=>A(P.target.value)})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-xs text-slate-500",children:["הדביקו שתי עמודות מאקסל — ",e.jsx("b",{children:"שם הסל"})," ו",e.jsx("b",{children:"סכום"}),". שורה לכל סל."]}),e.jsx($e,{rows:7,value:j,onChange:P=>z(P.target.value),placeholder:`גינון	215,000
64ניהול יישוב	50,000
65תרבות	130,000`,className:"font-mono"}),D.length>0&&e.jsxs("div",{className:"rounded-xl border border-slate-200 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 bg-slate-50 text-xs font-bold text-slate-500 flex justify-between",children:[e.jsx("span",{children:"סל"}),e.jsx("span",{children:"סכום"})]}),e.jsx("div",{className:"max-h-44 overflow-y-auto divide-y divide-slate-50",children:D.map((P,G)=>{const Q=T(P.name);return e.jsxs("div",{className:"px-3 py-2 text-sm flex justify-between",children:[e.jsxs("span",{className:Q?"font-medium text-slate-800":"text-rose-500",children:[P.name,!Q&&" · לא נמצא"]}),e.jsx("span",{className:"tabular-nums text-slate-600",children:_(P.amount)})]},G)})})]})]})]}),e.jsx(Ae,{onClose:h,onSubmit:H,saving:R,submitLabel:p==="paste"&&!c?D.length?`הקצאת ${D.length} סלים`:"הקצאה":"שמירה"})]})})}function is({councilId:t,roles:s,onClose:l,onChanged:r}){const[o,m]=n.useState(s),[h,b]=n.useState(!1);n.useEffect(()=>{m(s)},[s]);const w=()=>m(x=>[...x,{_new:!0,id:`tmp_${x.length}_${Math.round(performance.now())}`,title:"",can_override:!1,order:x.length}]),c=(x,p,a)=>m(i=>i.map(B=>B.id===x?{...B,[p]:a}:B));async function g(){const x=o.filter(p=>(p.title||"").trim());b(!0);try{await Promise.all(x.map((p,a)=>{const i={kibbutz_id:t,title:p.title.trim(),can_override:!!p.can_override,order:a,is_active:!0};return p._new?S.entities.MoatzaBudgetRole.create(i):S.entities.MoatzaBudgetRole.update(p.id,i)})),k.success("בעלי התפקידים נשמרו"),await r(),l()}catch(p){k.error((p==null?void 0:p.message)||"שגיאה בשמירה")}finally{b(!1)}}async function u(x){if(x._new){m(p=>p.filter(a=>a.id!==x.id));return}if(window.confirm(`למחוק את התפקיד "${x.title}"?`))try{await S.entities.MoatzaBudgetRole.delete(x.id),m(p=>p.filter(a=>a.id!==x.id)),await r()}catch(p){k.error((p==null?void 0:p.message)||"לא ניתן למחוק — התפקיד בשימוש בשרשרת אישורים")}}return e.jsx(ae,{open:!0,onOpenChange:x=>!x&&l(),children:e.jsxs(le,{dir:"rtl",className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(ne,{children:e.jsx(re,{children:"בעלי תפקידים לאישורים במועצה"})}),e.jsx("p",{className:"text-xs text-slate-500 -mt-1 mb-2",children:"התפקידים הקבועים במועצה (גזבר, מנהל אגף, מנהל מועצה…) המרכיבים את שרשראות האישורים בסלים. סמנו מי רשאי לאשר חריגה מיתרת סל."}),e.jsx("div",{className:"space-y-2",children:o.map(x=>e.jsxs("div",{className:"flex items-center gap-2 bg-white rounded-xl border border-slate-200 p-2",children:[e.jsx(kt,{className:"w-4 h-4 text-slate-400 flex-none"}),e.jsx("input",{value:x.title,onChange:p=>c(x.id,"title",p.target.value),placeholder:"שם התפקיד",className:`${ue} py-2`}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-slate-600 whitespace-nowrap px-1",children:[e.jsx("input",{type:"checkbox",checked:!!x.can_override,onChange:p=>c(x.id,"can_override",p.target.checked)})," אישור חריגה"]}),e.jsx("button",{onClick:()=>u(x),className:"w-8 h-8 rounded-lg hover:bg-rose-50 text-rose-500 flex items-center justify-center flex-none",children:e.jsx(X,{className:"w-4 h-4"})})]},x.id))}),e.jsxs("button",{onClick:w,className:"mt-3 inline-flex items-center gap-1 text-sm font-bold text-primary hover:underline",children:[e.jsx(de,{className:"w-4 h-4"})," הוספת תפקיד"]}),e.jsx(Ae,{onClose:l,onSubmit:g,saving:h,submitLabel:"שמירה"})]})})}function Ae({onClose:t,onSubmit:s,saving:l,disabled:r,submitLabel:o="שמירה"}){return e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-5",children:[e.jsxs(Re,{onClick:t,children:[e.jsx(Be,{className:"w-4 h-4"})," ביטול"]}),e.jsxs(Ye,{onClick:s,disabled:l||r,children:[l?e.jsx(Z,{className:"w-4 h-4 animate-spin"}):e.jsx(me,{className:"w-4 h-4"})," ",o]})]})}function $s(){return e.jsx(St,{moduleKey:"budget_baskets",children:e.jsx(Vt,{})})}
65export{$s as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.