1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-CcgsY5Wm.js","assets/index-BuF13C9R.js","assets/index-B811haHf.css"])))=>i.map(i=>d[i]); 2import{aQ as Xe,r as g,j as e,C as J,ar as _e,aT as ue,aU as ae,X as he,b as X,a7 as xe,T as ve,aF as ke,z as T,d as P,aA as Oe,aa as Je,bM as Qe,l as Ze,J as et,K as tt,bR as st,aE as at,O as lt,V as nt,y as Ue,P as qe,Q as rt,m as Ke,n as We,o as He,p as Ye,a3 as it}from"./index-BuF13C9R.js";import{i as y,P as me,p as pe,S as ot,C as De}from"./SupplierManager-DrrjKqYx.js";import{S as Ge}from"./scale-Ccy3cfrP.js";import{C as dt}from"./calendar-clock-Dg6I_-A7.js";import{S as $e}from"./sparkles-Bk9eJtR5.js";import{T as ye}from"./trending-up-BxObsxzL.js";import{T as Te}from"./trending-down-zZ5K-mvN.js";import{R as Be,T as Pe,L as ct,B as Le,C as xt}from"./generateCategoricalChart-D9kEchEU.js";import{B as mt,X as ut,Y as ht}from"./BarChart-BV6G5gJY.js";import{C as pt}from"./CartesianGrid-D3McakTz.js";import{P as bt,a as ft}from"./PieChart-knnFYOG7.js";import{F as gt}from"./file-spreadsheet-B8pSCGeX.js";import{P as jt}from"./printer-BwQiYGcP.js";import{C as Ve}from"./clipboard-paste-BN_8xhLJ.js";import{H as Nt}from"./history-DRsCxblu.js";import{P as vt}from"./pencil-CoE4mwuD.js";import{L as Re}from"./landmark-sD1r4OgG.js";import{T as we}from"./truck-Vc5srr9S.js";import{P as yt}from"./pen-line-CuBxLD5W.js";import{B as wt}from"./banknote-BAXkyBwn.js";import{U as _t}from"./upload-DeFZlL4S.js";import"./money-CmD9E_V-.js";import"./hash-DXwUI4fi.js";import"./save-C6cWy1UE.js";import"./isEqual-Bszk2vQ5.js";import"./tiny-invariant-BaFNuDhB.js";const kt=t=>{const s=String(t||"").trim().match(/^#?([0-9a-fA-F]{6})$/);return s?`FF${s[1].toUpperCase()}`:"FF1E3A8A"},$t=(t,s)=>{let a=String(t||"××××××").replace(/[\\/?*[\]:]/g," ").trim().slice(0,28)||"××××××",r=a,d=2;for(;s.has(r);)r=`${a.slice(0,25)} ${d++}`;return s.add(r),r};async function Ce({fileName:t="×××-תקצ××.xlsx",sheets:s=[]}){const a=(await Xe(async()=>{const{default:u}=await import("./exceljs.min-CcgsY5Wm.js").then(j=>j.e);return{default:u}},__vite__mapDeps([0,1,2]))).default,r=new a.Workbook;r.creator="Eshuv";const d=new Set;for(const u of s){const j=kt(u.color),v=u.columns||[],_=v.length||1,i=r.addWorksheet($t(u.name,d),{views:[{rightToLeft:!0,state:"frozen",ySplit:u.subtitle?4:3}]});v.forEach((b,E)=>{i.getColumn(E+1).width=b.width||18}),i.mergeCells(1,1,1,_);const k=i.getCell(1,1);k.value=u.title||u.name||"",k.font={bold:!0,size:16,color:{argb:"FFFFFFFF"}},k.alignment={horizontal:"right",vertical:"middle",readingOrder:"rtl"},k.fill={type:"pattern",pattern:"solid",fgColor:{argb:j}},i.getRow(1).height=28;let S=2;if(u.subtitle){i.mergeCells(2,1,2,_);const b=i.getCell(2,1);b.value=u.subtitle,b.font={size:11,color:{argb:"FF475569"}},b.alignment={horizontal:"right",vertical:"middle",readingOrder:"rtl"},b.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFF1F5F9"}},i.getRow(2).height=20,i.getRow(3).height=6,S=4}const h=i.getRow(S);if(v.forEach((b,E)=>{const w=h.getCell(E+1);w.value=b.header,w.font={bold:!0,size:11,color:{argb:"FFFFFFFF"}},w.alignment={horizontal:"center",vertical:"middle",wrapText:!0,readingOrder:"rtl"},w.fill={type:"pattern",pattern:"solid",fgColor:{argb:j}},w.border={bottom:{style:"thin",color:{argb:"FFCBD5E1"}}}}),h.height=22,(u.rows||[]).forEach((b,E)=>{const w=i.getRow(S+1+E);v.forEach(($,D)=>{const C=w.getCell(D+1);C.value=b[$.key]??"",$.numFmt&&typeof C.value=="number"&&(C.numFmt=$.numFmt),C.alignment={horizontal:typeof C.value=="number"?"left":"right",vertical:"middle",readingOrder:"rtl"},E%2===1&&(C.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFF8FAFC"}})})}),u.totals){const b=i.getRow(S+1+(u.rows||[]).length);v.forEach((E,w)=>{const $=b.getCell(w+1);$.value=u.totals[E.key]??(w===0?'ס×"×':""),E.numFmt&&typeof $.value=="number"&&($.numFmt=E.numFmt),$.font={bold:!0},$.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFE2E8F0"}},$.alignment={horizontal:typeof $.value=="number"?"left":"right",vertical:"middle",readingOrder:"rtl"}})}}const p=await r.xlsx.writeBuffer(),N=new Blob([p],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),m=URL.createObjectURL(N),l=document.createElement("a");l.href=m,l.download=t.endsWith(".xlsx")?t:`${t}.xlsx`,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(m),4e3)}function Se(t,s="××× ×ª×§×¦××"){if(!t)return;const a=window.open("","_blank","width=1024,height=768");if(!a)return;const r=Array.from(document.querySelectorAll('style, link[rel="stylesheet"]')).map(d=>d.tagName==="LINK"?`<link rel="stylesheet" href="${d.href}">`:`<style>${d.textContent||""}</style>`).join(` 3`);a.document.write(`<!doctype html><html dir="rtl" lang="he"><head><meta charset="utf-8"><title>${s}</title>${r} 4 <style> 5 @page { size: A4 landscape; margin: 12mm; } 6 body { background: #fff; font-family: system-ui, 'Segoe UI', Arial, sans-serif; padding: 16px; } 7 .no-print { display: none !important; } 8 table { page-break-inside: auto; } 9 tr { page-break-inside: avoid; } 10 </style></head><body>${t.outerHTML}</body></html>`),a.document.close(),a.focus(),setTimeout(()=>{try{a.print()}catch{}},350)}const H=new Date().getFullYear(),Ie=["#2563eb","#059669","#d97706","#7c3aed","#e11d48","#0891b2","#65a30d","#db2777","#f59e0b","#4f46e5"],Q=(t,s)=>s>0?Math.min(999,Math.round(t/s*100)):0,ie=new Date().toLocaleDateString("he-IL",{month:"long"}),V=Math.round((new Date().getMonth()+Math.min(1,new Date().getDate()/30))/12*100);function Ct({baskets:t=[],councilName:s,communityName:a,initialTab:r="balance"}){const[d,p]=g.useState(r),N=g.useMemo(()=>[...t].map(l=>{const u=Number(l.allocated||0),j=Number(l.paid||0),v=Number(l.reserved||0),_=Number(l.available??u-j-v),i=j+v;return{id:l.basket_id,title:l.basket_title||"ס×",category:l.category_title||"××× ×§×××ר××",allocated:u,paid:j,reserved:v,used:i,available:_,util:Q(i,u)}}).sort((l,u)=>u.allocated-l.allocated),[t]),m=g.useMemo(()=>N.reduce((l,u)=>(l.allocated+=u.allocated,l.paid+=u.paid,l.reserved+=u.reserved,l.used+=u.used,l.available+=u.available,l),{allocated:0,paid:0,reserved:0,used:0,available:0}),[N]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(be,{active:d==="balance",onClick:()=>p("balance"),icon:Ge,label:"×××× ××××"}),e.jsx(be,{active:d==="planning",onClick:()=>p("planning"),icon:dt,label:`ת×× ×× ××©× ×ª ${H+1}`}),e.jsx(be,{active:d==="ai",onClick:()=>p("ai"),icon:$e,label:"ת××× ×ת AI"})]}),d==="balance"&&e.jsx(St,{rows:N,totals:m,councilName:s,communityName:a}),d==="planning"&&e.jsx(Ft,{rows:N,totals:m,councilName:s,communityName:a}),d==="ai"&&e.jsx(Mt,{rows:N,totals:m,councilName:s,communityName:a})]})}function be({active:t,onClick:s,icon:a,label:r}
10){return e.jsxs("button",{onClick:s,className:`h-9 px-4 rounded-full text-sm font-bold inline-flex items-center gap-1.5 transition ${t?"bg-primary text-white":"bg-white border border-slate-200 text-slate-600 hover:border-slate-300"}`,children:[e.jsx(a,{className:"w-4 h-4"})," ",r]})}function Fe({onExcel:t,onPdf:s}){return e.jsxs("div",{className:"no-print flex items-center gap-2",children:[e.jsxs("button",{onClick:t,className:"h-9 px-3 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center gap-1.5 hover:bg-emerald-700",children:[e.jsx(gt,{className:"w-4 h-4"})," ××ר×× ×âExcel"]}),e.jsxs("button",{onClick:s,className:"h-9 px-3 rounded-full bg-white border border-slate-200 text-slate-700 text-sm font-bold inline-flex items-center gap-1.5 hover:bg-slate-50",children:[e.jsx(jt,{className:"w-4 h-4"})," ××צ×× ×âPDF"]})]})}function Me({title:t,subtitle:s}){return e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-xl font-extrabold text-slate-900",children:t}),e.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:s})]})}function St({rows:t,totals:s,councilName:a,communityName:r}){const d=g.useRef(null),p=`×××× ×ª×§×¦×× ×××× Â· ${r||""}`,N=`${a||""} · ××©× ×ª ${H} · ××פק ${new Date().toLocaleDateString("he-IL")}`,m=()=>Ce({fileName:`××××-תקצ××-${H}.xlsx`,sheets:[{name:`×××× ${H}`,title:p,subtitle:N,color:"#1e3a8a",columns:[{key:"category",header:"×§×××ר××",width:20},{key:"title",header:"×©× ×ס×",width:26},{key:"allocated",header:"תקצ×× ×©× ×ª×",width:16,numFmt:"#,##0.00"},{key:"paid",header:"ש×××",width:15,numFmt:"#,##0.00"},{key:"reserved",header:"ש××ר (פת××)",width:15,numFmt:"#,##0.00"},{key:"used",header:'ס×"× × ×צ××',width:15,numFmt:"#,##0.00"},{key:"available",header:"××ª×¨× ×××× ×",width:15,numFmt:"#,##0.00"},{key:"util",header:"× ×צ×× %",width:10,numFmt:'0"%"'}],rows:t.map(l=>({...l})),totals:{category:'ס×"×',title:"",allocated:s.allocated,paid:s.paid,reserved:s.reserved,used:s.used,available:s.available,util:Q(s.used,s.allocated)}}]});return e.jsxs("div",{className:"card-float p-5",children:[e.jsxs("div",{className:"no-print flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm font-bold text-slate-500",children:"×××× ××¡×¤× ×ר××× ××× ×¡×× ×תקצ××"}),e.jsx(Fe,{onExcel:m,onPdf:()=>Se(d.current,p)})]}),e.jsxs("div",{ref:d,children:[e.jsx(Me,{title:p,subtitle:N}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-slate-200",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-800 text-white text-xs",children:[e.jsx("th",{className:"text-right font-bold px-3 py-2.5",children:"×§×××ר××"}),e.jsx("th",{className:"text-right font-bold px-3 py-2.5",children:"×©× ×ס×"}),e.jsx("th",{className:"text-left font-bold px-3 py-2.5",children:"תקצ×× ×©× ×ª×"}),e.jsx("th",{className:"text-left font-bold px-3 py-2.5",children:"ש×××"}),e.jsx("th",{className:"text-left font-bold px-3 py-2.5",children:"ש××ר"}),e.jsx("th",{className:"text-left font-bold px-3 py-2.5",children:'ס×"× × ×צ××'}),e.jsx("th",{className:"text-left font-bold px-3 py-2.5",children:"××ª×¨× ×××× ×"}),e.jsx("th",{className:"text-center font-bold px-3 py-2.5 w-28",children:"× ×צ××"})]})}),e.jsx("tbody",{children:t.map((l,u)=>e.jsxs("tr",{className:u%2?"bg-slate-50/60":"",children:[e.jsx("td",{className:"px-3 py-2 text-slate-500",children:l.category}),e.jsx("td",{className:"px-3 py-2 font-bold text-slate-800",children:l.title}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums",children:y(l.allocated)}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums",children:y(l.paid)}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums text-slate-500",children:y(l.reserved)}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums",children:y(l.used)}),e.jsx("td",{className:`px-3 py-2 text-left tabular-nums font-bold ${l.available<0?"text-rose-600":"text-emerald-600"}`,children:y(l.available)}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1.5 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${l.util>=90?"bg-rose-500":l.util>=70?"bg-amber-500":"bg-emerald-500"}`,style:{width:`${Math.min(100,l.util)}%`}})}),e.jsxs("span",{className:"text-[11px] tabular-nums text-slate-500
10w-8 text-left",children:[l.util,"%"]})]})})]},l.id))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"bg-slate-100 font-extrabold",children:[e.jsxs("td",{className:"px-3 py-2.5",colSpan:2,children:['ס×"× (',t.length," ס×××)"]}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums",children:y(s.allocated)}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums",children:y(s.paid)}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums",children:y(s.reserved)}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums",children:y(s.used)}),e.jsx("td",{className:`px-3 py-2.5 text-left tabular-nums ${s.available<0?"text-rose-600":"text-emerald-700"}`,children:y(s.available)}),e.jsxs("td",{className:"px-3 py-2.5 text-center tabular-nums",children:[Q(s.used,s.allocated),"%"]})]})})]})})]})]})}function Ft({rows:t,totals:s,councilName:a,communityName:r}){const d=g.useRef(null),p=H+1,N=`ת×× ×× ×ª×§×¦×× ××©× ×ª ${p} · ${r||""}`,m=`${a||""} · ×××סס ×¢× ×ס××× ××תקצ×× ×©× ${H} · ××פק ${new Date().toLocaleDateString("he-IL")}`,l=s.allocated,u=()=>Ce({fileName:`ת×× ××-תקצ××-${p}.xlsx`,sheets:[{name:`ת×× ×× ${p}`,title:N,subtitle:m,color:"#7c3aed",columns:[{key:"category",header:"×§×××ר××",width:20},{key:"title",header:"×©× ×ס×",width:26},{key:"allocated",header:`תקצ×× ${H}`,width:16,numFmt:"#,##0.00"},{key:"used",header:"× ×צ×× ×פ××¢×",width:15,numFmt:"#,##0.00"},{key:"util",header:"× ×צ×× %",width:10,numFmt:'0"%"'},{key:"proposed",header:`××¦×¢× ×â${p}`,width:16,numFmt:"#,##0.00"}],rows:t.map(j=>({...j,proposed:j.allocated})),totals:{category:'ס×"×',title:"",allocated:s.allocated,used:s.used,util:Q(s.used,s.allocated),proposed:l}}]});return e.jsxs("div",{className:"card-float p-5",children:[e.jsxs("div",{className:"no-print flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm font-bold text-slate-500",children:"×ס×ס ×××שת תקצ×× ××©× × ×××× â × ×©×¢× ×¢× ×ס××× ××תקצ×× ×× ××××××"}),e.jsx(Fe,{onExcel:u,onPdf:()=>Se(d.current,N)})]}),e.jsxs("div",{ref:d,children:[e.jsx(Me,{title:N,subtitle:m}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-slate-200",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-violet-700 text-white text-xs",children:[e.jsx("th",{className:"text-right font-bold px-3 py-2.5",children:"×§×××ר××"}),e.jsx("th",{className:"text-right font-bold px-3 py-2.5",children:"×©× ×ס×"}),e.jsxs("th",{className:"text-left font-bold px-3 py-2.5",children:["תקצ×× ",H]}),e.jsx("th",{className:"text-left font-bold px-3 py-2.5",children:"× ×צ×× ×פ××¢×"}),e.jsx("th",{className:"text-center font-bold px-3 py-2.5",children:"× ×צ×× %"}),e.jsxs("th",{className:"text-left font-bold px-3 py-2.5",children:["××¦×¢× ×â",p]})]})}),e.jsx("tbody",{children:t.map((j,v)=>e.jsxs("tr",{className:v%2?"bg-slate-50/60":"",children:[e.jsx("td",{className:"px-3 py-2 text-slate-500",children:j.category}),e.jsx("td",{className:"px-3 py-2 font-bold text-slate-800",children:j.title}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums",children:y(j.allocated)}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums text-slate-500",children:y(j.used)}),e.jsxs("td",{className:"px-3 py-2 text-center tabular-nums",children:[j.util,"%"]}),e.jsx("td",{className:"px-3 py-2 text-left tabular-nums font-bold text-violet-700",children:y(j.allocated)})]},j.id))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"bg-slate-100 font-extrabold",children:[e.jsxs("td",{className:"px-3 py-2.5",colSpan:2,children:['ס×"× (',t.length," ס×××)"]}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums",children:y(s.allocated)}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums",children:y(s.used)}),e.jsxs("td",{className:"px-3 py-2.5 text-center tabular-nums",children:[Q(s.used,s.allocated),"%"]}),e.jsx("td",{className:"px-3 py-2.5 text-left tabular-nums text-violet-700",children:y(l)})]})})]})}),e.jsx("p",{className:"text-xs text-slate-400 mt-3",children:"ð¡ ×××¦×¢× ××©× × ×××× ××עתקת ××תקצ×× ××©× ×ª× ×× ×××× ××ס×ס ×¢×××× â × ××ª× ×ער×× ×ת ×ס××××× ××××©× ×××עצ×."})]})]})}function Mt({rows:t,totals:s,councilName:a,communityName:r}){const d=g.useRef(null),p=`ת××× ×ת תקצ×× Â· ${r||""}`,N=`${a||""} · ××©× ×ª ${H} · × ×ת×× ${t.length} ס××× Â· ××פק ${new Date().toLocaleDateString("he-IL")}`,m=Q(s.used,s.allocated),l=t.filter(h=>h.util>V+10&&h.allocated>0),u=t.filter(h=>h.util<Math.max(0,V-25)&&h.allocated>0),j=t.filter(h=>h.available<0),v=[...t].sort((h,b)=>b.used-h.used).slice(0,8),_=g.useMemo(()=>{const h={};return t.forEach(b=>{h[b.category]=(h[b.category]||0)+b.used}),Object.entries(h).map(([b,E])=>({name:b,value:E})).filter(b=>b.value>0).sort((b,E)=>E.value-b.value)},[t]),i=g.useMemo(()=>{const h=[];return h.push(m>=V+8?{tone:"amber",icon:ye,text:`×§×¦× ×× ×צ×× ××××× (${m}%) ××§××× ×ת ×ת×× ×× ××××ש ${ie}
10 (${V}%). ×××××¥ ××¢×§×× ××ר ×××ª×¨× ×¢× ×¡××£ ××©× ×.`}:m<=V-15?{tone:"blue",icon:Te,text:`×§×¦× ×× ×צ×× ××××× (${m}%) × ××× ××ת×× ×× ××××ש ${ie} (${V}%). ×ש ×ר×× ×ת×× ×× ××צ××ת ×ס××× ×ר×××× ××××.`}:{tone:"emerald",icon:J,text:`×§×¦× ×× ×צ×× ××××× (${m}%) ת××× ×ת ×ת×× ×× ×¢× ×××ש ${ie} (${V}%).`}),j.length&&h.push({tone:"rose",icon:_e,text:`${j.length} ס××× ××ר××× ×××תר×: ${j.slice(0,3).map(b=>b.title).join(", ")}${j.length>3?"â¦":""}. × ×רשת ×××× × ××× ×××עצ×.`}),l.length&&h.push({tone:"amber",icon:ye,text:`${l.length} ס××× ××§××××× ×ש××¢×ת×ת ×ת ××§×¦× ×צפ××: ${l.slice(0,3).map(b=>`${b.title} (${b.util}%)`).join(", ")}.`}),u.length&&h.push({tone:"blue",icon:Te,text:`${u.length} ס××× ×× ×צ×× × ×××: ${u.slice(0,3).map(b=>`${b.title} (${b.util}%)`).join(", ")}. ×פשר ×××××¥ ××צ××¢ ×× ××ס×× ×ª×§×¦××.`}),v[0]&&h.push({tone:"slate",icon:ue,text:`××¡× ×××××× ×××צ××: ${v[0].title} â ${y(v[0].used)} (${v[0].util}% ××תקצ××).`}),h},[m,j,l,u,v]),k=()=>Ce({fileName:`ת××× ×ת-תקצ××-${H}.xlsx`,sheets:[{name:"ת××× ×ת",title:p,subtitle:N,color:"#0891b2",columns:[{key:"k",header:"×××",width:30},{key:"v",header:"ער×",width:22}],rows:[{k:"תקצ×× ×©× ×ª× ××××",v:s.allocated},{k:'ס×"× × ××¦× (ש×××+ש××ר)',v:s.used},{k:"ש×××",v:s.paid},{k:"××ª×¨× ×××× ×",v:s.available},{k:"×××× × ×צ×× ××××",v:`${m}%`},{k:`×§×¦× ×¦×¤×× ××××ש ${ie}`,v:`${V}%`},{k:"ס××× ××ר×××",v:j.length},{k:"ס××× ××¢× ×קצ×",v:l.length},{k:"ס××× ×× ×צ×× × ×××",v:u.length}]},{name:"× ×צ×× ××¤× ×¡×",color:"#0891b2",columns:[{key:"title",header:"ס×",width:26},{key:"category",header:"×§×××ר××",width:20},{key:"allocated",header:"תקצ××",width:15,numFmt:"#,##0.00"},{key:"used",header:"× ×צ×",width:15,numFmt:"#,##0.00"},{key:"util",header:"× ×צ×× %",width:10,numFmt:'0"%"'}],rows:t.map(h=>({...h}))}]}),S=v.map(h=>({name:h.title.length>10?`${h.title.slice(0,10)}â¦`:h.title,תקצ××:h.allocated,× ×צ×:h.used}));return e.jsxs("div",{className:"card-float p-5",children:[e.jsxs("div",{className:"no-print flex items-center justify-between mb-3",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-500 inline-flex items-center gap-1.5",children:[e.jsx($e,{className:"w-4 h-4 text-cyan-500"})," × ×ת×× ×ª××× ×ת ×××××××"]}),e.jsx(Fe,{onExcel:k,onPdf:()=>Se(d.current,p)})]}),e.jsxs("div",{ref:d,className:"space-y-4",children:[e.jsx(Me,{title:p,subtitle:N}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(oe,{tone:"blue",label:"תקצ×× ×©× ×ª×",value:y(s.allocated)}),e.jsx(oe,{tone:"cyan",label:"×××× × ×צ××",value:`${m}%`,sub:`×§×¦× ×¦×¤×× ${V}%`}),e.jsx(oe,{tone:"emerald",label:"××ª×¨× ×××× ×",value:y(s.available)}),e.jsx(oe,{tone:j.length?"rose":"slate",label:"ס××× ××ר×××",value:j.length,sub:`${l.length} ××¢× ×קצ×`})]}),e.jsx("div",{className:"space-y-2",children:i.map((h,b)=>{const E=h.icon,w={amber:"bg-amber-50 text-amber-800 border-amber-100",rose:"bg-rose-50 text-rose-800 border-rose-100",emerald:"bg-emerald-50 text-emerald-800 border-emerald-100",blue:"bg-blue-50 text-blue-800 border-blue-100",slate:"bg-slate-50 text-slate-700 border-slate-100"}[h.tone];return e.jsxs("div",{className:`flex items-start gap-2 rounded-xl border px-3 py-2.5 text-sm ${w}`,children:[e.jsx(E,{className:"w-4 h-4 mt-0.5 flex-none"}),e.jsx("span",{children:h.text})]},b)})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-xl border border-slate-200 p-3",children:[e.jsx("div",{className:"text-sm font-bold text-slate-700 mb-2",children:"תקצ×× ××× × ×צ×× â ס××× ×××××××"}),e.jsx("div",{style:{width:"100%",height:260},children:e.jsx(Be,{children:e.jsxs(mt,{data:S,margin:{top:8,right:8,bottom:8,left:8},children:[e.jsx(pt,{strokeDasharray:"3 3",stroke:"#eef2f6"}),e.jsx(ut,{dataKey:"name",tick:{fontSize:11},interval:0,angle:-20,textAnchor:"end",height:54}),e.jsx(ht,{tick:{fontSize:11}
10,tickFormatter:h=>h>=1e3?`${Math.round(h/1e3)}k`:h}),e.jsx(Pe,{formatter:h=>y(h)}),e.jsx(ct,{}),e.jsx(Le,{dataKey:"תקצ××",fill:"#93c5fd",radius:[4,4,0,0]}),e.jsx(Le,{dataKey:"× ×צ×",fill:"#2563eb",radius:[4,4,0,0]})]})})})]}),e.jsxs("div",{className:"rounded-xl border border-slate-200 p-3",children:[e.jsx("div",{className:"text-sm font-bold text-slate-700 mb-2",children:"×תפ×××ת ××צ×× ××¤× ×§×××ר××"}),e.jsx("div",{style:{width:"100%",height:260},children:e.jsx(Be,{children:e.jsxs(bt,{children:[e.jsx(ft,{data:_,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:90,label:h=>h.name,children:_.map((h,b)=>e.jsx(xt,{fill:Ie[b%Ie.length]},b))}),e.jsx(Pe,{formatter:h=>y(h)})]})})})]})]})]})]})}function oe({tone:t,label:s,value:a,sub:r}){const d={blue:"text-blue-600",cyan:"text-cyan-600",emerald:"text-emerald-600",rose:"text-rose-600",slate:"text-slate-700"}[t];return e.jsxs("div",{className:"rounded-xl border border-slate-200 p-3.5",children:[e.jsx("div",{className:`text-2xl font-extrabold tabular-nums ${d}`,children:a}),e.jsx("div",{className:"text-xs text-slate-500 mt-1",children:s}),r&&e.jsx("div",{className:"text-[11px] text-slate-400 mt-0.5",children:r})]})}const Et=t=>t?new Date(t).toLocaleDateString("he-IL",{day:"2-digit",month:"2-digit",year:"numeric"}):"";function Dt(t){const s=String(t||"").split(/\r?\n/).map(r=>r.replace(/\s+$/,"")).filter(r=>r.trim()),a=[];for(const r of s){const p=(r.includes(" ")?r.split(" "):r.split(/ {2,}|,/)).map(v=>v==null?"":String(v).trim()),N=p[0]||"";if(!N||/^(ש×\s*תקצ××|×©× ×תקצ××|תקצ××)$/.test(N)&&/ת×××ר|×ש××× ×ת|ס×××/.test(r))continue;const m=p[1]||"",l=p.slice(2);let u=0;for(let v=l.length-1;v>=0;v--){const _=String(l[v]).replace(/[,\sâª]/g,"");if(_!==""&&!Number.isNaN(Number(_))){u=Number(_),l.splice(v,1);break}}const j=l.find(v=>/^\d{5,}$/.test(String(v).replace(/\s/g,"")))||"";a.push({budget_name:N,description:m,invoice_no:j,amount:u})}return a}function Tt(t,s){const a=String(t||"").trim();if(!a)return"";const r=s.find(N=>(N.basket_title||"").trim()===a);if(r)return r.basket_id;const d=s.find(N=>(N.basket_title||"").includes(a)||a.includes((N.basket_title||"").trim()));if(d)return d.basket_id;const p=s.find(N=>(N.category_title||"").trim()===a);return p?p.basket_id:""}function Bt({baskets:t=[],expenses:s=[],onChanged:a}){const[r,d]=g.useState("paste"),[p,N]=g.useState(""),[m,l]=g.useState([]),[u,j]=g.useState(!1),[v,_]=g.useState(null),[i,k]=g.useState(null),S=c=>{var n;return((n=t.find(f=>f.basket_id===c))==null?void 0:n.basket_title)||""};function h(){const c=Dt(p);if(!c.length){T.error("×× ×××× ×©×ר×ת â ×××××§× ×××× ××קס×");return}l(c.map(n=>({...n,basket_id:Tt(n.budget_name,t),paid:!1}))),d("review")}const b=(c,n,f)=>l(O=>O.map((R,U)=>U===c?{...R,[n]:f}:R)),E=c=>l(n=>n.filter((f,O)=>O!==c)),w=m.filter(c=>c.basket_id).length,$=m.reduce((c,n)=>c+(Number(n.amount)||0),0);async function D(){var n;const c=m.filter(f=>f.basket_id);if(!c.length){T.error("×ש ××פ×ת ×פ××ת ש××¨× ××ת ××¡× ×ª×§×¦××");return}j(!0);try{const f=await P.functions.invoke("moatzaBudgetExpenseImport",{action:"import",rows:c.map(R=>({basket_id:R.basket_id,budget_name:R.budget_name,description:R.description,invoice_no:R.invoice_no,amount:Number(R.amount)||0,paid:!!R.paid}))}),O=((n=f==null?void 0:f.data)==null?void 0:n.imported)??(f==null?void 0:f.imported)??c.length;T.success(`× ××¢× × ${O} ××צ××ת ×ס×××`),N(""),l([]),d("paste"),await(a==null?void 0:a())}catch(f){T.error((f==null?void 0:f.message)||"ש×××× ×××¢×× ×ª ×××צ××ת")}finally{j(!1)}}const C=g.useMemo(()=>{const c={};for(const n of s){const f=n.request_no||n.id;(c[f]=c[f]||{key:f,rows:[],at:n.submitted_at||n.created_date,total:0,paid:0}).rows.push(n),c[f].total+=Number(n.amount)||0,n.status==="paid"&&(c[f].paid+=Number(n.amount)||0),n.submitted_at&&(!c[f].at||n.submitted_at<c[f].at)&&(c[f].at=n.submitted_at)}return Object.values(c).sort((n,f)=>String(f.at||"").localeCompare(String(n.at||"")))},[s]);async function I(c){if(window.confirm(`×××××§ ×ת ×§×××¥ ×××צ××ת (${c.rows.length} ש×ר×ת)? ×פע××× ×ª×©×רר ×ת ×תקצ×× ×©× ×צ×.`)){k(c.key);try{await P.functions.invoke("moatzaBudgetExpenseImport",{action:"delete_batch",batch_id:c.key}),T.success("×§×××¥ ×××צ××ת × ×××§"),await(a==null?void 0:a())}catch(n){T.error((n==null?void 0:n.message)||"ש×××× ×××××§×")}finally{k(null)}}}async function Y(c){if(window.confirm("×××××§ ש×רת ××צ×× ××?")){k(c.id);try{await P.functions.invoke("moatzaBudgetExpenseImport",{action:"delete",charge_id:c.id}),T.success("×××צ×× × ×××§×"),await(a==null?void 0:a())}catch(n){T.error((n==null?void 0:n.message)||"ש×××× ×××××§×")}finally{k(null)}}}async function z(c){k(c.id);try{await P.functions.invoke("moatzaBudgetExpenseImport",{action:"update",charge_id:c.id,patch:{paid:c.status!=="paid"}}),await(a==null?void 0:a())}catch(n){T.error((n==null?void 0:n.message)||"ש××××")}finally{k(null)}}return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"card-float p-5",children:r==="paste"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"w-9 h-9 rounded-xl bg-emerald-50 text-emerald-600 flex items-center justify-center",children:e.jsx(Ve,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-extrabold text-slate-900",children:"×××קת ××צ××ת ××קס×"}),e.jsx("p",{className:"text-xs text-slate-500",children:"4 ×¢××××ת: ×©× ×ª×§×¦×× Â· ת×××ר · ×ס׳ ×ש××× ×ת · ס××× ×תש×××. ×××¢×× × ×ת×צעת ×ש×ר×ת ×ס××× â ××× ×¦××¨× ×××ש×ר ×××עצ×."})]})]}),e.jsx("textarea",{value:p,onChange:c=>N(c.target.value),rows:8,dir:"rtl",placeholder:`ר×× ×§×××× ×ש××רת ×× ××ר 12,500.00 11ת×××¨× ×××ר ר××××ת - פ×ר××ר 2026 400290608 3,605.23`,className:"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 font-mono"}),e.jsx("div",{className:"flex justify-end mt-3",children:e.jsxs("button",{onClick:h,className:"h-10 px-5 rounded-full bg-primary text-white text-sm font-bold inline-flex items-center gap-1.5 hover:brightness-110",children:[e.jsx(ae,{className:"w-4 h-4 rotate-180"})," ×××©× ×ער××× ×××פ××"]})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base font-extrabold text-slate-900",children:["ער××× ×××פ×× Â· ",m.length," ש×ר×ת"]}),e.jsxs("p",{className:"text-xs text-slate-500",children:["××פ×× ×ס×, ס×××, ס×××ס תש××× â × ××ª× ×ער×× ×× ×©×ר×. ",w,"/",m.length,' ×××פ×ת · ס×"× ',y($)]})]}),e.jsxs("button",{onClick:()=>{d("paste")},className:"text-sm font-bold text-slate-500 hover:text-slate-700 inline-flex items-center gap-1",children:[e.jsx(ae,{className:"w-4 h-4"})," ×××¨× ×××××§×"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-slate-200",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50 text-xs text-slate-500",children:[e.jsx("th",{className:"text-right font-bold px-2 py-2",children:"×©× ×ª×§×¦×× (××§×ר)"}),e.jsx("th",{className:"text-right font-bold px-2 py-2",children:"ת×××ר"}),e.jsx("th",{className:"text-right font-bold px-2 py-2",children:"×ש××× ×ת"}),e.jsx("th",{className:"text-right font-bold px-2 py-2 w-28",children:"ס×××"}),e.jsx("th",{className:"text-right font-bold px-2 py-2 w-48",children:"××פ×× ×ס×"}),e.jsx("th",{className:"text-center font-bold px-2 py-2 w-20",children:"ש×××"}),e.jsx("th",{className:"px-2 py-2"})]})}),e.jsx("tbody",{children:m.map((c,n)=>e.jsxs("tr",{className:`border-t border-slate-50 ${c.basket_id?"":"bg-amber-50/40"}`,children:[e.jsx("td",{className:"px-2 py-1.5",children:e.jsx("input",{value:c.budget_name,onChange:f=>b(n,"budget_name",f.target.value),className:W})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsx("input",{value:c.description,onChange:f=>b(n,"description",f.target.value),className:W})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsx("input",{value:c.invoice_no,onChange:f=>b(n,"invoice_no",f.target.value),className:`${W} w-24`})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsx("input",{value:c.amount,onChange:f=>b(n,"amount",f.target.value),inputMode:"decimal",className:`${W} text-left tabular-nums`})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsxs("select",{value:c.basket_id,onChange:f=>b(n,"basket_id",f.target.value),className:`${W} ${c.basket_id?"":"text-amber-700"}`,children:[e.jsx("option",{value:"",children:"â ×××¨× ×¡× â"}),t.map(f=>e.jsx("option",{value:f.basket_id,children:f.basket_title},f.basket_id))]})}),e.jsx("td",{className:"px-2 py-1.5 text-center",children:e.jsx("button",{onClick:()=>b(n,"paid",!c.paid),className:`w-16 h-7 rounded-full text-[11px] font-bold ${c.paid?"bg-emerald-100 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:c.paid?"ש×××":"×תש×××"})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsx("button",{onClick:()=>E(n),className:"w-7 h-7 rounded-lg hover:bg-rose-50 text-rose-500 flex items-center justify-center",children:e.jsx(he,{className:"w-4 h-4"})})})]},n))})]})}),w<m.length&&e.jsxs("p",{className:"text-xs text-amber-700 mt-2 flex items-center gap-1",children:[e.jsx(_e,{className:"w-3.5 h-3.5"})," ש×ר×ת ××× ××פ×× ××¡× ×× ××××¢× × â ××¤× ×××ª× ×× ×ס×ר×."]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-3",children:[e.jsx("button",{onClick:()=>{d("paste")}
11,className:"h-10 px-4 rounded-full bg-white border border-slate-200 text-slate-700 text-sm font-semibold hover:bg-slate-50",children:"×××××"}),e.jsxs("button",{onClick:D,disabled:u||!w,className:"h-10 px-5 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center gap-1.5 hover:bg-emerald-700 disabled:opacity-50",children:[u?e.jsx(X,{className:"w-4 h-4 animate-spin"}):e.jsx(J,{className:"w-4 h-4"})," ××¢×× ×ª ",w," ××צ××ת ×ס×××"]})]})]})}),e.jsxs("div",{className:"card-float p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"w-8 h-8 rounded-lg bg-slate-100 text-slate-500 flex items-center justify-center",children:e.jsx(Nt,{className:"w-4 h-4"})}),e.jsxs("h3",{className:"text-sm font-extrabold text-slate-800",children:["××ס××ר××ת ××¢×× ×ת",C.length?` (${C.length})`:""]})]}),C.length===0?e.jsx("div",{className:"text-center text-sm text-slate-400 py-8",children:"××¨× × ××¢× × ××צ××ת ××§×××¥"}):e.jsx("div",{className:"space-y-3",children:C.map(c=>e.jsxs("details",{className:"rounded-xl border border-slate-200 overflow-hidden group",children:[e.jsxs("summary",{className:"flex items-center justify-between gap-2 px-4 py-3 cursor-pointer hover:bg-slate-50 list-none",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(xe,{className:"w-4 h-4 text-slate-400"})," ×§×××¥ ××צ××ת · ",Et(c.at)]}),e.jsxs("div",{className:"text-xs text-slate-500 mt-0.5",children:[c.rows.length,' ש×ר×ת · ס×"× ',y(c.total)," · ש××× ",y(c.paid)]})]}),e.jsxs("button",{onClick:n=>{n.preventDefault(),I(c)},disabled:i===c.key,className:"h-8 px-3 rounded-full bg-white border border-rose-200 text-rose-600 text-xs font-bold inline-flex items-center gap-1 hover:bg-rose-50 flex-none",children:[i===c.key?e.jsx(X,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ve,{className:"w-3.5 h-3.5"})," ×××קת ××§×××¥"]})]}),e.jsx("div",{className:"border-t border-slate-100 divide-y divide-slate-50",children:c.rows.map(n=>e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm font-bold text-slate-800 truncate",children:n.purpose||"â"}),e.jsxs("div",{className:"text-[11px] text-slate-400 truncate flex items-center gap-1",children:[e.jsx(ue,{className:"w-3 h-3"})," ",S(n.basket_id),n.notes?` · ××§×ר: ${n.notes}`:"",n.invoice_no?` · ×ש××× ×ת ${n.invoice_no}`:""]})]}),e.jsx("span",{className:"text-sm font-extrabold tabular-nums text-slate-900 flex-none",children:y(n.amount)}),e.jsxs("button",{onClick:()=>z(n),disabled:i===n.id,className:`w-16 h-7 rounded-full text-[11px] font-bold flex-none inline-flex items-center justify-center gap-1 ${n.status==="paid"?"bg-emerald-100 text-emerald-700":"bg-amber-50 text-amber-700"}`,children:[i===n.id?e.jsx(X,{className:"w-3 h-3 animate-spin"}):n.status==="paid"?e.jsx(J,{className:"w-3 h-3"}):e.jsx(ke,{className:"w-3 h-3"}),n.status==="paid"?"ש×××":"×תש×××"]}),e.jsx("button",{onClick:()=>_(n),title:"ער×××",className:"w-7 h-7 rounded-lg hover:bg-slate-100 text-slate-500 flex items-center justify-center flex-none",children:e.jsx(vt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>Y(n),title:"××××§×",className:"w-7 h-7 rounded-lg hover:bg-rose-50 text-rose-500 flex items-center justify-center flex-none",children:e.jsx(ve,{className:"w-4 h-4"})})]},n.id))})]},c.key))})]}),v&&e.jsx(Pt,{expense:v,baskets:t,onClose:()=>_(null),onSaved:async()=>{_(null),await(a==null?void 0:a())}})]})}const W="w-full border border-slate-200 rounded-lg px-2 py-1.5 text-sm bg-white focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20";function Pt({expense:t,baskets:s,onClose:a,onSaved:r}){const[d,p]=g.useState({description:t.purpose||"",invoice_no:t.invoice_no||"",budget_name:t.notes||"",amount:t.amount??"",basket_id:t.basket_id||"",paid:t.status==="paid"}),[N,m]=g.useState(!1),l=j=>v=>p(_=>({..._,[j]:v.target.value}));async function u(){if(!d.basket_id){T.error("×××¨× ×¡×");return}if(!(Number(d.amount)>
11=0)){T.error("ס××× ×× ×ª×§××");return}m(!0);try{await P.functions.invoke("moatzaBudgetExpenseImport",{action:"update",charge_id:t.id,patch:{description:d.description,invoice_no:d.invoice_no,budget_name:d.budget_name,amount:Number(d.amount)||0,basket_id:d.basket_id,paid:!!d.paid}}),T.success("×××צ×× ×¢×××× ×"),await r()}catch(j){T.error((j==null?void 0:j.message)||"ש×××× ××¢××××")}finally{m(!1)}}return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",onClick:a,children:e.jsxs("div",{dir:"rtl",className:"bg-white rounded-2xl shadow-xl w-full max-w-md p-5",onClick:j=>j.stopPropagation(),children:[e.jsx("h3",{className:"text-base font-extrabold text-slate-900 mb-3",children:"ער××ת ××צ××"}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsx(te,{label:"ת×××ר",children:e.jsx("input",{value:d.description,onChange:l("description"),className:W})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(te,{label:"×ס׳ ×ש××× ×ת",children:e.jsx("input",{value:d.invoice_no,onChange:l("invoice_no"),className:W})}),e.jsx(te,{label:"ס××× (âª)",children:e.jsx("input",{value:d.amount,onChange:l("amount"),inputMode:"decimal",className:`${W} tabular-nums`})})]}),e.jsx(te,{label:"×©× ×ª×§×¦×× (××§×ר)",children:e.jsx("input",{value:d.budget_name,onChange:l("budget_name"),className:W})}),e.jsx(te,{label:"ס×",children:e.jsxs("select",{value:d.basket_id,onChange:l("basket_id"),className:W,children:[e.jsx("option",{value:"",children:"â ×××¨× ×¡× â"}),s.map(j=>e.jsx("option",{value:j.basket_id,children:j.basket_title},j.basket_id))]})}),e.jsxs("label",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 pt-1",children:[e.jsx("input",{type:"checkbox",checked:d.paid,onChange:j=>p(v=>({...v,paid:j.target.checked}))})," ס××× ×ש×××"]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-4",children:[e.jsx("button",{onClick:a,className:"h-10 px-4 rounded-full bg-white border border-slate-200 text-slate-700 text-sm font-semibold hover:bg-slate-50",children:"×××××"}),e.jsxs("button",{onClick:u,disabled:N,className:"h-10 px-5 rounded-full bg-primary text-white text-sm font-bold inline-flex items-center gap-1.5 hover:brightness-110 disabled:opacity-50",children:[N?e.jsx(X,{className:"w-4 h-4 animate-spin"}):e.jsx(Oe,{className:"w-4 h-4"})," ש××ר×"]})]})]})})}function te({label:t,children:s}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold text-slate-500 mb-1 block",children:t}),s]})}const fe=new Date().getFullYear(),Lt={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"},de=t=>t?new Date(t).toLocaleString("he-IL",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"}):"";async function Rt(t){const s=[];for(const a of t){const{file_url:r}=await P.integrations.Core.UploadFile({file:a});r&&s.push({url:r,name:a.name})}return s}function Ae({status:t}){const s=De[t]||De.draft;return e.jsx("span",{className:`text-[11px] font-bold rounded-full px-2.5 py-1 ${Lt[s.tone]}`,children:s.label})}function It({pct:t,tone:s}){const a=s==="rose"?"#e11d48":s==="amber"?"#d97706":"#2563eb";return e.jsx("div",{className:"w-28 h-28 rounded-full mx-auto grid place-items-center",style:{background:`conic-gradient(${a} ${t}%, #eef2f6 0)`},children:e.jsx("div",{className:"w-[86px] h-[86px] rounded-full bg-white grid place-items-center text-center"})})}function At({totals:t}){const s=Number(t.allocated||0),a=Number(t.paid||0)+Number(t.reserved||0),r=s>0?Math.min(100,Math.round(a/s*100)):0,d=new Date,p=d.toLocaleDateString("he-IL",{month:"long"}),N=Math.round((d.getMonth()+Math.min(1,d.getDate()/30))/12*100),m=r>=90?"rose":r>=70?"amber":"emerald",l=m==="rose"?"#e11d48":m==="amber"?"#d97706":"#059669",u=m==="rose"?"text-rose-600":m==="amber"?"text-amber-600":"text-emerald-600",j=120,v=120,_=96,i=20,k=C=>Math.PI+C/100*Math.PI,S=(C,I)=>[j+I*Math.cos(k(C)),v+I*Math.sin(k(C))],h=C=>
11{const[I,Y]=S(0,_),[z,c]=S(Math.max(.001,C),_);return`M ${I} ${Y} A ${_} ${_} 0 0 1 ${z} ${c}`},[b,E]=S(N,_-i/2-4),[w,$]=S(N,_+i/2+4),D=r>N+3;return e.jsxs("div",{className:"card-float p-5 flex flex-col sm:flex-row items-center gap-6",children:[e.jsxs("div",{className:"relative flex-none",children:[e.jsxs("svg",{width:"240",height:"140",viewBox:"0 0 240 140",className:"overflow-visible",children:[e.jsx("path",{d:h(100),fill:"none",stroke:"#eef2f6",strokeWidth:i,strokeLinecap:"round"}),r>0&&e.jsx("path",{d:h(r),fill:"none",stroke:l,strokeWidth:i,strokeLinecap:"round"}),e.jsx("line",{x1:b,y1:E,x2:w,y2:$,stroke:"#0f172a",strokeWidth:"2.5",strokeLinecap:"round"})]}),e.jsxs("div",{className:"absolute inset-x-0 bottom-1 text-center",children:[e.jsx("div",{className:`text-2xl font-extrabold leading-none ${t.available<0?"text-rose-600":"text-slate-900"}`,children:y(t.available)}),e.jsx("div",{className:"text-[11px] text-slate-400 mt-1",children:"××ª×¨× ×××× ×"})]})]}),e.jsxs("div",{className:"flex-1 min-w-0 w-full space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-bold text-slate-600",children:"× ×צ×× ××תקצ×× ××©× ×ª×"}),e.jsxs("span",{className:`text-lg font-extrabold tabular-nums ${u}`,children:[r,"%"]})]}),e.jsxs("div",{className:"h-2.5 rounded-full bg-slate-100 overflow-hidden relative",children:[e.jsx("div",{className:"h-full rounded-full",style:{width:`${r}%`,background:l}}),e.jsx("span",{className:"absolute top-1/2 -translate-y-1/2 w-[3px] h-4 bg-slate-800 rounded",style:{right:`calc(${N}% - 1.5px)`}})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[e.jsxs("span",{children:["תקצ×× ×©× ×ª× ",y(s)]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-3 h-[3px] bg-slate-800 inline-block rounded"})," ×§×¦× ×¦×¤×× Â· ",p," ",N,"%"]})]}),e.jsx("div",{className:`text-xs font-semibold rounded-xl px-3 py-2 ${D?"bg-amber-50 text-amber-700":"bg-emerald-50 text-emerald-700"}`,children:D?`â¡ ×§×¦× ×× ×צ×× ×××ר ××צפ×× ××××ש ${p} â ×××××¥ ××¢×§×× ××ר ××תר×.`:`â ×§×¦× ×× ×צ×× ×ª××× ×ת ×ת×× ×× ×¢× ××××ש ${p}.`})]})]})}function zt(){var Ee;const{id:t}=Je(),{kibbutz:s}=((Ee=Qe)==null?void 0:Ee())||{},a=(s==null?void 0:s.parent_id)||null,[r,d]=g.useState(null),[p,N]=g.useState(""),[m,l]=g.useState([]),[u,j]=g.useState([]),[v,_]=g.useState([]),[i,k]=g.useState([]),[S,h]=g.useState(!0),[b,E]=g.useState(null),[w,$]=g.useState("baskets"),[D,C]=g.useState("all"),[I,Y]=g.useState("balance"),[z,c]=g.useState("");g.useEffect(()=>{if(!a)return;let o=!1;return P.entities.KibbutzPublic.get(a).then(M=>{o||d(M||null)}).catch(()=>{}),P.entities.KibbutzWebsiteLayout.filter({kibbutz_id:a}).then(M=>{var B;o||N(((B=M==null?void 0:M[0])==null?void 0:B.logo)||"")}).catch(()=>{}),()=>{o=!0}},[a]);const n=g.useCallback(async()=>{if(t){h(!0);try{const[o,M,B,ee]=await Promise.all([P.rpc("moatza_budget_settlement_baskets",{p_settlement_id:t,p_fiscal_year:fe}).catch(()=>[]),P.entities.MoatzaBudgetCharge.filter({settlement_id:t},"-created_date",2e3).catch(()=>[]),P.entities.MoatzaBudgetApproval.filter({settlement_id:t},"step_order",5e3).catch(()=>[]),P.entities.MoatzaBudgetPayment.filter({settlement_id:t},"-created_date",5e3).catch(()=>[])]);l(o||[]),j(M||[]),_(B||[]),k(ee||[])}finally{h(!1)}}},[t]);g.useEffect(()=>{n()},[n]);const f=g.useMemo(()=>u.filter(o=>o.source!=="manager_expense"),[u]),O=g.useMemo(()=>u.filter(o=>o.source==="manager_expense"),[u]),R=g.useMemo(()=>{const o={};for(const M of f)me.includes(M.status)&&(o[M.basket_id]=(o[M.basket_id]||0)+1);return o},[f]),U=g.useMemo(()=>m.reduce((o,M)=>(o.allocated+=Number(M.allocated||0),o.paid+=Number(M.paid||0),o.reserved+=Number(M.reserved||0),o.available+=Number(M.available||0),o),{allocated:0,paid:0,reserved:0,available:0}),[m]),Z=g.useMemo(()=>f.filter(o=>me.includes(o.status)).length,[f]),le=g.useMemo(()=>f.filter(o=>pe(o.id,i)>0).length,[f,i]),x=g.useMemo(()=>{const o=z.trim();return o?m.filter(M=>`${M.basket_title||""} ${M.category_title||""}`.includes(o)):m},[m,z]),F=g.useMemo(()=>D==="pending"?f.filter(o=>me.includes(o.status)):D==="paid"?f.filter(o=>pe(o.id,i)>0):f,[f,D,i]),L=o=>{C(o),$("requests")};async function A(o,M,B){const ee={council_id:a,settlement_id:t,allocation_id:B.allocation_id,basket_id:B.basket_id,amount:Number(o.amount)||0,purpose:o.purpose,vendor_name:o.vendor_name,vendor_taxid:o.vendor_taxid,supplier_id:o.supplier_id||null,notes:o.notes,status:"submitted",current_step:0,is_override:(Number(o.amount)||0)>Number(B.available||0),submitted_at:new Date().toISOString()},re=await P.entities.MoatzaBudgetCharge.create(ee);M.length&&await Promise.all(M.map(G=>P.entities.MoatzaBudgetChargeDoc.create({council_id:a,settlement_id:t,request_id:re.id,file_url:G.url,file_name:G.name,title:G.title||G.name,description:G.description||null,doc_type:G.doc_type||"other"}))),T.success("×××§×©× ××××©× ××××¢××¨× ×××ש×ר ×××עצ×"),E(null),await n()}const q=p||(r==null?void 0:r.logo)||"",ne=(r==null?void 0:r.name)||"××××¢×¦× ×©×××";return a?e.jsxs("div",{dir:"rtl",className:"space-y-4",children:[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 gap-5",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 overflow-hidden",children:q?e.jsx("img",{src:q,alt:"",className:"max-h-12 max-w-[85%] object-contain"}):e.jsx(Re,{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-[11px] font-bold text-primary bg-primary/10 rounded-full px-3 py-1 mb-1.5",children:[e.jsx(Ze,{className:"w-3.5 h-3.5"})," ",ne]}),e.jsxs("h1",{className:"text-2xl font-extrabold text-foreground leading-tight truncate",children:["ס×× ×ª×§×¦×× ",(s==null?void 0:s.name)||""," · ××©× ×ª ",fe]}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"××ª×¨× ×××× ××ת · ××שת ×קש×ת ×××× ××ס×××× Â· ××¢×§× ×¡×××ס ××ש×ר×× ×תש×××"})]}),e.jsx("div",{className:"ms-auto flex-none",children:e.jsxs(et,{dir:"rtl",children:[e.jsx(tt,{asChild:!0,children:e.jsxs("button",{className:"group inline-flex items-center gap-2 h-11 px-4 roun
11ded-full bg-white border border-slate-200 shadow-sm text-sm font-bold text-slate-700 hover:border-slate-300 hover:shadow transition",children:[e.jsx(st,{className:"w-4 h-4 text-slate-500"})," פע×××ת × ×ספ×ת",e.jsx(at,{className:"w-4 h-4 text-slate-400 transition-transform group-data-[state=open]:rotate-180"})]})}),e.jsxs(lt,{align:"start",sideOffset:8,className:"w-64 p-1.5 rounded-2xl shadow-lg",children:[e.jsx(ge,{icon:Ge,bg:"bg-blue-50",color:"text-blue-600",label:"××××ת תקצ××",onClick:()=>{Y("balance"),$("reports")}}),e.jsx(ge,{icon:$e,bg:"bg-cyan-50",color:"text-cyan-600",label:"××× ×ª××× ×ת AI",onClick:()=>{Y("ai"),$("reports")}}),e.jsx(nt,{}),e.jsx(ge,{icon:Ve,bg:"bg-emerald-50",color:"text-emerald-600",label:"×××קת ××צ××ת",onClick:()=>$("expenses")})]})]})})]})}),S?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(X,{className:"w-8 h-8 animate-spin text-slate-400"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3",children:[e.jsx(se,{active:w==="baskets",onClick:()=>$("baskets"),icon:ye,tone:"emerald",value:y(U.available),label:"××ª×¨× ×××× ×",negative:U.available<0}),e.jsx(se,{active:w==="baskets",onClick:()=>$("baskets"),icon:ue,tone:"blue",value:y(U.allocated),label:"תקצ×× ×©× ×ª× ××××"}),e.jsx(se,{active:w==="requests"&&D==="paid",onClick:()=>L("paid"),icon:J,tone:"teal",value:y(U.paid),label:"ש×××",badge:le}),e.jsx(se,{active:w==="requests"&&D==="pending",onClick:()=>L("pending"),icon:ke,tone:"amber",value:y(U.reserved),label:"××ת×× ×ת",sub:"×קש×ת פת×××ת",badge:Z}),e.jsx(se,{active:w==="suppliers",onClick:()=>$("suppliers"),icon:we,tone:"violet",label:"ספק××",sub:"× ×××× ×¡×¤×§××"})]}),w==="reports"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:()=>$("baskets"),className:"text-sm font-bold text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(ae,{className:"w-4 h-4"})," ×××¨× ×ס×××"]}),e.jsx(Ct,{baskets:m,councilName:ne,communityName:s==null?void 0:s.name,initialTab:I},I)]}):w==="expenses"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{onClick:()=>$("baskets"),className:"text-sm font-bold text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(ae,{className:"w-4 h-4"})," ×××¨× ×ס×××"]}),e.jsx(Bt,{baskets:m,expenses:O,communityName:s==null?void 0:s.name,onChanged:n})]}):w==="suppliers"?e.jsx(ot,{mode:"settlement",parentId:a,settlementId:t}):w==="requests"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(je,{active:D==="all",onClick:()=>C("all"),label:"×××",count:f.length}),e.jsx(je,{active:D==="pending",onClick:()=>C("pending"),label:"××ת×× ×ת",count:Z}),e.jsx(je,{active:D==="paid",onClick:()=>C("paid"),label:"ש××××",count:le}),e.jsxs("button",{onClick:()=>$("baskets"),className:"ms-auto text-sm font-bold text-primary hover:underline inline-flex items-center gap-1",children:[e.jsx(ae,{className:"w-4 h-4"})," ×××¨× ×ס×××"]})]}),F.length===0?e.jsx("div",{className:"card-float p-10 text-center text-sm text-slate-400",children:u.length?"××× ×קש×ת ×ס×× ×× ××":"××¨× ×××©×ª× ×קש×ת ××××"}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 items-stretch",children:F.map(o=>{var M;
11return e.jsx(Ot,{charge:o,approvals:v.filter(B=>B.request_id===o.id),payments:i.filter(B=>B.request_id===o.id),paid:pe(o.id,i),basketTitle:(M=m.find(B=>B.basket_id===o.basket_id))==null?void 0:M.basket_title},o.id)})})]}):m.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(ue,{className:"w-7 h-7"})}),e.jsxs("p",{className:"text-slate-500",children:["××××¢×¦× ××¨× ××§×¦×ª× ××× ×¡×× ×ª×§×¦×× ××©× ×ª ",fe,"."]})]}):e.jsxs(e.Fragment,{children:[e.jsx(At,{totals:U}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(Ue,{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:z,onChange:o=>c(o.target.value),placeholder:"××פ×ש ×¡× ×ª×§×¦××â¦",className:"w-full h-10 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"})]}),x.length===0?e.jsx("div",{className:"card-float p-10 text-center text-sm text-slate-400",children:"×× × ××¦× ×¡× ×ª××× ×××פ×ש"}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 items-stretch",children:x.map(o=>{const M=Number(o.paid||0)+Number(o.reserved||0),B=o.allocated>0?Math.min(100,Math.round(M/o.allocated*100)):0,ee=B>=90?"rose":B>=70?"amber":"blue",re=B>=90,G=R[o.basket_id]||0;return e.jsxs("div",{className:"card-float p-5 flex flex-col h-full",children:[e.jsx("div",{className:"text-xs text-slate-500 font-bold",children:o.category_title||"×§×××ר××"}),e.jsx("h3",{className:"text-lg font-extrabold text-slate-900 truncate",children:o.basket_title}),e.jsxs("div",{className:"relative my-3",children:[e.jsx(It,{pct:B,tone:ee}),e.jsx("div",{className:"absolute inset-0 grid place-items-center text-center pointer-events-none",children:e.jsxs("div",{children:[e.jsx("div",{className:`text-lg font-extrabold leading-none ${Number(o.available)<0?"text-rose-600":"text-slate-900"}`,children:y(o.available)}),e.jsx("div",{className:"text-[10px] text-slate-400 mt-0.5",children:"××ª×¨× ×××× ×"})]})})]}),e.jsxs("div",{className:"space-y-0.5 text-sm",children:[e.jsx(Ne,{k:"תקצ×× ×©× ×ª×",v:y(o.allocated)}),e.jsx(Ne,{k:"× ××¦× / ש×××",v:y(o.paid)}),e.jsx(Ne,{k:"ש××ר (×קש×ת פת×××ת)",v:y(o.reserved),last:!0})]}),G>0&&e.jsxs("div",{className:"mt-2 text-[11px] text-amber-600 text-center",children:["â ",G," ×קש×ת פת×××ת ×ת×××× ××ש×ר"]}),o.emphasis&&e.jsxs("div",{className:"mt-2 bg-slate-50 border border-slate-100 rounded-xl px-3 py-2 text-[12px] text-slate-600",children:["ð¡ ",o.emphasis]}),re&&e.jsx("div",{className:"mt-2 bg-rose-50 border border-rose-100 rounded-xl px-3 py-2 text-[12px] text-rose-700",children:"â ï¸ ×§×¨×× ×× ×צ×× ××× â ××§×©× ××¢× ×××ª×¨× ×ª×¡××× ××ר××× ×תצר×× ××ש×ר ××××× ×××עצ×."}),e.jsxs("button",{onClick:()=>E(o),className:`mt-auto w-full h-10 rounded-full text-sm font-bold inline-flex items-center justify-center gap-1.5 ${re?"bg-white border border-rose-200 text-rose-600 hover:bg-rose-50":"bg-primary text-white hover:brightness-110"} transition`,children:[e.jsx(qe,{className:"w-4 h-4"})," ××שת ×קשת ××××"]})]},o.allocation_id)})})]})]}),b&&e.jsx(Ut,{basketRow:b,parentId:a,settlementId:t,onClose:()=>E(null),onSubmit:A})]}):e.jsxs("div",{dir:"rtl",className:"card-float p-10 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(Re,{className:"w-7 h-7"})}),e.jsx("p",{className:"text-slate-500",children:"×××ש×× ××× × ××§×שר ××××¢×¦× â ××× ×¡×× ×ª×§×¦×× ××צ××."})]})}const ze={blue:{badge:"bg-blue-50 text-blue-600",ring:"ring-blue-200 border-blue-300"},emerald:{badge:"bg-emerald-50 text-emerald-600",ring:"ring-emerald-200 border-emerald-300"},teal:{badge:"bg-teal-50 text-teal-600",ring:"ring-teal-200 border-teal-300"},amber:{badge:"bg-amber-50 text-amber-600",ring:"ring-amber-200 border-amber-300"},violet:{badge:"bg-violet-50 text-violet-600",ring:"ring-violet-200 border-violet-300"}};function se({active:t,onClick:s,icon:a,tone:r,value:d,label:p,sub:N,badge:m,negative:l}){const u=ze[r]||ze.blue;return e.jsxs("button",{onClick:s,className:`card-float p-4 text-right transition ${t?`ring-2 ${u.ring}`:"hover:shadow-md"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:`w-9 h-9 rounded-xl flex items-center justify-center ${u.badge}`,children:e.jsx(a,{className:"w-5 h-5"})}),m>0&&e.jsx("span",{className:"text-[11px] rounded-full px-1.5 py-0.5 font-extrabold bg-slate-100 text-slate-600",children:m})]}),d!==void 0&&e.jsx("div",{className:`text-2xl font-extrabold tabular-nums leading-none ${l?"text-rose-600":"text-slate-900"}`,children:d}),e.jsx("div",{className:`text-slate-800 ${d!==void 0?"text-xs text-slate-500 mt-1":"text-sm font-extrabold mt-0.5"}`,children:p}),N&&e.jsx("div",{className:"text-[11px] text-slate-400 mt-0.5",children:N})]})}function ge({icon:t,bg:s,color:a,label:r,onClick:d}){return e.jsxs(rt,{onClick:d,className:"rounded-lg px-2.5 py-2 gap-2.5 cursor-pointer hover:bg-accent",children:[e.jsx("span",{className:`w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 ${s}`,children:e.jsx(t,{className:`w-4 h-4 ${a}`})}),e.jsx("span",{className:"text-sm flex-1 text-right",children:r})]})}function je({active:t,onClick:s,label:a,count:r}
11){return e.jsxs("button",{onClick:s,className:`h-9 px-4 rounded-full text-sm font-bold inline-flex items-center gap-1.5 transition ${t?"bg-primary text-white":"bg-white border border-slate-200 text-slate-500 hover:border-slate-300"}`,children:[a,r>0&&e.jsx("span",{className:`text-[11px] rounded-full px-1.5 py-0.5 font-extrabold ${t?"bg-white/20 text-white":"bg-slate-100 text-slate-500"}`,children:r})]})}function Ne({k:t,v:s,last:a}){return e.jsxs("div",{className:`flex items-center justify-between py-1.5 ${a?"":"border-b border-dashed border-slate-100"}`,children:[e.jsx("span",{className:"text-slate-500",children:t}),e.jsx("span",{className:"font-bold tabular-nums text-slate-800",children:s})]})}function Ot({charge:t,approvals:s,payments:a=[],paid:r,basketTitle:d}){const[p,N]=g.useState(!1),[m,l]=g.useState(null),u=[...s].sort((i,k)=>i.step_order-k.step_order),j=g.useMemo(()=>{const i={};return s.forEach(k=>{i[Math.round(Number(k.step_order)||0)]=k}),i},[s]),v=Math.floor(Number(t.current_step)||0),_=me.includes(t.status);return g.useEffect(()=>{!p||m||P.rpc("moatza_budget_charge_chain",{p_charge_id:t.id}).then(i=>l(i||[])).catch(()=>l([]))},[p,m,t.id]),e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>N(!0),className:"card-float p-4 text-right flex flex-col h-full hover:shadow-md transition",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Ae,{status:t.status}),t.is_override&&e.jsx("span",{className:"text-[10px] font-bold rounded-full px-2 py-0.5 bg-rose-50 text-rose-600",children:"×ר×××"})]}),e.jsx("h3",{className:"text-sm font-extrabold text-slate-900 mt-2 line-clamp-2 leading-snug",children:t.purpose||"×קשת ××××"}),e.jsxs("div",{className:"text-xs text-slate-500 mt-1 truncate",children:[d||"",t.vendor_name?` · ${t.vendor_name}`:""]}),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:y(t.amount)}),e.jsx("span",{className:"text-[11px] text-slate-400",children:de(t.submitted_at||t.created_date)})]})]}),p&&e.jsx(Ke,{open:!0,onOpenChange:i=>!i&&N(!1),children:e.jsxs(We,{dir:"rtl",className:"max-w-lg max-h-[92vh] overflow-y-auto",children:[e.jsx(He,{children:e.jsxs(Ye,{className:"flex items-center gap-2 text-right",children:[e.jsx(Ae,{status:t.status})," ",e.jsx("span",{className:"truncate",children:t.purpose||"×קשת ××××"})]})}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 mb-3 text-sm",children:[e.jsx(ce,{k:"ס×××",v:y(t.amount)}),e.jsx(ce,{k:"ש×××",v:y(r)}),e.jsx(ce,{k:"ספק",v:t.vendor_name||"â"}),e.jsx(ce,{k:"×××ש",v:de(t.submitted_at||t.created_date)})]}),t.is_override&&e.jsx("div",{className:"mb-3 text-[12px] text-rose-700 bg-rose-50 border border-rose-100 rounded-xl px-3 py-2",children:"××§×©× ×× ×¡××× × ××ר××× ××תרת ××¡× â × ×רש ××ש×ר ×ר××× ×××עצ×."}),e.jsx("div",{className:"text-xs font-bold text-slate-500 mb-2",children:"×ס××× ×××ש×ר"}),m===null?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-400",children:[e.jsx(X,{className:"w-4 h-4 animate-spin"})," ×××¢×â¦"]}):m.length>0?e.jsx("div",{className:"space-y-0",children:m.map((i,k)=>{const S=j[Math.round(Number(i.step_order)||0)],h=_&&k===v,b=S&&S.action==="rejected";return e.jsxs("div",{className:"flex gap-3 py-2",children:[e.jsx("span",{className:`w-7 h-7 rounded-full grid place-items-center text-xs font-extrabold flex-none ${b?"bg-rose-100 text-rose-600":S?"bg-emerald-100 text-emerald-700 border-2 border-emerald-500":h?"bg-blue-600 text-white":"bg-slate-100 text-slate-400"}`,children:S?b?e.jsx(he,{className:"w-3.5 h-3.5"}):e.jsx(J,{className:"w-3.5 h-3.5"}):k+1}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-bold text-slate-800",children:[i.role_title||"××ש×ר",i.is_override_step?" · ××ש×ר ×ר×××":""]}),S?e.jsxs("div",{className:"text-xs text-slate-500",children:[S.approver_name||""," · ",de(S.signed_at),S.note?` · "${S.note}"`:"",S.signature_data&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-emerald-700 mr-1",children:[e.jsx(yt,{className:"w-3 h-3"})," × ×ת×"]})]}):h?e.jsx("div",{className:"text-xs text-blue-600 font-semibold",children:"××ת×× ×××ש×ר ×עת"}):e.jsx("div",{className:"text-xs text-slate-400",children:"××ת××"})]})]},k)})}):u.length>0?e.jsx("div",{className:"space-y-0",children:u.map(i=>e.jsxs("div",{className:"flex gap-3 py-2",children:[e.jsx("span",{className:`w-7 h-7 rounded-full grid place-items-center text-xs font-extrabold flex-none ${i.action==="rejected"?"bg-rose-100 text-rose-600":"bg-emerald-100 text-emerald-700 border-2 border-emerald-500"}`,children:i.action==="rejected"?e.jsx(he,{className:"w-3.5 h-3.5"}):e.jsx(J,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-sm font-bold text-slate-800",children:[i.role_title||"××ש×ר"," â ",i.approver_name||""]}),e.jsxs("div",{className:"text-xs text-slate-500",children:[de(i.signed_at),i.note?` · "${i.note}"`:""]})]})]},i.id))}):e.jsxs("div",{className:"flex items-center gap-2 text-sm text-amber-700",children:[e.jsx(ke,{className:"w-4 h-4"})," ××ת×× ×ת×××ת ×××ש×ר ×××עצ×"]}),a.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-100",children:[e.jsxs("div",{className:"text-xs font-bold text-slate-500 mb-2 flex items-center gap-1.5",children:[e.jsx(wt,{className:"w-4 h-4 text-emerald-600"})," תש××××× ×©××צע×"]}),e.jsx("div",{className:"space-y-1.5",children:a.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-sm bg-white rounded-xl border border-slate-100 px-3 py-2",children:[e.jsx("b",{className:"tabular-nums text-emerald-700",children:y(i.amount)}),e.jsxs("span",{className:"text-xs text-slate-500",children:[i.credit_date?`×××× ××× ×§ ${new Date(i.credit_date).toLocaleDateString("he-IL")}`:"××ת×× ××××¢× ×××××",i.reference?` · ×ס×××ª× ${i.reference}`:""]})]},i.id))})]})]})})]})}function ce({k:t,v:s}){return e.jsxs("div",{className:"bg-white rounded-xl border border-slate-100 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] text-slate-400",children:t}),e.jsx("div",{className:"font-bold text-slate-800 truncate",children:s})]})}const K="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 Ut({basketRow:t,parentId:s,settlementId:a,onClose:r,onSubmit:d}){const[p,N]=g.useState({purpose:"",amount:"",vendor_name:"",vendor_taxid:"",supplier_id:"",notes:""}),[m,l]=g.useState([]),[u,j]=g.useState(!1),[v,_]=g.useState(!1),[i,k]=g.useState([]),[S,h]=g.useState([]),[b,E]=g.useState(""),[w,$]=g.useState(!1),[D,C]=g.useState({name:"",tax_id:"",category_id:"",phone:""}),[I,Y]=g.useState(!1),z=x=>F=>N(L=>({...L,[x]:F.target.value})),c=(Number(p.amount)||0)>Number(t.available||0),n=g.useCallback(async()=>{const x=await P.entities.MoatzaBudgetSupplier.filter({kibbutz_id:s}
11,"-created_date",2e3).catch(()=>[]);k(x||[])},[s]);g.useEffect(()=>{n(),P.rpc("moatza_budget_visible_categories").then(x=>h(x||[])).catch(()=>{})},[n]);const f=g.useMemo(()=>{const x=b.trim(),F=i.filter(A=>!t.category_id||!A.category_id||A.category_id===t.category_id),L=F.length?F:i;return x?L.filter(A=>`${A.name||""} ${A.tax_id||""}`.includes(x)):L},[i,b,t.category_id]);function O(x){N(F=>({...F,supplier_id:x.id,vendor_name:x.name||"",vendor_taxid:x.tax_id||""}))}async function R(){if(!D.name.trim()){T.error("× ×רש ×©× ×¡×¤×§");return}Y(!0);try{const x=await P.entities.MoatzaBudgetSupplier.create({kibbutz_id:s,settlement_id:a,category_id:D.category_id||t.category_id||null,name:D.name.trim(),tax_id:D.tax_id,phone:D.phone,is_active:!0});T.success("×ספק × ×סף"),await n(),O(x),$(!1),C({name:"",tax_id:"",category_id:"",phone:""})}catch(x){T.error((x==null?void 0:x.message)||"ש×××× ×××ספת ספק")}finally{Y(!1)}}async function U(x){const F=Array.from(x.target.files||[]);if(x.target.value="",!!F.length){j(!0);try{const L=await Rt(F);l(A=>[...A,...L.map(q=>({...q,title:q.name,description:"",doc_type:"other"}))])}catch{T.error("ש×××× ×××¢××ת ×§×××¥")}finally{j(!1)}}}const Z=(x,F,L)=>l(A=>A.map((q,ne)=>ne===x?{...q,[F]:L}:q));async function le(){if(!p.purpose.trim()){T.error("×××× × ××רת ××××");return}if(!(Number(p.amount)>0)){T.error("×××× × ×¡××× ×××§×");return}_(!0);try{await d(p,m,t)}catch(x){T.error((x==null?void 0:x.message)||"ש×××× ×××שת ××קש×")}finally{_(!1)}}return e.jsx(Ke,{open:!0,onOpenChange:x=>!x&&r(),children:e.jsxs(We,{dir:"rtl",className:"max-w-3xl max-h-[92vh] overflow-y-auto",children:[e.jsx(He,{children:e.jsx(Ye,{children:"××שת ×קשת ××××"})}),e.jsxs("div",{className:"rounded-xl bg-blue-50/70 border border-blue-100 px-3 py-2 text-[13px] text-blue-800 flex items-center justify-between mb-3",children:[e.jsxs("span",{children:["ס×: ",e.jsx("b",{children:t.basket_title}),t.category_title?` · ${t.category_title}`:""]}),e.jsxs("b",{children:["××ª×¨× ×××× ×: ",y(t.available)]})]}),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("h4",{className:"text-sm font-extrabold text-slate-800 mb-3 flex items-center gap-1.5",children:[e.jsx(xe,{className:"w-4 h-4 text-blue-600"})," פר×× ××קש×"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-bold text-slate-500 mb-1.5",children:"××רת ×××××"}),e.jsx("input",{value:p.purpose,onChange:z("purpose"),className:K,placeholder:"××××××: ××××¨× ×××¤×§× â ××ר××¢ ×§××¥",autoFocus:!0})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-bold text-slate-500 mb-1.5",children:"ס××× ××××× (âª)"}),e.jsx("input",{inputMode:"numeric",value:p.amount,onChange:z("amount"),className:K,placeholder:"0"})]}),c&&e.jsxs("div",{className:"text-[12px] text-rose-700 bg-rose-50 border border-rose-100 rounded-xl px-3 py-2 flex items-start gap-1.5",children:[e.jsx(_e,{className:"w-4 h-4 flex-none mt-0.5"})," ×ס××× ×××¨× ××××ª×¨× ××××× × â ×××§×©× ×ª×¡××× ××ר××× ×תצר×× ××ש×ר ×ר××× ×××עצ×."]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-bold text-slate-500 mb-1.5",children:"×ער×ת (רש×ת)"}),e.jsx("textarea",{rows:3,value:p.notes,onChange:z("notes"),className:`${K} resize-none`})]})]})]}),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(we,{className:"w-4 h-4 text-emerald-600"})," ספק / ××××"]}),e.jsx("button",{onClick:()=>$(x=>!x),className:"text-xs font-bold text-primary hover:underline",children:w?"××××¨× ××רש×××":"+ ספק ××ש"})]}),p.vendor_name&&!w&&e.jsxs("div",{className:"mb-2 rounded-xl bg-emerald-50 border border-emerald-100 px-3 py-2 text-sm text-emerald-800 flex items-center justify-between",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Oe,{className:"w-4 h-4"})," ",p.vendor_name,p.vendor_taxid?` · ×.פ ${p.vendor_taxid}`:""]}),e.jsx("button",{onClick:()=>N(x=>({...x,supplier_id:"",vendor_name:"",vendor_taxid:""})),className:"text-emerald-600 hover:text-rose-500",children:e.jsx(he,{className:"w-4 h-4"})})]}),w?e.jsxs("div",{className:"space-y-2",children:[e.jsx("input",{value:D.name,onChange:x=>C(F=>({...F,name:x.target.value})),placeholder:"×©× ×ספק",className:K,autoFocus:!0}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("input",{value:D.tax_id,onChange:x=>C(F=>({...F,tax_id:x.target.value})),placeholder:"×¢.× / ×.פ",className:K}),e.jsx("input",{value:D.phone,onChange:x=>C(F=>({...F,phone:x.target.value})),placeholder:"××פ××",className:K,inputMode:"tel"})]}),e.jsxs("select",{value:D.category_id,onChange:x=>C(F=>({...F,category_id:x.target.value})),className:K,children:[e.jsx("option",{value:"",children:"â ×§×××ר×× â"}),S.map(x=>e.jsx("option",{value:x.id,children:x.title},x.id))]}),e.jsxs("button",{onClick:R,disabled:I,className:"w-full 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:[I?e.jsx(X,{className:"w-4 h-4 animate-spin"}):e.jsx(qe,{className:"w-4 h-4"})," ×××¡×¤× ××××ר×"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mb-2",children:[e.jsx(Ue,{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:b,onChange:x=>E(x.target.value),placeholder:"××פ×ש ספק ××רש×××â¦",className:`${K} pr-9`})]}),e.jsx("div",{className:"max-h-52 overflow-y-auto rounded-xl border border-slate-200 bg-white divide-y divide-slate-50",children:f.length===0?e.jsxs("div",{className:"px-3 py-4 text-sm text-slate-400 text-center",children:["×××
11 ספק×× ",b?"ת×××××":"×¢××××"," â ××ס××¤× ×¡×¤×§ ××ש"]}):f.map(x=>e.jsxs("button",{onClick:()=>O(x),className:`w-full text-right px-3 py-2 text-sm flex items-center justify-between transition ${p.supplier_id===x.id?"bg-emerald-50/70 text-emerald-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(we,{className:"w-4 h-4 text-slate-400 flex-none"})," ",e.jsxs("span",{className:"truncate",children:[x.name,x.tax_id?` · ${x.tax_id}`:""]})]}),!x.settlement_id&&e.jsx("span",{className:"text-[10px] font-bold rounded-full px-1.5 py-0.5 bg-blue-50 text-blue-600 flex-none",children:"××עצ×"})]},x.id))})]})]})]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-slate-200 bg-white 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(xe,{className:"w-4 h-4 text-rose-500"})," ×ס×××× (×ש××× ×ת / ×צע×ת ×××ר)"]}),e.jsxs("label",{className:"flex flex-col items-center justify-center gap-1 border-[1.5px] border-dashed border-slate-300 rounded-xl py-4 text-sm text-slate-400 cursor-pointer hover:border-primary hover:text-primary bg-slate-50/50 transition",children:[u?e.jsx(X,{className:"w-5 h-5 animate-spin"}):e.jsx(_t,{className:"w-5 h-5"}),"××¨×¨× ×× ×××¦× ×××¢××× Â· PDF / ת××× ×",e.jsx("input",{type:"file",multiple:!0,accept:"application/pdf,image/*",className:"hidden",onChange:U})]}),m.length>0&&e.jsx("div",{className:"space-y-2 mt-3",children:m.map((x,F)=>e.jsxs("div",{className:"rounded-xl border border-slate-200 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("a",{href:x.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-[12px] text-slate-500 hover:text-primary min-w-0",children:[e.jsx(xe,{className:"w-3.5 h-3.5 text-rose-500 flex-none"})," ",e.jsx("span",{className:"truncate max-w-[220px]",children:x.name})]}),e.jsx("button",{onClick:()=>l(L=>L.filter((A,q)=>q!==F)),className:"text-slate-400 hover:text-rose-500",children:e.jsx(ve,{className:"w-4 h-4"})})]}),e.jsx("input",{value:x.title,onChange:L=>Z(F,"title",L.target.value),placeholder:"××תרת ××ס××",className:`${K} mb-2`}),e.jsx("input",{value:x.description,onChange:L=>Z(F,"description",L.target.value),placeholder:"ת×××ר (רש×ת)",className:K})]},F))})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 mt-5",children:[e.jsx("button",{onClick:r,className:"h-10 px-4 rounded-full bg-white border border-slate-200 text-slate-700 text-sm font-semibold hover:bg-slate-50",children:"×××××"}),e.jsxs("button",{onClick:le,disabled:v||u,className:"h-10 px-5 rounded-full bg-primary text-white text-sm font-bold inline-flex items-center gap-1.5 hover:brightness-110 disabled:opacity-50",children:[v?e.jsx(X,{className:"w-4 h-4 animate-spin"}):e.jsx(it,{className:"w-4 h-4"})," ×××©× ×××¢××¨× ×××ש×ר ×××עצ×"]})]})]})})}function ps(){return e.jsx(zt,{})}export{ps 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.