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","assets/reportPdf-BRmDXPVe.js"])))=>i.map(i=>d[i]); 2import{R as he,bS as ir,r as i,j as e,d as D,as as Pt,a9 as Oe,X as $e,y as qt,F as bs,U as so,aA as ye,T as Re,P as We,C as la,b as Ie,z as W,aE as Jt,dx as Ke,a7 as nt,ar as At,x as De,ad as fs,aT as es,H as or,l as ra,aH as ao,M as no,u as ia,w as xt,aM as Xe,bs as Ns,aU as oa,Y as vs,aQ as In,ak as lo,a8 as gn,bK as ro,aD as Rc,a3 as Gs,aF as ws,N as zn,G as ca,_ as Kn,aG as ks,bX as io,dw as qc,aP as Ic,$ as gs,a as Aa,bE as yn,t as zc,ao as Kc,aJ as cr,aa as Wc,aO as Uc,d8 as Hc,ap as kr}from"./index-BuF13C9R.js";import{K as Yc}from"./KibbutzModuleGuard-ervrt65z.js";import{u as Vc}from"./useActionVisibility-DLgqAw2q.js";import{N as Me}from"./softDelete-X2GBluex.js";import{f as ve,b as oo}from"./money-CmD9E_V-.js";import{S as Gc}from"./SumitEmbeddedCheckout-X1I3bJQZ.js";import{g as Xc}from"./dashboardUtils-BNRxAObU.js";import{y as _e,W as dr,z as Zc,A as Qc,B as Jc,E as ed,G as ka,o as td,l as _n,r as Sr,v as Wn,h as Lt,q as as,S as sd,H as $r,J as ad,K as nd,M as ld,N as rd,O as Xs,Q as Cr,R as Es,U as ur,V as id,C as co,X as uo,Y as mo,Z as od,_ as cd,$ as dd,s as ud,u as md,m as xd,t as Ll,F as pd,i as hd,j as xo,w as po,k as bd}from"./kolboFile-9wwPFBSx.js";import{I as Un}from"./info-BIFqAg3-.js";import{H as Tl}from"./history-DRsCxblu.js";import{P as It}from"./pencil-CoE4mwuD.js";import{P as ho}from"./power-Cjs5sAhy.js";import{U as ys}from"./user-round-4Z7t4la9.js";import{B as fd}from"./baby-BUG_dxit.js";import{I as gd}from"./id-card-CMzMo_8f.js";import{S as da}from"./shopping-basket-Z4y6WHkT.js";import{B as yd}from"./BudgetItemSelect-D9zLjNZr.js";import{P as mr}from"./percent-C2DmKTeC.js";import{C as Be}from"./calendar-clock-Dg6I_-A7.js";import{E as _d}from"./eye-off-lYYIvXNt.js";import{R as Mt}from"./repeat-CJHHLdIV.js";import{S as jd}from"./StepCards-CDtME9a2.js";import{C as Ma,G as Nd,R as vd,F as wd,P as kd,a as xr,S as Sd,c as $d,b as bo,H as Cd}from"./sheet-D9xmjyjc.js";import{S as Ad}from"./settings-2-O6_6aFLq.js";import{C as lt}from"./chevron-left-D2IUBEPa.js";import{R as fo}from"./receipt-C8ikpKpP.js";import{S as Hn}from"./sliders-horizontal-D0cjPgOh.js";import{C as Md}from"./columns-3-DJizGI6o.js";import{F as pr}from"./file-spreadsheet-B8pSCGeX.js";import{F as go}from"./file-down-CrVKunWa.js";import{P as yo}from"./printer-BwQiYGcP.js";import{F as hr}from"./filter-Bnc7eQ-s.js";import{A as _o}from"./arrow-down-CqE1RxaS.js";import{A as jo}from"./arrow-up-down-H69UbrCK.js";import{C as No}from"./ConfirmDialog-B9VWyx7W.js";import{U as La}from"./upload-DeFZlL4S.js";import{C as Pd}from"./circle-pause-ARb36XiP.js";import{P as vo}from"./play-BbfkX4y6.js";import{P as Ed}from"./pause-Li2qDNkT.js";import{R as br}from"./refresh-cw-DvPS6Mu1.js";import{A as Ar}from"./arrow-left-right-CHYYMQPF.js";import{B as Fd}from"./banknote-BAXkyBwn.js";import{F as Dd}from"./file-check-D2O-2b5u.js";import{P as jn}from"./paperclip-BMrctHny.js";import{B as Od}from"./ban-BrNeMJoo.js";import{C as rt}from"./coins-Ke0c7IVk.js";import{C as Ld}from"./calendar-range-Drzgm4HZ.js";import{S as Mr}from"./sticky-note-Cb-DcYYp.js";import{P as fr,k as kt,a as gr,b as Js,e as Wa,f as Ua,g as Pr,B as Er,n as Fr,i as wo,v as Dr,s as Or,j as Td,c as ko,l as Bd,d as Rd,p as qd,h as Id,t as zd}from"./paymentCatalogs-CvImawYM.js";import{S as Lr}from"./shopping-cart-CMl29wkm.js";import{L as Zt}from"./link-2-BTwRH0ED.js";import{f as Bt,e as wt,$ as Ha,i as Ws,I as un,M as So,N as Nt,J as Ht,a0 as Kd,O as Bl,Z as Wd,P as Ta,Q as $o,b as Nn,G as Co,K as Zs,_ as vn,H as Ud,S as Tr,a1 as Hd,h as Yd,U as Ao,Y as Vd,a2 as Gd,C as _s,p as Xd,B as pt,q as Zd,R as Rt,T as ht,L as Qd,a3 as Mo}from"./generateCategoricalChart-D9kEchEU.js";import{X as Qt,Y as Ct,B as Ba}from"./BarChart-BV6G5gJY.js";import{C as js}from"./CartesianGrid-D3McakTz.js";import{P as Yn,a as Vn}from"./PieChart-knnFYOG7.js";import{S as Jd}from"./scale-Ccy3cfrP.js";import{L as yr}from"./Line-rdVrUAZx.js";import{S as wn}from"./sparkles-Bk9eJtR5.js";import{W as eu}from"./wand-sparkles-vdWz8Wpd.js";import{B as Po}from"./bookmark-BA373k3D.js";import{H as tu}from"./hash-DXwUI4fi.js";import{m as Br}from"./digitalPageOrder-C4niF6hl.js";import{o as Rr}from"./reorder-BJ1u2xSy.js";import{G as su}from"./grip-vertical-D-WILyUY.js";import{b as au,c as nu,k as lu}from"./messageComposition-CWPHxpB-.js";import{C as Eo}
2from"./copy-BClGV4nG.js";import{S as ru}from"./share-2-BamByTGH.js";import{L as iu}from"./list-ordered-tSTk2Phj.js";import{R as ou}from"./rotate-ccw-BudqP26q.js";import{F as cu}from"./file-pen-line-D5MCQ02J.js";import"./votingUtils-3kN6dDVT.js";import"./headphones-Bk55olo7.js";import"./formStyles-CzLsWpb8.js";import"./alert-dialog-BrDEU3Wj.js";import"./isEqual-Bszk2vQ5.js";import"./tiny-invariant-BaFNuDhB.js";var du=["layout","type","stroke","connectNulls","isRange","ref"],uu=["key"],Fo;function ea(t){"@babel/helpers - typeof";return ea=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},ea(t)}function Do(t,s){if(t==null)return{};var n=mu(t,s),a,l;if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(l=0;l<r.length;l++)a=r[l],!(s.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(t,a)&&(n[a]=t[a])}return n}function mu(t,s){if(t==null)return{};var n={};for(var a in t)if(Object.prototype.hasOwnProperty.call(t,a)){if(s.indexOf(a)>=0)continue;n[a]=t[a]}return n}function ms(){return ms=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},ms.apply(this,arguments)}function qr(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);s&&(a=a.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),n.push.apply(n,a)}return n}function Ut(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?qr(Object(n),!0).forEach(function(a){St(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):qr(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function xu(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function Ir(t,s){for(var n=0;n<s.length;n++){var a=s[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,Lo(a.key),a)}}function pu(t,s,n){return s&&Ir(t.prototype,s),n&&Ir(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function hu(t,s,n){return s=kn(s),bu(t,Oo()?Reflect.construct(s,n||[],kn(t).constructor):s.apply(t,n))}function bu(t,s){if(s&&(ea(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return fu(t)}function fu(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Oo(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Oo=function(){return!!t})()}function kn(t){return kn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},kn(t)}function gu(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&Rl(t,s)}function Rl(t,s){return Rl=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,l){return a.__proto__=l,a},Rl(t,s)}function St(t,s,n){return s=Lo(s),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Lo(t){var s=yu(t,"string");return ea(s)=="symbol"?s:s+""}function yu(t,s){if(ea(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s);if(ea(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}var Ss=(function(t){function s(){var n;xu(this,s);for(var a=arguments.length,l=new Array(a),r=0;r<a;r++)l[r]=arguments[r];return n=hu(this,s,[].concat(l)),St(n,"state",{isAnimationFinished:!0}),St(n,"id",$o("recharts-area-")),St(n,"handleAnimationEnd",function(){var o=n.props.onAnimationEnd;n.setState({isAnimationFinished:!0}),Nn(o)&&o()}),St(n,"handleAnimationStart",function(){var o=n.props.onAnimationStart;n.setState({isAnimationFinished:!1}),Nn(o)&&o()}),n}return gu(s,t),pu(s,[{key:"renderDots",value:function(a,l,r){var o=this.props.isAnimationActive,p=this.state.isAnimationFinished;if(o&&!p)return null;var u=this.props,d=u.dot,c=u.points,m=u.dataKey,h=Bt(this.props,!1),b=Bt(d,!0),f=c.map(function(g,y){var $=Ut(Ut(Ut({key:"dot-".concat(y),r:3},h),b),{},{index:y,cx:g.x,cy:g.y,dataKey:m,value:g.value,payload:g.payload,points:c});return s.renderDotItem(d,$)}
2),x={clipPath:a?"url(#clipPath-".concat(l?"":"dots-").concat(r,")"):null};return he.createElement(wt,ms({className:"recharts-area-dots"},x),f)}},{key:"renderHorizontalRect",value:function(a){var l=this.props,r=l.baseLine,o=l.points,p=l.strokeWidth,u=o[0].x,d=o[o.length-1].x,c=a*Math.abs(u-d),m=Ha(o.map(function(h){return h.y||0}));return Ws(r)&&typeof r=="number"?m=Math.max(r,m):r&&Array.isArray(r)&&r.length&&(m=Math.max(Ha(r.map(function(h){return h.y||0})),m)),Ws(m)?he.createElement("rect",{x:u<d?u:u-c,y:0,width:c,height:Math.floor(m+(p?parseInt("".concat(p),10):1))}):null}},{key:"renderVerticalRect",value:function(a){var l=this.props,r=l.baseLine,o=l.points,p=l.strokeWidth,u=o[0].y,d=o[o.length-1].y,c=a*Math.abs(u-d),m=Ha(o.map(function(h){return h.x||0}));return Ws(r)&&typeof r=="number"?m=Math.max(r,m):r&&Array.isArray(r)&&r.length&&(m=Math.max(Ha(r.map(function(h){return h.x||0})),m)),Ws(m)?he.createElement("rect",{x:0,y:u<d?u:u-c,width:m+(p?parseInt("".concat(p),10):1),height:Math.floor(c)}):null}},{key:"renderClipRect",value:function(a){var l=this.props.layout;return l==="vertical"?this.renderVerticalRect(a):this.renderHorizontalRect(a)}},{key:"renderAreaStatically",value:function(a,l,r,o){var p=this.props,u=p.layout,d=p.type,c=p.stroke,m=p.connectNulls,h=p.isRange;p.ref;var b=Do(p,du);return he.createElement(wt,{clipPath:r?"url(#clipPath-".concat(o,")"):null},he.createElement(un,ms({},Bt(b,!0),{points:a,connectNulls:m,type:d,baseLine:l,layout:u,stroke:"none",className:"recharts-area-area"})),c!=="none"&&he.createElement(un,ms({},Bt(this.props,!1),{className:"recharts-area-curve",layout:u,type:d,connectNulls:m,fill:"none",points:a})),c!=="none"&&h&&he.createElement(un,ms({},Bt(this.props,!1),{className:"recharts-area-curve",layout:u,type:d,connectNulls:m,fill:"none",points:l})))}},{key:"renderAreaWithAnimation",value:function(a,l){var r=this,o=this.props,p=o.points,u=o.baseLine,d=o.isAnimationActive,c=o.animationBegin,m=o.animationDuration,h=o.animationEasing,b=o.animationId,f=this.state,x=f.prevPoints,g=f.prevBaseLine;return he.createElement(So,{begin:c,duration:m,isActive:d,easing:h,from:{t:0},to:{t:1},key:"area-".concat(b),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(y){var $=y.t;if(x){var O=x.length/p.length,A=p.map(function(k,C){var w=Math.floor(C*O);if(x[w]){var _=x[w],T=Nt(_.x,k.x),M=Nt(_.y,k.y);return Ut(Ut({},k),{},{x:T($),y:M($)})}return k}),S;if(Ws(u)&&typeof u=="number"){var P=Nt(g,u);S=P($)}else if(Ht(u)||Kd(u)){var E=Nt(g,0);S=E($)}else S=u.map(function(k,C){var w=Math.floor(C*O);if(g[w]){var _=g[w],T=Nt(_.x,k.x),M=Nt(_.y,k.y);return Ut(Ut({},k),{},{x:T($),y:M($)})}return k});return r.renderAreaStatically(A,S,a,l)}return he.createElement(wt,null,he.createElement("defs",null,he.createElement("clipPath",{id:"animationClipPath-".concat(l)},r.renderClipRect($))),he.createElement(wt,{clipPath:"url(#animationClipPath-".concat(l,")")},r.renderAreaStatically(p,u,a,l)))})}},{key:"renderArea",value:function(a,l){var r=this.props,o=r.points,p=r.baseLine,u=r.isAnimationActive,d=this.state,c=d.prevPoints,m=d.prevBaseLine,h=d.totalLength;return u&&o&&o.length&&(!c&&h>0||!Bl(c,o)||!Bl(m,p))?this.renderAreaWithAnimation(a,l):this.renderAreaStatically(o,p,a,l)}},{key:"render",value:function(){var a,l=this.props,r=l.hide,o=l.dot,p=l.points,u=l.className,d=l.top,c=l.left,m=l.xAxis,h=l.yAxis,b=l.width,f=l.height,x=l.isAnimationActive,g=l.id;if(r||!p||!p.length)return null;var y=this.state.isAnimationFinished,$=p.length===1,O=ir("recharts-area",u),A=m&&m.allowDataOverflow,S=h&&h.allowDataOverflow,P=A||S,E=Ht(g)?this.id:g,k=(a=Bt(o,!1))!==null&&a!==void 0?a:{r:3,strokeWidth:2},C=k.r,w=C===void 0?3:C,_=k.strokeWidth,T=_===void 0?2:_,M=Wd(o)?o:{},B=M.clipDot,R=B===void 0?!0:B,j=w*2+T;return he.createElement(wt,{className:O},A||S?he.createElement("defs",null,he.createElement("clipPath",{id:"clipPath-".concat(E)},he.createElement("rect",{x:A?c:c-b/2,y:S?d:d-f/2,width:A?b:b*2,height:S?f:f*2})),!R&&he.createElement("clipPath",{id:"clipPath-dots-".concat(E)},he.createElement("rect",{x:c-j/2,y:d-j/2,width:b+j,height:f+j}))):null,$?null:this.renderArea(P,E),(o||$)&&this.renderDots(P,R,E),(!x||y)&&Ta.renderCallByParent(this.props,p))}}],[{key:"getDerivedStateFromProps",value:function(a,l){return a.animationId!==l.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,curBaseLine:a.baseLine,prevPoints:l.curPoints,prevBaseLine:l.curBaseLine}:a.points!==l.curPoints||a.baseLine!==l.curBaseLine?{curPoints:a.points,curBaseLine:a.baseLine}:null}}])})(i.PureComponent);Fo=Ss;
2St(Ss,"displayName","Area");St(Ss,"defaultProps",{stroke:"#3182bd",fill:"#3182bd",fillOpacity:.6,xAxisId:0,yAxisId:0,legendType:"line",connectNulls:!1,points:[],dot:!1,activeDot:!0,hide:!1,isAnimationActive:!Co.isSsr,animationBegin:0,animationDuration:1500,animationEasing:"ease"});St(Ss,"getBaseValue",function(t,s,n,a){var l=t.layout,r=t.baseValue,o=s.props.baseValue,p=o??r;if(Ws(p)&&typeof p=="number")return p;var u=l==="horizontal"?a:n,d=u.scale.domain();if(u.type==="number"){var c=Math.max(d[0],d[1]),m=Math.min(d[0],d[1]);return p==="dataMin"?m:p==="dataMax"||c<0?c:Math.max(Math.min(d[0],d[1]),0)}return p==="dataMin"?d[0]:p==="dataMax"?d[1]:d[0]});St(Ss,"getComposedData",function(t){var s=t.props,n=t.item,a=t.xAxis,l=t.yAxis,r=t.xAxisTicks,o=t.yAxisTicks,p=t.bandSize,u=t.dataKey,d=t.stackedData,c=t.dataStartIndex,m=t.displayedData,h=t.offset,b=s.layout,f=d&&d.length,x=Fo.getBaseValue(s,n,a,l),g=b==="horizontal",y=!1,$=m.map(function(A,S){var P;f?P=d[c+S]:(P=Zs(A,u),Array.isArray(P)?y=!0:P=[x,P]);var E=P[1]==null||f&&Zs(A,u)==null;return g?{x:vn({axis:a,ticks:r,bandSize:p,entry:A,index:S}),y:E?null:l.scale(P[1]),value:P,payload:A}:{x:E?null:a.scale(P[1]),y:vn({axis:l,ticks:o,bandSize:p,entry:A,index:S}),value:P,payload:A}}),O;return f||y?O=$.map(function(A){var S=Array.isArray(A.value)?A.value[0]:null;return g?{x:A.x,y:S!=null&&A.y!=null?l.scale(S):null}:{x:S!=null?a.scale(S):null,y:A.y}}):O=g?l.scale(x):a.scale(x),Ut({points:$,baseLine:O,layout:b,isRange:y},h)});St(Ss,"renderDotItem",function(t,s){var n;if(he.isValidElement(t))n=he.cloneElement(t,s);else if(Nn(t))n=t(s);else{var a=ir("recharts-area-dot",typeof t!="boolean"?t.className:""),l=s.key,r=Do(s,uu);n=he.createElement(Ud,ms({},r,{key:l,className:a}))}return n});function ta(t){"@babel/helpers - typeof";return ta=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},ta(t)}function _u(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function ju(t,s){for(var n=0;n<s.length;n++){var a=s[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,Ro(a.key),a)}}function Nu(t,s,n){return s&&ju(t.prototype,s),Object.defineProperty(t,"prototype",{writable:!1}),t}function vu(t,s,n){return s=Sn(s),wu(t,To()?Reflect.construct(s,n||[],Sn(t).constructor):s.apply(t,n))}function wu(t,s){if(s&&(ta(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ku(t)}function ku(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function To(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(To=function(){return!!t})()}function Sn(t){return Sn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},Sn(t)}function Su(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&ql(t,s)}function ql(t,s){return ql=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,l){return a.__proto__=l,a},ql(t,s)}function Bo(t,s,n){return s=Ro(s),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Ro(t){var s=$u(t,"string");return ta(s)=="symbol"?s:s+""}function $u(t,s){if(ta(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s);if(ta(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}var Gn=(function(t){function s(){return _u(this,s),vu(this,s,arguments)}return Su(s,t),Nu(s,[{key:"render",value:function(){return null}}])})(i.Component);Bo(Gn,"displayName","ZAxis");Bo(Gn,"defaultProps",{zAxisId:0,range:[64,64],scale:"auto",type:"number"});var Cu=["option","isActive"];function Sa(){return Sa=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},Sa.apply(this,arguments)}function Au(t,s){if(t==null)return{};var n=Mu(t,s),a,l;if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);for(l=0;l<r.length;l++)a=r[l],!(s.indexOf(a)>=0)&&Object.prototype.propertyIsEnumerable.call(t,a)&&(n[a]=t[a])}return n}function Mu(t,s){if(t==null)return{};var n={};for(var a in t)if(Object.prototype.hasOwnProperty.call(t,a)){if(s.indexOf(a)>=0)continue;n[a]=t[a]}return n}function Pu(t){var s=t.option,n=t.isActive,a=Au(t,Cu);return typeof s=="string"?i.createElement(Tr,Sa({option:i.createElement(Hd,Sa({type:s},a)),isActive:n,shapeType:"symbols"},a)):i.createElement(Tr,Sa({option:s,isActive:n,shapeType:"symbols"},a))}function sa(t){"@babel/helpers - typeof";return sa=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},sa(t)}function $a(){return $a=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},$a.apply(this,arguments)}function zr(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);
2s&&(a=a.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),n.push.apply(n,a)}return n}function tt(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?zr(Object(n),!0).forEach(function(a){Yt(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):zr(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function Eu(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function Kr(t,s){for(var n=0;n<s.length;n++){var a=s[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,Io(a.key),a)}}function Fu(t,s,n){return s&&Kr(t.prototype,s),n&&Kr(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Du(t,s,n){return s=$n(s),Ou(t,qo()?Reflect.construct(s,n||[],$n(t).constructor):s.apply(t,n))}function Ou(t,s){if(s&&(sa(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Lu(t)}function Lu(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function qo(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(qo=function(){return!!t})()}function $n(t){return $n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},$n(t)}function Tu(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&Il(t,s)}function Il(t,s){return Il=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,l){return a.__proto__=l,a},Il(t,s)}function Yt(t,s,n){return s=Io(s),s in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Io(t){var s=Bu(t,"string");return sa(s)=="symbol"?s:s+""}function Bu(t,s){if(sa(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s);if(sa(a)!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}var Xn=(function(t){function s(){var n;Eu(this,s);for(var a=arguments.length,l=new Array(a),r=0;r<a;r++)l[r]=arguments[r];return n=Du(this,s,[].concat(l)),Yt(n,"state",{isAnimationFinished:!1}),Yt(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0})}),Yt(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1})}),Yt(n,"id",$o("recharts-scatter-")),n}return Tu(s,t),Fu(s,[{key:"renderSymbolsStatically",value:function(a){var l=this,r=this.props,o=r.shape,p=r.activeShape,u=r.activeIndex,d=Bt(this.props,!1);return a.map(function(c,m){var h=u===m,b=h?p:o,f=tt(tt({}
2,d),c);return he.createElement(wt,$a({className:"recharts-scatter-symbol",key:"symbol-".concat(c==null?void 0:c.cx,"-").concat(c==null?void 0:c.cy,"-").concat(c==null?void 0:c.size,"-").concat(m)},Yd(l.props,c,m),{role:"img"}),he.createElement(Pu,$a({option:b,isActive:h,key:"symbol-".concat(m)},f)))})}},{key:"renderSymbolsWithAnimation",value:function(){var a=this,l=this.props,r=l.points,o=l.isAnimationActive,p=l.animationBegin,u=l.animationDuration,d=l.animationEasing,c=l.animationId,m=this.state.prevPoints;return he.createElement(So,{begin:p,duration:u,isActive:o,easing:d,from:{t:0},to:{t:1},key:"pie-".concat(c),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(h){var b=h.t,f=r.map(function(x,g){var y=m&&m[g];if(y){var $=Nt(y.cx,x.cx),O=Nt(y.cy,x.cy),A=Nt(y.size,x.size);return tt(tt({},x),{},{cx:$(b),cy:O(b),size:A(b)})}var S=Nt(0,x.size);return tt(tt({},x),{},{size:S(b)})});return he.createElement(wt,null,a.renderSymbolsStatically(f))})}},{key:"renderSymbols",value:function(){var a=this.props,l=a.points,r=a.isA
2nimationActive,o=this.state.prevPoints;return r&&l&&l.length&&(!o||!Bl(o,l))?this.renderSymbolsWithAnimation():this.renderSymbolsStatically(l)}},{key:"renderErrorBar",value:function(){var a=this.props.isAnimationActive;if(a&&!this.state.isAnimationFinished)return null;var l=this.props,r=l.points,o=l.xAxis,p=l.yAxis,u=l.children,d=Ao(u,Vd);return d?d.map(function(c,m){var h=c.props,b=h.direction,f=h.dataKey;return he.cloneElement(c,{key:"".concat(b,"-").concat(f,"-").concat(r[m]),data:r,xAxis:o,yAxis:p,layout:b==="x"?"vertical":"horizontal",dataPointFormatter:function(g,y){return{x:g.cx,y:g.cy,value:b==="x"?+g.node.x:+g.node.y,errorVal:Zs(g,y)}}})}):null}},{key:"renderLine",value:function(){var a=this.props,l=a.points,r=a.line,o=a.lineType,p=a.lineJointType,u=Bt(this.props,!1),d=Bt(r,!1),c,m;if(o==="joint")c=l.map(function(O){return{x:O.cx,y:O.cy}});else if(o==="fitting"){var h=Gd(l),b=h.xmin,f=h.xmax,x=h.a,g=h.b,y=function(A){return x*A+g};c=[{x:b,y:y(b)},{x:f,y:y(f)}]}var $=tt(tt(tt({},u),{},{fill:"none",stroke:u&&u.fill},d),{},{points:c});return he.isValidElement(r)?m=he.cloneElement(r,$):Nn(r)?m=r($):m=he.createElement(un,$a({},$,{type:p})),he.createElement(wt,{className:"recharts-scatter-line",key:"recharts-scatter-line"},m)}},{key:"render",value:function(){var a=this.props,l=a.hide,r=a.points,o=a.line,p=a.className,u=a.xAxis,d=a.yAxis,c=a.left,m=a.top,h=a.width,b=a.height,f=a.id,x=a.isAnimationActive;if(l||!r||!r.length)return null;var g=this.state.isAnimationFinished,y=ir("recharts-scatter",p),$=u&&u.allowDataOverflow,O=d&&d.allowDataOverflow,A=$||O,S=Ht(f)?this.id:f;return he.createElement(wt,{className:y,clipPath:A?"url(#clipPath-".concat(S,")"):null},$||O?he.createElement("defs",null,he.createElement("clipPath",{id:"clipPath-".concat(S)},he.createElement("rect",{x:$?c:c-h/2,y:O?m:m-b/2,width:$?h:h*2,height:O?b:b*2}))):null,o&&this.renderLine(),this.renderErrorBar(),he.createElement(wt,{key:"recharts-scatter-symbols"},this.renderSymbols()),(!x||g)&&Ta.renderCallByParent(this.props,r))}}],[{key:"getDerivedStateFromProps",value:function(a,l){return a.animationId!==l.prevAnimationId?{prevAnimationId:a.animationId,curPoints:a.points,prevPoints:l.curPoints}:a.points!==l.curPoints?{curPoints:a.points}:null}}])})(i.PureComponent);Yt(Xn,"displayName","Scatter");Yt(Xn,"defaultProps",{xAxisId:0,yAxisId:0,zAxisId:0,legendType:"circle",lineType:"joint",lineJointType:"linear",data:[],shape:"circle",hide:!1,isAnimationActive:!Co.isSsr,animationBegin:0,animationDuration:400,animationEasing:"linear"});Yt(Xn,"getComposedData",function(t){var s=t.xAxis,n=t.yAxis,a=t.zAxis,l=t.item,r=t.displayedData,o=t.xAxisTicks,p=t.yAxisTicks,u=t.offset,d=l.props.tooltipType,c=Ao(l.props.children,_s),m=Ht(s.dataKey)?l.props.dataKey:s.dataKey,h=Ht(n.dataKey)?l.props.dataKey:n.dataKey,b=a&&a.dataKey,f=a?a.range:Gn.defaultProps.range,x=f&&f[0],g=s.scale.bandwidth?s.scale.bandwidth():0,y=n.scale.bandwidth?n.scale.bandwidth():0,$=r.map(function(O,A){var S=Zs(O,m),P=Zs(O,h),E=!Ht(b)&&Zs(O,b)||"-",k=[{name:Ht(s.dataKey)?l.props.name:s.name||s.dataKey,unit:s.unit||"",value:S,payload:O,dataKey:m,type:d},{name:Ht(n.dataKey)?l.props.name:n.name||n.dataKey,unit:n.unit||"",value:P,payload:O,dataKey:h,type:d}];E!=="-"&&k.push({name:a.name||a.dataKey,unit:a.unit||"",value:E,payload:O,dataKey:b,type:d});var C=vn({axis:s,ticks:o,bandSize:g,entry:O,index:A,dataKey:m}),w=vn({axis:n,ticks:p,bandSize:y,entry:O,index:A,dataKey:h}),_=E!=="-"?a.scale(E):x,T=Math.sqrt(Math.max(_,0)/Math.PI);return tt(tt({},O),{},{cx:C,cy:w,x:C-T,y:w-T,xAxis:s,yAxis:n,zAxis:a,width:2*T,height:2*T,size:_,node:{x:S,y:P,z:E},tooltipPayload:k,tooltipPosition:{x:C,y:w},payload:O},c&&c[A]&&c[A].props)});return tt({points:$},u)});
2var zo=Xd({chartName:"ComposedChart",GraphicalChild:[yr,Ss,pt,Xn],axisComponents:[{axisType:"xAxis",AxisComp:Qt},{axisType:"yAxis",AxisComp:Ct},{axisType:"zAxis",AxisComp:Gn}],formatAxisMap:Zd});const rl=t=>Number(t)||0,Wr=t=>Math.round((t+Number.EPSILON)*100)/100,Ur=new Set(["approved","issued"]);function Ru(t){const s=rl(t==null?void 0:t.amount),n=rl(t==null?void 0:t.discount_amount),a=rl(t==null?void 0:t.credit_amount),l=Wr(n+a),r=(t==null?void 0:t.status)==="cancelled",o=r?0:Math.max(0,Wr(s-l)),p=!r&&l>0&&o<=.005;return{gross:s,discount:n,credit:a,relief:l,net:o,cancelled:r,nothingLeft:p}}function qu(t,{paid:s=!1,today:n="",labels:a={}}={}){const l=Ru(t),r=!l.cancelled&&s,o=Ur.has(t==null?void 0:t.status)&&!r&&!l.cancelled&&!l.nothingLeft,p=!!(o&&(t!=null&&t.due_date)&&String(t.due_date).slice(0,10)<n),u=l.cancelled?"××××":(t==null?void 0:t.status)==="credited"||l.nothingLeft?"××××":r?"ש×××":p?"×××××ר":Ur.has(t==null?void 0:t.status)?"×תש×××":a[t==null?void 0:t.status]||(t==null?void 0:t.status)||"";return{...l,paid:r,open:o,overdue:p,status:u}}function zt(t=[],s=[],{ready:n=!0}={}){if(!n||!(s!=null&&s.length))return t||[];const a=new Set(s.map(l=>l==null?void 0:l.id));return(t||[]).filter(l=>a.has(l==null?void 0:l.charge_type_id))}const Ko=i.createContext(null);function Iu({children:t}){const[s,n]=i.useState(null),a=i.useMemo(()=>({node:s,setNode:n}),[s]);return e.jsx(Ko.Provider,{value:a,children:typeof t=="function"?t(s):t})}function zu(t,s=[]){const n=i.useContext(Ko),a=n==null?void 0:n.setNode;i.useEffect(()=>{if(a)return a(()=>t),()=>a(null)},[a,...s])}const Hr={indigo:"bg-indigo-50 text-indigo-600",blue:"bg-blue-50 text-blue-600",sky:"bg-sky-50 text-sky-600",violet:"bg-violet-50 text-violet-600",purple:"bg-purple-50 text-purple-600",amber:"bg-amber-50 text-amber-600",emerald:"bg-emerald-50 text-emerald-600",rose:"bg-rose-50 text-rose-600",slate:"bg-slate-100 text-slate-600"},Ku={3:"grid-cols-2 sm:grid-cols-3",4:"grid-cols-2 sm:grid-cols-3 md:grid-cols-4",5:"grid-cols-2 sm:grid-cols-3 md:grid-cols-5"};function Wu({items:t=[],className:s="",columns:n,compact:a=!1}){const l=Vc(t);if(l.length===0)return null;const r=Ku[n]||"grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7";return e.jsx("div",{className:`grid gap-3 ${a?"":"sm:gap-4"} ${r} ${s}`,children:l.map((o,p)=>{const u=o.icon,d=Hr[o.tone]||Hr.indigo;return e.jsxs("button",{type:"button",onClick:o.onClick,disabled:o.disabled,className:`group relative flex flex-col items-center justify-start text-center 3 rounded-2xl bg-white border border-slate-200/80 shadow-sm 4 hover:shadow-md hover:border-slate-300 hover:-translate-y-0.5 5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-indigo-400 6 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0 7 transition-all ${a?"gap-2 px-3 py-4":"gap-4 px-4 py-8"}`,children:[o.badge?e.jsx("span",{className:"absolute top-3 left-3 min-w-[22px] h-[22px] px-1.5 rounded-full bg-red-500 text-white text-[11px] font-black grid place-items-center",children:o.badge}):null,e.jsx("span",{className:`rounded-2xl grid place-items-center flex-none ${d} ${a?"w-12 h-12":"w-20 h-20"}`,children:u?e.jsx(u,{className:a?"w-6 h-6":"w-9 h-9",strokeWidth:1.7}):null}),e.jsxs("span",{className:`min-w-0 flex flex-col items-center justify-start ${a?"min-h-[2.5rem]":"min-h-[3rem]"}`,children:[e.jsx("span",{className:`block font-black text-slate-900 leading-snug ${a?"text-[15px]":"text-[17px]"}`,children:o.label}),o.hint&&e.jsx("span",{className:`block text-slate-400 ${a?"text-[11px] mt-0.5":"text-[12px] mt-1"}`,children:o.hint})]})]},o.key||o.label||p)})})}const Yr=t=>String(t??"").replace(/\D/g,""),Cn=t=>String(t??"").trim().replace(/[×´"׳']/g,"").replace(/\s+/g," ").toLowerCase();function Wo(t,{family:s,residents:n=[],properties:a=[]}={}){const l=[],r=(u,d,c)=>{const m=String(c??"").trim();m&&l.push({kind:u,label:d,value:m})};r("name","×©× ××ש×××",t==null?void 0:t.name),r("name","×©× ×שפ××",s==null?void 0:s.name),r("account","×ספר ×ש×××",t==null?void 0:t.account_number),r("budget","×ספר תקצ××",(t==null?void 0:t.budget_number)??(t==null?void 0:t.budget)),r("id","×ספר ×××ת",t==null?void 0:t.id_number);const o=[s==null?void 0:s.street,s==null?void 0:s.house_number].filter(
7Boolean).join(" ");r("address","×ת××ת",o),a.forEach(u=>r("address","×ת××ת × ×ס",u==null?void 0:u.address)),n.forEach(u=>{r("name","×©× ×רש×××",u==null?void 0:u.full_name),r("phone","××פ××",u==null?void 0:u.phone),r("budget","×ספר תקצ××",u==null?void 0:u.budget)});const p=new Set;return l.filter(u=>{const d=`${u.kind}|${Cn(u.value)}`;return p.has(d)?!1:(p.add(d),!0)})}function Uo(t,s){const n=Cn(s);if(!n)return 0;if(/^[\d\s-]+$/.test(String(s??"").trim())&&(t.kind==="phone"||t.kind==="budget"||t.kind==="account"||t.kind==="id")){const r=Yr(s),o=Yr(t.value);if(r&&o)return o===r?3:o.startsWith(r)?2:r.length>=4&&o.includes(r)?1:0}const l=Cn(t.value);return l?l===n?3:l.startsWith(n)||l.split(" ").some(r=>r.startsWith(n))?2:l.includes(n)?1:0:0}function Ho(t=[],s,{limit:n=12}={}){if(Cn(s).length<2)return[];const l=[];for(const r of t){const o=Wo(r.account,r);let p=0,u=null;for(const d of o){const c=Uo(d,s);if(c>p&&(p=c,u=d),p===3)break}p>0&&l.push({...r,score:p,why:u})}return l.sort((r,o)=>{var p,u;return o.score-r.score||String(((p=r.account)==null?void 0:p.name)||"").localeCompare(String(((u=o.account)==null?void 0:u.name)||""),"he")}).slice(0,n)}const Vr={name:["name"],account:["account"],budget:["budget"],phone:["phone"],address:["address"]};function Uu(t=[],s={},{limit:n=25}={}){const a=Object.entries(s).map(([r,o])=>[r,String(o??"").trim()]).filter(([r,o])=>o&&Vr[r]);if(!a.length)return[];const l=[];for(const r of t){const o=Wo(r.account,r);let p=0,u=null,d=!0;for(const[c,m]of a){const h=new Set(Vr[c]);let b=0,f=null;for(const x of o){if(!h.has(x.kind))continue;const g=Uo(x,m);g>b&&(b=g,f=x)}if(!b){d=!1;break}p+=b,u||(u=f)}d&&l.push({...r,score:p,why:u})}return l.sort((r,o)=>{var p,u;return o.score-r.score||String(((p=r.account)==null?void 0:p.name)||"").localeCompare(String(((u=o.account)==null?void 0:u.name)||""),"he")}).slice(0,n)}const il=t=>ve(t,"âª",{decimals:2}),zl="h-11 rounded-xl border border-slate-200 px-3 text-sm focus:outline-none focus:border-teal-400",pa=`${zl} w-full`;function Hu({kibbutzId:t,onClose:s,onDone:n}){const[a,l]=i.useState("who"),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState(null),[b,f]=i.useState(""),[x,g]=i.useState(null),[y,$]=i.useState(!1),[O,A]=i.useState({first:"",last:"",phone:"",email:""}),[S,P]=i.useState([{title:"",price:""}]),[E,k]=i.useState(!1),[C,w]=i.useState(null),[_,T]=i.useState(null);i.useEffect(()=>{let H=!0;return(async()=>{const[z,te,ie,V]=await Promise.all([D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me}).catch(()=>[]),D.functions.invoke("cardTerminal",{action:"status",community_id:t}).then(Y=>(Y==null?void 0:Y.data)||null).catch(()=>null)]);H&&(o(z||[]),u(te||[]),c(ie||[]),h((V==null?void 0:V.ready)??!1))})(),()=>{H=!1}},[t]),i.useEffect(()=>{const H=z=>{z.key==="Escape"&&a!=="card"&&s()};return document.addEventListener("keydown",H),()=>document.removeEventListener("keydown",H)},[s,a]);const M=i.useMemo(()=>{const H=new Map((d||[]).map(te=>[te.id,te])),z=new Map;return(p||[]).forEach(te=>{te.family_id&&(z.has(te.family_id)||z.set(te.family_id,[]),z.get(te.family_id).push(te))}),(r||[]).map(te=>({id:te.id,account:te,family:H.get(te.family_id)||null,residents:z.get(te.family_id)||[],properties:[]}))},[r,p,d]),B=i.useMemo(()=>{const H=b.trim();return H.length<2?[]:Ho(M,H,{limit:8}).map(z=>z.account)},[b,M]),R=i.useMemo(()=>S.reduce((H,z)=>H+(Number(z.price)||0),0),[S]),j=S.filter(H=>H.title.trim()&&Number(H.price)>0),q=(H,z,te)=>P(ie=>ie.map((V,Y)=>Y===H?{...V,[z]:te}:V)),L=()=>P(H=>[...H,{title:"",price:""}]),N=H=>P(z=>z.length===1?[{title:"",price:""}]:z.filter((te,ie)=>ie!==H)),v=()=>{const H=[O.first.trim(),O.last.trim()].filter(Boolean).join(" ");if(!H){W.error("×ש ××××× ×©×");return}g({id:null,name:H,phone:O.phone.trim(),email:O.email.trim(),_new:!0}),$(!1),l("what")},F=async()=>{if(!j.length){W.error("×ש ××××× ×פ××ת ש×רת ×××× ××ת");return}k(!0);try{const H=await D.functions.invoke("cardTerminal",{action:"start",community_id:t,payer_account_id:(x==null?void 0:x.id)||null,customer_name:(x==null?void 0:x.name)||null,customer_phone:(x==null?void 0:x.phone)||null,customer_email:(x==null?void 0:x.email)||null,lines:j.map(te=>({title:te.title.trim(),price:Number(te.price)}))}),z=(H==null?void 0:H.data)||H;if(!(z!=null&&z.checkout))throw new Error((z==null?void 0:z.error)||"פת××ת ××××× × ×ש××");w(z),l("card")}catch(H){W.error((H==null?void 0:H.message)||"פת××ת ××××× × ×ש××")}finally{k(!1)}},K=i.useCallback(H=>{T(H||{success:!0}),l("done"),n==null||n()},[n]),Z={who:"ס××קת ×שר××",what:"פר×× ×××××",card:"תש××× ××ר××ס",done:"××××× ××צע"}[a];return Pt.createPortal(e.jsxs("div",{dir:"rtl",className:"fixed inset-0 z-[80] grid place-items-center p-4",role:"dialog","aria-modal":"true","aria-label":"ס××קת ×שר××",children:[e.jsx("button",{type:"button","aria-label":"ס××ר×",onClick:()=>a!=="card"&&s(),className:"absolute inset-0 bg-slate-900/50 backdrop-blur-[2px] curs
7or-default"}),e.jsxs("div",{className:"relative w-full max-w-2xl h-[640px] max-h-[92vh] bg-white rounded-2xl border border-slate-200 shadow-2xl flex flex-col overflow-hidden",children:[e.jsxs("header",{className:"flex items-center gap-3 px-5 py-4 border-b border-slate-100 flex-none",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl bg-rose-50 text-rose-600 grid place-items-center flex-none",children:e.jsx(Oe,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[17px] font-black text-slate-900",children:Z}),x&&a!=="who"&&e.jsxs("p",{className:"text-[12.5px] text-slate-500 truncate",children:[x.name,x.account_number?` · ×ש××× ${x.account_number}`:x._new?" · ×ש×× ××ש":""]})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"ס××ר×",disabled:a==="card"&&E,className:"mr-auto w-8 h-8 rounded-lg grid place-items-center text-slate-400 hover:text-slate-700 hover:bg-slate-100 flex-none disabled:opacity-40",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[a==="who"&&e.jsxs("div",{className:"space-y-3",children:[m===!1&&e.jsx("p",{className:"text-[12.5px] font-bold text-amber-700 bg-amber-50 border border-amber-200 rounded-xl px-3 py-2",children:"ס××קת ×שר×× ××× × ××××רת ××§××××. ×ש ×××××ר ספק תש××××× ×××¡× Â«×××ר×ת ×ער×ת»."}),e.jsxs("label",{className:"block relative",children:[e.jsx(qt,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"}),e.jsx("input",{value:b,onChange:H=>f(H.target.value),autoFocus:!0,placeholder:"××פ×ש ××¤× ×©×, ×ספר ×ש××× ×× ×ספר תקצ××",className:`${pa} pr-9`})]}),e.jsxs("div",{className:"rounded-xl border border-slate-200 overflow-hidden",children:[B.length===0&&e.jsx("p",{className:"text-[13px] text-slate-400 text-center py-8",children:b.trim()?"××× ×ª×צ××ת":"××¤×©× ×ש××× ×ש××, ×× ××ס××¤× ×ש×× ××ש"}),B.map(H=>e.jsxs("button",{type:"button",onClick:()=>{g(H),l("what")},className:"w-full flex items-center gap-3 px-3 py-2.5 text-right hover:bg-slate-50 border-b border-slate-50 last:border-0",children:[e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-[14px] font-bold text-slate-800 truncate",children:H.name||`×ש××× #${H.account_number}`}),e.jsx("span",{className:"block text-[12px] text-slate-400",children:[H.account_number&&`×ש××× ${H.account_number}`,(H.budget_number||H.budget)&&`תקצ×× ${H.budget_number||H.budget}`].filter(Boolean).join(" · ")})]}),e.jsx(bs,{className:"w-4 h-4 text-slate-300 flex-none"})]},H.id))]}),y?e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/70 p-4 space-y-3",children:[e.jsx("h4",{className:"text-[13px] font-black text-slate-800",children:"×ש×× ××ש"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx("input",{className:pa,placeholder:"×©× ×××",value:O.first,onChange:H=>A(z=>({...z,first:H.target.value}))}),e.jsx("input",{className:pa,placeholder:"×©× ×שפ××",value:O.last,onChange:H=>A(z=>({...z,last:H.target.value}))}),e.jsx("input",{className:pa,placeholder:"××פ××",inputMode:"tel",value:O.phone,onChange:H=>A(z=>({...z,phone:H.target.value}))}),e.jsx("input",{className:pa,placeholder:"××××´×",inputMode:"email",value:O.email,onChange:H=>A(z=>({...z,email:H.target.value}))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:v,className:"h-10 px-4 rounded-xl bg-teal-600 text-white text-[13px] font-bold inline-flex items-center gap-1.5 hover:bg-teal-700",children:[e.jsx(ye,{className:"w-4 h-4"})," ××ספ×"]}),e.jsx("button",{type:"button",onClick:()=>$(!1),className:"h-10 px-4 rounded-xl border border-slate-200 text-[13px] font-bold text-slate-600",children:"×××××"})]})]}):e.jsxs("button",{type:"button",onClick:()=>$(!0),className:`h-10 px-4 rounded-xl border border-slate-200 bg-white text-[13px] font-bold text-slate-700 8 inline-flex items-center gap-2 hover:border-teal-300 hover:text-teal-700 transition-colors`,children:[e.jsx(so,{className:"w-4 h-4"})," ×ש×× ××ש"]})]}),a==="what"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/70 p-4",children:[e.jsx("h4",{className:"text-[13px] font-black text-slate-800 mb-1",children:"פר×××"}),e.jsx("p",{className:"text-[14px] font-bold text-slate-900",children:x==null?void 0:x.name}),e.jsx("p",{className:"text-[12.5px] text-slate-500",children:[(x==null?void 0:x.account_number)&&`×ש××× ${x.account_number}
8`,x==null?void 0:x.phone,x==null?void 0:x.email].filter(Boolean).join(" · ")||"××× ×ש××× ×ספר××"}),e.jsx("button",{type:"button",onClick:()=>l("who"),className:"text-[12px] font-bold text-teal-700 hover:underline mt-1.5",children:"×××פת ×ש××"})]}),e.jsx("h4",{className:"text-[13px] font-black text-slate-800 pt-1",children:"ש×ר×ת ×××××"}),S.map((H,z)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("input",{className:`${zl} flex-1 min-w-0`,placeholder:"××תרת ×××××",value:H.title,onChange:te=>q(z,"title",te.target.value)}),e.jsx("input",{className:`${zl} w-32 flex-none tabular-nums`,placeholder:"×××ר",inputMode:"decimal",type:"number",step:"0.01",min:"0",value:H.price,onChange:te=>q(z,"price",te.target.value)}),e.jsx("button",{type:"button",onClick:()=>N(z),"aria-label":"×סרת ש×ר×",className:"w-11 h-11 rounded-xl border border-slate-200 grid place-items-center text-slate-400 hover:text-red-600 hover:border-red-200 flex-none",children:e.jsx(Re,{className:"w-4 h-4"})})]},z)),e.jsxs("button",{type:"button",onClick:L,className:`h-10 px-4 rounded-xl border border-slate-200 bg-white text-[13px] font-bold text-slate-700 9 inline-flex items-center gap-2 hover:border-teal-300 hover:text-teal-700 transition-colors`,children:[e.jsx(We,{className:"w-4 h-4"})," ש××¨× × ×ספת"]})]}),a==="card"&&C&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/70 p-4",children:[e.jsx("p",{className:"text-[13px] text-slate-600",children:x==null?void 0:x.name}),e.jsx("ul",{className:"mt-2 space-y-1",children:j.map((H,z)=>e.jsxs("li",{className:"flex items-center justify-between text-[13px] text-slate-700",children:[e.jsx("span",{className:"truncate",children:H.title}),e.jsx("span",{className:"tabular-nums font-bold",dir:"ltr",children:il(Number(H.price))})]},z))})]}),e.jsx(Gc,{checkout:C.checkout,paymentReference:C.paymentReference,chargeFunction:"cardTerminal",onSuccess:K,onError:()=>{}})]}),a==="done"&&e.jsx("div",{className:"h-full grid place-items-center text-center",children:e.jsxs("div",{children:[e.jsx(la,{className:"w-16 h-16 text-emerald-500 mx-auto mb-3"}),e.jsx("h4",{className:"text-[19px] font-black text-slate-900",children:"××××× ××צע"}),e.jsx("p",{className:"text-[26px] font-black text-emerald-700 tabular-nums mt-1",dir:"ltr",children:il(R)}),e.jsx("p",{className:"text-[13px] text-slate-500 mt-1",children:x==null?void 0:x.name}),(_==null?void 0:_.reference)&&e.jsxs("p",{className:"text-[12px] text-slate-400 mt-1",dir:"ltr",children:["×ס×××ª× ",_.reference]}),(_==null?void 0:_.needsReview)&&e.jsx("p",{className:"text-[12.5px] font-bold text-amber-700 bg-amber-50 border border-amber-200 rounded-xl px-3 py-2 mt-3",children:"××××× × ×××, ×× ×¨×ש××× ×ספר×× × ×ש×. ×ש ×רש×× ×××ª× ××× ×ת."})]})})]}),e.jsx("footer",{className:"flex-none border-t border-slate-100 bg-slate-50 px-5 py-3.5 flex items-center gap-3",children:a==="done"?e.jsx("button",{type:"button",onClick:s,className:"h-11 px-6 rounded-xl bg-teal-600 text-white text-[14px] font-bold mr-auto hover:bg-teal-700",children:"ס××ר×"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[13px] text-slate-500",children:"ס××´× ×××××"}),e.jsx("span",{className:"text-[22px] font-black text-slate-900 tabular-nums",dir:"ltr",children:il(R)}),a==="what"&&e.jsxs("button",{type:"button",onClick:F,disabled:E||!j.length||m===!1,className:`h-11 px-6 rounded-xl bg-teal-600 text-white text-[14px] font-bold mr-auto 10 inline-flex items-center gap-2 hover:bg-teal-700 disabled:opacity-50`,children:[E?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(bs,{className:"w-4 h-4"})," ××ש×"]}),a==="card"&&e.jsx("button",{type:"button",onClick:()=>{w(null),l("what")},className:"h-11 px-5 rounded-xl border border-slate-200 bg-white text-[13px] font-bold text-slate-600 mr-auto",children:"×××¨× ×פר×× ×××××"})]})})]})]}),document.body)}const Se="w-full h-12 rounded-xl border border-slate-300 bg-white px-4 text-sm text-slate-800 placeholder:text-slate-400 focus:outline-none focus:border-indigo-500 focus:ring-4 focus:ring-indigo-50 transition-colors",ua="w-full rounded-xl border border-slate-300 bg-white px-4 py-3 text-sm text-slate-800 placeholder:text-slate-400 focus:outline-none focus:border-indigo-500 focus:ring-4 focus:ring-indigo-50 transition-colors",ts="inline-flex items-center justify-center gap-2 h-12 px-7 rounded-xl bg-orange-500 hover:bg-orange-600 text-white text-sm font-bold transition-colors disabled:opacity-50",$s="inline-flex items-center justify-center gap-2 h-12 px-7 rounded-xl border border-slate-300 bg-white text-slate-600 text-sm font-semibold hover:bg-slate-50 transition-colors";function Q({label:t,required:s,info:n,hint:a,children:l,className:r=""}){return e.jsxs("div",{className:r,children:[t!=null&&t!==""&&e.jsxs("label",{className:"block mb-1.5 text-sm font-semibold text-slate-700 text-right",children:[e.jsx("span",{children:t}),s&&e.jsx("span",{className:"text-red-500",children:" *"}),n&&e.jsx(Un,{className:"inline-block w-4 h-4 text-blue-500 align-[-3px] mr-1",title:typeof n=="string"?n:void 0})]}),l,a&&e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:a})]})}function Ra({title:t,icon:s,summary:n,action:a,children:l,open:r,onToggle:o,tone:p="indigo"}){const u={indigo:"bg-indigo-50 text-indigo-600",emerald:"bg-emerald-50 text-emerald-600",amber:"bg-amber-50 text-amber-600",
10sky:"bg-sky-50 text-sky-600"}[p];return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3",children:[e.jsxs("button",{type:"button",onClick:o,"aria-expanded":r,className:"flex items-center gap-2.5 flex-1 min-w-0 text-right",children:[e.jsx("span",{className:`w-9 h-9 rounded-lg flex items-center justify-center flex-shrink-0 ${u}`,children:e.jsx(s,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-base font-bold text-slate-900 truncate",children:t}),n&&e.jsx("span",{className:"block text-xs text-slate-400 truncate",children:n})]}),e.jsx(Jt,{className:`w-4 h-4 text-slate-400 flex-shrink-0 transition-transform ${r?"rotate-180":""}`})]}),a]}),r&&e.jsx("div",{className:"px-4 pb-4 pt-0 border-t border-slate-100",children:l})]})}const ns=Object.freeze({water_low_rate:8.508,water_high_rate:15.623,water_quota_per_soul:3.5,water_min_souls:2,water_eligible_addition:3.5,includes_vat:!0,vat_rate:18}),Yo=(t,s)=>{const n=Number(t);if(!Number.isFinite(n))return NaN;const a=String(n);return a.includes("e")||a.includes("E")?Math.round(n*10**s)/10**s:+`${Math.round(+`${a}e${s}`)}e${-s}`},ha=t=>Yo(t,2),Fs=t=>Yo(t,3),gt=t=>{if(t==null||t==="")return null;const s=Number(t);return Number.isFinite(s)?s:null},Tt=Object.freeze({ok:"ok",opening:"opening",no_meter:"no_meter",no_previous:"no_previous",regression:"regression",duplicate:"duplicate",invalid:"invalid"}),Pa=Object.freeze({ok:"××ת×× ××צ×××",opening:"קר××ת פת×××",no_meter:"×× × ××¦× ××× ×",no_previous:"××¡×¨× ×§×¨××× ×§×××ת",regression:"קר××× × ××××ת × ×××× ××§×××ת",duplicate:"רש××× ×פ××× ××§×××¥",invalid:"ש×××× ×× ×ª×× ××"});function Yu({consumption:t,souls:s,eligible:n,months:a,tariff:l}={}){const r=l||{},o=gt(r.water_low_rate),p=gt(r.water_high_rate),u=gt(r.water_quota_per_soul),d=gt(r.water_min_souls)??0,c=gt(r.water_eligible_addition)??0,m=r.includes_vat!==!1,h=gt(r.vat_rate)??0,b=gt(t);if(b===null||b<0)throw new Error("צר××× ×× ×ª×§×× ×");if(o===null||p===null||u===null)throw new Error("ס×× ××××× ×סר תער××¤× ×××");const f=gt(a)??1,x=Math.max(gt(s)??0,d),g=Math.max(0,Math.round(gt(n)??0)),y=Fs(x*u*f),$=Fs(g*c*f),O=Fs(y+$),A=Fs(Math.min(b,O)),S=Fs(Math.max(b-O,0)),P=A*o,E=S*p,k=P+E,C=m?0:k*(h/100),w=ha(k+C);return{consumption:Fs(b),souls_used:x,eligible_used:g,months_used:f,quota_base:y,quota_eligible:$,quota_total:O,low_consumption:A,high_consumption:S,low_rate:o,high_rate:p,low_amount:ha(P),high_amount:ha(E),subtotal:ha(k),includes_vat:m,vat_rate:h,vat_amount:ha(C),amount:w}}function Vu(t,s){const n="".slice(0,10);return(t||[]).filter(a=>a.calculation_method!=="water_meter"||a.is_active===!1?!1:n?!(a.valid_from&&String(a.valid_from).slice(0,10)>n||a.valid_until&&String(a.valid_until).slice(0,10)<n):!0)}function Gu(t,s){if(!t||!s)return null;const n=new Date(`${String(t).slice(0,10)}T00:00:00Z`),a=new Date(`${String(s).slice(0,10)}T00:00:00Z`);if(Number.isNaN(n.getTime())||Number.isNaN(a.getTime())||a<=n)return null;const l=(a-n)/864e5;return Math.max(.5,Math.round(l/30.44*2)/2)}const yt=Se,Vo=t=>{if(!t)return"â";const[s,n,a]=String(t).slice(0,10).split("-");return a?`${a}/${n}/${s}`:t},mn=t=>t==null||t===""?"â":Number(t).toFixed(3).replace(/\.?0+$/,""),ol=t=>({meter_number:"",consumer_id:"",property_id:"",property_address:"",consumer_name:"",previous_reading:"",previous_reading_date:"",souls:t??"",eligible_count:"0",status:"active",notes:""});function Xu({kibbutzId:t,account:s,properties:n=[],familySouls:a,familyName:l,open:r,onToggle:o}){const[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState(!0),[b,f]=i.useState(!1),[x,g]=i.useState(null),[y,$]=i.useState(()=>ol(a)),[O,A]=i.useState(!1),[S,P]=i.useState(null),E=(j,q)=>$(L=>({...L,[j]:q})),k=i.useCallback(async()=>{h(!0);try{const[j,q]=await Promise.all([D.entities.WaterMeter.filter({kibbutz_id:t,payer_account_id:s.id},"-created_date",50).catch(()=>[]),D.entities.Charge.filter({kibbutz_id:t,payer_account_id:s.id},"-created_date",300).catch(()=>[])]);u(j||[]),c((q||[]).filter(L=>L.water_meter_id))}finally{h(!1)}},[t,s.id]);i.useEffect(()=>{k()},[k]);const C=i.useCallback(j=>d.filter(q=>
10q.water_meter_id===j),[d]),w=()=>{var j,q;g(null),$({...ol(a),consumer_name:l||"",property_id:((j=n[0])==null?void 0:j.id)||"",property_address:((q=n[0])==null?void 0:q.address)||""}),f(!0)},_=j=>{g(j),$({...ol(a),...j,previous_reading:j.previous_reading??"",previous_reading_date:j.previous_reading_date||"",souls:j.souls??"",eligible_count:j.eligible_count??0,property_id:j.property_id||""}),f(!0)},T=async()=>{if(!String(y.meter_number).trim()){W.error("×ש ××××× ×ספר ××× ×");return}A(!0);const j={kibbutz_id:t,payer_account_id:s.id,meter_number:String(y.meter_number).trim(),consumer_id:String(y.consumer_id||"").trim()||null,property_id:y.property_id||null,property_address:y.property_address||null,consumer_name:y.consumer_name||null,previous_reading:y.previous_reading===""?null:Number(y.previous_reading),previous_reading_date:y.previous_reading_date||null,souls:y.souls===""?null:Number(y.souls),eligible_count:y.eligible_count===""?0:Number(y.eligible_count),status:y.status,notes:y.notes||null};try{x?await D.entities.WaterMeter.update(x.id,j):await D.entities.WaterMeter.create(j),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:x?"water_meter_updated":"water_meter_created",entity_type:"water_meter",entity_id:(x==null?void 0:x.id)||null,payer_account_id:s.id,new_value:j.meter_number}).catch(()=>{}),W.success("×××× × × ×©×ר"),f(!1),k()}catch(q){W.error(String((q==null?void 0:q.message)||"").includes("unique")?"×ספר ×××× × ××ר ×§××× ××§××××":"ש×××× ×ש××רת ×××× ×")}finally{A(!1)}},M=async j=>{const q=j.status==="active"?"inactive":"active";try{await D.entities.WaterMeter.update(j.id,{status:q}),W.success(q==="active"?"×××× × ××פע×":"×××× × ××ש×ת"),k()}catch{W.error("ש××××")}},B=async j=>{if(C(j.id).length){W.error("×××× × ×× ×××¤×§× ×ש××× ×ת â × ××ª× ××ש××ת ×××ª× ××××");return}if(confirm(`×××××§ ×ת ××× × ${j.meter_number}?`))try{await D.entities.WaterMeter.delete(j.id),W.success("×××× × × ×××§"),k()}catch{W.error("ש××××")}},R=i.useMemo(()=>{if(m)return"×××¢×â¦";if(!p.length)return"×× ×××××¨× ××× × ××× ××ש××× ××";const j=p.filter(q=>q.status!=="inactive").length;return[p.map(q=>q.meter_number).filter(Boolean).join(" · "),j===p.length?"":_e(j,"××× ×¤×¢××","פע××××")].filter(Boolean).join(" · ")},[p,m]);return e.jsx(Ra,{tone:"sky",icon:Ke,title:`××× × ××× (${p.length})`,summary:R,open:r,onToggle:o,action:!b&&e.jsxs("button",{onClick:()=>{w(),r||o()},className:"h-8 px-3 rounded-full bg-sky-600 text-white text-xs inline-flex items-center gap-1 flex-shrink-0",children:[e.jsx(We,{className:"w-3.5 h-3.5"})," ××סף ××× ×"]}),children:e.jsx("div",{className:"billing-form pt-4",children:b?e.jsxs("div",{className:"rounded-xl border border-slate-200 p-4 mb-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(Q,{label:"×ספר ××× ×",required:!0,children:e.jsx("input",{className:yt,placeholder:"××× ×ספר ××× ×",value:y.meter_number,onChange:j=>E("meter_number",j.target.value)})}),e.jsx(Q,{label:"×ס׳ ××××× ×ת×××× ××××",info:"××ספר ש×× ×ת×××× ×××× ×ת ×צר×× â ×ש×ש ××ת××× ×ש×ספר ×××× × ××× × ×ª×××",children:e.jsx("input",{className:yt,placeholder:"××× ×ס׳ ×××××",value:y.consumer_id,onChange:j=>E("consumer_id",j.target.value)})}),e.jsx(Q,{label:"× ×ס ×ש×××",children:e.jsxs("select",{className:yt,value:y.property_id,onChange:j=>{const q=n.find(L=>L.id===j.target.value);$(L=>({...L,property_id:j.target.value,property_address:(q==null?void 0:q.address)||L.property_address}))},children:[e.jsx("option",{value:"",children:"â ××× â"}),n.map(j=>e.jsx("option",{value:j.id,children:j.property_number||j.address},j.id))]})}),e.jsx(Q,{label:"×ת××ת ×× ×ס",children:e.jsx("input",{className:yt,placeholder:"××× ×ת××ת",value:y.property_address||"",onChange:j=>E("property_address",j.target.value)})}),e.jsx(Q,{label:"×©× ×¦×¨××",info:"××¤× ×©××× ××פ××¢ ××§×××¥ ×ת×××× â ×תצ××× ××××, ××ת××× ××¢××× ××× × ××¤× ×©×",children:e.jsx("input",{className:yt,placeholder:"××× ×©× ×¦×¨××",value:y.consumer_name||"",onChange:j=>
10E("consumer_name",j.target.value)})}),e.jsx(Q,{label:"ס×××ס",required:!0,children:e.jsxs("select",{className:yt,value:y.status,onChange:j=>E("status",j.target.value),children:[e.jsx("option",{value:"active",children:"פע××"}),e.jsx("option",{value:"inactive",children:"×× ×¤×¢××"})]})}),e.jsx(Q,{label:"קר××× ×§×××ת (××´×§)",info:"×קר××× ×©××× × ×ª×××©× ×צר××× ×××¢×× × ××××",children:e.jsx("input",{type:"number",step:"0.001",className:yt,placeholder:"××× ×§×¨××× ×§×××ת",value:y.previous_reading,onChange:j=>E("previous_reading",j.target.value)})}),e.jsx(Q,{label:"ת×ר×× ×§×¨××× ×§×××ת",children:e.jsx("input",{type:"date",className:yt,value:y.previous_reading_date||"",onChange:j=>E("previous_reading_date",j.target.value)})}),e.jsx(Q,{label:"× ×¤×©×ת ×××ש××",info:"×ר×רת ××××× ××× ×ספר ×× ×¤×©×ת ××שפ××, ×× ××ª× ××©× ×ת ×××ª× â ××סת ×××× ××× ×¢× ××× ×©× ×ת×××× ×××× × ×ª××× ×××",children:e.jsx("input",{type:"number",step:"0.5",className:yt,placeholder:"××× ×ספר × ×¤×©×ת",value:y.souls,onChange:j=>E("souls",j.target.value)})}),e.jsx(Q,{label:"×ספר ×××××",info:"× ×¤×©×ת ××××××ת ×ת×ספת ×××¡× ×××ש×ת",children:e.jsx("input",{type:"number",className:yt,placeholder:"0",value:y.eligible_count,onChange:j=>E("eligible_count",j.target.value)})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(Q,{label:"×ער×ת",children:e.jsx("textarea",{className:ua,rows:2,placeholder:"×ער×ת (×× ××××)",value:y.notes||"",onChange:j=>E("notes",j.target.value)})})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-4",children:[e.jsxs("button",{onClick:T,disabled:O,className:ts,children:[e.jsx(ye,{className:"w-4 h-4"})," ",O?"ש××רâ¦":"ש××ר ××× ×"]}),e.jsx("button",{onClick:()=>f(!1),className:$s,children:"×××××"})]})]}):p.length===0?e.jsx("p",{className:"text-sm text-slate-400 text-center py-4",children:"×× ×××××¨× ××× × ××× ××ש××× ××"}):e.jsx("div",{className:"space-y-2",children:p.map(j=>{const q=C(j.id),L=(S==null?void 0:S.meterId)===j.id;return e.jsxs("div",{className:"rounded-xl border border-slate-200",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-sm font-bold text-slate-800",children:["××× × ",j.meter_number]}),j.consumer_id&&e.jsxs("span",{className:"text-[11px] px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:["××××× ",j.consumer_id]}),j.status==="inactive"&&e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-full bg-red-50 text-red-600",children:"×× ×¤×¢××"})]}),e.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:[j.property_address,j.previous_reading!=null?`קר××× ××ר×× × ${mn(j.previous_reading)} (${Vo(j.previous_reading_date)})`:"××× ×§×¨××× ×§×××ת",j.souls!=null?_e(Number(j.souls),"× ×¤×© ××ת","× ×¤×©×ת"):"",j.eligible_count?_e(Number(j.eligible_count),"×××× ×××","×××××"):""].filter(Boolean).join(" · ")})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>P(L&&S.tab==="readings"?null:{meterId:j.id,tab:"readings"}),title:"××ס××ר××ת קר×××ת",className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(Tl,{className:"w-4 h-4"})}),e.jsxs("button",{onClick:()=>P(L&&S.tab==="charges"?null:{meterId:j.id,tab:"charges"}),title:"×ש××× ×ת ש××פק×",className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-100 relative",children:[e.jsx(nt,{className:"w-4 h-4"}),q.length>0&&e.jsx("span",{className:"absolute -top-0.5 -left-0.5 text-[9px] bg-sky-600 text-white rounded-full px-1",children:q.length})]}),e.jsx("button",{onClick:()=>_(j),title:"ער×××",className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(It,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>M(j),title:j.status==="active"?"×ש×ת ××× ×":"××¤×¢× ××× ×",className:`w-8 h-8 rounded-lg flex items-center justify-center hover:bg-slate-100 ${j.status==="active"?"text-amber-600":"text-emerald-600"}`,children:e.jsx(ho,{className:"w-4 h-4"})}),q.length===0&&e.jsx("button",{onClick:()=>B(j),title:"××××§×",className:"w-8 h-8 rounded-lg flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})]})]}),L&&(S.tab==="readings"?e.jsx(Zu,{kibbutzId:t,meter:j}):e.jsx(Qu,{bills:q}))]},j.id)})})})})}function Zu({kibbutzId:t,meter:s}){const[n,a]=i.useState(null);return i.useEffect(()=>{let l=!0;return D.entities.WaterReading.filter({kibbutz_id:t,water_meter_id:s.id},"-created_date",60).then(r=>{l&&a(r||[])}).catch(()=>{l&&a([])}),()=>{l=!1}},[t,s.id]),n===null?e.jsx("p",{className:"text-xs text-slate-400 px-3 pb-3",children:"×××¢× ×§×¨×××תâ¦"}):n.length?e.jsx("div",{className:"border-t border-slate-100 px-3 py-2 overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-slate-400",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right font-medium py-1",children:"ת×ר××"}),e.jsx("th",{className:"text-right font-medium",children:"×§×××ת"}),e.jsx("th",{className:"text-right font-medium",children:"× ××××ת"}),e.jsx("th",{className:"text-right font-medium",children:"צר×××"}),e.jsx("th",{className:"text-right font-medium",children:"ס×××"}),e.jsx("th",{className:"text-right font-medium",children:"ס×××ס"})]})}),e.jsx("tbody",{children:n.map(l=>e.jsxs("tr",{className:"border-t border-slate-50",children:[e.jsx("td",{className:"py-1.5 text-slate-500",children:l.read_at||Vo(l.created_date)}),e.jsx("td",{className:"tabular-nums",dir:"ltr",children:mn(l.previous_reading)}),e.jsx("td",{className:"tabular-nums",dir:"ltr",children:mn(l.current_reading)}),e.jsx("td",{className:"tabular-nums font-semibold",dir:"ltr",children:mn(l.consumption)}),e.jsx("td",{className:"tabular-nums",dir:"ltr",children:l.amount==null?"â":ve(l.amount)}),e.jsx("td",{className:"text-slate-500",children:Pa[l.status]||l.status})]},l.id))})]})}):e.jsx("p",{className:"text-xs text-slate-400 px-3 pb-3",children:"××× ×¢×××× ×§×¨×××ת ×××× × ××"})}function Qu({bills:t}){const[s,n]=i.useState(null);return t.length?e.jsx("div",{className:"border-t border-slate-100 px-3 py-2 space-y-1.5",children:t.map(a=>{var l;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>n(s===a.id?null:a.id),className:"w-full flex items-center justify-between gap-2 text-xs py-1 text-right",children:[e.jsx("span",{className:"text-slate-600 truncate",children:a.description||a.billing_period}),e.jsx("span",{className:"font-bold tabular-nums flex-shrink-0",dir:"ltr",children:ve(a.amount)})]}),s===a.id&&((l=a.details)==null?void 0:l.breakdown)&&e.jsx(dr,{b:a.details.breakdown,compact:!0})]},a.id)})}):e.jsx("p",{className:"text-xs text-slate-400 px-3 pb-3",children:"×× ×××¤×§× ×ש××× ×ת ×××× × ××"})}const Gr=()=>`apm-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function Ju({kibbutzId:t,account:s}){const[n,a]=i.useState([]),[l,r]=i.useState([]),[o,p]=i.useState({}),[u,d]=i.useState([]),[c,m]=i.useState(!0),[h,b]=i.useState(null),[f,x]=i.useState(!1),g=i.useCallback(async()=>{m(!0);try{const[S,P,E]=await Promise.all([D.entities.ChargeType.filter({kibbutz_id:t,is_active:!0},"order",300).catch(()=>[]),D.entities.AccountPaymentMethod.filter({kibbutz_id:t,payer_account_id:s.id},"-created_date",50).catch(()=>[]),D.entities.ChargeTypePaymentMethod.filter({kibbutz_id:t,payer_account_id:s.id},"-created_date",200).catch(()=>[])]);a(S||[]),r((P||[]).filter(C=>C.is_active!==!1)),d(E||[]);const k={};
10for(const C of E||[])k[C.charge_type_id]=C.payment_method_id;p(k)}finally{m(!1)}},[t,s.id]);i.useEffect(()=>{g()},[g]);const y=i.useMemo(()=>new Map(l.map(S=>[S.id,S])),[l]),$=n.filter(S=>!o[S.id]).length,O=i.useMemo(()=>l.map(S=>({...S,in_use_for:n.filter(P=>o[P.id]===S.id).map(P=>P.name)})),[l,n,o]),A=async(S,P)=>{x(!0);try{let E=P.payment_method_id;E||(E=(await D.entities.AccountPaymentMethod.create({id:Gr(),kibbutz_id:t,payer_account_id:s.id,kind:P.kind,label:ed(P.label),last4:Jc(P.last4),is_active:!0,created_source:"manager"})).id);const k=u.find(C=>C.charge_type_id===S);k?await D.entities.ChargeTypePaymentMethod.update(k.id,{payment_method_id:E,updated_source:"manager"}):await D.entities.ChargeTypePaymentMethod.create({id:Gr().replace("apm-","ctm-"),kibbutz_id:t,payer_account_id:s.id,charge_type_id:S,payment_method_id:E,updated_source:"manager"}),W.success("×××¦×¢× ×תש××× × ×©×ר"),b(null),await g()}catch{W.error("ש×××× ×ש××רת ×××¦×¢× ×תש×××")}finally{x(!1)}};return c?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-400 py-4",children:[e.jsx(Ie,{className:"w-4 h-4 animate-spin"})," ×××¢× ×××¦×¢× ×ª×©×××â¦"]}):n.length?e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50/60 p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 flex-wrap mb-3",children:[e.jsxs("h4",{className:"text-sm font-extrabold text-slate-800 inline-flex items-center gap-1.5",children:[e.jsx(Oe,{className:"w-4 h-4 text-slate-400"})," ×××¦×¢× ×ª×©××× ××¤× ×¡×× ××××"]}),$>0?e.jsx("span",{className:"text-[12px] font-bold text-red-600",children:$===1?"ס×× ×××× ××× ××× ×××¦×¢× ×ª×©×××":`${$} ס××× ×××× ××× ×××¦×¢× ×ª×©×××`}):e.jsx("span",{className:"text-[12px] font-bold text-emerald-600",children:"××× ×¡××× ××××× ××××ר ×××¦×¢× ×ª×©×××"})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:n.map(S=>{const P=y.get(o[S.id]);return e.jsxs("button",{type:"button",onClick:()=>b(S),className:`flex items-center gap-2.5 p-3 rounded-xl border bg-white text-right transition-colors ${P?"border-slate-200 hover:border-slate-300":"border-red-200 hover:border-red-300"}`,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800 truncate",children:S.name}),e.jsx("span",{className:`block text-[12px] mt-0.5 truncate ${P?"text-slate-500":"text-red-600 font-bold"}`,children:P?Zc(P):"×××¦×¢× ×ª×©××× ×× ××××ר"})]}),e.jsx(It,{className:"w-3.5 h-3.5 text-slate-400 flex-none"})]},S.id)})}),e.jsxs("p",{className:"text-[11.5px] text-slate-400 mt-3 flex items-start gap-1.5",children:[e.jsx(Un,{className:"w-3.5 h-3.5 flex-none mt-0.5"}),"×× ×©××××ר ××× ×××¦× ×ת××©× ××ר×× ××××©× ×ª×ת «×תש××××× ×©××», ×××× ×××× ××©× ×ת ×××ª× ×עצ××. ×× × ×©×ר×× ××¡×¤×¨× ×ר××ס ×× ×ש××× ×× ×§."]}),h&&e.jsx(Qc,{title:`×××רת ×××¦×¢× ×ª×©××× â ${h.name}`,subtitle:`${s.name||`×ש××× #${s.account_number}`} · × ××ª× ××××ר ×××¦×¢× ×ª×©××× ×©××ר ××××ר ××ש××× ×× ×××ס××£ ××ש`,methods:O,value:o[h.id],busy:f,onClose:()=>b(null),onSave:S=>A(h.id,S)})]}):null}const Go=[{v:"personal_area",l:"×××ר ××ש×"},{v:"email",l:'×××"×'},{v:"whatsapp",l:"WhatsApp"},{v:"push",l:"Push"},{v:"print",l:"××פס×/×ס×ר×"}],Ea=t=>String(t||"").split(",").map(s=>s.trim()).filter(Boolean),em=t=>Ea(t).map(s=>{var n;return((n=Go.find(a=>a.v===s))==null?void 0:n.l)||s}),Xr=[{v:"",l:"â ×× ××××ר â"},{v:"standing_order",l:"××ר×ת ×§××¢"},{v:"credit",l:"×ר××ס ×שר××"},{v:"bank_transfer",l:"××¢××¨× ×× ×§××ת"},{v:"cash",l:"×××××"},{v:"check",l:"×××××"}],Zr={active:"פע××",inactive:"×× ×¤×¢××",frozen:"××קפ×"},Qr=["××ת ×××ר××","××××ת ×××ר","עסק","××ס×","××× × ××§×××","× ×ס × ×סף"],Fa=t=>(t==null?void 0:t.full_name)||[t==null?void 0:t.first_name,t==null?void 0:t.last_name].filter(
10Boolean).join(" ")||"ת×ש×",Pe=Se,Vt=t=>{if(t==null||t==="")return"";const s=Number(t);return Number.isFinite(s)?String(s):String(t).trim()};function tm({kibbutzId:t}){const[s,n]=i.useState(!0),[a,l]=i.useState([]),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState(""),[b,f]=i.useState("all"),[x,g]=i.useState(null),[y,$]=i.useState([]),[O,A]=i.useState({}),S=N=>A(v=>({...v,[N]:!v[N]})),P=i.useCallback(async()=>{n(!0);try{const[N,v,F,K,Z]=await Promise.all([D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name"),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me},"-created_date"),D.entities.PayerAccount.filterAll({kibbutz_id:t}),D.entities.Property.filterAll({kibbutz_id:t}),D.entities.KolboImportBatch.filter({kibbutz_id:t,status:"approved"}).catch(()=>[])]);l(N||[]),o(v||[]),u(F||[]),c(K||[]),$(Z||[])}catch{W.error("ש×××× ×××¢×× ×ª × ×ª×× ××")}finally{n(!1)}},[t]);i.useEffect(()=>{P()},[P]);const E=i.useMemo(()=>Object.fromEntries(p.map(N=>[N.family_id,N])),[p]),k=i.useCallback(N=>{const v=r.filter(te=>te.family_id===N.id&&te.status!=="inactive"),F=v.find(te=>te.id===N.head_of_family_id)||v.find(te=>te.family_role==="head"),K=v.find(te=>te.family_role==="spouse"),Z=v.filter(te=>te.family_role==="child").map(te=>({...te,age:Xc(te.birth_date)})).sort((te,ie)=>(ie.age??-1)-(te.age??-1)),H=[N.street,N.house_number].filter(Boolean).join(" ")||[F==null?void 0:F.street,F==null?void 0:F.house_number].filter(Boolean).join(" "),z=Vt(F==null?void 0:F.budget)||v.map(te=>Vt(te.budget)).find(Boolean)||"";return{members:v,head:F,spouse:K,children:Z,address:H,budget:z}},[r]),C=i.useMemo(()=>{const N={};r.forEach(F=>{var K;F.family_id&&F.status!=="inactive"&&(N[K=F.family_id]||(N[K]=[])).push(F)});const v={};return a.forEach(F=>{const K=N[F.id]||[],Z=K.find(z=>z.id===F.head_of_family_id)||K.find(z=>z.family_role==="head"),H=Vt(Z==null?void 0:Z.budget)||K.map(z=>Vt(z.budget)).find(Boolean)||"";H&&(v[F.id]=H)}),v},[a,r]),w=i.useMemo(()=>{const N=new Map;return Object.values(C).forEach(v=>N.set(v,(N.get(v)||0)+1)),new Set([...N.entries()].filter(([,v])=>v>1).map(([v])=>v))},[C]),_=i.useMemo(()=>y.map(N=>N.id),[y]),T=i.useMemo(()=>{const N=new Set(r.filter(v=>v.status!=="inactive").map(v=>v.family_id));return a.filter(v=>N.has(v.id)||E[v.id]||C[v.id])},[a,r,E,C]),M=i.useMemo(()=>{let N=[...T];b==="account"?N=N.filter(F=>E[F.id]):b==="budget"?N=N.filter(F=>C[F.id]):b==="none"&&(N=N.filter(F=>!E[F.id]&&!C[F.id]));const v=m.trim().toLowerCase();return v&&(N=N.filter(F=>{var K;return(F.name||"").toLowerCase().includes(v)||[F.street,F.house_number].filter(Boolean).join(" ").toLowerCase().includes(v)||String(((K=E[F.id])==null?void 0:K.account_number)||"").includes(v)||(C[F.id]||"").includes(v)})),N.sort((F,K)=>String(F.name||"").localeCompare(String(K.name||""),"he"))},[T,b,m,E,C]),B=()=>{const N=p.map(v=>parseInt(String(v.account_number||"").replace(/\D/g,""),10)).filter(v=>!Number.isNaN(v));return String((N.length?Math.max(...N):1e3)+1)};async function R(N){var F;const v=k(N);try{const K=await D.entities.PayerAccount.create({kibbutz_id:t,family_id:N.id,primary_resident_id:((F=v.head)==null?void 0:F.id)||null,account_number:B(),name:N.name||Fa(v.head),status:"active",opening_balance:0,preferred_delivery_channel:"personal_area"});D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"account_created",entity_type:"payer_account",entity_id:K.id,payer_account_id:K.id,new_value:K.account_number}).catch(()=>{}),W.success("×ש××× ××ש×× × ×¤×ª×"),await P(),g(N.id)}catch{W.error("ש×××× ×פת××ת ×ש×××")}}if(s)return e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})});const j=x?a.find(N=>N.id===x):null,q=j?E[j.id]:null,L=j?k(j):null;return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4 items-start",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[e.jsxs("div",{className:"relative mb-2",children:[e.jsx(qt,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{value:m,onChange:N=>h(N.target.value),placeholder:"××פ×ש ×שפ×× / ×ש××× / תקצ××â¦",className:"w-full h-10 rounded-lg border border-slate-200 pr-9 pl-3 text-sm"})]}),e.jsx("div",{className:"grid grid-cols-4 gap-1 mb-2",children:[{k:"all",l:"×××",n:T.length},{k:"account",l:"×ש×××",n:T.filter(N=>E[N.id]).length},{k:"budget",l:"תקצ××",n:T.filter(N=>C[N.id]).length},{k:"none",l:"×××",n:T.filter(N=>!E[N.id]&&!C[N.id]).length}].map(N=>{const v=b===N.k;return e.jsxs("button",{onClick:()=>f(N.k),title:N.k==="none"?"××× ×ש××× ×××× ×ספר תקצ××":void 0,className:`h-11 rounded-xl text-xs font-bold border transition-all flex flex-col items-center justify-center leading-none gap-0.5 11 ${v?"bg-indigo-600 text-white border-transparent shadow-sm":"bg-white border-slate-200 text-slate-600 hover:border-slate-300"}`,children:[e.jsx("span",{children:N.l}),e.jsx("span",{className:`text-[10px] font-semibold ${v?"text-white/70":"text-slate-400"}`,children:N.n})]},N.k)})}),e.jsxs("div",{className:"space-y-1.5 max-h-[70vh] overflow-y-auto",children:[M.map(N=>{const v=E[N.id],F=x===N.id;return e.jsxs("button",{onClick:()=>g(N.id),className:`w-full text-right rounded-xl border px-3 py-2.5 transition-all ${F?"border-indigo-300 ring-2 ring-indigo-100":"border-slate-200 hover:bg-slate-50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-bold text-slate-800 truncate",children:N.name||"â"}),e.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[C[N.id]&&e.jsxs("span",{className:`text-[11px] px-2 py-0.5 rounded-full inline-flex items-center gap-1 12 ${w.has(C[N.id])?"bg-rose-50 text-rose-700 ring-1 ring-rose-200":"bg-amber-50 text-amber-700"}`,title:w.has(C[N.id])?"×ספר ×תקצ×× ××× ×¨×©×× ×× ××שפ×× ××רת â ×§× ××ת ×××××× ×©×× ×× ××צ×× ×××ש":"×ספר תקצ××",children:[w.has(C[N.id])&&e.jsx(At,{className:"w-3 h-3"}),"תקצ×× ",C[N.id]]}),v?e.jsxs("span",{className:"text-[11px] px-2 py-0.5 rounded-full bg-emerald-50 text-emerald-700",children:["#",v.account_number]}):e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-full bg-slate-100 text-slate-500",children:"××× ×ש×××"})]})]}),e.jsx("span",{className:"text-xs text-slate-400 truncate block",children:[N.street,N.house_number].filter(
12Boolean).join(" ")})]},N.id)}),M.length===0&&e.jsx("p",{className:"text-sm text-slate-400 text-center py-6",children:"××× ×ª×צ××ת"})]})]}),e.jsx("div",{className:"lg:col-span-2 space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsx(Ra,{tone:"indigo",icon:De,title:j.name,summary:[_e(L.members.length,"× ×¤×© ××ת","× ×¤×©×ת"),L.head&&Fa(L.head),L.address].filter(Boolean).join(" · "),open:!!O.family,onToggle:()=>S("family"),action:e.jsxs("button",{onClick:()=>S("family"),className:"h-8 px-3 rounded-full bg-indigo-600 text-white text-xs inline-flex items-center gap-1 hover:bg-indigo-700 transition-colors flex-shrink-0",children:[e.jsx(fs,{className:"w-3.5 h-3.5"})," ",O.family?"×סתר פר×××":"××¦× ×¤×¨×××"]}),children:e.jsx(sm,{info:L})}),q?e.jsx(am,{kibbutzId:t,account:q,residents:L.members,budget:L.budget,onSaved:P,open:!!O.account,onToggle:()=>S("account")}):e.jsxs("div",{className:"bg-white rounded-2xl border border-dashed border-indigo-300 p-6 text-center",children:[e.jsx(es,{className:"w-9 h-9 text-indigo-400 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-slate-600 mb-3",children:"××שפ×× ×× ××× ×¢×××× ×ש××× ×ש××."}),e.jsxs("button",{onClick:()=>R(j),className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full bg-indigo-600 text-white text-sm font-bold",children:[e.jsx(We,{className:"w-4 h-4"})," ×¤×ª× ×ש××× ×ש××"]})]}),q&&e.jsx(nm,{kibbutzId:t,account:q,properties:d.filter(N=>N.payer_account_id===q.id),onChanged:P,open:!!O.properties,onToggle:()=>S("properties")}),q&&e.jsx(Xu,{kibbutzId:t,account:q,properties:d.filter(N=>N.payer_account_id===q.id),familySouls:L.members.length,familyName:j.name,open:!!O.water,onToggle:()=>S("water")}),_.length>0&&L.budget&&e.jsx(lm,{kibbutzId:t,family:j,budget:L.budget,approvedBatchIds:_,open:!!O.kolbo,onToggle:()=>S("kolbo")})]}):e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-12 text-center text-sm text-slate-400",children:[e.jsx(De,{className:"w-10 h-10 text-slate-300 mx-auto mb-2"})," ×××¨× ×שפ×× ××× ×צפ×ת ××ש××× ××ש×× ××× ×× × ×ס××"]})})]})}function Jr({label:t,person:s,icon:n}){return e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50/60 p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(n,{className:"w-3.5 h-3.5 text-slate-400"}),e.jsx("span",{className:"text-[11px] font-bold text-slate-500",children:t})]}),s?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-bold text-slate-900 truncate mb-1.5",children:Fa(s)}),e.jsxs("p",{className:"flex items-center gap-1.5 text-[13px] text-slate-700 mb-0.5",children:[e.jsx(ao,{className:"w-3.5 h-3.5 text-slate-400 flex-shrink-0"}),s.phone?e.jsx("a",{href:`tel:${s.phone}`,className:"hover:underline",dir:"ltr",children:s.phone}):e.jsx("span",{className:"text-slate-400",children:"â"})]}),e.jsxs("p",{className:"flex items-center gap-1.5 text-[13px] text-slate-700 min-w-0",children:[e.jsx(no,{className:"w-3.5 h-3.5 text-slate-400 flex-shrink-0"}),s.email?e.jsx("a",{href:`mailto:${s.email}`,className:"hover:underline truncate",dir:"ltr",title:s.email,children:s.email}):e.jsx("span",{className:"text-slate-400",children:"â"})]}),Vt(s.budget)&&e.jsxs("p",{className:"mt-2 inline-flex items-center gap-1 text-[11px] font-bold px-2 py-0.5 rounded-full bg-amber-50 text-amber-700",children:[e.jsx(es,{className:"w-3 h-3"})," תקצ×× ",Vt(s.budget)]})]}):e.jsx("p",{className:"text-sm text-slate-400",children:"â"})]})}function sm({info:t}){return e.jsxs("div",{className:"pt-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 mb-3",children:[e.jsx(Jr,{label:"ר×ש ×שפ××",person:t.head,icon:ys}),e.jsx(Jr,{label:"××/×ת ×××",person:t.spouse,icon:ys})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm rounded-xl border border-slate-200 px-3 py-2.5 mb-3",children:[e.jsx(or,{className:"w-4 h-4 text-slate-400 flex-shrink-0"}),e.jsx("span",{className:"text-slate-500",children:"×ת××ת ××שפ××"}),e.jsx("span",{className:"font-medium text-slate-900",children:t.address||"â"})]}),e.jsxs("div",{className:"rounded-xl border border-slate-200 px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1.5",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(fd,{className:"w-4 h-4 text-slate-400"}),e.jsxs("span",{className:"text-[11px] font-bold text-slate-500",children:["××××× (",t.children.length,")"]})]}),e.jsxs("span",{className:"text-[11px] font-bold text-slate-500 bg-slate-100 rounded-full px-2.5 py-0.5 whitespace-nowrap",children:["ס××´× ",t.members.length," × ×¤×©×ת ××שפ××"]})]}),t.children.length===0?e.jsx("p",{className:"text-sm text-slate-400",children:"××× ××××× ×¨×©×××× ××שפ××"}):e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.children.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[13px] bg-slate-50 border border-slate-200 rounded-lg px-2.5 py-1",children:[e.jsx("span",{className:"font-medium text-slate-800",children:Fa(s)}),e.jsx("span",{className:"text-slate-400",children:s.age==null?"â":`××× ${s.age}`})]},s.id))})]})]})}function am({kibbutzId:t,account:s,residents:n,budget:a="",onSaved:l,open:r,onToggle:o}){var x;const[p,u]=i.useState(!1),[d,c]=i.useState({...s}),[m,h]=i.useState(!1);i.useEffect(()=>{c({...s})},[s]);const b=(g,y)=>c($=>({...$,[g]:y})),f=async()=>{h(!0);try{await D.entities.PayerAccount.update(s.id,{account_number:d.account_number,name:d.name,id_number:d.id_number,status:d.status,opening_balance:Number(d.opening_balance)||0,preferred_delivery_channel:d.preferred_delivery_channel,payment_method:d.payment_method,primary_resident_id:d.primary_resident_id,notes:d.notes}),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"account_updated",entity_type:"payer_account",entity_id:s.id,payer_account_id:s.id}).catch(()=>{}),W.success("××ש××× ×¢××××"),u(!1),l()}catch{W.error("ש×××× ×ש××ר×")}finally{h(!1)}};return e.jsx(Ra,{tone:"emerald",icon:gd,title:`×ש××× ×ש×× #${s.account_number}`,summary:[a&&`תקצ×× ${a}
12`,Zr[s.status]||s.status,s.name].filter(Boolean).join(" · "),open:r,onToggle:o,action:p?e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsxs("button",{onClick:f,disabled:m,className:"h-8 px-3 rounded-full bg-emerald-600 text-white text-xs inline-flex items-center gap-1",children:[e.jsx(ye,{className:"w-3.5 h-3.5"})," ש××ר"]}),e.jsx("button",{onClick:()=>{u(!1),c({...s})},className:"h-8 w-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-3.5 h-3.5"})})]}):e.jsxs("button",{onClick:()=>{u(!0),r||o()},className:"h-8 px-3 rounded-full bg-emerald-600 text-white text-xs inline-flex items-center gap-1 hover:bg-emerald-700 transition-colors flex-shrink-0",children:[e.jsx(It,{className:"w-3.5 h-3.5"})," ער×××"]}),children:e.jsx("div",{className:"billing-form pt-4",children:p?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx(Q,{label:"×ספר ×ש×××",required:!0,children:e.jsx("input",{className:Pe,placeholder:"××× ×ספר ×ש×××",value:d.account_number||"",onChange:g=>b("account_number",g.target.value)})}),e.jsx(Q,{label:"×©× ××ש×× ×ר×ש×",required:!0,children:e.jsx("input",{className:Pe,placeholder:"××× ×©× ×ש××",value:d.name||"",onChange:g=>b("name",g.target.value)})}),e.jsx(Q,{label:'ת"× / ×××× ×¤× ×××',children:e.jsx("input",{className:Pe,placeholder:'××× ×ª"× / ××××',value:d.id_number||"",onChange:g=>b("id_number",g.target.value)})}),e.jsx(Q,{label:"×ש×× ×¨×ש×",children:e.jsxs("select",{className:Pe,value:d.primary_resident_id||"",onChange:g=>b("primary_resident_id",g.target.value),children:[e.jsx("option",{value:"",children:"â"}),n.map(g=>e.jsx("option",{value:g.id,children:Fa(g)},g.id))]})}),e.jsx(Q,{label:"ס×××ס",required:!0,children:e.jsx("select",{className:Pe,value:d.status||"active",onChange:g=>b("status",g.target.value),children:Object.entries(Zr).map(([g,y])=>e.jsx("option",{value:g,children:y},g))})}),e.jsx(Q,{label:"×תרת פת××× (âª)",children:e.jsx("input",{type:"number",className:Pe,placeholder:"0",value:d.opening_balance??0,onChange:g=>b("opening_balance",g.target.value)})}),e.jsx(Q,{label:"×××¦×¢× ×§××ת ×ש×××",info:"×ער×צ×× ×©××× ××ש××× ×××××©× ××ש×× ×ת××©× â ×פשר ×ס×× ×××",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Go.map(g=>{const y=Ea(d.preferred_delivery_channel).includes(g.v);return e.jsxs("button",{type:"button",onClick:()=>{const $=Ea(d.preferred_delivery_channel),O=y?$.filter(A=>A!==g.v):[...$,g.v];b("preferred_delivery_channel",O.join(","))},className:`h-9 px-3 rounded-lg border text-[13px] font-bold inline-flex items-center gap-1.5 transition-colors ${y?"bg-indigo-50 border-indigo-300 text-indigo-700":"bg-white border-slate-200 text-slate-500 hover:border-slate-300"}`,children:[e.jsx("span",{className:`w-3.5 h-3.5 rounded-[4px] border flex items-center justify-center ${y?"bg-indigo-600 border-indigo-600 text-white":"border-slate-300"}`,children:y&&e.jsx(ye,{className:"w-2.5 h-2.5"})}),g.l]},g.v)})})}),e.jsx(Q,{label:"×××¦×¢× ×ª×©××× ××ר×רת ××××",hint:"×ש×ש ×ש×× ××××ר ×××¦×¢× ×ª×©××× ×ס×× ×××××",children:e.jsx("select",{className:Pe,value:d.payment_method||"",onChange:g=>b("payment_method",g.target.value),children:Xr.map(g=>e.jsx("option",{value:g.v,children:g.l},g.v))})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(Q,{label:"×ער×ת",children:e.jsx("textarea",{className:ua,rows:2,placeholder:"×ער×ת (×× ××××)",value:d.notes||"",onChange:g=>b("notes",g.target.value)})})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(Ju,{kibbutzId:t,account:s})})]}):e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-x-6 gap-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-400",children:"×©× ××ש××"}),e.jsx("p",{className:"font-medium",children:s.name||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-400",children:'ת"× / ××××'}),e.jsx("p",{className:"font-medium",children:s.id_number||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-400",children:"×תרת פת×××"}),e.jsx("p",{className:"font-medium",children:ve(s.opening_balance)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-400",children:"×××¦×¢× ×§××ת ×ש×××"}),e.jsx("p",{className:"font-medium",children:em(s.preferred_delivery_channel).join(" · ")||"â"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-slate-400",children:"×××¦×¢× ×ª×©×××"}),e.jsx("p",{className:"font-medium",children:((x=Xr.find(g=>g.v===s.payment_method))==null?void 0:x.l)||"â"})]}),s.notes&&e.jsxs("div",{className:"col-span-full",children:[e.jsx("p",{className:"text-xs text-slate-400",children:"×ער×ת"}),e.jsx("p",{className:"font-medium",children:s.notes})]})]})})})}function nm({kibbutzId:t,account:s,properties:n,onChanged:a,open:l,onToggle:r}){const[o,p]=i.useState(!1),[u,d]=i.useState(null),c={property_number:"",property_type:Qr[0],address:"",gush_helka:"",size_sqm:"",built_sqm:"",extra_sqm:"",occupancy_count:"",active_from:"",active_until:"",status:"active",notes:""},[m,h]=i.useState(c),[b,f]=i.useState(!1),x=(A,S)=>h(P=>({...P,[A]:S})),g=()=>{d(null),h(c),p(!0)},y=A=>{d(A),h({...c,...A}),p(!0)},$=async()=>
12{if(!m.property_number&&!m.address){W.error("×ש ××××× ×ספר/×ת××ת × ×ס");return}f(!0);const A={kibbutz_id:t,payer_account_id:s.id,property_number:m.property_number,property_type:m.property_type,address:m.address,gush_helka:m.gush_helka,size_sqm:m.size_sqm===""?null:Number(m.size_sqm),built_sqm:m.built_sqm===""?null:Number(m.built_sqm),extra_sqm:m.extra_sqm===""?null:Number(m.extra_sqm),occupancy_count:m.occupancy_count===""?null:Number(m.occupancy_count),active_from:m.active_from||null,active_until:m.active_until||null,status:m.status,notes:m.notes};try{u?await D.entities.Property.update(u.id,A):await D.entities.Property.create(A),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:u?"property_updated":"property_created",entity_type:"property",entity_id:(u==null?void 0:u.id)||null,payer_account_id:s.id}).catch(()=>{}),W.success("×× ×ס × ×©×ר"),p(!1),a()}catch{W.error("ש×××× ×ש××רת ×× ×ס")}finally{f(!1)}},O=async A=>{if(confirm(`×××××§ ×ת ×× ×ס "${A.property_number||A.address}"?`))try{await D.entities.Property.delete(A.id),W.success("×× ×ס × ×××§"),a()}catch{W.error("ש××××")}};return e.jsx(Ra,{tone:"amber",icon:ra,title:`× ×ס×× (${n.length})`,summary:n.length?n.map(A=>A.property_number||A.address).filter(Boolean).join(" · "):"×× ×©×××× × ×ס×× ××ש××× ××",open:l,onToggle:r,action:!o&&e.jsxs("button",{onClick:()=>{g(),l||r()},className:"h-8 px-3 rounded-full bg-amber-600 text-white text-xs inline-flex items-center gap-1 flex-shrink-0",children:[e.jsx(We,{className:"w-3.5 h-3.5"})," ××סף × ×ס"]}),children:e.jsx("div",{className:"billing-form pt-4",children:o?e.jsxs("div",{className:"rounded-xl border border-slate-200 p-4 mb-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(Q,{label:"×ספר/×©× × ×ס",required:!0,children:e.jsx("input",{className:Pe,placeholder:"××× ×ספר ×× ×©× × ×ס",value:m.property_number,onChange:A=>x("property_number",A.target.value)})}),e.jsx(Q,{label:"ס×× × ×ס",required:!0,children:e.jsx("select",{className:Pe,value:m.property_type,onChange:A=>x("property_type",A.target.value),children:Qr.map(A=>e.jsx("option",{value:A,children:A},A))})}),e.jsx(Q,{label:"×ת××ת",required:!0,children:e.jsx("input",{className:Pe,placeholder:"××× ×ת××ת",value:m.address,onChange:A=>x("address",A.target.value)})}),e.jsx(Q,{label:"××ש/×××§×",required:!0,children:e.jsx("input",{className:Pe,placeholder:"××× ××ש/×××§×",value:m.gush_helka,onChange:A=>x("gush_helka",A.target.value)})}),e.jsx(Q,{label:"×××× (×״ר)",required:!0,children:e.jsx("input",{type:"number",className:Pe,placeholder:'××× ×××× ××"ר',value:m.size_sqm,onChange:A=>x("size_sqm",A.target.value)})}),e.jsx(Q,{label:"ש×× ×× ×× (×״ר)",children:e.jsx("input",{type:"number",className:Pe,placeholder:'××× ×©×× ×× ×× ××"ר',value:m.built_sqm,onChange:A=>x("built_sqm",A.target.value)})}),e.jsx(Q,{label:"ש×× × ×סף ×××××",info:"ש×× × ×סף ש×צ×רף ×××ש×× ××××× ××¤× ×״ר",children:e.jsx("input",{type:"number",className:Pe,placeholder:"××× ×©×× × ×סף ×××××",value:m.extra_sqm,onChange:A=>x("extra_sqm",A.target.value)})}),e.jsx(Q,{label:"× ×¤×©×ת ×ש××××ת",info:"×ספר ×× ×¤×©×ת ××ש×ש ××××× ××¤× × ×¤×©",children:e.jsx("input",{type:"number",className:Pe,placeholder:"××× ×ספר × ×¤×©×ת",value:m.occupancy_count,onChange:A=>x("occupancy_count",A.target.value)})}),e.jsx(Q,{label:"ס×××ס",required:!0,children:e.jsxs("select",{className:Pe,value:m.status,onChange:A=>x("status",A.target.value),children:[e.jsx("option",{value:"active",children:"פע××"}),e.jsx("option",{value:"inactive",children:"×× ×¤×¢××"})]})}),e.jsx(Q,{label:"ת×ר×× ×ª×××ת ש×××",children:e.jsx("input",{type:"date",className:Pe,value:m.active_from||"",onChange:A=>x("active_from",A.target.value)})}),e.jsx(Q,{label:"ס××× ×©×××",children:e.jsx("input",{type:"date",className:Pe,value:m.active_until||"",onChange:A=>x("active_until",A.target.value)})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-4",children:[e.jsxs("button",{onClick:$,disabled:b,className:ts,children:[e.jsx(ye,{className:"w-4 h-4"})," ",b?"ש××רâ¦":"ש××ר × ×ס"]}),e.jsx("button",{onClick:()=>p(!1),className:$s,children:"×××××"})]})]}):n.length===0?e.jsx("p",{className:"text-sm text-slate-400 text-center py-4",children:"×× ×©×××× × ×ס×× ××ש××× ××"}):e.jsx("div",{className:"space-y-2",children:n.map(A=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-slate-200 px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-bold text-slate-800",children:A.property_number||A.address||"× ×ס"}),e.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:A.property_type}),A.status==="inactive"&&e.jsx("span",{className:"text-[11px] text-red-500",children:"×× ×¤×¢××"})]}),e.jsx("div",{className:"text-xs text-slate-400 mt-0.5",children:[A.address,A.size_sqm!=null?`${A.size_sqm} ×״ר`:"",A.occupancy_count!=null?`${A.occupancy_count}
12 × ×¤×©×ת`:""].filter(Boolean).join(" · ")})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>y(A),className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(It,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>O(A),className:"w-8 h-8 rounded-lg flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})]})]},A.id))})})})}function lm({kibbutzId:t,family:s,budget:n,approvedBatchIds:a,open:l,onToggle:r}){const[o,p]=i.useState(null);i.useEffect(()=>{if(!l||o!==null||!(s!=null&&s.id)||!a.length)return;let m=!0;return D.entities.KolboPurchase.filterAll({kibbutz_id:t,family_id:s.id}).then(h=>{m&&p((h||[]).filter(b=>a.includes(b.batch_id)))}).catch(()=>{m&&p([])}),()=>{m=!1}},[l,o,t,s==null?void 0:s.id,a]);const u=i.useMemo(()=>{const m=new Map;return(o||[]).forEach(h=>{const b=String(h.txn_date||"").slice(0,7);if(!b)return;const f=m.get(b)||{month:b,total:0,receipts:new Set,lines:0};f.total+=Number(h.total)||0,f.receipts.add(`${h.txn_date}|${h.receipt}`),f.lines+=1,m.set(b,f)}),[...m.values()].map(h=>({...h,total:ka(h.total),visits:h.receipts.size})).sort((h,b)=>b.month.localeCompare(h.month))},[o]),d=td((o||[]).map(m=>({total:Number(m.total)||0}))),c=_n(o||[]).length;return e.jsx(Ra,{tone:"indigo",icon:da,title:"ר××ש×ת ××××××",summary:o===null?`תקצ×× ${n} · ×××¦× ×צפ××× ××××`:o.length?[_e(u.length,"×××ש ×××","×××ש××"),_e(c,"×××§×ר ×××","×××§×ר××"),ve(d)].join(" · "):"××× ×¨××ש×ת רש×××ת ××שפ×× ××",open:l,onToggle:r,children:e.jsx("div",{className:"pt-4",children:o===null?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx("div",{className:"w-6 h-6 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})}):o.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-1.5",children:u.map(m=>e.jsx(rm,{month:m,rows:o||[]},m.month))}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2.5 mt-2 rounded-xl bg-slate-50 border border-slate-200",children:[e.jsxs("span",{className:"text-sm font-extrabold text-slate-700",children:["ס××´× ×¨××ש×ת · תקצ×× ",n]}),e.jsx("span",{className:"text-sm font-extrabold tabular-nums",dir:"ltr",children:ve(d)})]})]}):e.jsx("p",{className:"text-sm text-slate-400 text-center py-4",children:"××× ×¨××ש×ת רש×××ת ××שפ×× ××."})})})}function rm({month:t,rows:s}){const[n,a]=i.useState(!1),l=i.useMemo(()=>{if(!n)return[];const r=s.filter(o=>String(o.txn_date||"").slice(0,7)===t.month);return _n(r).map(o=>({...o,total:ka(o.total)})).sort((o,p)=>String(p.date).localeCompare(String(o.date))||String(p.receipt).localeCompare(String(o.receipt)))},[n,s,t.month]);return e.jsxs("div",{className:"rounded-xl border border-slate-200 overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>a(r=>!r),className:"w-full flex items-center justify-between gap-3 px-3 py-2.5 text-right hover:bg-slate-50",children:[e.jsx("span",{className:"text-sm font-bold text-slate-800",children:om(t.month)}),e.jsxs("span",{className:"text-xs text-slate-400 flex-1",children:[_e(t.visits,"×××§×ר ×××","×××§×ר××")," · ",_e(t.lines,"ש××¨× ××ת","ש×ר×ת")]}),e.jsx("span",{className:"text-sm font-extrabold text-slate-900 tabular-nums",dir:"ltr",children:ve(t.total)}),e.jsx(Jt,{className:`w-4 h-4 text-slate-400 flex-shrink-0 transition-transform ${n?"rotate-180":""}`})]}),n&&e.jsxs("div",{className:"border-t border-slate-100 divide-y divide-slate-50",children:[l.map(r=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("span",{className:"text-[11px] font-extrabold px-2 py-1 rounded-lg bg-indigo-50 text-indigo-700 tabular-nums whitespace-nowrap",dir:"ltr",children:["×ס×××ª× ",r.receipt]}),e.jsxs("span",{className:"text-xs text-slate-500 flex-1 whitespace-nowrap",children:[im(r.date),Sr(r.receipt)?` · ${Sr(r.receipt)}`:""," · ",_e(r.lines.length,"פר×× ×××","פר××××")]}),e.jsx("span",{className:"text-sm font-bold text-slate-800 tabular-nums",dir:"ltr",children:ve(r.total)})]},`${r.date}|${r.receipt}`)),l.length===0&&e.jsx("p",{className:"text-xs text-slate-400 px-3 py-2",children:"××× ×ש××× ××ת ××××ש ××"})]})]})}const im=t=>{const[s,n,a]=String(t||"").slice(0,10).split("-");return a?`${a}/${n}/${String(s).slice(2)}`:t||""};function om(t){const s=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"],[n,a]=String(t).split("-");return`${s[Number(a)-1]||a} ${n}`}const cm={×:"A",×:"B",×:"G",×:"D",×:"H",×:"V",×:"Z",×:"H",×:"T",×:"Y",×:"K",×:"K",×:"L",×:"M",×:"M",× :"N",×:"N",ס:"S",×¢:"A",פ:"P",×£:"P",צ:"TZ",×¥:"TZ",×§:"K",ר:"R",ש:"SH",ת:"T"},dm=(t,s,n)=>t==="×"?s===0?"V":"O":t==="×"?s===0?"Y":"I":t==="×"?s===n?"A":"H":cm[t],Xo=16;function um(t){return String(t||"").trim().split(/[\s\-_/]+/).filter(
12Boolean).map(a=>{const l=[...a];return l.map((r,o)=>{const p=dm(r,o,l.length-1);return p||(/[A-Za-z0-9]/.test(r)?r.toUpperCase():"")}).join("")}).filter(Boolean).join("_").slice(0,Xo).replace(/_+$/,"")}function mm(t,s=[],n=null){const a=um(t);if(!a)return"";const l=new Set((s||[]).filter(r=>!n||r.id!==n).map(r=>String((r==null?void 0:r.code)||"").trim().toUpperCase()).filter(Boolean));if(!l.has(a))return a;for(let r=2;r<100;r+=1){const o=`${a.slice(0,Xo-String(r).length)}${r}`;if(!l.has(o))return o}return a}const Da=[{v:"fixed",l:"ס××× ×§×××¢",hint:"ס××× ××× ××× ×ש××"},{v:"per_sqm",l:"××¤× ×״ר",hint:"תער××£ à ש×× ×× ×ס"},{v:"per_person",l:"××¤× × ×¤×©",hint:"תער××£ à ×ספר × ×¤×©×ת"},{v:"per_property",l:"××¤× × ×ס",hint:"תער××£ à ×ספר × ×ס××"},{v:"tiered",l:"×××ר×",hint:"××ר××ת תער××£ ××¤× ×××ת"},{v:"custom",l:"××× ×",hint:"ס××× × ×§××¢ ××× ×ת ××× ×ש××"},{v:"water_meter",l:"צר××ת ××× ××¤× ×§×¨××ת ××× ×",hint:"×××¡× ×× ×¤×© ×תער××£ × ×××, ××ש×ר ×תער××£ ××××"}],Je=t=>t==="water_meter",Oa=t=>{var s;return((s=Da.find(n=>n.v===t))==null?void 0:s.l)||t||"â"},Zo=[{v:"monthly",l:"×××ש×"},{v:"bimonthly",l:"××-×××ש×"},{v:"quarterly",l:"ר××¢×× ×"},{v:"yearly",l:"×©× ×ª×"},{v:"one_time",l:"××-פע××"},{v:"per_file",l:"××¤× ××¢×× ×ª ×§×××¥"}],ei=t=>{var s;return((s=Zo.find(n=>n.v===t))==null?void 0:s.l)||"×××ש×"},it=Se,Ya=()=>({name:"",code:"",description:"",calculation_method:"fixed",rate:"",includes_vat:!0,sumit_budget_item_id:null,billing_cycle:"monthly",due_day:"",issue_days_before:"",valid_from:"",valid_until:"",is_active:!0,show_in_personal_area:!0,online_payable:!1,requires_approval:!1,water_low_rate:"",water_high_rate:"",water_quota_per_soul:"",water_min_souls:"",water_eligible_addition:"",vat_rate:""}),ti=()=>({water_low_rate:String(ns.water_low_rate),water_high_rate:String(ns.water_high_rate),water_quota_per_soul:String(ns.water_quota_per_soul),water_min_souls:String(ns.water_min_souls),water_eligible_addition:String(ns.water_eligible_addition),vat_rate:String(ns.vat_rate),includes_vat:ns.includes_vat,billing_cycle:"per_file"}),et=t=>t===""||t===null||t===void 0?null:Number(t),Ys=t=>t==null||t===""?"â":`${Number(t).toFixed(3).replace(/\.?0+$/,"")} âª`;function xm({kibbutzId:t,onManage:s}){var R;const[,n]=ia(),a=()=>s?s():n({tab:"monthly"},{replace:!0}),[l,r]=i.useState(!0),[o,p]=i.useState([]),[u,d]=i.useState(null),[c,m]=i.useState(!1),[h,b]=i.useState(null),[f,x]=i.useState(Ya()),[g,y]=i.useState(!1),$=(j,q)=>x(L=>({...L,[j]:q})),O=i.useCallback(async()=>{var j;r(!0);try{const[q,L]=await Promise.all([D.entities.ChargeType.filter({kibbutz_id:t},"order",300),D.entities.BillingSettings.filter({kibbutz_id:t},"-created_date",1).catch(()=>[])]);p(q||[]);const N=Number((j=L==null?void 0:L[0])==null?void 0:j.default_due_day);d(Number.isFinite(N)&&N>0?N:null)}catch{W.error("ש×××× ×××¢×× ×ª ס××× ××××××")}finally{r(!1)}},[t]);i.useEffect(()=>{O()},[O]);const A=()=>{b(null),x(Ya()),m(!0)},S=j=>x(q=>({...q,name:j,code:q.code_touched?q.code:mm(j,o,(h==null?void 0:h.id)||null)})),P=()=>{b(null),x({...Ya(),name:"×××",code:"WATER",code_touched:!0,calculation_method:"water_meter",...ti()}),m(!0)},E=j=>{const q=L=>L==null?"":String(L);b(j),x({...Ya(),...j,code_touched:!0,rate:j.rate??"",due_day:j.due_day??"",issue_days_before:j.issue_days_before??"",valid_from:j.valid_from||"",valid_until:j.valid_until||"",water_low_rate:q(j.water_low_rate),water_high_rate:q(j.water_high_rate),water_quota_per_soul:q(j.water_quota_per_soul),water_min_souls:q(j.water_min_souls),water_eligible_addition:q(j.water_eligible_addition),vat_rate:q(j.vat_rate)}),m(!0)},k=j=>x(q=>({...q,calculation_method:j,...Je(j)&&q.water_low_rate===""?ti():{}})),C=async()=>{if(!f.name.trim()){W.error("×ש ××××× ×©× ×¡×× ××××");return}if(Je(f.calculation_method)&&["water_low_rate","water_high_rate","water_quota_per_soul"].filter(L=>f[L]===""||f[L]===null).length){W.error("×ש ××××× ×××ר × ×××, ×××ר ×××× ××××¡× ×× ×¤×©");return}y(!0);const j={kibbutz_id:t,name:f.name.trim(),code:f.code.trim()||null,description:f.description||null,sumit_budget_item_id:f.sumit_budget_item_id||null,calculation_method:f.calculation_method,rate:f.rate===""?0:Number(f.rate),includes_vat:!!f.includes_vat,water_low_rate:Je(f.calculation_method)?et(f.water_low_rate):null,water_high_rate:Je(f.calculation_method)?et(f.water_high_rate):null,water_quota_per_soul:Je(f.calculation_method)?et(f.water_quota_per_soul):null,water_min_souls:Je(f.calculation_method)?et(f.water_min_souls):null,water_eligible_addition:Je(f.calculation_method)?et(f.water_eligible_addition):null,vat_rate:Je(f.calculation_method)?et(f.vat_rate):null,billing_cycle:f.billing_cycle,due_day:f.due_day===""||f.due_day===null?null:Math.min(31,Math.max(1,Number(f.due_day))),issue_days_before:f.issue_days_before===""||f.issue_days_before===null?null:Math.min(60,Math.max(0,Number(f.issue_days_before))),valid_from:f.valid_from||null,valid_until:f.valid_until||null,is_active:!!f.is_active,show_in_personal_area:!!f.show_in_personal_area,online_payable:!!f.online_payable,requires_approval:!!f.requires_approval,order:h?h.order:o.length};try{h?await D.entities.ChargeType.update(h.id,j):await D.entities.ChargeType.create(j),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:h?"charge_type_updated":"charge_type_created",entity_type:"charge_type",entity_id:(h==null?void 0:h.id)||null,new_value:f.name}).catch(()=>{}),W.success("ס×× ××××× × ×©×ר"),m(!1),O()}catch{W.error("ש×××× ×ש××ר×")}finally{y(!1)}},w=async j=>{if(confirm(`×××××§ ×ת ס×× ××××× "${j.name}"? ×××××× ×§××××× ×× ×××××§×.`))try{await D.entities.ChargeType.delete(j.id),W.success("× ×××§"),O()}catch{W.error("ש××××")}},_=async j=>{try{await D.entities.ChargeType.update(j.id,{is_active:!j.is_active}),O()}catch{W.error("ש××××")}},T=Je(f.calculation_method),M=i.useMemo(()=>
12{if(!T)return null;try{return Yu({consumption:40,souls:4,eligible:1,months:2,tariff:{water_low_rate:et(f.water_low_rate),water_high_rate:et(f.water_high_rate),water_quota_per_soul:et(f.water_quota_per_soul),water_min_souls:et(f.water_min_souls),water_eligible_addition:et(f.water_eligible_addition),includes_vat:!!f.includes_vat,vat_rate:et(f.vat_rate)}})}catch{return null}},[T,f.water_low_rate,f.water_high_rate,f.water_quota_per_soul,f.water_min_souls,f.water_eligible_addition,f.includes_vat,f.vat_rate]);if(l)return e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})});const B=({label:j,k:q,icon:L})=>e.jsxs("button",{type:"button",onClick:()=>$(q,!f[q]),className:`flex items-center gap-2 h-10 px-3 rounded-lg border text-sm transition-all ${f[q]?"border-indigo-300 bg-indigo-50 text-indigo-700":"border-slate-200 text-slate-500"}`,children:[L&&e.jsx(L,{className:"w-4 h-4"})," ",e.jsx("span",{className:"flex-1 text-right",children:j}),e.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center ${f[q]?"bg-indigo-600":"bg-slate-200"}`,children:f[q]&&e.jsx(ye,{className:"w-3 h-3 text-white"})})]});return e.jsxs("div",{children:[!c&&e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50 px-4 py-3 mb-4 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("p",{className:"text-[14.5px] font-black text-slate-800",children:["××פע×ת ×××××× ×××××××ת ×× ××× ×ת ×ש"," ",e.jsx("button",{type:"button",onClick:a,className:"text-emerald-700 underline decoration-2 decoration-emerald-300 underline-offset-4 hover:text-emerald-800 hover:decoration-emerald-500 transition-colors",children:"×× ×××× ××××××"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!o.some(j=>Je(j.calculation_method))&&e.jsxs("button",{onClick:P,className:"h-9 px-4 rounded-full bg-sky-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(Ke,{className:"w-4 h-4"})," ס×× ×××× ×××"]}),e.jsxs("button",{onClick:A,className:"h-9 px-4 rounded-full bg-indigo-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(We,{className:"w-4 h-4"})," ס×× ×××× ××ש"]})]})]}),c&&e.jsxs("div",{className:"bg-white rounded-2xl border border-indigo-200 shadow-sm p-5 mb-5 billing-form",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-base font-bold",children:h?"ער××ת ס×× ××××":"ס×× ×××× ××ש"}),e.jsx("button",{onClick:()=>m(!1),className:"w-8 h-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/60 p-4",children:[e.jsx("h4",{className:"text-[13px] font-black text-slate-800 mb-3",children:"פר×× ×¡×× ×××××"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(Q,{label:"×©× ×¡×× ×××××",required:!0,children:e.jsx("input",{className:it,value:f.name,onChange:j=>S(j.target.value),placeholder:"××¨× ×× × / ××¢× / ש××ר×â¦"})}),e.jsx(Q,{label:"×§×× / ××××",hint:f.code_touched?void 0:"× ××ª× ××ש×; ×פשר ××©× ×ת",children:e.jsx("input",{className:it,value:f.code,placeholder:"× ××ª× ××ש×",onChange:j=>x(q=>({...q,code:j.target.value.toUpperCase(),code_touched:!0}))})}),e.jsx(Q,{label:"××××ר ××××",required:!0,children:e.jsx("select",{className:it,value:f.billing_cycle,onChange:j=>$("billing_cycle",j.target.value),children:Zo.map(j=>e.jsx("option",{value:j.v,children:j.l},j.v))})}),e.jsx(yd,{communityId:t,value:f.sumit_budget_item_id,onChange:j=>$("sumit_budget_item_id",j),hint:"×סע××£ ש×××× ××××§×¤× ××××××× ×ס×× ××"}),e.jsx("div",{className:"sm:col-span-2 lg:col-span-3",children:e.jsx(Q,{label:"ת×××ר",children:e.jsx("textarea",{className:ua,rows:2,placeholder:"ת×××ר ס×× ××××× (×× ××××)",value:f.description,onChange:j=>$("description",j.target.value)})})})]})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4 mt-3",children:[e.jsx("h4",{className:"text-[13px] font-black text-slate-800 mb-3",children:"×××ר×ת ××ש××"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(Q,{label:"ש××ת ××ש××",required:!0,info:"×§××עת ×××¦× ××××©× ×ס××× ××× ×ש××",children:e.jsx("select",{className:it,value:f.calculation_method,onChange:j=>k(j.target.value),children:Da.map(j=>e.jsx("option",{value:j.v,children:j.l},j.v))})}),T?e.jsxs("div",{className:"sm:col-span-2 lg:col-span-3 rounded-xl border border-sky-200 bg-sky-50/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ke,{className:"w-4 h-4 text-sky-600"}),e.jsx("h4",{className:"text-sm font-extrabold text-slate-800",children:"תער××¤× ×××× ××× ×ס××"})]}),e.jsxs("p",{className:"text-[12px] text-slate-600 leading-relaxed mb-3",children:["×××¡× ×××רת = (× ×¤×©×ת à ×××¡× ×× ×¤×© + ××××× Ã ×ª×ספת ×××××) à ×ספר ××××©× ×××××.",e.jsx("br",{}),"×××× = MIN(צר×××, ××ס×) à ×××ר × ××× + MAX(צר××× â ××ס×, 0) à ×××ר ××××",f.includes_vat?" (××××ר×× ×××××× ××¢×´×).":", ××ת×ספת ××¢×´×."]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsx(Q,{label:"×××ר ×××´×§ â תער××£ × ××× (âª)",required:!0,info:"××××ר ×ת×× ××××¡× ××××רת",children:e.jsx("input",{type:"number",step:"0.001",className:it,value:f.water_low_rate,onChange:j=>$("water_low_rate",j.target.value),placeholder:"8.508"})}),e.jsx(Q,{label:"×××ר ×××´×§ â תער××£ ×××× (âª)",required:!0,info:"××××ר ××× ××´×§ ××¢×ר ×××ס×",children:e.jsx("input",{type:"number",step:"0.001",className:it,value:f.water_high_rate,onChange:j=>$("water_high_rate",j.target.value),placeholder:"15.623"})}),e.jsx(Q,{label:"×××¡× ×××ש×ת ×× ×¤×© (××´×§)",required:!0,children:e.jsx("input",{type:"number",step:"0.001",className:it,value:f.water_quota_per_soul,onChange:j=>$("water_quota_per_soul",j.target.value),placeholder:"3.5"})}),e.jsx(Q,{label:"××× ×××× × ×¤×©×ת ×××ש××",info:"×שק ××ת ×§×× ××תר ××××©× ××¤× ×ספר ××",children:e.jsx("input",{type:"number",step:"0.5",className:it,value:f.water_min_souls,onChange:j=>$("water_min_souls",j.target.value),placeholder:"2"})}),e.jsx(Q,{label:"ת×ספת ×××ש×ת ×× ×¤×© ××××ת (××´×§)",children:e.jsx("input",{type:"number",step:"0.001",className:it,value:f.water_eligible_addition,onChange:j=>$("water_eligible_addition",j.target.value),placeholder:"3.5"})}),e.jsx(Q,{label:"×××× ××¢×´×",info:"× ×סף ××ש××× ×¨×§ ××שר ××××ר×× ××× × ×××××× ××¢×´×",children:e.jsx("input",{type:"number",step:"0.1",className:`${it} disabled:bg-slate-50 disabled:text-slate-400`,value:f.vat_rate,onChange:j=>$("vat_rate",j.target.value),placeholder:"18",disabled:!!f.includes_vat})})]}),M&&e.jsxs("div",{className:"mt-3 rounded-lg bg-white border border-sky-200 px-3 py-2 text-[12px] text-slate-600 leading-relaxed",children:[e.jsx("span",{className:"font-bold text-slate-800",children:"××××§× ×××ר×:"})," ×שפ×× ×ת 4 × ×¤×©×ת, ×××× ×××, ×××ש×××, ",M.consumption," ××´×§ â"," ","×××¡× ",M.quota_total," ××´×§ · ",M.low_consumption," à ",M.low_rate," = ",M.low_amount.toFixed(2)," âª",M.high_consumption>0&&e.jsxs(e.Fragment,{children:[" · ",M.high_consumption," à ",M.high_rate," = ",M.high_amount.toFixed(2)," âª"]}
12)," ","· ",e.jsxs("span",{className:"font-extrabold text-slate-900",children:["ס××´× ",M.amount.toFixed(2)," âª"]})]})]}):e.jsx(e.Fragment,{children:e.jsx(Q,{label:f.calculation_method==="per_sqm"?"תער××£ ××״ר (âª)":f.calculation_method==="per_person"?"תער××£ ×× ×¤×© (âª)":f.calculation_method==="per_property"?"תער××£ ×× ×ס (âª)":"תער××£ / ס××× (âª)",required:f.calculation_method!=="custom",hint:(R=Da.find(j=>j.v===f.calculation_method))==null?void 0:R.hint,children:e.jsx("input",{type:"number",className:it,value:f.rate,onChange:j=>$("rate",j.target.value),disabled:f.calculation_method==="custom",placeholder:f.calculation_method==="custom"?"× ×§××¢ ××× ×ת":"0"})})})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2 mt-4",children:[e.jsx(B,{label:"פע××",k:"is_active",icon:ye}),e.jsx(B,{label:"×××× ××¢×´×",k:"includes_vat",icon:mr}),e.jsx(B,{label:"×××¦× ××××ר ××ש×",k:"show_in_personal_area",icon:fs}),e.jsx(B,{label:"××רש ××ש×ר",k:"requires_approval",icon:xt})]})]}),e.jsxs("p",{className:"text-[11.5px] text-slate-400 mt-3 flex items-start gap-1.5",children:[e.jsx(Be,{className:"w-3.5 h-3.5 flex-none mt-0.5"}),"×××¢× ×××¤×§× ××××¢× ××××× × ×§××¢×× ××פע×ת ס×× ×××××, ×××¡× Â«× ×××× ××××××»."]}),e.jsxs("div",{className:"flex items-center gap-3 mt-5",children:[e.jsxs("button",{onClick:C,disabled:g,className:ts,children:[e.jsx(ye,{className:"w-4 h-4"})," ",g?"ש××רâ¦":"ש××ר ס×× ××××"]}),e.jsx("button",{onClick:()=>m(!1),className:$s,children:"×××××"})]})]}),c?null:o.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-10 text-center",children:[e.jsx(Xe,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"××× ×¢×××× ×¡××× ××××××"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"×××××¨× ×¡×× ×××× ×¨×ש×× (××¨× ×× ×, ××¢×, ש××ר×, ×××â¦) ××× ××ת××× ××פ××§ ××××××."}),e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsxs("button",{onClick:P,className:"h-9 px-4 rounded-full bg-sky-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(Ke,{className:"w-4 h-4"})," ס×× ×××× ×××"]}),e.jsxs("button",{onClick:A,className:"h-9 px-4 rounded-full bg-indigo-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(We,{className:"w-4 h-4"})," ס×× ×××× ××ש"]})]})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3",children:o.map(j=>e.jsxs("div",{className:`bg-white rounded-2xl border shadow-sm p-4 ${j.is_active?"border-border":"border-slate-200 opacity-70"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-indigo-50 flex items-center justify-center flex-shrink-0",children:e.jsx(Xe,{className:"w-5 h-5 text-indigo-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-sm font-bold truncate",children:j.name}),e.jsx("p",{className:"text-xs text-slate-400",children:j.code||ei(j.billing_cycle)})]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>_(j),title:j.is_active?"×ש×ת":"×פע×",className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-400 hover:bg-slate-100",children:j.is_active?e.jsx(fs,{className:"w-4 h-4"}):e.jsx(_d,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>E(j),className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(It,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>w(j),className:"w-8 h-8 rounded-lg flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:Oa(j.calculation_method)}),Je(j.calculation_method)?e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-sky-50 text-sky-700 font-semibold",dir:"ltr",children:[Ys(j.water_low_rate)," / ",Ys(j.water_high_rate)," ×××´×§"]}):j.calculation_method!=="custom"&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-blue-50 text-blue-700 font-semibold",children:ve(j.rate)}),Je(j.calculation_method)&&j.water_quota_per_soul!=null&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:[j.water_quota_per_soul," ××´×§ ×× ×¤×© ××××ש"]}),e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:ei(j.billing_cycle)}),j.auto_billing_enabled&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-emerald-600 text-white font-bold inline-flex items-center gap-1",children:[e.jsx(Mt,{className:"w-3 h-3"})," ××¤×§× ×××××××ת"]}),j.due_day?e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-indigo-50 text-indigo-700 font-bold inline-flex items-center gap-1",children:[e.jsx(Be,{className:"w-3 h-3"})," ×תש××× ×-",j.due_day," ××××ש"]}):u&&j.billing_cycle!=="per_file"?e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-slate-100 text-slate-500 inline-flex items-center gap-1",title:"×ר×רת ××××× ×©× ××§××××",children:[e.jsx(Be,{className:"w-3 h-3"})," ×תש××× ×-",u," ××××ש"]}):null,j.includes_vat&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-amber-50 text-amber-700",children:"×××× ××¢×´×"}),j.requires_approval&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-purple-50 text-purple-700",children:"××רש ××ש×ר"}),j.online_payable&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-emerald-50 text-emerald-700 inline-flex items-center gap-0.5",children:[e.jsx(Oe,{className:"w-3 h-3"})," תש××× ××§×××"]})]}),j.description&&e.jsx("p",{className:"text-xs text-slate-500 mt-2 line-clamp-2",children:j.description})]},j.id))})]})}function pm(t,s){const n=Number(s);if(!t||!Number.isFinite(n)||n<1)return"";const[a,l]=String(t).split("-").map(Number);if(!a||!l||l<1||l>12)return"";const r=new Date(a,l,0).getDate();return`${a}-${String(l).padStart(2,"0")}-${String(Math.min(n,r)).padStart(2,"0")}`}const ot=Se,Ds=t=>ve(t),si=()=>new Date().toISOString().slice(0,7);function hm({kibbutzId:t,mode:s,onClose:n,onDone:a}){var wr;const l=s==="recurring",[r,o]=i.useState(!0),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState([]),[x,g]=i.useState([]),[y,$]=i.useState([]),[O,A]=i.useState([]),[S,P]=i.useState(0),[E,k]=i.useState(""),[C,w]=i.useState("all"),[_,T]=i.useState(""),[M,B]=i.useState(""),[R,j]=i.useState(new Set),[q,L]=i.useState(""),[N,v]=i.useState("fixed"),[F,K]=i.useState(""),[Z,H]=i.useState(si()),[z,te]=i.useState(""),[ie,V]=i.useState(!1),[Y,J]=i.useState(null),[I,X]=i.useState(""),[se,G]=i.useState(!1),[ne,ge]=i.useState(""),[ke,be]=i.useState("monthly"),[je,Ce]=i.useState(si()+"-01"),[ee,oe]=i.useState(""),[le,xe]=i.useState({}),[de,ae]=i.useState(new Set),[Ne,we]=i.useState(!1),Ue=i.useCallback(async()=>{var U;o(!0);try{const[me,fe,pe,ft,al,Ka,Tc,nl]=await Promise.all([D.entities.ChargeType.filter({kibbutz_id:t,is_active:!0},"order",300).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me}).catch(()=>[]),D.entities.Property.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ResidentGroup.filter({kibbutz_id:t},"order",300).catch(()=>[]),D.entities.ResidentGroupMember.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.BillingSettings.filter({kibbutz_id:t},"-created_date",1).catch(()=>[])]);
12u(me||[]),c((fe||[]).filter(Bc=>Bc.status!=="inactive")),h(pe||[]),f(ft||[]),g(al||[]),$(Ka||[]),A(Tc||[]);const ll=Number((U=nl==null?void 0:nl[0])==null?void 0:U.default_due_day);J(Number.isFinite(ll)&&ll>0?ll:null)}catch{W.error("ש×××× ×××¢×× ×ª × ×ª×× ××")}finally{o(!1)}},[t]);i.useEffect(()=>{Ue()},[Ue]);const re=p.find(U=>U.id===E)||null;i.useEffect(()=>{re&&(v(re.calculation_method||"fixed"),K(re.rate??""),G(!!re.requires_approval),X(U=>U||re.name),ge(U=>U||re.name),re.billing_cycle&&re.billing_cycle!=="one_time"&&be(re.billing_cycle))},[E,re]);const Qe=((re==null?void 0:re.due_day)??null)||Y;i.useEffect(()=>{ie||te(pm(l?je.slice(0,7):Z,Qe))},[Qe,Z,je,l,ie]);const Et=i.useCallback(U=>{const me=d.find(fe=>fe.id===U);return me?m.find(fe=>fe.id===me.family_id):null},[d,m]),bt=i.useCallback(U=>{const me=d.find(pe=>pe.id===U);if(!me)return 0;const fe=b.filter(pe=>pe.family_id===me.family_id&&pe.status!=="inactive").length;return fe||x.filter(pe=>pe.payer_account_id===U).reduce((pe,ft)=>pe+(Number(ft.occupancy_count)||0),0)},[d,b,x]),ue=i.useCallback(U=>x.filter(me=>me.payer_account_id===U&&me.status!=="inactive"),[x]),Ee=i.useMemo(()=>{let U=d;if(C==="group"&&_){const me=new Set(O.filter(pe=>pe.group_id===_&&pe.is_active!==!1).map(pe=>pe.resident_id)),fe=new Set(b.filter(pe=>me.has(pe.id)).map(pe=>pe.family_id));U=d.filter(pe=>fe.has(pe.family_id))}else if(C==="property_type"&&M){const me=new Set(x.filter(fe=>fe.property_type===M).map(fe=>fe.payer_account_id));U=d.filter(fe=>me.has(fe.id))}else C==="select"&&(U=d.filter(me=>R.has(me.id)));return U},[d,C,_,M,R,O,b,x]),za=i.useCallback(U=>{const me=Number(F)||0;switch(N){case"fixed":return me;case"per_sqm":return me*ue(U).reduce((fe,pe)=>fe+(Number(pe.size_sqm)||Number(pe.built_sqm)||0),0);case"per_person":return me*bt(U);case"per_property":return me*ue(U).length;case"tiered":return me*ue(U).reduce((fe,pe)=>fe+(Number(pe.size_sqm)||0),0);case"custom":return 0;default:return me}},[N,F,ue,bt]),Ps=i.useMemo(()=>Ee.map(U=>{const me=za(U.id),fe=le[U.id]!=null?Number(le[U.id]):me;return{account:U,family:Et(U.id),computed:me,amount:fe,included:!de.has(U.id)}}),[Ee,za,le,de,Et]),He=Ps.filter(U=>U.included),sl=He.reduce((U,me)=>U+(Number(me.amount)||0),0),Dc=i.useMemo(()=>[...new Set(x.map(U=>U.property_type).filter(Boolean))],[x]),Nr=[{key:"type",label:"ס×× ××××",icon:Xe},{key:"audience",label:"×§×× ××¢×",icon:De},{key:"calc",label:"××ש×× ×תער××£",icon:Ma},{key:"preview",label:"תצ××× ××§××××",icon:fs},{key:"options",label:"×פשר×××ת",icon:Ad},{key:"confirm",label:"ס×××× ×××ש×ר",icon:la}],Oc=U=>U===S?"current":U===0?E?"done":"todo":U===1?Ee.length>0?"done":U<S?"error":"todo":U<S?"done":"todo",vr=()=>S===0?!!E:S===1?Ee.length>0:S===2?N==="custom"||F!=="":S===3?He.length>0:!0,Lc=async()=>{if(He.length===0){W.error("××× ×ש×××× ×××××");return}we(!0);try{let U=null;l&&(U=(await D.entities.BillingPlan.create({kibbutz_id:t,charge_type_id:E,name:ne||(re==null?void 0:re.name),audience_type:C,audience_ref:{group_id:_||null,property_type:M||null,account_ids:C==="select"?[...R]:null},calculation_method:N,rate:Number(F)||0,billing_cycle:ke,start_date:je||null,end_date:ee||null,due_day:z?Number(z.slice(8,10)):null,status:"active"})).id);const me=se?"pending":"approved";for(const fe of He){const pe=ue(fe.account.id)[0],ft=N==="per_sqm"||N==="tiered"?ue(fe.account.id).reduce((al,Ka)=>al+(Number(Ka.size_sqm)||Number(Ka.built_sqm)||0),0):N==="per_person"?bt(fe.account.id):N==="per_property"?ue(fe.account.id).length:1;await D.entities.Charge.create({kibbutz_id:t,payer_account_id:fe.account.id,property_id:(pe==null?void 0:pe.id)||null,charge_type_id:E,billing_plan_id:U,billing_period:Z,description:I||(re==null?void 0:re.name),quantity:ft,rate:Number(F)||0,amount:Number(fe.amount)||0,status:me,due_date:z||null})}D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:l?"recurring_charges_created":"onetime_charges_created",entity_type:"charge",new_value:`${He.length} ×××××× Â· ${Ds(sl)}`}).catch(()=>{}),W.success(`× ××¦×¨× ${He.length} ××××××`),a==null||a()}catch{W.error("ש×××× ××צ×רת ×××××××"),we(!1)}};return r?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-5 billing-form",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-9 h-9 rounded-lg flex items-center justify-center ${l?"bg-blue-50":"bg-amber-50"}`,children:l?e.jsx(Mt,{className:"w-5 h-5 text-blue-600"}):e.jsx(Ns,{className:"w-5 h-5 text-amber-600"})}),e.jsx("h3",{className:"text-base font-bold",children:l?"×××× ××××©× ××ש (×××ר)":"×××× ××־פע×× ××ש"})]}),e.jsx("button",{onClick:n,className:"w-8 h-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"mb-5",children:e.jsx(jd,{steps:Nr.map((U,me)=>({...U,state:Oc(me)})),onStep:P,primaryColor:"#4f46e5",containerClassName:"grid grid-cols-3 sm:grid-cols-6 gap-2"})}),S===0&&(p.length===0?e.jsx("p",{className:"text-sm text-slate-500 text-center py-10",children:'××× ×¡××× ×××××× ×¤×¢××××. ×××××¨× ×¡×× ×××× ××ש×× ×ת âס××× ××××××" ת××××.'}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2.5",children:p.map(U=>e.jsxs("button",{onClick:()=>k(U.id),className:`text-right rounded-xl border p-3.5 transition-all ${E===U.id?"border-indigo-400 ring-2 ring-indigo-100 bg-indigo-50/40":"border-slate-200 hover:border-slate-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Xe,{className:"w-4 h-4 text-indigo-500"}),e.jsx("span",{className:"text-sm font-bold",children:U.name})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 text-[11px]",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:Oa(U.calculation_method)}),U.calculation_method!=="custom"&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-blue-50 text-blue-700",children:Ds(U.rate)})]})]},U.id))})),S===1&&e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 mb-4",children:[{v:"all",l:"×× ××ש××× ×ת"},{v:"group",l:"××¤× ×§××צ×"},{v:"property_type",l:"××¤× ×¡×× × ×ס"},{v:"select",l:"××××¨× ××× ×ת"}].map(U=>e.jsx("button",{onClick:()=>w(U.v),className:`h-10 rounded-lg border text-sm font-medium ${C===U.v?"border-indigo-400 bg-indigo-50 text-indigo-700":"border-slate-200 text-slate-600"}`,children:U.l},U.v))}),C==="group"&&e.jsxs("select",{className:ot+" mb-3",value:_,onCh
12ange:U=>T(U.target.value),children:[e.jsx("option",{value:"",children:"×××¨× ×§××צ×â¦"}),y.map(U=>e.jsx("option",{value:U.id,children:U.title},U.id))]}),C==="property_type"&&e.jsxs("select",{className:ot+" mb-3",value:M,onChange:U=>B(U.target.value),children:[e.jsx("option",{value:"",children:"×××¨× ×¡×× × ×סâ¦"}),Dc.map(U=>e.jsx("option",{value:U,children:U},U))]}),C==="select"&&e.jsxs("div",{className:"border border-slate-200 rounded-xl p-3 mb-3",children:[e.jsxs("div",{className:"relative mb-2",children:[e.jsx(qt,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{value:q,onChange:U=>L(U.target.value),placeholder:"××פ×ש ×ש×××â¦",className:"w-full h-9 rounded-lg border border-slate-200 pr-9 pl-3 text-sm"})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto space-y-1",children:d.filter(U=>!q||(U.name||"").includes(q)||(U.account_number||"").includes(q)).map(U=>{var fe;const me=R.has(U.id);return e.jsxs("button",{onClick:()=>j(pe=>{const ft=new Set(pe);return ft.has(U.id)?ft.delete(U.id):ft.add(U.id),ft}),className:`w-full flex items-center justify-between gap-2 rounded-lg border px-3 py-2 text-right ${me?"border-indigo-300 bg-indigo-50":"border-slate-200"}`,children:[e.jsxs("span",{className:"text-sm font-medium",children:[U.name||((fe=Et(U.id))==null?void 0:fe.name)||"â"," ",e.jsxs("span",{className:"text-xs text-slate-400",children:["#",U.account_number]})]}),e.jsx("span",{className:`w-5 h-5 rounded-md flex items-center justify-center ${me?"bg-indigo-600":"bg-slate-100"}`,children:me&&e.jsx(ye,{className:"w-3.5 h-3.5 text-white"})})]},U.id)})})]}),e.jsxs("div",{className:"text-sm bg-slate-50 rounded-lg px-4 py-3 flex items-center gap-2",children:[e.jsx(De,{className:"w-4 h-4 text-indigo-500"})," × ×××¨× ",e.jsx("b",{children:Ee.length})," ×ש××× ×ת ×ש×××× ×××××."]})]}),S===2&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:[e.jsx(Q,{label:"ש××ת ××ש××",required:!0,info:"×§××עת ×××¦× ××××©× ×ס××× ××× ×ש××",children:e.jsx("select",{className:ot,value:N,onChange:U=>v(U.target.value),children:Da.map(U=>e.jsx("option",{value:U.v,children:U.l},U.v))})}),e.jsx(Q,{label:N==="custom"?"תער××£ (××× × ××× ×©×ר×)":"תער××£ / ס××× (âª)",required:N!=="custom",children:e.jsx("input",{type:"number",className:ot,placeholder:"0",value:F,onChange:U=>K(U.target.value),disabled:N==="custom"})}),e.jsx(Q,{label:"תק×פת ××××",required:!0,children:e.jsx("input",{type:"month",className:ot,value:Z,onChange:U=>H(U.target.value)})}),l&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:"×©× ×ת××× ×ת",children:e.jsx("input",{className:ot,value:ne,onChange:U=>ge(U.target.value)})}),e.jsx(Q,{label:"××××ר",children:e.jsxs("select",{className:ot,value:ke,onChange:U=>be(U.target.value),children:[e.jsx("option",{value:"monthly",children:"×××ש×"}),e.jsx("option",{value:"bimonthly",children:"××-×××ש×"}),e.jsx("option",{value:"quarterly",children:"ר××¢×× ×"}),e.jsx("option",{value:"yearly",children:"×©× ×ª×"})]})}),e.jsx(Q,{label:"ת×××ת ×ת××× ×ת",children:e.jsx("input",{type:"date",className:ot,value:je,onChange:U=>Ce(U.target.value)})})]}),e.jsxs("div",{className:"sm:col-span-2 lg:col-span-3 text-sm bg-indigo-50/60 rounded-lg px-4 py-3 text-slate-600",children:[(wr=Da.find(U=>U.v===N))==null?void 0:wr.hint,". ×ס××××× ×××ש×× ×××××××ת ××× ×ש×× ×× ××ª× ×ער×× ×× ×©××¨× ×ש×× ×××."]})]}),S===3&&e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-2 text-sm",children:e.jsxs("span",{className:"text-slate-500",children:[He.length," ×ת×× ",Ps.length," ×ש××× ×ת · ס××´× ",e.jsx("b",{className:"text-slate-800",children:Ds(sl)})]})}),e.jsx("div",{className:"border border-slate-200 rounded-xl overflow-hidden max-h-[50vh] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"××××"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"×ש×××"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"×××ש×"}),e.jsx("th",{className:"text-right px-3 py-2 font-medium",children:"ס××× ××××× (âª)"})]})}),e.jsx("tbody",{children:Ps.map(U=>{var me;return e.jsxs("tr",{className:`border-t border-slate-100 ${U.included?"":"opacity-40"}`,children:[e.jsx("td",{className:"px-3 py-1.5",children:e.jsx("button",{onClick:()=>ae(fe=>{const pe=new Set(fe);return pe.has(U.account.id)?pe.delete(U.account.id):pe.add(U.account.id),pe}),className:`w-5 h-5 rounded-md flex items-center justify-center ${U.included?"bg-indigo-600":"bg-slate-200"}`,children:U.included&&e.jsx(ye,{className:"w-3.5 h-3.5 text-white"})})}),e.jsxs("td",{className:"px-3 py-1.5",children:[e.jsx("span",{className:"font-medium",children:U.account.name||((me=U.family)==null?void 0:me.name)||"â"})," ",e.jsxs("span",{className:"text-xs text-slate-400",children:["#",U.account.account_number]})]}),e.jsx("td",{className:"px-3 py-1.5 text-slate-400",children:Ds(U.computed)}),e.jsx("td",{className:"px-3 py-1.5",children:e.jsx("input",{type:"number",value:U.amount,onChange:fe=>xe(pe=>({...pe,[U.account.id]:fe.target.value})),className:"w-28 h-8 rounded-lg border border-slate-200 px-2 text-sm"})})]},U.account.id)})})]})})]}),S===4&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx("div",{className:"sm:col-span-2",children:e.jsx(Q,{label:"ת×××ר ××××× (××פ××¢ ××ש×××)",children:e.jsx("input",{className:ot,value:I,onChange:U=>X(U.target.value)})})}),e.jsx(Q,{label:"ת×ר×× ×תש×××",hint:ie||!Qe?void 0:`××¤× ${re!=null&&re.due_day?`××× ××××× ×©× ${re.
12name}`:"×ר×רת ××××× ×©× ××§××××"} â ×-${Qe} ××××ש`,children:e.jsx("input",{type:"date",className:ot,value:z,onChange:U=>{V(!0),te(U.target.value)}})}),l&&e.jsx(Q,{label:"ס××× ×ת××× ×ת (×× ××××)",children:e.jsx("input",{type:"date",className:ot,value:ee,onChange:U=>oe(U.target.value)})}),e.jsxs("button",{type:"button",onClick:()=>G(U=>!U),className:`flex items-center gap-2 h-10 px-3 rounded-lg border text-sm ${se?"border-purple-300 bg-purple-50 text-purple-700":"border-slate-200 text-slate-500"}`,children:[e.jsx("span",{className:"flex-1 text-right",children:"××××××× ×××¨×©× ××ש×ר ××¤× × ×פק×"}),e.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center ${se?"bg-purple-600":"bg-slate-200"}`,children:se&&e.jsx(ye,{className:"w-3 h-3 text-white"})})]})]}),S===5&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2",children:[{l:"ס×× ××××",v:(re==null?void 0:re.name)||"â",icon:Xe},{l:"×ש××××",v:He.length,icon:De},{l:"ס××´× ×××××",v:Ds(sl),icon:Ma},{l:"תק×פ×",v:Z,icon:ra}].map(U=>{const me=U.icon;return e.jsxs("div",{className:"bg-slate-50 rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-slate-400 mb-1",children:[e.jsx(me,{className:"w-3.5 h-3.5"}),U.l]}),e.jsx("p",{className:"text-sm font-bold text-slate-800",children:U.v})]},U.l)})}),e.jsxs("div",{className:"text-sm bg-white border border-slate-200 rounded-xl p-4 space-y-1 text-slate-600",children:[e.jsxs("p",{children:["⢠ש××ת ××ש××: ",e.jsx("b",{children:Oa(N)}),N!=="custom"&&e.jsxs(e.Fragment,{children:[" · תער××£ ",Ds(F)]})]}),e.jsxs("p",{children:["⢠ת×××ר: ",e.jsx("b",{children:I||(re==null?void 0:re.name)}),z&&e.jsxs(e.Fragment,{children:[" · ×תש××× ×¢× ",z]})]}),l&&e.jsxs("p",{children:["⢠ת××× ×ת ×××רת: ",e.jsx("b",{children:ne})," · ××××ר ",ke==="monthly"?"×××ש×":ke," · ת×××צר ×× ×¨×©××ת ת××× ×ת."]}),e.jsxs("p",{children:["⢠ס×××ס ×עת ×צ×ר×: ",e.jsx("b",{children:se?"××ת×× ×××ש×ר":"×××שר ××פק×"}),"."]})]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-5 pt-4 border-t border-slate-100",children:[e.jsxs("button",{onClick:()=>S===0?n():P(S-1),className:"h-10 px-4 rounded-full border border-slate-200 text-sm inline-flex items-center gap-1",children:[e.jsx(oa,{className:"w-4 h-4"})," ",S===0?"×××××":"××§×××"]}),S<Nr.length-1?e.jsxs("button",{onClick:()=>vr()?P(S+1):W.error("×ש ××ש××× ×©×× ××"),disabled:!vr(),className:"h-10 px-6 rounded-full bg-indigo-600 text-white text-sm font-bold inline-flex items-center gap-1 disabled:opacity-40",children:["××× ",e.jsx(lt,{className:"w-4 h-4"})]}):e.jsxs("button",{onClick:Lc,disabled:Ne||He.length===0,className:"h-10 px-6 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center gap-1.5 disabled:opacity-40",children:[e.jsx(ye,{className:"w-4 h-4"})," ",Ne?"××צרâ¦":`צ×ר ${He.length} ××××××`]})]})]})}function _r({title:t,icon:s,steps:n,step:a,onStep:l,onClose:r,onSubmit:o,submitLabel:p="××ש×ר ×ש××ר×",submitting:u,children:d,width:c="max-w-2xl"}){const m=a===n.length-1;return e.jsx("div",{className:"fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:r,dir:"rtl",children:e.jsxs("div",{className:`billing-form bg-white rounded-2xl shadow-2xl w-full ${c} flex flex-col h-[min(42rem,92vh)]`,onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 pt-5 pb-3 flex-none",children:[e.jsxs("h3",{className:"text-[22px] font-black text-slate-900 flex items-center gap-2",children:[s?e.jsx(s,{className:"w-6 h-6 text-teal-600"}):null,t]}),e.jsx("button",{onClick:r,"aria-label":"ס××ר×",className:"w-9 h-9 rounded-full border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50 flex-none",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("ol",{className:"flex items-center gap-1.5 px-6 pb-3 flex-none","aria-label":"ש××××",children:n.map((h,b)=>{const f=b<a,x=b===a;return e.jsxs("li",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsxs("button",{type:"button",disabled:b>a,onClick:()=>l(b),"aria-current":x?"step":void 0,className:`h-8 px-3 rounded-full text-[12.5px] font-bold inline-flex items-center gap-1.5 transition-colors whitespace-nowrap ${x?"bg-teal-600 text-white":f?"bg-teal-50 text-teal-700 hover:bg-teal-100":"bg-slate-100 text-slate-400 cursor-default"}`,children:[e.jsx("span",{className:`w-4 h-4 rounded-full grid place-items-center text-[10px] flex-none ${x?"bg-white/25":f?"bg-teal-600 text-white":"bg-white text-slate-400"}`,children:f?e.jsx(ye,{className:"w-2.5 h-2.5"}):b+1}),h]}),b<n.length-1&&e.jsx("span",{className:"w-4 h-px bg-slate-200 flex-none"})]},h)})}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 pb-2",children:d}),e.jsxs("div",{className:"flex items-center gap-2 px-6 py-4 border-t border-slate-100 flex-none",children:[a>0&&e.jsxs("button",{type:"button",onClick:()=>
12l(a-1),className:"h-11 px-4 rounded-xl border border-slate-200 text-slate-600 text-sm font-bold inline-flex items-center gap-1.5 hover:bg-slate-50",children:[e.jsx(oa,{className:"w-4 h-4"})," ×××ר"]}),e.jsxs("button",{type:"button",onClick:()=>m?o():l(a+1),disabled:u,className:"h-11 px-6 rounded-xl bg-teal-600 hover:bg-teal-700 text-white text-sm font-bold inline-flex items-center gap-1.5 transition-colors disabled:opacity-60 mr-auto",children:[u?"ש××רâ¦":m?p:"××ש×",!m&&!u&&e.jsx(lt,{className:"w-4 h-4"})]}),e.jsx("button",{type:"button",onClick:r,className:"h-11 px-4 rounded-xl text-slate-500 text-sm font-bold hover:bg-slate-50",children:"×××××"})]})]})})}function Qo({value:t,onChange:s,options:n,disabled:a,note:l}){return e.jsxs("div",{className:"space-y-2",children:[n.map(r=>{const o=!!t[r.v];return e.jsxs("button",{type:"button",disabled:a,onClick:()=>s(r.v,!o),className:`w-full rounded-xl border p-3 text-right transition-colors flex items-center gap-3 ${a?"opacity-50 cursor-not-allowed border-slate-200":o?"border-teal-400 bg-teal-50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsx("span",{className:`w-10 h-5 rounded-full relative transition-colors flex-none ${o?"bg-teal-500":"bg-slate-300"}`,children:e.jsx("span",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white transition-all ${o?"right-0.5":"right-5.5"}`})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800",children:r.l}),e.jsx("span",{className:"block text-[11.5px] text-slate-400",children:r.hint})]})]},r.v)}),l&&e.jsx("p",{className:"text-[12px] text-amber-700 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2",children:l})]})}const bm=[{v:"all",l:"×× ××ש××× ×ת",hint:"×× ×ש××× ×ש×× ×¤×¢×× ××§××××"},{v:"with_budget",l:"רק ×ש××× ×ת ×¢× ×ספר תקצ××",hint:"×שפ××ת ש×ש ××× ×ספר תקצ×× ××××××"},{v:"with_account",l:"רק ×ש××× ×ת ×¢× ×ספר ×ש×××",hint:"×ש××× ×ת שק×××× ×ספר ×ש××× ××ער×ת"},{v:"selected",l:"רק ×ש××× ×ת ×ס××× ××",hint:"רש××× ×©× ××רת ××× ×ת"}],va=t=>Math.round((Number(t)+Number.EPSILON)*100)/100;function fm(t,s,{residents:n=[],properties:a=[]}={}){var u,d,c,m;const l=Number(t==null?void 0:t.rate)||0,r=(a||[]).filter(h=>h.payer_account_id===s.id&&h.status!=="inactive"),o=r.reduce((h,b)=>h+(Number(b.size_sqm)||Number(b.built_sqm)||0),0),p=(n||[]).filter(b=>b.family_id===s.family_id&&b.status!=="inactive").length||r.reduce((b,f)=>b+(Number(f.occupancy_count)||0),0);switch(t==null?void 0:t.calculation_method){case"per_sqm":case"tiered":return{amount:va(l*o),quantity:o,property_id:((u=r[0])==null?void 0:u.id)||null};case"per_person":return{amount:va(l*p),quantity:p,property_id:((d=r[0])==null?void 0:d.id)||null};case"per_property":return{amount:va(l*r.length),quantity:r.length,property_id:((c=r[0])==null?void 0:c.id)||null};case"fixed":default:return{amount:va(l),quantity:1,property_id:((m=r[0])==null?void 0:m.id)||null}}}const Xt=t=>(t==null?void 0:t.calculation_method)==="water_meter"||(t==null?void 0:t.billing_cycle)==="per_file",Kl=[{v:"manual",l:"×פע×× ×××××",hint:"×××©×¨× ×פע×× ×ת ×××¤×§× ××× ×¤×¢× ×××ש. ××× ×©×¢××."},{v:"auto",l:"×פע×× ×××××××ת",hint:"××ער×ת ×פ××§× ××¤× ××××ר×ת, ××× ××××ר, ×¢× ×©××ש××."}],Wl=[{v:"demand",l:"×ר×שת תש×××",hint:"×ס×× ×©××שפ×× ×ת×קשת ×ש×× ×פ××"},{v:"charge",l:"×ס×× ×××× ×תש×××",hint:"××××× × ×××, ×××פקת ×ש××× ×ת ××§×××"}],Ul=[{v:"now",l:"××××",hint:"×××¤×§× × ×¢×©×ת ×¢× ×ש××ר×"},{v:"scheduled",l:"ת×××",hint:"×××¤×§× ××¤× ××××¢××× ×©×××§××¢×"}],cl=[{v:"auto",l:"×××××× ××××××××",hint:"רצ×× ××¤× ××××ר×ת ×¢× ×©××ש××"},{v:"manual",l:"×××××× ××××××",hint:"××פע××× ×××, ש×× ×ש××"},{v:"file",l:"×××××× ××§×××¥",hint:"× ×צר×× ×××¢×× ×ª ×§×××¥"},{v:"paused",l:"×××××× ××ש×××",hint:"×××××¨× ×××¨× ××פע××"}],dl=(t,s)=>{var n;return((n=t.find(a=>a.v===s))==null?void 0:n.l)||""};function gm(t){return Xt(t)?"file":ze(t)||"paused"}const ze=t=>(t==null?void 0:t.activation_mode)==="auto"||(t==null?void 0:t.activation_mode)==="manual"?t.activation_mode:t!=null&&t.auto_billing_enabled?"auto":null;function ym(t,s=null){return Xt(t)?ze(t)?!!t.activated_batch_id&&
12(!s||t.activated_batch_id===s):!1:!0}function _m(t,{done:s=!1}={}){const n=ze(t);return Xt(t)?n?s?"×סת×××":"פע××":"××ש××":n?n==="manual"?(t==null?void 0:t.issue_timing)==="scheduled"?"×ת××××":"××××":"×××××××":"××ש××"}const jm={×××××××:"bg-emerald-50 text-emerald-700 border-emerald-200",××××:"bg-indigo-50 text-indigo-700 border-indigo-200",×ת××××:"bg-indigo-50 text-indigo-700 border-indigo-200",פע××:"bg-sky-50 text-sky-700 border-sky-200","×ר×שת תש×××":"bg-sky-50 text-sky-700 border-sky-200","×××× ××ס×× ×ª×©×××":"bg-teal-50 text-teal-700 border-teal-200","×ת××ש ×××××××":"bg-emerald-50 text-emerald-700 border-emerald-200","×ת××ש ××× ×":"bg-indigo-50 text-indigo-700 border-indigo-200",×סת×××:"bg-slate-100 text-slate-500 border-slate-200",××ש××:"bg-amber-50 text-amber-700 border-amber-200"},Nm=[{v:"active",l:"פע××"},{v:"demand",l:"×ר×שת תש×××"},{v:"charge",l:"×××× ××ס×× ×ª×©×××"},{v:"done",l:"×סת×××"}],vm={file:"×סת×××",auto:"×ת××ש ×××××××",manual:"×ת××ש ××× ×"},wm=(t=new Date)=>typeof t=="string"?t.slice(0,10):`${t.getFullYear()}-${Mn(t.getMonth()+1)}-${Mn(t.getDate())}`;function ai({activated:t=!1,billed:s=!1,demandDate:n=null,chargeDate:a=null,lastDueDate:l=null,kind:r="file",approvals:o=null,needsApproval:p=!1,now:u=new Date}={}){const d=wm(u),c=ut(a)||ut(l),m=[!!t,!!t&&!!s,!1,!1];m[2]=m[1]&&!!c&&c<=d,m[3]=r==="file"?m[2]&&!!ut(l)&&ut(l)<d:m[2];const h=[null,ut(n),ut(a),r==="file"?ut(l):null],b=m.lastIndexOf(!0),f=o||{},x=[null,f.demand||null,f.charge||null,null];return Nm.map((g,y)=>({...g,l:y===3&&vm[r]||g.l,done:m[y],at:y===b,date:h[y],approved:x[y],awaiting:!!x[y]&&!m[y],blocked:!!p&&!m[y]&&!x[y]&&(y===1||y===2)}))}const km=(t=[])=>{var s;return((s=t.find(n=>n.at))==null?void 0:s.l)||"××ש××"};function Sm(t){return t?Xt(t)?"×××× ×××× ××©×ª× ×":t.billing_cycle==="one_time"?"×××× ××־פע××":ze(t)==="auto"?"×××× ×ת××ש ×××××××":ze(t)==="manual"?"×××× ××××":"××¨× ××פע×":""}const Hl=t=>{const s=Number(t);return Number.isFinite(s)&&s>=1&&s<=31?Math.round(s):null},ut=t=>/^\d{4}-\d{2}-\d{2}$/.test(String(t||"").slice(0,10))?String(t).slice(0,10):null,An=t=>ut(t)?Number(String(t).slice(8,10)):null,Mn=t=>String(t).padStart(2,"0"),ni=t=>`${t.getFullYear()}-${Mn(t.getMonth()+1)}-${Mn(t.getDate())}`;function li(t,s=new Date){const n=Hl(t);if(!n)return"";const a=s.getFullYear(),l=s.getMonth(),r=new Date(a,l+1,0).getDate(),o=Math.min(n,r);if(o>=s.getDate())return ni(new Date(a,l,o));const p=new Date(a,l+2,0).getDate();return ni(new Date(a,l+1,Math.min(n,p)))}const xn=t=>{const[s,n,a]=String(t||"").slice(0,10).split("-");return a?`${a}/${n}/${s}`:""};function Pn(t={},{file:s=!1}={}){const n=Kl.some(u=>u.v===t.mode)?t.mode:"manual",a=Ul.some(u=>u.v===t.timing)?t.timing:"now",l=a==="scheduled",r=Wl.some(u=>u.v===t.document_kind)?t.document_kind:"demand",o=r==="demand"?ut(t.demand_issue_date):null,p=ut(t.charge_issue_date);return{activation_mode:n,document_kind:r,issue_timing:a,demand_issue_date:o,charge_issue_date:p,last_due_date:s?ut(t.last_due_date):null,demand_issue_day:s?null:An(o)??Hl(t.demand_issue_day),charge_issue_day:s?null:An(p)??Hl(t.charge_issue_day),requires_manager_approval:n==="manual"&&l?!!t.requires_manager_approval:!1}}function ri(t={},{file:s=!1}={}){const n=Pn(t,{file:s});if(n.document_kind==="demand"&&!n.demand_issue_date)return"×ש ××××ר ת×ר×× ××פקת ×ר×שת ×תש×××";if(!n.charge_issue_date)return"×ש ××××ר ×××¢× ××××× ×××פקת ×ס×× ×תש×××";if(n.demand_issue_date&&n.demand_issue_date>n.charge_issue_date)return"×ר×שת ×תש××× ××× × ××××× ×צ×ת ×××¨× ×××¢× ×××××";if(s){if(!n.last_due_date)return"×ש ××××ר ת×ר×× ××ר×× ×תש×××";if(n.charge_issue_date>n.last_due_date)return"×ת×ר×× ×××ר×× ×תש××× ××× × ×××× ×××§××× ×ת ×××¢× ×××××"}return t.audience==="selected"&&!(t.account_ids||[]).length?"×ש ××××ר ×פ××ת ×ש××× ×××":null}function Jo(t={}){const s=t.demand_issue_day??An(t.demand_issue_date),n=t.charge_issue_day??An(t.charge_issue_date);return n?t.document_kind==="demand"&&s?`×ר××©× ×-${s} ××××ש, ×××× ×-${n} ××××ש`:`×××× ×-${n} ××××ש`:""}function ec(t={},{file:s=!1,typeName:n="",accounts:a=null,total:l=null,now:r=new Date,pending:o=!1}={}){const p=Pn(t,{file:s}),u=n?` ×¢××ר ××××× ${n}`:"",d=[],c=p.demand_issue_date||li(p.demand_issue_day,r),m=p.charge_issue_date||li(p.charge_issue_day,r),h=o&&p.issue_timing==="now"?", ×¢× ×ש××ר×":"";p.document_kind==="demand"&&d.push(c?`×ר×שת ×תש××× ×ª×פק ×ת×ר×× ${xn(c)}${h}${u}.`:`×ר×שת ×תש××× ×ª×פק ××××¢× ×©××××ר${u}.`),d.push(m?`××××× ××פקת ×ס×× ×תש××× ×ת××¦×¢× ×ת×ר×× ${xn(m)}.`:"××××× ××פקת ×ס×× ×תש××× ×ת××¦×¢× ××××¢× ×©××××ר."),s&&p.last_due_date&&d.push(`ת×ר×× ××ר×× ×תש×××: ${xn(p.last_due_date)}.`);const b=s?"":Jo(p);if(d.push(p.activation_mode==="auto"?`×פע×× ×××××××ת â ${b?`×××× ××××ר: ${b}`:"××× ××××ר"}, ×¢× ×©×××¤×§× ×ª×ש××.`:`×פע×× ××××× â ××פע×ת ×××, ש×× ×ש××.${p.requires_manager_approval?" ×××¤×§× ×ª×ת×× ×××ש×ר ×× ××.":""}
12`),a!==null){const f=l===null?"":` · ${Number(l).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2})} âª`;d.push(`×¢××ר ${_e(a,"×ש××× ×ש×× ×××","×ש××× ×ת ×ש××××")}${f}.`)}return d}const ii=t=>ve(t),ul=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),$m={manual:Ns,auto:Mt},Cm={demand:nt,charge:fo};function Va({options:t,value:s,onChange:n,icons:a={},columns:l=2}){return e.jsx("div",{className:`grid gap-2 ${l===2?"sm:grid-cols-2":""}`,children:t.map(r=>{const o=s===r.v,p=a[r.v];return e.jsxs("button",{type:"button",onClick:()=>n(r.v),"aria-pressed":o,className:`text-right rounded-2xl border-2 p-3.5 transition-colors flex items-start gap-3 ${o?"border-teal-500 bg-teal-50/60":"border-slate-200 bg-white hover:border-slate-300"}`,children:[p&&e.jsx("span",{className:`w-10 h-10 rounded-xl grid place-items-center flex-none ${o?"bg-teal-600 text-white":"bg-slate-50 text-slate-400 border border-slate-200"}`,children:e.jsx(p,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[14px] font-black text-slate-900",children:r.l}),r.hint&&e.jsx("span",{className:"block text-[11.5px] text-slate-500 leading-snug mt-0.5",children:r.hint})]}),e.jsx("span",{className:`w-[18px] h-[18px] rounded-full border-2 grid place-items-center flex-none mt-0.5 ${o?"border-teal-600 bg-teal-600":"border-slate-300"}`,children:o&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-white"})})]},r.v)})})}function ml({label:t,value:s,onChange:n,hint:a}){return e.jsxs("label",{className:"block min-w-0",children:[e.jsx("span",{className:"block text-[11.5px] font-bold text-slate-500 mb-1",children:t}),e.jsx("input",{type:"date",value:s||"",onChange:l=>n(l.target.value||null),className:"w-full h-11 rounded-xl border border-slate-200 px-3 text-sm font-bold focus:outline-none focus:border-teal-400"}),a&&e.jsx("span",{className:"block text-[11px] text-slate-400 mt-1",children:a})]})}const Am=()=>{const t=new Date,s=n=>String(n).padStart(2,"0");return`${t.getFullYear()}-${s(t.getMonth()+1)}-${s(t.getDate())}`};function Mm({type:t,accounts:s=[],residents:n=[],properties:a=[],busy:l=!1,onSave:r,onClose:o}){const p=Xt(t),[u,d]=i.useState(0),[c,m]=i.useState(()=>({mode:ze(t)||"manual",document_kind:t.document_kind||"demand",timing:t.issue_timing||(ze(t)==="auto"?"scheduled":"now"),demand_issue_date:t.demand_issue_date||t.next_issue||null,charge_issue_date:t.charge_issue_date||t.next_due||null,last_due_date:t.last_due_date||t._batchDue||null,requires_manager_approval:!!t.requires_manager_approval,audience:t.audience||t.auto_audience||"all",account_ids:t.account_ids||t.auto_account_ids||[]})),h=(j,q)=>m(L=>({...L,[j]:q})),b=i.useRef({});i.useEffect(()=>{const j=Am(),q=["demand_issue_date","charge_issue_date",...p?["last_due_date"]:[]];m(L=>{const N={...L};return q.forEach(v=>{c.timing==="now"?L[v]||(N[v]=j,b.current[v]=j):L[v]&&L[v]===b.current[v]&&(N[v]=null,b.current[v]=null)}),N})},[c.timing,p]);const[f,x]=i.useState(""),g=i.useMemo(()=>new Set(c.account_ids||[]),[c.account_ids]),y=j=>j!=null&&String(j).trim()!=="",$=i.useMemo(()=>s.filter(j=>j.status!=="inactive"),[s]),O=i.useMemo(()=>{switch(c.audience){case"with_budget":return $.filter(j=>y(j.budget_number)||y(j.budget));case"with_account":return $.filter(j=>y(j.account_number));case"selected":return $.filter(j=>g.has(j.id));default:return $}},[c.audience,$,g]),A=i.useMemo(()=>{const j=O.map(q=>fm(t,q,{residents:n,properties:a}).amount).filter(q=>q>0);return{accounts:j.length,total:va(j.reduce((q,L)=>q+L,0))}},[O,t,n,a]),S=i.useMemo(()=>{const j=f.trim();return j?$.filter(q=>[q.name,q.account_number,q.budget_number,q.budget].filter(Boolean).join(" ").includes(j)):$},[$,f]),P=j=>m(q=>{const L=new Set(q.account_ids||[]);return L.has(j)?L.delete(j):L.add(j),{...q,account_ids:[...L]}}),E=t._batch||null,k={accounts:Number((E==null?void 0:E.bill_count)||(E==null?void 0:E.row_count))||0,total:Number(E==null?void 0:E.total_amount)||0},C=c.timing==="scheduled",w=ri(c,{file:p}),_=ri({...c,audience:"all"},{file:p}),T=Jo(Pn(c,{file:p})),M=!!ze(t),B=ec(c,{file:p,pending:!0,typeName:t.name,accounts:p?k.accounts:u>=2?A.accounts:null,total:p?k.total:u>=2?A.total:null}),R=()=>{w||l||r({...Pn(c,{file:p}),audience:c.audience,account_ids:c.audience==="selected"?[...g]:null})};return Pt.createPortal(e.jsxs(_r,{title:`× ×××× ×××××× â ${t.name}`,icon:Be,steps:[u>0?dl(Kl,c.mode):"×××¤× ××פע××",u>1?`${dl(Wl,c.document_kind)} · ${dl(Ul,c.timing)}`:"××ס×× ×××××¢×",...p?[]:["×ש××× ×ת ×××××"]],step:u,onStep:d,onClose:o,onSubmit:R,submitLabel:l?"ש××רâ¦":M?"ש××רת ×ש×× ××××":"ש×××¨× ××פע××",submitting:l,width:"max-w-2xl",children:[u===0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(Va,{options:Kl,value:c.mode,onCh
12ange:j=>h("mode",j),icons:$m,columns:1}),e.jsx("p",{className:"text-[12px] text-slate-500 leading-relaxed bg-slate-50 border border-slate-200 rounded-xl px-3 py-2",children:c.mode==="manual"?"×××× ×××× × ×©×ר ×××××× ×©× ××שר×: ××× ××פק ××× ×¤×¢× ×©×פע×××× ××ת×, ××פשר ××פע×× ×××ª× ×©×× ×ש××.":"×××× ××××××× ×¨×¥ ×עצ×× ××¤× ××××ר×ת, ××× ××××ר, ×¢× ×©××ש×× ×ש×× ××ת×."})]}),u===1&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("section",{children:[e.jsx("h4",{className:"text-[13px] font-black text-slate-800 mb-2",children:"××ס×× ×©××פק"}),e.jsx(Va,{options:Wl,value:c.document_kind,onChange:j=>h("document_kind",j),icons:Cm})]}),e.jsxs("section",{children:[e.jsx("h4",{className:"text-[13px] font-black text-slate-800 mb-2",children:"×××¢× ××פק×"}),e.jsx(Va,{options:Ul,value:c.timing,onChange:j=>h("timing",j)})]}),e.jsxs("section",{className:"rounded-2xl border border-slate-200 bg-slate-50/60 p-3.5",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[c.document_kind==="demand"&&e.jsx(ml,{label:"×פקת ×ר×שת תש×××",value:c.demand_issue_date,onChange:j=>h("demand_issue_date",j),hint:C?"××¤× × ×××¢× ×××××":"××ס×× ××פק ×¢× ×ש××ר×"}),e.jsx(ml,{label:"×××¢× ××××× ××פקת ×ס×× ×תש×××",value:c.charge_issue_date,onChange:j=>h("charge_issue_date",j),hint:"×××× ×©×× ××××× × ×××"}),p&&e.jsx(ml,{label:"ת×ר×× ××ר×× ×תש×××",value:c.last_due_date,onChange:j=>h("last_due_date",j),hint:"×ת×ר×× ×©×××פס ××שפ××"})]}),c.mode==="auto"&&T&&e.jsxs("p",{className:"text-[12px] text-slate-500 mt-2.5 flex items-start gap-1.5",children:[e.jsx(Mt,{className:"w-3.5 h-3.5 flex-none mt-0.5 text-slate-400"}),"××× ×××¢×× ×××××ר ×ר×ש××. ××× ××××ר ש××ר××: ",T,"."]})]}),C&&c.mode==="manual"&&e.jsxs("section",{className:"rounded-2xl border border-slate-200 bg-slate-50/60 p-3.5",children:[e.jsxs("h4",{className:"text-[13px] font-black text-slate-800 mb-2 flex items-center gap-1.5",children:[e.jsx(xt,{className:"w-4 h-4 text-slate-400"})," ××רש ××ש×ר ×× ××"]}),e.jsx(Va,{options:[{v:"yes",l:"××",hint:"××× ××ש×ר ×× ×× ××ס×× ×× ××פק ××××¢× ×©× ×§××¢"},{v:"no",l:"××",hint:"×××¤×§× ×ª××¢×©× ××××¢× ××× ××ש×ר × ×סף"}],value:c.requires_manager_approval?"yes":"no",onChange:j=>h("requires_manager_approval",j==="yes")})]}),p&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Ga,{label:"×ש××× ×ת ×××××",value:ul(k.accounts)}),e.jsx(Ga,{label:"ס××× ×××××",value:ii(k.total),strong:!0})]}),e.jsx(oi,{lines:B}),_&&e.jsx("p",{className:"text-[12.5px] font-bold text-rose-600",children:_})]}),u===2&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"space-y-2",children:bm.map(j=>{const q=c.audience===j.v,L=j.v==="all"?$.length:j.v==="with_budget"?$.filter(N=>y(N.budget_number)||y(N.budget)).length:j.v==="with_account"?$.filter(N=>y(N.account_number)).length:g.size;return e.jsxs("button",{type:"button",onClick:()=>h("audience",j.v),className:`w-full text-right flex items-center gap-3 p-3 rounded-xl border-2 transition-colors ${q?"border-teal-500 bg-teal-50/50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsx("span",{className:`w-5 h-5 rounded-full border-2 grid place-items-center flex-none ${q?"border-teal-600":"border-slate-300"}`,children:q&&e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-teal-600"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[14px] font-bold text-slate-800",children:j.l}),e.jsx("span",{className:"block text-[12px] text-slate-400 mt-0.5",children:j.hint})]}),e.jsx("span",{className:"text-[13px] font-black text-slate-500 tabular-nums flex-none",children:ul(L)})]},j.v)})}),c.audience==="selected"&&e.jsxs("div",{className:"rounded-xl border border-slate-200 overflow-hidden",children:[e.jsxs("div",{className:"relative border-b border-slate-100",children:[e.jsx(qt,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"}),e.jsx("input",{value:f,onChange:j=>x(j.target.value),placeholder:"××פ×ש ××¤× ×©×, ×ספר ×ש××× ×× ×ª×§×¦××",className:"w-full h-11 pr-9 px-3 text-sm focus:outline-none"})]}),e.jsxs("div",{className:"max-h-44 overflow-y-auto",children:[S.map(j=>{const q=g.has(j.id);return e.jsxs("button",{type:"button",onClick:()=>P(j.id),className:"w-full flex items-center gap-2.5 px-3 py-2 text-right hover:bg-slate-50 border-b border-slate-50 last:border-0",children:[e.jsx("span",{className:`w-[18px] h-[18px] rounded-md border grid place-items-center flex-none ${q?"bg-teal-600 border-teal-600 text-white":"border-slate-300"}`,children:q&&e.jsx(ye,{className:"w-3 h-3"})}),e.jsx("span",{className:"flex-1 min-w-0 text-[13.5px] font-bold text-slate-700 truncate",children:j.name||`×ש××× #${j.account_number}`}),e.jsx("span",{className:"text-[12px] text-slate-400 flex-none",children:[j.account_number&&`#${j.account_number}`,(j.budget_number||j.budget)&&`תקצ×× ${j.budget_number||j.budget}
12`].filter(Boolean).join(" · ")})]},j.id)}),S.length===0&&e.jsx("p",{className:"text-sm text-slate-400 text-center py-6",children:"××× ×ª×צ××ת"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Ga,{label:"×ש××× ×ת ×××××",value:ul(A.accounts)}),e.jsx(Ga,{label:"×¦×¤× ××× ×¡×ת",value:ii(A.total),strong:!0})]}),e.jsx(oi,{lines:B}),w&&e.jsxs("p",{className:"text-[12.5px] font-bold text-rose-600 flex items-center gap-1.5",children:[e.jsx(Ie,{className:"w-3.5 h-3.5 opacity-0"})," ",w]})]})]}),document.body)}function Ga({label:t,value:s,strong:n}){return e.jsxs("div",{className:"rounded-xl border border-slate-200 p-3 text-center",children:[e.jsx("p",{className:`text-[17px] font-black tabular-nums leading-tight ${n?"text-emerald-700":"text-slate-900"}`,children:s}),e.jsx("p",{className:"text-[11.5px] text-slate-400 mt-0.5",children:t})]})}function oi({lines:t=[]}){return e.jsxs("div",{className:"rounded-2xl border border-teal-100 bg-teal-50/60 p-3",children:[e.jsx("p",{className:"text-[11.5px] font-black text-teal-800 mb-1",children:"×× ×קר×"}),e.jsx("ul",{className:"space-y-1",children:t.map(s=>e.jsxs("li",{className:"text-[13px] text-slate-700 leading-snug flex items-start gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-teal-500 flex-none mt-1.5"})," ",s]},s))})]})}const ci=t=>ve(t),xl=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),Pm=t=>{const[s,n,a]=String(t||"").slice(0,10).split("-");return a?`${a}/${n}/${s}`:""},Em=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"],di=t=>{const[s,n]=String(t||"").split("-").map(Number);return s&&n>=1&&n<=12?`${Em[n-1]} ${s}`:String(t||"")},Xa=({icon:t,label:s,children:n})=>e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[11px] font-bold text-slate-400 whitespace-nowrap",children:s}),e.jsxs("span",{className:"block text-[13.5px] font-black text-slate-800 truncate inline-flex items-center gap-1.5",children:[t&&e.jsx(t,{className:"w-3.5 h-3.5 text-slate-400 flex-none"}),n]})]});function tc({row:t,stage:s,period:n,busy:a,onClose:l,onConfirm:r}){const[o,p]=i.useState(!1),[u,d]=i.useState(""),c=s==="demand",m=c?"×פקת ×ר×שת תש×××":"××××× ××פקת ×ס×× ×תש×××",h=Pm(c?(t==null?void 0:t.next_issue)||(t==null?void 0:t.date):(t==null?void 0:t.next_due)||(t==null?void 0:t.date));return i.useEffect(()=>{const b=f=>{f.key==="Escape"&&l()};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[l]),Pt.createPortal(e.jsxs("div",{dir:"rtl",className:"fixed inset-0 z-[75] grid place-items-center p-4",role:"dialog","aria-modal":"true","aria-label":`××ש×ר ${m}`,children:[e.jsx("button",{type:"button","aria-label":"ס××ר×",onClick:l,className:"absolute inset-0 bg-slate-900/50 backdrop-blur-[2px] cursor-default"}),e.jsxs("div",{className:"relative w-full max-w-lg bg-white rounded-2xl border border-slate-200 shadow-2xl",children:[e.jsxs("div",{className:"flex items-start gap-3 p-5 pb-3",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl bg-amber-50 text-amber-600 grid place-items-center flex-none",children:e.jsx(xt,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"text-[17px] font-black text-slate-900",children:["××ש×ר ",m]}),e.jsxs("p",{className:"text-[12.5px] text-slate-500 mt-0.5",children:[t.name," · ××××ר ",di(n)]})]}),e.jsx("button",{type:"button",onClick:l,"aria-label":"ס××ר×",className:"mr-auto w-8 h-8 rounded-lg grid place-items-center text-slate-400 hover:text-slate-700 hover:bg-slate-100 flex-none",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"px-5 pb-4 space-y-3",children:[e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50 px-3.5 py-2.5 grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(Xa,{label:"ס×× ××××",children:t.name}),e.jsx(Xa,{label:"××××ר",children:di(n)}),e.jsx(Xa,{label:"×ש××× ×ת",children:t.accounts?xl(t.accounts):"â"}),e.jsx(Xa,{label:c?"×××¢× ××ר×ש×":"×××¢× ×××××",icon:vs,children:h||"â"})]}),e.jsx("p",{className:"text-[13.5px] text-slate-700 leading-relaxed bg-amber-50/70 border border-amber-200 rounded-xl px-3.5 py-3",children:c?e.jsxs(e.Fragment,{children:["×××ש×ר ×× ",e.jsx("b",{children:"ת×פק ×¢×ש××"})," ×ר×שת תש××× ×¢××ר ",e.jsx("b",{children:t.name})," ×ת×ש×× ××שפ××ת",t.accounts?e.jsxs(e.Fragment,{children:[" â ",xl(t.accounts)," ×ש××× ×ת ×ש××××"]}):null,t.forecast?e.jsxs(e.Fragment,{children:[", ××¡× ",e.jsx("b",{dir:"ltr",children:ci(t.forecast)})]}):null,". פע××× ×× ××× × × ××ª× ×ª ×××××× ×××ר ××פק×."]}):e.jsxs(e.Fragment,{children:["×××ש×ר ×× ××××× ××××× ×¢××ר ",e.jsx("b",{children:t.name})," ×××פק ×ס×× ×ª×©×××",t.accounts?e.jsxs(e.Fragment,{children:[" â ",xl(t.accounts)," ×ש××× ×ת ×ש××××"]}):null,t.forecast?e.jsxs(e.Fragment,{children:[", ××¡× ",e.jsx("b",{dir:"ltr",children:ci(t.forecast)})]}):null,". פע××× ×× ××× × × ××ª× ×ª ×××××× ×××ר ××××××."]})}),e.jsxs("label",{className:"flex items-start gap-2.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:o,onChange:b=>p(b.target.checked),className:"w-5 h-5 mt-0.5 rounded accent-amber-500 flex-none"}),e.jsxs("span",{className:"text-[13.5px] font-bold text-slate-800",children:["קר××ª× ×ת ×פר××× ××× × ××שר/ת ×ת ",m,"."]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-[11.5px] font-bold text-slate-500 mb-1",children:"××¢×¨× ×××ש×ר (×× ××××)"}),e.jsx("input",{value:u,onChange:b=>d(b.target.value),maxLength:300,className:"w-full h-11 rounded-xl border border-slate-200 px-3 text-sm focus:outline-none focus:border-amber-400"})]}),e.jsx("p",{className:"text-[11.5px] text-slate-400",children:"×©× ×××שר, ×ת×ר×× ×××©×¢× ××רש×× ×¢× ×××ש×ר."})]}),e.jsxs("div",{className:"flex items-center gap-3 px-5 py-3.5 border-t border-slate-100 bg-slate-50 rounded-b-2xl",children:[e.jsxs("button",{type:"button",onClick:()=>r(u),disabled:!o||a,className:`h-11 px-6 rounded-xl bg-amber-500 text-white text-[14px] font-bold 13 inline-flex items-center gap-2 hover:bg-amber-600 disabled:opacity-50`,children:[a?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(ye,{className:"w-4 h-4"}),c?"××ש×ר ××פק×":"××ש×ר ×ש××ר×"]}),e.jsx("button",{type:"button",onClick:l,className:"h-11 px-5 rounded-xl border border-slate-200 bg-white text-[13px] font-bold text-slate-600",children:"×××××"})]})]})]}),document.body)}const ui={monthly:"×××ש×",bimonthly:"××-×××ש×",quarterly:"ר××¢×× ×",yearly:"×©× ×ª×",one_time:"××-פע××",per_file:"××¤× ××¢×× ×ª ×§×××¥"},Fm={fixed:"ס××× ×§×××¢",per_sqm:"××¤× ×״ר",per_person:"××¤× × ×¤×©",per_property:"××¤× × ×ס",tiered:"×××ר×",custom:"××× ×",water_meter:"צר××ת ××× ××¤× ×§×¨××ת ××× ×"},Dm=t=>Fm[t]||t||"â",Om={serial:["×ס×","×ספרס×××ר×","ס×××ר×","×ס×ר","#"],consumer_id:["×ס×××××","×ספר×××××","×××××צר××","×סצר××","×ספרצר××","×§××צר××"],meter_number:["×ס××× ×","×ספר××× ×","××× ×","×ס××","×ספר××"],property_address:["×ת××ת×× ×ס","×ת×××ª× ×ס","×ת××ת"],consumer_name:["ש×צר××","ש××צר××","צר××","ש×"],read_at:["ת×ר××××××","ת×ר×××שע×","ת×ר××קר×××","ת×ר××","ת×ר×××××"],current_reading:["קר×××","קר×××× ××××ת","קר××ת××× ×","××× ×× ××××"],file_consumption:["צר×××","צר×××××§","×××תצר×××"],meter_status:["ס×××ס××× ×","ס×××ס","×צ×××× ×"]},sc=t=>String(t??"").replace(/[׳״"'`״׳]/g,"").replace(/[\s ._\-ââ/\\]/g,"").replace(/[()[\]]/g,"").trim().toLowerCase(),Lm=(()=>{const t=new Map;for(const[s,n]of Object.entries(Om))for(const a of n)t.set(sc(a),s);return t})(),mi=t=>{if(t==null)return null;if(typeof t=="number")return Number.isFinite(t)?t:null;const s=String(t).replace(/[âââª-â®]/g,"").replace(/,/g,"").trim();if(!s)return null;const n=s.match(/-?\d+(\.\d+)?/);if(!n)return null;const a=Number(n[0]);return Number.isFinite(a)?a:null},En=t=>{var s;return t==null?"":t instanceof Date?t.toISOString().slice(0,16).replace("T"," "):typeof t=="object"?String(t.text??t.result??((s=t.ric
13hText)==null?void 0:s.map(n=>n.text).join(""))??"").trim():String(t).replace(/[ââ]/g,"").trim()};function Tm(t){const s=Math.min((t==null?void 0:t.length)||0,15);for(let n=0;n<s;n++){const a={};let l=0;if((t[n]||[]).forEach((r,o)=>{const p=Lm.get(sc(En(r)));p&&a[p]===void 0&&(a[p]=o,l+=1)}),l>=2&&a.meter_number!==void 0)return{headerRow:n,cols:a};if(l>=3)return{headerRow:n,cols:a}}return null}function Bm(t,s){const n=[];let a="",l=!1;for(let r=0;r<t.length;r++){const o=t[r];l?o==='"'?t[r+1]==='"'?(a+='"',r+=1):l=!1:a+=o:o==='"'?l=!0:o===s?(n.push(a),a=""):a+=o}return n.push(a),n.map(r=>r.trim())}function Rm(t){const s=String(t||"").split(/\r\n|\r|\n/).filter(r=>r.trim()!=="");if(!s.length)return[];const n=s.slice(0,20),a=r=>n.reduce((o,p)=>o+(p.split(r).length-1),0),l=[",",";"," "].sort((r,o)=>a(o)-a(r))[0];return s.map(r=>Bm(r,l))}async function qm(t){const s=(await In(async()=>{const{default:r}=await import("./exceljs.min-CcgsY5Wm.js").then(o=>o.e);return{default:r}},__vite__mapDeps([0,1,2]))).default,n=new s.Workbook;await n.xlsx.load(t);const a=n.worksheets[0];if(!a)return[];const l=[];return a.eachRow({includeEmpty:!1},r=>{const o=r.values||[];l.push(o.slice(1).map(En))}),l}const Im=t=>/\.xlsx?$/i.test(String(t||""));async function zm(t){const s=(t==null?void 0:t.name)||"",n=await t.arrayBuffer();let a=[];if(Im(s))try{a=await qm(n)}catch{return{rows:[],errors:["×× × ××ª× ×קר×× ×ת ××§×××¥. ש××¨× ×××ª× ×××ש ×פ×ר×× XLSX ×× CSV ×× ×¡× ×©××."],headerRow:-1,columns:{}}}else a=Rm(new TextDecoder("utf-8").decode(n));return Km(a)}function Km(t){const s=[],n=Tm(t);if(!n)return{rows:[],errors:["×× ××××ª× ×©×רת ××תר×ת ××§×××¥. × ×רש×ת ×פ××ת ××¢××××ת: ×ס׳ ××× ×, קר×××."],headerRow:-1,columns:{}};const{headerRow:a,cols:l}=n;l.meter_number===void 0&&l.consumer_id===void 0&&s.push("××§×××¥ ××× ×ס׳ ××× × ×××× ×ס׳ ××××× â ×× × ××ª× ××ת××× ×ת ×רש×××ת ×××× ××."),l.current_reading===void 0&&s.push("××§×××¥ ××× ×¢×××ת קר×××.");const r=(u,d)=>l[d]===void 0?"":En(u[l[d]]),o=[],p=new Map;for(let u=a+1;u<t.length;u++){const d=t[u]||[];if(d.every(g=>En(g)===""))continue;const c=r(d,"meter_number"),m=r(d,"consumer_id"),h=mi(r(d,"current_reading")),b=o.length+1,f={row_no:b,source_serial:r(d,"serial"),consumer_id:m,meter_number:c,property_address:r(d,"property_address"),consumer_name:r(d,"consumer_name"),read_at:r(d,"read_at"),current_reading:h,file_consumption:mi(r(d,"file_consumption")),meter_status:r(d,"meter_status"),file_error:""};!c&&!m?f.file_error="×ש××¨× ××× ×ס׳ ××× × ×××× ×ס׳ ×××××":h===null&&(f.file_error="×קר××× ×ש××¨× ××× × ×ספר");const x=c||`id:${m}`;x&&p.has(x)?f.duplicate_of=p.get(x):x&&p.set(x,b),o.push(f)}return o.length||s.push("×× × ×צ×× ×©×ר×ת × ×ª×× ×× ×ת×ת ×ש×רת ×××תר×ת."),{rows:o,errors:s,headerRow:a,columns:l}}function Wm(t){const s=t||[];return{rows:s.length,meters:new Set(s.map(n=>n.meter_number).filter(Boolean)).size,duplicates:s.filter(n=>n.duplicate_of).length,errors:s.filter(n=>n.file_error).length}}const qa=(t,s)=>t.value?t.value(s):s[t.key],pl=new Set(["num","money","cube","dec3"]);function Fn(t,s){const n=qa(t,s);if(n==null||n==="")return t.blank??"â";switch(t.type){case"money":return Number(n).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2});case"cube":case"dec3":return Number(n).toFixed(3).replace(/\.?0+$/,"");case"num":return new Intl.NumberFormat("he-IL").format(Number(n));case"pct":return`${Number(n).toFixed(1)}%`;case"date":{const a=String(n).slice(0,10),[l,r,o]=a.split("-");return o?`${o}/${r}/${l}`:a}default:return String(n)}}function ac(t,s){const n={};for(const a of t)if(a.total){if(a.total==="count"){n[a.key]=s.length;continue}n[a.key]=s.reduce((l,r)=>{const o=Number(qa(a,r));return l+(Number.isFinite(o)?o:0)},0)}return n}async function nc({fileName:t,sheetName:s,title:n,meta:a=[],columns:l,rows:r,totals:o}){const p=(await In(async()=>{const{default:A}=await import("./exceljs.min-CcgsY5Wm.js").then(S=>S.e);return{default:A}},__vite__mapDeps([0,1,2]))).default,u=new p.Workbook;u.creator="Eshuv",u.created=new Date;const d=l.filter(A=>!A.hide),c=u.addWorksheet((s||n||"×××").slice(0,30),{views:[{rightToLeft:!0,state:"frozen",ySplit:a.length?3:2}]}),m=d.length;d.forEach((A,S)=>{c.getColumn(S+1).width=A.width||16}),c.mergeCells(1,1,1,m);const h=c.getCell(1,1);h.value=n,h.font={bold:!0,size:15,color:{argb:"FFFFFFFF"}},h.alignment={horizontal:"right",vertical:"middle",readingOrder:"rtl"},h.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FF1E293B"}},c.getRow(1).height=26;let b=2;if(a.length){c.mergeCells(2,1,2,m);const A=c.getCell(2,1);
13A.value=a.join(" · "),A.font={size:10,color:{argb:"FF475569"}},A.alignment={horizontal:"right",vertical:"middle",readingOrder:"rtl"},b=3}const f=c.getRow(b);d.forEach((A,S)=>{const P=f.getCell(S+1);P.value=A.header,P.font={bold:!0,size:11,color:{argb:"FFFFFFFF"}},P.alignment={horizontal:"center",vertical:"middle",wrapText:!0,readingOrder:"rtl"},P.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FF0F766E"}}}),f.height=20,r.forEach((A,S)=>{const P=c.getRow(b+1+S);d.forEach((E,k)=>{const C=P.getCell(k+1),w=qa(E,A);if(pl.has(E.type)){const _=Number(w);C.value=Number.isFinite(_)?_:null,C.numFmt=E.type==="money"?"#,##0.00":E.type==="num"?"#,##0":"#,##0.000"}else C.value=w==null?"":String(Fn(E,A)==="â"?"":Fn(E,A));C.font={size:10,color:{argb:"FF1E293B"}},C.alignment={horizontal:pl.has(E.type)?"left":E.align==="center"?"center":"right",vertical:"middle",readingOrder:"rtl"},S%2===1&&(C.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFF8FAFC"}}),C.border={bottom:{style:"hair",color:{argb:"FFE2E8F0"}}}})});const x=o||ac(d,r);if(Object.keys(x).length){const A=c.getRow(b+1+r.length);d.forEach((S,P)=>{const E=A.getCell(P+1);P===0?E.value=`ס××´× ${r.length}`:x[S.key]!==void 0&&(E.value=Number(x[S.key]),E.numFmt=S.type==="money"?"#,##0.00":S.type==="num"?"#,##0":"#,##0.000"),E.font={bold:!0,size:11},E.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFEFF2F6"}},E.alignment={horizontal:pl.has(S.type)?"left":"right",vertical:"middle",readingOrder:"rtl"}})}const g=await u.xlsx.writeBuffer(),y=new Blob([g],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),$=URL.createObjectURL(y),O=document.createElement("a");O.href=$,O.download=`${t||"×××"}.xlsx`,document.body.appendChild(O),O.click(),O.remove(),setTimeout(()=>URL.revokeObjectURL($),1e3)}const hl=new Set(["num","money","cube","dec3"]),Um=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),lc=` 14@media print { 15 @page { size: A4 landscape; margin: 10mm; } 16 body * { visibility: hidden !important; } 17 #billing-report, #billing-report * { visibility: visible !important; } 18 #billing-report { position: absolute; inset: 0; width: 100%; padding: 0; } 19 .no-print { display: none !important; } 20 .print-only { display: block !important; } 21 #billing-report table { font-size: 10px; } 22 #billing-report thead { display: table-header-group; } 23 #billing-report tr { break-inside: avoid; } 24 #billing-report .card, #billing-report .rounded-2xl { box-shadow: none !important; } 25} 26.print-only { display: none; } 27/* The table and the filter row steer with buttons, not with a scrollbar that 28 sits under the fold and that nobody on a laptop trackpad finds. */ 29.report-scroll { scrollbar-width: none; -ms-overflow-style: none; } 30.report-scroll::-webkit-scrollbar { width: 0; height: 0; } 31`;function ma({anchorRef:t,open:s,onClose:n,children:a,width:l}){const r=i.useRef(null),[o,p]=i.useState(null),u=i.useCallback(()=>{const d=t.current;if(!d)return;const c=d.getBoundingClientRect(),m=Number.isFinite(l)?l:0,h=c.right-8;if(m&&h<m&&window.innerWidth-c.left-8>=m){p({top:c.bottom+4,left:Math.max(8,c.left),maxWidth:window.innerWidth-c.left-8});return}p({top:c.bottom+4,right:Math.max(8,window.innerWidth-c.right),maxWidth:Math.max(h,m)})},[t,l]);return i.useLayoutEffect(()=>{if(!s)return;u();const d=()=>u();return window.addEventListener("scroll",d,!0),window.addEventListener("resize",d),()=>{window.removeEventListener("scroll",d,!0),window.removeEventListener("resize",d)}},[s,u]),i.useEffect(()=>{if(!s)return;const d=m=>{var h,b;(h=r.current)!=null&&h.contains(m.target)||(b=t.current)!=null&&b.contains(m.target)||n()},c=m=>{m.key==="Escape"&&n()};return document.addEventListener("mousedown",d),document.addEventListener("keydown",c),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",c)}},[s,n,t]),!s||!o?null:Pt.createPortal(e.jsx("div",{ref:r,dir:"rtl",style:{position:"fixed",top:o.top,right:o.right,left:o.left,maxWidth:o.maxWidth,width:l},className:"z-[60] bg-white rounded-2xl border border-slate-200 shadow-xl",children:a}),document.body)}const Yl="text-[12.5px] font-extrabold text-slate-600 whitespace-nowrap";function jr({label:t,wide:s,children:n}){return e.jsxs("label",{className:`block flex-none ${s?"flex-1 min-w-[8rem] max-w-[15rem]":""}`,children:[e.jsx("span",{className:`block mb-1.5 ${Yl}`,children:t}),n]})}const Ia="h-10 rounded-xl border border-slate-200 bg-white px-3 text-sm text-slate-700 focus:outline-none focus:border-teal-500 focus:ring-4 focus:ring-teal-50 transition-colors",rc=Symbol("countTotal");function Te(t=[],s={}){const n={};for(const a of Object.keys(s))n[a]=0;
31for(const a of t)for(const[l,r]of Object.entries(s))r(a)&&(n[l]+=1);return Object.defineProperty(n,rc,{value:t.length,enumerable:!1}),n}function ic(t=[],s,n,a){if(!s)return t;const l=Number.isFinite(a)?a:s[rc],r=t.filter(p=>{const u=String(p.v??"");return u===""||u===String(n??"")?!0:(s[u]??0)>0}),o=r.filter(p=>String(p.v??"")!=="");return o.length===0?[]:o.length===1&&Number.isFinite(l)&&(s[String(o[0].v)]??0)===l?[]:r}function Ae({label:t,hint:s,value:n,onChange:a,options:l=[],counts:r,total:o,inline:p}){const u=l.some(m=>String(m.v??"")===""),d=ic(l,r,n,o).filter(m=>!(u&&String(m.v??"")===""));if(d.length===0)return null;const c=d.map(m=>{const h=String(n??"")===String(m.v),b=()=>a(h&&u?"":m.v);return e.jsx("button",{type:"button",onClick:b,"aria-pressed":h,title:h&&u?"×××¦× ×©×× ××צ×ת ×××":m.l,className:`h-9 rounded-xl text-[13px] font-bold border transition-colors whitespace-nowrap ${p?"px-3":"px-3.5"} ${h?"bg-teal-600 border-teal-600 text-white shadow-sm":"bg-white border-slate-200 text-slate-600 hover:border-slate-300"}`,children:m.l},String(m.v))});return p?e.jsxs("div",{className:"flex items-center gap-1.5 flex-none",children:[t&&e.jsx("span",{className:`${Yl} px-0.5`,children:t}),c]}):e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-1.5",children:[e.jsx("span",{className:Yl,children:t}),s&&e.jsx("span",{className:"text-[11px] text-slate-400 whitespace-nowrap",children:s})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:c})]})}const Vl=[{v:"month",l:"××××ש"},{v:"prev",l:"×××ש ×§×××"},{v:"q",l:"3 ×××ש××"},{v:"year",l:"××©× ×"}],ds=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;function Dn(t,s=new Date){const n=s.getFullYear(),a=s.getMonth();return t==="month"?{from:ds(new Date(n,a,1)),to:ds(new Date(n,a+1,0))}:t==="prev"?{from:ds(new Date(n,a-1,1)),to:ds(new Date(n,a,0))}:t==="q"?{from:ds(new Date(n,a-2,1)),to:ds(new Date(n,a+1,0))}:t==="year"?{from:`${n}-01-01`,to:`${n}-12-31`}:{from:"",to:""}}const oc=({label:t,value:s,onChange:n,options:a=[],counts:l,total:r})=>{const o=ic(a,l,s,r);return o.length===0?null:e.jsx(jr,{label:t,children:e.jsx("select",{className:`${Ia} min-w-[8rem]`,value:s,onChange:p=>n(p.target.value),children:o.map(p=>e.jsx("option",{value:p.v,children:p.l},p.v))})})},cc=({label:t,value:s,onChange:n,placeholder:a})=>e.jsx(jr,{label:t,children:e.jsx("input",{type:"number",className:`${Ia} w-24`,value:s,placeholder:a,onChange:l=>n(l.target.value)})}),Zn=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"],Hm=["×","×","×","×","×","×","ש"],ba=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,dc=t=>{const s=String(t||"").slice(0,10);if(!/^\d{4}-\d{2}-\d{2}$/.test(s))return null;const[n,a,l]=s.split("-").map(Number);return new Date(n,a-1,l)},Ve=t=>{const s=dc(t);return s?`${String(s.getDate()).padStart(2,"0")}.${String(s.getMonth()+1).padStart(2,"0")}.${String(s.getFullYear()).slice(2)}`:""},Ym=(t,s)=>{const a=new Date(t,s,1).getDay(),l=new Date(t,s+1,0).getDate(),r=Array.from({length:a},()=>null);for(let o=1;o<=l;o++)r.push(new Date(t,s,o));for(;r.length%7;)r.push(null);return r};function uc({from:t,to:s,onChange:n,onDone:a}){const[l,r]=i.useState(()=>{const c=dc(t)||new Date;return new Date(c.getFullYear(),c.getMonth(),1)}),o=c=>{const m=ba(c);if(!t||t&&s){n({from:m,to:""});return}if(m<t){n({from:m,to:t}),a();return}n({from:t,to:m}),a()},p=ba(new Date),u=({base:c})=>e.jsxs("div",{className:"w-[15.5rem]",children:[e.jsxs("p",{className:"text-center text-sm font-bold text-teal-700 mb-2",children:[Zn[c.getMonth()]," ",c.getFullYear()]}),e.jsxs("div",{className:"grid grid-cols-7 gap-y-1 text-center",children:[Hm.map(m=>e.jsx("span",{className:"text-[11px] font-bold text-slate-400",children:m},m)),Ym(c.getFullYear(),c.getMonth()).map((m,h)=>{if(!m)return e.jsx("span",{},h);const b=ba(m),f=b===t,x=b===s,g=t&&s&&b>t&&b<s;return e.jsx("button",{type:"button",onClick:()=>o(m),className:`h-8 w-8 mx-auto text-[13px] rounded-full transition-colors 32 ${f||x?"bg-teal-600 text-white font-bold":g?"bg-teal-50 text-teal-800":"text-slate-700 hover:bg-slate-100"} 33 ${b===p&&!f&&!x?"ring-1 ring-teal-400":""}`,children:m.getDate()},b)})]})]}
33),d=new Date(l.getFullYear(),l.getMonth()+1,1);return e.jsxs("div",{className:"p-4",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:[{k:"from",l:"×ת×ר××",v:t},{k:"to",l:"×¢× ×ª×ר××",v:s}].map(c=>e.jsxs("span",{className:"flex items-center gap-2 h-10 px-3 rounded-xl border border-slate-200 text-sm min-w-[8.5rem]",children:[e.jsx("span",{className:c.v?"text-slate-800":"text-slate-400",children:c.v?Ve(c.v):c.l}),c.v&&e.jsx("button",{type:"button",className:"text-slate-400 hover:text-slate-700",onClick:()=>n({from:c.k==="from"?"":t,to:c.k==="to"?"":s}),children:e.jsx($e,{className:"w-3.5 h-3.5"})})]},c.k))}),e.jsxs("div",{className:"flex items-start gap-6",children:[e.jsx("button",{type:"button",onClick:()=>r(new Date(l.getFullYear(),l.getMonth()-1,1)),className:"w-7 h-7 rounded-full flex items-center justify-center text-slate-400 hover:bg-slate-100 mt-1",children:e.jsx(oa,{className:"w-4 h-4"})}),e.jsx(u,{base:l}),e.jsx(u,{base:d}),e.jsx("button",{type:"button",onClick:()=>r(new Date(l.getFullYear(),l.getMonth()+1,1)),className:"w-7 h-7 rounded-full flex items-center justify-center text-slate-400 hover:bg-slate-100 mt-1",children:e.jsx(lt,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-3 pt-3 border-t border-slate-100",children:[[{l:"××××ש",from:new Date(new Date().getFullYear(),new Date().getMonth(),1),to:new Date},{l:"×××ש××× ××ר×× ××",from:new Date(new Date().getFullYear(),new Date().getMonth()-1,1),to:new Date},{l:"××©× ×",from:new Date(new Date().getFullYear(),0,1),to:new Date}].map(c=>e.jsx("button",{type:"button",onClick:()=>{n({from:ba(c.from),to:ba(c.to)}),a()},className:"h-8 px-3 rounded-full border border-slate-200 text-xs text-slate-600 hover:bg-slate-50",children:c.l},c.l)),e.jsx("button",{type:"button",onClick:()=>{n({from:"",to:""}),a()},className:"h-8 px-3 rounded-full text-xs text-slate-400 hover:text-slate-700 mr-auto",children:"× ××§××"})]})]})}function Vm({label:t="×××× ×ª×ר××××",from:s,to:n,onChange:a,placeholder:l="×× ×ת×ר××××"}){const[r,o]=i.useState(!1),p=i.useRef(null),u=s||n?`${Ve(s)||"â¦"} â ${Ve(n)||"â¦"}`:"";return e.jsxs("div",{className:"block flex-none",children:[e.jsx("span",{className:"block text-[11px] font-bold text-slate-500 mb-1 whitespace-nowrap",children:t}),e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{type:"button",onClick:()=>o(d=>!d),className:`${Ia} w-[13.5rem] flex items-center gap-2 text-right`,children:[e.jsx(vs,{className:"w-4 h-4 text-slate-400 flex-none"}),e.jsx("span",{className:`flex-1 truncate ${u?"text-slate-700":"text-slate-400"}`,children:u||l}),u?e.jsx($e,{className:"w-4 h-4 text-slate-400 flex-none hover:text-slate-700",onClick:d=>{d.stopPropagation(),a({from:"",to:""})}}):e.jsx(Jt,{className:"w-4 h-4 text-slate-400 flex-none"})]}),e.jsx(ma,{anchorRef:p,open:r,onClose:()=>o(!1),children:e.jsx(uc,{from:s,to:n,onChange:a,onDone:()=>o(!1)})})]})]})}function Gm({label:t="תק×פ×",value:s,from:n,to:a,onChange:l,counts:r,inline:o}){const[p,u]=i.useState(!1),d=i.useRef(null),c=s==="custom",m=c&&(n||a),h=b=>`h-9 rounded-xl text-[13px] font-bold border transition-colors whitespace-nowrap inline-flex items-center gap-1.5 ${o?"px-3":"px-3.5"} ${b?"bg-teal-600 border-teal-600 text-white shadow-sm":"bg-white border-slate-200 text-slate-600 hover:border-slate-300"}`;return e.jsxs("div",{className:o?"flex items-center gap-1.5 flex-none":"min-w-0",children:[o?t&&e.jsx("span",{className:"text-[11px] font-bold text-slate-400 whitespace-nowrap px-0.5",children:t}):e.jsx("div",{className:"flex items-baseline gap-2 mb-1.5",children:e.jsx("span",{className:"text-[11px] font-bold text-slate-500 whitespace-nowrap",children:t})}),e.jsxs("div",{className:o?"flex items-center gap-1.5":"flex flex-wrap items-center gap-1.5",children:[Vl.filter(b=>!r||b.v===s||(r[b.v]??0)>0).map(b=>e.jsx("button",{type:"button",className:h(s===b.v),onClick:()=>{u(!1),l({span:b.v,...Dn(b.v)})},children:b.l},b.v)),e.jsxs("span",{className:"relative inline-block",ref:d,children:[e.jsxs("button",{type:"button",className:h(c),onClick:()=>u(b=>!b),children:[e.jsx(vs,{className:`w-4 h-4 flex-none ${c?"text-white/80":"text-slate-400"}`}),m?`${Ve(n)||"â¦"} â ${Ve(a)||"â¦"}`:"××ר",m&&e.jsx($e,{className:"w-3.5 h-3.5 flex-none opacity-70 hover:opacity-100",onClick:b=>{b.stopPropagation(),u(!1),l({span:"month",...Dn("month")})}})]}),e.jsx(ma,{anchorRef:d,open:p,onClose:()=>
33u(!1),children:e.jsx(uc,{from:c?n:"",to:c?a:"",onChange:({from:b,to:f})=>l({span:"custom",from:b,to:f}),onDone:()=>u(!1)})})]})]})]})}const Gl=(t,s)=>`${t}-${String(s+1).padStart(2,"0")}`;function xi(t){const[s,n]=String(t||"").split("-").map(Number);return!s||!n?{from:"",to:""}:{from:`${s}-${String(n).padStart(2,"0")}-01`,to:ds(new Date(s,n,0))}}const xs=t=>{const[s,n]=String(t||"").split("-").map(Number);return s&&n?`${Zn[n-1]} ${s}`:""},Xm=t=>{const[s,n]=String(t||"").split("-").map(Number);return s&&n?`${Zn[n-1]} ${String(s).slice(-2)}`:""};function mc({label:t="תק×פת ××××",value:s,onChange:n,monthsWithData:a,allowAll:l=!1}){const r=i.useRef(null),[o,p]=i.useState(!1),[u]=String(s||"").split("-").map(Number),[d,c]=i.useState(u||new Date().getFullYear());i.useEffect(()=>{o&&c(u||new Date().getFullYear())},[o,u]);const m=b=>!a||a.has(b),h=a&&![...Array(12).keys()].some(b=>m(Gl(d,b)));return e.jsxs(jr,{label:t,children:[e.jsxs("button",{ref:r,type:"button",onClick:()=>p(b=>!b),"aria-haspopup":"dialog","aria-expanded":o,className:`${Ia} h-9 inline-flex items-center gap-2 font-bold text-[13px] ${o?"border-teal-500 ring-4 ring-teal-50":""}`,children:[e.jsx(vs,{className:"w-4 h-4 flex-none text-teal-600"}),e.jsx("span",{className:"whitespace-nowrap",children:Xm(s)||(l?"×× ×תק×פ×ת":"×××רת ×××ש")}),e.jsx(Jt,{className:`w-3.5 h-3.5 flex-none text-slate-400 transition-transform ${o?"rotate-180":""}`})]}),e.jsx(ma,{anchorRef:r,open:o,onClose:()=>p(!1),width:272,children:e.jsxs("div",{className:"p-3",role:"dialog","aria-label":t,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[e.jsx("button",{type:"button","aria-label":"×©× × ×§×××ת",title:"×©× × ×§×××ת",onClick:()=>c(b=>b-1),className:"w-8 h-8 rounded-lg grid place-items-center text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(oa,{className:"w-4 h-4"})}),e.jsx("span",{className:"text-[14px] font-black text-slate-800 tabular-nums",children:d}),e.jsx("button",{type:"button","aria-label":"×©× × ××××",title:"×©× × ××××",onClick:()=>c(b=>b+1),className:"w-8 h-8 rounded-lg grid place-items-center text-slate-400 hover:bg-slate-100 hover:text-slate-700",children:e.jsx(lt,{className:"w-4 h-4"})})]}),l&&e.jsx("button",{type:"button",onClick:()=>{n(""),p(!1)},"aria-pressed":!s,className:`w-full h-9 mb-2 rounded-xl text-[12.5px] font-bold border transition-colors ${s?"bg-white border-slate-200 text-slate-700 hover:border-teal-300 hover:text-teal-700":"bg-teal-600 border-teal-600 text-white shadow-sm"}`,children:"×× ×תק×פ×ת"}),h?e.jsxs("p",{className:"text-[12.5px] text-slate-400 text-center py-4",children:["××× × ×ª×× ×× ××©× ×ª ",d,"."]}):e.jsx("div",{className:"grid grid-cols-3 gap-1.5",role:"group",children:Zn.map((b,f)=>{const x=Gl(d,f),g=x===s;return!g&&!m(x)?null:e.jsx("button",{type:"button",title:b,"aria-pressed":g,onClick:()=>{n(x),p(!1)},className:`h-9 rounded-xl text-[12.5px] font-bold border transition-colors ${g?"bg-teal-600 border-teal-600 text-white shadow-sm":"bg-white border-slate-200 text-slate-700 hover:border-teal-300 hover:text-teal-700"}`,children:b},b)})})]})})]})}const Zm="h-9 px-3.5 rounded-xl bg-white border border-slate-200 text-slate-600 text-[13px] font-bold inline-flex items-center gap-1.5 hover:border-slate-300 disabled:opacity-40 transition-colors";function Qm({open:t,onClose:s,columns:n,hidden:a,onToggle:l,onAll:r,onReset:o}){const p=n.length-a.size;i.useEffect(()=>{if(!t)return;const d=c=>{c.key==="Escape"&&s()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,s]);const u=d=>{s()};return e.jsx(e.Fragment,{children:t&&Pt.createPortal(e.jsx("div",{dir:"rtl",className:"fixed inset-0 z-[70] bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:()=>u(),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-lg max-h-[85vh] flex flex-col",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 p-5 pb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-lg font-black text-slate-900",children:"×××רת ×¢××××ת"}),e.jsx("p",{className:"text-[12.5px] text-slate-500 mt-0.5",children:`××צ××ת ${p} ×ת×× ${n.length} ×¢××××ת. ×××××¨× × ×©×רת ×ת×××ר ×× ×××¨× ×¨×¢× ××.`})]}),e.jsx("button",{type:"button",onClick:()=>u(),"aria-label":"ס××ר×",className:"w-9 h-9 rounded-full border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50 flex-none",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-3 pb-2 grid sm:grid-cols-2 gap-x-2 content-start",children:n.map(d=>{const c=!a.has(d.key);return e.jsxs("button",{type:"button",onClick:()=>l(d.key),className:`flex items-center gap-2.5 px-2.5 py-2 rounded-xl text-sm text-right transition-colors ${c?"hover:bg-teal-50/60":"hover:bg-slate-50"}`,children:[e.jsx("span",{className:`w-[18px] h-[18px] rounded-md border flex items-center justify-center flex-none ${c?"bg-teal-500 border-teal-500 text-white":"border-slate-300"}`,children:c&&e.jsx(ye,{className:"w-3 h-3"})}),e.jsx("span",{className:`flex-1 truncate ${c?"text-slate-700 font-semibold":"text-slate-400"}`,children:d.header})]},d.key)})}),e.jsxs("div",{className:"flex items-center gap-2 p-4 border-t border-slate-100",children:[a.size>0&&e.jsx("button",{type:"button",onClick:r,className:"h-10 px-4 roun
33ded-xl border border-teal-200 bg-teal-50 text-teal-700 text-sm font-bold hover:bg-teal-100 transition-colors",children:"ס×× ×××"}),e.jsx("button",{type:"button",onClick:o,className:"h-10 px-4 rounded-xl border border-slate-200 text-slate-500 text-sm font-bold hover:bg-slate-50 transition-colors",children:"××פ×ס ××ר×רת ×××××"}),e.jsx("button",{type:"button",onClick:()=>u(),className:"h-10 px-5 rounded-xl bg-slate-900 text-white text-sm font-bold hover:bg-slate-800 transition-colors mr-auto",children:"ס×××"})]})]})}),document.body)})}function Jm({columns:t,hidden:s,onToggleColumn:n,onAllColumns:a,onResetColumns:l,onExcel:r,onPdf:o,pdfBusy:p,hasRows:u,compact:d}){const c=i.useRef(null),[m,h]=i.useState(!1),[b,f]=i.useState(!1),x=t.length-s.size,g=t.length>4,y=({Icon:$,iconClass:O,title:A,note:S,onClick:P,disabled:E})=>e.jsxs("button",{type:"button",role:"menuitem",disabled:E,onClick:()=>{h(!1),P()},className:"w-full text-right flex items-start gap-3 px-3 py-2.5 rounded-xl hover:bg-slate-50 disabled:opacity-40 disabled:hover:bg-transparent transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-teal-400",children:[e.jsx("span",{className:"w-8 h-8 rounded-lg bg-slate-50 grid place-items-center flex-none mt-0.5",children:e.jsx($,{className:`w-4 h-4 ${O}`})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800",children:A}),e.jsx("span",{className:"block text-[11.5px] text-slate-500 leading-snug",children:S})]})]});return e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:c,type:"button",onClick:()=>h($=>!$),"aria-haspopup":"menu","aria-expanded":m,className:`${Zm} no-print ${d?"":"h-10"} ${m?"border-slate-300 bg-slate-50":""}`,children:[e.jsx(Hn,{className:"w-4 h-4 flex-none text-teal-600"}),"פע×××ת",e.jsx(Jt,{className:`w-3.5 h-3.5 flex-none text-slate-400 transition-transform ${m?"rotate-180":""}`})]}),e.jsx(ma,{anchorRef:c,open:m,onClose:()=>h(!1),width:288,children:e.jsxs("div",{className:"p-2",role:"menu",children:[g&&e.jsx(y,{Icon:Md,iconClass:"text-teal-600",title:"×××רת ×¢××××ת",note:`××צ××ת ${x} ×ת×× ${t.length}. ×××××¨× × ×©×רת.`,onClick:()=>f(!0)}),e.jsx(y,{Icon:pr,iconClass:"text-emerald-600",title:"××צ×× ××קס×",note:"×× ××¢××××ת, ×× ×××סתר×ת, ××¤× ×ס×× ×× ×××××× ×× ××××××.",onClick:r,disabled:!u}),e.jsx(y,{Icon:p?Ie:go,iconClass:`text-rose-600 ${p?"animate-spin":""}`,title:p?"×××× PDFâ¦":"××צ×× ×-PDF",note:"×××× ××§×××¥, ×××××§ ××¤× ×©××× × ×¨×× ×××פס×.",onClick:o,disabled:!u||p}),e.jsx(y,{Icon:yo,iconClass:"text-slate-500",title:"××פס×",note:"×¢× ×××× ×פר×× ×××ש××, ×××× ×ª×¤×¨××× ××ער×ת.",onClick:()=>window.print(),disabled:!u})]})}),e.jsx(Qm,{open:b,onClose:()=>f(!1),columns:t,hidden:s,onToggle:n,onAll:a,onReset:l})]})}function ex({value:t,placeholder:s,onChange:n,compact:a}){const l=i.useRef(null),r=t||"",o=a?"h-9":"h-10";return e.jsxs("span",{className:`relative block flex-1 min-w-[7rem] max-w-[17rem] ${o}`,children:[e.jsx(qt,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none z-10","aria-hidden":"true"}),e.jsx("input",{ref:l,value:r,placeholder:s||"××פ×ש","aria-label":s||"××פ×ש ××××",onChange:p=>n(p.target.value),onKeyDown:p=>{p.key==="Escape"&&r&&(n(""),p.stopPropagation())},className:`${Ia} ${o} w-full pr-9 pl-8 ${a?"text-[13px]":""}`}),r.length>0&&e.jsx("button",{type:"button","aria-label":"× ××§×× ×××פ×ש",onMouseDown:p=>p.preventDefault(),onClick:()=>{var p;n(""),(p=l.current)==null||p.focus()},className:"absolute left-2 top-1/2 -translate-y-1/2 w-6 h-6 rounded-full grid place-items-center text-slate-400 hover:text-slate-700 hover:bg-slate-100",children:e.jsx($e,{className:"w-3.5 h-3.5"})})]})}const tx=t=>{let s=String(t||"").replace(/\D/g,"");return s.startsWith("0")?s=`972${s.slice(1)}`:s.length===9&&(s=`972${s}`),s};function sx({phone:t,name:s}){const[n,a]=i.useState(!1),l=i.useRef(null);if(!t)return e.jsx("span",{className:"text-slate-300",children:"â"});const r=tx(t);return e.jsxs("span",{className:"inline-block",ref:l,children:[e.jsx("button",{type:"button",onClick:()=>a(o=>!o),title:`${s||""} ${t}`.trim(),className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-emerald-600 bg-emerald-50 hover:bg-emerald-100 transition-colors",children:e.jsx(gn,{className:"w-4 h-4"})}),e.jsx(ma,{anchorRef:l,open:n,onClose:()=>a(!1),width:"13rem",children:e.jsxs("div",{className:"p-3 text-right",children:[s&&e.jsx("p",{className:"text-xs font-bold text-slate-700 truncate",children:s}),e.jsx("p",{className:"text-sm font-bold text-slate-900 tabular-nums",dir:"ltr",children:t}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-2",children:[e.jsxs("a",{href:`https://wa.me/${r}`,target:"_blank",rel:"noopener noreferrer",className:"flex-1 h-8 rounded-lg bg-emerald-600 text-white text-xs font-bold inline-flex items-center justify-center gap-1",children:[e.jsx(gn,{className:"w-3.5 h-3.5"})," WhatsApp"]}),e.jsx("a",{href:`tel:${t}`,className:"w-8 h-8 rounded-lg border border-slate-200 inline-flex items-center justify-center text-slate-500 hover:bg-slate-50",children:e.jsx(ao,{className:"w-3.5 h-3.5"})})]})]})})]})}function ax(t){if(t.scrollLeft<0)return-1;if(t.scrollLeft>0)return 1;t.scrollLeft=-1;const s=t.scrollLeft<0?-1:1;return t.scrollLeft=0,s}function nx({children:t,className:s=""}){const n=i.useRef(null),[a,l]=i.useState({show:!1,start:!0,end:!1,pct:0}),r=i.useCallback(()=>{const u=n.current;if(!u)return;const d=u.scrollWidth-u.clientWidth,c=Math.abs(u.scrollLeft),m=(()=>{const h=u.getBoundingClientRect();return h.bottom>120&&h.top<window.innerHeight-40})();l({show:d>8&&m,start:c<=2,end:c>=d-2,pct:d>0?Math.min(100,Math.round(c/d*100)):0})},[]);i.useEffect(()=>{const u=n.current;if(!u)return;r();const d=new ResizeObserver(r);return d.observe(u),u.firstElementChild&&d.observe(u.firstElementChild),u.addEventListener("scroll",r,{passive:!0}),window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r),()=>{d.disconnect(),u.removeEventListener("scroll",r),window.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[r,t]);const o=u=>{const d=n.current;if(!d)return;const c=ax(d);d.scrollBy({left:u*c*d.clientWidth*.8,behavior:"smooth"})},p="w-10 h-10 rounded-full flex items-center justify-center transition-colors disabled:opacity-30 disabled:cursor-default";return e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:n,className:`overflow-x-auto report-scroll ${s}`,children:t}),a.show&&Pt.createPortal(e.jsxs("div",{dir:"rtl",className:"no-print fixed bottom-6 left-1/2 -translate-x-1/2 z-50 flex items-center gap-1 bg-white/95 backdrop-blur border border-slate-200 shadow-xl rounded-full p-1.5",children:[e.jsx("button",{type:"button",onClick:()=>o(-1),disabled:a.start,title:"×××× ×××× ×",className:`${p} text-teal-700 hover:bg-teal-50`,children:e.jsx(oa,{className:"w-5 h-5"})}),e.jsx("span",{className:"w-16 h-1.5 rounded-full bg-slate-100 overflow-hidden mx-1",children:e.jsx("span",{className:"block h-full bg-teal-500 rounded-full transition-all",style:{width:`${Math.max(12,a.pct)}%`}})}),e.jsx("button",{type:"button",onClick:()=>o(1),disabled:a.end,title:"×××× ×©××××",className:`${p} text-teal-700 hover:bg-teal-50`,children:e.jsx(lt,{className:"w-5 h-5"})})]}),document.body)]})}const lx=new Set(["num","money","dec3","dec2","pct"]),pi=typeof Intl<"u"?new Intl.Collator("he",{numeric:!0,sensitivity:"base"}):null;function rx(t,s,n){if(!(n!=null&&n.key))return t;const a=s.find(p=>p.key===n.key);if(!a)return t;const l=n.dir==="desc"?-1:1,r=lx.has(a.type),o=p=>{const u=qa(a,p);return u==null||u===""?null:r?Number(u):String(u)};return[...t].sort((p,u)=>{const d=o(p),c=o(u);return d===null&&c===null?0:d===null?1:c===null?-1:r?(d-c)*l:(pi?pi.compare(d,c):String(d).localeCompare(c,"he"))*l})}const ix=t=>t.sortable===!0||t.sortable!==!1&&!t.render;function ox({columns:t,rows:s,totals:n,sort:a,onSort:l,empty:r="××× ×¨×©×××ת ×ת××××ת ×ת ×ס×× ××"}){const o=t.filter(c=>!c.hide);if(!s.length)return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-12 text-center",children:[e.jsx(hr,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r})]});const p=n||ac(o,s),u=Object.keys(p).length>0,d=c=>`text-right${hl.has(c.type)?" tabular-nums":""}`;return e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsx(nx,{children:e.jsxs("table",{className:"w-full text-sm border-collapse",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsx("tr",{children:o.map(c=>{const m=(a==null?void 0:a.key)===c.key;if(!l||!ix(c))return e.jsx("th",{className:`px-3 py-2.5 font-semibold whitespace-nowrap ${d(c)}`,children:c.header},c.key);const h=m?a.dir==="desc"?_o:lo:jo;return e.jsx("th",{className:`px-3 py-2.5 font-semibold whitespace-nowrap ${d(c)} no-print-hover`,children:e.jsxs("button",{type:"button",onClick:()=>l(c.key),title:`×××× ××¤× ${c.header}`,className:`group inline-flex items-center gap-1 ${m?"text-teal-700":"hover:text-slate-700"}`,children:[c.header,e.jsx(h,{className:`w-3 h-3 flex-none transition-opacity ${m?"opacity-100":"opacity-25 group-hover:opacity-70"}`})]})},c.key)})})}),e.jsx("tbody",{children:s.map((c,m)=>e.jsx("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60 even:bg-slate-50/30",children:o.map(h=>
33e.jsx("td",{className:`px-3 py-2 ${d(h)} ${h.strong?"font-bold":""} ${h.muted?"text-slate-500":""} ${h.clamp?"max-w-[12rem] truncate":"whitespace-nowrap"}`,dir:hl.has(h.type)?"ltr":void 0,title:h.clamp?String(qa(h,c)??""):void 0,children:h.render?h.render(c):Fn(h,c)},h.key))},c.id||m))}),u&&e.jsx("tfoot",{children:e.jsx("tr",{className:"border-t-2 border-slate-200 bg-slate-50 font-bold",children:o.map((c,m)=>e.jsx("td",{className:`px-3 py-2.5 ${d(c)}`,dir:hl.has(c.type)?"ltr":void 0,children:m===0?`ס××´× ${Um(s.length)}`:p[c.key]===void 0?"":Fn(c,{[c.key]:p[c.key]})},c.key))})})]})})})}function cx({stats:t}){return t!=null&&t.length?e.jsx("div",{className:`grid grid-cols-2 gap-3 ${t.length>=5?"lg:grid-cols-5":"sm:grid-cols-4"}`,children:t.map(s=>{const n=s.icon;return e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4 flex items-center gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] text-slate-500 text-right truncate",children:s.label}),e.jsxs("p",{className:"text-[22px] font-black text-slate-900 tabular-nums text-right leading-tight mt-0.5",children:[e.jsx("span",{dir:"ltr",className:"inline-block",children:s.value}),s.currency&&e.jsx("span",{className:"text-[16px] font-extrabold text-slate-500",children:" âª"})]}),s.sub&&e.jsx("p",{className:"text-[11px] text-slate-400 text-right truncate",children:s.sub})]}),n&&e.jsx("div",{className:`w-11 h-11 rounded-xl flex items-center justify-center flex-none ${s.tone||"text-teal-600 bg-teal-50"}`,children:e.jsx(n,{className:"w-[22px] h-[22px]"})})]},s.label)})}):null}function ss({title:t,subtitle:s,settings:n,chips:a=[],filters:l,stats:r,columns:o,rows:p=[],totals:u,fileName:d,loading:c,empty:m,children:h,footNote:b,defaultSort:f,search:x,after:g,banner:y,hero:$,inlineFilters:O}){const A=o.map(K=>K.key).join("|"),S=`report-cols:${d||t}:${A.length}:${A.slice(0,80)}`,P=i.useCallback(()=>{try{const K=localStorage.getItem(S);if(K!==null)return new Set(JSON.parse(K))}catch{}return new Set(o.filter(K=>K.off).map(K=>K.key))},[S,o]),[E,k]=i.useState(P);i.useEffect(()=>{k(P())},[P]);const C=K=>{try{localStorage.setItem(S,JSON.stringify([...K]))}catch{}return K},w=i.useMemo(()=>o.map(K=>E.has(K.key)?{...K,hide:!0}:K),[o,E]),[_,T]=i.useState(f||null);i.useEffect(()=>{T(f||null)},[A]);const M=K=>T(Z=>(Z==null?void 0:Z.key)===K?{key:K,dir:Z.dir==="asc"?"desc":"asc"}:{key:K,dir:"asc"}),B=i.useMemo(()=>rx(p,o,_),[p,o,_]),R=K=>k(Z=>{const H=new Set(Z);return H.has(K)?H.delete(K):H.add(K),C(H)}),j=i.useMemo(()=>
33[...a.filter(Boolean),`××פק ${new Date().toLocaleDateString("he-IL")} ${new Date().toLocaleTimeString("he-IL",{hour:"2-digit",minute:"2-digit"})}`,`${p.length} רש×××ת`],[a,p.length]),q=i.useRef(null),[L,N]=i.useState(!1),v=async()=>{if(!p.length){W.error("××× × ×ª×× ×× ×××צ××");return}N(!0);try{const{exportNodePdf:K}=await In(async()=>{const{exportNodePdf:Z}=await import("./reportPdf-BRmDXPVe.js");return{exportNodePdf:Z}},__vite__mapDeps([3,1,2]));await K(q.current,d||t),W.success("×§×××¥ ×-PDF × ×צר")}catch{W.error("ש×××× ××צ×רת ×-PDF")}finally{N(!1)}},F=async()=>{if(!p.length){W.error("××× × ×ª×× ×× ×××צ××");return}try{await nc({fileName:d||t.replace(/\s+/g,"_"),sheetName:t,title:t,meta:j,columns:o,rows:B,totals:u})}catch{W.error("ש×××× ×××צ××")}};return e.jsxs("div",{id:"billing-report",ref:q,children:[e.jsx("style",{children:lc}),e.jsxs("div",{className:"min-w-0 hidden print:block mb-2",children:[e.jsx("h3",{className:"text-xl font-black text-slate-900",children:t}),s&&e.jsx("p",{className:"text-[13px] text-slate-500 mt-0.5",children:s}),e.jsxs("div",{className:"print-only mt-1 text-[11px] text-slate-500",children:[[n==null?void 0:n.legal_name,(n==null?void 0:n.business_number)&&`×.פ. ${n.business_number}`,n==null?void 0:n.address].filter(Boolean).join(" · "),e.jsx("div",{children:j.join(" · ")})]})]}),$?e.jsx("div",{className:"mb-4",children:$}):null,!c&&((r==null?void 0:r.length)>0||y)&&e.jsxs("div",{className:"space-y-4 mb-4",children:[y,e.jsx(cx,{stats:r})]}),e.jsx("div",{className:`no-print rounded-2xl border border-slate-200 bg-white shadow-sm mb-4 ${$?"p-4":"p-5"}`,children:e.jsxs("div",{className:"flex flex-wrap items-end gap-x-6 gap-y-4 no-print",children:[l,x&&e.jsx(ex,{value:x.value,placeholder:x.placeholder,onChange:x.onChange,compact:!!O}),e.jsx("span",{className:"flex items-center flex-none mr-auto gap-2",children:e.jsx(Jm,{columns:o,hidden:E,onToggleColumn:R,onAllColumns:()=>k(C(new Set)),onResetColumns:()=>{try{localStorage.removeItem(S)}catch{}k(new Set(o.filter(K=>K.off).map(K=>K.key)))},onExcel:F,onPdf:v,pdfBusy:L,hasRows:p.length>0,compact:!!O})})]})}),c?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-teal-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[h,e.jsx(ox,{columns:w,rows:B,totals:u,sort:_,onSort:M,empty:m}),g,b&&e.jsx("p",{className:"text-[11px] text-slate-400",children:b})]})]})}const bl=300,aa=async(t,s)=>{const n=await D.functions.invoke("waterImport",{...s,kibbutz_id:t});return(n==null?void 0:n.data)??n??{}},$t=t=>new Intl.NumberFormat("he-IL").format(t),Xl=t=>oo(t,"",{decimals:2}).trim(),ls=t=>t==null||t===""?"â":Number(t).toFixed(3).replace(/\.?0+$/,""),xc=t=>{if(!t)return"â";const[s,n,a]=String(t).slice(0,10).split("-");return a?`${a}/${n}/${s}`:t},hi=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"];function dx(t,s){if(!t)return"";const n=new Date(`${t}T00:00:00`),a=s?new Date(`${s}T00:00:00`):n;s&&a.getDate()===1&&a.setDate(0);const l=[hi[n.getMonth()]];return(a.getMonth()!==n.getMonth()||a.getFullYear()!==n.getFullYear())&&l.push(hi[a.getMonth()]),`${l.join("â")} ${a.getFullYear()}`}const On={draft:{label:"×××××",cls:"bg-slate-100 text-slate-600"},pending:{label:"××ת×× ×××ש×ר",cls:"bg-amber-50 text-amber-700"},approved:{label:"××שר",cls:"bg-emerald-50 text-emerald-700"},partially_approved:{label:"××שר ×××§×ת",cls:"bg-sky-50 text-sky-700"},cancelled:{label:"××××",cls:"bg-red-50 text-red-600"}},ux={ok:"bg-emerald-50 text-emerald-700",opening:"bg-sky-50 text-sky-700",no_meter:"bg-red-50 text-red-600",no_previous:"bg-amber-50 text-amber-800",regression:"bg-amber-50 text-amber-800",duplicate:"bg-purple-50 text-purple-700",invalid:"bg-red-50 text-red-600"};function vt({label:t,value:s,tone:n=""}){return e.jsxs("div",{className:"bg-white/80 border border-black/5 rounded-2xl px-3 py-2.5 text-right",children:[e.jsx("p",{className:"text-[11px] font-bold text-slate-500",children:t}),e.jsx("p",{className:`text-xl font-extrabold tracking-tight mt-0.5 tabular-nums ${n}`,children:e.jsx("span",{dir:"ltr",className:"inline-block",children:s})})]})}function mx({kibbutzId:t}){const[s,n]=i.useState("home"),[a,l]=i.useState([]),[r,o]=i.useState(""),[p,u]=i.useState(null),[d,c]=i.useState(null),m=i.useCallback(async()=>{try{const f=await aa(t,{action:"list"});l((f==null?void 0:f.batches)||[])}catch{l([])}},[t]);i.useEffect(()=>{m()},[m]);const h=f=>{u(f),n("summary")}
33,b=async f=>{o("cancel");try{await aa(t,{action:f.bill_count?"delete":"cancel",batch_id:f.id}),W.success("×××¢×× × × ×××§×"),c(null),p===f.id&&(u(null),n("home")),m()}catch(x){W.error((x==null?void 0:x.message)||"×× × ××ª× ×××××§ ×ת ×××¢×× ×"),c(null)}finally{o("")}};return s==="summary"&&p?e.jsx(px,{kibbutzId:t,batchId:p,onBack:()=>{u(null),n("home"),m()}}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"××¢×× ×ª ×§×××¥ קר×××ת ××× × ×××, ×ת××× ××ש××××, ××ש×× ××פקת ×ר×ש×ת תש×××."}),e.jsxs("button",{onClick:()=>n("wizard"),className:"h-9 px-4 rounded-full bg-sky-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(La,{className:"w-4 h-4"})," ××¢×× ×ª ×§×××¥ צר××ת ×××"]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-200 bg-slate-50/60",children:e.jsx("span",{className:"text-sm font-extrabold text-slate-800",children:"××ס××ר××ת ××¢×× ×ת"})}),a.length===0?e.jsxs("div",{className:"p-10 text-center",children:[e.jsx(Ke,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"××× ×¢×××× ××¢×× ×ת קר×××ת ×××"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"××¢× × ×§×××¥ קר×××ת ××× ×××©× ×ש××× ×ת ××× ××ש××××."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ת×ר××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"×§×××¥"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"תק×פ×"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"רש×××ת"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"×ש××× ×ת"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×××ס"}),e.jsx("th",{className:"px-4 py-2.5"})]})}),e.jsx("tbody",{children:a.map(f=>{const x=On[f.status]||On.draft;return e.jsxs("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60",children:[e.jsx("td",{className:"px-4 py-2.5 text-slate-500 whitespace-nowrap",children:xc(f.created_date)}),e.jsx("td",{className:"px-4 py-2.5 truncate max-w-[14rem]",children:f.file_name||"â"}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:f.period_name||"â"}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",dir:"ltr",children:$t(f.row_count||0)}),e.jsx("td",{className:"px-4 py-2.5 tabular-nums",dir:"ltr",children:$t(f.bill_count||0)}),e.jsx("td",{className:"px-4 py-2.5 font-bold tabular-nums",dir:"ltr",children:Xl(f.total_amount)}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${x.cls}`,children:x.label})}),e.jsxs("td",{className:"px-4 py-2.5 text-left whitespace-nowrap",children:[e.jsx("button",{onClick:()=>h(f.id),className:"h-8 px-3 rounded-full border border-slate-200 text-xs hover:bg-slate-50",children:f.status==="pending"||f.status==="draft"?"××ש×":"צפ×××"}),e.jsx("button",{onClick:()=>c(f),title:"×××קת ××¢×× ×",className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-red-500 hover:bg-red-50 mr-1",children:e.jsx(Re,{className:"w-4 h-4"})})]})]},f.id)})})]})})]}),s==="wizard"&&e.jsx(xx,{kibbutzId:t,onCancel:()=>n("home"),onLoaded:f=>{m(),h(f)}}),d&&e.jsx(No,{open:!0,onOpenChange:f=>{f||c(null)},title:d.bill_count?"×××קת ×§×××¥ ש×××¤×§× ××× × ××××××":"×××קת ××¢×× ×ª קר×××ת",description:d.bill_count?`×××קת ××§×××¥ «${d.file_name||d.peri
33od_name||""}» ת×××§ ×××ער×ת ×ת ×× ××ס×××× ×××××××× ×©×××¤×§× ××× × â ${_e(d.bill_count,"×ר×שת תש××× ××ת","×ר×ש×ת תש×××")} â ××¢××× ××ש×× ××××ר×× ××××©× ×©× ×ת×ש×××. ×××× ×× ×××××¨× ×קר××× ×©××××ª× ××¤× × ×××¢×× ×. ××× ××¨× ×ש××ר.`:`×¢×××× ×× ×××¤×§× ×ס×××× ××§×××¥ «${d.file_name||d.period_name||""}», ××××××§× ×× ×ª×©×¤××¢ ×¢× × ×ª×× ×× ××ר×× ××ער×ת. ${_e(d.row_count||0,"×ש××¨× ×©×× ×ª××××§","×ש×ר×ת ש×× ×××××§×")}.`,confirmLabel:r==="cancel"?"××××§â¦":"×××§ ××¢×× ×",destructive:!0,onConfirm:()=>b(d)})]})}function xx({kibbutzId:t,onCancel:s,onLoaded:n}){var E,k;const a=i.useRef(null),[,l]=ia(),r=()=>l({tab:"chargeTypes"}),[o,p]=i.useState(null),[u,d]=i.useState(""),[c,m]=i.useState({period_name:"",period_start:"",period_end:"",due_date:"",months:"2"}),[h,b]=i.useState(null),[f,x]=i.useState(""),[g,y]=i.useState(0),$=(C,w)=>m(_=>({..._,[C]:w}));i.useEffect(()=>{D.entities.ChargeType.filter({kibbutz_id:t},"order",300).then(C=>{const w=Vu(C||[]);p(w),w.length===1&&d(w[0].id)}).catch(()=>p([]))},[t]),i.useEffect(()=>{const C=Gu(c.period_start,c.period_end);C&&m(w=>({...w,months:String(C)}))},[c.period_start,c.period_end]);const O=async C=>{var _;const w=(_=C.target.files)==null?void 0:_[0];if(C.target.value="",!!w){x("read");try{const T=await zm(w);T.errors.length&&!T.rows.length?(W.error(T.errors[0]),b(null)):b({name:w.name,...T,summary:Wm(T.rows)})}catch{W.error("×× × ××ª× ×קר×× ×ת ××§×××¥")}finally{x("")}}},A=async()=>{var C;if((C=h==null?void 0:h.rows)!=null&&C.length){x("upload"),y(0);try{const w=await aa(t,{action:"start",charge_type_id:u,file_name:h.name,months:Number(c.months),period_name:c.period_name,period_start:c.period_start||null,period_end:c.period_end||null,due_date:c.due_date||null}),_=w==null?void 0:w.batch_id;if(!_)throw new Error("ש×××× ×פת××ת ×××¢×× ×");for(let T=0;T<h.rows.length;T+=bl)await aa(t,{action:"rows",batch_id:_,rows:h.rows.slice(T,T+bl)}),y(Math.min(100,Math.round((T+bl)/h.rows.length*100)));W.success("××§×××¥ × ××¢× ×××ש×"),n(_)}catch(w){W.error((w==null?void 0:w.message)||"ש×××× ×××¢×× ×ª ××§×××¥")}finally{x("")}}},S=!!u&&!!c.period_name.trim()&&Number(c.months)>0&&!!((E=h==null?void 0:h.rows)!=null&&E.length),P=u?c.period_name.trim()?Number(c.months)>0?(k=h==null?void 0:h.rows)!=null&&k.length?"":"×ש ××××ר ×§×××¥ קר×××ת":"×ש ××××× ×ספר ××××©× ××××":"×ש ××××× ×©× ×ª×§×פ×":"×ש ××××ר ס×× ×××× ×××";return Pt.createPortal(e.jsx("div",{dir:"rtl",className:"fixed inset-0 z-[80] bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:()=>!f&&s(),children:e.jsxs("div",{className:"billing-form bg-white rounded-2xl shadow-2xl w-full max-w-2xl flex flex-col h-[min(42rem,92vh)]",onClick:C=>C.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between px-6 pt-5 pb-3 flex-none",children:[e.jsxs("h3",{className:"text-[20px] font-black text-slate-900 flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5 text-sky-600"})," ××¢×× ×ª ×§×××¥ צר××ת ×××"]}),e.jsx("button",{onClick:s,"aria-label":"ס××ר×",className:"w-9 h-9 rounded-full border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50 flex-none",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 pb-2 space-y-4",children:o===null?e.jsx("p",{className:"text-sm text-slate-400",children:"×××¢× ×¡××× ××××â¦"}):o.length===0?e.jsxs("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900",children:[e.jsx("p",{className:"font-bold",children:"×× ××××ר ס×× ×××× ×¤×¢×× ×ס×× Â«×¦×¨××ת ××× ××¤× ×§×¨××ת ××× ×»"}),e.jsx("p",{className:"text-[13px] mt-0.5",children:"ס×× ××××× × ××©× ×ת ×תער×פ×× ××ת ××××¡× ×©×פ××× ××××©× ××ש×××, ×××× ××× × ×רש ××¤× × ×××¢×× ×."}
33),e.jsxs("button",{onClick:r,className:"mt-3 h-9 px-4 rounded-full bg-sky-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(Ke,{className:"w-4 h-4"})," ××××רת ס×× ×××× ×××"]})]}):e.jsxs(e.Fragment,{children:[o.length===1?e.jsxs("div",{className:"rounded-xl border border-sky-200 bg-sky-50/60 px-3.5 py-2.5 flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-[13px] font-black text-slate-800",children:o[0].name}),e.jsxs("span",{className:"text-[11.5px] text-slate-500",dir:"ltr",children:[Ys(o[0].water_low_rate)," / ",Ys(o[0].water_high_rate)]}),e.jsxs("span",{className:"text-[11.5px] text-slate-500",children:["×××´×§ · ",o[0].water_quota_per_soul," ××´×§ ×× ×¤×© ××××ש"]})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2.5",children:o.map(C=>e.jsxs("button",{onClick:()=>d(C.id),className:`text-right rounded-2xl border p-3 transition-colors ${u===C.id?"border-sky-400 bg-sky-50":"border-slate-200 hover:bg-slate-50"}`,children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800",children:C.name}),e.jsxs("span",{className:"block text-[11.5px] text-slate-500 mt-0.5",children:[Ys(C.water_low_rate)," / ",Ys(C.water_high_rate)," ×××´×§ · ",C.water_quota_per_soul," ××´×§ ×× ×¤×©"]})]},C.id))}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx(Q,{label:"×©× ×תק×פ×",required:!0,hint:"××פ××¢ ××ר×שת ×תש×××, ×××©× Â«××××â×××××¡× 2026»",children:e.jsx("input",{className:Se,placeholder:"××× ×©× ×ª×§×פ×",value:c.period_name,onChange:C=>m(w=>({...w,period_name:C.target.value,name_touched:!0}))})}),e.jsx(Vm,{label:"תק×פת ×××××",from:c.period_start,to:c.period_end,onChange:({from:C,to:w})=>m(_=>({..._,period_start:C,period_end:w,period_name:_.name_touched?_.period_name:dx(C,w)}))}),e.jsx(Q,{label:"×ספר ××××©× ××××",required:!0,info:"××××¡× ××××רת ×××פ×ת ××ספר ××",children:e.jsx("input",{type:"number",step:"0.5",className:Se,value:c.months,onChange:C=>$("months",C.target.value)})})]}),e.jsx("input",{ref:a,type:"file",accept:".csv,.xls,.xlsx,text/csv",className:"hidden",onChange:O}),h?e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5",children:[e.jsx(vt,{label:"ש×ר×ת ××§×××¥",value:$t(h.summary.rows)}),e.jsx(vt,{label:"××× ××",value:$t(h.summary.meters)}),e.jsx(vt,{label:"רש×××ת ×פ×××ת",value:$t(h.summary.duplicates),tone:h.summary.duplicates?"text-purple-700":""}),e.jsx(vt,{label:"ש×ר×ת ×¢× ×©××××",value:$t(h.summary.errors),tone:h.summary.errors?"text-red-600":""})]}),h.errors.map(C=>e.jsxs("div",{className:"flex gap-2 rounded-2xl border border-amber-200 bg-amber-50 p-3 text-sm text-amber-900",children:[e.jsx(At,{className:"w-5 h-5 flex-none"})," ",C]},C)),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[11.5px] text-slate-500 truncate",children:h.name}),e.jsx("button",{onClick:()=>b(null),className:"text-[11.5px] text-slate-500 underline flex-none",children:"×××רת ×§×××¥ ××ר"})]})]}):e.jsxs("button",{onClick:()=>{var C;return(C=a.current)==null?void 0:C.click()},disabled:f==="read",className:"w-full rounded-2xl border-2 border-dashed border-sky-300 bg-sky-50/40 p-8 text-center hover:bg-sky-50",children:[f==="read"?e.jsx(Ie,{className:"w-8 h-8 text-sky-500 mx-auto mb-2 animate-spin"}):e.jsx(pr,{className:"w-8 h-8 text-sky-500 mx-auto mb-2"}),e.jsx("span",{className:"block text-sm font-bold text-slate-700",children:"×××¨× ×§×××¥ קר×××ת"}),e.jsx("span",{className:"block text-xs text-slate-400 mt-1",children:"XLSX ×× CSV â ××¢××××ת ×××××ת ××¤× ×©××ת×××"})]}),f==="upload"&&e.jsx("div",{className:"h-2 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("div",{className:"h-full bg-sky-500 transition-all",style:{width:`${g}%`}})})]})}),e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 border-t border-slate-100 flex-none",children:[e.jsx("button",{onClick:A,disabled:!S||!!f,title:P,className:ts,children:f==="upload"?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"w-4 h-4 animate-spin"})," ×××¢×â¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ma,{className:"w-4 h-4"})," ××¢×× × ×××ש×ר"]})}),e.jsx("button",{onClick:s,className:$s,children:"×××××"}),P&&!f&&e.jsx("span",{className:"text-[11.5px] text-slate-400 mr-auto",children:P})]})]})}),document.body)}function px({kibbutzId:t,batchId:s,onBack:n}){const[,a]=ia(),l=()=>a({tab:"monthly",bucket:"file"}),[r,o]=i.useState(null),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState(!0),[x]=i.useState(""),[g,y]=i.useState(null),[$,O]=i.useState(null),A=i.useCallback(async()=>{f(!0);try{const[_,T,M,B]=await Promise.all([D.entities.WaterImportBatch.get(s).catch(()=>null),D.entities.WaterReading.filter({kibbutz_id:t,batch_id:s},"row_no",5e3).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.WaterMeter.filterAll({kibbutz_id:t}).catch(()=>[])]);o(_),u(T||[]),c(M||[]),h(B||[])}finally{f(!1)}},[t,s]);i.useEffect(()=>{A()},[A]);const S=i.useCallback(_=>{const T=d.find(M=>M.id===_);return T?T.name||`#${T.account_number}`:"â"},[d]),P=i.useMemo(()=>{const _=p.filter(M=>M.status===Tt.ok),T=p.filter(M=>M.status!==Tt.ok&&M.status!==Tt.opening);return{rows:p.length,ok:_.length,problem:T.length,unmatched:p.filter(M=>M.status===Tt.no_meter).length,cubic:p.reduce((M,B)=>M+(Number(B.consumption)||0),0),total:_.reduce((M,B)=>M+(Number(B.amount)||0),0),billed:p.filter(M=>M.charge_id).length}}
33,[p]),E=()=>{const _=p.filter(L=>L.status!==Tt.ok&&L.status!==Tt.opening),T=["ש×ר×","×ס׳ ××× ×","×ס׳ ×××××","×©× ×¦×¨××","×ת××ת","קר××× ××§×××¥","ס×××ס","×ער×"],M=L=>`"${String(L??"").replace(/"/g,'""')}"`,B=[T,..._.map(L=>[L.row_no,L.meter_number,L.consumer_id,L.consumer_name,L.property_address,L.current_reading,Pa[L.status]||L.status,L.status_note])].map(L=>L.map(M).join(",")).join(`\r 34`),R=new Blob([`\uFEFF${B}`],{type:"text/csv;charset=utf-8"}),j=URL.createObjectURL(R),q=document.createElement("a");q.href=j,q.download=`ש××××ת_${r.period_name||r.id}.csv`,document.body.appendChild(q),q.click(),q.remove(),setTimeout(()=>URL.revokeObjectURL(j),1e3)},k=async _=>{if(confirm(`××ס×ר ×ת ש××¨× ${_.row_no} ××××¢×× ×?`))try{await aa(t,{action:"row",reading_id:_.id,remove:!0}),W.success("×ש××¨× ××סר×"),A()}catch(T){W.error((T==null?void 0:T.message)||"ש××××")}};if(b)return e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-sky-500 rounded-full animate-spin"})});if(!r)return e.jsx("div",{className:"p-10 text-center text-sm text-slate-400",children:"×××¢×× × ×× × ×צ××"});const C=On[r.status]||On.draft,w=r.status==="approved"||r.status==="partially_approved";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h3",{className:"text-base font-extrabold flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5 text-sky-600"})," ס×××× ×ש××× ×ת ×××",e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${C.cls}`,children:C.label})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:[r.period_name,r.file_name,`${r.months} ××××©× ××××`,r.due_date?`×תש××× ×¢× ${xc(r.due_date)}`:""].filter(Boolean).join(" · ")})]}),e.jsxs("button",{onClick:n,className:"h-9 px-4 rounded-full border border-slate-200 text-sm inline-flex items-center gap-1.5 hover:bg-slate-50",children:[e.jsx(bs,{className:"w-4 h-4"})," ××ר×"]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2.5",children:[e.jsx(vt,{label:"רש×××ת",value:$t(P.rows)}),e.jsx(vt,{label:"תק×× ×ת",value:$t(P.ok),tone:"text-emerald-700"}),e.jsx(vt,{label:"××רש×ת ××××§×",value:$t(P.problem),tone:P.problem?"text-amber-700":""}),e.jsx(vt,{label:"××× ××× ×",value:$t(P.unmatched),tone:P.unmatched?"text-red-600":""}),e.jsx(vt,{label:"ס××´× ××´×§",value:ls(P.cubic)}),e.jsx(vt,{label:"ס××´× ×××××",value:Xl(P.total)})]}),P.problem>0&&!w&&e.jsxs("div",{className:"flex gap-3 rounded-2xl border border-amber-200 bg-amber-50 p-3.5 text-sm text-amber-900",children:[e.jsx(At,{className:"w-5 h-5 flex-none mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold",children:_e(P.problem,"ש××¨× ××ת ×× ×ª××××","ש×ר×ת ×× ××××××")}),e.jsx("p",{className:"text-[13px] mt-0.5",children:"× ××ª× ××שר ×ת ×ש×ר×ת ×תק×× ×ת ×¢×ש××, ××××¤× ×ש×ר ×××ר ××× â ××ש×ר ×××ר ×פ××§ רק ×ת ×× ×©××¨× ××××."}),e.jsxs("button",{onClick:E,className:"mt-2 h-8 px-3 rounded-full bg-white border border-amber-300 text-xs inline-flex items-center gap-1.5",children:[e.jsx(ro,{className:"w-3.5 h-3.5"})," ××ר×ת ××× ×ש×ר×ת ש×× ×××××"]})]})]}),e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"#"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"×ש××× ×ש××"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"××× ×"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"×ת××ת"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"×§×××ת"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"× ××××ת"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"צר×××"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"× ×¤×©×ת"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"××ס×"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"× ×××/××××"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"ס×××"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"ס×××ס"}),e.jsx("th",{className:"px-3 py-2.5"})]})}),e.jsx("tbody",{children:p.map(_=>e.jsxs(he.Fragment,{children:[e.jsxs("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60",children:[e.jsx("td",{className:"px-3 py-2 text-slate-400 tabular-nums",dir:"ltr",children:_.row_no}),e.jsx("td",{className:"px-3 py-2 font-medium",children:_.payer_account_id?S(_.payer_account_id):e.jsx("span",{className:"text-slate-400",children:_.consumer_name||"â"})}),e.jsx("td",{className:"px-3 py-2 text-slate-600 tabular-nums",dir:"ltr",children:_.meter_number||"â"}),e.jsx("td",{className:"px-3 py-2 text-slate-500 truncate max-w-[10rem]",children:_.property_address||"â"}),e.jsx("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:ls(_.previous_reading)}),e.jsx("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:ls(_.current_reading)}),e.jsx("td",{className:"px-3 py-2 tabular-nums font-semibold",dir:"ltr",children:ls(_.consumption)}),e.jsxs("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:[_.souls_used??"â",_.eligible_used?`+${_.eligible_used}`:""]}),e.jsx("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:ls(_.quota_total)}),e.jsxs("td",{className:"px-3 py-2 tabular-nums text-xs text-slate-500",dir:"ltr",children:[ls(_.low_consumption)," / ",ls(_.high_consumption)]}),e.jsx("td",{className:"px-3 py-2 font-bold tabular-nums",dir:"ltr",children:_.amount==null?"â":Xl(_.amount)}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full whitespace-nowrap ${ux[_.status]||"bg-slate-100 text-slate-600"}`,title:_.status_note||"",children:Pa[_.status]||_.status}),_.charge_id&&e.jsx("span",{className:"block text-[10px] text-emerald-600 mt-0.5",children:"×××¤×§× ×ר×שת תש×××"})]}),e.jsxs("td",{className:"px-3 py-2 text-left whitespace-nowrap",children:[_.breakdown&&e.jsx("button",{onClick:()=>O($===_.id?null:_.id),title:"פ×ר×× ××ש××",className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(Ma,{className:"w-4 h-4"})}),!_.charge_id&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>y(_),title:"ער××× / ש×××",className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(It,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>k(_),title:"×סרת ש×ר×",className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})]})]})]}),$===_.id&&_.breakdown&&e.jsx("tr",{className:"bg-slate-50/70",children:e.jsx("td",{colSpan:13,className:"px-4 py-3",children:e.jsx("div",{className:"max-w-xl",children:e.jsx(dr,{b:_.breakdown})})})}),_.status_note&&_.status!==Tt.ok&&e.jsx("tr",{className:"bg-amber-50/40",children:e.jsxs("td",{colSpan:13,className:"px-4 py-1.5 text-[12px] text-amber-800",children:["ש××¨× ",_.row_no,": ",_.status_note]})})]},_.id))})]})})}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[P.ok>0?e.jsxs("button",{onClick:l,disabled:!!x,className:ts,children:[e.jsx(Be,{className:"w-4 h-4"})," ××ש×ר ×××¢×ר ××פקת ××××××"]}):e.jsxs("button",{onClick:n,className:$s,children:[e.jsx(bs,{className:"w-4 h-4"})," ×××¨× ×רש××ת ×××¢×× ×ת"]}),P.billed>0&&e.jsxs("span",{className:"text-xs font-bold text-emerald-700 inline-flex items-center gap-1.5 bg-emerald-50 border border-emerald-200 rounded-full px-3 py-1.5",children:[e.jsx(Rc,{className:"w-4 h-4"})," ×××¤×§× ",_e(P.billed,"×ר×שת תש××× ××ת","×ר×ש×ת תש×××")," ×××¢×× × ××"]})]}),g&&e.jsx(pc,{kibbutzId:t,row:g,meters:m,accounts:d,onClose:()=>y(null),onSaved:()=>{y(null),A()}})]})}function pc({kibbutzId:t,row:s,meters:n,accounts:a,onClose:l,onSaved:r}){const[,o]=ia(),p=A=>n.find(S=>S.id===A)||null,u=(A,S)=>A==null||A===""?S??"":String(A),d=p(s.water_meter_id),[c,m]=i.useState({water_meter_id:s.water_meter_id||"",previous_reading:s.previous_reading??(d==null?void 0:d.previous_reading)??"",previous_reading_date:s.previous_reading_date||(d==null?void 0:d.previous_reading_date)||"",current_reading:s.current_reading??"",souls:u(s.souls_used,d==null?void 0:d.souls),eligible_count:u(s.eligible_used,d==null?void 0:d.eligible_count),mark_opening:!1}),[h,b]=i.useState(!1),f=(A,S)=>m(P=>({...P,[A]:S})),x=A=>{const S=a.find(P=>P.id===A);return S?S.name||`#${S.account_number}`:"××× ×ש×××"},g=p(c.water_meter_id),y=g?a.find(A=>A.id===g.payer_account_id):a.find(A=>A.id===s.payer_account_id)||null,$=()=>o(y!=null&&y.id?{tab:"accounts",account:y.id}:{tab:"accounts"});i.useEffect(()=>{g&&m(A=>({...A,previous_reading:A.previous_reading===""?u(g.previous_reading):A.previous_reading,previous_reading_date:A.previous_reading_date||g.previous_reading_date||"",souls:A.s
34ouls===""?u(g.souls):A.souls,eligible_count:A.eligible_count===""?u(g.eligible_count):A.eligible_count}))},[c.water_meter_id]);const O=async()=>{b(!0);try{const A=await aa(t,{action:"row",reading_id:s.id,water_meter_id:c.water_meter_id||void 0,previous_reading:c.previous_reading===""?void 0:c.previous_reading,previous_reading_date:c.previous_reading_date||void 0,current_reading:c.current_reading===""?void 0:c.current_reading,mark_opening:c.mark_opening});W.success(Pa[A==null?void 0:A.status]||"×ש××¨× ×¢×××× ×"),r()}catch(A){W.error((A==null?void 0:A.message)||"ש×××× ××¢×××× ×ש×ר×")}finally{b(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-4",onClick:l,children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-xl w-full max-w-2xl p-5 billing-form",onClick:A=>A.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-base font-bold",children:["ש××¨× ",s.row_no," · ××× × ",s.meter_number||"â"]}),e.jsx("button",{onClick:l,className:"w-8 h-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-slate-500 mb-3",children:[s.consumer_name,s.property_address,s.status_note].filter(Boolean).join(" · ")}),(y||g)&&e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50/70 px-3 py-2 mb-4 flex items-center gap-x-4 gap-y-1 flex-wrap text-[12px]",children:[y&&e.jsxs("span",{className:"font-bold text-slate-800",children:[y.name||`#${y.account_number}`,y.account_number?e.jsxs("span",{className:"text-slate-400 font-normal",children:[" · ×ש××× ",y.account_number]}):null]}),g&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-slate-500",children:["× ×¤×©×ת ×××× ×: ",e.jsx("b",{className:"text-slate-800",children:g.souls??"â"})]}),e.jsxs("span",{className:"text-slate-500",children:["×××××: ",e.jsx("b",{className:"text-slate-800",children:g.eligible_count??0})]}),e.jsxs("span",{className:"text-slate-500",children:["קר××× ×§×××ת: ",e.jsx("b",{className:"text-slate-800",dir:"ltr",children:g.previous_reading??"â"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(Q,{label:"ש××× ×××× ×",info:"×ש××× × ×©×ר ×¢× ×××× ×, ×× ×©×××¢×× × ×××× ××ת××× ×ª×ª×צע ×××××××ת",children:e.jsxs("select",{className:Se,value:c.water_meter_id,onChange:A=>f("water_meter_id",A.target.value),children:[e.jsx("option",{value:"",children:"â ×××¨× ××× × â"}),n.map(A=>e.jsxs("option",{value:A.id,children:[A.meter_number," · ",x(A.payer_account_id),A.status==="inactive"?" (×× ×¤×¢××)":""]},A.id))]})}),e.jsx(Q,{label:"קר××× × ××××ת (××´×§)",children:e.jsx("input",{type:"number",step:"0.001",className:Se,value:c.current_reading,onChange:A=>f("current_reading",A.target.value)})}),e.jsx(Q,{label:"קר××× ×§×××ת (××´×§)",info:"×××× × ×©××× ×× ×§×¨××× ×§×××ת â ×××× × ×××ª× ×××, ×× ×¡×× × ×ת ×קר××× ×× ××××ת ×קר××ת פת×××",children:e.jsx("input",{type:"number",step:"0.001",className:Se,value:c.previous_reading,onChange:A=>f("previous_reading",A.target.value),disabled:c.mark_opening})}),e.jsx(Q,{label:"ת×ר×× ×§×¨××× ×§×××ת",children:e.jsx("input",{type:"date",className:Se,value:c.previous_reading_date,onChange:A=>f("previous_reading_date",A.target.value),disabled:c.mark_opening})}),e.jsx(Q,{label:"× ×¤×©×ת ×××ש××",hint:"×ת×× ×ש××× ××ש××",children:e.jsx("p",{className:`${Se} bg-slate-50 flex items-center font-black text-emerald-700 tabular-nums`,children:c.souls===""?"â":c.souls})}),e.jsx(Q,{label:"×ספר ×××××",hint:"×ת×× ×ש××× ××ש××",children:e.jsx("p",{className:`${Se} bg-slate-50 flex items-center font-black text-amber-600 tabular-nums`,children:c.eligible_count===""?"0":c.eligible_count})})]}),e.jsxs("p",{className:"text-[12px] text-slate-500 mt-3",children:["×ש×× ×× ×ספר ×× ×¤×©×ת ×××××××"," ",e.jsx("button",{type:"button",onClick:$,className:"font-bold text-sky-700 underline decoration-sky-300 underline-offset-4 hover:text-sky-900",children:"×¢××¨× ××ש××× ××ש××"}),y!=null&&y.name?` â ${y.name}`:"",". ×ש×× ×× ×× ×¢× ×× ×ש××× ×ת ×××× ×©× ×שק ×××ת, ××× ×¢× ×ש××¨× ×××ת ××××."]}),e.jsxs("button",{type:"button",onClick:()=>f("mark_opening",!c.mark_opening),className:`flex items-center gap-2 h-11 px-3 mt-4 w-full rounded-xl border text-sm ${c.mark_opening?"border-sky-300 bg-sky-50 text-sky-800":"border-slate-200 text-slate-600"}`,children:[e.jsx("span",{className:`w-4 h-4 rounded-full flex items-center justify-center ${c.mark_opening?"bg-sky-600":"bg-slate-200"}`,children:c.mark_opening&&e.jsx(ye,{className:"w-3 h-3 text-white"})}),e.jsx("span",{className:"flex-1 text-right",children:"ש××ר ×קר××ת פת××× â ××× ×ר×שת תש×××, תש×ש ×קר××× ×§×××ת ×××¢×× × ××××"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-5",children:[e.jsxs("button",{onClick:O,disabled:h,className:ts,children:[e.jsx(ye,{className:"w-4 h-4"})," ",h?"ש××רâ¦":"ש××ר ×××©× ×××ש"]}),e.jsx("button",{onClick:l,className:$s,children:"×××××"})]})]})})}const Ln=t=>ve(t),Vs=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),hx=t=>{if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const n=a=>String(a).padStart(2,"0");return`${n(s.getDate())}/${n(s.getMonth()+1)}/${s.getFullYear()}, ${n(s.getHours())}:${n(s.getMinutes())}`},fa=t=>{const[s,n,a]=String(t||"").slice(0,10).split("-");return a?`${a}/${n}/${s}`:"â"},hc=t=>{const s=t==null?void 0:t.produced;
34if(!s)return"×××ש×ר × ×¨×©×";if(s.status==="ok"){const n=Number(s.charges)||0;return n===1?"×××ש×ר × ×¨×©× Â· ×××¤×§× ×ר×שת תש××× ××ת":`×××ש×ר × ×¨×©× Â· ×××¤×§× ${Vs(n)} ×ר×ש×ת תש××× Â· ${Ln(s.total)}`}return`×××ש×ר × ×¨×©× Â· ${s.reason_label||"×××¤×§× ×ª×ª×צע ××××¢× ×©× ×§××¢"}`},bx={auto:Mt,manual:Ns,file:Ke,paused:Pd},fx={auto:"text-emerald-600 bg-emerald-50 border-emerald-200",manual:"text-indigo-600 bg-indigo-50 border-indigo-200",file:"text-sky-600 bg-sky-50 border-sky-200",paused:"text-amber-600 bg-amber-50 border-amber-200"};function bc({kibbutzId:t}){const[s,n]=i.useState(null),[a,l]=i.useState([]),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState(!0),[x,g]=i.useState(null),[y,$]=i.useState(null),[O,A]=i.useState(""),[S]=ia(),P=S.get("bucket"),[E,k]=i.useState(null),[C,w]=i.useState(()=>cl.some(N=>N.v===P)?P:"auto"),_=i.useCallback(async()=>{f(!0);try{const[N,v,F,K,Z,H]=await Promise.all([D.functions.invoke("recurringBilling",{action:"status",community_id:t}).catch(()=>null),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me}).catch(()=>[]),D.entities.Property.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.WaterImportBatch.filterAll({kibbutz_id:t}).catch(()=>[])]);n((N==null?void 0:N.data)||null),l((v||[]).filter(z=>z.is_active!==!1)),o(F||[]),u(K||[]),c(Z||[]),h(H||[])}catch{W.error("ש×××× ×××¢×× ×")}finally{f(!1)}},[t]);i.useEffect(()=>{_()},[_]);const T=async(N,v)=>{A(N.charge_type_id||"run");try{const F=await D.functions.invoke("recurringBilling",{community_id:t,...N});return v&&W.success(typeof v=="function"?v(F==null?void 0:F.data):v),g(null),await _(),F==null?void 0:F.data}catch{return W.error("ש×××× ×פע×××"),null}finally{A("")}},M=async N=>{var z;
34const v=x,F=ze(v)?"××××ר×ת ×¢×××× ×":N.activation_mode==="auto"?"×××¤×§× ××××××××ת ××פע××":"ס×× ××××× ×××¤×¢× ××××× ××××",K=v._batch||R.get(v.id);if(!await T({action:"activate",charge_type_id:v.id,...N,activated_batch_id:Xt(v)&&(K==null?void 0:K.id)||null},F))return;const H=K;if(!(!Xt(v)||N.issue_timing!=="now"||!H||H.bill_count))try{const te=await D.functions.invoke("waterImport",{action:"approve",community_id:t,batch_id:H.id,due_date:N.last_due_date||null}),ie=Number(((z=te==null?void 0:te.data)==null?void 0:z.created)||0);W.success(ie===1?"×××¤×§× ×ר×שת תש××× ××ת":`×××¤×§× ${Vs(ie)} ×ר×ש×ת תש×××`),await _()}catch{W.error("××××ר×ת × ×©×ר×, ×× ×פקת ××××××× ×××§×××¥ × ×ש××")}},B=i.useMemo(()=>{const N=new Map;return(m||[]).forEach(v=>{!v.charge_type_id||v.status==="cancelled"||(N.has(v.charge_type_id)||N.set(v.charge_type_id,[]),N.get(v.charge_type_id).push(v))}),N.forEach(v=>v.sort((F,K)=>String(K.created_date||"").localeCompare(String(F.created_date||"")))),N},[m]),R=i.useMemo(()=>{const N=new Map;return B.forEach((v,F)=>N.set(F,v[0])),N},[B]),j=i.useMemo(()=>{const N=new Map(((s==null?void 0:s.types)||[]).map(F=>[F.id,F])),v=[];return(a||[]).forEach(F=>{const K=N.get(F.id)||{},Z=Xt(F);(Z?B.get(F.id)||[null]:[null]).forEach(z=>{const te=Z?!!ze(F)&&!!z&&F.activated_batch_id===z.id:ym(F,null),ie=!!(z!=null&&z.bill_count),V=te?F:{...F,activation_mode:null,auto_billing_enabled:!1,issue_timing:null,demand_issue_date:null,charge_issue_date:null,last_due_date:null},Y=ze(V)||(Z&&ie?ze(F):null),J=ai(Z?{activated:te||ie,billed:ie,demandDate:ie?z==null?void 0:z.approved_at:F.demand_issue_date,chargeDate:te?F.charge_issue_date:null,lastDueDate:(te?F.last_due_date:null)||(z==null?void 0:z.due_date)||null,kind:"file"}:{activated:!!Y,billed:!!K.billed_this_period,demandDate:K.next_issue||F.demand_issue_date,chargeDate:K.next_due||F.charge_issue_date,kind:Y==="auto"?"auto":"manual",approvals:K.approvals||null,needsApproval:!!F.requires_manager_approval});v.push({...V,accounts:Z?(z==null?void 0:z.bill_count)||(z==null?void 0:z.row_count)||null:K.accounts??null,forecast:Z?(z==null?void 0:z.total_amount)??null:K.forecast??null,next_issue:K.next_issue||"",next_due:K.next_due||"",billed_this_period:!!K.billed_this_period,due_now:!!K.due_now,due_day:K.due_day??F.due_day??null,_schedulable:!!K.id,_key:z?`${F.id}|${z.id}`:F.id,_mode:Y,_live:te,_approvals:K.approvals||{},_needsApproval:!!F.requires_manager_approval,_canActivate:Z?!te&&!ie:!ze(F),_bucket:gm(V),_status:Y?km(J):_m(V),_steps:Y?J:null,_issued:Z?ie:!!K.billed_this_period,_caption:Z?(z==null?void 0:z.period_name)||"":`×××× ${ui[F.billing_cycle]||""}`.trim(),_batch:z||null,_batchDue:(z==null?void 0:z.due_date)||null})})}),v},[a,s,B]),q=i.useMemo(()=>{const N={auto:0,manual:0,file:0,paused:0};return j.forEach(v=>{(v._bucket!=="file"||v._batch)&&(N[v._bucket]+=1)}),N},[j]);i.useEffect(()=>{if(b||q[C]||P)return;const N=cl.map(v=>v.v).find(v=>q[v]);N&&w(N)},[b,q,C,P]);const L=j.filter(N=>N._bucket===C&&!(N._bucket==="file"&&!N._batch));return b?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-emerald-500 rounded-full animate-spin"})}):j.length?e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2.5 mb-4",children:cl.map(N=>{const v=bx[N.v],F=C===N.v;return e.jsxs("button",{type:"button",onClick:()=>w(N.v),"aria-pressed":F,className:`rounded-2xl border bg-white p-3.5 text-right transition-all ${F?"border-slate-800 shadow-md":"border-slate-200 hover:border-slate-300 shadow-sm"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:`text-[26px] font-black tabular-nums leading-none ${q[N.v]?"text-slate-900":"text-slate-300"}`,children:Vs(q[N.v])}),e.jsx("span",{className:`w-10 h-10 rounded-xl grid place-items-center flex-none border ${fx[N.v]}`,children:e.jsx(v,{className:"w-5 h-5"})})]}),e.jsx("p",{className:"text-[13px] font-bold text-slate-700 mt-2",children:N.l}),e.jsx("p",{className:"text-[11px] text-slate-400 leading-snug",children:N.hint})]},N.v)})}),e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"ס×× ××××"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"××××ר"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"ש××ת ××ש××"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"×××¢×××"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"×ש××× ×ת"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"×¦×¤× ××× ×¡×ת"}),e.jsx("th",{className:"text-right px-4 py-3 font-semibold",children:"ס×××ס"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsxs("tbody",{children:[L.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-4 py-10 text-center text-[13px] text-slate-400",children:"××× ×¡××× ×××× ×××××¨× ×××ת."})}),L.map(N=>{var v,F,K,Z,H;return e.jsxs(he.Fragment,{children:[e.jsxs("tr",{className:`border-t border-slate-100 align-middle ${N._batch?"cursor-pointer hover:bg-slate-50":"hover:bg-slate-50/60"}`,onClick:N._batch?()=>k(z=>z===N._key?null:N._key):void 0,children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("span",{className:"font-bold text-slate-800 inline-flex items-center gap-1.5",children:[N._batch&&e.jsx(Jt,{className:`w-4 h-4 text-slate-400 transition-transform ${E===N._key?"":"-rotate-90"}`}),N.name]}),N.billed_this_period&&e.jsxs("span",{className:"block text-[11px] text-emerald-700 font-bold",children:["×××× ××ר ×תק××¤× ",s==null?void 0:s.period]})]}),e.jsx("td",{className:"px-4 py-3 text-slate-600",children:ui[N.billing_cycle]||N.billing_cycle}),e.jsx("td",{className:"px-4 py-3 text-slate-500",children:Dm(N.calculation_method)}),e.jsx("td",{className:"px-4 py-3 text-slate-600 text-[12.5px] whitespace-nowrap",children:e.jsx(yx,{row:N})}),e.jsx("td",{className:"px-4 py-3 tabular-nums",children:N.accounts===null?e.jsx("span",{className:"text-slate-300",children:"â"}):Vs(N.accounts)}),e.jsx("td",{className:"px-4 py-3 tabular-nums font-bold",dir:"ltr",children:N.forecast===null?e.jsx("span",{className:"text-slate-300",children:"â"}):Ln(N.forecast)}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:`text-[11.5px] font-bold px-2.5 py-1 rounded-full border ${jm[N._status]||"bg-slate-100 text-slate-500 border-slate-200"}`,children:N._status}),N._mode&&e.jsx("span",{className:`text-[11px] font-bold px-2 py-0.5 rounded-full border ${N._mode==="auto"?"bg-emerald-50 text-emerald-700 border-emerald-200":"bg-indigo-50 text-indigo-700 border-indigo-200"}`,children:N._mode==="auto"?"×××××××":N.issue_timing==="scheduled"?"×ת××××":"××××"})]}),N._mode&&!N._steps&&!N._note&&e.jsx("ul",{className:"mt-1.5 space-y-0.5",children:ec({mode:N._mode,document_kind:N.document_kind,timing:N.issue_timing,demand_issue_day:N.demand_issue_day,charge_issue_day:N.charge_issue_day,demand_issue_date:N.demand_issue_date||N.next_issue||null,charge_issue_date:N.charge_issue_date||N.next_due||null,last_due_date:N.last_due_date,requires_manager_approval:N.requires_manager_approval},{file:N._bucket==="file"}).slice(0,-1).map(z=>e.jsxs("li",{className:"text-[11.5px] text-slate-500 leading-snug flex items-start gap-1",children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-slate-300 flex-none mt-1.5"})," ",z]},z))})]}),e.jsx("td",{className:"px-4 py-3 text-left whitespace-nowrap",onClick:z=>z.stopPropagation(),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[N.due_now&&N._mode&&e.jsxs("button",{type:"button",disabled:!!O,onClick:()=>T({action:"run",charge_type_ids:[N.id]},z=>`×××¤×§× ${Vs((z==null?void 0:z.charges)||0)} ×××××× Â· ${Ln((z==null?void 0:z.total)||0)}`),className:"h-8 px-3 rounded-full bg-blue-600 text-white text-[12px] font-bold inline-flex items-center gap-1 hover:bg-blue-700 disabled:opacity-50",children:[O===N.id?e.jsx(Ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Ns,{className:"w-3.5 h-3.5"})," ×פק ×¢×ש××"]}),N._needsApproval&&N._live&&!((v=N._approvals)!=null&&v.demand)&&e.jsxs("button",{type:"button",disabled:!!O,onClick:()=>$({row:N,stage:"demand"}),className:`h-8 px-3 rounded-full bg-amber-500 text-white text-[12px] font-bold 35 inline-flex items-center gap-1.5 hover:bg-amber-600 disabled:opacity-50`,children:[e.jsx(xt,{className:"w-3.5 h-3.5"})," ××ש×ר ×ר×שת תש×××"]}),N._needsApproval&&N._live&&((F=N._approvals)==null?void 0:F.demand)&&!((K=N._approvals)!=null&&K.charge)&&e.jsxs("button",{type:"button",disabled:!!O,onClick:()=>$({row:N,stage:"charge"}),className:`h-8 px-3 rounded-full bg-amber-500 text-white text-[12px] font-bold 36 inline-flex items-center gap-1.5 hover:bg-amber-600 disabled:opacity-50`,children:[e.jsx(xt,{className:"w-3.5 h-3.5"})," ××ש×ר ×××× ××ס×× ×ª×©×××"]}),N._canActivate?e.jsxs("button",{type:"button",onClick:()=>g(N),disabled:!!O,className:"h-8 px-3 rounded-full text-[12px] font-bold inline-flex items-center gap-1.5 disabled:opacity-50 bg-emerald-600 text-white hover:bg-emerald-700",children:[e.jsx(vo,{className:"w-3.5 h-3.5"})," × ×××× ××××××"]}):N._live&&!N._issued?e.jsxs("button",{type:"button",onClick:()=>g(N),disabled:!!O,className:`h-8 px-3 rounded-full border border-slate-200 bg-white text-[12px] font-bold text-slate-600 37 inline-flex items-center gap-1.5 hover:border-emerald-300 hover:text-emerald-700 disabled:opacity-50`,children:[e.jsx(It,{className:"w-3.5 h-3.5"})," ער×××"]}
37):N._live?null:e.jsx("span",{className:"text-[11.5px] text-slate-400",children:"××××ר ×§×××"}),N._mode&&N._live&&e.jsx("button",{type:"button",disabled:!!O,onClick:()=>T({action:"disable",charge_type_id:N.id},"ס×× ××××× ××ש××"),title:"×ש×××","aria-label":"×ש×××",className:"w-8 h-8 rounded-full border border-slate-200 bg-white grid place-items-center text-slate-400 hover:text-amber-600 hover:border-amber-200 disabled:opacity-50",children:e.jsx(ho,{className:"w-3.5 h-3.5"})})]})})]}),N._steps&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"rounded-2xl border border-slate-200/70 bg-slate-50 px-6 py-5",children:[e.jsx(gx,{steps:N._steps,caption:N._caption}),(((Z=N._approvals)==null?void 0:Z.demand)||((H=N._approvals)==null?void 0:H.charge))&&e.jsx("ul",{className:"mt-4 pt-3 border-t border-slate-200/70 flex flex-wrap items-center justify-center gap-x-6 gap-y-1",children:[["demand","×ר×שת ×תש×××"],["charge","××××× ××ס×× ×תש×××"]].map(([z,te])=>{var ie;return(ie=N._approvals)!=null&&ie[z]?e.jsxs("li",{className:"text-[12px] text-slate-500 inline-flex items-center gap-1.5",children:[e.jsx(xt,{className:"w-3.5 h-3.5 text-emerald-600 flex-none"}),te," ×××©×¨× ×¢× ××× ",e.jsx("b",{className:"text-slate-700",children:N._approvals[z].by||"×× ××"}),e.jsx("span",{dir:"ltr",className:"tabular-nums",children:hx(N._approvals[z].at)})]},z):null})})]})})}),E===N._key&&N._batch&&e.jsx("tr",{className:"bg-slate-50/60",children:e.jsx("td",{colSpan:8,className:"px-4 py-3",children:e.jsx(_x,{kibbutzId:t,batch:N._batch,locked:!!N._batch.bill_count,onChanged:_})})})]},N._key)})]})]})}),C==="file"&&e.jsxs("p",{className:"text-[11.5px] text-slate-400 mt-3 flex items-start gap-1.5",children:[e.jsx(Ke,{className:"w-3.5 h-3.5 flex-none mt-0.5"}),"×××× ××§×××¥ × ×צר ×¢× ××ש×ר ××§×××¥, ××¤× ×××¢× ×תש××× ×©× ×§××¢ ×××¢×× ×. ××× ×× ××××ר ×§×××¢ â ××§×××¥ ××××¢ ××ת×××× ××× ××¤× ××× ×©× × â ××ת×× ×××××ר ××× × ×©×ר ××× ×ס×××ס «×סת×××»."]}),y&&e.jsx(tc,{row:y.row,stage:y.stage,period:s==null?void 0:s.period,busy:O===y.row.id,onClose:()=>$(null),onConfirm:N=>T({action:"approve_cycle",charge_type_id:y.row.id,stage:y.stage,period:s==null?void 0:s.period,note:N},hc).then(()=>$(null))}),x&&e.jsx(Mm,{type:x,accounts:r,residents:p,properties:d,busy:O===x.id,onClose:()=>g(null),onSave:M})]}):e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-12 text-center",children:[e.jsx(Xe,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"××× ×¢×××× ×¡××× ××××"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-md mx-auto",children:"×××××¨× ×¡×× ×××× ×××¡× Â«×¡××× ××××××», ×××× ××פ××¢ ××× ××ש×× â ×××× ××פע×× ××××× ×× ×××××××ת."})]})}const bi={done:{dot:"bg-emerald-500 border-emerald-500",line:"bg-emerald-500",text:"text-emerald-700"},now:{dot:"bg-indigo-600 border-indigo-600 ring-4 ring-indigo-100",line:"bg-indigo-500",text:"text-slate-900"},waiting:{dot:"bg-amber-500 border-amber-500 ring-4 ring-amber-100",line:"bg-slate-200",text:"text-amber-700"},blocked:{dot:"bg-white border-amber-400",line:"bg-slate-200",text:"text-amber-700"},next:{dot:"bg-white border-slate-300",line:"bg-slate-200",text:"text-slate-400"}},fi=t=>t.done?t.at?"now":"done":t.awaiting?"waiting":t.blocked?"blocked":t.at?"now":"next";function gx({steps:t=[],caption:s=""}){const n=t.length?100/t.length/2:0;return e.jsxs("div",{className:"relative w-full",children:[e.jsx("div",{className:"absolute top-[12px] h-1 flex overflow-hidden rounded-full",style:{insetInlineStart:`${n}%`,insetInlineEnd:`${n}%`},"aria-hidden":"true",children:t.slice(0,-1).map(a=>e.jsx("span",{className:`flex-1 ${bi[fi(a)].line}`},a.v))}),e.jsx("ol",{className:"relative flex items-start w-full","aria-label":"ש××× ×××××ר",children:t.map(a=>{var o;const l=fi(a),r=bi[l];return e.jsxs("li",{className:"flex-1 min-w-0 flex flex-col items-center",children:[e.jsx("div",{className:"h-7 grid place-items-center",children:e.jsxs("span",{className:`grid place-items-center flex-none rounded-full border-2 ${r.dot} ${l==="next"?"w-4 h-4":"w-7 h-7"}`,children:[(l==="done"||l==="now")&&e.jsx(ye,{className:"w-3.5 h-3.5 text-white",strokeWidth:3}),l==="waiting"&&e.jsx(xt,{className:"w-3.5 h-3.5 text-white",strokeWidth:2.5}),l==="blocked"&&e.jsx(xt,{className:"w-3.5 h-3.5 text-amber-500",strokeWidth:2.5})]})}),e.jsx("p",{className:`text-[15px] leading-tight mt-2.5 text-center px-1 ${a.at?"font-black":"font-bold"} ${r.text}`,children:a.l}),a.date&&e.jsx("p",{className:"text-[14px] font-bold text-slate-500 tabular-nums mt-1.5",dir:"ltr",children:xn(a.date)}),(a.awaiting||a.blocked)&&e.jsx("p",{className:`text-[12px] font-bold mt-1 text-center ${r.text}`,children:a.awaiting?"××שר · ××ת×× ××פק×":"××ת×× ×××ש×ר ×× ××"}),a.v===((o=t[0])==null?void 0:o.v)&&s&&e.jsx("p",{className:"text-[12.5px] text-slate-400 mt-1 text-center",children:s})]},a.v)})})]})}function yx({row:t}){if(t._bucket==="file"){const s=t._batch;return s?e.jsxs("span",{children:[s.period_name||fa(s.created_date),s.due_date?e.jsxs(e.Fragment,{children:[" · תש××× ",e.jsx("b",{className:"text-slate-800",children:fa(s.due_date)})]}):null]}):e.jsx("span",{className:"text-slate-300",children:"××¨× × ××¢× ×§×××¥"})}return t._mode?t._bucket==="auto"?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-emerald-600 flex-none"}),"××¤×§× ",e.jsx("b",{className:"text-slate-800",children:t.next_issue?fa(t.next_issue):`×-${t.demand_issue_day||t.due_day||"â"}`}),e.jsx("span",{className:"text-slate-300",children:"·"}),"×××× ",e.jsx("b",{className:"text-slate-800",children:t.next_due?fa(t.next_due):`×-${t.charge_issue_day||t.due_day||"â"}`})]}):t.issue_timing!=="scheduled"?e.jsx("span",{className:"text-slate-500",children:"××פע××"}):e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-indigo-500 flex-none"}),t.charge_issue_date?e.jsxs(e.Fragment,{children:["×××× ",e.jsx("b",{className:"text-slate-800",children:fa(t.charge_issue_date)})]}):"×ת××××",t.requires_manager_approval?" · ××רש ××ש×ר ×× ××":""]}):e.jsx("span",{className:"text-slate-300",children:"â"})}function _x({kibbutzId:t,batch:s,locked:n,onChanged:a}){const[l,r]=i.useState(null),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState(null),[h,b]=i.useState(null),f=i.useCallback(()=>{Promise.all([D.entities.WaterReading.filterAll({kibbutz_id:t,batch_id:s.id}).catch(()=>[]),D.entities.WaterMeter.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[])]).then(([S,P,E])=>{r((S||[]).slice().sort((k,C)=>(k.row_no||0)-(C.row_no||0))),p(P||[]),d(E||[])})},[t,s.id]);if(i.useEffect(()=>{f()},[f]),l===null)return e.jsx("p",{className:"text-[12.5px] text-slate-400 py-2",children:"×××¢× ×ת ש×ר×ת ××§×××¥â¦"});if(!l.length)return e.jsx("p",{className:"text-[12.5px] text-slate-400 py-2",children:"××× ×©×ר×ת ×××¢×× × ×××ת."});const x=new Map(o.map(S=>[S.id,S])),g=new Map(u.map(S=>[S.id,S])),y=S=>{var P;return((P=g.get(S))==null?void 0:P.name)||""},$=S=>{var P;return S.souls_used??((P=x.get(S.water_meter_id))==null?void 0:P.souls)??null},O=S=>{var P;return S.eligible_used??((P=x.get(S.water_meter_id))==null?void 0:P.eligible_count)??null},A=S=>S==null||S===""?"â":S;return e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-slate-100 flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-[12.5px] font-black text-slate-700",children:[s.period_name||"××¢×× ×"," · ",Vs(l.length)," ש×ר×ת"]}),e.jsx("span",{className:"text-[11.5px] text-slate-400",children:n?"ש×ר×ת ש××פק ××× ×××× × ×¢×××ת; ×× ×©××¨× ×××× ×¢×××× × ××ª× ×ת××§××.":"× ××ª× ×ער×× ×©××¨× ×× ×¢×× ×× ××פק ××× × ××××."})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-[12.5px]",children:[e.jsx("thead",{className:"bg-slate-50/70 text-slate-500",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"#"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"×ש××× ×ש××"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"× ×¤×©×ת / ×××××"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"××× ×"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"קר××× ××ר×× ×"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"קר××× ×¢××× ×ת"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"צר××× (××´×§)"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"ס××× (âª)"}),e.jsx("th",{className:"text-right px-3 py-2 font-semibold",children:"ס×××ס"}),e.jsx("th",{className:"px-3 py-2"})]})}),e.jsx("tbody",{children:l.map(S=>e.jsxs("tr",{className:"border-t border-slate-100",children:[e.jsx("td",{className:"px-3 py-2 text-slate-400 tabular-nums",children:S.row_no}),e.jsx("td",{className:"px-3 py-2 font-bold text-slate-700",children:y(S.payer_account_id)||S.consumer_name||e.jsx("span",{className:"text-slate-300",children:"â"})}),e.jsxs("td",{className:"px-3 py-2 tabular-nums",children:[e.jsx("span",{className:"font-black text-emerald-700",children:A($(S))}),e.jsx("span",{className:"text-slate-300 mx-1",children:"/"}),e.jsx("span",{className:"font-black text-amber-600",children:O(S)??
370})]}),e.jsx("td",{className:"px-3 py-2 text-slate-500 tabular-nums",dir:"ltr",children:S.meter_number||"â"}),e.jsx("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:A(S.previous_reading)}),e.jsx("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:A(S.current_reading)}),e.jsx("td",{className:"px-3 py-2 tabular-nums",dir:"ltr",children:A(S.consumption)}),e.jsx("td",{className:"px-3 py-2 tabular-nums font-bold",dir:"ltr",children:S.amount?Ln(S.amount):"â"}),e.jsxs("td",{className:"px-3 py-2",children:[e.jsx("span",{className:`text-[11px] font-bold px-2 py-0.5 rounded-full ${S.status===Tt.ok?"bg-emerald-50 text-emerald-700":S.status===Tt.opening?"bg-slate-100 text-slate-500":"bg-amber-50 text-amber-700"}`,children:Pa[S.status]||S.status}),S.charge_id&&e.jsx("span",{className:"block text-[10.5px] text-emerald-600 mt-0.5",children:"××פק ××××"})]}),e.jsx("td",{className:"px-3 py-2 text-left whitespace-nowrap",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[S.breakdown&&e.jsxs("button",{type:"button",onClick:()=>b(S),className:"h-7 px-2.5 rounded-full border border-slate-200 text-[11.5px] font-bold text-slate-600 hover:bg-slate-50 inline-flex items-center gap-1",children:[e.jsx(Ma,{className:"w-3 h-3"})," ××¦× ××ש××"]}),!S.charge_id&&e.jsxs("button",{type:"button",onClick:()=>m(S),className:"h-7 px-2.5 rounded-full border border-slate-200 text-[11.5px] font-bold text-slate-600 hover:bg-slate-50 inline-flex items-center gap-1",children:[e.jsx(It,{className:"w-3 h-3"})," ער×××"]})]})})]},S.id))})]})}),h&&e.jsx(Wn,{onClose:()=>b(null),title:`פ×ר×× ×××ש×× Â· ${y(h.payer_account_id)||h.consumer_name||""} · ××× × ${h.meter_number||""}`.trim(),children:e.jsx("div",{className:"max-w-xl mx-auto",children:e.jsx(dr,{b:h.breakdown})})}),c&&e.jsx(pc,{kibbutzId:t,row:c,meters:o,accounts:u,onClose:()=>m(null),onSaved:()=>{m(null),f(),a==null||a()}})]})}const fl=t=>ve(t),jx={draft:"×××××",pending:"××ת×× ×××ש×ר",approved:"×××שר",issued:"××פק",cancelled:"××××",credited:"××××"},Nx={monthly:"×××ש×",bimonthly:"××-×××ש×",quarterly:"ר××¢×× ×",yearly:"×©× ×ª×",one_time:"××-פע××",per_file:"××¤× ××¢×× ×ª ×§×××¥"},vx={draft:"bg-slate-100 text-slate-600",pending:"bg-amber-50 text-amber-700",approved:"bg-blue-50 text-blue-700",issued:"bg-emerald-50 text-emerald-700",cancelled:"bg-red-50 text-red-600",credited:"bg-purple-50 text-purple-700"};function gi({kibbutzId:t,mode:s}){const n=s==="recurring",[a,l]=i.useState(!0),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState(!1),[x,g]=i.useState(""),y=i.useCallback(async()=>{l(!0);try{const[w,_,T,M]=await Promise.all([D.entities.Charge.filter({kibbutz_id:t},"-created_date",5e3).catch(()=>[]),D.entities.BillingPlan.filter({kibbutz_id:t},"-created_date",500).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filter({kibbutz_id:t},"order",300).catch(()=>[])]);o(w||[]),u(_||[]),c(T||[]),h(M||[])}catch{W.error("ש×××× ×××¢×× ×")}finally{l(!1)}},[t]);i.useEffect(()=>{y()},[y]);const $=i.useCallback(w=>{const _=d.find(T=>T.id===w);return _?_.name||`#${_.account_number}`:"â"},[d]),O=i.useCallback(w=>{var _;return((_=m.find(T=>T.id===w))==null?void 0:_.name)||"â"},[m]),A=i.useMemo(()=>n?r.filter(w=>w.billing_plan_id):r.filter(w=>!w.billing_plan_id),[r,n]),S=i.useMemo(()=>[...new Set(A.map(w=>w.billing_period).filter(Boolean))].sort().reverse(),[A]),P=i.useMemo(()=>x?A.filter(w=>w.billing_period===x):A,[A,x]),E=async w=>{if(confirm("×××××§ ×××× ××?"))try{await D.entities.Charge.delete(w.id),W.success("× ×××§"),y()}catch{W.error("ש××××")}},k=async w=>{try{await D.entities.BillingPlan.update(w.id,{status:w.status==="active"?"paused":"active"}),y()}catch{W.error("ש××××")}},C=async w=>{if(confirm("×××××§ ת××× ×ת ×××× ×××רת? ×××××× ×©××ר × ××¦×¨× ××ש×ר×."))try{await D.entities.BillingPlan.delete(w.id),W.success("× ×××§×"),y()}catch{W.error("ש××××")}};return n?e.jsx(bc,{kibbutzId:t}):b?e.jsx(hm,{kibbutzId:t,mode:s,onClose:()=>f(!1),onDone:()=>{f(!1),y()}}):a?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4 gap-2 flex-wrap",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n?"×××××× ×××ר×× ×ת××× ××ת ×××× ×××ש××ת.":"×××××× ××־פע×××× ××× ××× ××ש×××× × ××ר××."}),e.jsxs("button",{onClick:()=>
37f(!0),className:`h-9 px-4 rounded-full text-white text-sm font-bold inline-flex items-center gap-1.5 ${n?"bg-blue-600":"bg-amber-600"}`,children:[e.jsx(We,{className:"w-4 h-4"})," ",n?"×××× ××××©× ××ש":"×××× ××־פע×× ××ש"]})]}),n&&p.length>0&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-3 mb-5",children:p.map(w=>e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-blue-50 flex items-center justify-center flex-shrink-0",children:e.jsx(Mt,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-sm font-bold truncate",children:w.name||O(w.charge_type_id)}),e.jsxs("p",{className:"text-xs text-slate-400",children:[Oa(w.calculation_method)," · ",Nx[w.billing_cycle]||w.billing_cycle]})]})]}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${w.status==="active"?"bg-emerald-50 text-emerald-700":"bg-slate-100 text-slate-500"}`,children:w.status==="active"?"פע×××":w.status==="paused"?"××ש××ת":w.status})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] mb-2",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-blue-50 text-blue-700",children:fl(w.rate)}),e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-slate-100 text-slate-600",children:[r.filter(_=>_.billing_plan_id===w.id).length," ××××××"]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>k(w),className:"h-8 px-3 rounded-full border border-slate-200 text-xs inline-flex items-center gap-1 hover:bg-slate-50",children:w.status==="active"?e.jsxs(e.Fragment,{children:[e.jsx(Ed,{className:"w-3.5 h-3.5"})," ×ש××"]}):e.jsxs(e.Fragment,{children:[e.jsx(vo,{className:"w-3.5 h-3.5"})," ×פע×"]})}),e.jsx("button",{onClick:()=>C(w),className:"w-8 h-8 rounded-full flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})]})]},w.id))}),S.length>1&&e.jsxs("div",{className:"flex items-center gap-1.5 mb-3 overflow-x-auto pb-1",children:[e.jsx(hr,{className:"w-4 h-4 text-slate-400 flex-shrink-0"}),e.jsx("button",{onClick:()=>g(""),className:`h-8 px-3 rounded-full text-xs font-medium border flex-shrink-0 ${x?"bg-white border-slate-200 text-slate-600":"bg-indigo-600 text-white border-transparent"}`,children:"×××"}),S.map(w=>e.jsx("button",{onClick:()=>g(w),className:`h-8 px-3 rounded-full text-xs font-medium border flex-shrink-0 ${x===w?"bg-indigo-600 text-white border-transparent":"bg-white border-slate-200 text-slate-600"}`,children:w},w))]}),P.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-10 text-center",children:[n?e.jsx(Mt,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}):e.jsx(Ns,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsxs("h3",{className:"text-base font-semibold mb-1",children:["××× ",n?"×××××× ×××ר××":"×××××× ××־פע××××"," ×¢××××"]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"×¦×¨× ×××× ××ש ××× ×ª×× ×× ××פ××¢× ×××. ×ס××××× ×××ש××× ×××××××ת ××× ×ש×× ××¤× ×¡×× ×××××."}),e.jsxs("button",{onClick:()=>f(!0),className:`h-9 px-4 rounded-full text-white text-sm font-bold inline-flex items-center gap-1.5 ${n?"bg-blue-600":"bg-amber-600"}`,children:[e.jsx(We,{className:"w-4 h-4"})," ×××× ××ש"]})]}):e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"×ש××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×× ××××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"תק×פ×"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×××ס"}),e.jsx("th",{className:"px-4 py-2.5"})]})}),e.jsx("tbody",{children:P.map(w=>e.jsxs("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium",children:$(w.payer_account_id)}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Xe,{className:"w-3.5 h-3.5 text-slate-400"}),O(w.charge_type_id)]})}),e.jsx("td",{className:"px-4 py-2.5 text-slate-500",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Be,{className:"w-3.5 h-3.5 text-slate-400"}),w.billing_period||"â"]}
37)}),e.jsx("td",{className:"px-4 py-2.5 font-bold",children:fl(w.amount)}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${vx[w.status]||"bg-slate-100 text-slate-600"}`,children:jx[w.status]||w.status})}),e.jsx("td",{className:"px-4 py-2.5 text-left",children:e.jsx("button",{onClick:()=>E(w),className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})})]},w.id))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t-2 border-slate-200 bg-slate-50",children:[e.jsxs("td",{colSpan:3,className:"px-4 py-2.5 text-xs text-slate-500 inline-flex items-center gap-1",children:[e.jsx(De,{className:"w-3.5 h-3.5"})," ",P.length," ××××××"]}),e.jsx("td",{className:"px-4 py-2.5 font-black",children:fl(P.reduce((w,_)=>w+(Number(_.amount)||0),0))}),e.jsx("td",{colSpan:2})]})})]})})]})}const yi=()=>new Date().toISOString().slice(0,7),wx={draft:"×××××",pending_approval:"××ת×× ×××ש×ר",approved:"×××שר",issued:"××פק",sent:"× ×©××",paid:"ש×××",partial:"ש××× ×××§×ת",overdue:"×××××ר",cancelled:"××××",credited:"××××"},kx={draft:"bg-slate-100 text-slate-600",issued:"bg-blue-50 text-blue-700",sent:"bg-indigo-50 text-indigo-700",paid:"bg-emerald-50 text-emerald-700",partial:"bg-amber-50 text-amber-700",overdue:"bg-red-50 text-red-600",cancelled:"bg-slate-100 text-slate-400",credited:"bg-purple-50 text-purple-700"},_i=[{v:"email",l:'×××"×',icon:no},{v:"whatsapp",l:"WhatsApp",icon:gn},{v:"personal_area",l:"×××ר ××ש×",icon:or},{v:"print",l:"××פס×/×ס×ר×",icon:yo}];function Sx({kibbutzId:t}){var ie,V,Y,J;const[s,n]=i.useState(!0),[a,l]=i.useState(yi()),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState([]),[x,g]=i.useState([]),[y,$]=i.useState([]),[O,A]=i.useState({}),[S,P]=i.useState(!1),[E,k]=i.useState(null),[C,w]=i.useState(null),[_,T]=i.useState([]),[M,B]=i.useState(null),R=i.useCallback(async()=>{n(!0);try{const[I,X,se,G,ne,ge,ke,be,je]=await Promise.all([D.entities.MonthlyStatement.filter({kibbutz_id:t},"-billing_month",5e3).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Charge.filter({kibbutz_id:t},"-created_date",8e3).catch(()=>[]),D.entities.Payment.filter({kibbutz_id:t},"-created_date",5e3).catch(()=>[]),D.entities.ChargeType.filter({kibbutz_id:t},"order",300).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me}).catch(()=>[]),D.entities.BillingSettings.filter({kibbutz_id:t},"-created_date",1).catch(()=>[]),D.entities.Kibbutz.get(t).catch(()=>null)]);o(I||[]),u(X||[]),c(se||[]),h(G||[]),f(ne||[]),g(ge||[]),$(ke||[]);const Ce=(be||[])[0]||{};A({name:Ce.legal_name||(je==null?void 0:je.name)||"×ש××× ×ª×§×פת×",address:Ce.address||"",phone:Ce.phone||"",email:Ce.email||"",business_number:Ce.business_number||"",logo_url:Ce.logo_url||(je==null?void 0:je.logo_url)||"",footer_note:Ce.footer_note||""})}catch{W.error("ש×××× ×××¢×× ×")}finally{n(!1)}},[t]);i.useEffect(()=>{R()},[R]);const j=i.useCallback(I=>{var X;return((X=b.find(se=>se.id===I))==null?void 0:X.name)||"××××"},[b]),q=i.useCallback(I=>x.find(X=>X.id===(I==null?void 0:I.family_id)),[x]),L=i.useCallback(I=>{const X=y.filter(se=>se.family_id===(I==null?void 0:I.family_id)&&se.status!=="inactive");return{emails:[...new Set(X.map(se=>se.email).filter(Boolean))],phones:[...new Set(X.map(se=>se.phone).filter(Boolean))],head:X.find(se=>se.family_role==="head")||X[0]}},[y]),N=i.useMemo(()=>r.filter(I=>I.billing_month===a),[r,a]),v=i.useMemo(()=>{const I=new Set(r.map(X=>X.billing_month).filter(Boolean));return I.add(yi()),I.add(a),[...I].sort().reverse()},[r,a]),F=i.useMemo(()=>{const I=new Set(N.map(se=>se.payer_account_id));return[...new Set(d.filter(se=>se.billing_period===a&&se.status==="approved"&&se.payer_account_id).map(se=>se.payer_account_id))].filter(se=>!I.has(se)).length},[d,a,N]);async function K(){var I,X;P(!0);try{const se=d.filter(be=>be.billing_period===a&&(be.status==="approved"||be.status==="issued")),G={};for(const be of se)(G[I=be.payer_account_id]||(G[I]=[])).push(be);
37const ne=Object.keys(G).filter(Boolean);if(ne.length===0){W.error("××× ×××××× ×××שר×× ×תק××¤× ×× ××פק×"),P(!1);return}const ge=new Date().toISOString();let ke=0;for(const be of ne){const je=p.find(ue=>ue.id===be);if(!je)continue;const Ce=q(je),ee=L(je),oe=G[be].map(ue=>({description:ue.description,charge_type:j(ue.charge_type_id),quantity:ue.quantity,rate:ue.rate,amount:ue.amount})),le=G[be].reduce((ue,Ee)=>ue+(Number(Ee.amount)||0),0),xe=G[be].reduce((ue,Ee)=>ue+(Number(Ee.discount_amount)||0),0),de=G[be].reduce((ue,Ee)=>ue+(Number(Ee.credit_amount)||0),0),ae=r.filter(ue=>ue.payer_account_id===be&&ue.billing_month<a).sort((ue,Ee)=>Ee.billing_month.localeCompare(ue.billing_month))[0],Ne=ae?Number(ae.balance_due)||0:Number(je.opening_balance)||0,we=m.filter(ue=>ue.payer_account_id===be&&ue.status==="paid"&&String(ue.payment_date||"").slice(0,7)===a).reduce((ue,Ee)=>ue+(Number(Ee.amount)||0),0),Ue=Ne+le-xe-de-we,re={issuer:O,account:{account_number:je.account_number,name:je.name,id_number:je.id_number,payment_method:je.payment_method},family:{name:Ce==null?void 0:Ce.name,address:[Ce==null?void 0:Ce.street,Ce==null?void 0:Ce.house_number].filter(Boolean).join(" "),head:(X=ee.head)==null?void 0:X.full_name,emails:ee.emails,phones:ee.phones},lines:oe,previous_balance:Ne,charges_total:le,discounts_total:xe,credits_total:de,payments_total:we,balance_due:Ue,month:a,issued_at:ge},Qe={kibbutz_id:t,payer_account_id:be,billing_month:a,previous_balance:Ne,charges_total:le,discounts_total:xe,credits_total:de,payments_total:we,balance_due:Ue,status:"issued",snapshot:re,due_date:je.due_date||null,issued_at:ge},Et=r.find(ue=>ue.payer_account_id===be&&ue.billing_month===a);let bt;Et?(await D.entities.MonthlyStatement.update(Et.id,Qe),bt=Et.id):bt=(await D.entities.MonthlyStatement.create(Qe)).id;for(const ue of G[be])(ue.status!=="issued"||ue.statement_id!==bt)&&await D.entities.Charge.update(ue.id,{statement_id:bt,status:"issued"});ke++}D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"statements_generated",entity_type:"monthly_statement",new_value:`${ke} ×ס××× ×ש××× Â· ${Lt(a)}`}).catch(()=>{}),W.success(`×××¤×§× ${ke} ×ס××× ×ש×××`),await R()}catch{W.error("ש×××× ××פקת ××ס××××")}finally{P(!1)}}async function Z(I,X){var je,Ce,ee,oe,le,xe,de,ae,Ne;const se=p.find(we=>we.id===I.payer_account_id),G=L(se),ne=Number(I.balance_due)||0,ge=`×ש××× ×תק××¤× ${Lt(I.billing_month)} â ${O.name}`;let ke="sent",be=null;try{if(X==="email"){const we=G.emails[0];if(!we){W.error('××× ×ת××ת ×××"× ××ש××');return}const Ue=`<div dir="rtl" style="font-family:Arial,sans-serif"><h2>${O.name}</h2><p>ש××× ${((Ce=(je=I.snapshot)==null?void 0:je.account)==null?void 0:Ce.name)||((ee=G.head)==null?void 0:ee.full_name)||""},</p><p>×צ×רף ×ש××× ×תק××¤× <b>${Lt(I.billing_month)}</b>.</p><p>××ª×¨× ×תש×××: <b>${as(ne)}</b>${I.due_date?` · ×תש××× ×¢× ${I.due_date}`:""}</p><p>× ××ª× ×צפ×ת ×פ×ר×× ×××× ××ש×× ××××ר ××××©× ××ער×ת.</p><p>${O.footer_note||""}</p></div>`,re=await D.functions.invoke("sendNotification",{channel:"email",to:we,subject:ge,body:Ue});!((oe=re==null?void 0:re.data)!=null&&oe.ok)&&((le=re==null?void 0:re.data)==null?void 0:le.ok)!==void 0&&(ke="failed",be="email_failed")}else if(X==="whatsapp"){const we=G.phones[0];if(!we){W.error("××× ××פ×× ××ש××");return}const Ue=`×ש××× ${Lt(I.billing_month)} · ××ª×¨× ×תש××× ${as(ne)}${I.due_date?` · ×¢× ${I.due_date}`:""}. ×פ×ר×× ××× â ××××ר ×××ש×.`,re=await D.functions.invoke("sendNotification",{channel:"whatsapp",to:we,name:((de=(xe=I.snapshot)==null?void 0:xe.account)==null?void 0:de.name)||"",variables:[ge,Ue]});((ae=re==null?void 0:re.data)==null?void 0:ae.ok)===!1&&(ke="failed",be=((Ne=re==null?void 0:re.data)==null?void 0:Ne.error)||"whatsapp_failed")}await D.entities.StatementDelivery.create({kibbutz_id:t,statement_id:I.id,payer_account_id:I.payer_account_id,channel:X,status:ke,sent_at:new Date().toISOString()}),ke==="sent"&&I.status==="issued"&&await D.entities.MonthlyStatement.update(I.id,{status:"sent"}),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"statement_sent",entity_type:"monthly_statement",entity_id:I.id,payer_account_id:I.payer_account_id,new_value:X}).catch(()=>{}
37),ke==="failed"?W.error(`×ש×××× × ×ש×× (${be})`):W.success("××ש××× × ×©××"),w(null),await R()}catch{W.error("ש×××× ×ש××××")}}async function H(){const I=N.filter(X=>X.status==="issued");if(I.length===0){W.error("××× ×ס×××× ××ש×× ×ש××××");return}if(confirm(`×ש××× ${I.length} ×ש××× ×ת ××¤× ×××¦×¢× ××§××× ××××¢××£ ×©× ×× ×ש××?`)){P(!0);for(const X of I){const se=p.find(ne=>ne.id===X.payer_account_id),G=Ea(se==null?void 0:se.preferred_delivery_channel);for(const ne of G.length?G:["personal_area"])await Z(X,ne)}P(!1)}}async function z(I){B(I);try{const X=await D.entities.StatementDelivery.filter({kibbutz_id:t,statement_id:I.id},"-sent_at",100);T(X||[])}catch{T([])}}if(s)return e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})});const te=N.reduce((I,X)=>({charges:I.charges+(Number(X.charges_total)||0),balance:I.balance+(Number(X.balance_due)||0)}),{charges:0,balance:0});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-slate-500",children:"תק×פ×:"}),e.jsx("select",{value:a,onChange:I=>l(I.target.value),className:"h-9 rounded-lg border border-slate-200 px-3 text-sm",children:v.map(I=>e.jsx("option",{value:I,children:Lt(I)},I))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:K,disabled:S,className:"h-9 px-4 rounded-full bg-indigo-600 text-white text-sm font-bold inline-flex items-center gap-1.5 disabled:opacity-50",children:[e.jsx(br,{className:`w-4 h-4 ${S?"animate-spin":""}`})," ×פק ×ס××× ×ש×××"]}),N.some(I=>I.status==="issued")&&e.jsxs("button",{onClick:H,disabled:S,className:"h-9 px-4 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center gap-1.5 disabled:opacity-50",children:[e.jsx(Gs,{className:"w-4 h-4"})," ש×× ×××"]})]})]}),F>0&&e.jsxs("div",{className:"flex items-center gap-2 bg-amber-50 border border-amber-200 rounded-xl px-4 py-2.5 mb-4 text-sm text-amber-800",children:[e.jsx(At,{className:"w-4 h-4 flex-shrink-0"})," ",F,' ×ש××× ×ת ×¢× ×××××× ×××שר×× ×תק××¤× ×× ××¨× ××פק×. ×××¦× â×פק ×ס××× ×ש×××".']}),N.length>0&&e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mb-4",children:[{l:"×ס×××× ×תק×פ×",v:N.length,icon:nt,tone:"text-indigo-600 bg-indigo-50"},{l:"ס××´× ××××××",v:as(te.charges),icon:nt,tone:"text-blue-600 bg-blue-50"},{l:"××ª×¨× ××××××",v:as(te.balance),icon:ws,tone:"text-amber-600 bg-amber-50"},{l:"× ×©×××",v:N.filter(I=>["sent","paid","partial"].includes(I.status)).length,icon:la,tone:"text-emerald-600 bg-emerald-50"}].map(I=>{const X=I.icon;return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg flex items-center justify-center mb-2 ${I.tone}`,children:e.jsx(X,{className:"w-5 h-5"})}),e.jsx("p",{className:"text-lg font-black text-slate-900",children:I.v}),e.jsx("p",{className:"text-xs text-muted-foreground",children:I.l})]},I.l)})}),N.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-10 text-center",children:[e.jsx(nt,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsxs("h3",{className:"text-base font-semibold mb-1",children:["××× ×ס××× ×ש××× ×תק××¤× ",Lt(a)]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'×××ר ×צ×רת ×××××× ×××שר×× ×תק×פ×, ×××¦× â×פק ×ס××× ×ש×××" ××× ×××× ×××ª× ××ס×× ××× ××× ×ש××.'})]}):e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"×ש××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"××××××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"××ª×¨× ×תש×××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×××ס"}),e.jsx("th",{className:"px-4 py-2.5"})]})}),e.jsx("tbody",{children:N.map(I=>{var X,se,G,ne,ge;return e.jsxs("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60",children:[e.jsxs("td",{className:"px-4 py-2.5 font-medium",children:[((se=(X=I.snapshot)==null?void 0:X.account)==null?void 0:se.name)||((G=p.find(ke=>ke.id===I.payer_account_id))==null?void 0:G.name)||"â"," ",e.jsxs("span",{className:"text-xs text-slate-400",children:["#",((ge=(ne=I.snapshot)==null?void 0:ne.account)==null?void 0:ge.account_number)||""]})]}),e.jsx("td",{className:"px-4 py-2.5",children:as(I.charges_total)}),e.jsx("td",{className:"px-4 py-2.5 font-bold",children:as(I.balance_due)}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${kx[I.status]||"bg-slate-100 text-slate-600"}`,children:wx[I.status]||I.status})}),e.jsx("td",{className:"px-4 py-2.5 text-left",children:e.jsxs("div",{className:"inline-flex items-center gap-1",children:[e.jsx("button",{onClick:()=>k(I),title:"צפ××× / ××פס×",className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-500 hover:bg-slate-100",children:e.jsx(fs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>w(I),title:"ש××××",className:"w-8 h-8 rounded-lg flex items-center justify-center text-indigo-600 hover:bg-indigo-50",children:e.jsx(Gs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>z(I),title:"×××× ×©××××ת",className:"w-8 h-8 rounded-lg flex items-center justify-center text-slate-400 hover:bg-slate-100",children:e.jsx(Tl,{className:"w-4 h-4"})})]})})]},I.id)})})]})}),E&&e.jsx(Wn,{onClose:()=>k(null),title:`×ס×× ×ש××× â ${((V=(ie=E.snapshot)==null?void 0:ie.account)==null?void 0:V.name)||""}`,children:e.jsx(sd,{statement:E})}),C&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",onClick:()=>w(null),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-md p-5",onClick:I=>I.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-base font-bold",children:"ש×××ת ×ש×××"}),e.jsx("button",{onClick:()=>w(null),className:"w-8 h-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("p",{className:"text-sm text-slate-500 mb-3",children:[(J=(Y=C.snapshot)==null?void 0:Y.account)==null?void 0:J.name," · ",Lt(C.billing_month)," · ××ª×¨× ",as(C.balance_due)]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:_i.map(I=>{const X=I.icon,se=p.find(ne=>ne.id===C.payer_account_id),G=Ea(se==null?void 0:se.preferred_delivery_channel).includes(I.v);return e.jsxs("button",{onClick:()=>Z(C,I.v),className:`flex items-center gap-2 h-11 px-3 rounded-xl border text-sm ${G?"border-indigo-300 bg-indigo-50 text-indigo-700":"border-slate-200 text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(X,{className:"w-4 h-4"})," ",I.l," ",G&&e.jsx("span",{className:"text-[10px] mr-auto",children:"×××¢××£"})]},I.v)})})]})}),M&&e.jsx("div",{className:"fixed inset-0 z-50 bg-black/50 flex items-center justify-center p-4",onClick:()=>B(null),children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-md p-5",onClick:I=>I.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-base font-bold inline-flex items-center gap-1.5",children:[e.jsx(Tl,{className:"w-4 h-4"})," ×××× ×©××××ת"]}),e.jsx("button",{onClick:()=>B(null),className:"w-8 h-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-4 h-4"})})]}),_.length===0?e.jsx("p",{className:"text-sm text-slate-400 text-center py-6",children:"××¨× × ×©×× ×ש××× ××"}):e.jsx("div",{className:"space-y-2",children:_.map(I=>{const X=_i.find(G=>G.v===I.channel),se=(X==null?void 0:X.icon)||Gs;return e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-slate-200 px-3 py-2",children:[e.jsxs("span",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx(se,{className:"w-4 h-4 text-slate-400"})," ",(X==null?void 0:X.l)||I.channel]}),e.jsx("span",{className:"text-xs text-slate-400",children:String(I.sent_at||"").slice(0,16).replace("T"," ")}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${I.status==="failed"?"bg-red-50 text-red-600":"bg-emerald-50 text-emerald-700"}`,children:I.status==="failed"?"× ×ש×":"× ×©××"})]},I.id)})})]})})]})}const Os=t=>ve(t),ji=()=>new Date().toISOString().slice(0,10),Zl=[{v:"standing_order",l:"××ר×ת ×§××¢",icon:Ar},{v:"credit",l:"×ר××ס ×שר××",icon:Oe},{v:"bank_transfer",l:"××¢××¨× ×× ×§××ת",icon:Ar},{v:"cash",l:"×××××",icon:Fd},{v:"check",l:"×××××",icon:Dd}],$x=t=>{var s;return((s=Zl.find(n=>n.v===t))==null?void 0:s.l)||t||"â"},rs=Se;function Cx({kibbutzId:t}){const[s,n]=i.useState(!0),[a,l]=i.useState([]),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState(!1),[b,f]=i.useState(!1),[x,g]=i.useState(!1),[y,$]=i.useState(""),[O,A]=i.useState(""),S={payer_account_id:"",statement_id:"",amount:"",payment_method:"standing_order",reference_number:"",payment_date:ji(),receipt_url:"",notes:""},[P,E]=i.useState(S),k=(L,N)=>E(v=>({...v,[L]:N})),C=i.useCallback(async()=>{n(!0);try{const[L,N,v,F]=await Promise.all([D.entities.Payment.filter({kibbutz_id:t},"-payment_date",5e3).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.MonthlyStatement.filter({kibbutz_id:t},"-billing_month",5e3).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[])]);l(L||[]),o(N||[]),u(v||[]),c(F||[])}catch{W.error("ש×××× ×××¢×× ×")}finally{n(!1)}},[t]);i.useEffect(()=>{C()},[C]);const w=i.useCallback(L=>{var v;const N=r.find(F=>F.id===L);return N?N.name||((v=d.find(F=>F.id===N.family_id))==null?void 0:v.name)||`#${N.account_number}`:"â"},[r,d]),_=i.useMemo(()=>p.filter(L=>P.payer_account_id?L.payer_account_id===P.payer_account_id:!1),[p,P.payer_account_id]);async function T(L,N){const v=p.find(z=>z.id===L);if(!v)return;const F=N.filter(z=>z.statement_id===L&&z.status==="paid").reduce((z,te)=>z+(Number(te.amount)||0),0),Z=(Number(v.previous_balance)||0)+(Number(v.charges_total)||0)-(Number(v.discounts_total)||0)-(Number(v.credits_total)||0)-F,H=Z<=.001?"paid":F>0?"partial":v.status==="paid"||v.status==="partial"?"sent":v.status;await D.entities.MonthlyStatement.update(L,{payments_total:F,balance_due:Z,status:H})}async function M(L){if(L){g(!0);try{const{file_url:N}=await D.integrations.Core.UploadFile({file:L});k("receipt_url",N),W.success("××§××× ×××¢×ת×")}catch{W.error("ש×××× ×××¢×××")}finally{g(!1)}}}async function B(){if(!P.payer_account_id){W.error("×××¨× ×ש××× ×ש××");return}if(!P.amount||Number(P.amount)<=0){W.error("×××× × ×¡×××");return}f(!0);try{const L=await D.entities.Payment.create({kibbutz_id:t,payer_account_id:P.payer_account_id,statement_id:P.statement_id||null,amount:Number(P.amount),payment_method:P.payment_method,reference_number:P.reference_number||null,payment_date:P.payment_date||ji(),status:"paid",receipt_url:P.receipt_url||null,notes:P.notes||null}),N=[...a,L];P.statement_id&&await T(P.statement_id,N),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"payment_recorded",entity_type:"payment",entity_id:L.id,payer_account_id:P.payer_account_id,new_value:Os(P.amount)}).catch(()=>{}),W.success("×תש××× × ×¨×©×"),h(!1),E(S),await C()}catch{W.error("ש×××× ×ר×ש××")}finally{f(!1)}}async function R(L){if(confirm(`×××××§ תש××× ×¢× ×¡× ${Os(L.amount)}?`))try{await D.entities.Payment.delete(L.id),L.statement_id&&await T(L.statement_id,a.filter(N=>
37N.id!==L.id)),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"payment_deleted",entity_type:"payment",entity_id:L.id,payer_account_id:L.payer_account_id,old_value:Os(L.amount)}).catch(()=>{}),W.success("×תש××× × ×××§"),await C()}catch{W.error("ש××××")}}if(s)return e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})});const j=O?a.filter(L=>L.payment_method===O):a,q=j.filter(L=>L.status==="paid").reduce((L,N)=>L+(Number(N.amount)||0),0);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap mb-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"ר×ש×× ×ª×©××××× ×תק××××× ××× × ××× ×ש××× ×ת ××ס××× ×ש×××."}),!m&&e.jsxs("button",{onClick:()=>{E(S),h(!0)},className:"h-9 px-4 rounded-full bg-emerald-600 text-white text-sm font-bold inline-flex items-center gap-1.5",children:[e.jsx(We,{className:"w-4 h-4"})," ר×ש×× ×ª×©×××"]})]}),e.jsx("div",{className:"bg-blue-50/60 border border-blue-100 rounded-xl px-4 py-2.5 mb-4 text-xs text-slate-500",children:"תש××× ××§××× ××ר××ס ×שר×× (ס×××§×) ×ת××סף ××××©× ×××ר ××××ר ספק ס×××§×. ×ש×× ×× × ×¨×©××× ×ª×©××××× ××× ×ת."}),m&&e.jsxs("div",{className:"bg-white rounded-2xl border border-emerald-200 shadow-sm p-5 mb-5 billing-form",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-base font-bold",children:"ר×ש×× ×ª×©××× ××ש"}),e.jsx("button",{onClick:()=>h(!1),className:"w-8 h-8 rounded-full border border-slate-200 flex items-center justify-center text-slate-400",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx("div",{className:"sm:col-span-1",children:e.jsxs(Q,{label:"×ש××× ×ש××",required:!0,children:[e.jsxs("div",{className:"relative mb-2",children:[e.jsx(qt,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{value:y,onChange:L=>$(L.target.value),placeholder:"××פ×שâ¦",className:"w-full h-10 rounded-xl border border-slate-300 pr-9 pl-3 text-sm"})]}),e.jsxs("select",{className:rs,value:P.payer_account_id,onChange:L=>{k("payer_account_id",L.target.value),k("statement_id","")},children:[e.jsx("option",{value:"",children:"×××¨× ×ש×××â¦"}),r.filter(L=>{var N;return!y||(L.name||"").includes(y)||(L.account_number||"").includes(y)||(((N=d.find(v=>v.id===L.family_id))==null?void 0:N.name)||"").includes(y)}).map(L=>e.jsxs("option",{value:L.id,children:[w(L.id)," · #",L.account_number]},L.id))]})]})}),e.jsx(Q,{label:"ש××× ××ס×× ×ש×××",info:"ש××× ×תש××× ××ש××× ××××©× ×ס××× ××¢××× ×ת ××ª×¨×ª× ×××××××ת",children:e.jsxs("select",{className:rs,value:P.statement_id,onChange:L=>k("statement_id",L.target.value),disabled:!P.payer_account_id,children:[e.jsx("option",{value:"",children:"â תש××× ×¢× ××ש××× â"}),_.map(L=>e.jsxs("option",{value:L.id,children:[Lt(L.billing_month)," · ××ª×¨× ",Os(L.balance_due)]},L.id))]})}),e.jsx(Q,{label:"ס××× (âª)",required:!0,children:e.jsx("input",{type:"number",className:rs,placeholder:"××× ×¡×××",value:P.amount,onChange:L=>k("amount",L.target.value)})}),e.jsx(Q,{label:"×××¦×¢× ×ª×©×××",required:!0,children:e.jsx("select",{className:rs,value:P.payment_method,onChange:L=>k("payment_method",L.target.value),children:Zl.map(L=>e.jsx("option",{value:L.v,children:L.l},L.v))})}),e.jsx(Q,{label:"×ס×××ª× / ×ס' ×§×××",children:e.jsx("input",{className:rs,placeholder:"××× ×ס×××ª× / ×ספר ×§×××",value:P.reference_number,onChange:L=>k("reference_number",L.target.value)})}),e.jsx(Q,{label:"ת×ר×× ×ª×©×××",required:!0,children:e.jsx("input",{type:"date",className:rs,value:P.payment_date,onChange:L=>k("payment_date",L.target.value)})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(Q,{label:"×ער×ת",children:e.jsx("input",{className:rs,placeholder:"×ער×ת (×× ××××)",value:P.notes,onChange:L=>k("notes",L.target.value)})})}),e.jsx(Q,{label:"×§××× ×¡×¨××§×",children:P.receipt_url?e.jsxs("a",{href:P.receipt_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 h-12 px-4 roun
37ded-xl border border-emerald-200 bg-emerald-50 text-emerald-700 text-sm",children:[e.jsx(jn,{className:"w-4 h-4"})," ×§××× ×צ×רפת"]}):e.jsxs("label",{className:"inline-flex items-center gap-1.5 h-12 px-4 rounded-xl border border-slate-300 text-sm text-slate-500 cursor-pointer hover:bg-slate-50",children:[e.jsx(La,{className:"w-4 h-4"})," ",x?"××¢××â¦":"××¢××ת ×§×××",e.jsx("input",{type:"file",className:"hidden",onChange:L=>{var N;return M((N=L.target.files)==null?void 0:N[0])}})]})})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-5",children:[e.jsxs("button",{onClick:B,disabled:b,className:ts,children:[e.jsx(ye,{className:"w-4 h-4"})," ",b?"ש××רâ¦":"רש×× ×ª×©×××"]}),e.jsx("button",{onClick:()=>h(!1),className:$s,children:"×××××"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mb-3 overflow-x-auto pb-1",children:[e.jsx(hr,{className:"w-4 h-4 text-slate-400 flex-shrink-0"}),e.jsx("button",{onClick:()=>A(""),className:`h-8 px-3 rounded-full text-xs font-medium border flex-shrink-0 ${O?"bg-white border-slate-200 text-slate-600":"bg-indigo-600 text-white border-transparent"}`,children:"×××"}),Zl.map(L=>e.jsx("button",{onClick:()=>A(L.v),className:`h-8 px-3 rounded-full text-xs font-medium border flex-shrink-0 ${O===L.v?"bg-indigo-600 text-white border-transparent":"bg-white border-slate-200 text-slate-600"}`,children:L.l},L.v))]}),j.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-10 text-center",children:[e.jsx(es,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"××× ×ª×©××××× ×¨×©××××"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"רש×× ×ª×©××× ×¨×ש××. ××× ×ש××× ××ש××× ×××ס×× ××ש××× ×××¢××× ×ת ×××ª×¨× ×××××××ת."})]}):e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ת×ר××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"×ש××"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"××צע×"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"×ס××ת×"}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"ס×××"}),e.jsx("th",{className:"px-4 py-2.5"})]})}),e.jsx("tbody",{children:j.map(L=>e.jsxs("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60",children:[e.jsx("td",{className:"px-4 py-2.5 text-slate-500",children:L.payment_date||"â"}),e.jsxs("td",{className:"px-4 py-2.5 font-medium",children:[w(L.payer_account_id),L.statement_id&&e.jsx("span",{className:"text-[11px] text-slate-400",children:" · ×ש××× ××ס××"})]}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:$x(L.payment_method)}),e.jsxs("td",{className:"px-4 py-2.5 text-slate-500",children:[L.reference_number||"â",L.receipt_url&&e.jsx("a",{href:L.receipt_url,target:"_blank",rel:"noreferrer",className:"text-indigo-500 mr-1 inline-flex",children:e.jsx(jn,{className:"w-3.5 h-3.5"})})]}),e.jsx("td",{className:"px-4 py-2.5 font-bold text-emerald-700",children:Os(L.amount)}),e.jsx("td",{className:"px-4 py-2.5 text-left",children:e.jsx("button",{onClick:()=>R(L),className:"w-8 h-8 rounded-lg inline-flex items-center justify-center text-red-500 hover:bg-red-50",children:e.jsx(Re,{className:"w-4 h-4"})})})]},L.id))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t-2 border-slate-200 bg-slate-50",children:[e.jsxs("td",{colSpan:4,className:"px-4 py-2.5 text-xs text-slate-500",children:[j.length," תש×××××"]}),e.jsx("td",{className:"px-4 py-2.5 font-black text-emerald-700",children:Os(q)}),e.jsx("td",{})]})})]})})]})}const gl=t=>ve(t);function Ax({kibbutzId:t}){const[s,n]=i.useState(!0),[a,l]=i.useState([]),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState([]),[x,g]=i.useState("pending"),[y,$]=i.useState(null),O=i.useCallback(async()=>{n(!0);try{const[w,_,T,M,B,R]=await Promise.all([D.entities.Charge.filter({kibbutz_id:t},"-created_date",8e3).catch(()=>[]),D.entities.Payment.filter({kibbutz_id:t},"-created_date",5e3).catch(()=>[]),D.entities.BillingApproval.filter({kibbutz_id:t},"-created_date",1e3).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filter({kibbutz_id:t},"order",300).catch(()=>[]),D.entities.MonthlyStatement.filter({kibbutz_id:t},"-billing_month",5e3).catch(()=>[])]);l(w||[]),o(_||[]),u(T||[]),c(M||[]),h(B||[]),f(R||[])}catch{W.error("ש×××× ×××¢×× ×")}finally{n(!1)}},[t]);i.useEffect(()=>{O()},[O]);const A=i.useCallback(w=>{const _=d.find(T=>T.id===w);return _?_.name||`#${_.account_number}`:"â"},[d]),S=i.useCallback(w=>{var _;return((_=m.find(T=>T.id===w))==null?void 0:_.name)||"××××"},[m]);async function P(w){const _=b.find(R=>R.id===w);if(!_)return;const T=r.filter(R=>R.statement_id===w&&R.status==="paid").reduce((R,j)=>R+(Number(j.amount)||0),0),B=(Number(_.previous_balance)||0)+(Number(_.charges_total)||0)-(Number(_.discounts_total)||0)-(Number(_.credits_total)||0)-T;await D.entities.MonthlyStatement.update(w,{payments_total:T,balance_due:B,status:B<=.001?"paid":T>0?"partial":_.status})}const E=i.useMemo(()=>{const w=[];for(const _ of a)_.status==="pending"&&w.push({kind:"charge",id:_.id,row:_,account:_.payer_account_id,title:S(_.charge_type_id),sub:`${_.description||""} · ${Lt(_.billing_period)}`,amount:_.amount,icon:nt,tone:"text-blue-600 bg-blue-50"});for(const _ of r)_.status==="pending_approval"&&w.push({kind:"payment",id:_.id,row:_,account:_.payer_account_id,title:"תש×××",sub:_.reference_number||_.payment_method||"",amount:_.amount,icon:es,tone:"text-emerald-600 bg-emerald-50"});for(const _ of p)_.status==="pending"&&w.push({kind:"approval",id:_.id,row:_,account:_.payer_account_id,title:_.approval_type||"×קשת ××ש×ר",sub:_.reason||"",amount:_.amount,icon:Oe,tone:"text-purple-600 bg-purple-50"});return w},[a,r,p,S]),k=i.useMemo(()=>p.filter(w=>w.status!=="pending").map(w=>({kind:"approval",id:w.id,row:w,account:w.payer_account_id,title:w.approval_type||"×קש×",amount:w.amount,status:w.status})),[p]);async function C(w,_){$(w.id);try{w.kind==="charge"?await D.entities.Charge.update(w.id,{status:_?"approved":"cancelled"}):w.kind==="payment"?(await D.entities.Payment.update(w.id,{status:_?"paid":"cancelled"}),w.row.statement_id&&await P(w.row.statement_id)):w.kind==="approval"&&await D.entities.BillingApproval.update(w.id,{status:_?"approved":"rejected",resolved_at:new Date().toISOString()}),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:_?"approval_granted":"approval_rejected",entity_type:w.kind,entity_id:w.id,payer_account_id:w.account,new_value:w.amount!=null?gl(w.amount):null}).catch(()=>{}),W.success(_?"××שר":"× ×××"),await O()}catch{W.error("ש××××")}finally{$(null)}}return s?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-4",children:[e.jsxs("button",{onClick:()=>
37g("pending"),className:`h-9 px-4 rounded-full text-sm font-medium border ${x==="pending"?"bg-indigo-600 text-white border-transparent":"bg-white border-slate-200 text-slate-600"}`,children:["××ת×× ×× ×××ש×ר ",E.length>0&&e.jsx("span",{className:"mr-1 px-1.5 py-0.5 rounded-full bg-white/25 text-[11px]",children:E.length})]}),e.jsx("button",{onClick:()=>g("resolved"),className:`h-9 px-4 rounded-full text-sm font-medium border ${x==="resolved"?"bg-indigo-600 text-white border-transparent":"bg-white border-slate-200 text-slate-600"}`,children:"××ס××ר××ת ×××××ת"})]}),x==="pending"?E.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-10 text-center",children:[e.jsx(la,{className:"w-10 h-10 text-emerald-300 mx-auto mb-3"}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:"××× ×¤×¨×××× ×××ת×× ×× ×××ש×ר"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'×××××× ×©×××××¨× â××רש ××ש×ר", תש××××× ×××ש×ר ××קש×ת ×ר××× ××פ××¢× ×××.'})]}):e.jsx("div",{className:"space-y-2",children:E.map(w=>{const _=w.icon;return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4 flex items-center gap-3",children:[e.jsx("span",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${w.tone}`,children:e.jsx(_,{className:"w-5 h-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-bold",children:w.title}),e.jsx("span",{className:"text-xs text-slate-400",children:A(w.account)})]}),w.sub&&e.jsx("p",{className:"text-xs text-slate-500 truncate",children:w.sub})]}),w.amount!=null&&e.jsx("span",{className:"text-base font-black text-slate-800 flex-shrink-0",children:gl(w.amount)}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsxs("button",{onClick:()=>C(w,!0),disabled:y===w.id,className:"h-9 px-3 rounded-full bg-emerald-600 text-white text-sm inline-flex items-center gap-1 disabled:opacity-50",children:[e.jsx(ye,{className:"w-4 h-4"})," ×שר"]}),e.jsxs("button",{onClick:()=>C(w,!1),disabled:y===w.id,className:"h-9 px-3 rounded-full border border-red-200 text-red-600 text-sm inline-flex items-center gap-1 disabled:opacity-50",children:[e.jsx($e,{className:"w-4 h-4"})," ×××"]})]})]},w.kind+w.id)})}):k.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-10 text-center",children:[e.jsx(ws,{className:"w-10 h-10 text-slate-300 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"××× ×¢×××× ××ס××ר××ת ×××××ת."})]}):e.jsx("div",{className:"space-y-2",children:k.map(w=>e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4 flex items-center gap-3",children:[e.jsx("span",{className:`w-9 h-9 rounded-lg flex items-center justify-center flex-shrink-0 ${w.status==="approved"?"text-emerald-600 bg-emerald-50":"text-red-500 bg-red-50"}`,children:w.status==="approved"?e.jsx(ye,{className:"w-5 h-5"}):e.jsx(Od,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-bold",children:w.title})," ",e.jsx("span",{className:"text-xs text-slate-400",children:A(w.account)})]}),w.amount!=null&&e.jsx("span",{className:"text-sm font-bold text-slate-700",children:gl(w.amount)}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full ${w.status==="approved"?"bg-emerald-50 text-emerald-700":"bg-red-50 text-red-600"}`,children:w.status==="approved"?"××שר":"× ×××"})]},w.kind+w.id))})]})}const Mx={status:"active",link:"",ready:"",q:""},Za=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),yl=t=>t==null||t===""?null:Number(t);function Px({kibbutzId:t,settings:s}){const[n,a]=i.useState(!0),[l,r]=i.useState([]),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState([]),[h,b]=i.useState(Mx),f=(k,C)=>b(w=>({...w,[k]:C})),x=i.useCallback(async()=>{a(!0);try{const[k,C,w,_]=await Promise.all([D.entities.WaterMeter.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.Property.filterAll({kibbutz_id:t}).catch(()=>[])]);r(k||[]),p(C||[]),d(w||[]),m(_||[])}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{x()},[x]);const g=i.useMemo(()=>new Map(o.map(k=>[k.id,k])),[o]),y=i.useMemo(()=>new Map(u.map(k=>[k.id,k])),[u]),$=i.useMemo(()=>new Map(c.map(k=>[k.id,k])),[c]),O=k=>!!k.payer_account_id&&Number(k.souls)>0&&k.previous_reading!=null,A=i.useMemo(()=>({status:Te(l||[],{active:k=>(k.status||"active")==="active",inactive:k=>k.status==="inactive"}),link:Te(l||[],{linked:k=>!!k.payer_account_id,orphan:k=>!k.payer_account_id}),ready:Te(l||[],{ready:O,missing:k=>!O(k)})}),[l]),S=i.useMemo(()=>{const k=h.q.trim();return(l||[]).filter(C=>{const w=C.status||"active";if(h.status&&w!==h.status||h.link==="linked"&&!C.payer_account_id||h.link==="orphan"&&
37C.payer_account_id)return!1;const _=!!C.payer_account_id&&Number(C.souls)>0&&C.previous_reading!=null;if(h.ready==="ready"&&!_||h.ready==="missing"&&_)return!1;if(k){const T=g.get(C.payer_account_id);if(![C.meter_number,C.consumer_id,C.property_address,C.consumer_name,T==null?void 0:T.name,T==null?void 0:T.account_number].join(" ").includes(k))return!1}return!0}).map(C=>{const w=g.get(C.payer_account_id),_=w!=null&&w.family_id?y.get(w.family_id):null,T=$.get(C.property_id),M=[!C.payer_account_id&&"×ש×××",!(Number(C.souls)>0)&&"× ×¤×©×ת",C.previous_reading==null&&"קר×××"].filter(Boolean);return{...C,_account:w?w.name||`#${w.account_number}`:"××× ×ש××× ×ש××",_accountNumber:(w==null?void 0:w.account_number)||"",_family:(_==null?void 0:_.name)||"",_property:(T==null?void 0:T.property_number)||"",_address:C.property_address||(T==null?void 0:T.address)||"",_souls:yl(C.souls),_eligible:yl(C.eligible_count),_reading:yl(C.previous_reading),_statusLabel:(C.status||"active")==="active"?"פע××":"××ש×ת",_ready:M.length===0,_missing:M.length?`×סר ${M.join(" · ")}`:"×××× ×××××"}})},[l,h,g,y,$]),P=[{key:"_account",header:"×ש××× ×ש××",width:24,strong:!0},{key:"_accountNumber",header:"×ס׳ ×ש×××",width:11,muted:!0,off:!0},{key:"_family",header:"×שפ××",width:18,muted:!0,off:!0},{key:"meter_number",header:"×ספר ××× ×",width:14,strong:!0},{key:"consumer_id",header:"×ס׳ ×××××",width:12,muted:!0},{key:"_address",header:"×ת××ת ×× ×ס",width:24,clamp:!0},{key:"_property",header:"× ×ס",width:10,muted:!0,off:!0},{key:"consumer_name",header:"×©× ×¦×¨××",width:20,muted:!0,off:!0},{key:"_souls",header:"× ×¤×©×ת",width:9,type:"num",total:!0},{key:"_eligible",header:"×××××",width:9,type:"num",total:!0},{key:"_reading",header:"קר××× ××ר×× ×",width:13,type:"cube"},{key:"previous_reading_date",header:"ת×ר×× ×§×¨×××",width:12,type:"date"},{key:"notes",header:"×ער×ת",width:20,muted:!0,clamp:!0,off:!0},{key:"_statusLabel",header:"ס×××ס",width:10,align:"center"},{key:"_missing",header:"×××× ×ת ×××××",width:18,align:"center",render:k=>e.jsx("span",{className:`inline-block px-2.5 py-1 rounded-full border text-[11.5px] font-bold ${k._ready?"bg-emerald-50 text-emerald-700 border-emerald-200":"bg-amber-50 text-amber-700 border-amber-200"}`,children:k._missing})}],E=i.useMemo(()=>{const k=S.filter(w=>!w.payer_account_id).length,C=S.filter(w=>!w._ready).length;return[{label:"××× ××",value:Za(S.length),icon:Nd,tone:"text-sky-600 bg-sky-50"},{label:"ס××´× × ×¤×©×ת",value:Za(S.reduce((w,_)=>w+(Number(_._souls)||0),0)),icon:De,tone:"text-blue-600 bg-blue-50"},{label:"××× ×ש××× ×ש××",value:Za(k),icon:or,tone:k?"text-amber-600 bg-amber-50":"text-slate-400 bg-slate-100"},{label:"×סר×× ×¤×¨××× ×××××",value:Za(C),icon:At,tone:C?"text-red-600 bg-red-50":"text-slate-400 bg-slate-100"}]},[S]);return e.jsx(ss,{title:"××× ××× ××",subtitle:"××× × ×××× ×רש×××× ××§×××× â ××ש××× ×©×× ×©××××× ××, ×× ×ס, ×× ×¤×©×ת ש××××¡× ×××ש×ת ×פ××× ××קר××× ×××ר×× ×",settings:s,chips:[h.status?h.status==="active"?"××× ×× ×¤×¢××××":"××× ×× ××ש×ת××":"×× ×ס×××ס××",h.link==="linked"?"×ש××××× ××ש×××":h.link==="orphan"?"××× ×ש××× ×ש××":"",h.ready==="ready"?"×××× ×× ×××××":h.ready==="missing"?"×סר×× ×¤×¨×××":"",h.q&&`××פ×ש: ${h.q}`],search:{value:h.q,onChange:k=>f("q",k),placeholder:"××פ×ש ××¤× ×ש××, ××× ×, ×ס׳ ××××× ×× ×ת××ת"},filters:e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"ס×××ס",value:h.status,onChange:k=>f("status",k),counts:A.status,options:[{v:"active",l:"פע××××"},{v:"inactive",l:"××ש×ת××"},{v:"",l:"×××"}]}),e.jsx(Ae,{label:"ש×××",value:h.link,onChange:k=>f("link",k),counts:A.link,options:[{v:"",l:"×××"},{v:"linked",l:"×ש××××× ××ש×××"},{v:"orphan",l:"××× ×ש×××"}]}),e.jsx(Ae,{label:"×××× ×ת ×××××",value:h.ready,onChange:k=>f("ready",k),counts:A.ready,options:[{v:"",l:"×××"},{v:"ready",l:"×××× ××"},{v:"missing",l:"×סר×× ×¤×¨×××"}]})]}),stats:E,columns:P,defaultSort:{key:"_account",dir:"asc"},rows:S,loading:n,fileName:"×××_××× ××",empty:"××× ××× ×× ×ת××××× ×ת ×ס×× ××",footNote:"«×××× ×××××» = ×××× × ×ש ×ש××× ×ש××, ×ספר × ×¤×©×ת ×קר××× ××ר×× ×. ××× ×©×××©×ª× ××¢×× ×ª ×§×××¥ קר×××ת ×× ×ª××× ××פ××§ ××× × ×ש×××."})}const Ex={type:"",status:"active",link:"",q:"",min:""},Qa=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),Ja=t=>t==null||t===""?null:Number(t);function Fx({kibbutzId:t,settings:s}){const[n,a]=i.useState(!0),[l,r]=i.useState([]),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState([]),[h,b]=i.useState(Ex),f=(k,C)=>b(w=>({...w,[k]:C})),x=i.useCallback(async()=>{a(!0);try{const[k,C,w,_]=await Promise.all([D.entities.Property.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.WaterMeter.filterAll({kibbutz_id:t}).catch(()=>[])]);r(k||[]),p(C||[]),d(w||[]),m(_||[])}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{x()},[x]);const g=i.useMemo(()=>new Map(o.map(k=>[k.id,k])),[o]),y=i.useMemo(()=>new Map(u.map(k=>[k.id,k])),[u]),$=i.useMemo(()=>{const k=new Map;
37return c.forEach(C=>{C.property_id&&k.set(C.property_id,[...k.get(C.property_id)||[],C])}),k},[c]),O=i.useMemo(()=>[...new Set(l.map(k=>k.property_type).filter(Boolean))],[l]),A=i.useMemo(()=>({status:Te(l,{active:k=>(k.status||"active")==="active",inactive:k=>k.status==="inactive"}),link:Te(l,{linked:k=>!!k.payer_account_id,orphan:k=>!k.payer_account_id})}),[l]),S=i.useMemo(()=>{const k=h.q.trim(),C=h.min===""?null:Number(h.min);return(l||[]).filter(w=>{if(h.type&&w.property_type!==h.type||h.status&&(w.status||"active")!==h.status||h.link==="linked"&&!w.payer_account_id||h.link==="orphan"&&w.payer_account_id||C!==null&&!(Number(w.size_sqm)>=C))return!1;if(k){const _=g.get(w.payer_account_id);if(![w.property_number,w.address,w.gush_helka,_==null?void 0:_.name,_==null?void 0:_.account_number].join(" ").includes(k))return!1}return!0}).map(w=>{const _=g.get(w.payer_account_id),T=_!=null&&_.family_id?y.get(_.family_id):null;return{...w,_account:_?_.name||`#${_.account_number}`:"××× ×ש××× ×ש××",_accountNumber:(_==null?void 0:_.account_number)||"",_family:(T==null?void 0:T.name)||"",_meters:($.get(w.id)||[]).map(M=>M.meter_number).join(", "),_status:(w.status||"active")==="active"?"פע××":"×× ×¤×¢××",_size:Ja(w.size_sqm),_built:Ja(w.built_sqm),_extra:Ja(w.extra_sqm),_souls:Ja(w.occupancy_count)}}).sort((w,_)=>String(w._account).localeCompare(String(_._account),"he"))},[l,h,g,y,$]),P=[{key:"property_number",header:"×ספר / ×©× × ×ס",width:16,strong:!0},{key:"property_type",header:"ס××",width:14,muted:!0},{key:"address",header:"×ת××ת",width:24,clamp:!0},{key:"gush_helka",header:"××ש/×××§×",width:14,muted:!0},{key:"_size",header:"ש×× (×״ר)",width:11,type:"num",total:!0},{key:"_built",header:"×× ×× (×״ר)",width:11,type:"num",total:!0},{key:"_extra",header:"ש×× × ×סף",width:11,type:"num",total:!0},{key:"_souls",header:"× ×¤×©×ת",width:9,type:"num",total:!0},{key:"_account",header:"×ש××× ×ש××",width:24,strong:!0},{key:"_accountNumber",header:"×ס׳ ×ש×××",width:11,muted:!0},{key:"_family",header:"×שפ××",width:18,muted:!0},{key:"_meters",header:"××× × ×××",width:14,muted:!0},{key:"active_from",header:"ת×××ת ש×××",width:12,type:"date",muted:!0},{key:"_status",header:"ס×××ס",width:10,align:"center"}],E=i.useMemo(()=>{const k=S.filter(C=>!C.payer_account_id).length;return[{label:"× ×ס××",value:Qa(S.length),icon:ra},{label:"ס××´× ×״ר",value:Qa(S.reduce((C,w)=>C+(Number(w._size)||0),0)),icon:vd,tone:"text-indigo-600 bg-indigo-50"},{label:"ס××´× × ×¤×©×ת",value:Qa(S.reduce((C,w)=>C+(Number(w._souls)||0),0)),icon:De,tone:"text-blue-600 bg-blue-50"},{label:"××× ×ש××× ×ש××",value:Qa(k),icon:es,tone:k?"text-amber-600 bg-amber-50":"text-slate-400 bg-slate-100"}]},[S]);return e.jsx(ss,{title:"××× × ×ס××",subtitle:"×××××ת ××××× ×©× ××§××××, ש×××××, ×× ×¤×©×ת ××ש××××ת ×××ש××× ×©×ש×× ×¢××××",settings:s,chips:[h.type&&`ס××: ${h.type}`,h.status?h.status==="active"?"× ×ס×× ×¤×¢××××":"× ×ס×× ×× ×¤×¢××××":"×× ×ס×××ס××",h.link==="linked"?"×ש××××× ××ש×××":h.link==="orphan"?"××× ×ש××× ×ש××":"",h.min!==""&&`ש×× ××¢× ${h.min} ×״ר`,h.q&&`××פ×ש: ${h.q}`],search:{value:h.q,onChange:k=>f("q",k),placeholder:"××פ×ש ××¤× × ×ס, ×ת××ת, ××ש/×××§× ×× ×ש××"},filters:e.jsxs(e.Fragment,{children:[e.jsx(oc,{label:"ס×× × ×ס",value:h.type,onChange:k=>f("type",k),options:[{v:"",l:"×××"},...O.map(k=>({v:k,l:k}))]}),e.jsx(Ae,{label:"ס×××ס",value:h.status,onChange:k=>f("status",k),counts:A.status,options:[{v:"active",l:"פע××××"},{v:"inactive",l:"×× ×¤×¢××××"},{v:"",l:"×××"}]}),e.jsx(Ae,{label:"ש×××",value:h.link,onChange:k=>f("link",k),counts:A.link,options:[{v:"",l:"×××"},{v:"linked",l:"×ש××××× ××ש×××"},{v:"orphan",l:"××× ×ש×××"}]}),e.jsx(cc,{label:"ש×× ××¢× (×״ר)",value:h.min,onChange:k=>f("min",k),placeholder:"0"})]}),stats:E,columns:P,defaultSort:{key:"_account",dir:"asc"},rows:S,loading:n,fileName:"×××_× ×ס××",empty:"××× × ×ס×× ×ת××××× ×ת ×ס×× ××"})}const _l=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),Dx=t=>
37(Number(t)||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),jl=[{v:"lines",l:"ש×ר×ת"},{v:"family",l:"××¤× ×שפ××"},{v:"dept",l:"××¤× ×§××צת ××צר"},{v:"item",l:"××¤× ×¤×¨××"}];function Ox({kibbutzId:t,settings:s}){var O,A;const[n,a]=i.useState(!0),[l,r]=i.useState([]),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState({batch:"",mode:"family",q:""}),h=(S,P)=>m(E=>({...E,[S]:P})),b=i.useCallback(async()=>{a(!0);try{const[S,P]=await Promise.all([D.entities.KolboImportBatch.filterAll({kibbutz_id:t,status:"approved"},"-created_date").catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[])]);r(S||[]),d(P||[]),m(E=>{var k;return{...E,batch:E.batch||((k=S==null?void 0:S[0])==null?void 0:k.id)||""}})}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{b()},[b]),i.useEffect(()=>{if(!c.batch){p([]);return}let S=!0;return a(!0),D.entities.KolboPurchase.filterAll({kibbutz_id:t,batch_id:c.batch}).then(P=>{S&&p(P||[])}).catch(()=>{S&&p([])}).finally(()=>{S&&a(!1)}),()=>{S=!1}},[t,c.batch]);const f=i.useMemo(()=>new Map(u.map(S=>[S.id,S])),[u]),x=i.useMemo(()=>{const S=c.q.trim();return o.filter(P=>{var E;if(S){const k=P.family_id?(E=f.get(P.family_id))==null?void 0:E.name:"";if(![P.item,P.dept,P.payer_name,P.budget,P.sku,k].join(" ").includes(S))return!1}return!0}).map(P=>{var E;return{...P,_family:P.family_id&&((E=f.get(P.family_id))==null?void 0:E.name)||P.payer_name||"",_unit:P.qty!=null&&P.unit?`${P.unit}`:""}})},[o,c,f]),g=i.useMemo(()=>{if(c.mode==="lines")return{rows:[...x].sort((E,k)=>String(k.txn_date).localeCompare(String(E.txn_date))||String(E.receipt).localeCompare(String(k.receipt))),columns:[{key:"txn_date",header:"ת×ר××",width:12,type:"date"},{key:"receipt",header:"×ש××× ×ת",width:12,muted:!0},{key:"budget",header:"תקצ××",width:10},{key:"_family",header:"×שפ×× / ×ש××",width:22,strong:!0,clamp:!0},{key:"dept",header:"×§××צת ××צר",width:18,muted:!0},{key:"item",header:"פר××",width:28,clamp:!0},{key:"qty",header:"×××ת",width:9,type:"num",total:!0},{key:"_unit",header:"×××××",width:8,muted:!0,align:"center"},{key:"total",header:"ס××× (âª)",width:12,type:"money",total:!0,strong:!0}]};if(c.mode==="family"){const E=new Map;return x.forEach(k=>{const C=k.family_id||`b:${k.budget}`,w=E.get(C)||{id:C,_family:k._family||"â",budget:k.budget,lines:0,total:0,rows:[]};w.lines+=1,w.total+=Number(k.total)||0,w.rows.push(k),E.set(C,w)}),{rows:[...E.values()].map(k=>({...k,visits:_n(k.rows).length,total:ka(k.total)})).sort((k,C)=>C.total-k.total),columns:[{key:"_family",header:"×שפ×× / ×ש××",width:28,strong:!0},{key:"budget",header:"×ספר תקצ××",width:12},{key:"visits",header:"×××§×ר××",width:10,type:"num",total:!0},{key:"lines",header:"ש×ר×ת",width:10,type:"num",total:!0},{key:"total",header:"ס××´× ×§× ××ת (âª)",width:14,type:"money",total:!0,strong:!0}]}}const S=new Map;return x.forEach(E=>{const k=c.mode==="dept"?E.dept||"â":`${E.sku||""}|${E.item||"â"}`,C=S.get(k)||{id:k,dept:E.dept||"â",item:E.item||"â",sku:E.sku||"",lines:0,qty:0,total:0,buyers:new Set};C.lines+=1,C.qty+=Number(E.qty)||0,C.total+=Number(E.total)||0,C.buyers.add(E.family_id||E.budget),S.set(k,C)}),{rows:[...S.values()].map(E=>({...E,qty:ka(E.qty),total:ka(E.total),buyers:E.buyers.size})).sort((E,k)=>k.total-E.total),columns:c.mode==="dept"?[{key:"dept",header:"×§××צת ××צר",width:28,strong:!0},{key:"lines",header:"ש×ר×ת",width:10,type:"num",total:!0},{key:"qty",header:"×××ת",width:10,type:"num",total:!0},{key:"buyers",header:"××©×§× ××ת",width:11,type:"num"},{key:"total",header:"ס××´× (âª)",width:14,type:"money",total:!0,strong:!0}]:[{key:"item",header:"פר××",width:32,strong:!0,clamp:!0},{key:"sku",header:"××§×´×",width:12,muted:!0},{key:"dept",header:"×§××צת ××צר",width:20,muted:!0},{key:"qty",header:"×××ת",width:10,type:"num",total:!0},{key:"buyers",header:"××©×§× ××ת",width:11,type:"num"},{key:"total",header:"ס××´× (âª)",width:14,type:"money",total:!0,strong:!0}]}},[c.mode,x]),y=l.find(S=>S.id===c.batch),$=i.useMemo(()=>{const S=x.reduce((k,C)=>k+(Number(C.total)||0),0),P=new Set(x.map(k=>k.family_id||k.budget)).size,E=_n(x).length;return[{label:"ש×ר×ת",value:_l(x.length),icon:da},{label:"×××§×ר××",value:_l(E),icon:fo,tone:"text-indigo-600 bg-indigo-50"},{label:"××©×§× ××ת",value:_l(P),icon:De,tone:"text-blue-600 bg-blue-50"},{label:"ס××´× ×§× ××ת",value:Dx(S),currency:!0,icon:rt,tone:"text-emerald-600 bg-emerald-50"}
37]},[x]);return e.jsx(ss,{title:"××× ×××××",subtitle:y?`×§× ××ת ××ר××× ××§×××¥ «${y.file_name||""}»${y.period_from?` · ${String(y.period_from).slice(0,10)} â ${String(y.period_to||"").slice(0,10)}`:""}`:"×§× ××ת ××ר×××, ××¤× ×§×××¥ ×©× ××¢× ×××שר",settings:s,chips:[y&&`××¢×× ×: ${y.file_name||y.id.slice(0,6)}`,`תצ×××: ${(O=jl.find(S=>S.v===c.mode))==null?void 0:O.l}`,c.q&&`××פ×ש: ${c.q}`],search:{value:c.q,onChange:S=>h("q",S),placeholder:"××פ×ש ××¤× ×¤×¨××, ×שפ××, ×ספר תקצ×× ×× ××§×´×"},filters:e.jsx(Ae,{label:"תצ×××",value:c.mode,onChange:S=>h("mode",S),options:jl}),stats:$,columns:g.columns,defaultSort:{key:"_family",dir:"asc"},rows:g.rows,loading:n,fileName:`×××_×××××_${((A=jl.find(S=>S.v===c.mode))==null?void 0:A.l)||""}`,empty:l.length?"××× ×©×ר×ת ×ת××××ת ×ת ×ס×× ××":"×¢×××× ×× ×××©×¨× ××¢×× ×ª ×§×××¥ ×××××",footNote:"×ספר ××ש××× ×ת ××× ××ת×ת ××©×¢× ×××§×פ×, ×××× ×××§×ר ××××× ××¤× ×ª×ר×× + ×ש××× ×ת + ×ספר תקצ××."})}function Tn(t,s=new Date){const n=String(t||"").slice(0,10);if(!/^\d{4}-\d{2}-\d{2}$/.test(n))return null;const[a,l,r]=n.split("-").map(Number),o=Date.UTC(a,l-1,r),p=Date.UTC(s.getFullYear(),s.getMonth(),s.getDate());return Math.round((o-p)/864e5)}function wa(t,{prefix:s=""}={}){if(t==null)return"";const n=s?`${s} `:"";if(t<0){const a=Math.abs(t);return a===1?s?`${s} ××× ×ת×××`:"×××××ר ×××":a===2?s?`${s} ×¢×ר ××¤× × ××××××`:"×××××ר ××××××":s?`${s} ×¢×ר ××¤× × ${a} ××××`:`×××××ר ${a} ××××`}return t===0?s?`${s} ××××`:"××××":t===1?s?`${s} ××ר`:"××ר":t===2?`${n}×¢×× ××××××`:`${n}×¢×× ${t} ××××`}function Ql(t){return t==null?"none":t<0?"late":t<=3?"soon":t<=7?"week":"far"}const Lx={late:"bg-red-50 text-red-700 border-red-200",soon:"bg-emerald-50 text-emerald-700 border-emerald-200",week:"bg-cyan-50 text-cyan-700 border-cyan-200",far:"bg-sky-50 text-sky-700 border-sky-200",none:"bg-slate-50 text-slate-400 border-slate-200"};function Tx(t=[],{today:s=new Date}={}){const n=new Map;for(const o of t){const p=String((o==null?void 0:o.date)||"").slice(0,10);if(!/^\d{4}-\d{2}-\d{2}$/.test(p))continue;const u=n.get(p)||{date:p,count:0,sum:0,days:Tn(p,s)};u.count+=Number((o==null?void 0:o.count)??1)||0,u.sum+=Number(o==null?void 0:o.amount)||0,n.set(p,u)}const a=[...n.values()].sort((o,p)=>o.days-p.days),r=a.filter(o=>o.days>=0)[0]||a[0]||null;return{dates:a,next:r,mixed:a.length>1,count:a.reduce((o,p)=>o+p.count,0),sum:Math.round(a.reduce((o,p)=>o+p.sum,0)*100)/100}}function Bx(t,s){if(!s)return t;const n={...t,...s},a=String(s.due||"").slice(0,7);return a&&a!==t.month?{...n,month:a}:n}const Bn=t=>/^\d{4}-\d{2}$/.test(String(t||"").slice(0,7));function Rx(t){const s=String((t==null?void 0:t.billing_period)||"").slice(0,7);if(Bn(s))return s;const n=String((t==null?void 0:t.created_date)||"").slice(0,7);return Bn(n)?n:String((t==null?void 0:t.due_date)||"").slice(0,10).slice(0,7)}const Le=t=>(Number(t)||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),Ls=t=>{const s=String(t||"").slice(0,10),[n,a,l]=s.split("-");return l?`${l}/${a}/${n}`:"â"},qx=()=>new Date().toISOString().slice(0,10),Nl=t=>Bn(t)?Xs(String(t).slice(0,7)):String(t||""),Ts=`w-full h-11 rounded-xl border border-slate-200 bg-white px-3 text-[14px] text-slate-800 38 focus:outline-none focus:border-teal-500 focus:ring-4 focus:ring-teal-50 transition-colors`,Kt=({label:t,hint:s,required:n,children:a})=>e.jsxs("label",{className:"block min-w-0",children:[e.jsxs("span",{className:"block text-[12.5px] font-bold text-slate-600 mb-1.5",children:[t,n&&e.jsx("span",{className:"text-rose-500",children:" *"})]}),a,s&&e.jsx("span",{className:"block text-[11.5px] text-slate-400 mt-1.5",children:s})]});function vl({options:t,value:s,onChange:n,name:a}){return e.jsx("div",{className:`grid gap-3 ${t.length>1?"grid-cols-2":"grid-cols-1"}`,children:t.map(l=>{const r=s===l.v;return e.jsxs("button",{type:"button",role:"radio","aria-checked":r,name:a,onClick:()=>
38n(l.v),className:`h-14 px-4 rounded-2xl border-2 flex items-center gap-2.5 transition-colors ${r?"border-teal-500 bg-teal-50/70":"border-slate-200 bg-white hover:border-slate-300"}`,children:[e.jsx("span",{className:`w-5 h-5 rounded-full border-2 grid place-items-center flex-none ${r?"border-teal-600 bg-teal-600":"border-slate-300"}`,children:r&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-white"})}),e.jsx("span",{className:`text-[14px] font-bold ${r?"text-teal-800":"text-slate-500"}`,children:l.l})]},l.v)})})}const is=({children:t,note:s})=>e.jsxs("div",{className:"rounded-2xl bg-teal-50/70 border border-teal-100 px-4 py-3 flex items-start gap-3",children:[e.jsx("span",{className:"w-8 h-8 rounded-full bg-teal-600 text-white grid place-items-center flex-none",children:e.jsx(ye,{className:"w-4 h-4",strokeWidth:3})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-teal-900 leading-relaxed",children:t}),s&&e.jsx("span",{className:"block text-[12.5px] text-teal-700/80 mt-0.5",children:s})]})]}),en=({children:t})=>e.jsxs("p",{className:"rounded-2xl bg-sky-50/70 border border-sky-100 px-4 py-3 text-[13px] text-slate-600 flex items-start gap-3",children:[e.jsx(Un,{className:"w-4 h-4 text-sky-500 flex-none mt-0.5"}),e.jsx("span",{children:t})]}),ga=({label:t,children:s,tone:n=""})=>e.jsxs("span",{className:`px-3 py-1.5 rounded-xl text-center min-w-0 ${n||"bg-white/70"}`,children:[e.jsx("span",{className:"block text-[11px] font-bold text-slate-400 whitespace-nowrap",children:t}),e.jsx("span",{className:"block text-[13.5px] font-black text-slate-800 truncate",children:s})]}),Ix=[{v:"due_date",l:"ש×× ×× ×××¢×× ××××",hint:"×¢×××× ×××¢×× ×פקת ××ס×× ××תש×××",icon:Ld,card:"bg-teal-50/50 border-teal-100/80",icon_:"bg-teal-100 text-teal-600"},{v:"credit",l:"××××× ××××",hint:"××××× ××× ×× ×××§×",icon:wd,card:"bg-sky-50/50 border-sky-100/80",icon_:"bg-sky-100 text-sky-600"},{v:"cancel",l:"××××× ×××××",hint:"××××× ×§×××¢ ×× ××ספר ××××ר××",icon:Re,card:"bg-rose-50/50 border-rose-100/80",icon_:"bg-rose-100 text-rose-500"},{v:"add",l:"××ספת ××צר××",hint:"××ספת פר×××× ××ש××× ×××××",icon:kd,card:"bg-teal-50/50 border-teal-100/80",icon_:"bg-teal-100 text-teal-600"},{v:"back",l:"×××¨× ×פר×× ×××××",hint:"××× ××צ××¢ ש×× ××",icon:bs,card:"bg-sky-50/50 border-sky-100/80",icon_:"bg-sky-100 text-sky-600"}];function zx({charge:t,account:s,type:n,existing:a=[],onClose:l,onSave:r,onCancelException:o}){const p=!!n&&!["per_file","one_time"].includes(n.billing_cycle)&&n.calculation_method!=="water_meter"&&n.calculation_method!=="custom",u=Ix,[d,c]=i.useState("menu"),[m,h]=i.useState([{description:"",amount:""}]),[b,f]=i.useState(6),[x,g]=i.useState(()=>$r(t)?"now":"cycles"),[y,$]=i.useState({kind:"partial",amount:""}),[O,A]=i.useState(p?"temporary":"permanent"),[S,P]=i.useState(3),[E,k]=i.useState(String((t==null?void 0:t.due_date)||"").slice(0,10)||qx()),[C,w]=i.useState(""),[_,T]=i.useState(!1),[M,B]=i.useState(null),R=Number(t==null?void 0:t.amount)||0,j=Number((t==null?void 0:t._net)??(t==null?void 0:t.amount))||0,q=ad(n),L=$r(t),N=y.kind==="full"?Math.max(0,j):Number(y.amount)||0,v=nd(m),F=x==="now",K=x==="next",Z=F||K?1:Es(b),H=v.reduce((G,ne)=>G+ne.amount,0),z=H*Z,te=ld(t==null?void 0:t.due_date,S,q),ie=d==="due_date"?/^\d{4}-\d{2}-\d{2}$/.test(E)?E===String((t==null?void 0:t.due_date)||"").slice(0,10)?"××××¢× ×× ×©×× ×":null:"×ש ××××ר ×××¢× ×××× ×תש×××":d==="add"?v.length?F&&!L?"××××× ××ר × ××× â ×× × ××ª× ×××ס××£ ×× ×¤×¨××××":null:"×ש ××××× ×פ××ת ××צר ××× â ××תרת ××××ר":d==="credit"?N>0?N>R+.001?"×××××× ×××× ×ס××× ×××××":C.trim()?null:"×ש ××¤×¨× ×ת ס××ת ××××××":"×ש ××××× ×¡××× ×××××":d==="cancel"?C.trim()?null:"×ש ××¤×¨× ×ת ס××ת ××××××":"×ש ××××ר פע×××";function V(){const G={reason:C.trim(),payer_account_id:t==null?void 0:t.payer_account_id,charge_type_id:t==null?void 0:t.charge_type_id,charge_id:t==null?void 0:t.id};if(d==="due_date")return[{...G,exception_action:"due_date",due_date:E}];if(d==="add")return F?[{...G,exception_action:"add_now",lines:v}]:K?p?[{...G,exception_action:"add",cycles:1,lines:v}]:[{...G,exception_action:"add_next",lines:v}]:[{...G,exception_action:"add",cycles:Z,lines:v}];if(d==="credit")return[{...G,exception_action:"credit",discount_amount:0,credit_amount:N}];if(d==="cancel"){if(O==="temporary")return[{...G,exception_action:"skip",cycles:Es(S)}];const ne=[{...G,exception_action:"cancel"}];return p&&ne.push({...G,exception_action:"stop",cycles:1}),ne}return[]}const Y=()=>d==="due_date"?[`ת×ר×× ×××× ××ש××× ×©×× × ××××¢× ${Ls(E)}`]:d==="add"?[...v.map(G=>`× ×סף «${G.description}» â ${Le(G.amount)} âª`),F?`××××× ××× Â· ס×××× ×¢×××× ×-${Le(R+H)} âª`:K?"××××× ××× ×©××פק ××ש×××":`×-${Z} ×××××¨× ××××× ×××××`]:d==="credit"?[`${y.kind==="full"?"××××× ×××":"××××× ×××§×"} â ${Le(N)} âª`,"×§××× ×××××× ×××; ס××× ××××× ×¢×¦×× ×× ××©×ª× ×"]:d==="cancel"?O==="temporary"?[`××××× ××ש×× ×-${Es(S)} ${Es(S)===1?"××××ר":"××××ר××"}`,te?`×××× ×©×× ××××¢× ${Ls(te)}
38`:""].filter(Boolean):["××××× ×××× ×××¨× ××תרת ××ש×××",...p?["×××××ר×× ××××× × ×¤×¡×§×"]:[]]:[];i.useEffect(()=>{const G=document.documentElement,ne=[G.style.overflow,document.body.style.overflow];return G.style.overflow="hidden",document.body.style.overflow="hidden",()=>{G.style.overflow=ne[0],document.body.style.overflow=ne[1]}},[]),i.useEffect(()=>{const G=ne=>{ne.key==="Escape"&&(d==="menu"||M?l():c("menu"))};return document.addEventListener("keydown",G),()=>document.removeEventListener("keydown",G)},[l,d,M]);const J=async()=>{if(!(ie||_)){T(!0);try{const G=Y();await r(V()),B(G)}catch{}finally{T(!1)}}},I=u.find(G=>G.v===d),X=(s==null?void 0:s.name)||(t==null?void 0:t._account)||"",se=(s==null?void 0:s.account_number)||(t==null?void 0:t._accountNumber)||"";return Pt.createPortal(e.jsx("div",{dir:"rtl",className:"fixed inset-0 z-[80] bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-3 sm:p-5",onClick:l,children:e.jsxs("div",{className:"bg-white rounded-3xl shadow-2xl w-full max-w-2xl flex flex-col max-h-[94vh] overflow-hidden",onClick:G=>G.stopPropagation(),children:[e.jsxs("header",{className:"flex items-center gap-3 px-6 pt-5 pb-4 flex-none bg-gradient-to-l from-teal-50/80 via-sky-50/40 to-transparent",children:[e.jsx("span",{className:"w-11 h-11 rounded-2xl bg-teal-100/80 text-teal-700 grid place-items-center flex-none",children:d==="menu"&&!M?e.jsx(zn,{className:"w-5 h-5"}):e.jsx(De,{className:"w-5 h-5"})}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-[20px] font-black text-slate-900 truncate",children:M?"×ש×× ×× × ×©×ר":(I==null?void 0:I.l)||"× ×××× ×××× â ××ר פע×××"}),e.jsx("span",{className:"block text-[13px] text-slate-500 truncate",children:[X,se&&`×ש××× ${se}`].filter(Boolean).join(" · ")||"××××"})]}),e.jsx("button",{type:"button",onClick:d==="menu"||M?l:()=>c("menu"),"aria-label":d==="menu"||M?"ס××ר×":"×××¨× ×פע×××ת",className:"w-10 h-10 rounded-2xl bg-white border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50 flex-none",children:d==="menu"||M?e.jsx($e,{className:"w-4 h-4"}):e.jsx(bs,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"mx-6 rounded-2xl bg-slate-50 border border-slate-100 px-2 py-2 flex items-center justify-between gap-1 flex-none overflow-x-auto",children:[e.jsx(ga,{label:"ס×× ×ª×©×××",tone:"bg-sky-50",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Ke,{className:"w-3.5 h-3.5 text-sky-500 flex-none"}),(t==null?void 0:t._type)||(n==null?void 0:n.name)||"â"]})}),e.jsx(ga,{label:"ס××× ××××",children:e.jsxs("span",{className:"tabular-nums",dir:"ltr",children:[Le(j)," âª"]})}),(t==null?void 0:t.billing_period)&&e.jsx(ga,{label:"תק×פ×",children:Nl(t.billing_period)}),e.jsx(ga,{label:"×××¢× ××××",children:e.jsx("span",{className:"tabular-nums",dir:"ltr",children:Ls(t==null?void 0:t.due_date)})}),(t==null?void 0:t._status)&&e.jsx(ga,{label:"ס×××ס",tone:"bg-emerald-50",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-emerald-700",children:[e.jsx(xt,{className:"w-3.5 h-3.5 flex-none"}),t._status]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-6 py-4 space-y-4",children:M?e.jsx("div",{className:"rounded-2xl border border-teal-100 bg-teal-50/60 p-4",children:e.jsxs("ul",{className:"space-y-1.5",children:[M.map(G=>e.jsxs("li",{className:"text-[14px] font-bold text-teal-900 flex items-start gap-2",children:[e.jsx(ye,{className:"w-4 h-4 text-teal-600 flex-none mt-0.5",strokeWidth:3})," ",G]},G)),C.trim()&&e.jsxs("li",{className:"text-[12.5px] text-teal-700/80 flex items-start gap-2 pt-1",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-teal-400 flex-none mt-1.5"}),"×ס××× ×©× ×¨×©××: ",C.trim()]})]})}):d==="menu"?e.jsxs(e.Fragment,{children:[[u.slice(0,3),u.slice(3)].map((G,ne)=>G.length===0?null:e.jsx("div",{className:`grid grid-cols-1 gap-3 ${G.length>=3?"sm:grid-cols-3":G.length===2?"sm:grid-cols-2":""}`,children:G.map(ge=>{const ke=ge.icon;return e.jsxs("button",{type:"button",onClick:()=>ge.v==="back"?l():c(ge.v),className:`rounded-2xl border p-4 text-center flex flex-col items-center gap-2 transition-all 39 hover:shadow-md hover:-translate-y-0.5 ${ge.card}`,children:[e.jsx("span",{className:`w-12 h-12 rounded-full grid place-items-center flex-none ${ge.icon_}`,children:e.jsx(ke,{className:"w-6 h-6",strokeWidth:1.9})}),e.jsx("span",{className:"block text-[15px] font-black text-slate-800 leading-tight",children:ge.l}),e.jsx("span",{className:"block text-[11.5px] text-slate-400 leading-snug",children:ge.hint})]},ge.v)})},ne)),a.length>0&&e.jsxs("section",{className:"rounded-2xl border border-amber-200 bg-amber-50/60 p-3.5",children:[e.jsx("p",{className:"text-[12.5px] font-black text-amber-800 mb-1.5",children:a.length===1?"××ר×× ×¤×¢××× ×¢× ××××× ×××":`${a.length} ××ר××ת פע×××ת ×¢× ××××× ×××`}),e.jsx("ul",{className:"space-y-2",children:a.map(G=>{const ne=rd(G);return e.jsxs("li",{className:"flex items-start gap-2 text-[12.5px] text-slate-700",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-bold text-slate-900",children:ne.text}),e.jsxs("span",{className:"block text-[11.5px] text-slate-500",children:[[ne.by&&`×¢× ××× ${ne.by}
39`,ne.at].filter(Boolean).join(" · "),G.from_period&&` · ${Xs(G.from_period)}${G.through_period?` â ${Xs(G.through_period)}`:" ×××××"}`,G.reason&&` · ${G.reason}`]})]}),o&&e.jsxs("button",{type:"button",onClick:()=>o(G.id),className:"mr-auto flex-none inline-flex items-center gap-1 text-[11.5px] font-bold text-rose-600 hover:text-rose-800",children:[e.jsx(Re,{className:"w-3.5 h-3.5"})," ××××× ×××ר××"]})]},G.id)})})]})]}):d==="due_date"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-2xl border border-slate-200 p-4",children:e.jsx(Kt,{label:"×××¢× ×××× ×תש×××",hint:`××××¢× ×× ××××: ${Ls(t==null?void 0:t.due_date)}`,children:e.jsx("input",{type:"date",value:E,className:`${Ts} tabular-nums`,onChange:G=>k(G.target.value)})})}),E!==String((t==null?void 0:t.due_date)||"").slice(0,10)&&e.jsxs(is,{note:"×ס××× ××××××ר×× ××××× ××× × ××שפע××.",children:["ת×ר×× ×××× ××ש××× ×ש×× × ××××¢× ",e.jsx("b",{className:"tabular-nums",dir:"ltr",children:Ls(E)}),t!=null&&t.billing_period?` (${Nl(t.billing_period)})`:"","."]}),e.jsx(en,{children:"×××¢× ×פקת ×ס×× ×ר×שת ×תש××× × ×§××¢ ×ס×× ××××× ×××× × ××©×ª× × ×××."})]}):d==="credit"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4 space-y-4",children:[e.jsx(vl,{name:"credit-kind",options:[{v:"partial",l:"××××× ×××§×"},{v:"full",l:"××××× ×××"}],value:y.kind,onChange:G=>$(ne=>({...ne,kind:G}))}),y.kind==="partial"?e.jsx(Kt,{label:"ס××× ××××××",hint:`× ××ª× ×תת ××××× ×¢× ×××× ×¡××× ×××××: ${Le(R)} âª`,children:e.jsxs("span",{className:"flex items-stretch",children:[e.jsx("span",{className:"w-11 rounded-r-xl border border-l-0 border-slate-200 bg-slate-50 grid place-items-center text-[13px] font-bold text-slate-400 flex-none",children:"âª"}),e.jsx("input",{type:"number",min:"0",step:"0.01",max:R,value:y.amount,placeholder:"0.00",dir:"ltr",className:`${Ts} tabular-nums rounded-r-none text-left`,onChange:G=>$(ne=>({...ne,amount:G.target.value}))})]})}):e.jsxs("p",{className:"text-[13.5px] text-slate-600",children:["××××× ×××× ×ס××× ×תש××× â ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(j)," âª"]}),"."]}),e.jsx(Kt,{label:"ס××ת ××××××",required:!0,children:e.jsx("textarea",{value:C,onChange:G=>w(G.target.value),rows:3,maxLength:500,placeholder:"×ש ××¤×¨× ×ת ס××ת ××××××",className:`w-full rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-[14px] text-slate-800 resize-none 40 focus:outline-none focus:border-teal-500 focus:ring-4 focus:ring-teal-50 transition-colors`})})]}),N>0&&e.jsxs(is,{children:["××××× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(N)," âª"]})," ××§××× ×××××× ×××. ס××× ××××× ×¢×¦×× ××× × ××©×ª× ×."]}),e.jsx(en,{children:"××ס×× ×ר×שת ×תש××× ×××ס×× ××××× ×ª×ª××סף ש×רת ××××× ×ת×ת ×ש×רת ×××××."})]}):d==="cancel"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-[15px] font-black text-slate-900 mb-2.5",children:"ס×× ××××××"}),e.jsx(vl,{name:"cancel-kind",options:[...p?[{v:"temporary",l:"××××× ××××ר×"}]:[],{v:"permanent",l:"××××× ×§×××¢"}],value:O,onChange:A})]}),O==="temporary"&&e.jsx(Kt,{label:"×ספר ××××ר××",children:e.jsx("input",{type:"number",min:"1",max:Cr,value:S,dir:"ltr",className:`${Ts} tabular-nums text-left`,onChange:G=>P(G.target.value)})})]}),O==="temporary"?e.jsxs(is,{children:["××××× ××ש×× ×-",Es(S)," ",Es(S)===1?"××××ר":"××××ר××",te?e.jsxs(e.Fragment,{children:[" ×××× ×©×× ××××¢× ",e.jsx("b",{className:"tabular-nums",dir:"ltr",children:Ls(te)})]}):"","."]}):e.jsx(is,{note:p?"××××××ר×× ××××× ××פסק×.":null,children:"××××× ×××××, ×××¨× ××תרת ××ש××× ×××ש×ר ××ר×סת ×ס××× ××××××."}),e.jsx("div",{className:"rounded-2xl border border-slate-200 p-4",children:e.jsx(Kt,{label:"ס××ת ××××××",required:!0,children:e.jsx("textarea",{value:C,onChange:G=>w(G.target.value),rows:3,maxLength:500,placeholder:"×ש ××¤×¨× ×ת ס××ת ××××××",className:`w-full rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-[14px] text-slate-800 resize-none 41 focus:outline-none focus:border-teal-500 focus:ring-4 focus:ring-teal-50 transition-colors`})})}),e.jsx(en,{children:"××××× ×§×××¢ ×ס×ר ×ת ××××× ×××ש×××. ××××× ×××××¨× ×ש×× ×××ª× ××× ×ת."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4 space-y-3",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[15px] font-black text-slate-900",children:"××צר×× ×××××"}),e.jsx("button",{type:"button","aria-label":"××ספת ××צר × ×סף",title:"××ספת ××צר × ×סף",onClick:()=>h(G=>[...G,{description:"",amount:""}]),className:`mr-auto w-9 h-9 rounded-xl bg-teal-50 border border-teal-200 text-teal-700 42 grid place-items-center flex-none hover:bg-teal-100 transition-colors`,children:e.jsx(We,{className:"w-4 h-4",strokeWidth:2.5})})]}),m.map((G,ne)=>e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-3 flex items-end gap-2",children:[e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(Kt,{label:"××תרת ×××צר",children:e.jsx("input",{value:G.description,placeholder:"××××××: ××× ×ª××××§×",className:Ts,onChange:ge=>h(ke=>ke.map((be,je)=>je===ne?{...be,description:ge.target.value}:be))})})}),e.jsx("div",{className:"w-36 flex-none",children:e.jsx(Kt,{label:"×××ר",children:e.jsxs("span",{className:"flex items-stretch",children:[e.jsx("span",{className:"w-10 rounded-r-xl border border-l-0 border-slate-200 bg-slate-50 grid place-items-center text-[13px] font-bold text-slate-400 flex-none",children:"âª"}),e.jsx("input",{type:"number",min:"0",step:"0.01",value:G.amount,placeholder:"0.00",dir:"ltr",className:`${Ts} tabular-nums rounded-r-none text-left`,onChange:ge=>h(ke=>ke.map((be,je)=>je===ne?{...be,amount:ge.target.value}:be))})]})})}),e.jsx("button",{type:"button","aria-label":"×סרת ×××צר",disabled:m.length===1,onClick:()=>h(ge=>ge.filter((ke,be)=>be!==ne)),className:`w-11 h-11 rounded-xl bg-rose-50 border border-rose-100 grid place-items-center text-rose-500 43 hover:bg-rose-100 disabled:opacity-30 flex-none`,children:e.jsx(Re,{className:"w-4 h-4"})})]},ne))]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 p-4 space-y-3",children:[e.jsx("span",{className:"block text-[15px] font-black text-slate-900",children:"××ר ×××ס××£ ×××××"}),e.jsx(vl,{name:"add-span",options:[...L?[{v:"now",l:"××××× ×× ××××"}]:[],{v:"next",l:"××××× ×××"},...p?[{v:"cycles",l:"××××××¨× ××××"}]:[]],value:x,onChange:g}),!F&&!K&&p&&e.jsx(Kt,{label:"×ספר ××××××",children:e.jsx("input",{type:"number",min:"1",max:Cr,value:b,dir:"ltr",className:`${Ts} tabular-nums text-left`,onChange:G=>f(G.target.value)})})]}),v.length>0&&(F?e.jsxs(is,{note:`ס××× ××××× ××¢×××× ×-${Le(R)} ⪠×-${Le(R+H)} âª.`,children:[v.length===1?e.jsxs(e.Fragment,{children:["××צר ××× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(H)," âª"]}
43)," ×ת××סף"]}):e.jsxs(e.Fragment,{children:[v.length," ××צר×× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(H)," âª"]})," ×ת××ספ×"]})," ","××××× ×××",t!=null&&t.billing_period?` (${Nl(t.billing_period)})`:"","."]}):K?e.jsxs(is,{note:p?"××××× ××× ××× × ××©×ª× ×.":"×פר×××× ××ת×× × ×¢× ×××¢×× ×ª ××§×××¥ ×××, ××××× ×¡× ××××× ×©××××צר ××× ×.",children:[v.length===1?e.jsxs(e.Fragment,{children:["××צר ××× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(H)," âª"]})," ×ת××סף"]}):e.jsxs(e.Fragment,{children:[v.length," ××צר×× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(H)," âª"]})," ×ת××ספ×"]})," ","××××× ××× ×©××פק ××ש×××, ×¤×¢× ××ת."]}):e.jsxs(is,{note:Z>1?`ס××´× ×ª×ספת צפ×××: ${Le(z)} âª`:null,children:[v.length===1?e.jsxs(e.Fragment,{children:["××צר ××× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(H)," âª"]})]}):e.jsxs(e.Fragment,{children:[v.length," ××צר×× ××¡× ",e.jsxs("b",{className:"tabular-nums",dir:"ltr",children:[Le(H)," âª"]})]})," ",v.length===1?"×ת××סף":"×ת××ספ×"," ×-",Z," ×××××¨× ××××× ×××××."]})),e.jsx(en,{children:L?F?"×× ×¢×× ×× ××פק ×ס×× ×××× ×××ש×ר תש×××, ×פר×××× × ×× ×¡×× ××××× ×× ×××× ××ס×× ×ר×שת ×תש××× ××× ×¤×§ ×××ש ××××× ××ת×.":K?"×××ר×× ××ת×× × ×¢× ×©××פק ××××× ××× ××ש×××, × ×× ×¡×ª ×××× ×¤×¢× ××ת ××× ×סת×××ת. ××× ××צ×ת ×¢× ×× ×רש××ת ×××ר××ת ×פע×××ת, ××פשר ×××× ××ת×.":"×פר×××× ×ת×××¡×¤× ××× ××× ××××××ר×× ×©× ××ר×. ××××× ××× ××× × ××©×ª× ×.":"××××× ××× ××ר × ×××, ×××× ×× × ××ª× ×××ס××£ ×× ×¤×¨×××× â ×ס×× ×©××ר × ×סר ××× × ××©×ª× ×. ת×ספת ת××× ×¡ ××××× ×××."})]})}),e.jsxs("footer",{className:"flex items-center gap-3 px-6 py-4 flex-none border-t border-slate-100",children:[M?e.jsx("button",{type:"button",onClick:l,className:"h-12 px-8 rounded-2xl bg-teal-600 text-white text-[15px] font-bold hover:bg-teal-700",children:"ס××ר"}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:J,disabled:!!ie||_,title:ie||"",className:`h-12 flex-1 rounded-2xl bg-teal-600 text-white text-[15px] font-bold inline-flex items-center justify-center gap-2 44 hover:bg-teal-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:[_?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):d==="menu"?null:e.jsx(ye,{className:"w-4 h-4",strokeWidth:3}),"×¢××× ×©×× ××××"]}),e.jsx("button",{type:"button",onClick:l,className:"h-12 px-8 rounded-2xl border border-slate-200 text-slate-600 text-[15px] font-bold hover:bg-slate-50",children:"×××××"})]}),!M&&ie&&d!=="menu"&&e.jsx("span",{className:"text-[11.5px] text-slate-400 flex-none max-w-[12rem] truncate",children:ie})]})]})}),document.body)}const ce=t=>Math.round(((Number(t)||0)+Number.EPSILON)*100)/100,Qs=t=>Number.isFinite(Number(t))?Number(t):0,Qn=t=>String(t||"").slice(0,7),na=t=>Math.max(0,ce(Qs(t==null?void 0:t.amount)-Qs(t==null?void 0:t.discount_amount)-Qs(t==null?void 0:t.credit_amount))),Gt=t=>(t==null?void 0:t.status)!=="cancelled",Kx=t=>{const s=String(t||"").match(/(\d{4})(\d{2})$/);return s?`${s[1]}-${s[2]}`:""};function xa({statements:t=[],payments:s=[],charges:n=[]}={}){const a=new Set(t.filter(h=>(h==null?void 0:h.status)==="paid").map(h=>h.id)),l=new Map(t.map(h=>[h.id,String((h==null?void 0:h.billing_month)||"")])),r=new Map;for(const h of s){if(!["paid","partial"].includes(h==null?void 0:h.status))continue;const b=l.get(h.statement_id)||Kx(h.reference_number);if(!b||!h.payer_account_id)continue;const f=`${h.payer_account_id}|${b}`;r.set(f,ce((r.get(f)||0)+Qs(h.amount)))}const o=new Map;for(const h of n){if(!Gt(h))continue;const b=String((h==null?void 0:h.billing_period)||"");if(!b||!h.payer_account_id)continue;const f=`${h.payer_account_id}|${b}`;o.set(f,ce((o.get(f)||0)+na(h)))}const p=h=>`${(h==null?void 0:h.payer_account_id)||""}|${String((h==null?void 0:h.billing_period)||"")}`,u=h=>{const b=p(h),f=r.get(b)||0;return f>0?f+.01>
44=(o.get(b)||0):!1},d=h=>!!h&&Gt(h)&&(!!h.statement_id&&a.has(h.statement_id)||u(h)),c=h=>{if(!h||!Gt(h))return 0;if(d(h))return 1;const b=p(h),f=o.get(b)||0;return f>0?Math.min(1,(r.get(b)||0)/f):0};return{isPaid:d,paidOf:h=>Gt(h)?ce(na(h)*c(h)):0,coverOf:c}}const Wx=[{v:"credit",l:"×ר××ס ×שר××",color:"#3b82f6"},{v:"standing_order",l:"××ר×ת ×§××¢",color:"#0d9488"},{v:"bank_transfer",l:"××¢××¨× ×× ×§××ת",color:"#6ee7b7"},{v:"bit",l:"×××",color:"#8b5cf6"},{v:"cash",l:"×××××",color:"#f59e0b"},{v:"check",l:"×××××",color:"#94a3b8"},{v:"other",l:"××ר",color:"#cbd5e1"}];function Ux({payments:t=[],inRange:s=()=>!0}={}){const n=new Map(Wx.map(a=>[a.v,{key:a.v,label:a.l,color:a.color,count:0,gross:0,fee:0,net:0,byMonth:{}}]));for(const a of t){if(!["paid","partial"].includes(a==null?void 0:a.status))continue;const l=a.payment_date||a.created_date;if(!s(l))continue;const r=n.has(a.payment_method)?a.payment_method:"other",o=n.get(r),p=ce(Qs(a.amount)),u=ce(Qs(a.fee_amount??a.commission));o.count+=1,o.gross=ce(o.gross+p),o.fee=ce(o.fee+u),o.net=ce(o.gross-o.fee);const d=Qn(l);d&&(o.byMonth[d]=ce((o.byMonth[d]||0)+p))}return[...n.values()].filter(a=>a.count>0).sort((a,l)=>l.gross-a.gross)}function Hx(t=[]){var a;const s=ce(t.reduce((l,r)=>l+r.gross,0)),n=ce(t.reduce((l,r)=>l+r.fee,0));return{count:t.reduce((l,r)=>l+r.count,0),gross:s,fee:n,net:ce(s-n),leader:((a=t[0])==null?void 0:a.label)||"â",hasFees:t.some(l=>l.fee>0)}}const ya=(t,s)=>s>0?ce(t.gross/s*100):0;function Yx({charges:t=[],accounts:s=[],types:n=[],isPaid:a=()=>!1,today:l=new Date}={}){var d;const r=typeof l=="string"?l.slice(0,10):l.toISOString().slice(0,10),o=new Map(s.map(c=>[c.id,c])),p=new Map(n.map(c=>[c.id,c])),u=[];for(const c of t){if(!Gt(c))continue;const m=String(c.due_date||"").slice(0,10);if(!m||m>=r||a(c))continue;const h=na(c);if(h<=.005)continue;const b=o.get(c.payer_account_id);u.push({id:c.id,payer:(b==null?void 0:b.name)||"××× ×ש×××",account:(b==null?void 0:b.account_number)||"",type:((d=p.get(c.charge_type_id))==null?void 0:d.name)||"â",dueDate:m,days:Math.max(0,Math.round((Date.parse(`${r}T00:00:00Z`)-Date.parse(`${m}T00:00:00Z`))/864e5)),balance:h,month:Qn(m)})}return u.sort((c,m)=>m.days-c.days||m.balance-c.balance)}function Vx(t=[]){const s=ce(t.reduce((n,a)=>n+a.balance,0));return{count:t.length,balance:s,avgDays:s>0?Math.round(t.reduce((n,a)=>n+a.days*a.balance,0)/s):0}}function Gx(t=[],s=[]){const n=new Map(s.map(a=>[a,{month:a,amount:0,count:0}]));for(const a of t){const l=n.get(a.month);l&&(l.amount=ce(l.amount+a.balance),l.count+=1)}return[...n.values()]}function Xx({charges:t=[],types:s=[],paidOf:n=()=>0,inRange:a=()=>!0,names:l={},groupUnassigned:r=!1}={}){const o=new Map(s.map(c=>[c.id,c])),p=new Map,u=c=>{const m=Jl(c);return m?`budget:${m}`:r?"none":c?`type:${c.id}`:"none"},d=c=>{const m=Jl(c);return m?l[m]||(c==null?void 0:c.budget_item_name)||`סע××£ ${m}`:r?"××× ×¡×¢××£ תקצ×××":(c==null?void 0:c.name)||"××× ×¡×¢××£"};for(const c of s){const m=u(c);p.has(m)||p.set(m,{key:m,name:d(c),count:0,billed:0,collected:0,balance:0,budget:c.budget_amount==null?null:ce(c.budget_amount)})}for(const c of t){if(!Gt(c))continue;const m=c.due_date||c.created_date;if(!a(m))continue;const h=o.get(c.charge_type_id);if(!h)continue;const b=u(h);p.has(b)||p.set(b,{key:b,name:d(h),count:0,billed:0,collected:0,balance:0,budget:null});const f=p.get(b),x=na(c);f.count+=1,f.billed=ce(f.billed+x),f.collected=ce(f.collected+n(c)),f.balance=ce(Math.max(0,f.billed-f.collected))}return[...p.values()].sort((c,m)=>m.billed-c.billed)}function Zx(t=[]){const s=t.filter(n=>n.budget!=null);return{lines:t.filter(n=>n.count>0).length,count:t.reduce((n,a)=>n+a.count,0),billed:ce(t.reduce((n,a)=>n+a.billed,0)),collected:ce(t.reduce((n,a)=>n+a.collected,0)),balance:ce(t.reduce((n,a)=>n+a.balance,0)),budget:s.length?ce(s.reduce((n,a)=>n+a.budget,0)):null}}const Jl=t=>(t==null?void 0:t.sumit_budget_item_id)||(t==null?void 0:t.budget_item_id)||null,wl=t=>t.billed>0?ce(t.collected/t.billed*100):0,fc=95;function Qx({charges:t=[],months:s=[],paidOf:n=()=>0}={}){const a=new Map(s.map(l=>[l,{month:l,billed:0,collected:0,balance:0,rate:0}]));for(const l of t){if(!Gt(l))continue;const r=Qn(l.due_date||l.created_date),o=a.get(r);o&&(o.billed=ce(o.billed+na(l)),o.collected=ce(o.collected+n(l)))}for(const l of a.values())l.balance=ce(Math.max(0,l.billed-l.collected)),l.rate=l.billed>0?ce(l.collected/l.billed*100):0;return[...a.values()]}function Jx(t=[]){const s=ce(t.reduce((a,l)=>a+l.billed,0)),n=ce(t.reduce((a,l)=>a+l.collected,0));return{billed:s,collected:n,balance:ce(Math.max(0,s-n)),rate:s>0?ce(n/s*100):0}}function kl(t,s=fc){return t>0?t>=s?{v:"above",l:"××¢× ×××¢×",tone:"emerald"}:t>=s-2?{v:"near",l:"קר×× ×××¢×",tone:"emerald"}:{v:"below",l:"×ת×ת ×××¢×",tone:"rose"}:{v:"none",l:"â",tone:"slate"}}function ep({charges:t=[],months:s=[],paidOf:n=()=>0,typeOf:a=()=>""}={}){const l=new Map(s.map(o=>[o,{month:o,count:0,billed:0,collected:0,balance:0,rate:0,mainDate:"",dates:0,types:[],_byDate:new Map,_byType:new Map}]));for(const o of t){if(!Gt(o))continue;const p=String(o.due_date||"").slice(0,10),u=l.get(Qn(p));if(!u)continue;const d=na(o);u.count+=1,u.billed=ce(u.billed+d),u.collected=ce(u.collected+n(o)),u._byDate.set(p,ce((u._byDate.get(p)||0)+d));const c=a(o)||"××× ×¡××",m=u._byType.get(c)||{name:c,count:0,amount:0};m.count+=1,m.amount=ce(m.amount+d),u._byType.set(c,m)}const r=[];for(const o of l.values()){const{_byDate:p,_byType:u,...d}=o;d.balance=ce(Math.max(0,d.billed-d.collected)),d.rate=d.billed>0?ce(d.collected/d.billed*100):0,d.dates=p.size;let c="",m=-1;for(const[h,b]of[...p.entries()].sort((f,x)=>String(f[0]).localeCompare(String(x[0]))))b>m&&(m=b,c=h);d.mainDate=c,d.types=[...u.values()].sort((h,b)=>b.amount-h.amount||b.count-h.count),r.push(d)}return r}function tp(t=[],s=[]){const n=ce(t.reduce((r,o)=>r+o.billed,0)),a=ce(t.reduce((r,o)=>r+o.collected,0)),l=s.length||t.length||0;return{count:t.reduce((r,o)=>r+o.count,0),months:t.filter(r=>r.count>0).length,billed:n,collected:a,balance:ce(Math.max(0,n-a)),rate:n>0?ce(a/n*100):0,avg:l>0?ce(n/l):0}}const Ge=t=>
44(Number(t)||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),Ni=()=>new Date().toISOString().slice(0,10),sp={draft:"×××××",pending:"××ת×× ×××ש×ר",approved:"×××שר",issued:"××פק",cancelled:"××××",credited:"××××"},ap={ש×××:"bg-emerald-50 text-emerald-700 border-emerald-200",×××××ר:"bg-red-50 text-red-700 border-red-200",×תש×××:"bg-amber-50 text-amber-700 border-amber-200","××ת×× ×××ש×ר":"bg-violet-50 text-violet-700 border-violet-200",×××××:"bg-slate-100 text-slate-500 border-slate-200",××××:"bg-slate-100 text-slate-400 border-slate-200",××××:"bg-purple-50 text-purple-700 border-purple-200"},np=t=>ap[t]||"bg-slate-100 text-slate-500 border-slate-200";function lp({cancelled:t,relief:s,marks:n=[]}){const a=new Set;return t&&a.add("××××"),s>0&&a.add(`×××× ${Ge(s)} âª`),n.forEach(l=>{var o;const r=(o=uo[l.action])==null?void 0:o.note;!r||r==="×××××"||r==="××××"||a.add(r)}),[...a]}const er=t=>Bn(t)?xs(String(t).slice(0,7)):t||"â",Sl=[{v:"lines",l:"×פ×ר×",full:"×פ×ר×"},{v:"type",l:"ס×× ××××",full:"××¤× ×¡×× ××××"},{v:"payer",l:"×ש××",full:"××¤× ×ש××"},{v:"period",l:"תק×פ×",full:"××¤× ×ª×§×פ×"}];function rp({kibbutzId:t,settings:s,initialFilter:n}){var be,je,Ce;const[a,l]=i.useState(!0),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState([]),[b,f]=i.useState([]),[x,g]=i.useState([]),[y,$]=i.useState([]),[O,A]=i.useState([]),[S,P]=i.useState(null),[E,k]=i.useState(null),[C,w]=i.useState(null),[_,T]=i.useState([]),M=i.useRef(!1),B={mode:"lines",type:"",status:"",month:Ni().slice(0,7),q:"",due:""},[R,j]=i.useState(()=>Bx(B,n)),q=(ee,oe)=>j(le=>({...le,[ee]:oe})),L=i.useCallback(async()=>{l(!0);try{const[ee,oe,le,xe,de,ae,Ne,we,Ue]=await Promise.all([D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.MonthlyStatement.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[]),D.functions.invoke("recurringBilling",{action:"exceptions",community_id:t}).then(re=>{var Qe;return((Qe=re==null?void 0:re.data)==null?void 0:Qe.exceptions)||[]}).catch(()=>[]),D.entities.AccountPaymentMethod.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeTypePaymentMethod.filterAll({kibbutz_id:t}).catch(()=>[])]);o(ee||[]),u(oe||[]),c(le||[]),h(xe||[]),f(de||[]),g(ae||[]),T(Ne||[]),$(we||[]),A(Ue||[])}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{l(!1)}},[t]);i.useEffect(()=>{L()},[L]);const N=i.useMemo(()=>new Map(p.map(ee=>[ee.id,ee])),[p]),v=i.useMemo(()=>ur(y,O),[y,O]),F=i.useMemo(()=>zt(r,p,{ready:!a}),[r,p,a]),K=i.useMemo(()=>new Map(d.map(ee=>[ee.id,ee])),[d]),Z=i.useMemo(()=>new Map(m.map(ee=>[ee.id,ee])),[m]),H=i.useMemo(()=>new Map(b.map(ee=>[ee.id,ee])),[b]),z=i.useMemo(()=>xa({statements:b,payments:x,charges:F}),[b,x,F]),te=i.useMemo(()=>{const ee=new Set(F.map(oe=>oe.charge_type_id).filter(Boolean));return p.filter(oe=>ee.has(oe.id))},[F,p]),ie=i.useMemo(()=>{const ee=Ni();return F.map(oe=>{var He;const le=K.get(oe.payer_account_id),xe=le!=null&&le.family_id?Z.get(le.family_id):null,de=N.get(oe.charge_type_id),ae=z.isPaid(oe),{gross:Ne,discount:we,credit:Ue,relief:re,net:Qe,cancelled:Et,paid:bt,open:ue,overdue:Ee,status:za}=qu(oe,{paid:ae,today:ee,labels:sp}),Ps=id(_,{accountId:oe.payer_account_id,typeId:oe.charge_type_id,chargeId:oe.id});return{...oe,_account:le?le.name||`#${le.account_number}`:"××× ×ש×××",_accountNumber:(le==null?void 0:le.account_number)||"",_family:(xe==null?void 0:xe.name)||"",_type:(de==null?void 0:de.name)||"â",_kindNote:Sm(de),_typeId:oe.charge_type_id||"",_method:Oa(de==null?void 0:de.calculation_method),_gross:Ne,_discount:we,_credit:Ue,_net:Qe,_open:ue,_overdue:Ee,_statement:((He=H.get(oe.statement_id))==null?void 0:He.billing_month)||"",_paid:bt,_status:za,_relief:re,_marks:Ps,_changes:lp({cancelled:Et,relief:re,marks:Ps})}})},[F,K,Z,N,H,z,_]),V=i.useMemo(()=>
44{if(!R.month)return 0;const{from:ee,to:oe}=xi(R.month);return ie.filter(le=>le._open&&(String(le.due_date||"")<ee||String(le.due_date||"9999")>oe)).length},[ie,R.month]),Y=i.useMemo(()=>{const ee=R.q.trim(),{from:oe,to:le}=xi(R.month);return ie.filter(xe=>!(R.type&&xe.charge_type_id!==R.type||R.status==="open"&&!xe._open||R.status==="paid"&&!xe._paid||R.status==="overdue"&&!xe._overdue||R.status==="cancelled"&&xe.status!=="cancelled"||oe&&String(xe.due_date||"")<oe||le&&String(xe.due_date||"9999")>le||ee&&![xe._account,xe._accountNumber,xe._family,xe._type,xe.description,xe.billing_period].join(" ").includes(ee)))},[ie,R]),J=i.useMemo(()=>R.due?Y.filter(ee=>ee._open&&String(ee.due_date||"").slice(0,10)===R.due):Y,[Y,R.due]),I=i.useMemo(()=>({status:Te(ie,{open:ee=>ee._open,paid:ee=>ee._paid,overdue:ee=>ee._overdue})}),[ie]),X=i.useMemo(()=>new Set(F.map(ee=>String(ee.due_date||"").slice(0,7)).filter(ee=>ee.length===7)),[F]),se=i.useRef(!1);i.useEffect(()=>{if(!(se.current||a||n!=null&&n.due)){if(!R.month){se.current=!0;return}!X.size||X.has(R.month)||(se.current=!0,j(ee=>({...ee,month:[...X].sort().pop()})))}},[a,X,R.month,n]);const G=i.useMemo(()=>Y.filter(ee=>ee._open&&ee.due_date).map(ee=>({date:ee.due_date,count:1,amount:ee._net})),[Y]),ne=(ee,oe,le={})=>({key:ee,header:oe,width:13,type:"money",total:!0,...le}),ge=i.useMemo(()=>{const ee=J.some(ae=>ae._relief>0);if(R.mode==="lines")return{rows:[...J].sort((ae,Ne)=>String(Ne.due_date||Ne.created_date||"").localeCompare(String(ae.due_date||ae.created_date||""))),columns:[{key:"_account",header:"×ש××× ×ש××",width:24,strong:!0},{key:"_accountNumber",header:"×ס׳ ×ש×××",width:11,muted:!0,off:!0},{key:"_type",header:"ס×× ××××",width:18,render:ae=>e.jsxs("span",{className:"block min-w-0",children:[e.jsx("span",{className:"block font-bold text-slate-800 truncate",children:ae._type}),ae._kindNote&&e.jsx("span",{className:"block text-[11px] text-slate-400 truncate",children:ae._kindNote})]})},{key:"_method",header:"ש××ת ××ש××",width:16,muted:!0,off:!0},{key:"billing_period",header:"תק×פ×",width:16,render:ae=>er(ae.billing_period)},{key:"description",header:"ת×××ר",width:26,muted:!0,clamp:!0,off:!0},{key:"quantity",header:"×××ת",width:9,type:"num",off:!0},{key:"rate",header:"תער××£ (âª)",width:11,type:"dec3",off:!0},ne("_gross","ס××× (âª)"),ne("_discount","×× ×× (âª)",{off:!ee}),ne("_credit","××××× (âª)",{off:!ee}),ne("_net","×תש××× (âª)",{strong:!0,width:14}),{key:"due_date",header:"×××¢× ×ª×©×××",width:12,type:"date"},{key:"_dueDays",header:"×¢××",width:12,align:"center",sortable:!0,render:ae=>{var Ne;return e.jsxs("button",{type:"button",onClick:()=>k(ae),title:"× ×××× ×××××",className:"inline-flex items-center gap-1 rounded-full transition-shadow hover:shadow-sm",children:[ae._open?e.jsx(tr,{days:Tn(ae.due_date)}):(Ne=ae._changes)!=null&&Ne.length?null:e.jsx("span",{className:"text-slate-300 px-2",children:"â"}
44),e.jsx(ip,{marks:ae._marks,labels:ae._changes})]})}},{key:"_statement",header:"×ס×× ×ש×××",width:12,muted:!0,off:!0},{key:"_status",header:"ס×××ס תש×××",width:16,align:"center",render:ae=>e.jsxs("button",{type:"button",onClick:()=>P(ae),title:"×צ×ת ××ס××",className:`inline-flex items-center gap-1 px-2.5 py-1 rounded-full border text-[11.5px] font-bold transition-shadow hover:shadow-sm ${np(ae._status)}`,children:[ae._status||"â",e.jsx(fs,{className:"w-3.5 h-3.5 opacity-60"})]})}]};const oe=ae=>R.mode==="type"?ae._typeId||"â":R.mode==="payer"?ae.payer_account_id||"â":ae.billing_period||"â",le=new Map;J.forEach(ae=>{const Ne=oe(ae),we=le.get(Ne)||{id:Ne,_type:ae._type,_method:ae._method,_account:ae._account,_accountNumber:ae._accountNumber,_family:ae._family,billing_period:ae.billing_period||"â",count:0,payers:new Set,_gross:0,_discount:0,_credit:0,_net:0,_overdue:0,_openSum:0,_dues:new Set,_lines:[]};we.count+=1,we._lines.push(ae),we.payers.add(ae.payer_account_id),we._gross+=ae._gross,we._discount+=ae._discount,we._credit+=ae._credit,we._net+=ae._net,ae._overdue&&(we._overdue+=1,we._openSum+=ae._net),ae._open&&ae.due_date&&we._dues.add(String(ae.due_date).slice(0,10)),le.set(Ne,we)});const xe=[...le.values()].map(ae=>{const Ne=[...ae._dues].sort();return{...ae,payers:ae.payers.size,_dues:Ne,_due:Ne[0]||"",_dueDays:Ne.length?Tn(Ne[0]):null,_dueMixed:Ne.length>1}}).sort((ae,Ne)=>Ne._net-ae._net),de=R.mode==="type"?[{key:"_type",header:"ס×× ××××",width:26,strong:!0},{key:"_method",header:"ש××ת ××ש××",width:18,muted:!0}]:R.mode==="payer"?[{key:"_account",header:"×ש××× ×ש××",width:26,strong:!0},{key:"_accountNumber",header:"×ס׳ ×ש×××",width:12,muted:!0}]:[{key:"billing_period",header:"תק×פ×",width:22,strong:!0,render:ae=>er(ae.billing_period)}];return{rows:xe,columns:[...de,{key:"count",header:"××××××",width:10,type:"num",total:!0},{key:"payers",header:"×ש××××",width:10,type:"num"},ne("_gross","ס××× (âª)"),ne("_discount","×× ××ת (âª)",{off:!ee}),ne("_credit","××××××× (âª)",{off:!ee}),ne("_net","×תש××× (âª)",{strong:!0,width:14}),{key:"_due",header:"×××¢× ××××",width:14,align:"center",sortable:!0,render:ae=>e.jsx(tr,{days:ae._dueDays,mixed:ae._dueMixed,onOpen:ae._dueMixed?()=>w(ae):null})},{key:"_overdue",header:"×××××ר",width:10,type:"num",total:!0},ne("_openSum","ס××× ×××××ר (âª)",{width:14})]}},[R.mode,J]),ke=i.useMemo(()=>{const ee=J.reduce((de,ae)=>de+ae._net,0),oe=J.filter(de=>de._overdue),le=J.filter(de=>de._paid),xe=J.filter(de=>de._open);return[{label:"×¡× ×××××××",value:Ge(ee),currency:!0,sub:_e(J.length,"×××× ×××","××××××"),icon:nt,tone:"text-indigo-600 bg-indigo-50"},{label:"×¡× ××××××",value:Ge(xe.reduce((de,ae)=>de+ae._net,0)),currency:!0,sub:"××ª×¨× ×¤×ª×××",icon:rt,tone:"text-amber-600 bg-amber-50"},{label:"×¡× ×©×××",value:Ge(le.reduce((de,ae)=>de+ae._net,0)),currency:!0,sub:_e(le.length,"×××× ××× ×©×××","×××××× ×©××××"),icon:mr,tone:"text-emerald-600 bg-emerald-50"},{label:"×¡× ×××××ר",value:Ge(oe.reduce((de,ae)=>de+ae._net,0)),currency:!0,sub:_e(oe.length,"×××× ××× ×××××ר","×××××× ×××××ר"),icon:Be,tone:oe.length?"text-red-600 bg-red-50":"text-slate-400 bg-slate-100"}]},[J]);return e.jsxs(ss,{title:"××× ××××××",subtitle:"×× ××××××× ×©×××¤×§× â ××¤× ×¡×× ××××, תק×פ×, ×××¢× ×ª×©××× ×××ש××× ××ש××",settings:s,chips:[R.type?`ס×× ××××: ${((be=N.get(R.type))==null?void 0:be.name)||""}`:"×××",{open:"×××××× ×¤×ª××××",paid:"שש××××",overdue:"×××××ר ××××",cancelled:"×××××××","":"×× ×ס×××ס××"}[R.status],xs(R.month)||"×× ×תק×פ×ת",R.mode!=="lines"&&`תצ×××: ${(je=Sl.find(ee=>ee.v===R.mode))==null?void 0:je.full}`,R.due&&`×××¢× ${Ve(R.due)}`,R.q&&`××פ×ש: ${R.q}`],search:{value:R.q,onChange:ee=>q("q",ee),placeholder:"××פ×ש ××¤× ×ש××, ×ש××× ×× ×ª×××ר ××××"},filters:e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"ס×× ××××",hint:"××צ××× ×¨×§ ס××× ×××× ×¢× × ×ª×× ××",value:R.type,onCh
44ange:ee=>q("type",ee),options:[{v:"",l:"×××"},...te.map(ee=>({v:ee.id,l:ee.name}))]}),e.jsx(Ae,{label:"ס×××ס תש×××",value:R.status,onChange:ee=>q("status",ee),counts:I.status,options:[{v:"",l:"×××"},{v:"open",l:"פת××"},{v:"paid",l:"ש×××"},{v:"overdue",l:"×××××ר"}]}),e.jsx(mc,{label:"תק×פ×",value:R.month,monthsWithData:X,allowAll:!0,onChange:ee=>j(oe=>({...oe,month:ee,due:""}))}),e.jsx(Ae,{label:"תצ×××",value:R.mode,onChange:ee=>q("mode",ee),options:Sl})]}),stats:ke,columns:ge.columns,defaultSort:{key:R.mode==="lines"||R.mode==="payer"?"_account":R.mode==="type"?"_type":"billing_period",dir:"asc"},rows:ge.rows,loading:a,fileName:`×××_××××××_${((Ce=Sl.find(ee=>ee.v===R.mode))==null?void 0:Ce.full)||""}`,empty:"××× ×××××× ×ת××××× ×ת ×ס×× ××",footNote:"«×תש×××» ××× ×ס××× ×× ×××× ×× ××ת ××××××××. «ש×××» × ×§××¢ ××¤× ×ס×× ×ש××× ×©× ×¤×¨×¢ ×× ×ª×©××× ×©×××¡× ×ת ×תק×פ×, ׫×××××ר» ××¤× ×××¢× ×תש××× ××× ×××× â ×× ××¤× ×¡×××ס ×××××.",children:[e.jsx(cp,{items:G,value:R.due,onPick:ee=>q("due",ee===R.due?"":ee)}),V>0&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-3 rounded-xl border border-amber-200 bg-amber-50/70 px-3 py-2",children:[e.jsx(rt,{className:"w-4 h-4 text-amber-600 flex-none"}),e.jsxs("span",{className:"text-[12.5px] text-slate-700",children:[_e(V,"×××× ×¤×ª×× ×××","×××××× ×¤×ª××××")," ××××¥ ×",xs(R.month),"."]}),e.jsx("button",{type:"button",onClick:()=>j(ee=>({...ee,month:"",due:""})),className:`h-7 px-2.5 rounded-lg bg-white border border-amber-300 text-[12px] font-bold text-amber-700 45 hover:bg-amber-100 transition-colors`,children:"×צ×ת ×× ×תק×פ×ת"})]}),S&&e.jsx(Wn,{onClose:()=>P(null),title:`${S._paid?"××ש×ר תש×××":"×ר×שת תש×××"} · ${S.description||S._type||""}`.trim(),children:e.jsx(co,{charge:{...S,charge_type_name:S._type,paid:S._paid},account:K.get(S.payer_account_id)||{name:S._account,account_number:S._accountNumber},issuer:s||{},method:v(S.payer_account_id,S.charge_type_id)})}),e.jsx(op,{row:C,mode:R.mode,onClose:()=>w(null)}),E&&e.jsx(zx,{charge:E,account:K.get(E.payer_account_id)||null,type:N.get(E.charge_type_id)||null,existing:E._marks||[],onClose:()=>{k(null),M.current&&(M.current=!1,L())},onSave:async ee=>{var le,xe;const oe=Array.isArray(ee)?ee:[ee];try{for(const de of oe){const ae=await D.functions.invoke("recurringBilling",{action:"exception_create",community_id:t,...de});if(!((le=ae==null?void 0:ae.data)!=null&&le.success))throw new Error("save failed")}M.current=!0}catch(de){throw W.error((xe=de==null?void 0:de.message)!=null&&xe.includes("ס××ת")?de.message:"ש××רת ×ש×× ×× × ×ש××"),de}},onCancelException:async ee=>{var oe;try{const le=await D.functions.invoke("recurringBilling",{action:"exception_cancel",community_id:t,exception_id:ee});W.success((oe=le==null?void 0:le.data)!=null&&oe.reverted?"×××ר×× ××××× ×××××× ××××ר ××צ×× ××§×××":"×××ר×× ×××××"),M.current=!0,k(null),await L()}catch(le){const xe=String((le==null?void 0:le.message)||"");W.error(xe.includes("×××××")||xe.includes("×××ר××")?xe:"××××× ×××ר×× × ×ש×")}}})]})}function ip({marks:t=[],labels:s=[]}){if(!s.length&&!t.length)return null;const n=t.map(a=>{const l=uo[a.action],r=(l==null?void 0:l.scope)==="charge"?"":a.through_period?` · ${Xs(a.from_period)} â ${Xs(a.through_period)}`:` · ${Xs(a.from_period)} ×××××`,o=a.details,p=o&&o.before&&o.after&&Number(o.before.amount)!==Number(o.after.amount)?` · ${Ge(o.before.amount)} ⪠â ${Ge(o.after.amount)} âª`:"";return`${(l==null?void 0:l.note)||a.action}${r}${p} · ${a.reason}`}).join(` 46`);return s.length?e.jsx("span",{className:"inline-flex items-center gap-1 flex-none",title:n||void 0,"aria-label":n?`×ער×: ${n}`:void 0,children:s.slice(0,2).map(a=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-amber-50 text-amber-700 border border-amber-200 text-[11px] font-bold whitespace-nowrap",children:[e.jsx(Mr,{className:"w-3 h-3 flex-none"})," ",a]},a))}):e.jsx("span",{title:n,"aria-label":`×ער×: ${n}`,className:"inline-flex items-center justify-center w-6 h-6 rounded-full bg-amber-100 text-amber-700 flex-none",children:e.jsx(Mr,{className:"w-3.5 h-3.5"})})}function op({row:t,mode:s,onClose:n}){i.useEffect(()=>{if(!t)return;const o=p=>{p.key==="Escape"&&n()};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[t,n]);const a=i.useMemo(()=>
46{if(!t)return[];const o=u=>s==="type"?u._account:u._type,p=new Map;return(t._lines||[]).forEach(u=>{const d=String(u.due_date||"").slice(0,10)||"â",c=p.get(d)||{due:d,count:0,net:0,names:new Set,open:0};c.count+=1,c.net+=u._net,u._open&&(c.open+=1);const m=o(u);m&&c.names.add(m),p.set(d,c)}),[...p.values()].sort((u,d)=>u.due.localeCompare(d.due))},[t,s]);if(!t)return null;const l=s==="type"?t._type:s==="payer"?t._account:er(t.billing_period),r=s==="payer"?De:s==="type"?Xe:Be;return Pt.createPortal(e.jsxs("div",{dir:"rtl",className:"fixed inset-0 z-[70] grid place-items-center p-4",role:"dialog","aria-modal":"true","aria-label":`×××¢×× ××××× ×©× ${l}`,children:[e.jsx("button",{type:"button","aria-label":"ס××ר×",onClick:n,className:"absolute inset-0 bg-slate-900/40 backdrop-blur-[3px] cursor-default"}),e.jsxs("div",{className:"relative w-full max-w-2xl bg-white rounded-3xl shadow-2xl overflow-hidden",children:[e.jsxs("header",{className:"relative bg-gradient-to-l from-teal-50/80 via-sky-50/60 to-white px-6 py-5 flex items-start gap-4",children:[e.jsx("span",{className:"w-12 h-12 rounded-2xl bg-white/90 border border-white shadow-sm grid place-items-center flex-none text-teal-600",children:e.jsx(r,{className:"w-6 h-6"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[21px] font-black text-slate-900 leading-tight truncate",children:l}),e.jsxs("p",{className:"text-[13px] text-slate-500 mt-0.5",children:["×××¢×× ××××× Â· ",_e(t.count,"×××× ×××","××××××")]})]}),e.jsx("button",{type:"button",onClick:n,"aria-label":"ס××ר×",className:`mr-auto w-9 h-9 rounded-xl bg-white/80 border border-slate-200 grid place-items-center 47 text-slate-400 hover:text-slate-700 hover:bg-white flex-none`,children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"px-4 pb-4 max-h-[60vh] overflow-y-auto",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,1.1fr)_minmax(0,1.3fr)_72px_minmax(0,1fr)] gap-3 px-3 py-2.5 text-[12px] font-bold text-slate-400",children:[e.jsx("span",{children:"×××¢× ××××"}),e.jsx("span",{children:s==="type"?"×ש××××":"ס×× ×ª×©×××"}),e.jsx("span",{className:"text-center",children:"××××××"}),e.jsx("span",{className:"text-left",children:"×תש××× (âª)"})]}),e.jsx("ul",{className:"space-y-2",children:a.map(o=>{const p=o.due==="â"?null:Tn(o.due);return e.jsxs("li",{className:`grid grid-cols-[minmax(0,1.1fr)_minmax(0,1.3fr)_72px_minmax(0,1fr)] gap-3 items-center 48 rounded-2xl border border-slate-100 bg-white shadow-[0_1px_2px_rgba(15,23,42,0.04)] px-3 py-3`,children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[15px] font-black text-slate-900 tabular-nums",dir:"ltr",children:o.due==="â"?"â":Ve(o.due)}),p!==null&&o.open>0&&e.jsx("span",{className:"block mt-1",children:e.jsx(tr,{days:p})})]}),e.jsx("span",{className:"min-w-0 text-[13px] font-bold text-slate-600 leading-snug",children:[...o.names].join(" · ")||"â"}),e.jsx("span",{className:"text-[15px] font-bold text-slate-700 tabular-nums text-center",dir:"ltr",children:o.count}),e.jsx("span",{className:"text-[17px] font-black text-slate-900 tabular-nums text-left",dir:"ltr",children:Ge(o.net)})]},o.due)})})]}),e.jsxs("footer",{className:`grid grid-cols-[minmax(0,1.1fr)_minmax(0,1.3fr)_72px_minmax(0,1fr)] gap-3 items-center 49 px-7 py-4 border-t border-slate-100 bg-gradient-to-l from-teal-50/70 to-sky-50/50`,children:[e.jsx("span",{className:"text-[15px] font-black text-slate-900",children:"ס××´×"}),e.jsx("span",{}),e.jsx("span",{className:"text-[15px] font-black text-slate-800 tabular-nums text-center",dir:"ltr",children:t.count}),e.jsx("span",{className:"text-[20px] font-black text-teal-700 tabular-nums text-left",dir:"ltr",children:Ge(t._net)})]})]})]}),document.body)}function tr({days:t,mixed:s,onOpen:n=null}){if(s){const a=e.jsxs(e.Fragment,{children:["×××¢××× ×©×× ××",n&&e.jsx(lt,{className:"w-3.5 h-3.5 opacity-60"})]}),l="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border text-[11.5px] font-bold bg-slate-50 text-slate-500 border-slate-200";return n?e.jsx("button",{type:"button",onClick:n,title:"פ×ר×× ××××¢××× ×©××§××צ×",className:`${l} hover:bg-slate-100 hover:text-slate-700 hover:border-slate-300 transition-colors`,children:a}):e.jsx("span",{className:l,title:"×ש×ר×ת ש××§×××¦× ×ש ××תר ××××¢× ×ª×©××× ×××",children:a})}return t==null?e.jsx("span",{className:"text-slate-300",children:"â"}):e.jsx("span",{className:`inline-flex items-center gap-1 px-2.5 py-1 rounded-full border text-[11.5px] font-bold ${Lx[Ql(t)]}`,children:wa(t)})}function cp({items:t=[],value:s="",onPick:n}){const a=i.useMemo(()=>Tx(t),[t]);if(!a.next)return null;const l=a.dates.find(d=>d.date===s)||null,r=Ql(a.next.days),o={late:"bg-red-50/70 border-red-200",soon:"bg-emerald-50/70 border-emerald-200",week:"bg-cyan-50/60 border-cyan-200",far:"bg-sky-50/60 border-sky-200",none:"bg-slate-50 border-slate-200"}[r],p={late:"bg-red-100 text-red-600",soon:"bg-emerald-100 text-emerald-700",week:"bg-cyan-100 text-cyan-700",far:"bg-sky-100 text-sky-700",none:"bg-white text-slate-400 border border-slate-200"}[r],u={late:"text-red-800",soon:"text-emerald-900",week:"text-cyan-900",far:"text-sky-900",none:"text-slate-800"}[r];return e.jsxs("div",{className:`rounded-2xl border px-4 py-3 flex items-center gap-4 flex-wrap ${o}`,children:[e.jsx("span",{className:`w-10 h-10 rounded-xl grid place-items-center flex-none ${p}`,children:e.jsx(Be,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block text-[15px] font-black leading-tight ${u}`,children:l?`${wa(l.days,{prefix:"×××¢× ×××××"})} · ${Ve(l.date)}
49`:a.mixed?`${a.dates.length} ×××¢×× ×××× Â· ×קר×× ${wa(a.next.days)}`:wa(a.next.days,{prefix:"×××¢× ×××××"})}),e.jsx("span",{className:"block text-[11.5px] text-slate-500 mt-0.5 whitespace-nowrap",children:l?`${_e(l.count,"×××× ×××","××××××")} · ${Ge(l.sum)} ⪠· ×××¦× ×××××`:a.mixed?`ס××´× ${_e(a.count,"×××× ×××","××××××")} · ${Ge(a.sum)} âª`:`${Ve(a.next.date)} · ${_e(a.next.count,"×××× ×××","××××××")} · ${Ge(a.next.sum)} âª`})]}),a.mixed&&e.jsx("span",{className:"flex items-stretch gap-2 flex-wrap mr-auto",children:a.dates.map(d=>{const c=d.date===s,m=Ql(d.days),h={late:"border-red-300",soon:"border-emerald-300",week:"border-cyan-300",far:"border-sky-300",none:"border-slate-200"}[m],b={late:"ring-red-400",soon:"ring-emerald-400",week:"ring-cyan-400",far:"ring-sky-400",none:"ring-slate-400"}[m],f={late:"text-red-600",soon:"text-emerald-600",week:"text-cyan-700",far:"text-sky-700",none:"text-slate-400"}[m];return e.jsxs("button",{type:"button",onClick:()=>n(d.date),"aria-pressed":c,title:c?"××××× ×ס×× ××":`×צ×ת ××××××× ×©× ${Ve(d.date)} ××××`,className:`rounded-xl bg-white border px-3.5 py-2.5 text-right transition-all min-w-[9.5rem] ${h} ${c?`ring-2 ${b} shadow-md`:"shadow-sm hover:shadow-md"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[14px] font-medium text-slate-800 tabular-nums",children:Ve(d.date)}),e.jsx("span",{className:`text-[12px] font-medium mr-auto whitespace-nowrap ${f}`,children:wa(d.days)})]}),e.jsxs("span",{className:"flex items-baseline gap-2 mt-1.5",children:[e.jsxs("span",{className:"text-[15px] font-medium text-slate-900",children:[e.jsx("span",{dir:"ltr",className:"inline-block tabular-nums",children:Ge(d.sum)}),e.jsx("span",{className:"text-[12px] text-slate-400",children:" âª"})]}),e.jsx("span",{className:"text-[11.5px] text-slate-400 mr-auto whitespace-nowrap",children:_e(d.count,"×××× ×××","××××××")})]})]},d.date)})}),l&&e.jsxs("button",{type:"button",onClick:()=>n(l.date),className:"h-9 px-3 rounded-xl bg-white border border-slate-300 text-[12.5px] font-bold text-slate-600 inline-flex items-center gap-1.5 hover:bg-slate-50 flex-none",children:[e.jsx($e,{className:"w-3.5 h-3.5 flex-none"})," ×× ××××¢×××"]})]})}const dp={status:"active",method:"",scope:"",q:"",min:""},up=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),$l=t=>(Number(t)||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),mp={active:"פע××",inactive:"×× ×¤×¢××",frozen:"××קפ×"},tn={standing_order:"××ר×ת ×§××¢",credit:"×ר××ס ×שר××",bank_transfer:"××¢××¨× ×× ×§××ת",cash:"×××××",check:"×××××"},xp={personal_area:"×××ר ××ש×",email:"××××´×",whatsapp:"WhatsApp",push:"Push",print:"××פס×/×ס×ר×"},vi=new Set(["approved","issued"]);function pp({kibbutzId:t,settings:s}){const[n,a]=i.useState(!0),[l,r]=i.useState([]),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState([]),[h,b]=i.useState([]),[f,x]=i.useState([]),[g,y]=i.useState([]),[$,O]=i.useState(dp),A=(_,T)=>O(M=>({...M,[_]:T})),S=i.useCallback(async()=>{a(!0);try{const[_,T,M,B,R,j,q,L]=await Promise.all([D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me},"-created_date").catch(()=>[]),D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Property.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.WaterMeter.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[])]);r(_||[]),p(T||[]),d(M||[]),m(zt(B,L)),b(R||[]),x(j||[]),y(q||[])}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{S()},[S]);const P=i.useMemo(()=>{const _=new Map(o.map(L=>[L.id,L])),T=L=>{const N=new Map;return L.forEach(v=>N.set(v.payer_account_id,[...N.get(v.payer_account_id)||[],v])),N}
49,M=T(c),B=T(h),R=T(f),j=T(g),q=new Map;return u.forEach(L=>{!L.family_id||L.status==="inactive"||q.set(L.family_id,[...q.get(L.family_id)||[],L])}),l.map(L=>{const N=L.family_id?_.get(L.family_id):null,v=L.family_id&&q.get(L.family_id)||[],F=v.find(z=>z.id===(N==null?void 0:N.head_of_family_id))||v.find(z=>z.family_role==="head")||v.find(z=>z.id===L.primary_resident_id),K=(M.get(L.id)||[]).filter(z=>vi.has(z.status)).reduce((z,te)=>z+(Number(te.amount)||0)-(Number(te.discount_amount)||0)-(Number(te.credit_amount)||0),0),Z=(B.get(L.id)||[]).filter(z=>z.status==="paid"||z.status==="partial").reduce((z,te)=>z+(Number(te.amount)||0),0),H=Number(L.opening_balance)||0;return{...L,_name:L.name||(N==null?void 0:N.name)||"â",_family:(N==null?void 0:N.name)||"",_head:F?F.full_name||[F.first_name,F.last_name].filter(Boolean).join(" "):"",_phone:(F==null?void 0:F.phone)||(F==null?void 0:F.mobile)||"",_budget:Vt(F==null?void 0:F.budget)||v.map(z=>Vt(z.budget)).find(Boolean)||"",_souls:v.length,_properties:(R.get(L.id)||[]).length,_meters:(j.get(L.id)||[]).length,_charges:(M.get(L.id)||[]).filter(z=>vi.has(z.status)).length,_opening:H,_billed:K,_paid:Z,_balance:H+K-Z,_method:tn[L.payment_method]||"",_delivery:String(L.preferred_delivery_channel||"").split(",").map(z=>xp[z.trim()]||z.trim()).filter(Boolean).join(" · "),_status:mp[L.status]||L.status||"פע××"}})},[l,o,u,c,h,f,g]),E=i.useMemo(()=>{const _=$.q.trim(),T=$.min===""?null:Number($.min);return P.filter(M=>!($.status&&(M.status||"active")!==$.status||$.method&&M.payment_method!==$.method||$.scope==="debt"&&!(M._balance>0)||$.scope==="credit"&&!(M._balance<0)||$.scope==="clear"&&M._balance!==0||T!==null&&!(M._balance>=T)||_&&![M._name,M.account_number,M._family,M._head,M._budget,M.id_number].join(" ").includes(_))).sort((M,B)=>B._balance-M._balance)},[P,$]),k=[{key:"account_number",header:"×ס׳ ×ש×××",width:12},{key:"_name",header:"×©× ××ש×××",width:26,strong:!0},{key:"_head",header:"ר×ש ×שפ××",width:20,muted:!0},{key:"_phone",header:"××פ××",width:14,align:"center",render:_=>e.jsx(sx,{phone:_._phone,name:_._head||_._name})},{key:"_budget",header:"×ספר תקצ××",width:12},{key:"_souls",header:"× ×¤×©×ת",width:9,type:"num",total:!0},{key:"_properties",header:"× ×ס××",width:9,type:"num",total:!0},{key:"_meters",header:"××× × ×××",width:10,type:"num",total:!0},{key:"_charges",header:"××××××",width:9,type:"num",total:!0},{key:"_opening",header:"×תרת פת××× (âª)",width:13,type:"money",total:!0},{key:"_billed",header:"ס××´× ×××× (âª)",width:13,type:"money",total:!0},{key:"_paid",header:"ס××´× ×©××× (âª)",width:13,type:"money",total:!0},{key:"_balance",header:"××ª×¨× (âª)",width:14,type:"money",total:!0,strong:!0},{key:"_method",header:"×××¦×¢× ×ª×©×××",width:15,muted:!0},{key:"_delivery",header:"ער××¥ ×ס×ר×",width:13,muted:!0},{key:"_status",header:"ס×××ס",width:10,align:"center"}],C=i.useMemo(()=>({status:Te(P,{active:_=>(_.status||"active")==="active",inactive:_=>_.status==="inactive",frozen:_=>_.status==="frozen"}),scope:Te(P,{debt:_=>_._balance>0,credit:_=>_._balance<0,clear:_=>_._balance===0}),method:Te(P,Object.fromEntries(Object.keys(tn).map(_=>[_,T=>T.payment_method===_])))}),[P]),w=i.useMemo(()=>{const _=E.reduce((B,R)=>B+R._billed,0),T=E.reduce((B,R)=>B+R._paid,0),M=E.filter(B=>B._balance>0);return[{label:"×ש××× ×ת",value:up(E.length),icon:De},{label:"ס××´× ××××",value:$l(_),currency:!0,icon:rt,tone:"text-indigo-600 bg-indigo-50"},{label:"ס××´× × ×××",value:$l(T),currency:!0,icon:Oe,tone:"text-emerald-600 bg-emerald-50"},{label:"ש××¢×ר ×××××",value:`${_>0?Math.min(100,Math.round(T/_*100)):0}%`,icon:rt,tone:"text-blue-600 bg-blue-50"},{label:"×ש××× ×ת ××תר×",value:$l(M.reduce((B,R)=>B+R._balance,0)),currency:!0,sub:_e(M.length,"×ש××× ×××","×ש××× ×ת"),icon:es,tone:M.length?"text-amber-600 bg-amber-50":"text-slate-400 bg-slate-100"}]},[E]);return e.jsx(ss,{title:"××× ×ש××× ×ת",subtitle:"פ×ר×× ×ש××× ×ת ××ש×××× â ××שפ×× ×©×××××¨× ×× ×ש×××, ×× ××××, ×× ×©××× ××× × ×תר",settings:s,chips:[{active:"×ש××× ×ת פע××××",inactive:"×× ×¤×¢××××",frozen:"××קפ×××","":"×× ×ס×××ס××"}[$.status],$.method&&`×××¦×¢× ×ª×©×××: ${tn[$.method]||$.method}`,{debt:"××תרת ××××",credit:"××תרת ×××ת",clear:"××× ×תר×","":""}[$.scope],$.min!==""&&`××ª×¨× ××¢× ${$.min} âª`,$.q&&`××פ×ש: ${$.q}`],search:{value:$.q,onChange:_=>A("q",_),placeholder:"××פ×ש ××¤× ×ש×××, ×שפ××, ר×ש ×שפ×× ×× ×ספר תקצ××"},filters:e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"ס×××ס",value:$.status,onChange:_=>A("status",_),counts:C.status,options:[{v:"active",l:"פע××××"},{v:"inactive",l:"×× ×¤×¢××××"},{v:"frozen",l:"××קפ×××"},{v:"",l:"×××"}]}
49),e.jsx(Ae,{label:"×תר×",value:$.scope,onChange:_=>A("scope",_),counts:C.scope,options:[{v:"",l:"×××"},{v:"debt",l:"×תרת ××××"},{v:"credit",l:"×תרת ×××ת"},{v:"clear",l:"××× ×תר×"}]}),e.jsx(oc,{label:"×××¦×¢× ×ª×©×××",value:$.method,onChange:_=>A("method",_),counts:C.method,options:[{v:"",l:"×××"},...Object.entries(tn).map(([_,T])=>({v:_,l:T}))]}),e.jsx(cc,{label:"××ª×¨× ××¢× (âª)",value:$.min,onChange:_=>A("min",_),placeholder:"0"})]}),stats:w,columns:k,defaultSort:{key:"_name",dir:"asc"},rows:E,loading:n,fileName:"×××_×ש××× ×ת_×ש××××",empty:"××× ×ש××× ×ת ×ת××××× ×ת ×ס×× ××",footNote:"××ª×¨× = ×תרת פת××× + ס××´× ×××× â ס××´× ×©×××. ×××× ××××× ×תש××× ×©× ××©× ××× × × ×××××."})}const hp={mode:"pages",kind:"",status:"",visibility:"",sales:"",buyer:"",pay:"",q:""},wi=[{v:"pages",l:"×¢×××××"},{v:"buyers",l:"ר××ש××"}],Rn=[{v:"paid",l:"ש×××",tone:"bg-emerald-50 text-emerald-700 border-emerald-200"},{v:"pending",l:"××ת××",tone:"bg-amber-50 text-amber-700 border-amber-200"},{v:"failed",l:"× ×ש×",tone:"bg-red-50 text-red-700 border-red-200"},{v:"refunded",l:"××××",tone:"bg-purple-50 text-purple-700 border-purple-200"}],Cl=t=>Rn.find(s=>s.v===t)||Rn[1],bp={credit_card:"×ר××ס ×שר××",bit:"×××",google_pay:"Google Pay",apple_pay:"Apple Pay",bank_transfer:"××¢××¨× ×× ×§××ת",account_charge:"×××× ××ש×××",cash:"×××××",check:"ש××§"},os=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),ki=t=>Number(t||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),Si={פע××:"bg-emerald-50 text-emerald-700 border-emerald-200",××ש×ת:"bg-slate-100 text-slate-500 border-slate-200"};function fp({kibbutzId:t,settings:s}){const[n,a]=i.useState(!0),[l,r]=i.useState([]),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState([]),[h,b]=i.useState(hp),f=(M,B)=>b(R=>({...R,[M]:B})),x=i.useCallback(async()=>{a(!0);try{const[M,B,R,j]=await Promise.all([D.entities.PaymentPage.filterAll({kibbutz_id:t}).catch(()=>
49[]),D.entities.PaymentPagePurchase.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[])]);r(M||[]),p(B||[]),d(R||[]),m(j||[])}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{x()},[x]);const g=i.useMemo(()=>new Map(u.map(M=>[M.id,M])),[u]),y=i.useMemo(()=>new Map(c.map(M=>[M.id,M])),[c]),$=i.useMemo(()=>{const M=new Map;return(o||[]).forEach(B=>{const R=B.payment_page_id;if(!R)return;const j=M.get(R)||{paid:0,pending:0,failed:0,refunded:0,total:0,last:null},q=B.status||"pending";j[q]!==void 0&&(j[q]+=1),q==="paid"&&(j.total+=Number(B.amount)||0),q==="refunded"&&(j.total-=Number(B.amount)||0);const L=B.paid_date||B.created_date;L&&(!j.last||L>j.last)&&(j.last=L),M.set(R,j)}),M},[o]),O=i.useMemo(()=>{const M=new Set(l.map(B=>B.kind||"one_time"));return fr.filter(B=>M.has(B.v))},[l]),A=i.useMemo(()=>{const M=B=>{var R;return(((R=$.get(B.id))==null?void 0:R.paid)||0)>0};return{status:Te(l||[],{active:B=>B.is_active!==!1,inactive:B=>B.is_active===!1}),visibility:Te(l||[],{public:B=>(B.visibility||"public")==="public",residents:B=>B.visibility==="residents"}),sales:Te(l||[],{sold:M,none:B=>!M(B)})}},[l,$]),S=i.useMemo(()=>{const M=h.q.trim();return(l||[]).filter(B=>{var q;const R=B.is_active!==!1;if(h.kind&&(B.kind||"one_time")!==h.kind||h.status==="active"&&!R||h.status==="inactive"&&R||h.visibility&&(B.visibility||"public")!==h.visibility)return!1;const j=(((q=$.get(B.id))==null?void 0:q.paid)||0)>0;return!(h.sales==="sold"&&!j||h.sales==="none"&&j||M&&![B.title,B.description,B.slug].join(" ").includes(M))}).map(B=>{var q;const R=$.get(B.id)||{paid:0,pending:0,refunded:0,total:0,last:null},j=kt(B.kind);return{...B,_kind:Wa(B.kind),_priceLabel:Js(B),_price:j.fields.price&&B.price!==null&&B.price!==void 0?Number(B.price):null,_months:B.months_limit?Number(B.months_limit):null,_visibility:(B.visibility||"public")==="public"?"צ×××ר×":"×ת×ש××× ××××",_status:B.is_active===!1?"××ש×ת":"פע××",_chargeType:B.charge_type_id&&((q=g.get(B.charge_type_id))==null?void 0:q.name)||"",_sales:R.paid,_pending:R.pending,_refunded:R.refunded,_total:R.total,_last:R.last||"",_link:gr(t,B.slug)}})},[l,h,$,g,t]),P=i.useMemo(()=>{const M=h.q.trim(),B=new Map(l.map(R=>[R.id,R]));return(o||[]).map(R=>{const j=B.get(R.payment_page_id)||null,q=Ua(Pr(R)),L=R.payer_account_id?y.get(R.payer_account_id):null;return{...R,_buyer:R.payer_name||"â",_who:q.v,_whoLabel:q.l,_page:(j==null?void 0:j.title)||"â ×¢××× ×©× ×××§ â",_pageKind:j?Wa(j.kind):"",_kindV:(j==null?void 0:j.kind)||"",_account:L&&L.account_number||"",_method:bp[R.payment_method]||R.payment_method||"",_statusHe:Cl(R.status).l,_amount:Number(R.amount)||0,_when:R.paid_date||R.created_date||""}}).filter(R=>!(h.buyer&&R._who!==h.buyer||h.pay&&R.status!==h.pay||h.kind&&R._kindV!==h.kind||M&&![R._buyer,R.payer_phone,R.payer_email,R._page,R._account,R.note].join(" ").includes(M)))},[o,l,y,h]),E=i.useMemo(()=>{const M=(o||[]).map(B=>({k:Pr(B),s:B.status}));return{buyer:Te(M,Object.fromEntries(Er.map(B=>[B.v,R=>R.k===B.v]))),pay:Te(M,Object.fromEntries(Rn.map(B=>[B.v,R=>R.s===B.v])))}},[o]),k=[{key:"_buyer",header:"ר××ש/ת",width:24,strong:!0,render:M=>e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:"font-bold text-slate-800",children:M._buyer}),e.jsx("span",{className:`inline-block px-2 py-0.5 rounded-full border text-[11px] font-bold whitespace-nowrap ${Ua(M._who).tone}`,title:Ua(M._who).full,children:M._whoLabel})]})},{key:"_whoLabel",header:"ס×× ×¨××ש",width:13,muted:!0,off:!0},{key:"_page",header:"×¢××× ×ª×©×××",width:26},{key:"_pageKind",header:"ס×× ××¢×××",width:18,muted:!0,off:!0},{key:"_amount",header:"ס××× (âª)",width:13,type:"money",total:!0,strong:!0},{key:"_statusHe",header:"ס×××ס",width:11,align:"center",render:M=>e.jsx("span",{className:`inline-block px-2.5 py-1 rounded-full border text-[11.5px] font-bold ${Cl(M.status).tone}`,children:M._statusHe})},{key:"_method",header:"×××¦×¢× ×ª×©×××",width:14,muted:!0}
49,{key:"_account",header:"×ס׳ ×ש×××",width:11,muted:!0},{key:"payer_phone",header:"××פ××",width:13,muted:!0},{key:"payer_email",header:"××××××",width:20,muted:!0,off:!0},{key:"months",header:"×××ש××",width:9,type:"num",off:!0},{key:"_when",header:"ת×ר××",width:12,type:"date"},{key:"note",header:"×ער×",width:22,muted:!0,clamp:!0,off:!0},{key:"provider_reference",header:"×ס××ת×",width:16,muted:!0,off:!0}],C=i.useMemo(()=>{const M=P.filter(q=>q.status==="paid"),B=M.reduce((q,L)=>q+L._amount,0)-P.filter(q=>q.status==="refunded").reduce((q,L)=>q+L._amount,0),R=P.filter(q=>q._who==="guest").length,j=P.filter(q=>q._who!=="guest").length;return[{label:"ר××ש×ת",value:os(P.length),icon:Lr,tone:"text-indigo-600 bg-indigo-50"},{label:"ס××´× × ×××",value:ki(B),currency:!0,sub:`${os(M.length)} ש××××`,icon:rt,tone:B?"text-teal-600 bg-teal-50":"text-slate-400 bg-slate-100"},{label:"ת×ש×××",value:os(j),sub:"×××××× ××§××××",icon:ys,tone:"text-sky-600 bg-sky-50"},{label:"××ר×××",value:os(R),sub:"××× × ×¨×©×××× ××§××××",icon:so,tone:R?"text-amber-600 bg-amber-50":"text-slate-400 bg-slate-100"}]},[P]),w=[{key:"title",header:"×©× ××£ ×תש×××",width:26,strong:!0},{key:"_kind",header:"ס××",width:20,muted:!0},{key:"_priceLabel",header:"×¢××ת",width:18},{key:"_price",header:"ס×××",width:12,type:"money",off:!0},{key:"_months",header:"×××ש××",width:9,type:"num",off:!0},{key:"_sales",header:"×ספר ר××ש×ת",width:12,type:"num",total:!0},{key:"_total",header:"ס××´×",width:14,type:"money",total:!0},{key:"_pending",header:"××ת×× ××",width:10,type:"num",total:!0,off:!0},{key:"_refunded",header:"××××",width:9,type:"num",total:!0,off:!0},{key:"_last",header:"ר×××©× ××ר×× ×",width:13,type:"date",muted:!0,off:!0},{key:"_visibility",header:"× ×¨××ת",width:13,align:"center"},{key:"_status",header:"ס×××ס",width:10,align:"center",render:M=>e.jsx("span",{className:`inline-block px-2.5 py-1 rounded-full border text-[11.5px] font-bold ${Si[M._status]||Si.××ש×ת}`,children:M._status})},{key:"_chargeType",header:"ס×× ××××",width:14,muted:!0,off:!0},{key:"description",header:"ת×××ר",width:28,muted:!0,clamp:!0,off:!0},{key:"_link",header:"×§×ש×ר",width:30,muted:!0,clamp:!0,off:!0},{key:"created_date",header:"× ×צר ×ת×ר××",width:12,type:"date",muted:!0}],_=i.useMemo(()=>{const M=S.filter(j=>j._status==="פע××").length,B=S.reduce((j,q)=>j+(q._sales||0),0),R=S.reduce((j,q)=>j+(q._total||0),0);return[{label:"×¢×××× ×ª×©×××",value:os(S.length),icon:Zt,tone:"text-purple-600 bg-purple-50"},{label:"פע××××",value:os(M),icon:ca,tone:"text-emerald-600 bg-emerald-50"},{label:"ס××´× ×¨××ש×ת",value:os(B),icon:Lr,tone:B?"text-indigo-600 bg-indigo-50":"text-slate-400 bg-slate-100"},{label:"ס××´× × ×××",value:ki(R),currency:!0,icon:rt,tone:R?"text-teal-600 bg-teal-50":"text-slate-400 bg-slate-100"}]},[S]),T=h.mode==="buyers";return e.jsx(ss,{title:"××× ×¢×××× ×ª×©×××",subtitle:"××§×ש×ר×× ×©××§×××× ××צ××× â ×× ×× ××× ××קש, ××× ×©×××× ×ר×× ×××× × ××× ×פ××¢×",settings:s,chips:T?["תצ×××: ר××ש××",h.buyer&&Ua(h.buyer).full,h.pay&&`ס×××ס: ${Cl(h.pay).l}`,h.kind&&`ס×× ××£: ${Wa(h.kind)}`,h.q&&`××פ×ש: ${h.q}`]:[h.kind&&`ס××: ${Wa(h.kind)}`,h.status==="active"?"×¢××××× ×¤×¢××××":h.status==="inactive"?"×¢××××× ××ש×ת××":"×× ×ס×××ס××",h.visibility==="public"?"צ×××ר×××":h.visibility==="residents"?"×ת×ש××× ××××":"",h.sales==="sold"?"×¢× ×¨××ש×ת":h.sales==="none"?"××× ×¨××ש×ת":"",h.q&&`××פ×ש: ${h.q}`],search:{value:h.q,onChange:M=>f("q",M),placeholder:T?"××פ×ש ××¤× ×©× ×ר××ש, ××פ××, ×××××× ×× ×¢×××":"××פ×ש ××¤× ×©× ×××£, ת×××ר ×× ×§×ש×ר"},filters:T?e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"תצ×××",value:h.mode,onChange:M=>f("mode",M),options:wi}
49),e.jsx(Ae,{label:"ר××ש",value:h.buyer,onChange:M=>f("buyer",M),counts:E.buyer,options:[{v:"",l:"×××"},...Er.map(M=>({v:M.v,l:M.l}))]}),e.jsx(Ae,{label:"ס×××ס תש×××",value:h.pay,onChange:M=>f("pay",M),counts:E.pay,options:[{v:"",l:"×××"},...Rn.map(M=>({v:M.v,l:M.l}))]}),e.jsx(Ae,{label:"ס×× ××£",hint:"××צ××× ×¨×§ ס×××× ×©×§××××× ××§××××",value:h.kind,onChange:M=>f("kind",M),options:[{v:"",l:"×××"},...O.map(M=>({v:M.v,l:M.l}))]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{label:"תצ×××",value:h.mode,onChange:M=>f("mode",M),options:wi}),e.jsx(Ae,{label:"ס×× ××£",hint:"××צ××× ×¨×§ ס×××× ×©×§××××× ××§××××",value:h.kind,onChange:M=>f("kind",M),options:[{v:"",l:"×××"},...O.map(M=>({v:M.v,l:M.l}))]}),e.jsx(Ae,{label:"ס×××ס",value:h.status,onChange:M=>f("status",M),counts:A.status,options:[{v:"",l:"×××"},{v:"active",l:"פע××××"},{v:"inactive",l:"××ש×ת××"}]}),e.jsx(Ae,{label:"× ×¨××ת",value:h.visibility,onChange:M=>f("visibility",M),counts:A.visibility,options:[{v:"",l:"×××"},{v:"public",l:"צ×××ר×"},{v:"residents",l:"×ת×ש×××"}]}),e.jsx(Ae,{label:"ר××ש×ת",value:h.sales,onChange:M=>f("sales",M),counts:A.sales,options:[{v:"",l:"×××"},{v:"sold",l:"×¢× ×¨××ש×ת"},{v:"none",l:"××× ×¨××ש×ת"}]})]}),stats:T?C:_,columns:T?k:w,defaultSort:T?{key:"_when",dir:"desc"}:{key:"title",dir:"asc"},rows:T?P:S,loading:n,fileName:T?"×××_ר××ש××_××¢××××_תש×××":"×××_×¢××××_תש×××",empty:T?"××× ×¨××ש×ת ×ת××××ת ×ת ×ס×× ××":"××× ×¢×××× ×ª×©××× ×ת××××× ×ת ×ס×× ××",footNote:T?"«××ר×/ת» ××× ×× ×©××× × ×¨×©×× ×ת××©× ××§×××× â ×¢××× ×¦××××¨× ×¤×ª×× ××× ×× ×©××§×ש×ר ××××¢ ××××, ××× ×××××¢ ×¢××× ××× ×× ×©××§××× ××¢×××. «ת×ש×/ת» ש×××/× ××ר××ס ×שר×× ×××× ××ר ×× × ×¨×©× ×¢× ×ש××× ××ש××; «ת×ש×/ת · ×ש×××» ××× ×××× ×©× ×¨×©× ××ש×××. ×ס××× ×ת×ת×ת ××××× ××× ×¡××× ×ש×ר×ת ×××צ××ת â ×××× ××ת×× ×× ×× ×ש××× â ××××× Â«×¡××´× × ×××» ש×××¢×× ×¡×פר תש××××× ×©××ש××× ××××, ×× ×××× ×××××××.":"«×ספר ר××ש×ת» ׫ס××´×» ס×פר×× ×ª×©××××× ×©××ש××× ×××× â ××ת×× ×× ××× × × ×¡×¤×¨×× ×××××× ×××¨× ××ס×××. תש××× ××§××× ××¨× ×××ר ××¢×××× ×תש×××, ×××× ××ספר×× ×ת×××× ×ר××¢ ××××ר ספק ×ס×××§×."})}const ps=t=>(Number(t)||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),pn=t=>(Number(t)||0).toLocaleString("he-IL",{maximumFractionDigits:0}),Us=(t,s)=>s>0?Math.round(t/s*1e3)/10:0,gp=()=>new Date().toISOString().slice(0,10),yp=new Set(["approved","issued"]),_p=(t,s)=>{if(s!=null&&s.due_day)return Number(s.due_day);const n=String((t==null?void 0:t.due_date)||"").slice(0,10),a=Number(n.slice(8,10));return Number.isFinite(a)&&a>0?a:null},jp=t=>{const s=String(t||"").match(/(\d{4})(\d{2})$/);return s?`${s[1]}-${s[2]}`:""},$i=[{v:"type",l:"××¤× ×¡×× ××××"},{v:"method",l:"××¤× ×××¦×¢× ×ª×©×××"},{v:"payer",l:"××¤× ×ש××"},{v:"lines",l:"×פ×ר×"}],sr=t=>t>=90?"#059669":t>=75?"#0d9488":t>=50?"#d97706":"#dc2626";function Np({kibbutzId:t,settings:s}){var te,ie;const[n,a]=i.useState(!0),[l,r]=i.useState([]),[o,p]=i.useState([]),[u,d]=i.useState([]),[c,m]=i.useState([]),[h,b]=i.useState([]),[f,x]=i.useState([]),[g,y]=i.useState([]),[$,O]=i.useState(null),A=new Date,S={month:Gl(A.getFullYear(),A.getMonth()),type:"",view:"type",q:""},[P,E]=i.useState(S),k=(V,Y)=>E(J=>({...J,[V]:Y})),C=i.useCallback(async()=>{a(!0);try{const[V,Y,J,I,X,se,G]=await Promise.all([D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.MonthlyStatement.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.AccountPaymentMethod.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeTypePaymentMethod.filterAll({kibbutz_id:t}).catch(()=>[])]);r(V||[]),p(Y||[]),d(J||[]),m(I||[]),b(X||[]),x(se||[]),y(G||[])}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{C()},[C]);const w=i.useMemo(()=>new Map(o.map(V=>[V.id,V])),[o]),_=i.useMemo(()=>zt(l,o,{ready:!n}
49),[l,o,n]),T=i.useMemo(()=>new Map(u.map(V=>[V.id,V])),[u]),M=i.useMemo(()=>{const V=ur(f,g);return(Y,J)=>{var I,X;return((I=V(Y,J))==null?void 0:I.kind)||((X=T.get(Y))==null?void 0:X.payment_method)||""}},[f,g,T]),B=i.useMemo(()=>{const V=new Set(h.filter(se=>se.status==="paid").map(se=>se.id)),Y=new Map(h.map(se=>[se.id,String(se.billing_month||"")])),J=new Map;c.filter(se=>se.status==="paid"||se.status==="partial").forEach(se=>{const G=Y.get(se.statement_id)||jp(se.reference_number);if(!G||!se.payer_account_id)return;const ne=`${se.payer_account_id}|${G}`;J.set(ne,(J.get(ne)||0)+(Number(se.amount)||0))});const I=new Map;_.filter(se=>se.status!=="cancelled").forEach(se=>{const G=String(se.billing_period||"");if(!G||!se.payer_account_id)return;const ne=`${se.payer_account_id}|${G}`;I.set(ne,(I.get(ne)||0)+(Number(se.amount)||0)-(Number(se.discount_amount)||0)-(Number(se.credit_amount)||0))});const X=new Set([...J.entries()].filter(([se,G])=>G+.01>=(I.get(se)||0)).map(([se])=>se));return{stPaid:V,covered:X}},[h,c,_]),R=i.useCallback(V=>Rx(V),[]),j=i.useMemo(()=>new Set(_.filter(V=>V.status!=="cancelled").map(R).filter(Boolean)),[_,R]),q=i.useMemo(()=>{if(!P.month||j.has(P.month))return[];const V=J=>{const[I,X]=J.split("-").map(Number);return I*12+(X-1)},Y=V(P.month);return[...j].sort((J,I)=>Math.abs(V(J)-Y)-Math.abs(V(I)-Y)||I.localeCompare(J)).slice(0,3)},[j,P.month]),L=i.useMemo(()=>{const V=gp();return _.filter(Y=>Y.status!=="cancelled").filter(Y=>R(Y)===P.month).map(Y=>{const J=T.get(Y.payer_account_id),I=w.get(Y.charge_type_id),X=(Number(Y.amount)||0)-(Number(Y.discount_amount)||0)-(Number(Y.credit_amount)||0),se=Y.statement_id&&B.stPaid.has(Y.statement_id)||B.covered.has(`${Y.payer_account_id}|${Y.billing_period||""}`),G=yp.has(Y.status)&&!se,ne=G&&Y.due_date&&String(Y.due_date).slice(0,10)<V,ge=M(Y.payer_account_id,Y.charge_type_id);return{...Y,_typeId:Y.charge_type_id||"",_type:(I==null?void 0:I.name)||"â",_dueDay:_p(Y,I),_account:J?J.name||`#${J.account_number}`:"××× ×ש×××",_accountNumber:(J==null?void 0:J.account_number)||"",_kind:ge||"",_method:ge?mo(ge).l:"×× ××××ר",_turnover:X,_paidSum:se?X:0,_lateSum:ne?X:0,_openSum:G?X:0,_paid:se,_overdue:ne}})},[_,P.month,R,T,w,B,M]),N=i.useMemo(()=>{const V=P.q.trim();return L.filter(Y=>!(P.type&&Y._typeId!==P.type||V&&![Y._type,Y._method,Y._account,Y._accountNumber,Y.description].join(" ").includes(V)))},[L,P.type,P.q]),v=i.useMemo(()=>{const V=new Set(L.map(Y=>Y._typeId).filter(Boolean));return o.filter(Y=>V.has(Y.id))},[L,o]),F=i.useMemo(()=>{const V=N.reduce((I,X)=>I+X._turnover,0),Y=N.reduce((I,X)=>I+X._paidSum,0),J=N.reduce((I,X)=>I+X._lateSum,0);return{turnover:V,paid:Y,late:J,lateCount:N.filter(I=>I._overdue).length,rate:Us(Y,V)}},[N]),K=i.useMemo(()=>{const V=new Map;return N.forEach(Y=>{const J=V.get(Y._typeId)||{id:Y._typeId||"â",_type:Y._type,_turnover:0,_paidSum:0,_lateSum:0,count:0};J._turnover+=Y._turnover,J._paidSum+=Y._paidSum,J._lateSum+=Y._lateSum,J.count+=1,V.set(Y._typeId,J)}),[...V.values()].map(Y=>({...Y,_rate:Us(Y._paidSum,Y._turnover)})).sort((Y,J)=>J._turnover-Y._turnover)},[N]),Z=i.useMemo(()=>{const V=new Map;return N.forEach(Y=>{const J=`${Y._typeId}|${Y._dueDay??""}`,I=V.get(J)||{id:J,_typeId:Y._typeId,_type:Y._type,_dueDay:Y._dueDay,_turnover:0,_paidSum:0,_lateSum:0,count:0,kinds:new Map};I._turnover+=Y._turnover,I._paidSum+=Y._paidSum,I._lateSum+=Y._lateSum,I.count+=1;const X=I.kinds.get(Y._kind)||{kind:Y._kind,label:Y._method,count:0,turnover:0,paid:0};X.count+=1,X.turnover+=Y._turnover,X.paid+=Y._paidSum,I.kinds.set(Y._kind,X),V.set(J,I)}),[...V.values()].map(Y=>{const J=[...Y.kinds.values()].sort((I,X)=>X.turnover-I.turnover);return{...Y,_methods:J,_method:J.length===1?J[0].label:`${J.length} ס××× ×ª×©×××`,_rate:Us(Y._paidSum,Y._turnover)}}).sort((Y,J)=>J._turnover-Y._turnover||(Y._dueDay??99)-(J._dueDay??99))},[N]),H=i.useMemo(()=>{const V=(J,I,X={})=>({key:J,header:I,width:14,type:"money",total:!0,...X}),Y={key:"_rate",header:"×××× ×××××",width:12,type:"pct",sortable:!0,render:J=>e.jsxs("span",{className:"inline-flex items-center gap-2 justify-start w-full",children:[e.jsxs("span",{className:"text-[13px] font-black tabular-nums",style:{color:sr(J._rate)},dir:"ltr",children:[J._rate.toFixed(1),"%"]}),e.jsx("span",{className:"w-20 h-2 rounded-full bg-slate-100 overflow-hidden flex-none",children:e.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,Math.max(2,J._rate))}%`,backgroundColor:sr(J._rate)}})})]})};if(P.view==="type")return{rows:Z,columns:[{key:"_type",header:"ס×× ×ª×©×××",width:20,strong:!0},{key:"_method",header:"×××¦×¢× ×ª×©×××",width:18,muted:!0,render:J=>J._methods.length>1?e.jsxs("button",{type:"button",onClick:()=>O(J),title:"פ×ר×× ××תפ×××ת ××¤× ×××¦×¢× ×ª×©×××",className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-lg bg-slate-100 border border-slate-200 50 text-[12.5px] font-bold text-slate-700 hover:bg-slate-200 hover:border-slate-300 transition-colors`,children:[J._method,e.jsx(lt,{className:"w-3.5 h-3.5 text-slate-400"})]}):J._method},V("_turnover","ס××× ×××××ר"),{key:"_dueDay",header:"××× ×××××",width:11,align:"center",sortable:!0,render:J=>J._dueDay?`${J._dueDay} ××××ש`:e.jsx("span",{className:"text-slate-300",children:"â"})},V("_paidSum","ס××× ×©×©×××",{strong:!0}),V("_lateSum","×××××ר"),Y]};if(P.view==="method"){const J=new Map;
50return N.forEach(I=>{const X=J.get(I._kind)||{id:I._kind||"â",_method:I._method,_turnover:0,_paidSum:0,_lateSum:0,count:0,types:new Set};X._turnover+=I._turnover,X._paidSum+=I._paidSum,X._lateSum+=I._lateSum,X.count+=1,X.types.add(I._typeId),J.set(I._kind,X)}),{rows:[...J.values()].map(I=>({...I,types:I.types.size,_rate:Us(I._paidSum,I._turnover)})).sort((I,X)=>X._turnover-I._turnover),columns:[{key:"_method",header:"×××¦×¢× ×ª×©×××",width:22,strong:!0},{key:"types",header:"ס××× ××××",width:10,type:"num"},{key:"count",header:"××××××",width:10,type:"num",total:!0},V("_turnover","ס××× ×××××ר"),V("_paidSum","ס××× ×©×©×××",{strong:!0}),V("_lateSum","×××××ר"),Y]}}if(P.view==="payer"){const J=new Map;return N.forEach(I=>{const X=J.get(I.payer_account_id)||{id:I.payer_account_id||"â",_account:I._account,_accountNumber:I._accountNumber,_method:I._method,_turnover:0,_paidSum:0,_lateSum:0,count:0};X._turnover+=I._turnover,X._paidSum+=I._paidSum,X._lateSum+=I._lateSum,X.count+=1,J.set(I.payer_account_id,X)}),{rows:[...J.values()].map(I=>({...I,_rate:Us(I._paidSum,I._turnover)})).sort((I,X)=>X._turnover-X._paidSum-(I._turnover-I._paidSum)),columns:[{key:"_account",header:"×ש××× ×ש××",width:24,strong:!0},{key:"_accountNumber",header:"×ס׳ ×ש×××",width:11,muted:!0},{key:"_method",header:"×××¦×¢× ×ª×©×××",width:16,muted:!0,off:!0},{key:"count",header:"××××××",width:9,type:"num",total:!0},V("_turnover","ס××× ×××××ר"),V("_paidSum","ס××× ×©×©×××",{strong:!0}),V("_lateSum","×××××ר"),Y]}}return{rows:[...N].sort((J,I)=>String(J._type).localeCompare(String(I._type),"he")),columns:[{key:"_type",header:"ס×× ×ª×©×××",width:18,strong:!0},{key:"_account",header:"×ש××× ×ש××",width:22},{key:"_accountNumber",header:"×ס׳ ×ש×××",width:11,muted:!0,off:!0},{key:"description",header:"ת×××ר",width:24,muted:!0,clamp:!0,off:!0},{key:"_method",header:"×××¦×¢× ×ª×©×××",width:16,muted:!0},V("_turnover","ס××× ×××××ר"),{key:"due_date",header:"×××¢× ×ª×©×××",width:12,type:"date"},V("_paidSum","ס××× ×©×©×××",{strong:!0}),V("_lateSum","×××××ר")]}},[P.view,Z,N]),z=[{label:"ס××× ×××××ר",value:ps(F.turnover),currency:!0,sub:xs(P.month),icon:Kn,tone:"text-indigo-600 bg-indigo-50"},{label:"ס××× ×©×©×××",value:ps(F.paid),currency:!0,sub:`${F.rate.toFixed(1)}% ××××××ר`,icon:rt,tone:"text-emerald-600 bg-emerald-50"},{label:"ס××× ×××××ר",value:ps(F.late),currency:!0,sub:_e(F.lateCount,"×××× ×××","××××××"),icon:ws,tone:F.late>0?"text-amber-600 bg-amber-50":"text-slate-400 bg-slate-100"},{label:"×××× ×××××",value:`${F.rate.toFixed(1)}%`,sub:F.turnover>0?`×ת×× ${pn(F.turnover)} âª`:"××× ××××ר ××××ש ××",icon:ks,tone:"text-teal-600 bg-teal-50"}];return e.jsxs(e.Fragment,{children:[e.jsx(ss,{title:"××× ××× ×¡×ת",subtitle:"×ר×× ××× ×¡×ת ××¤× ×¡×× ××××, ×××¦×¢× ×ª×©××× ××××¢× ××××",settings:s,chips:[xs(P.month),P.type?`ס×× ××××: ${((te=w.get(P.type))==null?void 0:te.name)||""}`:"×× ×¡××× ×××××",P.view!=="type"&&`תצ×××: ${(ie=$i.find(V=>V.v===P.view))==null?void 0:ie.l}`,P.q&&`××פ×ש: ${P.q}`],search:{value:P.q,onChange:V=>k("q",V),placeholder:"××פ×ש ××¤× ×¡×× ××××, ×××¦×¢× ×ª×©××× ×× ×ש×××"},filters:e.jsxs(e.Fragment,{children:[e.jsx(mc,{value:P.month,onChange:V=>k("month",V),monthsWithData:j}),e.jsx(Ae,{label:"ס×× ××××",value:P.type,onChange:V=>k("type",V),options:[{v:"",l:"×××"},...v.map(V=>({v:V.id,l:V.name}))]}),e.jsx(Ae,{label:"תצ×××",value:P.view,onChange:V=>k("view",V),options:$i})]}),stats:z,columns:H.columns,rows:H.rows,defaultSort:{key:"_turnover",dir:"desc"},loading:n,fileName:`×××_××× ×¡×ת_${P.month}`,empty:q.length?e.jsxs("span",{className:"inline-flex flex-wrap items-center justify-center gap-x-2 gap-y-1.5",children:[e.jsxs("span",{children:["××× ××× ×¡×ת ×",xs(P.month),". ×ש ××× ×¡×ת ×Ö¾"]}),q.map(V=>e.jsx("button",{type:"button",onClick:()=>k("month",V),className:`h-7 px-2.5 rounded-lg bg-teal-50 border border-teal-200 text-[12.5px] font-bold 51 text-teal-700 hover:bg-teal-100 hover:border-teal-300 transition-colors`,children:xs(V)},V))]}):"××× ××× ×¡×ת ××××ש ×©× ××ר",footNote:"«ס××× ×××××ר» ××× ×ס××× ×××ר ×× ××ת ××××××××. «ש×××» × ×§××¢ ××¤× ×ס×× ×ש××× ×©× ×¤×¨×¢ ×× ×ª×©××× ×©×××¡× ×ת ×תק×פ×, ׫×××××ר» ××¤× ×××¢× ×תש××× ××× ×××× â ×× ××¤× ×¡×××ס ×××××. ×××¦×¢× ×תש××× × ×§×¨× ××××××¨× ×©× ×שק ×××ת ××××ª× ×¡×× ××××, ×××××¢××¨× ××××¦×¢× ×תש××× ×©× ××ש×××.",after:H.rows.length>0?e.jsx(wp,{byType:K,totals:F}):null}),e.jsx(vp,{row:$,onClose:()=>O(null)})]})}function vp({row:t,onClose:s}){return i.useEffect(()=>{if(!t)return;const n=r=>{r.key==="Escape"&&s()};document.addEventListener("keydown",n);const a=document.documentElement,l={html:a.style.overflow,body:document.body.style.overflow};return a.style.overflow="hidden",document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",n),a.style.overflow=l.html,document.body.style.overflow=l.body}},[t,s]),t?Pt.createPortal(e.jsxs("div",{dir:"rtl",className:"fixed inset-0 z-[70] grid place-items-center p-4",role:"dialog","aria-modal":"true","aria-label":`×תפ×××ת ×××¦×¢× ×ª×©××× â ${t._type}`,children:[e.jsx("button",{type:"button","aria-label":"ס××ר×",onClick:s,className:"absolute inset-0 bg-slate-900/45 backdrop-blur-[2px] curs
51or-default"}),e.jsxs("div",{className:"relative w-full max-w-xl bg-white rounded-2xl border border-slate-200 shadow-2xl",children:[e.jsxs("div",{className:"flex items-start gap-3 p-5 pb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-[17px] font-black text-slate-900",children:t._type}),e.jsxs("p",{className:"text-[12.5px] text-slate-500 mt-0.5",children:["×תפ×××ת ××¤× ×××¦×¢× ×ª×©×××",t._dueDay?` · ×××× ×-${t._dueDay} ××××ש`:"",` · ${_e(t.count,"×××× ×××","××××××")}`]})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"ס××ר×",className:"mr-auto w-8 h-8 rounded-lg grid place-items-center text-slate-400 hover:text-slate-700 hover:bg-slate-100 flex-none",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("table",{className:"w-full text-sm border-collapse",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2.5 font-semibold text-right",children:"×××¦×¢× ×ª×©×××"}),e.jsx("th",{className:"px-3 py-2.5 font-semibold text-right",children:"×ש××××"}),e.jsx("th",{className:"px-3 py-2.5 font-semibold text-right",children:"ס××× ×תש×××"}),e.jsx("th",{className:"px-3 py-2.5 font-semibold text-right",children:"××××××ר"})]})}),e.jsx("tbody",{children:t._methods.map(n=>e.jsxs("tr",{className:"border-t border-slate-100",children:[e.jsx("td",{className:"px-3 py-2.5 font-bold text-slate-800 text-right",children:n.label}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-700",dir:"ltr",children:n.count}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums font-bold text-slate-900",dir:"ltr",children:ps(n.turnover)}),e.jsxs("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-500",dir:"ltr",children:[Us(n.turnover,t._turnover).toFixed(1),"%"]})]},n.kind||"none"))}),e.jsx("tfoot",{children:e.jsxs("tr",{className:"border-t-2 border-slate-200 bg-slate-50 font-bold",children:[e.jsx("td",{className:"px-3 py-2.5 text-right",children:"ס××´×"}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",dir:"ltr",children:t.count}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",dir:"ltr",children:ps(t._turnover)}),e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",dir:"ltr",children:"100.0%"})]})})]})})]})]}),document.body):null}function wp({byType:t,totals:s}){const n=t.slice(0,8).map(r=>({name:r._type,××××ר:Math.round(r._turnover),ש×××:Math.round(r._paidSum)})),a=[{name:"× ×××",value:Math.max(0,s.paid)},{name:"× ×תר",value:Math.max(0,s.turnover-s.paid)}],l=sr(s.rate);return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsxs("section",{className:"lg:col-span-2 bg-white rounded-2xl border border-slate-200 shadow-sm p-4",children:[e.jsxs("header",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ks,{className:"w-4 h-4 text-teal-600 flex-none"}),e.jsx("h4",{className:"text-[15px] font-bold text-slate-800",children:"××××× ××¤× ×¡×× ××××"})]}),e.jsx("div",{style:{width:"100%",height:260},children:e.jsx(Rt,{children:e.jsxs(Ba,{data:n,margin:{top:4,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#f1f5f9",vertical:!1}),e.jsx(Qt,{dataKey:"name",tick:{fontSize:12,fill:"#64748b"},axisLine:!1,tickLine:!1,reversed:!0}),e.jsx(Ct,{tick:{fontSize:11,fill:"#94a3b8"},axisLine:!1,tickLine:!1,orientation:"right",tickFormatter:pn,width:56}),e.jsx(ht,{formatter:(r,o)=>[`${ps(r)} âª`,o],contentStyle:{direction:"rtl",fontSize:12,borderRadius:12,border:"1px solid #e2e8f0"}}),e.jsx(Qd,{wrapperStyle:{fontSize:12,direction:"rtl"}}),e.jsx(pt,{dataKey:"××××ר",fill:"#cbd5e1",radius:[6,6,0,0],maxBarSize:44}),e.jsx(pt,{dataKey:"ש×××",fill:"#0d9488",radius:[6,6,0,0],maxBarSize:44})]})})})]}),e.jsxs("section",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4 flex flex-col",children:[e.jsxs("header",{className:"flex items-center gap-2 mb-1",children:[e.jsx(xr,{className:"w-4 h-4 text-teal-600 flex-none"}),e.jsx("h4",{className:"text-[15px] font-bold text-slate-800",children:"×××× ×××××"})]}),e.jsxs("div",{className:"relative flex-1 min-h-[220px]",children:[e.jsx(Rt,{children:e.jsxs(Yn,{children:[e.jsxs(Vn,{data:a,dataKey:"value",innerRadius:"66%",outerRadius:"88%",startAngle:90,endAngle:-270,stroke:"none",isAnimationActive:!1,children:[e.jsx(_s,{fill:l}),e.jsx(_s,{fill:"#e2e8f0"})]}),e.jsx(ht,{formatter:(r,o)=>[`${ps(r)} âª`,o],contentStyle:{direction:"rtl",fontSize:12,borderRadius:12,border:"1px solid #e2e8f0"}})]})}),e.jsx("div",{className:"absolute inset-0 grid place-items-center pointer-events-none",children:e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-[26px] font-black tabular-nums leading-none",style:{color:l},dir:"ltr",children:[s.rate.toFixed(1),"%"]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:"×ת×× ×××××ר"})]})})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-2 text-center pt-2 border-t border-slate-100",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-[11px] text-slate-400",children:"× ×××"}),e.jsxs("dd",{className:"text-[13px] font-black text-emerald-600 tabular-nums",dir:"ltr",children:[pn(s.paid)," âª"]}
51)]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-[11px] text-slate-400",children:"× ×תר"}),e.jsxs("dd",{className:"text-[13px] font-black text-slate-600 tabular-nums",dir:"ltr",children:[pn(Math.max(0,s.turnover-s.paid))," âª"]})]})]})]})]})}const us=t=>{const s=Number(t);return Number.isFinite(s)?Math.round((s+Number.EPSILON)*100)/100:0},kp=t=>us((Number(t==null?void 0:t.amount)||0)-(Number(t==null?void 0:t.discount_amount)||0)-(Number(t==null?void 0:t.credit_amount)||0)),Sp=t=>String((t==null?void 0:t.due_date)||(t==null?void 0:t.created_date)||"").slice(0,10),$p=t=>String((t==null?void 0:t.payment_date)||(t==null?void 0:t.created_date)||"").slice(0,10);function Cp({account:t,charges:s=[],payments:n=[],typeName:a=new Map}={}){const l=us(t==null?void 0:t.opening_balance),r=[...s.filter(c=>c.status!=="cancelled").map(c=>({id:`c:${c.id}`,kind:"charge",date:Sp(c),_type:a.get(c.charge_type_id)||"××××",description:c.description||a.get(c.charge_type_id)||"××××",reference:c.billing_period||"",note:c.notes||"",debit:kp(c),credit:0,_source:c})),...n.filter(c=>c.status==="paid"||c.status==="partial").map(c=>({id:`p:${c.id}`,kind:"payment",date:$p(c),_type:"תש×××",description:"תש××× ×©×תק××",reference:c.reference_number||"",note:c.notes||"",debit:0,credit:us(c.amount),_source:c}))];r.sort((c,m)=>String(c.date||"").localeCompare(String(m.date||""))||(c.kind===m.kind?0:c.kind==="charge"?-1:1));let o=l;const p=r.map(c=>(o=us(o+c.debit-c.credit),{...c,balance:o})),u=us(p.reduce((c,m)=>c+m.debit,0)),d=us(p.reduce((c,m)=>c+m.credit,0));return{rows:p,opening:l,debit:u,credit:d,balance:us(l+u-d)}}const Bs=t=>(Number(t)||0).toLocaleString("he-IL",{minimumFractionDigits:2,maximumFractionDigits:2}),Ap=[{v:"",l:"×××"},{v:"charge",l:"××××××"},{v:"payment",l:"תש×××××"}];function Mp({kibbutzId:t,settings:s}){var M;const[n,a]=i.useState(!0),[l,r]=i.useState({accounts:[],families:[],residents:[],properties:[],types:[],charges:[],payments:[],methods:[],methodLinks:[]}),[o,p]=i.useState(null),[u,d]=i.useState(null),c={kind:"",span:"year",...Dn("year"),q:""},[m,h]=i.useState(c),b=(B,R)=>h(j=>({...j,[B]:R})),f=i.useCallback(async()=>{a(!0);try{const[B,R,j,q,L,N,v,F,K]=await Promise.all([D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Family.filterAll({kibbutz_id:t,is_deleted:Me},"name").catch(()=>[]),D.entities.Resident.filterAll({kibbutz_id:t,is_deleted:Me}).catch(()=>[]),D.entities.Property.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.AccountPaymentMethod.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeTypePaymentMethod.filterAll({kibbutz_id:t}).catch(()=>[])]);r({accounts:B||[],families:R||[],residents:j||[],properties:q||[],types:L||[],charges:zt(N,L),payments:v||[],methods:F||[],methodLinks:K||[]})}catch{W.error("ש×××× ×××¢×× ×ª ××××")}finally{a(!1)}},[t]);i.useEffect(()=>{f()},[f]);const x=i.useMemo(()=>ur(l.methods,l.methodLinks),[l.methods,l.methodLinks]),g=i.useMemo(()=>{const B=new Map(l.families.map(q=>[q.id,q])),R=new Map;l.residents.forEach(q=>{q.family_id&&(R.has(q.family_id)||R.set(q.family_id,[]),R.get(q.family_id).push(q))});const j=new Map;return l.properties.forEach(q=>{q.payer_account_id&&(j.has(q.payer_account_id)||j.set(q.payer_account_id,[]),j.get(q.payer_account_id).push(q))}),l.accounts.map(q=>({account:q,family:q.family_id&&B.get(q.family_id)||null,residents:q.family_id?R.get(q.family_id)||[]:[],properties:j.get(q.id)||[]}))},[l]),y=i.useMemo(()=>new Map(l.types.map(B=>[B.id,B.name])),[l.types]),$=i.useMemo(()=>g.find(B=>B.account.id===o)||null,[g,o]),O=i.useMemo(()=>$?Cp({account:$.account,charges:l.charges.filter(B=>B.payer_account_id===$.account.id),payments:l.payments.filter(B=>B.payer_account_id===$.account.id),typeName:y}):null,[$,l.charges,l.payments,y]),A=i.useMemo(()=>{const B=(O==null?void 0:O.rows)||[],R=j=>{const{from:q,to:L}=Dn(j);return N=>(!q||N.date>=q)&&(!L||N.date<=L)};return{kind:Te(B,{charge:j=>j.kind==="charge",payment:j=>j.kind==="payment"}),span:Te(B,Object.fromEntries(Vl.map(j=>[j.v,R(j.v)])))}},[O]),S=i.useMemo(()=>
51{if(!O)return[];const B=m.q.trim();return O.rows.filter(R=>!(m.kind&&R.kind!==m.kind||m.from&&R.date&&R.date<m.from||m.to&&R.date&&R.date>m.to||B&&![R.description,R._type,R.reference].join(" ").includes(B)))},[O,m]);if(n)return e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-teal-500 rounded-full animate-spin"})});const P=B=>{p(B),h(c)},E=e.jsx(Fp,{rows:g,currentId:o,onPick:P});if(!$)return e.jsxs("div",{children:[E,e.jsxs("p",{className:"text-center text-[13px] text-slate-400 py-10",children:[_e(g.length,"×ש××× ×ש×× ××× ××§××××","×ש××× ×ת ×ש×××× ××§××××")," â ××¤×©× ×ש××× ××× ××צ×× ×ת ××ר×סת ש××."]})]});const{account:k,family:C,residents:w,properties:_}=$,T=w.find(B=>B.family_role==="head")||w[0]||null;return e.jsxs(e.Fragment,{children:[E,e.jsx(ss,{title:"××× ×ר×סת",subtitle:`×× ××ª× ××¢×ת ××ש××× â ××××××, תש××××× ×××ª×¨× ×¨×¦× Â· ${k.name||""}`,settings:s,chips:[k.account_number?`×ש××× ${k.account_number}`:null,{charge:"×××××× ××××",payment:"תש××××× ××××","":"×××××× ×תש×××××"}[m.kind],m.span==="custom"?m.from||m.to?`${Ve(m.from)||"â¦"} â ${Ve(m.to)||"â¦"}`:"×× ×תק×פ×ת":((M=Vl.find(B=>B.v===m.span))==null?void 0:M.l)||"×× ×תק×פ×ת",m.q&&`××פ×ש: ${m.q}`],search:{value:m.q,onChange:B=>b("q",B),placeholder:"××פ×ש ××ª× ××¢×ת â ת×××ר, ס×× ×××× ×× ×ס××ת×"},inlineFilters:!0,filters:e.jsxs(e.Fragment,{children:[e.jsx(Ae,{inline:!0,value:m.kind,onChange:B=>b("kind",B),options:Ap,counts:A.kind}),e.jsx(Gm,{inline:!0,value:m.span,from:m.from,to:m.to,counts:A.span,onChange:({span:B,from:R,to:j})=>h(q=>({...q,span:B,from:R,to:j}))})]}),hero:e.jsx(Pp,{account:k,family:C,head:T,properties:_}),stats:[{label:"×תרת פת×××",value:Bs(O.opening),currency:!0,icon:nt,tone:"text-slate-500 bg-slate-100"},{label:"×¡× ××××××",value:Bs(O.debit),currency:!0,icon:rt,tone:"text-indigo-600 bg-indigo-50"},{label:"×¡× ×ª×©×××××",value:Bs(O.credit),currency:!0,icon:es,tone:"text-emerald-600 bg-emerald-50"},{label:O.balance<-.001?"×תרת ×××ת":"××ª×¨× ×תש×××",value:Bs(Math.abs(O.balance)),currency:!0,icon:Jd,tone:O.balance>.001?"text-amber-600 bg-amber-50":"text-emerald-600 bg-emerald-50"}],columns:[{key:"date",header:"ת×ר××",width:12,type:"date"},{key:"description",header:"ת×××ר",width:28,strong:!0,clamp:!0},{key:"_type",header:"ס×× ×ª× ××¢×",width:14},{key:"reference",header:"×ס××ת×",width:13,muted:!0},{key:"debit",header:"×××× (âª)",width:13,type:"money",total:!0,sortable:!0,render:B=>B.debit?Bs(B.debit):""},{key:"credit",header:"תש××× (âª)",width:13,type:"money",total:!0,sortable:!0,render:B=>B.credit?Bs(B.credit):""},{key:"balance",header:"××ª×¨× (âª)",width:14,type:"money",strong:!0},{key:"note",header:"×ער×ת",width:20,muted:!0,clamp:!0,sortable:!0,render:B=>B.note||""}],rows:S,defaultSort:{key:"date",dir:"asc"},empty:"××× ×ª× ××¢×ת ××ש××× ×תק××¤× ×©× ××ר×",fileName:`×ר×סת_${k.account_number||k.name||""}`,footNote:"×××ª×¨× ××¨×¦× ×××ש×ת ×¢× ×× ×ª× ××¢×ת ××ש××× ××¤× ×¡×ר ×ר×× ×××××, ××תרת ×פת××× ××××× â ס×× ×× ×תק××¤× ×סת×ר ש×ר×ת ×× ××× × ××פס ×ת ××תר×. ×××× ××××× ××× × ×ª× ××¢×.",children:u&&e.jsx(Wn,{onClose:()=>d(null),title:`×ר×שת תש××× Â· ${u.description||""}`.trim(),children:e.jsx(co,{charge:u,account:k,issuer:s||{},method:x(u.payer_account_id,u.charge_type_id)})})})]})}function Pp({account:t,family:s,head:n,properties:a=[]}){var u;const l=[s==null?void 0:s.street,s==null?void 0:s.house_number].filter(Boolean).join(" ")||((u=a[0])==null?void 0:u.address)||"",r=t.status==="frozen",o=t.status==="inactive",p=[["××¢× ××ש×××",n==null?void 0:n.full_name,!1],["××פ××",n==null?void 0:n.phone,!0],["×ת××ת",l,!1],["×××¦×¢× ×ª×©×××",t.payment_method?mo(t.payment_method).l:"×× ××××ר",!1]];return e.jsx("section",{className:"rounded-2xl border border-slate-200/80 bg-white shadow-sm px-4 sm:px-5 py-3.5",children:e.jsxs("div",{className:"flex items-center gap-x-4 gap-y-2 flex-wrap",children:[e.jsx("h3",{className:"text-[19px] font-black text-slate-900 leading-none flex-none",children:t.name||(s==null?void 0:s.name)||"×ש××× ×ש××"}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-[11.5px] font-bold px-2.5 py-1 rounded-full flex-none ${r?"bg-sky-50 text-sky-700":o?"bg-slate-100 text-slate-500":"bg-emerald-50 text-emerald-700"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${r?"bg-sky-500":o?"bg-slate-400":"bg-emerald-500"}`}),r?"×ש××× ××קפ×":o?"×ש××× ×× ×¤×¢××":"×ש××× ×¤×¢××"]}),e.jsx("span",{className:"text-[12.5px] text-slate-500 flex-none",children:[t.account_number&&`×ש××× ×ש×× ×ס׳ ${t.account_number}`,(t.budget_number||t.budget)&&`תקצ×× ${t.budget_number||t.budget}
51`].filter(Boolean).join(" | ")||"×ש××× ×ש××"}),p.map(([d,c,m])=>e.jsxs("span",{className:"flex items-baseline gap-1.5 min-w-0 flex-none border-r border-slate-200 pr-4",children:[e.jsx("span",{className:"text-[11.5px] text-slate-400 flex-none",children:d}),e.jsx("span",{className:`text-[13.5px] font-bold truncate ${d==="×××¦×¢× ×ª×©×××"&&!t.payment_method?"text-amber-700":"text-slate-800"}`,dir:m&&c?"ltr":void 0,style:m&&c?{textAlign:"right"}:void 0,children:c||"â"})]},d))]})})}function Ci({h:t,onPick:s}){var n,a,l;return e.jsxs("button",{type:"button",onClick:()=>s(t.account.id),className:"w-full flex items-center gap-3 p-2.5 rounded-xl text-right hover:bg-teal-50/70 transition-colors",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-slate-100 text-slate-400 grid place-items-center flex-none",children:e.jsx(ys,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[14px] font-bold text-slate-800 truncate",children:t.account.name||((n=t.family)==null?void 0:n.name)||"×ש××× ××× ×©×"}),e.jsx("span",{className:"block text-[11.5px] text-slate-400 truncate",children:[t.account.account_number&&`×ש××× ${t.account.account_number}`,(t.account.budget_number||t.account.budget)&&`תקצ×× ${t.account.budget_number||t.account.budget}`,[(a=t.family)==null?void 0:a.street,(l=t.family)==null?void 0:l.house_number].filter(Boolean).join(" ")].filter(Boolean).join(" · ")})]}),t.why&&e.jsxs("span",{className:"text-[11px] text-slate-500 bg-slate-100 rounded-full px-2 py-0.5 flex-none max-w-[11rem] truncate",children:[t.why.label,": ",t.why.value]})]})}const Ep=[{k:"name",l:"×©× ×שפ×× / ת×ש×",p:"×××"},{k:"account",l:"×ספר ×ש×××",p:"1010"},{k:"budget",l:"×ספר תקצ××",p:"472"},{k:"phone",l:"××פ××",p:"050â¦"},{k:"address",l:"×ת××ת",p:"×××× ×ת 8"}],sn={name:"",account:"",budget:"",phone:"",address:""};function Fp({rows:t,currentId:s,onPick:n}){const[a,l]=i.useState(""),[r,o]=i.useState(!1),[p,u]=i.useState(!1),[d,c]=i.useState(sn),m=i.useRef(null),h=i.useRef(null),b=i.useMemo(()=>Ho(t,a).filter(y=>y.account.id!==s),[t,a,s]),f=Object.values(d).some(y=>y.trim()),x=i.useMemo(()=>Uu(t,d).filter(y=>y.account.id!==s),[t,d,s]);i.useEffect(()=>{if(!r)return;const y=$=>{var O;(O=m.current)!=null&&O.contains($.target)||o(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[r]);const g=y=>{n(y),l(""),o(!1),u(!1),c(sn)};return e.jsxs("section",{ref:m,className:"rounded-2xl border border-teal-200/70 bg-teal-50/40 p-3.5 sm:p-4 no-print mb-4",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2.5 flex-wrap",children:[e.jsx("label",{htmlFor:"ledger-find",className:"text-[14px] font-extrabold text-slate-700 flex-none",children:"×פש ×××¦× ×ר×סת"}),e.jsxs("div",{className:"relative w-full sm:w-[30rem]",children:[e.jsx("input",{id:"ledger-find",ref:h,value:a,onChange:y=>{l(y.target.value),o(!0)},onFocus:()=>o(!0),onKeyDown:y=>{y.key==="Enter"&&b[0]&&g(b[0].account.id),y.key==="Escape"&&o(!1)},placeholder:"××פ×ש ××¤× ×©× ×שפ××, ×ספר ×ש×××, ×ספר תקצ××, ××פ×× ×× ×ת××ת","aria-label":"××¢×ר ××ר×סת ××רת",autoComplete:"off",className:`w-full h-11 rounded-xl border border-slate-200 bg-white px-4 pl-10 text-[14px] text-slate-800 52 focus:outline-none focus:border-teal-500 focus:ring-4 focus:ring-teal-50 transition-colors`}),a&&e.jsx("button",{type:"button",onClick:()=>{l(""),o(!1)},"aria-label":"× ××§××",className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-7 h-7 rounded-full grid place-items-center text-slate-400 hover:bg-slate-100",children:e.jsx($e,{className:"w-4 h-4"})}),r&&a.trim().length>=2&&e.jsx("ul",{className:"absolute z-30 mt-1.5 w-full bg-white rounded-2xl border border-slate-200 shadow-xl p-1.5 max-h-80 overflow-y-auto",children:b.length===0?e.jsx("li",{className:"px-3 py-3 text-[13px] text-slate-400 text-center",children:s?`×× × ××¦× ×ש××× ××ר ×ת××× Â«${a.trim()}».`:`×× × ××¦× ×ש××× ×ת××× Â«${a.trim()}».`}):b.map(y=>e.jsx("li",{children:e.jsx(Ci,{h:y,onPick:g})},y.account.id))})]}),e.jsx("button",{type:"button","aria-label":"××פ×ש",onClick:()=>{var y;b[0]?g(b[0].account.id):(y=h.current)==null||y.focus()},className:"w-11 h-11 rounded-xl bg-teal-600 text-white grid place-items-center flex-none hover:bg-teal-700 transition-colors",children:e.jsx(qt,{className:"w-5 h-5"})}),e.jsx("span",{className:"hidden lg:block w-px h-8 bg-teal-200/80 flex-none"}),e.jsxs("button",{type:"button",onClick:()=>u(y=>
52!y),"aria-expanded":p,className:`h-11 px-4 rounded-xl border text-[13px] font-bold inline-flex items-center gap-1.5 flex-none transition-colors ${p?"bg-teal-600 border-teal-600 text-white":"bg-white border-teal-300 text-teal-700 hover:bg-teal-50"}`,children:[e.jsx(Hn,{className:"w-4 h-4"})," ××פ×ש ×תק××"]})]}),p&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-teal-200/60",children:[e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-5 gap-2",children:Ep.map(y=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-[11px] font-bold text-slate-500 mb-1",children:y.l}),e.jsx("input",{value:d[y.k],placeholder:y.p,autoComplete:"off",onChange:$=>c(O=>({...O,[y.k]:$.target.value})),className:`w-full h-9 rounded-xl border border-slate-200 bg-white px-3 text-[13px] text-slate-800 53 focus:outline-none focus:border-teal-500 focus:ring-4 focus:ring-teal-50 transition-colors`})]},y.k))}),e.jsx("div",{className:"mt-2.5",children:f?x.length===0?e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("p",{className:"text-[12.5px] text-slate-500",children:"×× × ××¦× ×ש××× ×©×¢×× × ×¢× ×× ×ש××ת."}),e.jsx("button",{type:"button",onClick:()=>c(sn),className:"text-[12px] font-bold text-teal-700 hover:underline",children:"× ××§×× ×ש××ת"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[e.jsx("span",{className:"text-[12px] font-bold text-slate-500",children:_e(x.length,"×ש××× ×××","×ש××× ×ת")}),e.jsx("button",{type:"button",onClick:()=>c(sn),className:"text-[12px] font-bold text-teal-700 hover:underline",children:"× ××§×× ×ש××ת"})]}),e.jsx("ul",{className:"bg-white rounded-2xl border border-slate-200 p-1.5 max-h-72 overflow-y-auto",children:x.map(y=>e.jsx("li",{children:e.jsx(Ci,{h:y,onPick:g})},y.account.id))})]}):e.jsx("p",{className:"text-[12px] text-slate-400",children:"×××× ×©×× ××× ×× ××תר â ××צ×× ×¨×§ ×ש××× ×ת שע×× ×× ×¢× ××××."})})]})]})}const ar=t=>String(t).padStart(2,"0"),gc=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"],nr=gc,Rs=(t,s,n)=>`${t}-${ar(s+1)}-${ar(n)}`,Ai=(t,s)=>new Date(t,s+1,0).getDate(),Al=[{v:"month",l:"×××ש×",hint:"×××ש ×××"},{v:"quarter",l:"ר××¢×× ×",hint:"ש×××©× ×××ש××"},{v:"year",l:"×©× ×ª×",hint:"×©× × ×©×××"},{v:"range",l:"×××× ×ª×ר××××",hint:"×ת×ר×× ×¢× ×ª×ר××"}],hs=[{v:1,l:"ר××¢×× ×¨×ש××",months:[0,2]},{v:2,l:"ר××¢×× ×©× ×",months:[3,5]},{v:3,l:"ר××¢×× ×©××ש×",months:[6,8]},{v:4,l:"ר××¢×× ×¨×××¢×",months:[9,11]}],Dp=(t=new Date)=>({mode:"year",year:t.getFullYear(),month:t.getMonth(),quarter:Math.floor(t.getMonth()/3)+1,from:"",to:""});function yc(t){const s=t||{},n=Number(s.year)||new Date().getFullYear();if(s.mode==="month"){const a=Math.min(11,Math.max(0,Number(s.month)||0));return{from:Rs(n,a,1),to:Rs(n,a,Ai(n,a))}}if(s.mode==="quarter"){const a=hs.find(o=>o.v===Number(s.quarter))||hs[0],[l,r]=a.months;return{from:Rs(n,l,1),to:Rs(n,r,Ai(n,r))}}if(s.mode==="range"){const a=String(s.from||"").slice(0,10),l=String(s.to||"").slice(0,10);return{from:a,to:l}}return{from:Rs(n,0,1),to:Rs(n,11,31)}}function Cs(t){const s=t||{},n=Number(s.year)||new Date().getFullYear();if(s.mode==="month")return`${gc[Math.min(11,Math.max(0,Number(s.month)||0))]} ${n}`;if(s.mode==="quarter")return`${(hs.find(a=>a.v===Number(s.quarter))||hs[0]).l} ${n}`;if(s.mode==="range"){const a=o=>{const[p,u,d]=String(o||"").slice(0,10).split("-");return d?`${d}/${u}/${p}`:""},l=a(s.from),r=a(s.to);return l&&r?`${l} â ${r}`:l?`×-${l}`:r?`×¢× ${r}`:"×× ×ת×ר××××"}return String(n)}function Jn(t,s){const n=String(t||"").slice(0,10);if(!n)return!1;const{from:a,to:l}=yc(s);return!(a&&n<a||l&&n>l)}function el(t){const{from:s,to:n}=yc(t);if(!s||!n)return[];const[a,l]=s.split("-").map(Number),[r,o]=n.split("-").map(Number),p=[];for(let u=a,d=l;(u<r||u===r&&d<=o)&&!(d>
5312&&(d=1,u+=1,u>r)||(p.push(`${u}-${ar(d)}`),p.length>=120));d+=1);return p}const mt=t=>Math.round(((Number(t)||0)+Number.EPSILON)*100)/100,Ft=t=>Number.isFinite(Number(t))?Number(t):0,Op=new Set(["pending_payment","cancelled","rejected"]),Lp=t=>(t==null?void 0:t.paid)===!0||["completed","paid"].includes(t==null?void 0:t.payment_status),Mi=[{v:"charge_type",l:"ס×× ××××",icon:"tag",tone:"teal"},{v:"payment_page",l:"×¢×××× ×ª×©×××",icon:"link",tone:"purple"},{v:"event",l:"×××× ××ר××¢××",icon:"calendar",tone:"sky"},{v:"class",l:"××××× ×ס×× ××ת",icon:"users",tone:"emerald"},{v:"venue",l:"×××× ×× ×ת×ר××",icon:"clock",tone:"indigo"},{v:"quick_charge",l:"ס×××§× ×××ר×",icon:"zap",tone:"amber"}],Tp=t=>Mi.find(s=>s.v===t)||Mi[0],qs=t=>String(t||"").slice(0,7),Is=(t,s,n,a=!0)=>({key:t,name:s,kind:n,connected:a,count:0,amount:0,paid:0,open:0,byMonth:{}}),zs=(t,{amount:s,paid:n,month:a})=>{t.count+=1,t.amount=mt(t.amount+s),t.paid=mt(t.paid+n),t.open=mt(Math.max(0,t.amount-t.paid)),a&&(t.byMonth[a]=mt((t.byMonth[a]||0)+s))};function Bp({charges:t=[],types:s=[],purchases:n=[],eventRegs:a=[],classRegs:l=[],bookings:r=[],quickCharges:o=[],connected:p={},paidOf:u=()=>0,inRange:d=()=>!0}={}){const c=new Map,m=new Map((s||[]).map(y=>[y.id,y]));for(const y of s||[])c.set(`type:${y.id}`,Is(`type:${y.id}`,y.name||"ס×× ××××","charge_type"));for(const y of t||[]){if((y==null?void 0:y.status)==="cancelled")continue;const $=y.due_date||y.created_date;if(!d($))continue;const O=m.get(y.charge_type_id);if(!O)continue;const A=`type:${O.id}`,S=Math.max(0,Ft(y.amount)-Ft(y.discount_amount)-Ft(y.credit_amount));zs(c.get(A),{amount:S,paid:Math.min(S,Math.max(0,Ft(u(y)))),month:qs($)})}const h=Is("pages","×¢×××× ×ª×©×××","payment_page");for(const y of n||[]){const $=y.paid_date||y.created_date;if(!d($)||!["paid","refunded"].includes(y.status))continue;const O=Ft(y.amount??y.total_amount??y.price);zs(h,{amount:y.status==="refunded"?0:O,paid:y.status==="refunded"?0:O,month:qs($)})}c.set("pages",h);const b=Is("events","×××× ××ר××¢××","event");for(const y of a||[]){if(Op.has(y==null?void 0:y.status))continue;const $=y.payment_completed_at||y.created_date;if(!d($))continue;const O=Ft(y.payment_amount);O>0&&zs(b,{amount:O,paid:Lp(y)?O:0,month:qs($)})}c.set("events",b);const f=Is("classes","××××× ×ס×× ××ת","class",!!p.class);for(const y of l||[]){const $=y.paid_at||y.created_date;if(!d($))continue;const O=Ft(y.payment_amount??y.amount);zs(f,{amount:O,paid:y.payment_status==="paid"?O:0,month:qs($)})}c.set("classes",f);const x=Is("venues","×××× ×× ×ת×ר××","venue",!!p.venue);for(const y of r||[]){const $=y.paid_at||y.start_at||y.created_date;if(!d($))continue;const O=Ft(y.total_price??y.payment_amount??y.amount??y.price);zs(x,{amount:O,paid:y.payment_status==="paid"?O:0,month:qs($)})}c.set("venues",x);const g=Is("quick","ס×××§× ×××ר×","quick_charge",p.quick_charge!==!1);g.counted="charge_type";for(const y of o||[]){const $=y.paid_at||y.payment_date||y.created_date;if(!d($))continue;const O=Ft(y.amount??y.total_amount);zs(g,{amount:O,paid:y.status==="paid"?O:0,month:qs($)})}return c.set("quick",g),[...c.values()].sort((y,$)=>Number($.connected)-Number(y.connected)||$.amount-y.amount||String(y.name).localeCompare(String($.name),"he"))}function Rp(t=[]){const s=t.filter(n=>n.connected);return{sources:s.filter(n=>n.count>0).length,count:s.reduce((n,a)=>n+a.count,0),amount:mt(s.reduce((n,a)=>n+a.amount,0)),paid:mt(s.reduce((n,a)=>n+a.paid,0)),open:mt(s.reduce((n,a)=>n+a.open,0)),pending:t.filter(n=>!n.connected).length}}const Ml=(t,s)=>s>0?mt(t.amount/s*100):0;function qp(t=[],s=[],n=6){const a=t.filter(u=>u.connected&&u.amount>0),l=a.slice(0,n),r=a.slice(n),o=[...l.map(u=>({key:u.key,name:u.name,kind:u.kind})),...r.length?[{key:"_rest",name:"××§×ר×ת × ×ספ××",kind:"charge_type"}]:[]],p=s.map(u=>{const d={month:u};let c=0;for(const m of l){const h=mt(m.byMonth[u]||0);d[m.key]=h,c+=h}if(r.length){const m=mt(r.reduce((h,b)=>h+(b.byMonth[u]||0),0));d._rest=m,c+=m}return d._total=mt(c),d});return{series:o,data:p}}const Ze=t=>{const[s,n]=String(t||"").split("-");return n?`${n}/${s}`:String(t||"")},Pl=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0);function Ip({label:t,value:s,sub:n,tone:a="teal"}){const l={teal:"bg-teal-50/60 border-teal-100",sky:"bg-sky-50/60 border-sky-100",rose:"bg-rose-50/60 border-rose-100",amber:"bg-amber-50/60 border-amber-100",slate:"bg-slate-50 border-slate-100"};return e.jsxs("div",{className:`h-full rounded-2xl border px-4 py-3 min-w-0 text-right ${l[a]||l.teal}`,children:[e.jsx("span",{className:"block text-[11.5px] font-medium text-slate-500 truncate whitespace-nowrap",children:t}),e.jsx("span",{className:"block text-[17px] font-bold text-slate-800 leading-snug tabular-nums truncate mt-0.5",dir:"ltr",children:s}),n&&e.jsx("span",{className:"block text-[11px] text-slate-400 truncate whitespace-nowrap mt-0.5",children:n})]})}const qe=({color:t,children:s})=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-slate-600 whitespace-nowrap",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-none",style:{background:t}}),s]});function As({title:t,legend:s,note:n,center:a,children:l,height:r="20rem"}){return e.jsxs("section",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-5 paper-keep",children:[e.jsxs("header",{className:"flex items-center flex-wrap gap-x-4 gap-y-2 mb-4",children:[e.jsx("h4",{className:"text-[15px] font-black text-slate-800 flex-none",children:t}),s&&e.jsx("span",{className:"mr-auto flex items-center flex-wrap gap-x-4 gap-y-1",children:s})]}),e.jsxs("div",{className:"w-full relative",style:{height:r},dir:"ltr",children:[l,a&&e.jsx("span",{className:"absolute inset-0 grid place-items-center pointer-events-none text-center",children:e.jsxs("span",{children:[e.jsx("span",{className:"block text-[11.5px] font-bold text-slate-400",children:a.label}),e.jsx("span",{className:"block text-[19px] font-black text-slate-900 tabular-nums",dir:"ltr",children:a.value})]})})]}),n&&e.jsx("p",{className:"text-[11.5px] text-slate-400 mt-3 text-center",children:n})]})}function zp({page:t,pages:s,from:n,to:a,total:l,unit:r,onPage:o}){return l===0?null:e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-t border-slate-100 no-print",children:[e.jsxs("span",{className:"text-[12px] text-slate-500",children:["×צ×× ",Pl(n),"â",Pl(a)," ×ת×× ",Pl(l)," ",r]}),s>1&&e.jsxs("span",{className:"mr-auto flex items-center gap-1",children:[e.jsx("button",{type:"button","aria-label":"××§×××",disabled:t===1,onClick:()=>o(t-1),className:"w-8 h-8 rounded-lg border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50 disabled:opacity-30",children:e.jsx(oa,{className:"w-4 h-4"})}),Array.from({length:s},(p,u)=>u+1).slice(0,9).map(p=>e.jsx("button",{type:"button",onClick:()=>o(p),className:`w-8 h-8 rounded-lg text-[12.5px] font-bold ${p===t?"bg-teal-600 text-white":"border border-slate-200 text-slate-600 hover:bg-slate-50"}`,children:p},p)),e.jsx("button",{type:"button","aria-label":"×××",disabled:t===s,onClick:()=>o(t+1),className:"w-8 h-8 rounded-lg border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50 disabled:opacity-30",children:e.jsx(lt,{className:"w-4 h-4"})})]})]})}function Ms({title:t,period:s,subtitle:n,icon:a,tone:l="teal",stats:r=[],chart:o,tableTitle:p,columns:u=[],rows:d=[],totals:c,excelTotals:m,unit:h="רש×××ת",perPage:b=8,loading:f,empty:x="××× × ×ª×× ×× ×תק××¤× ×©× ××ר×",footNote:g,fileName:y}){const[$,O]=i.useState(1),A=i.useRef(null),[S,P]=i.useState(!1),[E,k]=i.useState(!1),[C,w]=i.useState(null),_=i.useMemo(()=>
53{if(!C)return d;const v=u.find(Z=>Z.key===C.key);if(!v)return d;const F=v.sort||(Z=>Z[v.key]),K=C.dir==="asc"?1:-1;return[...d].sort((Z,H)=>{const z=F(Z),te=F(H),ie=z==null||z==="",V=te==null||te==="";return ie||V?ie&&V?0:ie?1:-1:typeof z=="number"&&typeof te=="number"?(z-te)*K:String(z).localeCompare(String(te),"he",{numeric:!0})*K})},[d,C,u]);i.useEffect(()=>{O(1)},[C]);const T=v=>w(F=>(F==null?void 0:F.key)===v?F.dir==="desc"?{key:v,dir:"asc"}:null:{key:v,dir:"desc"}),M=Math.max(1,Math.ceil(_.length/b)),B=Math.min($,M),R=i.useMemo(()=>_.slice((B-1)*b,B*b),[_,B,b]),j=`${t} â ${s}`,q=async()=>{if(!d.length){W.error("××× × ×ª×× ×× ×××צ××");return}try{await nc({fileName:(y||t).replace(/\s+/g,"_"),sheetName:t,title:j,meta:[n,s].filter(Boolean),columns:u.map(v=>({key:v.key,header:v.label,type:v.type,width:v.width,value:v.excel||(F=>F[v.key])})),rows:_,totals:m})}catch{W.error("ש×××× ×××צ××")}},L=async()=>{if(!d.length){W.error("××× × ×ª×× ×× ×××צ××");return}P(!0);try{const{exportNodePdf:v}=await In(async()=>{const{exportNodePdf:F}=await import("./reportPdf-BRmDXPVe.js");return{exportNodePdf:F}},__vite__mapDeps([3,1,2]));await v(A.current,j),W.success("×§×××¥ ×-PDF × ×צר")}catch{W.error("ש×××× ××צ×רת ×-PDF")}finally{P(!1)}},N={teal:"text-teal-700 bg-teal-50 border-teal-100",rose:"text-rose-600 bg-rose-50 border-rose-100",sky:"text-sky-700 bg-sky-50 border-sky-100"};return e.jsxs("div",{ref:A,id:"billing-report",children:[e.jsx("style",{children:lc}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("section",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4 paper-keep",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1.7fr,1fr,1fr,1fr] gap-3 items-stretch",children:[e.jsxs("div",{className:"h-full rounded-2xl border border-slate-100 bg-slate-50/70 px-4 py-3 flex items-center gap-3 min-w-0",children:[a&&e.jsx("span",{className:`w-11 h-11 rounded-2xl grid place-items-center flex-none border ${N[l]||N.teal}`,children:e.jsx(a,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0 flex-1 text-right",children:[e.jsxs("h3",{className:"text-[18px] font-black text-slate-900 leading-tight truncate",title:`${t} â ${s}`,children:[t," â ",s]}),n&&e.jsx("p",{className:"text-[12px] text-slate-500 mt-0.5 truncate",title:n,children:n})]})]}),r.map(v=>e.jsx(Ip,{...v},v.label))]})}),e.jsx("div",{className:"min-h-[46rem]",children:f?e.jsx("div",{className:"grid place-items-center py-40",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-teal-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-4",children:[o,e.jsxs("section",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden paper-keep",children:[e.jsxs("div",{className:"flex items-center gap-3 px-5 pt-5 pb-3",children:[e.jsx("h4",{className:"text-[15px] font-black text-slate-800",children:p}),e.jsxs("span",{className:"relative mr-auto flex-none no-print",children:[e.jsxs("button",{type:"button",onClick:()=>k(v=>!v),"aria-expanded":E,className:`h-10 px-4 rounded-xl border border-slate-200 bg-white text-[13.5px] font-bold text-slate-600 54 inline-flex items-center gap-2 hover:border-slate-300`,children:[S?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(Hn,{className:"w-4 h-4 text-slate-400"}),"פע×××ת"]}),E&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"ס××ר×",onClick:()=>k(!1),className:"fixed inset-0 z-[40] cursor-default"}),e.jsxs("div",{className:"absolute left-0 z-[41] mt-1 w-48 rounded-xl border border-slate-200 bg-white shadow-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>{k(!1),L()},className:"w-full text-right px-3.5 py-2.5 text-[13.5px] font-bold text-slate-700 hover:bg-slate-50 inline-flex items-center gap-2 border-b border-slate-50",children:[e.jsx(go,{className:"w-4 h-4 text-rose-500"})," ×פקת PDF"]}),e.jsxs("button",{type:"button",onClick:()=>{k(!1),q()},className:"w-full text-right px-3.5 py-2.5 text-[13.5px] font-bold text-slate-700 hover:bg-slate-50 inline-flex items-center gap-2",children:[e.jsx(Sd,{className:"w-4 h-4 text-emerald-600"})," ××צ×× ××קס×"]})]})]})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 text-slate-500 text-[12px]",children:e.jsx("tr",{children:u.map(v=>
54{const F=(C==null?void 0:C.key)===v.key,K=F?C.dir==="desc"?_o:lo:jo;return e.jsx("th",{"aria-sort":F?C.dir==="asc"?"ascending":"descending":"none",className:"px-4 py-3 font-semibold whitespace-nowrap text-right",children:v.sortable===!1?v.label:e.jsxs("button",{type:"button",onClick:()=>T(v.key),title:`×××× ××¤× ${v.label}`,className:`w-full inline-flex items-center gap-2 text-right ${F?"text-teal-700":"hover:text-slate-700"}`,children:[e.jsx("span",{children:v.label}),e.jsx(K,{className:`w-3.5 h-3.5 mr-auto flex-none ${F?"text-teal-600":"text-slate-300"}`})]})},v.key)})})}),e.jsxs("tbody",{children:[R.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:u.length,className:"px-4 py-12 text-center text-[13px] text-slate-400",children:x})}),R.map((v,F)=>e.jsx("tr",{className:"border-t border-slate-100 hover:bg-slate-50/60",children:u.map(K=>e.jsx("td",{className:"px-4 py-3 text-right whitespace-nowrap",children:K.render?K.render(v):v[K.key]},K.key))},v.key||v.id||F))]}),c&&d.length>0&&e.jsx("tfoot",{children:e.jsx("tr",{className:"bg-teal-50/60 border-t-2 border-teal-100 font-semibold text-slate-900",children:u.map(v=>e.jsx("td",{className:"px-4 py-3 text-right whitespace-nowrap",children:c[v.key]??""},v.key))})})]})}),e.jsx(zp,{page:B,pages:M,unit:h,from:_.length?(B-1)*b+1:0,to:Math.min(B*b,_.length),total:_.length,onPage:O})]}),g&&e.jsx("p",{className:"text-[11.5px] text-slate-400 text-center",children:g})]})})]})]})}const jt=t=>ve(t),_a=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),ct=t=>t.connected&&t.counted!=="charge_type",Kp={tag:Xe,link:Zt,calendar:vs,users:De,clock:ws,zap:Ns},an=["#0f766e","#14b8a6","#6ee7b7","#7dd3fc","#a78bfa","#f9a8d4","#cbd5e1"],Pi={teal:"bg-teal-50 text-teal-700 border-teal-100",purple:"bg-purple-50 text-purple-700 border-purple-100",sky:"bg-sky-50 text-sky-700 border-sky-100",emerald:"bg-emerald-50 text-emerald-700 border-emerald-100",indigo:"bg-indigo-50 text-indigo-700 border-indigo-100",amber:"bg-amber-50 text-amber-700 border-amber-100"};function Wp({row:t}){const s=Tp(t.kind),n=Kp[s.icon]||Xe;return e.jsxs("span",{className:"inline-flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg border text-[12.5px] font-bold ${Pi[s.tone]||Pi.teal}`,children:[e.jsx(n,{className:"w-3.5 h-3.5 flex-none"}),e.jsx("span",{className:"truncate",children:t.name})]}),!t.connected&&e.jsx("span",{className:"text-[10.5px] font-bold text-slate-400 border border-slate-200 rounded-full px-2 py-0.5 whitespace-nowrap",children:"××¨× ××××ר"}),t.counted==="charge_type"&&e.jsx("span",{className:"text-[10.5px] font-bold text-teal-600 bg-teal-50 border border-teal-100 rounded-full px-2 py-0.5 whitespace-nowrap",children:"× ×¡×¤×¨ ת×ת ס×× ×××××"})]})}function Up({active:t,payload:s,label:n}){if(!t||!(s!=null&&s.length))return null;const a=s.filter(r=>Number(r.value)>0).reverse(),l=a.reduce((r,o)=>r+Number(o.value),0);return e.jsxs("div",{dir:"rtl",className:"rounded-xl border border-slate-200 bg-white shadow-lg px-3 py-2 min-w-[11rem]",children:[e.jsx("p",{className:"text-[12px] font-black text-slate-800 mb-1",children:Ze(n)}),e.jsx("ul",{className:"space-y-0.5",children:a.map(r=>e.jsxs("li",{className:"flex items-center gap-2 text-[11.5px]",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm flex-none",style:{background:r.color}}),e.jsx("span",{className:"text-slate-600 truncate",children:r.name}),e.jsx("span",{className:"mr-auto font-bold tabular-nums text-slate-800",dir:"ltr",children:jt(r.value)})]},r.dataKey))}),e.jsxs("p",{className:"mt-1.5 pt-1.5 border-t border-slate-100 flex items-center gap-2 text-[12px]",children:[e.jsx("span",{className:"font-bold text-slate-500",children:"ס××´×"}),e.jsx("span",{className:"mr-auto font-black tabular-nums text-slate-900",dir:"ltr",children:jt(l)})]})]})}function Hp({kibbutzId:t,scope:s}){const[n,a]=i.useState({loading:!0,charges:[],types:[],purchases:[],eventRegs:[],statements:[],payments:[]});i.useEffect(()=>{let m=!0;return a(h=>({...h,loading:!0})),Promise.all([D.entities.Charge.filterAllFields({kibbutz_id:t},["id","charge_type_id","payer_account_id","billing_period","statement_id","amount","discount_amount","credit_amount","status","due_date","created_date"]).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>
54[]),D.entities.PaymentPagePurchase.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.EventRegistration.filterAllFields({kibbutz_id:t,is_deleted:Me},["id","status","paid","payment_amount","payment_status","payment_completed_at","created_date"]).catch(()=>[]),D.entities.MonthlyStatement.filterAllFields({kibbutz_id:t},["id","status","billing_month","payer_account_id"]).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[])]).then(([h,b,f,x,g,y])=>{m&&a({loading:!1,charges:h||[],types:(b||[]).filter($=>$.is_active!==!1),purchases:f||[],eventRegs:x||[],statements:g||[],payments:y||[]})}).catch(()=>{m&&a(h=>({...h,loading:!1}))}),()=>{m=!1}},[t]);const l=i.useMemo(()=>xa({statements:n.statements,payments:n.payments,charges:n.charges}),[n.statements,n.payments,n.charges]),r=i.useMemo(()=>Bp({charges:n.charges,types:n.types,purchases:n.purchases,eventRegs:n.eventRegs,paidOf:l.paidOf,inRange:m=>Jn(m,s)}),[n,l,s]),o=i.useMemo(()=>Rp(r),[r]),p=i.useMemo(()=>el(s),[s]),u=i.useMemo(()=>qp(r,p),[r,p]),d=Cs(s),c=[{key:"name",label:"××§×ר ××××",width:26,render:m=>e.jsx(Wp,{row:m}),excel:m=>m.name},{key:"count",label:"×ספר ××××××",type:"num",render:m=>ct(m)?_a(m.count):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:m=>ct(m)?m.count:void 0},{key:"amount",label:"ס××× ×××××",type:"money",render:m=>ct(m)?jt(m.amount):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:m=>ct(m)?m.amount:void 0},{key:"paid",label:"ש×××",type:"money",render:m=>ct(m)?jt(m.paid):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:m=>ct(m)?m.paid:void 0},{key:"open",label:"×תר×",type:"money",render:m=>ct(m)?jt(m.open):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:m=>ct(m)?m.open:void 0},{key:"share",label:"×××× ××ס×××",type:"pct",render:m=>ct(m)?e.jsxs("span",{className:"tabular-nums font-medium text-slate-700",children:[Ml(m,o.amount).toFixed(1),"%"]}):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:m=>ct(m)?Ml(m,o.amount):void 0,sort:m=>ct(m)?Ml(m,o.amount):null}];return e.jsx(Ms,{title:"××× ××§×ר×ת ××××",period:d,subtitle:"ר×××× ××××××× ××× ×××××××× ××ער×ת",icon:Kn,loading:n.loading,fileName:`×××_××§×ר×ת_××××_${d}`,stats:[{label:"××§×ר×ת פע××××",value:_a(o.sources),tone:"teal",sub:o.pending?`${_a(o.pending)} ××§×ר×ת ××¨× ××××ר××`:null},{label:"ס××´× ××××××",value:_a(o.count),tone:"sky"},{label:"ס××× ××××",value:jt(o.amount),tone:"amber",sub:`ש××× ${jt(o.paid)}`}],chart:e.jsx(As,{title:"××§×ר×ת ××××× ××¤× ×××ש",legend:u.series.map((m,h)=>e.jsx(qe,{color:an[h%an.length],children:m.name},m.key)),height:"20rem",note:u.series.length?null:"××× ×××××× ×תק××¤× ×©× ××ר×.",children:e.jsx(Rt,{width:"100%",height:"100%",children:e.jsxs(Ba,{data:u.data,margin:{top:24,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#e2e8f0",vertical:!1}),e.jsx(Qt,{dataKey:"month",tickFormatter:Ze,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:{stroke:"#e2e8f0"},reversed:!0}),e.jsx(Ct,{tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:!1,orientation:"right",width:70,tickFormatter:m=>new Intl.NumberFormat("he-IL").format(m)}),e.jsx(ht,{content:e.jsx(Up,{}),cursor:{fill:"#f1f5f9"}}),u.series.map((m,h)=>e.jsx(pt,{dataKey:m.key,name:m.name,stackId:"all",fill:an[h%an.length],radius:h===u.series.length-1?[6,6,0,0]:0,children:h===u.series.length-1&&e.jsx(Ta,{dataKey:"_total",position:"top",offset:8,formatter:b=>Number(b)>0?new Intl.NumberFormat("he-IL").format(b):"",style:{fontSize:11,fontWeight:700,fill:"#334155"}})},m.key))]})})}),tableTitle:"פ×ר×× ××¤× ××§×ר ××××",columns:c,rows:r,unit:"××§×ר×ת",perPage:16,totals:{name:"ס××´×",count:_a(o.count),amount:jt(o.amount),paid:jt(o.paid),open:jt(o.open),share:"100.0%"},excelTotals:{count:o.count,amount:o.amount,paid:o.paid,open:o.open,share:100},footNote:"×× ×¡×× ×××× ×©×× ××× ×××××× Â«×¡××× ××××××» ×××¦× ×ש××¨× × ×¤×¨×ת. «ש×××» × ××ר ××ס××× ××ש××× ×××תש×××××, ××× ×ש×ר ×××××ת. ס×××§× ××××¨× × ×¨×©×ת ××××× ×תש××× ×¨×××××, ×××× ××× × ×¡×¤×¨×ª ת×ת ס×× ××××× ×©×× ××× ×¤×¢××××. ××§×ר ש××¨× ×××ר ×××¦× ×ת×ת×ת ××××× ××× ×ספר×× â «××× × ×ª×× ××» ׫×× × ×××» ××× × ×××ª× ××ר."})}const _t=t=>ve(t),hn=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0);function Yp({active:t,payload:s}){var a;if(!t||!(s!=null&&s.length))return null;const n=(a=s[0])==null?void 0:a.payload;return n?e.jsxs("div",{dir:"rtl",className:"rounded-xl border border-slate-200 bg-white shadow-lg px-3 py-2",children:[e.jsxs("p",{className:"text-[12px] font-black text-slate-800 flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full",style:{background:n.color}}),n.label]}),e.jsx("p",{className:"text-[12px] text-slate-600 mt-1 tabular-nums",dir:"ltr",children:_t(n.gross)}),e.jsxs("p",{className:"text-[11.5px] text-slate-400",children:[hn(n.count)," תש×××××"]})]}):null}function Vp({kibbutzId:t,scope:s}){const[n,a]=i.useState({loading:!0,payments:[]});i.useEffect(()=>{let u=!0;return a(d=>({...d,loading:!0})),D.entities.Payment.filterAll({kibbutz_id:t}).then(d=>{u&&a({loading:!1,payments:d||[]})}).catch(()=>{u&&a({loading:!1,payments:[]})}),()=>{u=!1}},[t]);const l=i.useMemo(()=>Ux({payments:n.payments,inRange:u=>Jn(u,s)}),[n.payments,s]),r=i.useMemo(()=>Hx(l),[l]),o=Cs(s),p=[{key:"label",label:"×××¦×¢× ×ª×©×××",width:22,render:u=>e.jsxs("span",{className:"inline-flex items-center gap-2 font-medium text-slate-700 whitespace-nowrap",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-none",style:{background:u.color}}),u.label]}),excel:u=>u.label},{key:"count",label:"×ספר תש×××××",type:"num",render:u=>hn(u.count)},{key:"gross",label:"ס×××",type:"money",render:u=>_t(u.gross)},{key:"fee",label:"×¢×××ת",type:"money",render:u=>r.hasFees?_t(u.fee):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:u=>r.hasFees?u.fee:void 0},{key:"net",label:"× ××",type:"money",render:u=>e.jsx("span",{className:"font-medium text-slate-800",children:_t(u.net)})},{key:"share",label:"×××× ×××××××",type:"pct",render:u=>{const d=ya(u,r.gross);return e.jsxs("span",{className:"inline-flex items-center gap-2 min-w-[7rem]",children:[e.jsx("span",{className:"flex-1 h-1.5 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,d)}%`,background:u.color}})}),e.jsxs("span",{className:"tabular-nums font-medium text-slate-700 text-[12.5px] w-12 text-left",dir:"ltr",children:[d.toFixed(1),"%"]})]})},excel:u=>ya(u,r.gross),sort:u=>ya(u,r.gross)}];return e.jsx(Ms,{title:"××× ×××¦×¢× ×ª×©×××",period:o,subtitle:"×תפ×××ת ×××××× ××¤× ×××¦×¢× ×תש××× ×©× ×¤×¨×¢ ××",icon:Oe,tone:"sky",loading:n.loading,fileName:`×××_××צע×_תש×××_${o}`,stats:[{label:"ס××´× × ×××",value:_t(r.gross),tone:"teal",sub:r.hasFees?`× ×× ${_t(r.net)}`:null},{label:"×ספר תש×××××",value:hn(r.count),tone:"sky"},{label:"×××¦×¢× ×××××",value:r.leader,tone:"amber",sub:l[0]?`${ya(l[0],r.gross).toFixed(1)}% ×××××××`:null}],chart:e.jsx(As,{title:"×תפ×××ת ××××××",legend:l.map(u=>e.jsxs(qe,{color:u.color,children:[u.label," · ",e.jsxs("b",{className:"tabular-nums",children:[ya(u,r.gross).toFixed(1),"%"]})]},u.key)),height:"20rem",center:l.length?{label:"ס××´× × ×××",value:_t(r.gross)}:null,note:l.length?null:"×× × ×¨×©×× ×ª×©××××× ×תק××¤× ×©× ××ר×.",children:e.jsx(Rt,{width:"100%",height:"100%",children:e.jsxs(Yn,{children:[e.jsx(Vn,{data:l,dataKey:"gross",nameKey:"label",innerRadius:"58%",outerRadius:"86%",paddingAngle:l.length>1?2:0,stroke:"#fff",strokeWidth:2,children:l.map(u=>e.jsx(_s,{fill:u.color},u.key))}),e.jsx(ht,{content:e.jsx(Yp,{})})]})})}),tableTitle:"פ×ר×× ××¤× ×××¦×¢× ×ª×©×××",columns:p,rows:l,unit:"××צע××",totals:{label:"ס××´×",count:hn(r.count),gross:_t(r.gross),fee:r.hasFees?_t(r.fee):"â",net:_t(r.net),share:l.length?"100.0%":"â"},excelTotals:{count:r.count,gross:r.gross,...r.hasFees?{fee:r.fee}:{},net:r.net,share:l.length?100:void 0},footNote:"× ×¡×¤×¨×× ×ª×©××××× ×©× ×¤×¨×¢× ××××. ×¢×××ת ס×××§× ××× × × ×©×ר×ת ×××× ×¢× ×תש×××, ×××× ××¢×××× ×¨××§× ××× ×פס."})}const bn=t=>ve(t),Hs=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),Gp=t=>{const[s,n,a]=String(t||"").slice(0,10).split("-");return a?`${a}/${n}/${s}`:"â"},El=t=>t>
5490?"#e11d48":t>30?"#f59e0b":"#94a3b8";function Xp({active:t,payload:s,label:n}){var l;if(!t||!(s!=null&&s.length))return null;const a=(l=s[0])==null?void 0:l.payload;return e.jsxs("div",{dir:"rtl",className:"rounded-xl border border-slate-200 bg-white shadow-lg px-3 py-2",children:[e.jsx("p",{className:"text-[12px] font-black text-slate-800",children:Ze(n)}),e.jsx("p",{className:"text-[12px] text-slate-600 mt-1 tabular-nums",dir:"ltr",children:bn(a==null?void 0:a.amount)}),e.jsxs("p",{className:"text-[11.5px] text-slate-400",children:[Hs(a==null?void 0:a.count)," ×××××× ×××××ר"]})]})}function Zp({kibbutzId:t,scope:s}){const[n,a]=i.useState({loading:!0,charges:[],accounts:[],types:[],statements:[],payments:[]});i.useEffect(()=>{let b=!0;return a(f=>({...f,loading:!0})),Promise.all([D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.PayerAccount.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.MonthlyStatement.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[])]).then(([f,x,g,y,$])=>{b&&a({loading:!1,charges:f||[],accounts:x||[],types:g||[],statements:y||[],payments:$||[]})}).catch(()=>{b&&a(f=>({...f,loading:!1}))}),()=>{b=!1}},[t]);const l=i.useMemo(()=>zt(n.charges,n.types,{ready:!n.loading}),[n.charges,n.types,n.loading]),r=i.useMemo(()=>xa({statements:n.statements,payments:n.payments,charges:l}),[n.statements,n.payments,l]),o=i.useMemo(()=>Yx({charges:l.filter(b=>Jn(b.due_date,s)),accounts:n.accounts,types:n.types,isPaid:r.isPaid}),[l,n.accounts,n.types,r,s]),p=i.useMemo(()=>Vx(o),[o]),u=i.useMemo(()=>el(s),[s]),d=i.useMemo(()=>Gx(o,u),[o,u]),c=Cs(s),m=i.useMemo(()=>new Set(o.map(b=>b.payer)).size,[o]),h=[{key:"payer",label:"×ש××× ×ש××",width:24,render:b=>e.jsxs("span",{className:"min-w-0 block",children:[e.jsx("span",{className:"block font-medium text-slate-800 truncate",children:b.payer}),b.account&&e.jsxs("span",{className:"block text-[11.5px] text-slate-400 tabular-nums",dir:"ltr",children:["#",b.account]})]}),excel:b=>b.payer},{key:"type",label:"ס×× ××××",render:b=>e.jsx("span",{className:"text-slate-600",children:b.type})},{key:"dueDate",label:"×××¢× ×ª×©×××",type:"date",render:b=>e.jsx("span",{className:"tabular-nums",dir:"ltr",children:Gp(b.dueDate)})},{key:"days",label:"××× ××××ר",type:"num",render:b=>e.jsx("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[12.5px] font-bold tabular-nums",style:{color:El(b.days),background:`${El(b.days)}14`},children:Hs(b.days)})},{key:"balance",label:"××ª×¨× ×תש×××",type:"money",render:b=>e.jsx("span",{className:"font-medium text-slate-800",children:bn(b.balance)})}];return e.jsx(Ms,{title:"××× ×ש××× ×ת ×××××ר",period:c,subtitle:"×××××× ×©×××¢× ×תש××× ×©××× ×¢×ר ×××¨× × ×¤×¨×¢×",icon:ws,tone:"rose",loading:n.loading,fileName:`×××_×ש××× ×ת_×××××ר_${c}`,empty:"××× ×××××× ×××××ר ×תק××¤× ×©× ××ר×.",stats:[{label:"××ª×¨× ×××××ר",value:bn(p.balance),tone:"rose"},{label:"×ש××× ×ת ×××××ר",value:Hs(m),tone:"amber",sub:`${Hs(p.count)} ××××××`},{label:"×××צע ××× ××××ר",value:Hs(p.avgDays),tone:"slate",sub:"×ש××§×× ××¤× ×¡×××"}],chart:e.jsx(As,{title:"××ª×¨× ×××××ר ××¤× ×××ש ×××××",legend:[e.jsx(qe,{color:"#94a3b8",children:"×¢× 30 ×××"},"a"),e.jsx(qe,{color:"#f59e0b",children:"31â90 ×××"},"b"),e.jsx(qe,{color:"#e11d48",children:"××¢× 90 ×××"},"c")],height:"20rem",note:o.length?"×צ××¢ × ×§××¢ ××¤× ×תק ×××××ר ×©× ××××××× ××××ª× ×××ש.":"××× ×××××× ×××××ר ×תק××¤× ×©× ××ר×.",children:e.jsx(Rt,{width:"100%",height:"100%",children:e.jsxs(Ba,{data:d,margin:{top:24,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#e2e8f0",vertical:!1}),e.jsx(Qt,{dataKey:"month",tickFormatter:Ze,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:{stroke:"#e2e8f0"},reversed:!0}),e.jsx(Ct,{tick:{fontSize:11,fill:"#64748b"}
54,tickLine:!1,axisLine:!1,orientation:"right",width:70,tickFormatter:b=>new Intl.NumberFormat("he-IL").format(b)}),e.jsx(ht,{content:e.jsx(Xp,{}),cursor:{fill:"#f1f5f9"}}),e.jsxs(pt,{dataKey:"amount",radius:[6,6,0,0],maxBarSize:54,children:[d.map(b=>{const f=o.filter(g=>g.month===b.month),x=f.length?Math.max(...f.map(g=>g.days)):0;return e.jsx(_s,{fill:El(x)},b.month)}),e.jsx(Ta,{dataKey:"amount",position:"top",offset:8,formatter:b=>Number(b)>0?new Intl.NumberFormat("he-IL").format(b):"",style:{fontSize:11,fontWeight:700,fill:"#334155"}})]})]})})}),tableTitle:"פ×ר×× ××××××× ×××××ר",columns:h,rows:o,unit:"××××××",totals:{payer:"ס××´×",days:p.avgDays?`${Hs(p.avgDays)} ××××צע`:"",balance:bn(p.balance)},excelTotals:{days:p.avgDays,balance:p.balance},footNote:"×××× × ××©× ×¤×¨××¢ ×ש×ס×× ××ש××× ×©×× ×¡××× ×ש××× ×× ×©×ª×©×××× ×תק××¤× ××ס×× ×ת ×××××× â ×××ª× ××× ×××××§ ש××× ××××××× ×¤××¢× ×פ××."})}const Ye=t=>ve(t),nn=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),Ei=["#0f766e","#14b8a6","#6ee7b7","#7dd3fc","#38bdf8","#a78bfa","#f9a8d4","#fbbf24","#cbd5e1"],Qp=t=>Ei[t%Ei.length];function Jp({active:t,payload:s}){var a;if(!t||!(s!=null&&s.length))return null;const n=(a=s[0])==null?void 0:a.payload;return n?e.jsxs("div",{dir:"rtl",className:"rounded-xl border border-slate-200 bg-white shadow-lg px-3 py-2",children:[e.jsxs("p",{className:"text-[12px] font-black text-slate-800 flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full",style:{background:n.color}}),n.name]}),e.jsx("p",{className:"text-[12px] text-slate-600 mt-1 tabular-nums",dir:"ltr",children:Ye(n.billed)}),e.jsxs("p",{className:"text-[11.5px] text-slate-400",children:["× ××× ",Ye(n.collected)]})]}):null}function eh({kibbutzId:t,scope:s}){const[n,a]=i.useState({loading:!0,charges:[],types:[],statements:[],payments:[]}),[l,r]=i.useState({});i.useEffect(()=>{let x=!0;return a(g=>({...g,loading:!0})),Promise.all([D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.MonthlyStatement.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[])]).then(([g,y,$,O])=>{x&&a({loading:!1,charges:g||[],types:(y||[]).filter(A=>A.is_active!==!1),statements:$||[],payments:O||[]})}).catch(()=>{x&&a(g=>({...g,loading:!1}))}),D.functions.invoke("listSumitBudgetItems",{community_id:t}).then(g=>{var $;if(!x)return;const y=(($=g==null?void 0:g.data)==null?void 0:$.budgetItems)||[];r(Object.fromEntries(y.map(O=>[String(O.id),O.name])))}).catch(()=>{x&&r({})}),()=>{x=!1}},[t]);const o=i.useMemo(()=>zt(n.charges,n.types,{ready:!n.loading}),[n.charges,n.types,n.loading]),p=i.useMemo(()=>xa({statements:n.statements,payments:n.payments,charges:o}),[n.statements,n.payments,o]),u=i.useMemo(()=>Xx({charges:o,types:n.types,paidOf:p.paidOf,inRange:x=>Jn(x,s),names:l}).map((x,g)=>({...x,color:Qp(g)})),[o,n.types,p,s,l]),d=i.useMemo(()=>n.types.some(x=>Jl(x)),[n.types]),c=i.useMemo(()=>Zx(u),[u]),m=Cs(s),h=i.useMemo(()=>u.filter(x=>x.billed>0),[u]),b=[{key:"name",label:"סע××£ תקצ××",width:24,render:x=>e.jsxs("span",{className:"inline-flex items-center gap-2 font-medium text-slate-800 min-w-0",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-none",style:{background:x.color}}),e.jsx("span",{className:"truncate",children:x.name})]}),excel:x=>x.name},{key:"count",label:"×ספר ××××××",type:"num",render:x=>nn(x.count)}
54,{key:"budget",label:"×ת×קצ×",type:"money",render:x=>x.budget==null?e.jsx("span",{className:"text-slate-300",children:"â"}):Ye(x.budget),excel:x=>x.budget==null?void 0:x.budget},{key:"billed",label:"ס××× ××××",type:"money",render:x=>Ye(x.billed)},{key:"collected",label:"× ×××",type:"money",render:x=>e.jsx("span",{className:"text-emerald-700 font-medium",children:Ye(x.collected)})},{key:"balance",label:"×תר×",type:"money",render:x=>Ye(x.balance)},{key:"done",label:"×××× ××צ××¢",type:"pct",render:x=>{const g=wl(x);return e.jsxs("span",{className:"inline-flex items-center gap-2 min-w-[7rem]",children:[e.jsx("span",{className:"flex-1 h-1.5 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,g)}%`,background:x.color}})}),e.jsxs("span",{className:"tabular-nums font-medium text-slate-700 text-[12.5px] w-12 text-left",dir:"ltr",children:[g.toFixed(1),"%"]})]})},excel:x=>wl(x),sort:x=>wl(x)}],f=c.billed>0?c.collected/c.billed*100:0;return e.jsx(Ms,{title:"××× ×¡×¢××¤× ×ª×§×¦××",period:m,subtitle:"××××× ××××××× ×פ××¢×, ××¤× ×סע××£ ש××סף × ××§×£ ××××",icon:xr,loading:n.loading,fileName:`×××_סע×פ×_תקצ××_${m}`,stats:[{label:"סע×פ×× ×¤×¢××××",value:nn(c.lines),tone:"teal",sub:`${nn(c.count)} ××××××`},{label:"ס××× ××××",value:Ye(c.billed),tone:"sky"},{label:"× ××× ×פ××¢×",value:Ye(c.collected),tone:"amber",sub:`${f.toFixed(1)}% ××צ××¢`}],chart:e.jsx(As,{title:"×××קת ××××× ××× ×סע×פ××",legend:h.map(x=>e.jsxs(qe,{color:x.color,children:[x.name," · ",e.jsxs("b",{className:"tabular-nums",children:[c.billed>0?(x.billed/c.billed*100).toFixed(1):"0.0","%"]})]},x.key)),height:"20rem",center:h.length?{label:"ס××× ××××",value:Ye(c.billed)}:null,note:h.length?null:"×× ×××× ××ר ×תק××¤× ×©× ××ר×.",children:e.jsx(Rt,{width:"100%",height:"100%",children:e.jsxs(Yn,{children:[e.jsx(Vn,{data:h,dataKey:"billed",nameKey:"name",innerRadius:"58%",outerRadius:"86%",paddingAngle:h.length>1?2:0,stroke:"#fff",strokeWidth:2,children:h.map(x=>e.jsx(_s,{fill:x.color},x.key))}),e.jsx(ht,{content:e.jsx(Jp,{})})]})})}),tableTitle:"פ×ר×× ××¤× ×¡×¢××£ תקצ××",columns:b,rows:u,unit:"סע×פ××",totals:{name:"ס××´×",count:nn(c.count),budget:c.budget==null?"â":Ye(c.budget),billed:Ye(c.billed),collected:Ye(c.collected),balance:Ye(c.balance),done:`${f.toFixed(1)}%`},excelTotals:{count:c.count,...c.budget==null?{}:{budget:c.budget},billed:c.billed,collected:c.collected,balance:c.balance,done:Number(f.toFixed(1))},footNote:d?"×סע×פ×× ××××ר×× ×××שק ס×××× ×× ×©×פ×× ×ש×. ס×× ×××× ×©×× ×©××× ×סע××£ ×××¦× ×ש××. ס××× ×ת××§×¦× ××× × × ×©×ר ×××× ×××× ×××¦× ×××§×£.":"×ס××× ××××× ×©× ××§×××× ××¨× ×©×××× ×¡×¢××¤× ×ª×§×¦×× ×ס××××, ×××× ×פ×××× ××× ××× ××¤× ×¡×× ×××××. ×ש××× × ×¢×©× ×××פס ס×× ×××××."})}const dt=t=>ve(t),th={emerald:"bg-emerald-50 text-emerald-700 border-emerald-200",rose:"bg-rose-50 text-rose-700 border-rose-200",slate:"bg-slate-100 text-slate-400 border-slate-200"};function sh({active:t,payload:s,label:n}){var l;if(!t||!(s!=null&&s.length))return null;const a=(l=s[0])==null?void 0:l.payload;return a?e.jsxs("div",{dir:"rtl",className:"rounded-xl border border-slate-200 bg-white shadow-lg px-3 py-2 min-w-[11rem]",children:[e.jsx("p",{className:"text-[12px] font-black text-slate-800 mb-1",children:Ze(n)}),e.jsxs("p",{className:"flex items-center gap-2 text-[11.5px]",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm",style:{background:"#cbd5e1"}}),e.jsx("span",{className:"text-slate-600",children:"××××"}),e.jsx("span",{className:"mr-auto font-bold tabular-nums text-slate-800",dir:"ltr",children:dt(a.billed)})]}),e.jsxs("p",{className:"flex items-center gap-2 text-[11.5px]",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm",style:{background:"#0d9488"}}),e.jsx("span",{className:"text-slate-600",children:"× ×××"}),e.jsx("span",{className:"mr-auto font-bold tabular-nums text-slate-800",dir:"ltr",children:dt(a.collected)})]}),e.jsxs("p",{className:"mt-1.5 pt-1.5 border-t border-slate-100 flex items-center gap-2 text-[12px]",children:[e.jsx("span",{className:"font-bold text-slate-500",children:"×××× ×××××"}),e.jsx("span",{className:"mr-auto font-black tabular-nums text-slate-900",dir:"ltr",children:a.billed>0?`${Number(a.rate||0).toFixed(1)}%`:"â"})]})]}):null}function ah({kibbutzId:t,settings:s,scope:n}){const[a,l]=i.useState({loading:!0,charges:[],types:[],statements:[],payments:[]});i.useEffect(()=>{let g=!0;return l(y=>({...y,loading:!0})),Promise.all([D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.MonthlyStatement.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[])]).then(([y,$,O,A])=>{g&&l({loading:!1,charges:y||[],types:$||[],statements:O||[],payments:A||[]})}).catch(()=>{g&&l(y=>({...y,loading:!1}))}),()=>{g=!1}},[t]);const r=i.useMemo(()=>zt(a.charges,a.types,{ready:!a.loading}),[a.charges,a.types,a.loading]),o=i.useMemo(()=>xa({statements:a.statements,payments:a.payments,charges:r}),[a.statements,a.payments,r]),p=i.useMemo(()=>el(n),[n]),u=i.useMemo(()=>Qx({charges:r,months:p,paidOf:o.paidOf}),[r,p,o]),d=i.useMemo(()=>Jx(u),[u]),c=Cs(n),m=Number(s==null?void 0:s.collection_target)>0?Number(s.collection_target):fc,h=i.useMemo(()=>u.map(g=>({...g,rate:g.billed>0?g.rate:null})),[u]),b=i.useMemo(()=>[...u].reverse().map(g=>({...g,key:g.month})),[u]),f=kl(d.rate,m),x=[{key:"month",label:"×××ש",width:14,render:g=>e.jsx("span",{className:"font-medium text-slate-800 tabular-nums",dir:"ltr",children:Ze(g.month)}),excel:g=>Ze(g.month),sort:g=>g.month},{key:"billed",label:"ס××× ××××",type:"money",render:g=>dt(g.billed)},{key:"collected",label:"× ×××",type:"money",render:g=>e.jsx("span",{className:"text-emerald-700 font-medium",children:dt(g.collected)})},{key:"balance",label:"×תר×",type:"money",render:g=>dt(g.balance)},{key:"rate",label:"×××× ×××××",type:"pct",render:g=>g.billed>0?e.jsxs("span",{className:"inline-flex items-center gap-2 min-w-[7rem]",children:[e.jsx("span",{className:"flex-1 h-1.5 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("span",{className:"block h-full rounded-full",style:{width:`${Math.min(100,g.rate)}%`,background:g.rate>=m-2?"#0d9488":"#e11d48"}})}),e.jsxs("span",{className:"tabular-nums font-medium text-slate-700 text-[12.5px] w-12 text-left",dir:"ltr",children:[g.rate.toFixed(1),"%"]})]}):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:g=>g.billed>0?g.rate:void 0},{key:"target",label:`××× ×××¢× (${m}%)`,render:g=>{const y=kl(g.rate,m);return e.jsx("span",{className:`inline-block px-2.5 py-1 rounded-lg border text-[12px] font-bold ${th[y.tone]}`,children:y.l})},excel:g=>kl(g.rate,m).l,sort:g=>g.billed>0?g.rate:null}];return e.jsx(Ms,{title:"××× ××××× ×××××",period:c,subtitle:"×××××× ×פ××¢× ××× ×××××, ×××ש ××××ש, ××× ××¢× ××§××××",icon:ks,loading:a.loading,fileName:`×××_×××××_×××××_${c}`,empty:"×× ×××× ××ר ×תק××¤× ×©× ××ר×.",stats:[{label:"ס××× ××××",value:dt(d.billed),tone:"sky"},{label:"× ××× ×פ××¢×",value:dt(d.collected),tone:"teal",sub:`××ª×¨× ${dt(d.balance)}`},{label:"×××× ×××××",value:`${d.rate.toFixed(1)}
54%`,tone:f.tone==="rose"?"rose":"amber",sub:`${f.l} · ××¢× ${m}%`}],chart:e.jsx(As,{title:"×××× ××× ×××××",legend:[e.jsx(qe,{color:"#cbd5e1",children:"××××"},"b"),e.jsx(qe,{color:"#0d9488",children:"× ×××"},"c"),e.jsx(qe,{color:"#f59e0b",children:"×××× ×××××"},"r")],height:"20rem",note:`××§× ×××§×××§× ××× ××¢× ×××××× ×©× ××§×××× â ${m}%.`,children:e.jsx(Rt,{width:"100%",height:"100%",children:e.jsxs(zo,{data:h,margin:{top:24,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#e2e8f0",vertical:!1}),e.jsx(Qt,{dataKey:"month",tickFormatter:Ze,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:{stroke:"#e2e8f0"},reversed:!0}),e.jsx(Ct,{yAxisId:"money",orientation:"right",width:70,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:!1,tickFormatter:g=>new Intl.NumberFormat("he-IL").format(g)}),e.jsx(Ct,{yAxisId:"rate",orientation:"left",width:44,domain:[0,100],tick:{fontSize:11,fill:"#94a3b8"},tickLine:!1,axisLine:!1,tickFormatter:g=>`${g}%`}),e.jsx(ht,{content:e.jsx(sh,{}),cursor:{fill:"#f1f5f9"}}),e.jsx(Mo,{yAxisId:"rate",y:m,stroke:"#f59e0b",strokeDasharray:"5 4",strokeWidth:1.5}),e.jsx(pt,{yAxisId:"money",dataKey:"billed",name:"××××",fill:"#cbd5e1",radius:[6,6,0,0],maxBarSize:38}),e.jsx(pt,{yAxisId:"money",dataKey:"collected",name:"× ×××",fill:"#0d9488",radius:[6,6,0,0],maxBarSize:38}),e.jsx(yr,{yAxisId:"rate",type:"linear",dataKey:"rate",name:"×××× ×××××",connectNulls:!1,stroke:"#f59e0b",strokeWidth:2.5,dot:{r:3,fill:"#f59e0b"}})]})})}),tableTitle:"פ×ר×× ×××ש×",columns:x,rows:b,unit:"×××ש××",perPage:12,totals:{month:"ס××´×",billed:dt(d.billed),collected:dt(d.collected),balance:dt(d.balance),rate:`${d.rate.toFixed(1)}%`,target:f.l},excelTotals:{billed:d.billed,collected:d.collected,balance:d.balance,rate:d.rate},footNote:"××××ש × ×§××¢ ××¤× ×××¢× ×××××: תש××× ×©××××¢ ×ספ×××ר ×¢× ×××× ×©× ×××××¡× × ××§×£ ×××××ס×."})}const Dt=t=>ve(t),Ot=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),_c=t=>{const[s,n,a]=String(t||"").slice(0,10).split("-");return a?`${a}/${n}/${s}`:"â"},Fi=t=>{const[s,n]=String(t||"").split("-"),a=nr[Number(n)-1];return a?`${a} ${String(s).slice(2)}`:String(t||"")};function nh({active:t,payload:s,label:n}){var l;if(!t||!(s!=null&&s.length))return null;const a=(l=s[0])==null?void 0:l.payload;return a?e.jsxs("div",{dir:"rtl",className:"rounded-xl border border-slate-200 bg-white shadow-lg px-3 py-2 min-w-[11rem]",children:[e.jsx("p",{className:"text-[12px] font-black text-slate-800 mb-1",children:Ze(n)}),e.jsx("p",{className:"text-[12px] text-slate-600 tabular-nums",dir:"ltr",children:Dt(a.billed)}),e.jsxs("p",{className:"text-[11.5px] text-slate-400",children:[Ot(a.count)," ××××××"]}),a.mainDate&&e.jsxs("p",{className:"text-[11.5px] text-slate-400",children:["×××¢× ×ר××× ",_c(a.mainDate)]})]}):null}function lh({kibbutzId:t,scope:s}){const[n,a]=i.useState({loading:!0,charges:[],types:[],statements:[],payments:[]});i.useEffect(()=>{let b=!0;return a(f=>({...f,loading:!0})),Promise.all([D.entities.Charge.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").catch(()=>[]),D.entities.MonthlyStatement.filterAll({kibbutz_id:t}).catch(()=>[]),D.entities.Payment.filterAll({kibbutz_id:t}).catch(()=>[])]).then(([f,x,g,y])=>{b&&a({loading:!1,charges:f||[],types:x||[],statements:g||[],payments:y||[]})}).catch(()=>{b&&a(f=>({...f,loading:!1}))}),()=>{b=!1}},[t]);const l=i.useMemo(()=>zt(n.charges,n.types,{ready:!n.loading}),[n.charges,n.types,n.loading]),r=i.useMemo(()=>xa({statements:n.statements,payments:n.payments,charges:l}),[n.statements,n.payments,l]),o=i.useMemo(()=>el(s),[s]),p=i.useMemo(()=>{const b=new Map((n.types||[]).map(f=>[f.id,f.name]));return f=>b.get(f.charge_type_id)||""},[n.types]),u=i.useMemo(()=>ep({charges:l,months:o,paidOf:r.paidOf,typeOf:p}),[l,o,r,p]),d=i.useMemo(()=>tp(u,o),[u,o]),c=Cs(s),m=i.useMemo(()=>[...u].filter(b=>b.count>0).reverse().map(b=>({...b,key:b.month})),[u]),h=[{key:"month",label:"×××ש",width:14,render:b=>e.jsx("span",{className:"font-medium text-slate-800",children:Fi(b.month)}),excel:b=>Fi(b.month),sort:b=>b.month},{key:"count",label:"×ספר ××××××",type:"num",render:b=>Ot(b.count)},{key:"types",label:"ס××× ××××××",width:24,render:b=>b.types.length?e.jsxs("span",{className:"inline-flex items-center gap-1.5 flex-nowrap",children:[b.types.slice(0,2).map(f=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-slate-50 border border-slate-100 text-[12px] font-medium text-slate-600 whitespace-nowrap",children:[f.name,e.jsx("span",{className:"text-slate-400 tabular-nums",children:Ot(f.count)})]},f.name)),b.types.length>2&&e.jsxs("span",{className:"text-[11.5px] font-medium text-slate-400 whitespace-nowrap",title:b.types.slice(2).map(f=>f.name).join(", "),children:["+",Ot(b.types.length-2)]})]}):e.jsx("span",{className:"text-slate-300",children:"â"}),excel:b=>b.types.map(f=>`${f.name} (${f.count})`).join(", "),sort:b=>b.types.length},{key:"billed",label:"ס××× ×××××",type:"money",render:b=>Dt(b.billed)},{key:"collected",label:"ש×××",type:"money",render:b=>e.jsx("span",{className:"text-emerald-700 font-medium",children:Dt(b.collected)})},{key:"balance",label:"×תר×",type:"money",render:b=>Dt(b.balance)},{key:"rate",label:"×××× ×××××",type:"pct",render:b=>e.jsxs("span",{className:"inline-flex items-center gap-2 min-w-[7rem]",children:[e.jsx("span",{className:"flex-1 h-1.5 rounded-full bg-slate-100 overflow-hidden",children:e.jsx("span",{className:"block h-full rounded-full bg-teal-600",
54style:{width:`${Math.min(100,b.rate)}%`}})}),e.jsxs("span",{className:"tabular-nums font-medium text-slate-700 text-[12.5px] w-12 text-left",dir:"ltr",children:[b.rate.toFixed(0),"%"]})]}),excel:b=>b.rate},{key:"mainDate",label:"×××¢× ×ר×××",type:"date",render:b=>e.jsxs("span",{className:"inline-block",children:[e.jsx("span",{className:"block font-medium text-slate-700 tabular-nums",dir:"ltr",children:_c(b.mainDate)}),b.dates>1&&e.jsxs("span",{className:"block text-[11px] text-slate-400",children:[Ot(b.dates)," ×××¢××× ××××ש"]})]}),excel:b=>b.mainDate}];return e.jsx(Ms,{title:"××× ×××¢×× ××××",period:c,subtitle:"ר×××× ×××××× ××¤× ×××¢× ××××× ××××¨× ××©× ×",icon:Be,loading:n.loading,fileName:`×××_×××¢××_××××_${c}`,empty:"×× × ×§××¢× ×××¢×× ×××× ×תק××¤× ×©× ××ר×.",stats:[{label:"ס××´× ××××××",value:Ot(d.count),tone:"teal",sub:d.months?`×-${Ot(d.months)} ×××ש××`:null},{label:"ס××× ×××××",value:Dt(d.billed),tone:"sky"},{label:"×××צע ×××ש×",value:Dt(d.avg),tone:"amber",sub:`×¢× ×¤× × ${Ot(o.length)} ×××ש××`}],chart:e.jsx(As,{title:"ס××× ××××× ××¤× ×××ש (âª)",legend:[e.jsx(qe,{color:"#2dd4a7",children:"ס××× ×××××"},"b")],height:"20rem",note:d.count?"×××ש ××× ×××××× × ×©×ר ×¢× ×צ×ר â ×××¢××××ª× ×סת××¨× ×©×× ×××× ×× ××ר.":"×× × ×§××¢× ×××¢×× ×××× ×תק××¤× ×©× ××ר×.",children:e.jsx(Rt,{width:"100%",height:"100%",children:e.jsxs(Ba,{data:u,margin:{top:26,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#e2e8f0",vertical:!1}),e.jsx(Qt,{dataKey:"month",tickFormatter:Ze,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:{stroke:"#e2e8f0"},reversed:!0}),e.jsx(Ct,{tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:!1,orientation:"right",width:70,tickFormatter:b=>new Intl.NumberFormat("he-IL").format(b)}),e.jsx(ht,{content:e.jsx(nh,{}),cursor:{fill:"#f1f5f9"}}),e.jsx(pt,{dataKey:"billed",fill:"#2dd4a7",radius:[6,6,0,0],maxBarSize:54,children:e.jsx(Ta,{dataKey:"billed",position:"top",offset:8,formatter:b=>new Intl.NumberFormat("he-IL").format(Math.round(Number(b)||0)),style:{fontSize:11,fontWeight:700,fill:"#334155"}})})]})})}),tableTitle:"פ×ר×× ××¤× ×××¢×× ××××",columns:h,rows:m,unit:"×××ש××",perPage:12,totals:{month:"ס××´×",count:Ot(d.count),types:"",billed:Dt(d.billed),collected:Dt(d.collected),balance:Dt(d.balance),rate:`${d.rate.toFixed(0)}%`,mainDate:"â"},excelTotals:{count:d.count,billed:d.billed,collected:d.collected,balance:d.balance,rate:d.rate},footNote:"××××ש × ×§××¢ ××¤× ×××¢× ×××××. «×××¢× ×ר×××» ××× ×××× ×©×¨×× ××סף ×©× ×××ª× ×××ש × ××¤× ×¢××× â ×× ×ר×ש×× ××× ××××צע."})}function ln({label:t,value:s,onClick:n,open:a}){return e.jsxs("button",{type:"button",onClick:n,"aria-expanded":a,className:`w-full h-11 pr-3 pl-2 rounded-xl border bg-white text-right inline-flex items-center gap-1.5 min-w-0 transition-colors ${a?"border-teal-400 ring-4 ring-teal-50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[10px] font-bold text-slate-400 leading-none",children:t}),e.jsx("span",{className:"block text-[13px] font-black text-slate-800 truncate leading-tight mt-0.5",children:s})]}),e.jsx(Jt,{className:`w-3.5 h-3.5 text-slate-400 flex-none transition-transform ${a?"rotate-180":""}`})]})}function rn({open:t,onClose:s,children:n,width:a="w-full"}){return t?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"ס××ר×",onClick:s,className:"fixed inset-0 z-[40] cursor-default"}),e.jsx("div",{className:`absolute z-[41] mt-1 ${a} min-w-[9rem] rounded-xl border border-slate-200 bg-white shadow-xl overflow-hidden`,children:n})]}):null}function rh(t=12){const[s,n]=i.useState(t);return i.useEffect(()=>{const a=()=>{const o=document.querySelector('header.sticky, header[class*="sticky"]'),p=o?Math.round(o.getBoundingClientRect().height):0;n(p+t)};a(),window.addEventListener("resize",a);const l=typeof ResizeObserver<"u"?new ResizeObserver(a):null,r=document.querySelector('header.sticky, header[class*="sticky"]');return l&&r&&l.observe(r),()=>{window.removeEventListener("resize",a),l==null||l.disconnect()}},[t]),s}const on=({on:t,children:s,onClick:n})=>e.jsxs("button",{type:"button",onClick:n,className:`w-full text-right px-3.5 py-2.5 text-[13.5px] font-bold flex items-center gap-2 border-b border-slate-50 last:border-0 ${t?"bg-teal-50/70 text-teal-800":"text-slate-700 hover:bg-slate-50"}`,children:[t?e.jsx(ye,{className:"w-4 h-4 flex-none",strokeWidth:3}):e.jsx("span",{className:"w-4 flex-none"}),s]}),ja=[{key:"dates",label:"×××¢×× ××××",icon:Be,hint:"××ª× × ×××, ××× ×¢×× ××¤× ×× ×",tone:"teal",Comp:lh},{key:"budget",label:"סע××¤× ×ª×§×¦××",icon:xr,hint:"××××× ×¡×¢××£ × ××§×£ ××סף",tone:"violet",Comp:eh},{key:"collection",label:"××××× ×××××",icon:ks,hint:"××× ×××××× × ×¤×¨×¢ ×פ××¢×",tone:"emerald",Comp:ah},{key:"late",label:"×ש××× ×ת ×××××ר",icon:ws,hint:"×× ××××, ×××× ×××",tone:"rose",Comp:Zp},{key:"methods",label:"×××¦×¢× ×ª×©×××",icon:Oe,hint:"××× ×ש××××",tone:"sky",Comp:Vp},{key:"sources",label:"××§×ר×ת ××××",icon:Kn,hint:"××××× ××××× ××××¢",tone:"amber",Comp:Hp}],Di={teal:"bg-teal-50 text-teal-600",violet:"bg-violet-50 text-violet-600",emerald:"bg-emerald-50 text-emerald-600",rose:"bg-rose-50 text-rose-500",sky:"bg-sky-50 text-sky-600",amber:"bg-amber-50 text-amber-600"};function ih({kibbutzId:t,settings:s}){const n=rh(),[a,l]=i.useState(()=>{var x;return((x=ja.find(g=>g.Comp))==null?void 0:x.key)||ja[0].key}),[r,o]=i.useState(()=>Dp()),[p,u]=i.useState(""),d=()=>u(""),c=x=>{o(g=>({...g,...x})),d()},m=i.useMemo(()=>{const x=new Date().getFullYear();return[x+1,x,x-1,x-2,x-3,x-4]},[]),h=Al.find(x=>x.v===r.mode)||Al[2],b=ja.find(x=>x.key===a)||ja[0],f=b.Comp;return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr,17rem] gap-4 items-start",children:[e.jsx("div",{className:"min-w-0 order-2 lg:order-1",children:f?e.jsx(f,{kibbutzId:t,settings:s,scope:r},b.key):null}),e.jsx("aside",{className:"no-print order-1 lg:order-2 lg:sticky lg:self-start",style:{to
54p:`${n}px`,maxHeight:`calc(100vh - ${n+16}px)`},children:e.jsxs("div",{className:"space-y-3 lg:overflow-y-auto lg:max-h-full lg:pl-0.5",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-gradient-to-b from-teal-50/70 to-white shadow-sm p-4",children:[e.jsx("h3",{className:"text-[19px] font-black text-slate-900 leading-tight",children:"××××ת, ××× ×ש××××"}),e.jsx("p",{className:"text-[12px] text-slate-500 mt-1",children:"ר×××××× ××¤× ×ת×, ×¢× ×ª×§××¤× ××ת"}),e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("span",{className:"relative block",children:[e.jsx(ln,{label:"תק×פ×",value:h.l,open:p==="mode",onClick:()=>u(x=>x==="mode"?"":"mode")}),e.jsx(rn,{open:p==="mode",onClose:d,width:"w-52",children:Al.map(x=>e.jsx(on,{on:x.v===r.mode,onClick:()=>c({mode:x.v}),children:e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:x.l}),e.jsx("span",{className:"block text-[11px] font-normal text-slate-400",children:x.hint})]})},x.v))})]}),e.jsxs("span",{className:"relative block",children:[e.jsx(ln,{label:"×©× ×",value:String(r.year),open:p==="year",onClick:()=>u(x=>x==="year"?"":"year")}),e.jsx(rn,{open:p==="year",onClose:d,children:e.jsx("div",{className:"max-h-64 overflow-y-auto",children:m.map(x=>e.jsx(on,{on:x===r.year,onClick:()=>c({year:x}),children:x},x))})})]})]}),r.mode==="month"&&e.jsxs("span",{className:"relative block",children:[e.jsx(ln,{label:"×××ש",value:nr[r.month]||"",open:p==="month",onClick:()=>u(x=>x==="month"?"":"month")}),e.jsx(rn,{open:p==="month",onClose:d,children:e.jsx("div",{className:"max-h-64 overflow-y-auto",children:nr.map((x,g)=>e.jsx(on,{on:g===r.month,onClick:()=>c({month:g}),children:x},x))})})]}),r.mode==="quarter"&&e.jsxs("span",{className:"relative block",children:[e.jsx(ln,{label:"ר××¢××",value:(hs.find(x=>x.v===r.quarter)||hs[0]).l,open:p==="quarter",onClick:()=>u(x=>x==="quarter"?"":"quarter")}),e.jsx(rn,{open:p==="quarter",onClose:d,children:hs.map(x=>e.jsx(on,{on:x.v===r.quarter,onClick:()=>c({quarter:x.v}),children:x.l},x.v))})]}),r.mode==="range"&&e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[["from","×ת×ר××"],["to","×¢× ×ª×ר××"]].map(([x,g])=>e.jsxs("label",{className:"h-11 px-3 rounded-xl border border-slate-200 bg-white flex flex-col justify-center min-w-0",children:[e.jsx("span",{className:"text-[10px] font-bold text-slate-400 leading-none",children:g}),e.jsx("input",{type:"date",value:r[x]||"",onChange:y=>o($=>({...$,[x]:y.target.value})),className:"text-[12.5px] font-bold text-slate-800 bg-transparent focus:outline-none tabular-nums min-w-0"})]},x))})]}),e.jsxs("p",{className:"mt-2.5 text-[12px] text-slate-500 flex items-center gap-1.5",children:[e.jsx(vs,{className:"w-3.5 h-3.5 text-slate-400 flex-none"}),"×××¦× ×¢××ר ",e.jsx("b",{className:"text-slate-700",children:Cs(r)})]})]}),e.jsx("nav",{className:"rounded-2xl border border-slate-200 bg-white shadow-sm p-2 space-y-1","aria-label":"××××ת ×ª× ××¢×ת",children:ja.map(x=>{const g=x.icon,y=x.key===a,$=!!x.Comp;return e.jsxs("button",{type:"button",disabled:!$,onClick:()=>$&&l(x.key),"aria-current":y?"page":void 0,title:$?x.hint:"×××× ×",className:`w-full text-right rounded-xl px-3 py-2.5 flex items-center gap-2.5 transition-colors ${y?"bg-teal-600 text-white shadow-sm":$?"text-slate-700 hover:bg-slate-50":"text-slate-300 cursor-not-allowed"}`,children:[e.jsx("span",{className:`w-8 h-8 rounded-lg grid place-items-center flex-none ${y?"bg-white/20 text-white":$?Di[x.tone]||Di.teal:"bg-slate-50 text-slate-300"}`,children:$?e.jsx(g,{className:"w-4 h-4"}):e.jsx(io,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[14px] font-bold truncate",children:x.label}),e.jsx("span",{className:`block text-[11px] truncate ${y?"text-white/70":"text-slate-400"}`,children:$?x.hint:"×××× ×"})]})]},x.key)})})]})})]})}const jc=[{v:"billed",l:"ס××× ××××",unit:"money",hint:"××× ××××"},{v:"collected",l:"ס××× ×©×©×××",unit:"money",hint:"××× × ××× ×פ××¢×"},{v:"balance",l:"××ª×¨× ×¤×ª×××",unit:"money",hint:"××× ×¢×× ×× ×©×××"},{v:"overdue",l:"×××××× ×××××ר",unit:"money",hint:"×¢×ר ××××¢× ××× ×©×××"},{v:"rate",l:"×××× ×××××",unit:"percent",hint:"××× ×××××× × ×¤×¨×¢"},{v:"payments",l:"תש××××× ×©× ×§×××",unit:"money",hint:"×סף ×©× ×× ×¡ ×פ××¢×"},{v:"credits",l:"×××××××",unit:"money",hint:"××× ××××"},{v:"cancelled",l:"×××××××",unit:"money",hint:"×××××× ×©×××××"},{v:"failed",l:"עסק××ת ×©× ×ש××",unit:"money",hint:"תש××××× ×©× ×××"}],lr=t=>jc.find(s=>s.v===t)||null,Nc=[{v:"month",l:"×××ש"},{v:"method",l:"×××¦×¢× ×ª×©×××"},{v:"budget",l:"סע××£ תקצ××"},{v:"type",l:"ס×× ××××"},{v:"status",l:"ס×××ס"},{v:"source",l:"××§×ר ××××"},{v:"account",l:"×ש××× ×ש××"}],oh=t=>Nc.find(s=>s.v===t)||null,vc=[{v:"due",l:"×××¢× ×××××",hint:"×ת×ר×× ×©×× ××××× ×××ר ××××××ת"},{v:"created",l:"×××¢× ×צ×רת ×××××",hint:"×ת×ר×× ×©×× ××××× ××פק"},{v:"paid",l:"×××¢× ×תש×××",hint:"×ת×ר×× ×©×× ××סף × ×× ×¡"}],ch=["credit","standing_order","bank_transfer","bit","cash","check","other"],dh=["draft","pending","approved","issued","cancelled","credited"],uh=["charge_type","payment_page","event","class","venue","quick_charge"],mh={charge_type:{l:"ס××× ××××××",state:"connected"},quick_charge:{l:"ס×××§× ×××ר×",state:"connected",note:"× ×¨×©×ת ××××× ×תש×××, ×× ×¡×¤×¨×ª ת×ת ס×× ××××× ×©××"},event:{l:"×××× ××ר××¢××",state:"connected",note:"×רש××, ס×××, ס×××§× ×סע××£ תקצ×××"},payment_page:{l:"×¢×××× ×ª×©×××",state:"empty",note:"×××××× ×§××× ×× ×§×¨×, ×× ××¨× ×××ר ×××× ×¡×¤×§ ס×××§× ×××× ×× ×ª× ××¢×ת"},class:{l:"××××× ×ס×× ××ת",state:"unavailable",note:"××רש×× ×××× ××× ×©×× ×¡×××, ×××× × ××צרת ×××× ×× ×ª×©×××"},venue:{l:"×××× ×× ×ת×ר××",state:"partial",note:"××××× × ×ש ×××ר ×ס×××× ×ª×©××× ××× ×, ×× ××× ××× × × ×¡×קת ×××× × ××צרת ××××"}},xh={method:{l:"×××¦×¢× ×ª×©×××",values:ch,labels:{credit:"×ר××ס ×שר××",standing_order:"××ר×ת ×§××¢",bank_transfer:"××¢××¨× ×× ×§××ת",bit:"×××",cash:"×××××",check:"×××××",other:"××ר"}},status:{l:"ס×××ס ×××××",values:dh,labels:{draft:"×××××",pending:"××ת×× ×××ש×ר",approved:"×××שר",issued:"××פק",cancelled:"××××",credited:"××××"}},source:{l:"××§×ר",values:uh,labels:Object.fromEntries(Object.entries(mh).map(([t,s])=>[t,s.l]))},charge_type_id:{l:"ס×× ××××",dynamic:!0}},ph=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"];function wc(t){const{from:s,to:n}=t||{};if(!s||!n)return"";const[a,l,r]=s.split("-"),[o,p,u]=n.split("-"),d=String(new Date(Date.UTC(Number(o),Number(p),0)).getUTCDate()).padStart(2,"0");return a===o&&l===p&&r==="01"&&u===d?`${ph[Number(l)-1]} ${a}`:a===o&&l==="01"&&r==="01"&&p==="12"&&u==="31"?String(a):`${r}/${l}/${a} â ${u}/${p}/${o}`}function hh(t,{withPeriod:s=!0}={}){var p;const n=t||{},a=lr(n.metric),l=[(a==null?void 0:a.l)||"×××"],r=(p=n.dimensions)!=null&&p[0]?oh(n.dimensions[0]):null;r&&l.push(`××¤× ${r.l}`);const o=s?wc(n.dateRange):"";return o&&l.push(`â ${o}`),l.join(" ")}function bh(t,s={}){var r;const n=[],a=t||{},l=s.typeNames||{};for(const[o,p]of Object.entries(a.filters||{})){const u=xh[o];if(!u)continue;const d=c=>{var m;return u.dynamic?l[c]||c:((m=u.labels)==null?void 0:m[c])||c};n.push(`${u.l}: ${p.map(d).join(", ")}`)}return a.dateBasis&&n.push(`× ××ª× ××¤× ${(r=vc.find(o=>o.v===a.dateBasis))==null?void 0:r.l}`),a.comparison&&a.comparison!=="none"&&n.push(a.comparison==="previous_year"?"××ש×××× ××©× × ×©×¢×ר×":"××ש×××× ×תק××¤× ××§×××ת"),n}jc.map(t=>t.v),Nc.map(t=>t.v),vc.map(t=>t.v);const Ca=t=>ve(t),kc=t=>new Intl.NumberFormat("he-IL").format(Number(t)||0),cn=["#0f766e","#14b8a6","#6ee7b7","#7dd3fc","#38bdf8","#a78bfa","#f9a8d4","#fbbf24","#cbd5e1"],fh=["××¦× ×××××× ××¤× ×××¦×¢× ×ª×©××× ××××ש ספ×××ר","××¦× ×××××× ××¤× ×¡×¢××¤× ×ª×§×¦×× ××©× ×","××¦× ×ש××× ×ת ×××××ר","××¦× ××××× ××××× ××©× × ××¢××ת ×©× × ×©×¢×ר×","××¦× ×¢×¡×§××ת ×שר×× ×©× ×ש××"],Sc=(t,s)=>s==="money"?Ca(t):s==="percent"?`${Number(t||0).toFixed(1)}%`:s==="number"?kc(t):String(t??"â"),gh=t=>Sc(t.value,t.unit),yh=t=>{const s=[];return t.sub&&s.push(t.subValue===null||t.subValue===void 0?t.sub:`${t.sub} ${Sc(t.subValue,t.subUnit)}`),t.note&&s.push(t.note),s.join(" · ")||null},_h={money:rt,number:tu,percent:mr,text:Xe},Oi=(t,s)=>{const n=s[t.key];if(t.type==="money")return Ca(n);if(t.type==="num")return kc(n);if(t.type==="pct")return`${Number(n||0).toFixed(1)}%`;if(t.type==="month")return Ze(n);if(t.type==="date"){const[a,l,r]=String(n||"").slice(0,10).split("-");return r?`${r}/${l}/${a}`:"â"}return n??"â"};function jh({from:t,children:s}){const n=t==="user";return e.jsx("div",{className:`flex ${n?"justify-start":"justify-end"}`,children:e.jsx("div",{className:`max-w-[42rem] rounded-2xl px-4 py-3 text-[14px] leading-relaxed ${n?"bg-slate-100 text-slate-700":"bg-teal-600 text-white shadow-sm"}`,children:s})})}function Nh({result:t,intent:s,onBack:n,onSave:a,onFallback:l,saving:r,typeNames:o}){var f,x;const p=i.useMemo(()=>bh(s,{typeNames:o}),[s,o]),u=i.useMemo(()=>(t.columns||[]).map(g=>({key:g.key,label:g.label,type:g.type==="month"||g.type==="date"?"date":g.type,render:y=>e.jsxs("span",{className:g.type==="text"?"font-bold text-slate-800":"tabular-nums",children:[g.dot&&y[g.dot]&&e.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-full ml-2 align-middle",style:{background:y[g.dot]}}),Oi(g,y),g.sub&&y[g.sub]?e.jsxs("span",{className:"block text-[11.5px] text-slate-400",dir:"ltr",children:["#",y[g.sub]]}):null]}),excel:y=>y[g.key]})),[t.columns]),d=i.useMemo(()=>
54{if(!t.totals)return;const g={};for(const y of t.columns||[]){const $=t.totals[y.key];g[y.key]=$==null?"":Oi(y,t.totals)}return g},[t.totals,t.columns]),c=t.chart,m=c?e.jsx(As,{title:c.kind==="donut"?"×תפ×××ת":"××××¨× ×תק×פ×",legend:c.kind==="donut"?(c.data||[]).slice(0,8).map((g,y)=>e.jsx(qe,{color:g.color||cn[y%cn.length],children:g[c.nameKey]||g.name},g.key||g.name||y)):c.kind==="collection"?[e.jsx(qe,{color:"#cbd5e1",children:"××××"},"b"),e.jsx(qe,{color:"#0d9488",children:"× ×××"},"c"),e.jsx(qe,{color:"#f59e0b",children:"×××× ×××××"},"r")]:[e.jsx(qe,{color:"#e11d48",children:"××ª×¨× ×××××ר"},"a")],height:"20rem",children:e.jsx(Rt,{width:"100%",height:"100%",children:c.kind==="donut"?e.jsxs(Yn,{children:[e.jsx(Vn,{data:c.data,dataKey:c.valueKey,nameKey:c.nameKey,innerRadius:"58%",outerRadius:"86%",paddingAngle:2,stroke:"#fff",strokeWidth:2,children:(c.data||[]).map((g,y)=>e.jsx(_s,{fill:g.color||cn[y%cn.length]},g.key||y))}),e.jsx(ht,{formatter:g=>Ca(g)})]}):c.kind==="collection"?e.jsxs(zo,{data:c.data,margin:{top:20,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#e2e8f0",vertical:!1}),e.jsx(Qt,{dataKey:"month",tickFormatter:Ze,tick:{fontSize:11,fill:"#64748b"},reversed:!0,tickLine:!1}),e.jsx(Ct,{yAxisId:"m",orientation:"right",width:70,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:!1,tickFormatter:g=>new Intl.NumberFormat("he-IL").format(g)}),e.jsx(Ct,{yAxisId:"r",orientation:"left",width:44,domain:[0,100],tick:{fontSize:11,fill:"#94a3b8"},tickLine:!1,axisLine:!1,tickFormatter:g=>`${g}%`}),e.jsx(ht,{formatter:(g,y)=>y==="rate"?`${Number(g).toFixed(1)}%`:Ca(g)}),e.jsx(Mo,{yAxisId:"r",y:95,stroke:"#f59e0b",strokeDasharray:"5 4"}),e.jsx(pt,{yAxisId:"m",dataKey:"billed",name:"××××",fill:"#cbd5e1",radius:[6,6,0,0],maxBarSize:38}),e.jsx(pt,{yAxisId:"m",dataKey:"collected",name:"× ×××",fill:"#0d9488",radius:[6,6,0,0],maxBarSize:38}),e.jsx(yr,{yAxisId:"r",type:"linear",dataKey:"rate",name:"rate",stroke:"#f59e0b",strokeWidth:2.5,dot:{r:3}})]}):e.jsxs(Ba,{data:c.data,margin:{top:20,right:8,left:8,bottom:4},children:[e.jsx(js,{strokeDasharray:"3 3",stroke:"#e2e8f0",vertical:!1}),e.jsx(Qt,{dataKey:c.xKey,tickFormatter:Ze,tick:{fontSize:11,fill:"#64748b"},reversed:!0,tickLine:!1}),e.jsx(Ct,{orientation:"right",width:70,tick:{fontSize:11,fill:"#64748b"},tickLine:!1,axisLine:!1,tickFormatter:g=>new Intl.NumberFormat("he-IL").format(g)}),e.jsx(ht,{formatter:g=>Ca(g)}),e.jsx(pt,{dataKey:c.valueKey,fill:"#e11d48",radius:[6,6,0,0],maxBarSize:54})]})})}):null,h=(t.unavailable||[]).filter(g=>g.state!=="connected"),b=t.included||[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center flex-wrap gap-2 no-print",children:[e.jsxs("button",{type:"button",onClick:n,className:"h-10 px-4 rounded-xl border border-slate-200 bg-white text-[13.5px] font-bold text-slate-600 inline-flex items-center gap-2 hover:border-slate-300",children:[e.jsx(bs,{className:"w-4 h-4"})," ש××× ××ש×"]}),e.jsxs("button",{type:"button",onClick:a,disabled:r,className:"h-10 px-4 rounded-xl bg-teal-600 text-white text-[13.5px] font-bold inline-flex items-center gap-2 hover:bg-teal-700 disabled:opacity-60",children:[r?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(Po,{className:"w-4 h-4"})," ש××רת ××××"]}),e.jsx("span",{className:"mr-auto flex items-center flex-wrap gap-1.5",children:p.map(g=>e.jsx("span",{className:"text-[12px] font-bold text-slate-500 bg-slate-100 rounded-lg px-2.5 py-1",children:g},g))})]}),t.budget&&!t.budget.configured&&e.jsxs("section",{className:"rounded-2xl border border-amber-200 bg-amber-50/70 p-4 flex items-start gap-3",children:[e.jsx(At,{className:"w-4 h-4 text-amber-600 flex-none mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[13.5px] font-bold text-amber-900",children:"×× ×××××¨× ×¡×¢××¤× ×ª×§×¦×× ××§×××× ×× ×××שק ס××××"}),e.jsx("p",{className:"text-[12.5px] text-amber-800 mt-0.5",children:"××××××× ××צ××× ×ª×ת «××× ×¡×¢××£ תקצ×××». ×פשר ××צ×× ×ת ×××ª× ×ª×§××¤× ××¤× ×¡×× ×××××."}),e.jsx("button",{type:"button",onClick:l,className:"mt-2 h-9 px-3.5 rounded-xl bg-white border border-amber-300 text-[13px] font-bold text-amber-900 hover:bg-amber-50",children:"××¦× ×××§×× ××ת ××¤× ×¡×× ××××"})]})]}),e.jsx(Ms,{title:((f=lr(s.metric))==null?void 0:f.l)||t.title,period:t.period||wc(s.dateRange),subtitle:t.title||((x=lr(s.metric))==null?void 0:x.hint)||"",icon:wn,stats:(t.cards||[]).map(g=>({label:g.label,value:gh(g),sub:yh(g),icon:_h[g.unit]||wn,tone:g.unit==="percent"?"amber":g.unit==="number"?"sky":"teal"})),chart:m,tableTitle:"פ×ר××",columns:u,rows:t.rows||[],totals:d,unit:"ש×ר×ת",perPage:12,empty:"×× × ×צ×× × ×ª×× ×× ×××§×©× ×××ת ×תק××¤× ×©× ××ר×.",fileName:`×××_×××_${t.period||""}`,footNote:(t.notes||[]).join(" ")}),e.jsxs("section",{className:"rounded-2xl border border-slate-200 bg-slate-50/60 p-4",children:[e.jsxs("h4",{className:"text-[13.5px] font-black text-slate-800 flex items-center gap-2",children:[e.jsx($d,{className:"w-4 h-4 text-teal-600"})," ×××× ×××סס ×¢× ××§×ר×ת ××××× ×××××ר×× ×עת ××ער×ת"]}),b.length>0&&e.jsxs("p",{className:"mt-2 text-[12.5px] text-slate-600",children:[e.jsx("b",{className:"text-slate-700",children:"× ××××:"})," ",b.map(g=>g.label).join(" · ")]}),h.length>0&&e.jsx("ul",{className:"mt-1.5 space-y-1",children:h.map(g=>e.jsxs("li",{className:"text-[12.5px] text-slate-500",children:[e.jsxs("b",{className:"text-slate-600",children:["×× × ××× â ",g.label,":"]}
54)," ",g.state==="empty"?g.note||"××× × ×ª×× ×× ×××§×ר ×××":g.note||"×××××× ××× × ××××× ×¡×××××"]},g.key))})]})]})}function vh({kibbutzId:t}){const[s,n]=i.useState(""),[a,l]=i.useState([]),[r,o]=i.useState(!1),[p,u]=i.useState(null),[d,c]=i.useState({}),[m,h]=i.useState(""),[b,f]=i.useState(null),[x,g]=i.useState(null),[y,$]=i.useState(!1),[O,A]=i.useState([]),[S,P]=i.useState([]),[E,k]=i.useState(""),C=i.useRef(null),w=i.useMemo(()=>Object.fromEntries(S.map(N=>[N.id,N.name])),[S]),_=i.useCallback(()=>{D.functions.invoke("smartReport",{action:"list"}).then(N=>{var v;return A(((v=N==null?void 0:N.data)==null?void 0:v.reports)||[])}).catch(()=>A([]))},[]);i.useEffect(()=>{_(),D.entities.ChargeType.filterAll({kibbutz_id:t},"order").then(N=>P(N||[])).catch(()=>P([]))},[t,_]);const T=(N,v)=>l(F=>[...F,{from:N,body:v,id:`${Date.now()}-${F.length}`}]),M=async(N,v)=>{o(!0),u(null);try{const F=await D.functions.invoke("smartReport",{action:"parse",text:N,answers:v||{}}),K=F==null?void 0:F.data;if(!(K!=null&&K.success))throw new Error("parse");if(K.status==="unsupported"){T("bot",e.jsxs("span",{children:["×× ×צ×××ª× ××פ×× ×ת ×××§×©× ××××. ×פשר ×× ×¡× ×××ª× ××:",e.jsx("span",{className:"block mt-2 space-y-1",children:(K.suggestions||[]).map(Z=>e.jsx("button",{type:"button",onClick:()=>{n(Z)},className:"block w-full text-right rounded-lg bg-white/15 hover:bg-white/25 px-3 py-1.5 text-[13px]",children:Z},Z))})]}));return}if(K.status==="need_input"){g(K.intent),u(K.question),T("bot",K.question.text);return}g(K.intent),T("bot",e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ye,{className:"w-4 h-4",strokeWidth:3})," ×××× ×©×× ×××× â ",K.title]})),await B(K.intent)}catch(F){T("bot",(F==null?void 0:F.message)==="parse"?"×× ×צ×××ª× ×פרש ×ת ××קש×. × ×¡× ×× ×¡× ×××ª× ×××ש.":"×××¨×¢× ×©××××. × ×¡× ×©××.")}finally{o(!1)}},B=async(N,v)=>{o(!0);try{const F=await D.functions.invoke("smartReport",{action:"run",intent:N,saved_id:v}),K=F==null?void 0:F.data;if(!(K!=null&&K.success))throw new Error("run");f(K.result),g(K.intent)}catch{W.error("×× ×צ××× × ××פ××§ ×ת ××××"),T("bot","×× ×צ××× × ××פ××§ ×ת ××××. × ×¡× ×©×× ×× ×©× × ×ת ××קש×.")}finally{o(!1)}},R=N=>{const v=(N??s).trim();!v||r||(n(""),c({}),h(v),T("user",v),M(v,{}))},j=N=>{var F;const v={...d,[p.key]:N};c(v),T("user",((F=p.options.find(K=>K.v===N))==null?void 0:F.l)||N),M(m,v)},q=async()=>{var N;if(x){$(!0);try{const v=await D.functions.invoke("smartReport",{action:"save",intent:x,prompt:m,name:hh(x)});if(!((N=v==null?void 0:v.data)!=null&&N.success))throw new Error;W.success("×××× × ×©×ר"),_()}catch{W.error("×× ×צ××× × ×ש××ר ×ת ××××")}finally{$(!1)}}},L=async N=>{try{await D.functions.invoke("smartReport",{action:"delete",id:N}),_()}catch{W.error("×× ×צ××× × ×××××§")}};return i.useEffect(()=>{C.current&&(C.current.scrollTop=C.current.scrollHeight)},[a,p]),b&&x?e.jsx(Nh,{result:b,intent:x,typeNames:w,saving:y,onSave:q,onFallback:()=>B({...x,dimensions:["type"]}),onBack:()=>{f(null),l([]),u(null),c({})}}):e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr,19rem] gap-4 items-start",children:[e.jsxs("section",{className:"min-w-0 rounded-2xl border border-slate-200 bg-gradient-to-b from-slate-50 to-white shadow-sm overflow-hidden",children:[e.jsxs("header",{className:"px-5 py-4 border-b border-slate-100 bg-white/70",children:[e.jsxs("h3",{className:"text-[20px] font-black text-slate-900 flex items-center gap-2",children:[e.jsx("span",{className:"w-9 h-9 rounded-xl bg-teal-600 text-white grid place-items-center",children:e.jsx(wn,{className:"w-[18px] h-[18px]"})}),"×××× ××××"]}),e.jsx("p",{className:"text-[13px] text-slate-500 mt-1.5",children:"×ת×× ××©×¤× ××פש×ת ×××× ××× ××ª× ×¦×¨×××× â «××¦× ×××××× ××ר×××¡× ×שר×× ×ספ×××ר» â ××× ×× × × ×× × ×××ª× ×× ×ª×× × ××§×××× ×©×××. ×× ×סר פר×, × ×©×× ×©××× ××ת."})]}),e.jsxs("div",{ref:C,className:"px-5 py-4 space-y-3 max-h-[26rem] overflow-y-auto",children:[a.length===0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[12.5px] font-bold text-slate-400",children:"×פשר ××ת××× ×××ת ××××:"}),fh.map(N=>e.jsxs("button",{type:"button",onClick:()=>R(N),className:`w-full text-right rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-[13.5px] text-slate-700 55 hover:border-teal-300 hover:bg-teal-50/40 inline-flex items-center gap-2`,children:[e.jsx(eu,{className:"w-4 h-4 text-teal-500 flex-none"}),N]},N))]}),a.map(N=>e.jsx(jh,{from:N.from,children:N.body},N.id)),r&&e.jsx("div",{className:"flex justify-end",children:e.jsxs("span",{className:"rounded-2xl bg-teal-600/90 text-white px-4 py-3 inline-flex items-center gap-2 text-[13.5px]",children:[e.jsx(Ie,{className:"w-4 h-4 animate-spin"})," ××× × ×ת ××××â¦"]})}),p&&!r&&e.jsxs("div",{className:"rounded-2xl border border-teal-200 bg-teal-50/50 p-3",children:[e.jsx("p",{className:"text-[13.5px] font-bold text-teal-900 mb
55-2",children:p.text}),e.jsx("div",{className:"flex flex-wrap gap-2",children:p.options.map(N=>e.jsxs("button",{type:"button",onClick:()=>j(N.v),className:"rounded-xl border border-teal-200 bg-white px-3.5 py-2 text-[13px] font-bold text-slate-700 hover:border-teal-400 text-right",children:[e.jsx("span",{className:"block",children:N.l}),N.hint&&e.jsx("span",{className:"block text-[11px] font-normal text-slate-400",children:N.hint})]},N.v))}),p.allowOther&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("input",{value:E,onChange:N=>k(N.target.value),onKeyDown:N=>{N.key==="Enter"&&E.trim()&&(j(E.trim()),k(""))},placeholder:"××רâ¦",className:"h-9 flex-1 rounded-xl border border-slate-200 px-3 text-[13px] focus:outline-none focus:border-teal-400"}),e.jsx("button",{type:"button",disabled:!E.trim(),onClick:()=>{j(E.trim()),k("")},className:"h-9 px-3 rounded-xl bg-teal-600 text-white text-[13px] font-bold disabled:opacity-40",children:"ש××"})]})]})]}),e.jsx("div",{className:"px-5 pb-5",children:e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white shadow-sm focus-within:border-teal-400 focus-within:ring-4 focus-within:ring-teal-50 transition-all",children:[e.jsx("textarea",{value:s,onChange:N=>n(N.target.value),onKeyDown:N=>{N.key==="Enter"&&(N.metaKey||N.ctrlKey)&&R()},rows:4,placeholder:"××××××: ××¦× ×ת ×× ××××××× ××ר×××¡× ×שר×× ××××ש ספ×××ר, ××¤× ×¡×¢××¤× ×ª×§×¦××",className:"w-full resize-none bg-transparent px-4 py-3 text-[15px] leading-relaxed text-slate-800 placeholder:text-slate-300 focus:outline-none"}),e.jsxs("div",{className:"flex items-center gap-2 px-3 pb-3",children:[e.jsxs("span",{className:"text-[11.5px] text-slate-400 inline-flex items-center gap-1",children:[e.jsx(qc,{className:"w-3.5 h-3.5"})," Ctrl+Enter ×ש××××"]}),e.jsxs("button",{type:"button",onClick:()=>R(),disabled:r||!s.trim(),className:`mr-auto h-11 px-5 rounded-xl bg-teal-600 text-white text-[14px] font-bold inline-flex items-center gap-2 56 hover:bg-teal-700 disabled:opacity-40 disabled:cursor-not-allowed`,children:[r?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(Gs,{className:"w-4 h-4"}),"×× ××ת ××××"]})]})]})})]}),e.jsxs("aside",{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white shadow-sm p-4",children:[e.jsxs("h4",{className:"text-[14px] font-black text-slate-800 flex items-center gap-2",children:[e.jsx(Po,{className:"w-4 h-4 text-teal-600"})," ××××ת ש××ר××"]}),O.length===0?e.jsx("p",{className:"text-[12.5px] text-slate-400 mt-2",children:"××× ×©×©××¨×ª× ××פ××¢ ×××, ××××¤×ª× ×¢× ×× ×ª×× ×× ×©× ××××."}):e.jsx("ul",{className:"mt-2 space-y-1.5",children:O.map(N=>e.jsx("li",{className:"group rounded-xl border border-slate-100 hover:border-teal-200 hover:bg-teal-50/30",children:e.jsxs("div",{className:"flex items-center gap-1 px-2.5 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>B(N.intent,N.id),className:"min-w-0 flex-1 text-right",children:[e.jsx("span",{className:"block text-[13px] font-bold text-slate-700 truncate",children:N.name}),e.jsxs("span",{className:"block text-[11px] text-slate-400 truncate",children:[N.last_run_at?"××רץ ×××ר×× ×":"××¨× ××רץ",N.prompt?` · ${N.prompt}`:""]})]}),e.jsx("button",{type:"button",onClick:()=>B(N.intent,N.id),title:"××¨×¦× ×××ש",className:"w-7 h-7 rounded-lg grid place-items-center text-slate-300 hover:text-teal-600",children:e.jsx(br,{className:"w-3.5 h-3.5"})}),e.jsx("button",{type:"button",onClick:()=>L(N.id),title:"××××§×",className:"w-7 h-7 rounded-lg grid place-items-center text-slate-300 hover:text-rose-600",children:e.jsx(Re,{className:"w-3.5 h-3.5"})})]})},N.id))})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white shadow-sm p-4",children:[e.jsxs("h4",{className:"text-[14px] font-black text-slate-800 flex items-center gap-2",children:[e.jsx(ws,{className:"w-4 h-4 text-slate-400"})," ×× ×פשר ×ש×××"]}),e.jsxs("ul",{className:"mt-2 space-y-1 text-[12.5px] text-slate-500 list-disc pr-4",children:[e.jsx("li",{children:"×××××× ×תש××××× ××¤× ×××¦×¢× ×ª×©×××"}),e.jsx("li",{children:"×××××× ××¤× ×¡×¢××£ תקצ×× ×× ×¡×× ××××"}),e.jsx("li",{children:"×ש××× ×ת ×××××ר, ××× ×××× ××× ×ר×× ×××"}),e.jsx("li",{children:"××××× ×××××, ×××× ×ש×××× ××©× × ×©×¢×ר×"}),e.jsx("li",{children:"עסק××ת ×שר×× ×©× ×ש××"})]}),e.jsxs("p",{className:"mt-3 text-[11.5px] text-slate-400 flex items-start gap-1.5",children:[e.jsx(At,{className:"w-3.5 h-3.5 flex-none mt-0.5"}),"×××× ×××¦× ×¢× × ×ª×× × ××§×××× ×©××ª× ××××ר×× ×××× ××××."]})]})]})]})}const Na=[{key:"smart",label:"×××× ××××",icon:wn,tone:"teal",Comp:vh},{key:"charges",label:"××××××",icon:nt,tone:"blue",Comp:rp},{key:"paymentPages",label:"×¢×××× ×ª×©×××",icon:Zt,tone:"purple",Comp:fp},{key:"income",label:"××× ×¡×ת",icon:ks,tone:"rose",Comp:Np},{key:"accounts",label:"×ש××× ×ת",icon:De,tone:"emerald",Comp:pp},{key:"properties",label:"× ×ס××",icon:ra,tone:"amber",Comp:Fx}
56,{key:"water",label:"××× ××",icon:Ke,tone:"sky",Comp:Px},{key:"kolbo",label:"×××××",icon:da,tone:"indigo",Comp:Ox},{key:"ledger",label:"×ר×סת",icon:Ic,tone:"violet",Comp:Mp},{key:"movements",label:"×ª× ××¢×ת",icon:Kn,tone:"cyan",Comp:ih}],wh={purple:"bg-purple-600 border-transparent text-white",sky:"bg-sky-600 border-transparent text-white",amber:"bg-amber-600 border-transparent text-white",indigo:"bg-indigo-600 border-transparent text-white",teal:"bg-teal-600 border-transparent text-white",emerald:"bg-emerald-600 border-transparent text-white",rose:"bg-rose-600 border-transparent text-white",blue:"bg-blue-600 border-transparent text-white",violet:"bg-violet-600 border-transparent text-white",cyan:"bg-cyan-600 border-transparent text-white"},Li={purple:"text-purple-600",sky:"text-sky-600",amber:"text-amber-600",indigo:"text-indigo-600",teal:"text-teal-600",emerald:"text-emerald-600",rose:"text-rose-600",blue:"text-blue-600",violet:"text-violet-600",cyan:"text-cyan-600"};function kh({kibbutzId:t,initial:s,initialFilter:n}){const[a,l]=i.useState(()=>Na.some(d=>d.key===s)?s:Na[0].key),[r,o]=i.useState(null);i.useEffect(()=>{let d=!0;return D.entities.BillingSettings.filter({kibbutz_id:t},"-created_date",1).then(c=>{d&&o((c==null?void 0:c[0])||null)}).catch(()=>{}),()=>{d=!1}},[t]);const p=Na.find(d=>d.key===a)||Na[0],u=p.Comp;return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2 mb-4 no-print",children:Na.map(d=>{const c=d.icon,m=d.key===a;return e.jsxs("button",{onClick:()=>l(d.key),className:`h-12 px-3 rounded-xl text-[15px] font-bold border inline-flex items-center justify-center gap-2 transition-colors ${m?wh[d.tone]:"bg-white border-slate-200 text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(c,{className:`w-[18px] h-[18px] flex-none ${m?"":Li[d.tone]||Li.teal}`}),e.jsx("span",{className:"truncate",children:d.label})]},d.key)})}),e.jsx(u,{kibbutzId:t,settings:r,initialFilter:p.key===s?n:null},p.key)]})}const cs=Se;function Sh({kibbutzId:t}){const[s,n]=i.useState(!0),[a,l]=i.useState(null),[r,o]=i.useState({}),[p,u]=i.useState(!1),[d,c]=i.useState(!1),m=(x,g)=>o(y=>({...y,[x]:g})),h=i.useCallback(async()=>{n(!0);try{const g=(await D.entities.BillingSettings.filter({kibbutz_id:t},"-created_date",1)||[])[0]||null;l(g),o(g?{...g}:{currency:"ILS",default_due_day:15,online_payments_enabled:!1})}catch{W.error("ש×××× ×××¢×× ×ª ××××ר×ת")}finally{n(!1)}},[t]);i.useEffect(()=>{h()},[h]);async function b(x){if(x){c(!0);try{const{file_url:g}=await D.integrations.Core.UploadFile({file:x});m("logo_url",g),W.success("××××× ×××¢××")}catch{W.error("ש×××× ×××¢×××")}finally{c(!1)}}}async function f(){u(!0);const x={kibbutz_id:t,legal_name:r.legal_name||null,address:r.address||null,phone:r.phone||null,email:r.email||null,business_number:r.business_number||null,logo_url:r.logo_url||null,footer_note:r.footer_note||null,default_due_day:r.default_due_day===""||r.default_due_day==null?null:Number(r.default_due_day),currency:r.currency||"ILS",online_payments_enabled:!!r.online_payments_enabled};try{a?await D.entities.BillingSettings.update(a.id,x):await D.entities.BillingSettings.create(x),D.entities.BillingActivityLog.create({kibbutz_id:t,action_type:"settings_updated",entity_type:"billing_settings",entity_id:(a==null?void 0:a.id)||null}).catch(()=>{}),W.success("××××ר×ת × ×©×ר×"),await h()}catch{W.error("ש×××× ×ש××ר×")}finally{u(!1)}}return s?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})}):e.jsxs("div",{className:"max-w-3xl space-y-5 billing-form",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-indigo-50 flex items-center justify-center",children:e.jsx(ra,{className:"w-5 h-5 text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold",children:"פר×× ××× ×¤××§"}),e.jsx("p",{className:"text-xs text-slate-400",children:"××פ××¢×× ×××תרת ×× ×ס×× ×ש×××"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(Q,{label:"×©× ×שפ×× / ×©× ××× ×¤××§",required:!0,children:e.jsx("input",{className:cs,placeholder:"××× ×©× ×× ×¤××§",value:r.legal_name||"",onChange:x=>m("legal_name",x.target.value)})}),e.jsx(Q,{label:"×.פ / ×¢.×",children:e.jsx("input",{className:cs,placeholder:"××× ×.פ / ×¢.×",value:r.business_number||"",onChange:x=>m("business_number",x.target.value)})}),e.jsx(Q,{label:"×ת××ת",children:e.jsx("input",{className:cs,placeholder:"××× ×ת××ת",value:r.address||"",onChange:x=>m("address",x.target.value)})}),e.jsx(Q,{label:"××פ××",children:e.jsx("input",{className:cs,placeholder:"××× ××פ××",value:r.phone||"",onChange:x=>m("phone",x.target.value)})}),e.jsx(Q,{label:'×××"×',children:e.jsx("input",{className:cs,placeholder:'×××
56 ×××"×',value:r.email||"",onChange:x=>m("email",x.target.value)})}),e.jsx(Q,{label:"××××",children:e.jsxs("div",{className:"flex items-center gap-2",children:[r.logo_url&&e.jsx("img",{src:r.logo_url,alt:"",className:"h-12 w-auto max-w-[80px] object-contain rounded border border-slate-200"}),e.jsxs("label",{className:"inline-flex items-center gap-1.5 h-12 px-4 rounded-xl border border-slate-300 text-sm text-slate-500 cursor-pointer hover:bg-slate-50",children:[e.jsx(La,{className:"w-4 h-4"})," ",d?"××¢××â¦":r.logo_url?"×××פת ××××":"××¢××ת ××××",e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:x=>{var g;return b((g=x.target.files)==null?void 0:g[0])}})]})]})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(Q,{label:"×ערת ת×ת×ת ××ס××",hint:"××××××: פר×× ×ש××× ×× ×§ ×תש×××, ×× ××××¢× ×§×××¢×",children:e.jsx("textarea",{className:ua,rows:2,placeholder:"×ערת ת×ת×ת שת×פ××¢ ×ת×ת×ת ×× ×ס×× ×ש×××",value:r.footer_note||"",onChange:x=>m("footer_note",x.target.value)})})})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-slate-100 flex items-center justify-center",children:e.jsx(zn,{className:"w-5 h-5 text-slate-600"})}),e.jsx("h3",{className:"text-base font-bold",children:"×ר×ר×ת ××××"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsx(Q,{label:"××× ×תש××× ××ר×רת ×××× (××××ש)",children:e.jsx("input",{type:"number",min:"1",max:"31",className:cs,value:r.default_due_day??"",onChange:x=>m("default_due_day",x.target.value)})}),e.jsx(Q,{label:"××××¢",children:e.jsx("input",{className:cs,value:r.currency||"ILS",onChange:x=>m("currency",x.target.value)})})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-emerald-50 flex items-center justify-center",children:e.jsx(Oe,{className:"w-5 h-5 text-emerald-600"})}),e.jsx("h3",{className:"text-base font-bold",children:"תש××× ××§×××"})]}),e.jsxs("div",{className:"flex items-start gap-2 bg-amber-50 border border-amber-200 rounded-xl px-4 py-2.5 mb-3 text-xs text-amber-800",children:[e.jsx(Un,{className:"w-4 h-4 flex-shrink-0 mt-0.5"}),' ××¨× ×××ר ספק ס×××§× ××§×××× ××. ×פע×ת ×××ª× ×ª×¦×× ×ת×ש××× ×פת×ר âתש××× ××§×××" רק ×××ר ××××ר ספק. ×¢× ×× ×××××¥ ××ש×××¨× ××××.']}),e.jsxs("button",{type:"button",onClick:()=>m("online_payments_enabled",!r.online_payments_enabled),className:`flex items-center gap-2 h-11 px-4 rounded-xl border text-sm w-full sm:w-auto ${r.online_payments_enabled?"border-emerald-300 bg-emerald-50 text-emerald-700":"border-slate-200 text-slate-500"}`,children:[e.jsx(xt,{className:"w-4 h-4"}),e.jsx("span",{className:"flex-1 text-right",children:"×פשר תש××× ××§××× ××××ר ×××ש×"}),e.jsx("span",{className:`w-9 h-5 rounded-full flex items-center px-0.5 transition-all ${r.online_payments_enabled?"bg-emerald-500 justify-end":"bg-slate-300 justify-start"}`,children:e.jsx("span",{className:"w-4 h-4 rounded-full bg-white"})})]})]}),e.jsxs("button",{onClick:f,disabled:p,className:ts,children:[e.jsx(ye,{className:"w-4 h-4"})," ",p?"ש××רâ¦":"ש××רת ×××ר×ת"]})]})}const Fl=400,Fe=t=>new Intl.NumberFormat("he-IL").format(t),$h=t=>oo(t,"",{decimals:2}).trim(),Ti={pending:{label:"××ת×× ×××ש×ר",cls:"bg-amber-50 text-amber-700"},approved:{label:"×××¦× ×ת×ש×××",cls:"bg-emerald-50 text-emerald-700"}},Ks=t=>{if(!t)return"â";const[s,n,a]=String(t).slice(0,10).split("-");return`${a}/${n}/${s}`};function dn({label:t,value:s}){return e.jsxs("div",{className:"bg-white/80 border border-black/5 rounded-2xl px-3 py-2.5 text-right",children:[e.jsx("p",{className:"text-[11px] font-bold text-slate-500",children:t}),e.jsx("p",{className:"text-xl font-extrabold tracking-tight mt-0.5 tabular-nums",children:e.jsx("span",{dir:"ltr",className:"inline-block",children:s})})]})}function Dl({tone:t,icon:s,title:n,children:a}){const l=t==="ok"?"bg-emerald-50 border-emerald-200 text-emerald-800":t==="warn"?"bg-amber-50 border-amber-200 text-amber-900":"bg-rose-50 border-rose-200 text-rose-800";return e.jsxs("div",{className:`flex gap-3 rounded-2xl border p-3.5 ${l}`,children:[e.jsx(s,{className:"w-5 h-5 flex-none mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-bold text-sm",children:n}),a&&e.jsx("div",{className:"text-[13px] mt-0.5 leading-relaxed",children:a})]})]})}function Bi({title:t,hint:s,rows:n,extra:a}){return n!=null&&n.length?e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-slate-200 bg-slate-50/60",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"block text-sm font-extrabold text-slate-800",children:[t," (",n.length,")"]}),s&&e.jsx("span",{className:"block text-[11px] text-slate-400",children:s})]}),e.jsx("span",{className:"text-sm font-extrabold tabular-nums whitespace-nowrap",dir:"ltr",children:ve(n.reduce((l,r)=>l+(r.total||0),0))})]}),e.jsx("div",{className:"max-h-72 overflow-y-auto",children:e.jsx("table",{className:"w-full border-collapse",children:e.jsx("tbody",{children:n.map(l=>e.jsxs("tr",{className:"border-b border-slate-100 last:border-0",children:[e.jsxs("td",{className:"px-4 py-2 text-sm",children:[e.jsx("span",{className:"font-semibold text-slate-800",children:l.payer_name||"â"}),e.jsx("span",{className:"block text-[11px] text-slate-400",children:[`×××ר ${l.sector||"â"}
56`,a==null?void 0:a(l)].filter(Boolean).join(" · ")})]}),e.jsxs("td",{className:"px-4 py-2 text-xs text-slate-500 text-left whitespace-nowrap",children:["תקצ×× ",l.budget]}),e.jsxs("td",{className:"px-4 py-2 text-xs text-slate-500 text-left whitespace-nowrap",children:[Fe(l.lines)," ש×ר×ת"]}),e.jsx("td",{className:"px-4 py-2 text-sm font-bold text-left tabular-nums",dir:"ltr",children:$h(l.total)})]},l.budget))})})})]}):null}function Ch({kibbutzId:t}){var S,P;const s=i.useRef(null),[n,a]=i.useState(""),[l,r]=i.useState(0),[o,p]=i.useState(null),[u,d]=i.useState(null),[c,m]=i.useState([]),[h,b]=i.useState(null),f=i.useCallback(async()=>{var E;try{const k=await D.functions.invoke("kolboImport",{action:"list",community_id:t});m(((E=k==null?void 0:k.data)==null?void 0:E.batches)||(k==null?void 0:k.batches)||[])}catch{}},[t]);i.useEffect(()=>{f()},[f]);const x=()=>{p(null),d(null),r(0),s.current&&(s.current.value="")};async function g(E){var C;const k=(C=E.target.files)==null?void 0:C[0];if(k){a("parse");try{const w=od(await k.arrayBuffer()),{rows:_,errors:T}=cd(w);if(!_.length){W.error("×× × ×צ×× ×©×ר×ת קר×××ת ××§×××¥"),x();return}const M=dd(_);p({name:k.name,summary:M,rows:_,errors:T});const B=await D.functions.invoke("kolboImport",{action:"start",community_id:t,file_name:k.name,period_from:M.period_from,period_to:M.period_to,error_count:T.length,budgets:M.budgets.map(j=>({budget:j.budget,payer_name:j.payer_name,sector:j.sector,lines:j.lines,total:j.total}))}),R=(B==null?void 0:B.data)||B;if(!(R!=null&&R.batch_id))throw new Error("no batch");d(R),a("upload");for(let j=0;j<_.length;j+=Fl)await D.functions.invoke("kolboImport",{action:"rows",community_id:t,batch_id:R.batch_id,rows:_.slice(j,j+Fl)}),r(Math.min(_.length,j+Fl));await f()}catch(w){W.error((w==null?void 0:w.message)||"ש×××× ×××¢×× ×ª ××§×××¥"),x()}finally{a("")}}}async function y(E,k){a(E);try{const C=await D.functions.invoke("kolboImport",{action:E,community_id:t,batch_id:k}),w=(C==null?void 0:C.data)||C;E==="approve"?W.success(w!=null&&w.replaced?`××שר â ${Fe(w.replaced)} ש×ר×ת ×××¢×× × ×§×××ת ××××פ×`:"××שר ××××¦× ×ת×ש×××"):E==="delete"?W.success(`×××¢×× × × ×××§× â ${Fe((w==null?void 0:w.removed)||0)} ש×ר×ת ××סר×`):W.success("×××¢×× × ×××××"),x(),await f()}catch(C){W.error((C==null?void 0:C.message)||"×פע××× × ×ש××")}finally{a("")}}const $=o==null?void 0:o.summary,O=i.useMemo(()=>{if(!u||!$)return 0;const E=new Set([...u.unmatched||[],...u.ambiguous||[]].map(k=>k.budget));return $.budgets.filter(k=>!E.has(k.budget)).reduce((k,C)=>k+C.total,0)},[u,$]),A=((u==null?void 0:u.unmatched)||[]).reduce((E,k)=>E+k.total,0);return e.jsxs("div",{className:"space-y-4",dir:"rtl",children:[o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-2xl border border-black/5 shadow-sm p-5",style:{background:"linear-gradient(155deg,rgba(99,102,241,.12) 0%,#fff 48%,rgba(99,102,241,.08) 100%)"},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-bold px-2.5 py-1 rounded-full bg-indigo-100 text-indigo-700",children:[e.jsx(pr,{className:"w-3 h-3"})," ×§×××¥ ×××××"]}),e.jsx("h3",{className:"text-xl font-extrabold mt-2 truncate",children:o.name}),e.jsxs("p",{className:"text-xs text-slate-500 mt-0.5",children:[Fe($.rows)," ש×ר×ת · ",Ks($.period_from)," â ",Ks($.period_to),o.errors.length>0&&e.jsxs("span",{className:"text-rose-600 font-bold",children:[" · ",Fe(o.errors.length)," ש×ר×ת ×× × ×§×¨××"]})]})]}),e.jsx("p",{className:"text-2xl font-extrabold tabular-nums whitespace-nowrap",dir:"ltr",children:ve($.total)})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mt-4",children:[e.jsx(dn,{label:"ש×ר×ת",value:Fe($.rows)}),e.jsx(dn,{label:"×ש××× ××ת",value:Fe($.receipts)}),e.jsx(dn,{label:"××¡×¤×¨× ×ª×§×¦××",value:Fe($.budgets.length)}),e.jsx(dn,{label:"× ××¢× ×",value:Fe(l)})]}),n==="upload"&&e.jsx("div",{className:"h-1.5 rounded-full bg-white/70 mt-3 overflow-hidden",children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full transition-all",style:{width:`${l/$.rows*100}%`}})})]}),u&&e.jsxs(e.Fragment,{children:[e.jsxs(Dl,{tone:"ok",icon:la,title:`${Fe(u.matched)} ×ת×× ${Fe($.budgets.length)} ××¡×¤×¨× ×ª×§×¦×× × ×צ×× ×ª××©× ×ª×××.`,children:[ve(O)," ×ש×××× ×ת×ש××× ×××צ×× ××× ××ר×× ××××©× ×××ר ×××ש×ר."]}),((S=u.unmatched)==null?void 0:S.length)>0&&e.jsx(Dl,{tone:"warn",icon:At,title:`${Fe(u.unmatched.length)} ××¡×¤×¨× ×ª×§×¦×× ××§×××¥ ××× ×ª××©× ×ª××× â ${ve(A)}.`,children:"×רש×××ת × ×©××¨× ××× ××צ×× ×××ש. ×××× × ×ת ×ספר ×תקצ×× ×פר×× ×ת××©× ×××¢× × ×ת ××§×××¥ ש××."}),((P=u.ambiguous)==null?void 0:P.length)>0&&e.jsx(Dl,{tone:"bad",icon:De,title:`${Fe(u.ambiguous.length)} ××¡×¤×¨× ×ª×§×¦×× ×ש××××× ××©×ª× ×שפ××ת ש×× ×ת.`,children:"×× ×¢×× ××ספר רש×× ××©×ª× ×שפ××ת ×× ×פשר ××עת ××× ×©××××ת ××§× ××ת, ×××× ×× ×× ××צ×× ×××ש."}),e.jsx(Bi,{title:"××× ×ª××©× ×ª×××",hint:"×× ××צ×× ×××ש ×¢× ×©×ספר ×תקצ×× ×××× ×פר×× ×ת×ש×",rows:u.unmatched}),e.jsx(Bi,{title:"×ש××× ××©×ª× ×שפ××ת",hint:"×ש ××ש××ר ×ת ×ספר ×תקצ×× ××¦× ×שפ×× ××ת ××××",rows:u.ambiguous,extra:E=>(E.residents||[]).map(k=>k.name).join(" · ")}),e.jsxs("div",{className:"flex flex-wrap gap-2.5 pt-1",children:[e.jsxs("button",{type:"button",disabled:!!n,onClick:()=>y("approve",u.batch_id),className:"inline-flex items-center gap-2 h-11 px-6 rounded-full bg-emerald-600 text-white text-sm font-bold disabled:opacity-60",children:[n==="approve"?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(ye,{className:"w-4 h-4"}),"××©×¨× ××צ××× ×ת×ש×××"]}),e.jsxs("button",{type:"button",disabled:!!n,onClick:()=>y("cancel",u.batch_id),className:"inline-flex items-center gap-2 h-11 px-5 rounded-full bg-white border border-slate-200 text-slate-600 text-sm font-bold disabled:opacity-60",children:[e.jsx($e,{className:"w-4 h-4"})," ××××× ×××¢×× ×"]})]}),e.jsx("p",{className:"text-xs text-slate-400 leading-relaxed",children:"××§×××¥ ××ר × ×©×ר; «××ש×ר» ××× ×× ×©×××¤× ×××ª× ××××× ××ר×× ×××ש×. ×¢× ×× ××£ ת××©× ××× × ×¨××× ××ר, ×××××ש ש××ר ×××¦× × ×©×ר ×××¦× â ×× ×פשר ××ª×§× ××¡×¤×¨× ×ª×§×¦×× ××××¢×× ×©×× ××× ×©××ש×× ×ר×× × ×ª×× ×× ×××§×××."})]})]}):e.jsxs("div",{className:"bg-white rounded-2xl border border-dashed border-indigo-300 p-8 text-center",children:[e.jsx("span",{className:"w-12 h-12 rounded-2xl bg-indigo-50 grid place-items-center mx-auto mb-3",children:e.jsx(da,{className:"w-6 h-6 text-indigo-600"})}),e.jsx("h3",{className:"text-base font-bold text-slate-800",children:"××¢×× ×ª ×§×××¥ ×××××"}),e.jsx("p",{className:"text-sm text-slate-500 mt-1 max-w-md mx-auto leading-relaxed",children:"××§×××¥ ש××ר××× ×פ××§, ××¤× ×©×××. ×× ×©××¨× ×ש×××ת ×ת××©× ××¤× ×ספר ×תקצ××, ××××¨× ××ש×ר×× ×× ×שפ×× ×¨××× ××ר×× ××××©× ×ת ××§× ××ת ש×× ××××."}),e.jsxs("label",{className:"inline-flex items-center gap-2 h-11 px-6 rounded-full bg-indigo-600 text-white text-sm font-bold mt-4 cursor-pointer hover:brightness-110 transition-all",children:[n==="parse"?e.jsx(Ie,{className:"w-4 h-4 animate-spin"}):e.jsx(La,{className:"w-4 h-4"}
56),"×××¨× ×§×××¥",e.jsx("input",{ref:s,type:"file",accept:".csv,.txt",className:"hidden",onChange:g,disabled:!!n})]})]}),c.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-slate-200 bg-slate-50/60",children:e.jsx("h3",{className:"text-sm font-extrabold text-slate-800",children:"××¢×× ×ת ×§××××ת"})}),e.jsx("div",{className:"max-h-96 overflow-y-auto",children:c.map(E=>{const k=Ti[E.status]||Ti.pending;return e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-slate-100 last:border-0",children:[e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-sm font-bold text-slate-800 truncate",children:E.file_name||"×§×××¥ ×××××"}),e.jsxs("span",{className:"block text-[11px] text-slate-400",children:[Ks(E.period_from)," â ",Ks(E.period_to)," · ",Fe(E.row_count||0)," ש×ר×ת ·"," ",Fe(E.matched_count||0),"/",Fe(E.budget_count||0)," תקצ×××× ×©××××"]})]}),e.jsx("span",{className:`text-[11px] font-bold px-2.5 py-1 rounded-full whitespace-nowrap ${k.cls}`,children:k.label}),e.jsx("span",{className:"text-sm font-extrabold tabular-nums whitespace-nowrap",dir:"ltr",children:ve(E.total)}),e.jsxs("span",{className:"flex items-center gap-1 flex-none",children:[E.status==="pending"&&e.jsx("button",{type:"button",title:"××©×¨× ××צ×××",disabled:!!n,onClick:()=>y("approve",E.id),className:"w-8 h-8 rounded-full bg-emerald-50 text-emerald-600 grid place-items-center hover:bg-emerald-100 disabled:opacity-50",children:e.jsx(ye,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",title:E.status==="pending"?"××××× ×××¢×× ×":"×××קת ×××¢×× × ××× × ×ª×× ××",disabled:!!n,onClick:()=>b(E),className:"w-8 h-8 rounded-full bg-slate-50 text-slate-400 grid place-items-center hover:bg-rose-50 hover:text-rose-600 disabled:opacity-50",children:e.jsx(Re,{className:"w-4 h-4"})})]})]},E.id)})})]}),e.jsx(No,{open:!!h,onOpenChange:E=>{E||b(null)},destructive:!0,title:(h==null?void 0:h.status)==="pending"?"×××× ×ת ×××¢×× ×?":"×××××§ ×ת ×××¢×× × ××× × ×ª×× ××?",confirmLabel:(h==null?void 0:h.status)==="pending"?"×××× ×ת ×××¢×× ×":"×××§× ×ת ×××¢×× ×",description:h&&(h.status==="pending"?`××§×××¥ «${h.file_name||"×××××"}» ××¨× ××שר ×××£ ת××©× ×× ×¨×× ××ת×. ××× ××סר ×××ר×, ××פשר ×××¢×× ×××ª× ×©×× ××× ×¢×ª.`:`«${h.file_name||"×××××"}» ×××¦× ×עת ×ת×ש×××. ××××§× ×ª×¡×ר ×ת ${Fe(h.row_count||0)} ×ש×ר×ת ש×× â ××שק ×× ×××× ××× ×××ר×× ××××©× ×©× ×× ×ª××©× â ××× × ×©×ר ××ר ×ש×××ר ××× ×. ×תק××¤× ${Ks(h.period_from)} â ${Ks(h.period_to)} ת×××ר רק ×× ×ª××¢× × ×ת ××§×××¥ ש××.`),onConfirm:()=>{const E=h;b(null),y(E.status==="pending"?"cancel":"delete",E.id)}})]})}function Ah({catalog:t,pages:s,items:n,onClose:a,onSave:l}){const[r,o]=i.useState(0),[p,u]=i.useState(()=>{const _=Array.isArray(t==null?void 0:t.categories)?t.categories:[],T=[...n||[]].sort((M,B)=>(M.sort_order||0)-(B.sort_order||0));return{id:t==null?void 0:t.id,title:(t==null?void 0:t.title)||"",description:(t==null?void 0:t.description)||"",image_url:(t==null?void 0:t.image_url)||"",visibility:(t==null?void 0:t.visibility)||"public",show_in_menu:!!(t!=null&&t.show_in_menu),show_on_home:!!(t!=null&&t.show_on_home),show_in_personal:!!(t!=null&&t.show_in_personal),sectioned:_.length>0,categories:_,pageIds:T.map(M=>M.payment_page_id),categoryOf:Object.fromEntries(T.map(M=>[M.payment_page_id,M.category_id||""]))}}),d=(_,T)=>u(M=>({...M,[_]:T})),[c,m]=i.useState(!1),[h,b]=i.useState(!1),[f,x]=i.useState(""),g=i.useMemo(()=>new Set(p.pageIds),[p.pageIds]),y=i.useMemo(()=>{const _=f.trim();return(s||[]).filter(T=>!_||[T.title,T.description].join(" ").includes(_))},[s,f]),$=async _=>{if(_){m(!0);try{const{file_url:T}=await D.integrations.Core.UploadFile({file:_});d("image_url",T),W.success("×ת××× × ×××¢×ת×")}catch{W.error("ש×××× ×××¢××ת ×ת××× ×")}finally{m(!1)}}},O=_=>u(T=>T.pageIds.includes(_)?{...T,pageIds:T.pageIds.filter(M=>M!==_)}:{...T,pageIds:[...T.pageIds,_]}),A=()=>u(_=>({..._,categories:[..._.categories,{id:Fr(),title:""}]})),S=(_,T)=>u(M=>({...M,categories:M.categories.map(B=>B.id===_?{...B,title:T}:B)})),P=_=>u(T=>({...T,categories:T.categories.filter(M=>M.id!==_),categoryOf:Object.fromEntries(Object.entries(T.categoryOf).map(([M,B])=>[M,B===_?"":B]))})),E=()=>({...p,categories:p.sectioned?p.categories:[]}),k=_=>{if(_>r){if(r===0){if(!String(p.title||"").trim()){W.error("×ש ××××× ×©× ××§××××");return}if(p.sectioned&&p.categories.some(T=>!String(T.title||"").trim())){W.error("××× ×§×××ר×× ×ש ××××× ××תרת");return}}if(r===1){const T=Dr(E());if(T&&!T.includes("×©× ××§××××")){W.error(T);return}}}o(_)},C=async()=>{const _=E(),T=Dr(_);if(T){o(T.includes("×©× ××§××××")?0:1),W.error(T);return}b(!0),await l(_),b(!1)},w=p.visibility==="public"&&(s||[]).some(_=>g.has(_.id)&&_.visibility==="residents");return e.jsxs(_r,{title:p.id?"ער××ת ×§×××× ×ª×©×××":"×§×××× ×ª×©××× ××ש",icon:gs,steps:["פר×× ××§××××","×¢×××× ×ª×©×××","× ×¨××ת ××××§××"],step:r,onStep:k,onClose:a,onSubmit:C,submitting:h,children:[r===0&&e.jsxs("div",{className:"space-y-4 pb-2",children:[e.jsx(Q,{label:"××תרת ××§××××",required:!0,children:e.jsx("input",{className:Se,value:p.title,onChange:_=>d("title",_.target.value),placeholder:"××ש×: ×××× ×ª×©×¤×´×",autoFocus:!0})}),e.jsx(Q,{label:"ת×××ר קצר",hint:"×××¦× ×ת×ת ×××תרת ××¢××× ××§××××",children:e.jsx("textarea",{className:ua,rows:2,value:p.description,onChange:_=>d("description",_.target.value),placeholder:"×× ×ש ×××, ×¢× ××ª× × ×¨×©×××, ××× ××¤× ×תâ¦"})}),e.jsxs(Q,{label:"ת××× × ×¨×ש×ת",children:[e.jsxs("label",{className:`${Se} flex items-center gap-2 cursor-pointer ${c?"opacity-60":""}`,children:[e.jsx(jn,{className:"w-4 h-4 text-slate-400 flex-none"}),e.jsx("span",{className:`truncate ${p.image_url?"text-slate-700":"text-slate-400"}`,children:c?"××¢××â¦":p.image_url?"ת××× × × ××ר×":"×××רת ×§×××¥"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:_=>{var T;return $((T=_.target.files)==null?void 0:T[0])}})]}),p.image_url&&e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx("img",{src:p.image_url,alt:"",className:"w-16 h-16 rounded-lg object-cover border border-slate-200"}),e.jsx("button",{type:"button",onClick:()=>d("image_url",""),className:"text-[12px] text-red-600 font-bold",children:"×סר×"})]})]}),e.jsxs(Q,{label:"××××§× ××§×××ר××ת",children:[e.jsx("div",{className:"flex gap-2",children:[{v:!1,l:"××× ×§×××ר××ת",hint:"×× ××¢××××× ×¢× ×××£ ×××"},{v:!0,l:"×¢× ×§×××ר××ת",hint:"×× ×¢××× ×ש××× ×××תרת"}].map(_=>{const T=p.sectioned===_.v;return e.jsxs("button",{type:"button",onClick:()=>u(M=>({...M,sectioned:_.v,categories:_.v&&!M.categories.length?[{id:Fr(),title:""}]:M.categories})),className:`flex-1 rounded-xl border p-3 text-right transition-colors ${T?"border-teal-400 bg-teal-50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[13px] font-bold text-slate-800",children:[_.l,T&&e.jsx(ye,{className:"w-3.5 h-3.5 text-teal-600 mr-auto"})]}),e.jsx("span",{className:"block text-[11px] text-slate-400 mt-0.5",children:_.hint})]},String(_.v))})}),p.sectioned&&e.jsxs("div",{className:"mt-3 space-y-2",children:[p.categories.map((_,T)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"w-6 text-[12px] font-black text-slate-400 tabular-nums",children:[T+1,"."]}),e.jsx("input",{className:Se,value:_.title,onChange:M=>S(_.id,M.target.value),placeholder:"××תרת ××§×××ר××"}),e.jsx("button",{type:"button",onClick:()=>P(_.id),"aria-label":"×סרת ×§×××ר××",className:"w-10 h-10 rounded-xl border border-slate-200 grid place-items-center text-slate-400 hover:text-red-600 hover:bg-red-50 flex-none",children:e.jsx(Re,{className:"w-4 h-4"})})]},_.id)),e.jsxs("button",{type:"button",onClick:A,className:"h-9 px-3 rounded-lg border border-dashed border-slate-300 text-[12.5px] font-bold text-slate-500 inline-flex items-center gap-1.5 hover:border-teal-400 hover:text-teal-700",children:[e.jsx(We,{className:"w-4 h-4"})," ××ספת ×§×××ר××"]})]})]})]}),r===1&&e.jsxs("div",{className:"flex flex-col h-full pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-none pb-2",children:[e.jsx("p",{className:"text-[13px] font-bold text-slate-700",children:p.sectioned?"××× ×¢××× ×©× ××ר ×ש ××××ר ×§×××ר××"
56:"××¢××××× ××צ×× ××¤× ×¡×ר ××××ר×"}),e.jsxs("span",{className:"text-[12px] text-slate-400 mr-auto",children:["× ×××¨× ",p.pageIds.length]})]}),(s||[]).length>6&&e.jsxs("div",{className:"relative mb-2 flex-none",children:[e.jsx(qt,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2"}),e.jsx("input",{className:`${Se} pr-9`,value:f,onChange:_=>x(_.target.value),placeholder:"××פ×ש ×¢×××"})]}),e.jsxs("div",{className:"border border-slate-200 rounded-xl divide-y divide-slate-100 flex-1 min-h-0 overflow-y-auto",children:[y.length===0&&e.jsx("p",{className:"text-[12.5px] text-slate-400 p-4 text-center",children:"××× ×¢×××× ×ª×©××× ××צ××."}),y.map(_=>{const T=g.has(_.id);return e.jsx("div",{className:`p-2.5 ${T?"bg-teal-50/40":""}`,children:e.jsxs("label",{className:"flex items-center gap-2.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:()=>O(_.id),className:"w-4 h-4 rounded border-slate-300 text-teal-600 focus:ring-teal-500 flex-none"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"block text-[13px] font-bold text-slate-800 truncate",children:[_.title,_.visibility==="residents"&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10.5px] font-bold text-slate-500 bg-slate-100 rounded-full px-1.5 py-0.5 mr-1.5",children:[e.jsx(Aa,{className:"w-2.5 h-2.5"})," ת×ש×××"]})]}),e.jsxs("span",{className:"block text-[11.5px] text-slate-400",children:[kt(_.kind).l," · ",Js(_)]})]}),T&&p.sectioned&&e.jsxs("select",{className:"h-9 rounded-lg border border-slate-200 text-[12.5px] px-2 text-slate-700 flex-none max-w-[11rem]",value:p.categoryOf[_.id]||"",onClick:M=>M.preventDefault(),onChange:M=>u(B=>({...B,categoryOf:{...B.categoryOf,[_.id]:M.target.value}})),children:[e.jsx("option",{value:"",children:"â ×§×××ר×× â"}),p.categories.map(M=>e.jsx("option",{value:M.id,children:M.title||"××× ×©×"},M.id))]})]})},_.id)})]})]}),r===2&&e.jsxs("div",{className:"space-y-4 pb-2",children:[e.jsxs(Q,{label:"×× ×××× ×פת×× ×ת ××§××××",children:[e.jsx("div",{className:"flex gap-2",children:[{v:"public",l:"צ×××ר×",icon:ca,hint:"×× ×× ×©××§×× ×ת ××§×ש×ר"},{v:"residents",l:"ת×ש××× ××××",icon:Aa,hint:"× ×רשת ×ת××ר×ת ××××ר ×××ש×"}].map(_=>{const T=_.icon,M=p.visibility===_.v;return e.jsxs("button",{type:"button",onClick:()=>d("visibility",_.v),className:`flex-1 rounded-xl border p-3 text-right transition-colors ${M?"border-teal-400 bg-teal-50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[13px] font-bold text-slate-800",children:[e.jsx(T,{className:`w-4 h-4 ${M?"text-teal-600":"text-slate-400"}`})," ",_.l,M&&e.jsx(ye,{className:"w-3.5 h-3.5 text-teal-600 mr-auto"})]}),e.jsx("span",{className:"block text-[11px] text-slate-400 mt-0.5",children:_.hint})]},_.v)})}),w&&e.jsx("p",{className:"text-[12px] text-amber-700 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2 mt-2",children:"××§×××× × ×××¨× ×¢××××× ×©×¡××× × Â«×ª×ש××× ××××». ×× ××צ×× ×× ××× ×× ×©×¤××ª× ×ת ××§×ש×ר â ש×, ×××ר ×ת×××ר â ××תש××× ×¢×¦×× ××קש ××× ××ת××ר."})]}),e.jsx(Q,{label:"×××§×× ××תר ××§××××",children:e.jsx(Qo,{options:wo,value:p,disabled:p.visibility==="residents",onChange:(_,T)=>d(_,T),note:p.visibility==="residents"?"×××§×× ××תר ×××× ××§×××× ×¦××××¨× ××××.":""})})]})]})}const Ri={one_time:Oe,recurring:Mt,recurring_debt:nt,open_amount:rt};function Mh({pages:t,catalogs:s,items:n,onChanged:a}){const[l,r]=i.useState([]),[o,p]=i.useState(null),[u,d]=i.useState([]),c=i.useMemo(()=>(s||[]).filter(f=>f.show_in_menu||f.show_on_home||f.show_in_personal),[s]),m=f=>Number(f.placement_order)||0||Number.MAX_SAFE_INTEGER;i.useEffect(()=>{const f=[...(t||[]).filter(x=>x.show_in_menu||x.show_on_home||x.show_in_personal).map(x=>({...x,_kind:"page"})),...(s||[]).filter(x=>x.show_in_menu||x.show_on_home||x.show_in_personal).map(x=>({...x,_kind:"catalog"}))].sort((x,g)=>m(x)-m(g)||String(x.title).localeCompare(String(g.title),"he"));r(f)},[t,s]),i.useEffect(()=>{if(!o){d([]);return}const f=new Map((t||[]).map(x=>[x.id,x]));d((n||[]).filter(x=>x.catalog_id===o.id).sort((x,g)=>(x.sort_order||0)-(g.sort_order||0)).map(x=>({...x,page:f.get(x.payment_page_id)})).filter(x=>x.page))},[o,n,t]);const h=async f=>{r(f);const x=Rr(f,{orderKey:"placement_order"});if(x.length)try{await Promise.all(x.map(g=>{const y=f.find(O=>O.id===g.id),$=(y==null?void 0:y._kind)==="catalog"?"PaymentCatalog":"PaymentPage";return D.entities[$].update(g.id,{placement_order:g.placement_order})})),a==null||a()}catch{W.error("ס×ר ×תצ××× ×× × ×©×ר")}},b=async f=>{d(f);const x=Rr(f,{orderKey:"sort_order"});if(x.length)try{await Promise.all(x.map(g=>D.entities.PaymentCatalogItem.update(g.id,{sort_order:g.sort_order}))),a==null||a()}catch{W.error("×ס×ר ××§×××× ×× × ×©×ר")}};return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4 items-start",children:[e.jsx(qi,{title:"ס×ר ×תצ××× ×רצ××¢×",hint:"×××¦× ×¢× ×©××¨× ××× ×ס×× ××ת×, ×××¨×¨× ×××ª× ×××¢×× ×× ××××.",children:e.jsx(zi,{items:l,onReorder:h,empty:"××× ×¢×××× ×¢××× ×× ×§×××× ×©×¡××× ××צ×× ××תר.",renderRow:f=>e.jsx(Ki,{icon:f._kind==="catalog"?gs:Ri[f.kind]||Oe,title:f.title,sub:f._kind==="catalog"?"×§×××× ×ª×©×××":`${kt(f.kind).l} · ${Js(f)}`,badges:e.jsxs(e.Fragment,{children:[(f.show_in_menu||f.show_on_home)&&e.jsx(Ii,{icon:ca,label:"××תר"}),f.show_in_personal&&e.jsx(Ii,{icon:ys,label:"×ר×× ××ש×"})]})})})}),e.jsx(qi,{title:"ס×ר ×פר×××× ××§××××",hint:"×××¨× ×§××××, ××× ×¡×× × ×¢××× ×××¨×¨× ×××ª× ×××§×××.",children:c.length===0?e.jsx("p",{className:"text-[12.5px] text-slate-400 py-6 text-center",children:"××× ×§×××× ×©×××¦× ××תר."}):e.jsx("div",{className:"space-y-2",children:c.map(f=>{const x=(o==null?void 0:o.id)===f.id,g=(n||[]).filter(y=>y.catalog_id===f.id).length;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>p(x?null:f),className:`w-full flex items-center gap-2.5 p-3 rounded-xl border text-right transition-colors ${x?"border-teal-400 bg-teal-50":"border-slate-200 bg-white hover:border-slate-300"}`,children:[e.jsx("span",{className:"w-9 h-9 rounded-lg grid place-items-center flex-none bg-teal-50 text-teal-600 border border-teal-200",children:e.jsx(gs,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800 truncate",children:f.title}),e.jsxs("span",{className:"block text-[11.5px] text-slate-400",children:[g," פר××××"]})]}),e.jsx(lt,{className:`w-4 h-4 text-slate-400 transition-transform ${x?"-rotate-90":""}`})]}),x&&e.jsx("div",{className:"mt-2 mr-4 border-r-2 border-teal-100 pr-3",children:e.jsx(zi,{items:u,onReorder:b,empty:"××× ×¢××××× ××§×××× ×××.",renderRow:y=>e.jsx(Ki,{icon:Ri[y.page.kind]||Oe,title:y.page.title,sub:`${kt(y.page.kind).l} · ${Js(y.page)}`})})})]},f.id)})})})]})}
56function qi({title:t,hint:s,children:n}){return e.jsxs("section",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-4",children:[e.jsx("h4",{className:"text-[14px] font-black text-slate-900",children:t}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5 mb-3",children:s}),n]})}function Ii({icon:t,label:s}){return e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10.5px] font-bold px-1.5 py-0.5 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-200 whitespace-nowrap",children:[e.jsx(t,{className:"w-2.5 h-2.5"})," ",s]})}const Ph=8;function zi({items:t,onReorder:s,renderRow:n,empty:a}){const l=i.useRef(null),r=i.useRef(null),[o,p]=i.useState(null),[u,d]=i.useState(null),c=(x,g)=>y=>{var O,A,S;if(y.button!=null&&y.button!==0)return;p(g),(A=(O=y.currentTarget).focus)==null||A.call(O);const $=Array.from(((S=l.current)==null?void 0:S.children)||[]).map(P=>{const E=P.getBoundingClientRect();return{height:E.height,center:E.top+E.height/2}});r.current={rows:$,y0:y.clientY,from:x};try{y.currentTarget.setPointerCapture(y.pointerId)}catch{}d({from:x,to:x,dy:0})},m=x=>{var P;const g=r.current;if(!g)return;const y=x.clientY-g.y0,{rows:$,from:O}=g,A=(((P=$[O])==null?void 0:P.center)||0)+y;let S=O;if(y>0)for(let E=O+1;E<$.length;E+=1)A>$[E].center&&(S=E);else for(let E=O-1;E>=0;E-=1)A<$[E].center&&(S=E);d({from:O,to:S,dy:y})},h=()=>{const x=u;r.current=null,d(null),x&&x.to!==x.from&&s(Br(t,x.from,x.to))},b=x=>{var y;if(!u||!r.current||x===u.from)return 0;const g=(((y=r.current.rows[u.from])==null?void 0:y.height)||0)+Ph;return u.to>u.from&&x>u.from&&x<=u.to?-g:u.to<u.from&&x>=u.to&&x<u.from?g:0},f=x=>g=>{if(g.key!=="ArrowUp"&&g.key!=="ArrowDown"&&g.key!=="Escape")return;if(g.preventDefault(),g.key==="Escape"){p(null);return}const y=x+(g.key==="ArrowDown"?1:-1);y>=0&&y<t.length&&s(Br(t,x,y))};return t.length?e.jsx("div",{ref:l,className:"space-y-2 select-none",children:t.map((x,g)=>{const y=(u==null?void 0:u.from)===g,$=o===x.id;return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":`ש×× ×× ×××§××, ${g+1} ×ת×× ${t.length}`,onPointerDown:c(g,x.id),onPointerMove:y?m:void 0,onPointerUp:y?h:void 0,onPointerCancel:y?h:void 0,onKeyDown:f(g),style:{transform:`translateY(${y?u.dy:b(g)}px)`,transition:y?"none":"transform 160ms ease",touchAction:$?"none":"pan-y",zIndex:y?10:void 0,position:"relative"},className:`flex items-center gap-2.5 p-2.5 rounded-xl border outline-none ${y?"border-emerald-500 bg-emerald-50 shadow-lg cursor-grabbing":$?"border-emerald-400 bg-emerald-50 ring-1 ring-emerald-200 cursor-grab":"border-slate-200 bg-white hover:border-slate-300 cursor-grab"}`,children:[e.jsx(su,{className:`w-4 h-4 flex-none ${$?"text-emerald-500":"text-slate-300"}`}),n(x)]},x.id)})}):e.jsx("p",{className:"text-[12.5px] text-slate-400 py-6 text-center",children:a})}function Ki({icon:t,title:s,sub:n,badges:a}){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-9 h-9 rounded-lg grid place-items-center flex-none bg-slate-50 text-slate-500 border border-slate-200",children:e.jsx(t,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-[13.5px] font-bold text-slate-800 truncate",children:s}),a]}),e.jsx("span",{className:"block text-[11.5px] text-slate-400 truncate",children:n})]})]})}const $c={one_time:Oe,recurring:Mt,recurring_debt:nt,open_amount:rt},Wi={indigo:"bg-indigo-50 text-indigo-600 border-indigo-200",emerald:"bg-emerald-50 text-emerald-600 border-emerald-200",amber:"bg-amber-50 text-amber-600 border-amber-200",violet:"bg-violet-50 text-violet-600 border-violet-200"},Ui={indigo:"text-indigo-600 bg-indigo-50",emerald:"text-emerald-600 bg-emerald-50",amber:"text-amber-600 bg-amber-50",violet:"text-violet-600 bg-violet-50"},Hi=()=>`pp-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function Eh({kibbutzId:t}){const[s,n]=i.useState(!0),[a,l]=i.useState([]),[r,o]=i.useState([]),[p,u]=i.useState([]),[d,c]=i.useState([]),[m,h]=i.useState(""),[b,f]=i.useState(null),[x,g]=i.useState(null),[y,$]=i.useState(null),[O,A]=i.useState("pages"),[S,P]=i.useState(0),E=i.useCallback(()=>P(v=>v+1),[]);i.useEffect(()=>{if(!t)return;let v=!0;return n(!0),D.entities.PaymentPage.filterAll({kibbutz_id:t}).then(F=>{v&&l(F||[])}).catch(()=>{v&&W.error("ש×××× ×××¢×× ×ª ×¢×××× ×תש×××")}).finally(()=>{v&&n(!1)}),()=>{v=!1}},[t,S]),i.useEffect(()=>{if(!t)return;let v=!0;return D.entities.PaymentCatalog.filterAll({kibbutz_id:t}).then(F=>{v&&o(F||[])}).catch(()=>{}),D.entities.PaymentCatalogItem.filterAll({kibbutz_id:t}).then(F=>{v&&u(F||[])}).catch(()=>{}),()=>{v=!1}},[t,S]),i.useEffect(()=>{if(!t)return;let v=!0;return D.entities.ChargeType.filterAll({kibbutz_id:t},"order").then(F=>{v&&c(F||[])}).catch(()=>{}),D.entities.Kibbutz.get(t).then(F=>{v&&h((F==null?void 0:F.name)||"")}).catch(()=>{}),()=>{v=!1}},[t]);const k=i.useMemo(()=>{const v=new Map;
56return(p||[]).forEach(F=>{v.has(F.catalog_id)||v.set(F.catalog_id,[]),v.get(F.catalog_id).push(F)}),v},[p]),C=i.useMemo(()=>O==="pages"?a:a.filter(v=>(v.kind||"one_time")===O),[a,O]),w=async v=>{var Z;const F=!v.id,K={kibbutz_id:t,kind:v.kind,title:v.title.trim(),description:((Z=v.description)==null?void 0:Z.trim())||null,price:kt(v.kind).fields.price&&v.price!==""?Number(v.price):null,months_limit:kt(v.kind).fields.months&&v.months_limit!==""?Number(v.months_limit):null,image_url:kt(v.kind).fields.image&&v.image_url||null,charge_type_id:v.kind==="recurring_debt"&&v.charge_type_id||null,max_purchases:v.max_purchases===""?null:Number(v.max_purchases),closes_at:v.closes_at?new Date(v.closes_at).toISOString():null,visibility:v.visibility||"public",show_in_menu:v.visibility!=="residents"&&!!v.show_in_menu,show_on_home:v.visibility!=="residents"&&!!v.show_on_home,show_in_personal:!!v.show_in_personal,is_active:!0};try{F?(await D.entities.PaymentPage.create({...K,id:Hi(),slug:Or(v.title,a.map(H=>H.slug))}),W.success("××£ ×תש××× × ×צר")):(await D.entities.PaymentPage.update(v.id,K),W.success("××£ ×תש××× ×¢××××")),f(null),E()}catch{W.error("ש×××× ×ש××ר×")}},_=async(v,F)=>{try{await D.entities.PaymentPage.update(v.id,{visibility:F}),l(K=>K.map(Z=>Z.id===v.id?{...Z,visibility:F}:Z)),W.success(F==="public"?"×××£ צ×××ר×":"×××£ פת×× ×ת×ש××× ××××ר×× ××××")}catch{W.error("ש×××× ××¢××××")}},T=async(v,F,K)=>{const Z=v==="catalog"?"PaymentCatalog":"PaymentPage",H=v==="catalog"?o:l;try{await D.entities[Z].update(F.id,K);const z=await D.entities[Z].get(F.id).catch(()=>null),te=z||{...F,...K};H(V=>V.map(Y=>Y.id===F.id?{...Y,...te}:Y)),z&&Object.entries(K).some(([V,Y])=>!!z[V]!=!!Y)&&W.error("××¢×××× ×× × ×©×ר â ×ש ××¨×¢× × ××× ×¡×ת ש××")}catch{W.error("ש×××× ××¢××××")}},M=async v=>{const F=(p||[]).filter(Z=>Z.payment_page_id===v.id).length,K=F?` 57××¢××× ×××¦× ×-${F} ×§××××××, ×××סר ×× ×××.`:"";if(window.confirm(`×××××§ ×ת «${v.title}»? ××§×ש×ר ×©× ×©×× ×פס××§ ××¢×××.${K}`))try{await D.entities.PaymentPage.delete(v.id),l(Z=>Z.filter(H=>H.id!==v.id)),u(Z=>Z.filter(H=>H.payment_page_id!==v.id)),W.success("××£ ×תש××× × ×××§")}catch{W.error("ש×××× ×××××§×")}},B=async v=>{var Z;const F=!v.id,K={kibbutz_id:t,title:v.title.trim(),description:((Z=v.description)==null?void 0:Z.trim())||null,image_url:v.image_url||null,categories:v.categories||[],visibility:v.visibility||"public",show_in_menu:v.visibility!=="residents"&&!!v.show_in_menu,show_on_home:v.visibility!=="residents"&&!!v.show_on_home,show_in_personal:!!v.show_in_personal,is_active:!0};try{const H=v.id||Hi().replace(/^pp-/,"pc-");F?await D.entities.PaymentCatalog.create({...K,id:H,slug:Or(v.title,r.map(V=>V.slug))}):await D.entities.PaymentCatalog.update(H,K);const z=(p||[]).filter(V=>V.catalog_id===H),te=new Map(z.map(V=>[V.payment_page_id,V])),ie=new Set(v.pageIds);await Promise.all(z.filter(V=>!ie.has(V.payment_page_id)).map(V=>D.entities.PaymentCatalogItem.delete(V.id).catch(()=>{}))),await Promise.all(v.pageIds.map((V,Y)=>{var X;const J=te.get(V),I={category_id:((X=v.categoryOf)==null?void 0:X[V])||null,sort_order:Y};return J?D.entities.PaymentCatalogItem.update(J.id,I).catch(()=>{}):D.entities.PaymentCatalogItem.create({id:`pci-${H.slice(-6)}-${Y}-${Math.random().toString(36).slice(2,6)}`,kibbutz_id:t,catalog_id:H,payment_page_id:V,...I}).catch(()=>{})})),W.success(F?"××§×××× × ×צר":"××§×××× ×¢××××"),g(null),A("catalogs"),E()}catch{W.error("ש×××× ×ש××רת ××§××××")}},R=async(v,F)=>{try{await D.entities.PaymentCatalog.update(v.id,{visibility:F}),o(K=>K.map(Z=>Z.id===v.id?{...Z,visibility:F}:Z)),W.success(F==="public"?"××§×××× ×¦×××ר×":"××§×××× ×¤×ª×× ×ת×ש××× ××××ר×× ××××")}catch{W.error("ש×××× ××¢××××")}},j=async v=>{if(window.confirm(`×××××§ ×ת ××§×××× Â«${v.title}»? ××§×ש×ר ×©× ×©×× ×פס××§ ××¢×××. ×¢×××× ×תש××× ×¢×¦×× ××ש×ר×.`))try{await D.entities.PaymentCatalog.delete(v.id),o(F=>F.filter(K=>K.id!==v.id)),u(F=>F.filter(K=>K.catalog_id!==v.id)),W.success("××§×××× × ×××§")}catch{W.error("ש×××× ×××××§×")}},q=v=>{const F=`${window.location.origin}${yn(gr(t,v.slug))}`;$({title:v.title,subtitle:`${kt(v.kind).l} · ${Js(v)}`,url:F,message:Td({page:v,url:F,communityName:m}),imageUrl:v.image_url||"",note:v.visibility==="residents"?"×××£ פת×× ×ת×ש××× ××××ר×× ×××× â ×× ×©××× × ××××× ×ת×קש ××ת××ר.":""})},L=v=>{const F=`${window.location.origin}${yn(ko(t,v.slug))}`,K=(k.get(v.id)||[]).length;$({title:v.title,subtitle:`×§×××× ×ª×©××× Â· ${K} פר××××`,url:F,message:Bd({catalog:v,url:F,communityName:m,count:K}),imageUrl:v.image_url||"",note:v.visibility==="residents"?"××§×××× ×¤×ª×× ×ת×ש××× ××××ר×× ×××× â ×× ×©××× × ××××× ×ת×קש ××ת××ר.":""})};zu(e.jsx(Fh,{onPage:()=>f({}),onCatalog:()=>g({}),onArrange:()=>A("arrange")}),[]);const N=[{v:"pages",l:"×¢×××× ×ª×©×××",n:a.length,icon:Zt,tone:"text-emerald-600 bg-emerald-50"},{v:"catalogs",l:"×§×××× ×ª×©×××",n:r.length,icon:gs,tone:"text-teal-600 bg-teal-50"},...fr.map(v=>({v:v.v,l:v.l,n:a.filter(F=>
57(F.kind||"one_time")===v.v).length,icon:$c[v.v]||Oe,tone:Ui[v.tone]||Ui.indigo}))];return e.jsxs("div",{dir:"rtl",children:[e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-2.5 mb-5",children:N.map(v=>{const F=v.icon,K=O===v.v;return e.jsxs("button",{type:"button",onClick:()=>A(v.v),"aria-pressed":K,className:`rounded-2xl border bg-white p-3 text-right transition-all ${K?"border-teal-500 ring-2 ring-teal-100 shadow-sm":"border-slate-200 hover:border-slate-300 hover:shadow-sm"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[19px] font-black text-slate-900 tabular-nums",children:v.n}),e.jsx("span",{className:`w-8 h-8 rounded-xl grid place-items-center flex-none mr-auto ${v.tone}`,children:e.jsx(F,{className:"w-4 h-4"})})]}),e.jsx("span",{className:"block text-[12.5px] font-bold text-slate-600 mt-1.5 leading-tight",children:v.l})]},v.v)})}),s?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-emerald-500 rounded-full animate-spin"})}):O==="arrange"?e.jsx(Mh,{pages:a,catalogs:r,items:p,onChanged:E}):O==="catalogs"?e.jsx(Oh,{catalogs:r,itemsByCatalog:k,pages:a,kibbutzId:t,onNew:()=>g({}),onEdit:g,onShare:L,onVisibility:R,onDelete:j,onPlacement:(v,F)=>T("catalog",v,F)}):e.jsx(Dh,{rows:C,kibbutzId:t,everything:a.length===0,onNew:()=>f({}),onEdit:f,onShare:q,onVisibility:_,onDelete:M,onPlacement:(v,F)=>T("page",v,F)}),b&&e.jsx(Lh,{page:b,types:d,onClose:()=>f(null),onSave:w}),x&&e.jsx(Ah,{catalog:x,pages:a,items:k.get(x.id)||[],onClose:()=>g(null),onSave:B}),y&&e.jsx(Th,{share:y,kibbutzId:t,onClose:()=>$(null)})]})}function Fh({onPage:t,onCatalog:s,onArrange:n}){const[a,l]=i.useState(!1),r=i.useRef(null),o="w-full flex items-start gap-2.5 px-3.5 py-3 text-right hover:bg-slate-50";return e.jsxs("div",{className:"relative flex-none",ref:r,children:[e.jsxs("button",{type:"button",onClick:()=>l(p=>!p),"aria-haspopup":"menu","aria-expanded":a,className:"h-11 px-5 rounded-xl bg-emerald-600 hover:bg-emerald-700 text-white text-sm font-bold inline-flex items-center gap-2 transition-colors",children:[e.jsx(Hn,{className:"w-4 h-4"})," פע×××ת × ×ספ×ת",e.jsx(Jt,{className:`w-4 h-4 transition-transform ${a?"rotate-180":""}`})]}),e.jsx(ma,{anchorRef:r,open:a,onClose:()=>l(!1),width:"17rem",children:e.jsxs("div",{className:"overflow-hidden rounded-2xl",role:"menu",children:[e.jsxs("button",{className:o,onClick:()=>{l(!1),t()},children:[e.jsx(We,{className:"w-4 h-4 text-emerald-600 mt-0.5 flex-none"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800",children:"×¢××× ×ª×©××× ××ש"}),e.jsx("span",{className:"block text-[11.5px] text-slate-400",children:"×§×ש×ר ××× ×××ר ×××"})]})]}),e.jsxs("button",{className:`${o} border-t border-slate-100`,onClick:()=>{l(!1),s()},children:[e.jsx(gs,{className:"w-4 h-4 text-teal-600 mt-0.5 flex-none"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800",children:"×§×××× ×ª×©××× ××ש"}),e.jsx("span",{className:"block text-[11.5px] text-slate-400",children:"×§×ש×ר ××× ×©×צ×× ××× ×¢×××× ×ª×©×××"})]})]}),e.jsxs("button",{className:`${o} border-t border-slate-100`,onClick:()=>{l(!1),n()},children:[e.jsx(iu,{className:"w-4 h-4 text-slate-500 mt-0.5 flex-none"}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-[13.5px] font-bold text-slate-800",children:"× ×××× ×¡×ר ×תצ×××ת"}),e.jsx("span",{className:"block text-[11.5px] text-slate-400",children:"××××× ×¡×ר ×× ×¨×¦×× ××תר, ××× ×ס×ר ×ת×× ×§××××"})]})]})]})})]})}const st="text-right text-[12px] font-black text-slate-500 px-3 py-2.5 whitespace-nowrap",at="px-3 py-3 text-[13px] text-slate-700 align-middle";function rr({icon:t,title:s,text:n,action:a,onAction:l}){return e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm p-12 text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-emerald-50 flex items-center justify-center mx-auto mb-3",children:e.jsx(t,{className:"w-7 h-7 text-emerald-500"})}),e.jsx("h4",{className:"text-base font-bold mb-1",children:s}),e.jsx("p",{className:"text-sm text-slate-500 max-w-md mx-auto",children:n}
57),a&&e.jsxs("button",{onClick:l,className:"mt-4 h-10 px-4 rounded-xl bg-emerald-600 hover:bg-emerald-700 text-white text-sm font-bold inline-flex items-center gap-2",children:[e.jsx(We,{className:"w-4 h-4"})," ",a]})]})}function Cc({href:t,onShare:s,onEdit:n,onDelete:a,children:l}){return e.jsxs("span",{className:"flex items-center gap-1.5",children:[l,e.jsxs("a",{href:t,target:"_blank",rel:"noreferrer",title:"צפ×××","aria-label":"צפ×××",className:"h-8 px-2.5 rounded-lg border border-slate-200 text-[12.5px] font-bold text-slate-600 inline-flex items-center gap-1.5 hover:bg-slate-50",children:[e.jsx(fs,{className:"w-4 h-4"})," צפ×××"]}),e.jsxs("button",{onClick:s,title:"ש×ת××£","aria-label":"ש×ת××£",className:"h-8 px-2.5 rounded-lg bg-emerald-50 text-emerald-700 text-[12.5px] font-bold inline-flex items-center gap-1.5 hover:bg-emerald-100",children:[e.jsx(ru,{className:"w-4 h-4"})," שתף"]}),e.jsx("button",{onClick:n,title:"ער×××","aria-label":"ער×××",className:"w-8 h-8 rounded-lg border border-slate-200 grid place-items-center text-slate-500 hover:bg-slate-50 hover:text-slate-700",children:e.jsx(It,{className:"w-4 h-4"})}),e.jsx("button",{onClick:a,title:"××××§×","aria-label":"××××§×",className:"w-8 h-8 rounded-lg border border-slate-200 grid place-items-center text-slate-400 hover:bg-red-50 hover:text-red-600 hover:border-red-200",children:e.jsx(Re,{className:"w-4 h-4"})})]})}function Ac({row:t,onChange:s}){const n=!!(t.show_in_menu||t.show_on_home),a=l=>`w-8 h-8 rounded-lg border grid place-items-center transition-colors ${l?"border-emerald-300 bg-emerald-50 text-emerald-600 hover:bg-emerald-100":"border-slate-200 text-slate-300 hover:bg-slate-50 hover:text-slate-500"}`;return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:a(n),"aria-pressed":n,title:n?"×××¦× ××תר ××§×××× â ×××¦× ××× ××ס×ר":"××× × ×××¦× ××תר â ×××¦× ××× ××צ×× ××¢××× ×××ת",onClick:()=>s(t,n?{show_in_menu:!1,show_on_home:!1}:{show_on_home:!0}),children:e.jsx(ca,{className:"w-4 h-4"})}),e.jsx("button",{type:"button",className:a(!!t.show_in_personal),"aria-pressed":!!t.show_in_personal,title:t.show_in_personal?"×××¦× ××ר×× ××××©× â ×××¦× ××× ××ס×ר":"××× × ×××¦× ××ר×× ××××©× â ×××¦× ××× ××צ××",onClick:()=>s(t,{show_in_personal:!t.show_in_personal}),children:e.jsx(ys,{className:"w-4 h-4"})})]})}function Mc({href:t}){const[s,n]=i.useState(!1),a=async()=>{try{await navigator.clipboard.writeText(`${window.location.origin}${t}`),n(!0),setTimeout(()=>n(!1),1600),W.success("××§×ש×ר ××עתק")}catch{W.error("×× × ××ª× ××עת××§")}};return e.jsx("button",{type:"button",onClick:a,"aria-label":"×עתקת ××§×ש×ר",title:t,className:`w-8 h-8 rounded-lg border grid place-items-center transition-colors ${s?"border-emerald-300 bg-emerald-50 text-emerald-600":"border-slate-200 text-slate-400 hover:bg-slate-50 hover:text-slate-700"}`,children:s?e.jsx(ye,{className:"w-4 h-4"}):e.jsx(Eo,{className:"w-4 h-4"})})}function Pc({value:t,onChange:s}){const n=t!=="residents";return e.jsxs("button",{type:"button",role:"switch","aria-checked":n,onClick:()=>s(n?"residents":"public"),title:n?"צ××××¨× â ×××¦× ××× ×××××× ×ת×ש×××":"×ת×ש××× ×××× â ×××¦× ××× ×פת×× ×××××",className:`inline-flex items-center gap-1.5 h-8 px-2 rounded-full border text-[11.5px] font-bold transition-colors ${n?"bg-sky-50 border-sky-200 text-sky-700":"bg-slate-100 border-slate-200 text-slate-500"}`,children:[e.jsx("span",{className:`w-8 h-4 rounded-full relative transition-colors flex-none ${n?"bg-sky-500":"bg-slate-300"}`,children:e.jsx("span",{className:`absolute top-0.5 w-3 h-3 rounded-full bg-white transition-all ${n?"right-0.5":"right-4.5"}`})}),n?e.jsx(ca,{className:"w-3 h-3"}):e.jsx(Aa,{className:"w-3 h-3"}),n?"צ×××ר×":"ת×ש×××"]})}function Dh({rows:t,kibbutzId:s,everything:n,onNew:a,onEdit:l,onShare:r,onVisibility:o,onDelete:p,onPlacement:u}){return t.length?e.jsx("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:st,children:"×©× ×××£"}),e.jsx("th",{className:st,children:"ס××"}),e.jsx("th",{className:st,children:"×¢××ת"}),e.jsx("th",{className:st,children:"× ×¨××ת"}),e.jsx("th",{className:st,children:"×§×ש×ר"}),e.jsx("th",{className:st,children:"פע×××ת"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:t.map(d=>{const c=kt(d.kind),m=$c[c.v]||Oe,h=yn(gr(s,d.slug)),b=qd(d);return e.jsxs("tr",{className:"hover:bg-slate-50/60",children:[e.jsx("td",{className:at,children:e.jsxs("span",{className:"flex items-center gap-2.5 min-w-0",children:[d.image_url?e.jsx("img",{src:d.image_url,alt:"",className:"w-9 h-9 rounded-lg object-cover flex-none border border-slate-200"}):e.jsx("span",{className:`w-9 h-9 rounded-lg grid place-items-center flex-none border ${Wi[c.tone]||Wi.indigo}`,children:e.jsx(m,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"font-bold text-slate-900 truncate",children:d.title}),!b.open&&e.jsx("span",{className:"flex-none text-[10.5px] font-bold px-1.5 py-0.5 rounded-full bg-red-50 text-red-600 border border-red-200 whitespace-nowrap",title:b.label,children:b.reason==="sold_out"?"×××":"× ×¡×ר"})]}),d.description&&e.jsx("span",{className:"block text-[11.5px] text-slate-400 truncate max-w-[22rem]",children:d.description})]})]})}),e.jsx("td",{className:`${at}
57 text-slate-500 whitespace-nowrap`,children:c.l}),e.jsxs("td",{className:`${at} font-bold whitespace-nowrap`,children:[Js(d),b.open&&b.remaining!==null&&e.jsxs("span",{className:"block text-[11px] font-bold text-amber-600",children:["× ××ª×¨× ",b.remaining]}),d.closes_at&&b.open&&e.jsxs("span",{className:"block text-[11px] text-slate-400",children:["×¢× ",Id(d.closes_at)]})]}),e.jsx("td",{className:at,children:e.jsx(Pc,{value:d.visibility,onChange:f=>o(d,f)})}),e.jsx("td",{className:at,children:e.jsx(Mc,{href:h})}),e.jsx("td",{className:at,children:e.jsx(Cc,{href:h,onShare:()=>r(d),onEdit:()=>l(d),onDelete:()=>p(d),children:e.jsx(Ac,{row:d,onChange:u})})})]},d.id)})})]})})}):n?e.jsx(rr,{icon:Zt,title:"×¢×××× ××× ×¢×××× ×ª×©×××",text:"×¢××× ×ª×©××× ××× ×§×ש×ר עצ×××: ××× ××× × ×ª××× ××ש××× ×ש××, ××פשר ×ש××× ×××ª× ×××××ס×פ ××× ×©××× × ×ª×ש×.",action:"×¢××× ×ª×©××× ××ש",onAction:a}):e.jsx(rr,{icon:Zt,title:"××× ×¢××××× ×ס×× ××",text:"×××¨× ×ר××ס××× ××רת, ×× ×¦×¨× ×¢××× ××ש ××ס×× ×××.",action:"×¢××× ×ª×©××× ××ש",onAction:a})}function Oh({catalogs:t,itemsByCatalog:s,pages:n,kibbutzId:a,onNew:l,onEdit:r,onShare:o,onVisibility:p,onDelete:u,onPlacement:d}){return t.length?e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:st,children:"×©× ××§××××"}),e.jsx("th",{className:st,children:"פר××××"}),e.jsx("th",{className:st,children:"×§×××ר××ת"}),e.jsx("th",{className:st,children:"× ×¨××ת"}),e.jsx("th",{className:st,children:"×§×ש×ר"}),e.jsx("th",{className:st,children:"פע×××ת"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:t.map(c=>{const m=s.get(c.id)||[],h=Array.isArray(c.categories)?c.categories:[],b=yn(ko(a,c.slug)),f=Rd({categories:h,items:m,pages:n}).reduce((x,g)=>x+g.pages.length,0);return e.jsxs("tr",{className:"hover:bg-slate-50/60",children:[e.jsx("td",{className:at,children:e.jsxs("span",{className:"flex items-center gap-2.5 min-w-0",children:[c.image_url?e.jsx("img",{src:c.image_url,alt:"",className:"w-9 h-9 rounded-lg object-cover flex-none border border-slate-200"}):e.jsx("span",{className:"w-9 h-9 rounded-lg grid place-items-center flex-none border bg-teal-50 text-teal-600 border-teal-200",children:e.jsx(gs,{className:"w-4 h-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-bold text-slate-900 truncate",children:c.title}),c.description&&e.jsx("span",{className:"block text-[11.5px] text-slate-400 truncate max-w-[22rem]",children:c.description})]})]})}),e.jsxs("td",{className:`${at} font-bold tabular-nums`,children:[f,f!==m.length&&e.jsxs("span",{className:"text-[11px] text-slate-400",children:[" / ",m.length]})]}),e.jsx("td",{className:`${at} text-slate-500`,children:h.length?h.map(x=>x.title).filter(Boolean).join(" · "):e.jsx("span",{className:"text-slate-300",children:"××× ×§×××ר××ת"})}),e.jsx("td",{className:at,children:e.jsx(Pc,{value:c.visibility,onChange:x=>p(c,x)})}),e.jsx("td",{className:at,children:e.jsx(Mc,{href:b})}),e.jsx("td",{className:at,children:e.jsx(Cc,{href:b,onShare:()=>o(c),onEdit:()=>r(c),onDelete:()=>u(c),children:e.jsx(Ac,{row:c,onChange:d})})})]},c.id)})})]})}),e.jsx("p",{className:"px-4 py-2.5 text-[11.5px] text-slate-400 border-t border-slate-100",children:"×§×××× ×¦××××¨× ×צ×× ×× ×¢××× ×©×¡××× Â«×ª×ש××× ××××» â ×פר×× × ×¨×× ××× ×× ×©×¤××ª× ×ת ××§×ש×ר, ××תש××× ×¢×¦×× ××רש ×ת××ר×ת."})]}):e.jsx(rr,{icon:gs,title:"×¢×××× ××× ×§××××××",text:"×§×××× ××× ×§×ש×ר ××× ×©×צ×× ××× ×¢×××× ×ª×©××× ××× â ×¢×× ×ª ××××××, ×××רת ס××£ ×©× ×, רש××ת ××× ×××× â ××¢×צ×× ×תר ××§××××, ××× ×¨×צ×× ×× ×××××§ ××§×××ר××ת.",action:"×§×××× ×ª×©××× ××ש",onAction:l})}function Lh({page:t,types:s,onClose:n,onSave:a}){const[l,r]=i.useState(0),[o,p]=i.useState(()=>({id:t.id,kind:t.kind||"one_time",title:t.title||"",description:t.description||"",price:t.price??"",months_limit:t.months_limit??"",max_purchases:t.max_purchases??"",closes_at:zd(t.closes_at),image_url:t.image_url||"",charge_type_id:t.charge_type_id||"",visibility:t.visibility||"public",show_in_menu:!!t.show_in_menu,show_on_home:!!t.show_on_home,show_in_personal:!!t.show_in_personal})),u=($,O)=>p(A=>({...A,[$]:O})),[d,c]=i.useState(!1),[m,h]=i.useState(!1),b=kt(o.kind),f=o.visibility!=="residents",x=async $=>{if($){c(!0);try{const{file_url:O}=await D.integrations.Core.UploadFile({file:$});u("image_url",O),W.success("×ת××× × ×××¢×ת×")}catch{W.error("ש×××× ×××¢××ת ×ת××× ×")}finally{c(!1)}}},g=$=>{if($>l&&!o.title.trim()){W.error("×ש ××××× ×©× ×××צר/×ש×ר×ת");return}r($)}
57,y=async()=>{if(!o.title.trim()){r(0),W.error("×ש ××××× ×©× ×××צר/×ש×ר×ת");return}h(!0),await a(o),h(!1)};return e.jsx(_r,{title:o.id?"ער××ת ××£ תש×××":"×צ×רת ××£ תש×××",icon:Oe,steps:["×× × ××ר","תצ××× ×× ×¨××ת"],step:l,onStep:g,onClose:n,onSubmit:y,submitting:m,children:l===0?e.jsxs("div",{className:"space-y-4 pb-2",children:[e.jsxs(Q,{label:"ס×× ×§×ש×ר",children:[e.jsx("select",{className:Se,value:o.kind,onChange:$=>u("kind",$.target.value),disabled:!!o.id,children:fr.map($=>e.jsx("option",{value:$.v,children:$.l},$.v))}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-1",children:o.id?"ס×× ××§×ש×ר × ×§××¢ ××צ××¨× ×××× × ××©×ª× ×.":b.hint})]}),e.jsx(Q,{label:"×©× ×××צר/×ש×ר×ת",required:!0,children:e.jsx("input",{className:Se,value:o.title,onChange:$=>u("title",$.target.value),placeholder:"××× ×©×",autoFocus:!0})}),e.jsx(Q,{label:"ת×××ר",hint:"×××¦× ××¢××× ×תש××× ×¢×¦××",children:e.jsx("textarea",{className:ua,rows:2,value:o.description,onChange:$=>u("description",$.target.value),placeholder:"×ער×ת, ×× ×××× ×תש×××, ×××¢×××â¦"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[b.fields.price&&e.jsx(Q,{label:"×××ר ×××§××/×",children:e.jsx("input",{type:"number",min:"0",step:"0.01",className:Se,value:o.price,onChange:$=>u("price",$.target.value),placeholder:"0.00"})}),b.fields.months&&e.jsx(Q,{label:"×××ת ××××©× ××××",hint:"ר××§ = ××× ×××××",children:e.jsx("input",{type:"number",min:"1",step:"1",className:Se,value:o.months_limit,onChange:$=>u("months_limit",$.target.value),placeholder:"××× ×××××"})}),e.jsx(Q,{label:"××××ת ×××ת ר××ש×ת",hint:"ר××§ = ××× ×××××. ×××××¢ ××ספר â ××¢××× × ×¡×ר",children:e.jsx("input",{type:"number",min:"1",step:"1",className:Se,value:o.max_purchases,onChange:$=>u("max_purchases",$.target.value),placeholder:"××× ×××××"})}),e.jsx(Q,{label:"×××¢× ×¡××ר×",hint:"ר××§ = ××× ×××¢×. ××ר×× ××¢××× ×× ××××",children:e.jsx("input",{type:"datetime-local",className:Se,value:o.closes_at,onChange:$=>u("closes_at",$.target.value)})})]}),o.kind==="recurring_debt"&&e.jsx(Q,{label:"ס×× ××××",info:"××××× ×©××××צר ×××¨×©× ×ª×ת ס×× ×× ×××פ××¢ ×××××ת ×צ×××",children:e.jsxs("select",{className:Se,value:o.charge_type_id,onChange:$=>u("charge_type_id",$.target.value),children:[e.jsx("option",{value:"",children:"â ××× â"}),s.map($=>e.jsx("option",{value:$.id,children:$.name},$.id))]})})]}):e.jsxs("div",{className:"space-y-4 pb-2",children:[b.fields.image&&e.jsxs(Q,{label:"ת××× × ×¨×ש×ת",children:[e.jsxs("label",{className:`${Se} flex items-center gap-2 cursor-pointer ${d?"opacity-60":""}`,children:[e.jsx(jn,{className:"w-4 h-4 text-slate-400 flex-none"}),e.jsx("span",{className:`truncate ${o.image_url?"text-slate-700":"text-slate-400"}`,children:d?"××¢××â¦":o.image_url?"ת××× × × ××ר×":"×××רת ×§×××¥"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:$=>{var O;return x((O=$.target.files)==null?void 0:O[0])}})]}),o.image_url&&e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx("img",{src:o.image_url,alt:"",className:"w-16 h-16 rounded-lg object-cover border border-slate-200"}),e.jsx("button",{type:"button",onClick:()=>u("image_url",""),className:"text-[12px] text-red-600 font-bold",children:"×סר×"})]})]}),e.jsx(Q,{label:"×× ×××× ×פת×× ×ת ××§×ש×ר",children:e.jsx("div",{className:"flex gap-2",children:[{v:"public",l:"צ×××ר×",icon:ca,hint:"×× ×× ×©××§×× ×ת ××§×ש×ר"},{v:"residents",l:"ת×ש××× ××××",icon:Aa,hint:"× ×רשת ×ת××ר×ת ××××ר ×××ש×"}].map($=>{const O=$.icon,A=o.visibility===$.v;return e.jsxs("button",{type:"button",onClick:()=>u("visibility",$.v),className:`flex-1 rounded-xl border p-3 text-right transition-colors ${A?"border-teal-400 bg-teal-50":"border-slate-200 hover:border-slate-300"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[13px] font-bold text-slate-800",children:[e.jsx(O,{className:`w-4 h-4 ${A?"text-teal-600":"text-slate-400"}`})," ",$.l,A&&e.jsx(ye,{className:"w-3.5 h-3.5 text-teal-600 mr-auto"})]}),e.jsx("span",{className:"block text-[11px] text-slate-400 mt-0.5",children:$.hint})]},$.v)})})}),e.jsx(Q,{label:"×××§×× ××תר ××§××××",children:e.jsx(Qo,{options:wo,value:o,disabled:!f,onChange:($,O)=>u($,O),note:f?"":"×××§×× ××תר ×××× ××¢××× ×¦××××¨× ×××× â ×¢××× ×ת×ש××× ×××¦× ××××ר ××××©× ××¨× ××§×ש×ר עצ××."})})]})})}function Th({share:t,kibbutzId:s,onClose:n}
57){const a=zc(),{title:l,subtitle:r,url:o,message:p,imageUrl:u,note:d}=t,c=`${l} 58${r||""} 59${o}`,[m,h]=i.useState(!1),b=async()=>{try{await navigator.clipboard.writeText(o),h(!0),setTimeout(()=>h(!1),1800)}catch{W.error("×× × ××ª× ××עת××§")}},f=()=>{a(`/kibbutz/${s}/send-message`,{state:{prefill:{title:l,content:p,imageUrl:u||"",linkUrl:lu(p,o),kind:u?au:nu}}})};return e.jsx("div",{className:"fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:n,dir:"rtl",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-md p-5",onClick:x=>x.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("h3",{className:"text-lg font-black text-slate-900",children:"ש×ת××£ ××§×ש×ר"}),e.jsx("button",{onClick:n,"aria-label":"ס××ר×",className:"w-9 h-9 rounded-full border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsxs("p",{className:"text-sm text-slate-500 mb-4",children:[l,r?` · ${r}`:""]}),d&&e.jsx("p",{className:"text-[12px] text-amber-700 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2 mb-3",children:d}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("a",{href:`https://wa.me/?text=${encodeURIComponent(c)}`,target:"_blank",rel:"noreferrer",className:"flex items-center gap-3 p-3 rounded-xl border border-slate-200 hover:border-slate-300 hover:bg-slate-50 transition-colors",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl grid place-items-center flex-none bg-emerald-50 text-emerald-700",children:e.jsx(gn,{className:"w-5 h-5"})}),e.jsx("span",{className:"text-[14px] font-bold text-slate-800",children:"ש×ת××£ ×××××ס×פ"})]}),e.jsxs("button",{type:"button",onClick:f,className:"w-full flex items-center gap-3 p-3 rounded-xl border border-slate-200 hover:border-slate-300 hover:bg-slate-50 transition-colors text-right",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl grid place-items-center flex-none bg-blue-50 text-blue-700",children:e.jsx(Gs,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[14px] font-bold text-slate-800",children:"ש×××× ×××××¢×"}),e.jsx("span",{className:"block text-[11px] text-slate-400",children:"××××× ×©×××ת ××××¢×ת â ×××רת × ××¢× ××, ×××××¢× ××ר ×ת×××"})]})]}),e.jsxs("button",{onClick:b,className:"w-full flex items-center gap-3 p-3 rounded-xl border border-slate-200 hover:border-slate-300 hover:bg-slate-50 transition-colors text-right",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl grid place-items-center flex-none bg-slate-100 text-slate-600",children:m?e.jsx(ye,{className:"w-5 h-5 text-emerald-600"}):e.jsx(Eo,{className:"w-5 h-5"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[14px] font-bold text-slate-800",children:m?"××§×ש×ר ××עתק":"×עתקת ××§×ש×ר"}),e.jsx("span",{className:"block text-[11px] text-slate-400 truncate",dir:"ltr",children:o})]})]})]})]})})}function Bh({kibbutzId:t}){const[s,n]=i.useState([]),[a,l]=i.useState({}),[r,o]=i.useState({}),[p,u]=i.useState(!0),[d,c]=i.useState("all"),[m,h]=i.useState(""),[b,f]=i.useState(null),[x,g]=i.useState(null),y=i.useCallback(async()=>{if(t){u(!0);try{const[k,C,w]=await Promise.all([D.entities.BillingRequest.filter({community_id:t}),D.entities.BillingRequestMessage.filter({community_id:t}),D.entities.PayerAccount.filter({community_id:t}).catch(()=>[])]),_={};for(const M of C||[])(_[M.request_id]=_[M.request_id]||[]).push(M);Object.values(_).forEach(M=>M.sort((B,R)=>String(B.created_date||"").localeCompare(String(R.created_date||""))));const T={};for(const M of w||[])T[M.id]=M;n(k||[]),l(_),o(T)}catch{W.error("ש×××× ×××¢×× ×ª ××¤× ××ת")}finally{u(!1)}}},[t]);i.useEffect(()=>{y()},[y]),i.useEffect(()=>{D.auth.me().then(g).catch(()=>g(null))},[]);const $=i.useMemo(()=>ud(s),[s]),O=md(s,"manager"),A=i.useMemo(()=>{const k=m.trim().toLowerCase();return $.filter(C=>xd(C,d)).filter(C=>{if(!k)return!0;const w=r[C.payer_account_id];return[C.ticket_no,C.subject,Ll(C.topic),w==null?void 0:w.name,w==null?void 0:w.account_number].filter(
59Boolean).some(_=>String(_).toLowerCase().includes(k))})},[$,d,m,r]),S=async k=>{const C=b===k.id?null:k.id;f(C),C&&k.manager_unread&&(n(w=>w.map(_=>_.id===k.id?{..._,manager_unread:!1}:_)),await D.entities.BillingRequest.update(k.id,{manager_unread:!1}).catch(()=>{}))},P=async(k,C,{close:w=!1}={})=>{const _=new Date().toISOString();await D.entities.BillingRequestMessage.create({community_id:t,request_id:k.id,author_role:"manager",author_id:(x==null?void 0:x.id)||null,author_name:(x==null?void 0:x.full_name)||(x==null?void 0:x.email)||"×× ××ת ××§××××",body:C,created_date:_}),await D.entities.BillingRequest.update(k.id,{status:w?"closed":"in_progress",last_message_at:_,last_message_role:"manager",resident_unread:!0,manager_unread:!1,updated_date:_,...w?{closed_at:_,closed_by:(x==null?void 0:x.id)||null,closed_source:"manager"}:{}}),await y()},E=async(k,C)=>{const w=new Date().toISOString();await D.entities.BillingRequest.update(k.id,{status:C,manager_unread:!1,updated_date:w,...C==="closed"?{closed_at:w,closed_by:(x==null?void 0:x.id)||null,closed_source:"manager",resident_unread:!0}:{closed_at:null,closed_by:null,closed_source:null}}),W.success(C==="closed"?"××¤× ××× × ×¡×ר×":`××¤× ××× ×¡××× × ×${xo(C)}`),await y()};return e.jsxs("div",{dir:"rtl",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap mb-4",children:[e.jsx("h2",{className:"text-xl font-black text-slate-900",children:"×¤× ××ת ×× ××©× ××××××"}),e.jsxs("span",{className:"relative inline-grid place-items-center w-10 h-10 rounded-full bg-white border border-slate-200",title:O?`${O} ×¤× ××ת ××ת×× ×ת ×××¢× ×`:"××× ×¤× ××ת ××ש×ת",children:[e.jsx(Kc,{className:`w-[18px] h-[18px] ${O?"text-slate-700":"text-slate-300"}`}),O>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 min-w-[20px] h-5 px-1 rounded-full bg-rose-500 text-white text-[11px] font-black grid place-items-center",children:O})]}),O>0&&e.jsx("span",{className:"text-[13px] font-bold text-rose-600",children:O===1?"×¤× ××× ××ת ××ת×× × ×××¢× ×":`${O} ×¤× ××ת ××ת×× ×ת ×××¢× ×`})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4 sm:p-5",children:[e.jsxs("div",{className:"flex items-center gap-2.5 flex-wrap mb-4",children:[pd.map(k=>{const C=d===k.v;return e.jsxs("button",{type:"button",onClick:()=>c(k.v),className:`h-9 px-3.5 rounded-full text-[13px] font-bold border inline-flex items-center gap-1.5 transition-colors 60 ${C?"bg-slate-900 border-slate-900 text-white":"bg-white border-slate-200 text-slate-600 hover:border-slate-300"}`,children:[k.l,e.jsx("span",{className:`text-[11px] font-black px-1.5 min-w-[18px] text-center rounded-full ${C?"bg-white/25":"bg-slate-100 text-slate-500"}`,children:hd(s,k.v)})]},k.v)}),e.jsxs("div",{className:"relative mr-auto",children:[e.jsx(qt,{className:"w-4 h-4 text-slate-400 absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none"}),e.jsx("input",{value:m,onChange:k=>h(k.target.value),placeholder:"××פ×ש ××¤× ×ספר, ×שפ×× ×× × ×ש×","aria-label":"××פ×ש ×¤× ××ת",className:"h-9 w-64 rounded-full border border-slate-200 pr-9 pl-3 text-[13px]"})]})]}),p?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-slate-800 rounded-full animate-spin"})}):A.length===0?e.jsxs("div",{className:"text-center py-14",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-slate-100 grid place-items-center mx-auto mb-3",children:e.jsx(cr,{className:"w-7 h-7 text-slate-300"})}),e.jsx("p",{className:"text-sm text-slate-500",children:s.length===0?"×¢×××× ×× ×תק××× ×¤× ××ת ×× ××©× ××××××.":"××× ×¤× ××ת ×ת××××ת ×ס×× ××."})]}):e.jsx("ul",{className:"space-y-2",children:A.map(k=>e.jsxs("li",{className:`rounded-xl border transition-colors ${b===k.id?"border-slate-300 bg-slate-50/60":"border-slate-200 bg-white hover:border-slate-300"}`,children:[e.jsx(Rh,{r:k,account:r[k.payer_account_id],open:b===k.id,onToggle:()=>S(k)}),b===k.id&&e.jsx(qh,{r:k,messages:a[k.id]||[],onReply:P,onStatus:E})]},k.id))})]})]})}function Rh({r:t,account:s,open:n,onToggle:a}){return e.jsxs("button",{type:"button",onClick:a,"aria-expanded":n,className:"w-full flex items-center gap-3 p-3.5 text-right",children:[e.jsx(lt,{className:`w-4 h-4 flex-none text-slate-300 transition-transform ${n?"-rotate-90":""}`}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"block text-[15px] font-bold text-slate-800 truncate",children:["#",t.ticket_no," · ",t.subject||Ll(t.topic)]}),e.jsxs("span",{className:"block text-[12px] text-slate-400 mt-0.5 truncate",children:[(s==null?void 0:s.name)||"×ש××× ×× ××××¢",s!=null&&s.account_number?` · ×ש××× ${s.account_number}`:""," · ",Ll(t.topic)," · ",po(t.last_message_at||t.created_date)]})]}),t.manager_unread&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 h-7 px-2.5 rounded-full bg-rose-50 border border-rose-200 text-rose-700 text-[12px] font-bold flex-none",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-rose-500"})," ××ש×"]}),e.jsx("span",{className:`h-7 px-2.5 rounded-full border text-[12px] font-bold grid place-items-center flex-none ${bd(t.status)}`,children:xo(t.status)})]})}function qh({r:t,messages:s,onReply:n,onStatus:a}){const[l,r]=i.useState(""),[o,p]=i.useState(!1),u=async d=>{const c=l.trim();if(!c){W.error("×ש ××××× ×ª××× ×ת××××");return}p(!0);try{await n(t,c,d),r(""),W.success(d!=null&&d.close?"×ת×××× × ×©××× ×××¤× ××× × ×¡×ר×":"×ת×××× × ×©×××")}catch{W.error("ש×××× ×ש×××ת ×ת××××")}finally{p(!1)}};return e.jsxs("div",{className:"px-3.5 pb-3.5 pt-3 border-t border-slate-200/80",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-3",children:[t.status!=="in_progress"&&t.status!=="closed"&&e.jsx(Ol,{icon:bo,label:"ס×××× ××××פ××",onClick:()=>a(t,"in_progress")}),t.status!=="closed"?e.jsx(Ol,{icon:Aa,label:"ס××רת ××¤× ×××",onClick:()=>a(t,"closed")}):e.jsx(Ol,{icon:ou,label:"פת××× ×××ש",onClick:()=>a(t,"open")})]}),e.jsx("div",{className:"space-y-2.5",children:s.length===0?e.jsx("p",{className:"text-sm text-slate-400",children:"××× ××××¢×ת ××¤× ××× ×××."}):s.map(d=>e.jsx(Ih,{m:d},d.id))}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("input",{value:l,onCh
60ange:d=>r(d.target.value),onKeyDown:d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),u())},placeholder:"×ת××ת ת×××× ×ת×ש×â¦","aria-label":"×ת××ת ת××××",className:"flex-1 h-11 rounded-xl border border-slate-200 bg-white px-3.5 text-sm"}),e.jsxs("button",{type:"button",onClick:()=>u(),disabled:o||!l.trim(),className:"h-11 px-4 rounded-xl bg-slate-900 text-white font-bold text-sm inline-flex items-center gap-2 disabled:opacity-50 flex-none",children:[e.jsx(Gs,{className:"w-4 h-4 flex-none"})," ש××××"]}),e.jsxs("button",{type:"button",onClick:()=>u({close:!0}),disabled:o||!l.trim(),title:"ש×××ת ×ת×××× ×ס××רת ××¤× ×××",className:"h-11 px-4 rounded-xl border border-slate-300 text-slate-700 font-bold text-sm inline-flex items-center gap-2 disabled:opacity-50 flex-none hover:bg-slate-50",children:[e.jsx(la,{className:"w-4 h-4 flex-none"})," ××¢× × ×ס××ר×"]})]})]})}function Ol({icon:t,label:s,onClick:n}){return e.jsxs("button",{type:"button",onClick:n,className:"h-9 px-3.5 rounded-full border border-slate-200 bg-white text-[13px] font-bold text-slate-600 inline-flex items-center gap-1.5 hover:border-slate-300 hover:bg-slate-50",children:[e.jsx(t,{className:"w-3.5 h-3.5 flex-none"})," ",s]})}function Ih({m:t}){const s=t.author_role==="manager";return e.jsxs("div",{className:`flex items-start gap-2.5 ${s?"flex-row-reverse":""}`,children:[e.jsx("span",{className:`w-8 h-8 rounded-full grid place-items-center flex-none ${s?"bg-emerald-50 text-emerald-600":"bg-slate-100 text-slate-400"}`,children:s?e.jsx(ra,{className:"w-4 h-4"}):e.jsx(ys,{className:"w-4 h-4"})}),e.jsxs("div",{className:`min-w-0 max-w-[80%] rounded-2xl px-3.5 py-2.5 ${s?"bg-emerald-50/70":"bg-blue-50/70"}`,children:[e.jsx("p",{className:"text-[14px] text-slate-800 whitespace-pre-wrap break-words",children:t.body}),t.attachment_url&&e.jsxs("a",{href:t.attachment_url,target:"_blank",rel:"noreferrer",className:"mt-1.5 inline-flex items-center gap-1.5 text-[12px] font-bold text-slate-600 hover:text-slate-900 underline",children:[e.jsx(ro,{className:"w-3.5 h-3.5 flex-none"})," ",t.attachment_name||"×§×××¥ ×צ×רף"]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-1",children:[t.author_name?`${t.author_name} · `:"",po(t.created_date)]})]})]})}const tl=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,qn=t=>Math.round(((Number(t)||0)+Number.EPSILON)*100)/100,Ec=t=>(Number(t==null?void 0:t.amount)||0)-(Number(t==null?void 0:t.discount_amount)||0)-(Number(t==null?void 0:t.credit_amount)||0),Fc=t=>(t==null?void 0:t.status)==="approved"||(t==null?void 0:t.status)==="issued",Yi=t=>(t==null?void 0:t.calculation_method)==="water_meter"||(t==null?void 0:t.billing_cycle)==="per_file",zh=["××× ×¨×ש××","××× ×©× ×","××× ×©××ש×","××× ×¨×××¢×","××× ×××ש×","××× ×©×ש×","ש×ת"];function Kh(t,s=new Date){const n=String(t||"").slice(0,10);if(!/^\d{4}-\d{2}-\d{2}$/.test(n))return"";const[a,l,r]=n.split("-").map(Number),o=new Date(a,l-1,r),p=Math.round((Date.UTC(a,l-1,r)-Date.UTC(s.getFullYear(),s.getMonth(),s.getDate()))/864e5);return p===0?"××××":p===1?"××ר":zh[o.getDay()]}const Wh=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"],fn=t=>{const s=Number(String(t||"").slice(5,7));return s>=1&&s<=12?Wh[s-1]:""},Uh=t=>{const s=String(t||"").slice(0,7);return/^\d{4}-\d{2}$/.test(s)?`${fn(`${s}-01`)} ${s.slice(0,4)}`:""},Hh=(t,s)=>tl(new Date(t.getFullYear(),t.getMonth()+s+1,0));function Yh({charges:t=[],types:s=[],plan:n=null,today:a=new Date,months:l=2}={}){const r=tl(a),o=Hh(a,Math.max(1,l)-1),p=new Map(s.map(c=>[c.id,c])),u=new Map;for(const c of t){if(!Fc(c))continue;const m=String(c.due_date||"").slice(0,10);if(!m||m<r||m>o)continue;const h=`${m}|${c.charge_type_id||""}`,b=p.get(c.charge_type_id),f=u.get(h)||{date:m,month:m.slice(0,7),typeId:c.charge_type_id||"",name:(b==null?void 0:b.name)||"××××",calc:(b==null?void 0:b.calculation_method)||"",auto:ze(b)==="auto",byConsumption:Yi(b),count:0,amount:0,planned:!1,awaitingApproval:!1};f.count+=1,f.amount=qn(f.amount+Ec(c)),u.set(h,f)}const d=new Set([...u.values()].map(c=>`${c.month}|${c.typeId}`));for(const c of(n==null?void 0:n.types)||[]){if(!(c.enabled||c.activation_mode))continue;const m=String(c.next_due||"").slice(0,10);if(!/^\d{4}-\d{2}-\d{2}$/.test(m)||m<r||m>o)continue;const h=m.slice(0,7);if(d.has(`${h}|${c.id}`))continue;const b=p.get(c.id);u.set(`${m}|${c.id}|plan`,{date:m,month:h,typeId:c.id,name:c.name||(b==null?void 0:b.name)||"××××",calc:c.calculation_method||(b==null?void 0:b.calculation_method)||"",auto:c.enabled||c.activation_mode==="auto",byConsumption:Yi(b||c),count:Number(c.accounts)||0,amount:qn(c.forecast),planned:!0,awaitingApproval:!!c.awaiting_approval})}return[...u.values()].sort((c,m)=>c.date.localeCompare(m.date)||String(c.name).localeCompare(String(m.n
60ame),"he"))}function Vh(t=[]){return{amount:qn(t.filter(s=>!s.byConsumption).reduce((s,n)=>s+n.amount,0)),hasConsumption:t.some(s=>s.byConsumption)}}const Gh={overdue:{l:"×¢×ר ××××¢×",tone:"red",action:"×ש××ת ×פק×"},data:{l:"× ×רש ××פ××",tone:"red",action:"×ש××ת × ×ª×× ××"},file:{l:"×× ××ש××",tone:"amber",action:"×ש××ת ×××¢×× ×"},approval:{l:"××ת×× ×××ש×ר",tone:"amber",action:"××ש×ר ×פק×"}},Vi={demand:"×ר×שת תש×××",charge:"×××× ××ס×× ×ª×©×××"};function Xh({plan:t=null,today:s=new Date}={}){const n=tl(s),a=[];for(const l of(t==null?void 0:t.types)||[]){if(!l.requires_manager_approval||!(l.enabled||l.activation_mode))continue;const r=l.approvals||{},o=r.demand?r.charge?null:"charge":"demand";if(!o)continue;const p=String((o==="demand"?l.next_issue:l.next_due)||"").slice(0,10);a.push({kind:"approval",typeId:l.id,name:l.name||"××××",stage:o,period:(t==null?void 0:t.period)||"",date:/^\d{4}-\d{2}-\d{2}$/.test(p)?p:n,count:Number(l.accounts)||0,amount:Number(l.forecast)||0,next_issue:String(l.next_issue||"").slice(0,10),next_due:String(l.next_due||"").slice(0,10),note:`×פקת ${Vi[o]}`,title:`××ש×ר ${Vi[o]} · ${l.name||""}${t!=null&&t.period?` · ××××ר ${Uh(t.period)}`:""}`})}return a}const Zh=new Set(["draft","pending","partially_approved"]);function Qh({charges:t=[],types:s=[],batches:n=[],meters:a=[],plan:l=null,today:r=new Date}={}){const o=tl(r),p=new Map(s.map(m=>[m.id,m])),u=Xh({plan:l,today:r}),d=new Map;for(const m of t){if(!Fc(m))continue;const h=String(m.due_date||"").slice(0,10);if(!h||h>=o)continue;const b=m.charge_type_id||"",f=p.get(b),x=d.get(b)||{kind:"overdue",typeId:b,name:(f==null?void 0:f.name)||"××××",date:h,count:0,amount:0};h<x.date&&(x.date=h),x.count+=1,x.amount=qn(x.amount+Ec(m)),d.set(b,x)}for(const m of d.values())u.push({...m,note:m.count===1?"×ש××× ××× ×©×××¢× ×תש××× ×©×× ×¢×ר":`${m.count} ×ש××× ×ת ש×××¢× ×תש××× ×©××× ×¢×ר`});const c=a.filter(m=>(m.status||"active")!=="inactive"&&!(m.payer_account_id&&Number(m.souls)>0&&m.previous_reading!=null));if(c.length){const m=s.find(h=>h.calculation_method==="water_meter");u.push({kind:"data",typeId:(m==null?void 0:m.id)||"",name:(m==null?void 0:m.name)||"×××",date:o,count:c.length,amount:0,note:c.length===1?"×סר×× × ×ª×× ×× ×¢××ר ××× × ×××":`×סר×× × ×ª×× ×× ×¢××ר ${c.length} ××× ××`})}for(const m of n){if(!Zh.has(m==null?void 0:m.status))continue;const h=p.get(m.charge_type_id),b=Number(m.row_count)||0;u.push({kind:"file",typeId:m.charge_type_id||"",batchId:m.id,name:(h==null?void 0:h.name)||m.period_name||"×××× ××§×××¥",date:String(m.due_date||m.created_date||o).slice(0,10),count:b,amount:0,note:m.status==="partially_approved"?"××§×××¥ ××שר ×××§×ת â × ××ª×¨× ×©×ר×ת ×××פ××":`×§×××¥ ×©× ××¢× ×××¨× ××שר${b===1?" · ש××¨× ××ת":b?` · ${b} ש×ר×ת`:""}`})}return u.sort((m,h)=>String(m.date).localeCompare(String(h.date)))}const Jh={red:"bg-rose-600 text-white shadow-sm",emerald:"bg-emerald-600 text-white shadow-sm"},e0={red:"bg-rose-100 text-rose-700",emerald:"bg-emerald-100 text-emerald-700"},Gi={red:"bg-rose-50 text-rose-700 border-rose-200",amber:"bg-amber-50 text-amber-800 border-amber-200"};function Xi({tone:t,label:s,n,on:a,onClick:l}){return e.jsxs("button",{type:"button",onClick:l,"aria-pressed":a,className:`h-8 pr-3 pl-2 rounded-full text-[12.5px] font-bold inline-flex items-center gap-1.5 transition-colors 61 ${a?Jh[t]:"text-slate-500 hover:text-slate-800"}`,children:[s,e.jsx("span",{className:`min-w-[1.25rem] h-5 px-1 rounded-full text-[11px] font-black grid place-items-center tabular-nums 62 ${a?"bg-white/25 text-white":e0[t]}`,children:n})]})}function t0({date:t,today:s}){return e.jsxs("span",{className:"text-center",children:[e.jsx("span",{className:"block text-[19px] font-black text-slate-900 leading-none tabular-nums",children:Number(t.slice(8))}),e.jsx("span",{className:"block text-[10.5px] font-bold text-slate-400 mt-0.5 whitespace-nowrap",children:Kh(t,s)})]})}const Wt="text-[11px] font-bold text-slate-400",Zi="grid grid-cols-[3.4rem,1fr,5.5rem,7.5rem] gap-2 items-center",Qi="grid grid-cols-[3.4rem,1fr,5rem,8.5rem] gap-2 items-center";function s0({charges:t=[],types:s=[],batches:n=[],meters:a=[],plan:l=null,loading:r,onOpen:o,className:p=""}){const u=i.useMemo(()=>new Date,[]),d=i.useMemo(()=>Qh({charges:t,types:s,batches:n,meters:a,plan:l,today:u}),[t,s,n,a,l,u]),c=i.useMemo(()=>Yh({charges:t,types:s,plan:l,today:u}),[t,s,l,u]),m=i.useMemo(()=>Vh(c),[c]),[h,b]=i.useState("attention");i.useEffect(()=>{r||b(d.length?"attention":"upcoming")},[r,d.length]);const f=i.useMemo(()=>{const x=new Date(u.getFullYear(),u.getMonth()+2,0);return`${fn(`${x.getFullYear()}
62-${String(x.getMonth()+1).padStart(2,"0")}-01`)} ${x.getFullYear()}`},[u]);return e.jsxs("section",{className:`bg-white rounded-2xl border border-slate-200/80 shadow-sm flex flex-col overflow-hidden ${p}`,children:[e.jsxs("header",{className:"flex items-center gap-2 px-4 pt-4 pb-3",children:[e.jsx(vs,{className:"w-[18px] h-[18px] text-indigo-500 flex-none"}),e.jsx("h3",{className:"text-[15px] font-bold text-slate-800 flex-none",children:"×××× ××××××"}),e.jsxs("span",{className:"mr-auto flex items-center gap-0.5 p-0.5 rounded-full bg-slate-100/80",children:[e.jsx(Xi,{tone:"red",label:"× ×רש ×××פ××",n:d.length,on:h==="attention",onClick:()=>b("attention")}),e.jsx(Xi,{tone:"emerald",label:"×××××× ×§×¨××××",n:c.length,on:h==="upcoming",onClick:()=>b("upcoming")})]})]}),r?e.jsx("div",{className:"grid place-items-center py-16",children:e.jsx("div",{className:"w-7 h-7 border-4 border-slate-200 border-t-indigo-500 rounded-full animate-spin"})}):h==="attention"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mx-4 mb-2 rounded-lg bg-rose-50 border border-rose-100 px-3 py-1.5 text-[12px] font-bold text-rose-700 inline-flex items-center gap-1.5",children:[e.jsx(At,{className:"w-3.5 h-3.5 flex-none"}),"×× ×©×××¢×× ×¢×ר ××× ××ש××, ××× ×©××ת×× ×××ש×ר ×× ××"]}),e.jsx("div",{className:"px-4",children:e.jsxs("div",{className:`${Zi} pb-1.5 border-b border-slate-100`,children:[e.jsx("span",{className:`${Wt} text-center`,children:"ת×ר××"}),e.jsx("span",{className:Wt,children:"ס×× ××××× ×××תר××"}),e.jsx("span",{className:`${Wt} text-center`,children:"ס×××ס"}),e.jsx("span",{className:`${Wt} text-center`,children:"פע×××"})]})}),d.length===0?e.jsx(Ji,{children:"××× ×ר××¢ ×תר××ת. ×× ×× ×©×××¢×× ×¢×ר â ××פ×."}):e.jsx("ul",{className:"px-4 divide-y divide-slate-100 max-h-[21rem] overflow-y-auto",children:d.map((x,g)=>{const y=Gh[x.kind]||{};return e.jsxs("li",{className:`${Zi} py-2`,children:[e.jsxs("span",{className:"text-center",children:[e.jsx("span",{className:"block text-[15px] font-black text-slate-900 leading-none tabular-nums",children:Number(x.date.slice(8))}),e.jsx("span",{className:"block text-[10.5px] font-bold text-slate-400 mt-0.5 whitespace-nowrap",children:fn(x.date)})]}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[13px] font-bold text-slate-800 truncate",children:x.name}),e.jsxs("span",{className:`block text-[11.5px] text-slate-500 ${x.kind==="approval"?"leading-snug":"truncate"}`,title:x.title||x.note,children:[x.note,x.kind==="approval"&&x.count>0&&e.jsxs(e.Fragment,{children:[" · ",_e(x.count,"×ש××× ×××","×ש××× ×ת"),x.amount>0&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("span",{className:"font-bold tabular-nums",dir:"ltr",children:ve(x.amount)})]})]})]})]}),e.jsxs("span",{className:`text-[11px] font-bold px-2 py-0.5 rounded-full border whitespace-nowrap text-center inline-flex items-center justify-center gap-1 ${Gi[y.tone]||Gi.amber}`,children:[x.kind==="approval"&&e.jsx(bo,{className:"w-3 h-3 flex-none"}),y.l]}),x.kind==="approval"?e.jsxs("button",{type:"button",onClick:()=>o==null?void 0:o(x.kind,x),className:`h-8 px-3 rounded-lg bg-amber-500 text-white text-[12px] font-bold whitespace-nowrap 63 inline-flex items-center justify-center gap-1 hover:bg-amber-600 transition-colors`,children:[e.jsx(xt,{className:"w-3.5 h-3.5"}),y.action]}):e.jsxs("button",{type:"button",onClick:()=>o==null?void 0:o(x.kind,x),className:"text-[12px] font-bold text-slate-600 hover:text-indigo-700 whitespace-nowrap inline-flex items-center gap-0.5",children:[y.action,e.jsx(lt,{className:"w-3.5 h-3.5"})]})]},`${x.kind}${x.typeId}${x.batchId||""}${g}`)})}),e.jsxs("footer",{className:"mt-auto px-4 pt-3 pb-4",children:[d.length>0&&e.jsxs("p",{className:"rounded-xl bg-rose-600 text-white px-3.5 py-2.5 flex items-center gap-2",children:[e.jsx(At,{className:"w-4 h-4 flex-none"}),e.jsx("span",{className:"text-[13px] font-black",children:_e(d.length,"×××× ××× ××רש ××פ××","×××××× ××רש×× ××פ××")}),e.jsx("span",{className:"mr-auto text-[11.5px] font-bold opacity-90",children:"×ת××§×× ××¤× × ×××¤×§× ××××"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-2 text-center",children:"×××ר ×ש××ת ×××פ×× ××תר×× ×ª×סר ×××××××ת"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"mx-4 mb-2 text-[12px] font-bold text-slate-500",children:["×××××× ×§×¨×××× ×¢× ×¡××£ ",f]}),e.jsx("div",{className:"px-4",children:e.jsxs("div",{className:`${Qi} pb-1.5 border-b border-slate-100`,children:[e.jsx("span",{className:`${Wt} text-center`,children:"ת×ר××"}),e.jsx("span",{className:Wt,children:"ס×× ×××××"}),e.jsx("span",{className:`${Wt} text-center`,children:"×פק×"}),e.jsx("span",{className:`${Wt} text-center`,children:"פע×××"})]})}
63),c.length===0?e.jsxs(Ji,{children:["××× ×××××× ×××××× ×¢× ×¡××£ ",f,"."]}):e.jsx("ul",{className:"px-4 divide-y divide-slate-100 max-h-[21rem] overflow-y-auto",children:c.map((x,g)=>e.jsxs(he.Fragment,{children:[(g===0||c[g-1].month!==x.month)&&e.jsx("li",{className:"pt-2.5 pb-1 first:pt-0",children:e.jsxs("span",{className:"text-[11px] font-black text-slate-400 tracking-wide",children:[fn(x.date)," ",x.date.slice(0,4)]})}),e.jsxs("li",{className:`${Qi} py-2`,children:[e.jsx(t0,{date:x.date,today:u}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"block text-[13px] font-bold text-slate-800 truncate",children:[x.name,x.planned&&e.jsx("span",{className:"mr-1.5 align-middle text-[10px] font-bold px-1.5 py-0.5 rounded-full bg-slate-100 text-slate-500 border border-slate-200",children:"צפ×"}),x.awaitingApproval&&e.jsx("span",{className:"mr-1 align-middle text-[10px] font-bold px-1.5 py-0.5 rounded-full bg-amber-50 text-amber-700 border border-amber-200",children:"××ת×× ×××ש×ר"})]}),e.jsxs("span",{className:"block text-[11.5px] text-slate-500 truncate",children:[_e(x.count,"×ש××× ×××","×ש××× ×ת")," · ",x.byConsumption?e.jsx("span",{className:"font-bold text-teal-700",children:"××¤× ×¦×¨×××"}):e.jsx("span",{className:"font-bold tabular-nums",dir:"ltr",children:ve(x.amount)})]})]}),x.auto?e.jsxs("span",{className:"text-[11px] font-bold px-2 py-0.5 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-200 whitespace-nowrap inline-flex items-center gap-1",children:[e.jsx(Mt,{className:"w-3 h-3"})," ×××××××"]}):e.jsxs("span",{className:"text-[11px] font-bold px-2 py-0.5 rounded-full bg-slate-100 text-slate-500 border border-slate-200 whitespace-nowrap inline-flex items-center gap-1",children:[e.jsx(Cd,{className:"w-3 h-3"})," ××× ×"]}),e.jsx("button",{type:"button",onClick:()=>o==null?void 0:o(x.planned?"issue":"charges",x),title:`${x.name} · ${_e(x.count,"×ש××× ×××","×ש××× ×ת")}`,className:"h-8 px-3 rounded-lg text-[12px] font-bold whitespace-nowrap border border-indigo-200 text-indigo-700 hover:bg-indigo-50 transition-colors",children:x.planned?"××¦× ×פק×":"××¦× ××××××"})]})]},`${x.date}${x.typeId}${x.planned?"p":""}${g}`))}),e.jsxs("footer",{className:"mt-auto px-4 pt-3 pb-4",children:[c.length>0&&e.jsxs("p",{className:"rounded-xl bg-emerald-600 text-white px-3.5 py-2.5 flex items-center gap-2",children:[e.jsxs("span",{className:"text-[11.5px] font-bold opacity-90",children:["ס××´× ×¦×¤×× ×¢× ×¡××£ ",f]}),e.jsx("span",{className:"mr-auto text-[14px] font-black tabular-nums",dir:"ltr",children:ve(m.amount)}),m.hasConsumption&&e.jsx("span",{className:"text-[11px] font-bold opacity-90 whitespace-nowrap",children:"+ ××××× ×××"})]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-2 flex items-center justify-center gap-2",children:["××צ××× ×××××× ××××× ××¢× ×¡××£ ",f,e.jsxs("button",{type:"button",onClick:()=>o==null?void 0:o("all"),className:"font-bold text-indigo-600 hover:text-indigo-800 inline-flex items-center",children:["××× ×××××××",e.jsx(lt,{className:"w-3 h-3"})]})]})]})]})]})}const Ji=({children:t})=>e.jsx("p",{className:"px-4 py-10 text-center text-[12.5px] text-slate-400",children:t}),a0="https://app.sumit.co.il/users/login/",n0="https://app.upay.co.il/",eo=t=>window.open(t,"_blank","noopener,noreferrer"),to=[{key:"dashboard",label:"×ש××ר×",icon:Uc,tile:!1},{key:"accounts",label:"×ש××× ×ת ×ש××××",icon:De,tone:"indigo"},{key:"kolbo",label:"××¢×× ×ª ×§×××¥ ×××××",icon:da,tone:"purple",tile:!1},{key:"water",label:"××¢×× ×ª ×§×××¥ צר××ת ×××",icon:Ke,tone:"sky",tile:!1},{key:"paymentPages",label:"×¢×××× ×ª×©×××",icon:Zt,tone:"purple"},{key:"chargeTypes",label:"ס××× ××××××",icon:Xe,tone:"amber"},{key:"reports",label:"××××× ××××ת",icon:ks,tone:"violet"},{key:"documents",label:"× ×××× ×ס××××",tileLabel:"××××× ×ס××××",icon:cu,tone:"rose",hint:"×קר××",note:"××××× ××ס×××× ×פ××§ ××ת×××, ××ש×ר×× ××ס×××× ×ת×××× ×ת×× × ×ª×× × ××ש××× ×ת â ×ת×× ××ת ×©× ××§×××× ×××× ×××§××× ×××ש. ××××ר ××× ×××."},{key:"requests",label:"×¤× ××ת ת×ש×××",icon:cr,tone:"slate"},{key:"settings",label:"×××ר×ת ×ער×ת",icon:zn,tone:"blue"},{key:"monthly",label:"×פקת ××××××",icon:Be,tone:"emerald"},{key:"plans",label:"ת××× ××ת ××××",icon:Be,tile:!1},{key:"onetime",label:"×××××× ××־פע××××",icon:Ns,tile:!1},{key:"statements",label:"×ס××× ×ש×××",icon:nt,tile:!1},{key:"payments",label:"תש××××× ×תק×××××",icon:es,tile:!1},{key:"approvals",label:"×ר×××ת ×××ש×ר××",icon:Hc,tile:!1}];function Mb(){return e.jsx(Yc,{moduleKey:"settings",children:e.jsx(l0,{})})}function l0(){const{id:t}=Wc(),[s,n]=ia(),a=to.some(w=>w.key===s.get("tab"))?s.get("tab"):"dashboard",l=(w,_=null)=>n(w==="dashboard"?{}:{tab:w,..._||{}},{replace:!0}),[r,o]=i.useState(0),[p,u]=i.useState(!1),[d,c]=i.useState(!1),[m,h]=i.useState(null),[b,f]=i.useState(!1),[x,g]=i.useState(null),[y,$]=i.useState(null),[O,A]=i.useState(0),[S,P]=i.useState({charges:[],types:[],batches:[],meters:[],plan:null,loading:!0});i.useEffect(()=>{if(!t||a!=="dashboard")return;let w=!0;return P(_=>({..._,loading:!0})),Promise.all([D.entities.BillingRequest.filter({community_id:t,manager_unread:!0}).catch(()=>[]),D.entities.Charge.filterAllFields({kibbutz_id:t},["id","charge_type_id","due_date","amount","discount_amount","credit_amount","status"]).catch(()=>[]),D.entities.ChargeType.filterAllFields({kibbutz_id:t},["id","name","due_day","issue_days_before","auto_billing_enabled","calculation_method","billing_cycle","activation_mode","requires_manager_approval"],"order").catch(()=>[]),D.entities.WaterImportBatch.filterAllFields({kibbutz_id:t},["id","charge_type_id","period_name","due_date","status","row_count","bill_count","total_amount","created_date"]).catch(()=>[]),D.entities.WaterMeter.filterAllFields({kibbutz_id:t},["id","status","payer_account_id","souls","previous_reading"]).catch(()=>[]),D.functions.invoke("recurringBilling",{action:"status",community_id:t}).then(_=>
63(_==null?void 0:_.data)||null).catch(()=>null)]).then(([_,T,M,B,R,j])=>{w&&(A((_||[]).length),P({charges:zt(T,M),types:M||[],batches:B||[],meters:R||[],plan:j||null,loading:!1}))}).catch(()=>{w&&P(_=>({..._,loading:!1}))}),()=>{w=!1}},[t,a,r]);const E=()=>{o(w=>w+1),W.success("×× ×ª×× ×× × ×§×¨××× ×××ש")},k=to.find(w=>w.key===a),C=a==="dashboard";return e.jsx(Iu,{children:w=>{var _;return e.jsxs("div",{dir:"rtl",children:[e.jsxs("div",{className:"flex items-center flex-wrap mb-6",children:[e.jsxs("div",{className:`inline-flex items-center gap-3 bg-white border border-slate-200 rounded-full shadow-sm ${C?"px-5 py-2.5":"pr-5 pl-1 py-1"}`,children:[e.jsx("h1",{className:"text-[19px] font-bold text-slate-900 whitespace-nowrap leading-none",children:"×ש××× ×ת ×תש×××××"}),C?null:e.jsxs("span",{className:"inline-flex items-center gap-2 h-10 pr-4 pl-2 rounded-full bg-teal-700 text-white text-[15px] font-bold whitespace-nowrap",children:[(k==null?void 0:k.label)||"",e.jsx("button",{type:"button",onClick:()=>l("dashboard"),"aria-label":`ס××רת ${(k==null?void 0:k.label)||""}`,title:"×××¨× ××¢××× ××××××",className:"w-6 h-6 rounded-full grid place-items-center text-white/80 hover:bg-white/20 hover:text-white transition-colors",children:e.jsx($e,{className:"w-4 h-4"})})]})]}),w&&e.jsx("span",{className:"mr-auto flex-none",children:w})]}),C&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-5 gap-4 items-start",children:[e.jsx("div",{className:"xl:col-span-3",children:e.jsx(Wu,{columns:4,compact:!0,items:[{key:"accounts",label:"×ש××× ×ת ×ש××××",icon:De,tone:"indigo",onClick:()=>l("accounts")},{key:"monthly",label:"×פקת ××××××",icon:Be,tone:"emerald",onClick:()=>l("monthly")},{key:"reports",label:"××××× ××××ת",icon:ks,tone:"violet",onClick:()=>l("reports")},{key:"requests",label:"×¤× ××ת ת×ש×××",icon:cr,tone:"slate",badge:O>0?O:void 0,onClick:()=>l("requests")},{key:"paymentPages",label:"×¢×××× ×ª×©×××",icon:Zt,tone:"purple",onClick:()=>l("paymentPages")},{key:"terminal",label:"ס××קת ×שר××",icon:Oe,tone:"rose",onClick:()=>c(!0)},{key:"chargeTypes",label:"ס××× ××××××",icon:Xe,tone:"amber",onClick:()=>l("chargeTypes")},{key:"files",label:"××¢×× ×ª ×§×צ××",icon:La,tone:"sky",onClick:()=>u(!0)},{key:"sumit",label:"×ש××× ×¡××××",icon:kr,tone:"rose",onClick:()=>eo(a0)},{key:"upay",label:"×ש××× UPAY",icon:kr,tone:"rose",onClick:()=>eo(n0)},{key:"settings",label:"×××ר×ת ×ער×ת",icon:zn,tone:"blue",onClick:()=>l("settings")},{key:"refresh",label:"×¨×¢× ×× × ×ª×× ××",icon:br,tone:"emerald",onClick:E}]})}),e.jsx(s0,{className:"xl:col-span-2",charges:S.charges,types:S.types,batches:S.batches,meters:S.meters,plan:S.plan,loading:S.loading,onOpen:(T,M)=>{if(T==="approval"){h(M);return}if(T==="issue"){g(null),$(null),l("monthly");return}if(T==="file"){g(null),$(null),l("water");return}g(T==="data"?"water":"charges"),$(T==="charges"&&(M!=null&&M.date)?{type:M.typeId||"",due:M.date}:null),l("reports")}})]}),p&&e.jsx(i0,{onPick:T=>{u(!1),l(T)},onClose:()=>u(!1)}),d&&e.jsx(Hu,{kibbutzId:t,onClose:()=>c(!1),onDone:E}),m&&e.jsx(tc,{row:{name:m.name,accounts:m.count,forecast:m.amount,next_issue:m.next_issue,next_due:m.next_due,date:m.date},stage:m.stage,period:m.period||((_=S.plan)==null?void 0:_.period),busy:b,onClose:()=>h(null),onConfirm:async T=>{var M;f(!0);try{const B=await D.functions.invoke("recurringBilling",{action:"approve_cycle",community_id:t,charge_type_id:m.typeId,stage:m.stage,period:m.period||((M=S.plan)==null?void 0:M.period),note:T});W.success(hc(B==null?void 0:B.data)),h(null),o(R=>R+1)}catch{W.error("×××ש×ר × ×ש×")}finally{f(!1)}}})]}),C?null:a==="accounts"?e.jsx(tm,{kibbutzId:t},r):a==="paymentPages"?e.jsx(Eh,{kibbutzId:t},r):a==="chargeTypes"?e.jsx(xm,{kibbutzId:t,onManage:()=>l("monthly")},r):a==="monthly"?e.jsx(bc,{kibbutzId:t},r):a==="plans"?e.jsx(gi,{kibbutzId:t,mode:"recurring"},r):a==="onetime"?e.jsx(gi,{kibbutzId:t,mode:"onetime"},r):a==="statements"?e.jsx(Sx,{kibbutzId:t},r):a==="payments"?e.jsx(Cx,{kibbutzId:t},r):a==="approvals"?e.jsx(Ax,{kibbutzId:t},r):a==="reports"?e.jsx(kh,{kibbutzId:t,initial:x,initialFilter:y},`${r}-${x||""}-${(y==null?void 0:y.type)||""}-${(y==null?void 0:y.due)||""}`):a==="settings"?e.jsx(Sh,{kibbutzId:t},r):a==="kolbo"?e.jsx(Ch,{kibbutzId:t},r):a==="water"?e.jsx(mx,{kibbutzId:t},r):a==="requests"?e.jsx(Bh,{kibbutzId:t},r):e.jsx(r0,{section:k})]})}})}function r0({section:t}){const s=(t==null?void 0:t.icon)||io;return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-12 text-center",children:[e.jsx("div",{className:"w-14 h-14 roun
63ded-2xl bg-indigo-50 flex items-center justify-center mx-auto mb-3",children:e.jsx(s,{className:"w-7 h-7 text-indigo-500"})}),e.jsx("h3",{className:"text-base font-semibold mb-1",children:t==null?void 0:t.label}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-md mx-auto",children:(t==null?void 0:t.note)||"×××ר ×× ××× ××× ××ת××סף ×ש×× ××× ×©× ××××× ×××××××. תשת×ת ×× ×ª×× ×× ××ר ×××× ×."}),e.jsxs("button",{disabled:!0,className:"mt-4 inline-flex items-center gap-1.5 h-9 px-4 rounded-full bg-slate-100 text-slate-400 text-sm cursor-not-allowed",children:[e.jsx(We,{className:"w-4 h-4"})," ×קר××"]})]})}function i0({onPick:t,onClose:s}){const n=[{key:"kolbo",label:"××¢×× ×ª ×§×××¥ ×××××",hint:"×§×××¥ ×ר××ש×ת ×××××××, ××¤× ××¡×¤×¨× ×ª×§×¦××",icon:da,tone:"bg-purple-50 text-purple-600"},{key:"water",label:"××¢×× ×ª ×§×××¥ צר××ת ×××",hint:"קר×××ת ×××× ×× ××ת××××, ××¤× ××¡×¤×¨× ××× ×",icon:Ke,tone:"bg-sky-50 text-sky-600"}];return e.jsx("div",{className:"fixed inset-0 z-50 bg-slate-900/50 backdrop-blur-sm flex items-center justify-center p-4",onClick:s,dir:"rtl",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-lg p-5",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-black text-slate-900",children:"××¢×× ×ª ×§×צ××"}),e.jsx("button",{onClick:s,"aria-label":"ס××ר×",className:"w-9 h-9 rounded-full border border-slate-200 grid place-items-center text-slate-400 hover:bg-slate-50",children:e.jsx($e,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"space-y-2.5",children:n.map(a=>{const l=a.icon;return e.jsxs("button",{type:"button",onClick:()=>t(a.key),className:"w-full flex items-center gap-3.5 p-3.5 rounded-xl border border-slate-200 text-right hover:border-slate-300 hover:bg-slate-50 transition-all",children:[e.jsx("span",{className:`w-12 h-12 rounded-xl grid place-items-center flex-none ${a.tone}`,children:e.jsx(l,{className:"w-6 h-6"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-[15px] font-bold text-slate-800",children:a.label}),e.jsx("span",{className:"block text-[12px] text-slate-400 mt-0.5",children:a.hint})]})]},a.key)})})]})})}export{Mb 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.