1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ResidentsDashboard-Cer-G_Uk.js","assets/index-BH8Hq4fF.js","assets/index-AOxdnY9t.css","assets/GroupIconPicker-CajbHf9M.js","assets/siren-DUj7NgPZ.js","assets/stethoscope-CLBnbMpG.js","assets/sparkles-DYMjDKmN.js","assets/music-DKTtf7a1.js","assets/palette-CIgIe0F7.js","assets/graduation-cap-DnGVwVvF.js","assets/baby-Cs7Gtrey.js","assets/trophy-ouGVads6.js","assets/dumbbell-B6wytY5J.js","assets/coffee-QVdpUZKt.js","assets/truck-Btvrvfzs.js","assets/leaf-DJuap4o0.js","assets/sun-DO86yNCK.js","assets/residentGroupUtils-CFDJNblj.js","assets/softDelete-X2GBluex.js","assets/settings-2-CQkCCTmF.js","assets/sliders-horizontal-D7cGhbbA.js","assets/filter-BmqtgqMS.js","assets/KibbutzModuleGuard-BrSTzYkw.js","assets/refresh-cw-kjmzcQOe.js","assets/FilterPanel-C7WMOZ6A.js","assets/checkbox-BVYb58d2.js","assets/index-CikwpBsl.js","assets/columns-3-CwJYeXD2.js","assets/check-check-DLN-xcGC.js","assets/square-CAXqjE6a.js","assets/PageTitleMenu-CMXtRh6s.js","assets/useActionVisibility-oACH4aDh.js","assets/residentsMenu-DslBuIzo.js","assets/arrow-down-up-BP6AOQMS.js","assets/ManagerDialog-iFzxbOnI.js","assets/residentDemographics-DVG8IzKj.js","assets/SearchInput-CAHkvato.js","assets/residentFieldDefaults-DHDtzFDF.js","assets/bookmark-Cffis33a.js","assets/ellipsis-vertical-DoXvhv7J.js","assets/pencil-DlA_FTEn.js","assets/user-round-search-HjRLW1-T.js","assets/merge-cxZi_hXL.js","assets/eye-off-B4MzD2pP.js","assets/history-BGeSmqy2.js","assets/chevron-left-DaNP-hnR.js","assets/ResidentsTable-hwNjE91v.js","assets/input-RnZK1Sdh.js","assets/select-D1fi8zWO.js","assets/chevron-up-Nk0mcmku.js","assets/ContactIcons-DsYCwA1M.js","assets/popover-B7t_DJYN.js","assets/phone-call-BXoHXz4O.js","assets/ban-BN2sGUaC.js","assets/chevrons-up-down-CUcS79e_.js","assets/ResidentForm-BDhM26Ze.js","assets/label-BHWfbzXI.js","assets/textarea-C9Nd53i2.js","assets/switch-Sj01sJJm.js","assets/residentDynamicFields-B5kg_GhR.js","assets/file-check-2-UvL3Kzdg.js","assets/upload-DtbdHLAK.js","assets/residentFieldRules-DMS0Z1No.js","assets/AdvancedFilters-bKGjVvDI.js","assets/ImportHistory-DdwosSiw.js","assets/BulkActionBar-DwEd6OwS.js","assets/square-check-big-BrCHknOR.js","assets/user-round-plus-Z6rfEePC.js","assets/ManageViewsDialog-VkqW2mJb.js","assets/FormSection-8_EQ6Rzg.js","assets/formStyles-CzLsWpb8.js","assets/list-plus-mwazpKH4.js","assets/AddToGroupDialog-cq6Je-MU.js","assets/folder-plus-CpLzaPup.js","assets/DashboardCustomizer-DJPGosVq.js","assets/FamilyAssignmentDialog-CR05kTll.js","assets/FamilyManageDialog-DtRbtaEF.js","assets/familyLink-CwClu8eB.js","assets/crown-l_DHIXI5.js","assets/arrow-left-right-CFQjRNnL.js","assets/residentExcelExport-Cy2UnxIG.js"])))=>i.map(i=>d[i]); 2import{j as s,aP as Ds,cg as Ts,c4 as _t,cb as z,ac as $s,t as Ls,u as zs,r,d as g,ch as Ge,ci as Vs,cj as Ps,ck as Os,Z as Ue,x as zt,N as Gs,O as Us,V as Bs,X as wt,T as Ks,aH as Hs,m as qs,n as Js,o as Ys,p as Qs,a9 as Ws,c1 as Xs,aC as Vt,z as j,cl as Zs,aT as R}from"./index-BH8Hq4fF.js";import{N as jt}from"./softDelete-X2GBluex.js";import{K as kt}from"./KibbutzModuleGuard-BrSTzYkw.js";import{F as en}from"./FilterPanel-C7WMOZ6A.js";import{C as tn}from"./checkbox-BVYb58d2.js";import{C as sn}from"./columns-3-CwJYeXD2.js";import{C as nn}from"./check-check-DLN-xcGC.js";import{S as rn}from"./square-CAXqjE6a.js";import{P as vt}from"./PageTitleMenu-CMXtRh6s.js";import{g as Ct}from"./residentsMenu-DslBuIzo.js";import{M as ln}from"./ManagerDialog-iFzxbOnI.js";import{g as Pt,a as an}from"./residentGroupUtils-CFDJNblj.js";import{i as Ot,r as Ke,a as on,b as dn}from"./residentDemographics-DVG8IzKj.js";import{S as cn}from"./SearchInput-CAHkvato.js";import{D as un,a as mn}from"./residentFieldDefaults-DHDtzFDF.js";import{S as St}from"./sliders-horizontal-D7cGhbbA.js";import{B as Nt}from"./bookmark-Cffis33a.js";import{E as fn}from"./ellipsis-vertical-DoXvhv7J.js";import{P as hn}from"./pencil-DlA_FTEn.js";import{U as bn}from"./user-round-search-HjRLW1-T.js";import{M as gn}from"./merge-cxZi_hXL.js";import{E as Mt}from"./eye-off-B4MzD2pP.js";import{H as pn}from"./history-BGeSmqy2.js";import{C as xn}from"./chevron-left-DaNP-hnR.js";const Rt=[{key:"first_name",label:"×©× ×¤×¨××"},{key:"last_name",label:"×©× ×שפ××"},{key:"family_role",label:"תפק×× ××שפ××"},{key:"phone",label:"××פ××"},{key:"email",label:"××××××"},{key:"age",label:"×××"},{key:"gender",label:"×××ר"},{key:"street",label:"ר×××"},{key:"house_number",label:"×ספר ××ת"},{key:"neighborhood",label:"ש××× ×"},{key:"national_id",label:"תע××ת ×××ת"},{key:"budget",label:"תקצ××"},{key:"status",label:"ס×××ס"}],Ft=["first_name","last_name","family_role","phone","email","age","gender","status"],Gt={residents:Rt,all:Rt,children:[{key:"last_name",label:"×©× ×שפ××"},{key:"first_name",label:"×©× ×¤×¨××"},{key:"age",label:"×××"},{key:"gender",label:"×××ר"},{key:"street",label:"ר×××"},{key:"house_number",label:"×ספר ××ת"},{key:"neighborhood",label:"ש××× ×"},{key:"parents",label:"×××¨× ××××"},{key:"status",label:"ס×××ס"}],families:[{key:"name",label:"×©× ××שפ××"},{key:"head_first_name",label:"ר×ש ××שפ××"},{key:"member_count",label:"×ספר × ×¤×©×ת"},{key:"street",label:"ר×××"},{key:"house_number",label:"×ספר ××ת"},{key:"neighborhood",label:"ש××× ×"},{key:"status",label:"ס×××ס"}]},At={residents:Ft,all:Ft,children:["last_name","first_name","age","gender","street","house_number","neighborhood","parents","status"],families:["name","head_first_name","member_count","street","house_number","neighborhood","status"]};function Ut(t){return[...At[t]||At.residents]}function xe(t){try{const i=localStorage.getItem(`residents_columns_v2_${t}`);if(i)return JSON.parse(i)}catch{}return Ut(t)}function yn(t,i){try{localStorage.setItem(`residents_columns_v2_${t}`,JSON.stringify(i))}catch{}}function Be({icon:t,iconColor:i="text-slate-400",onClick:c,children:d}){return s.jsxs("button",{onClick:c,className:"inline-flex items-center gap-1.5 h-8 px-3 rounded-full bg-white border border-slate-200 shadow-sm transition-all hover:shadow-md hover:border-slate-300 text-xs font-medium text-slate-600 cursor-pointer whitespace-nowrap",children:[t&&s.jsx(t,{className:`w-3.5 h-3.5 ${i}`}),d]})}function _n({mode:t,visibleColumns:i,onChange:c,onClose:d,customFields:o=[]}){const l=Gt[t]||[],u=o.map(k=>
2({key:`custom:${k.field_key}`,label:k.display_name})),v=[...l,...u],h=k=>{if(i.includes(k))c(i.filter(F=>F!==k));else{const re=v.map(V=>V.key).filter(V=>i.includes(V)||V===k);c(re)}},_=()=>c(Ut(t)),C=()=>c(v.map(k=>k.key)),p=()=>c([]),S=k=>{const F=i.includes(k.key);return s.jsxs("label",{className:`flex items-center gap-2.5 cursor-pointer p-2.5 rounded-xl border transition-all select-none ${F?"border-primary/30 bg-primary/5":"border-border bg-white hover:border-slate-300 hover:bg-accent/40"}`,children:[s.jsx(tn,{checked:F,onCheckedChange:()=>h(k.key),className:F?"border-primary":""}),s.jsx("span",{className:`text-sm transition-colors ${F?"font-semibold text-foreground":"text-foreground"}`,children:k.label})]},k.key)};return s.jsxs(en,{title:"×××רת ×¢××××ת ×תצ×××",icon:sn,accent:"violet",onClose:d,actions:s.jsxs(s.Fragment,{children:[s.jsx(Be,{icon:nn,iconColor:"text-emerald-500",onClick:C,children:"××ר ×××"}),s.jsx(Be,{icon:rn,iconColor:"text-slate-400",onClick:p,children:"× ×§× ×××"}),s.jsx(Be,{icon:Ds,iconColor:"text-blue-500",onClick:_,children:"×ר×רת ××××"})]}),children:[s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-2",children:l.map(S)}),u.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-xs font-semibold text-muted-foreground mt-4 mb-2",children:"ש××ת ××ת××××"}),s.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-2",children:u.map(S)})]})]})}const Bt=t=>`resident_views_${t||"default"}`;function wn(t){try{const i=localStorage.getItem(Bt(t)),c=i?JSON.parse(i):[];return Array.isArray(c)?c:[]}catch{return[]}}function jn(t,i){try{localStorage.setItem(Bt(t),JSON.stringify(i||[]))}catch{}}function kn(){return`v_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function _e(t){return t?Ot(t):!1}function vn(t,i){const c=Array.isArray(t)?t:[];return i==="all"?c:i==="children"?c.filter(_e):c.filter(d=>!_e(d))}function He(t){return!(!t||t.is_deleted||Ts(t))}function we(t,i){const c=(Array.isArray(t)?t:[]).filter(He);return i==="active"?c.filter(_t):i==="inactive"?c.filter(d=>!_t(d)):c}const It={all:{mode:"all",statusView:"all"},residents:{mode:"residents",statusView:"active"},children:{mode:"children",statusView:"active"},families:{mode:"families",statusView:"active"},shelf:{mode:"all",statusView:"active"}},Et={mode:"all",statusView:"active"};function je(t){return It[t]||It.residents}const Kt=[{key:"all",label:"ס××´× ×ª×ש×××",icon:"Users",bg:"bg-blue-50",iconColor:"text-blue-600",countColor:"text-blue-700",mode:"all",filter:null},{key:"families",label:"×שפ××ת",icon:"UsersRound",bg:"bg-indigo-50",iconColor:"text-indigo-600",countColor:"text-indigo-700",mode:"families",filter:{type:"families"}},{key:"children",label:"××××× (×¢× ××× 18)",icon:"Baby",bg:"bg-cyan-50",iconColor:"text-cyan-600",countColor:"text-cyan-700",mode:"children",filter:{type:"age_range",max:17}},{key:"seniors",label:"×××× ×ש××ש×",icon:"Heart",bg:"bg-violet-50",iconColor:"text-violet-600",countColor:"text-violet-700",mode:"residents",filter:{type:"age_range",min:65}},{key:"men",label:"××ר××",icon:"User",bg:"bg-sky-50",iconColor:"text-sky-600",countColor:"text-sky-700",mode:"residents",filter:{field:"gender",value:"male"}},{key:"women",label:"× ×©××",icon:"User",bg:"bg-pink-50",iconColor:"text-pink-600",countColor:"text-pink-700",mode:"residents",filter:{field:"gender",value:"female"}},{key:"birthday_month",label:"××××× ××××ש",icon:"Cake",bg:"bg-amber-50",iconColor:"text-amber-600",countColor:"text-amber-700",mode:"residents",filter:{type:"birthday_month"}}],qe=Object.fromEntries(Kt.map(t=>[t.key,t])),ke=Kt.map(t=>t.key);function Cn(t,i){const c=new Date().getMonth(),d=(t||[]).filter(He),o=we(d,je("residents").statusView),l=o.filter(u=>!_e(u));return{all:we(d,je("all").statusView).length,families:i,children:o.filter(Ot).length,seniors:l.filter(on).length,men:l.filter(u=>u.gender==="male").length,women:l.filter(u=>u.gender==="female").length,birthday_month:l.filter(u=>u.birth_date&&new Date(u.birth_date).getMonth()===c).length}}const U=t=>t!=null&&String(t).trim()!=="";function Ht(t,i,{groupMembers:c=[],allResidents:d=[]}={}){if(!i)return t;let o=t;if(i.registration_status&&(o=o.filter(l=>l.registration_status===i.registration_status)),i.family_role&&(o=o.filter(l=>l.family_role===i.family_role)),i.gender&&(o=o.filter(l=>l.gender===i.gender)),i.street&&(o=o.filter(l=>l.street===i.street)),i.neighborhood&&(o=o.filter(l=>l.neighborhood===i.neighborhood)),i.ageMin!==null&&i.ageMin!==void 0&&(o=o.filter(l=>{const u=Ke(l);return u!==null&&u>=i.ageMin})),i.ageMax!==null&&i.ageMax!==void 0&&(o=o.filter(l=>{const u=Ke(l);return u!==null&&u<=i.ageMax})),i.national_id_presence==="has"&&(o=o.filter(l=>U(l.national_id))),i.national_id_presence==="missing"&&(o=o.filter(l=>!U(l.national_id))),i.budget_presence==="has"&&(o=o.filter(l=>U(l.budget))),i.budget_presence==="missing"&&(o=o.filter(l=>!U(l.budget))),i.phone_presence==="has"&&(o=o.filter(l=>U(l.phone))),i.phone_presence==="missing"&&(o=o.filter(l=>!U(l.phone))),i.email_presence==="has"&&(o=o.filter(l=>U(l.email))),i.email_presence==="missing"&&(o=o.filter(l=>!U(l.email))),Array.isArray(i.groupIds)&&i.groupIds.length){const l=new Set(Pt(i.groupIds,c,d).map(u=>u.id));o=o.filter(u=>l.has(u.id))}return o}function wi(t){return t?!Object.entries(t).some(([,i])=>Array.isArray(i)?i.length>0:i!=null&&i!==""):!0}function Sn(t){const i={version:1,vitals:[...ke],cards:[]};if(!t||typeof t!="object")return i;const c=Array.isArray(t.vitals)?t.vitals.filter(o=>qe[o]).filter((o,l,u)=>u.indexOf(o)===l):[...ke],d=Array.isArray(t.cards)?t.cards.map(Nn).filter(
2Boolean):[];return{version:1,vitals:c,cards:d}}function Nn(t){if(!t||typeof t!="object")return null;const i=t.id||Mn();return t.kind==="group"&&t.groupId?{id:i,kind:"group",groupId:t.groupId}:t.kind==="stat"&&qe[t.statKey]?{id:i,kind:"stat",statKey:t.statKey}:t.kind==="filter"&&t.filter&&typeof t.filter=="object"?{id:i,kind:"filter",label:(t.label||"ס×× ×× ××ת××").toString().slice(0,40),color:t.color||"blue",icon:t.icon||"Filter",filter:t.filter}:null}function ji(t){const i=Sn(t);return i.cards.length>0||i.vitals.length!==ke.length?!0:i.vitals.some((c,d)=>c!==ke[d])}function Mn(){return`c_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`}function ki(t,i){const{residents:c,familiesCount:d,groups:o,groupMembers:l,groupMemberCounts:u,statCounts:v}=i;if(t.kind==="stat"){const h=qe[t.statKey];return h?{id:t.id,kind:"stat",statKey:t.statKey,label:h.label,icon:h.icon,color:null,bg:h.bg,iconColor:h.iconColor,countColor:h.countColor,count:(v||Cn(c,d))[t.statKey],intent:{type:"stat",filter:h.filter,mode:h.mode}}:null}if(t.kind==="group"){const h=(o||[]).find(C=>C.id===t.groupId);if(!h)return null;const _=u instanceof Map?u.get(h.id)||0:Pt([h.id],l,c).length;return{id:t.id,kind:"group",groupId:h.id,label:h.title,icon:h.icon||"Users",color:h.color||"blue",count:_,intent:{type:"group",groupId:h.id}}}if(t.kind==="filter"){const h=Ht(c,t.filter,{groupMembers:l,allResidents:c}).length;return{id:t.id,kind:"filter",label:t.label,icon:t.icon||"Filter",color:t.color||"blue",count:h,intent:{type:"filter",filter:t.filter}}}return null}function Rn(t){return t.map(i=>({resident_id:i.id,full_name:z(i),phone:i.phone||"",email:i.email||""}))}function Fn(t,i){const c=new Map;let d=0,o=0;for(const v of t){const h=v.family_id;if(!h){d++;continue}const C=i.filter(p=>p.family_id===h).filter(p=>p.family_role==="head"||p.family_role==="spouse");if(C.length===0){d++;continue}for(const p of C){o++;const S=p.id||p.phone||p.email||z(p);c.has(S)||c.set(S,{resident_id:p.id,full_name:z(p),phone:p.phone||"",email:p.email||""})}}const l=Array.from(c.values()),u=o-l.length;return{parents:l,unresolvedCount:d,totalChildren:t.length,duplicatesRemoved:u}}function An(t,i){const c=new Map;for(const d of t){const l=i.filter(u=>u.family_id===d.id).filter(u=>u.family_role==="head"||u.family_role==="spouse");for(const u of l){const v=u.id||u.phone||u.email||z(u);c.has(v)||c.set(v,{resident_id:u.id,full_name:z(u),phone:u.phone||"",email:u.email||""})}}return Array.from(c.values())}function In(t){return(t||"").trim().replace(/\s+/g," ").toLowerCase()}function En(t){const i=String((t==null?void 0:t.street)??"").trim().replace(/[,Ø]+$/,"").replace(/\s+/g," ").toLowerCase(),c=String((t==null?void 0:t.house_number)??"").trim().replace(/\\/g,"/").replace(/\s+/g,"").toLowerCase();return!i&&!c?"":`${i}|${c}`}function Dn(t=[]){const i={};for(const c of t)c.is_deleted||c.family_id&&(i[c.family_id]=(i[c.family_id]||0)+1);return i}function Dt(t=[],i=[]){const c=Dn(i),d=new Map;for(const l of t){if(l.is_deleted)continue;const u=In(l.name);if(!u)continue;const v=En(l);if(!v)continue;const h=`${l.kibbutz_id||""}::${u}::${v}`;d.has(h)||d.set(h,[]),d.get(h).push(l)}const o=[];for(const l of d.values()){if(l.length<2)continue;const u=[...l].sort((_,C)=>{const p=(c[C.id]||0)-(c[_.id]||0);if(p)return p;const S=_.created_date||"",k=C.created_date||"";return S!==k?S<k?-1:1:(_.id||"")<(C.id||"")?-1:1}),[v,...h]=u;o.push({survivor:v,losers:h,memberCounts:Object.fromEntries(l.map(_=>[_.id,c[_.id]||0]))})}return o}function Tn(t=[],i=[]){const c=[],d=[],o=[];for(const{survivor:l,losers:u}of t){const v=i.filter(_=>_.family_id===l.id&&!_.is_deleted);let h=!!l.head_of_family_id||v.some(_=>_.family_role==="head");for(const _ of u){const C=i.filter(p=>p.family_id===_.id&&!p.is_deleted);for(const p of C){const S={id:p.id,family_id:l.id,family_name:l.name};p.family_role==="head"&&(h?S.family_role="adult":(h=!0,o.push({id:l.id,head_of_family_id:p.id}))),c.push(S)}d.push(_.id)}}return{residentUpdates:c,familyDeletes:d,familyHeadUpdates:o}}const qt=()=>R(()=>import("./ResidentsDashboard-Cer-G_Uk.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45])),$n=r.lazy(qt),Ln=r.lazy(()=>R(()=>import("./ResidentsTable-hwNjE91v.js"),__vite__mapDeps([46,1,2,47,48,26,49,50,51,52,53,54]))),zn=r.lazy(()=>R(()=>import("./ResidentForm-BDhM26Ze.js"),__vite__mapDeps([55,1,2,47,56,57,48,26,49,58,59,60,61,62]))),Vn=r.lazy(()=>R(()=>import("./AdvancedFilters-bKGjVvDI.js"),__vite__mapDeps([63,1,2,48,26,49,47,24,21,41]))),Pn=r.lazy(()=>R(()=>import("./ImportHistory-DdwosSiw.js"),__vite__mapDeps([64,1,2,18,17]))),On=r.lazy(()=>R(()=>import("./BulkActionBar-DwEd6OwS.js"),__vite__mapDeps([65,1,2,66,39,67,19,38]))),Gn=r.lazy(()=>R(()=>import("./ManageViewsDialog-VkqW2mJb.js"),__vite__mapDeps([68,1,2,34,69,70,38,71]))),Un=r.lazy(()=>R(()=>import("./AddToGroupDialog-cq6Je-MU.js"),__vite__mapDeps([72,1,2,17,18,34,69,70,73]))),Bn=r.lazy(()=>R(()=>import("./DashboardCustomizer-DJPGosVq.js"),__vite__mapDeps([74,1,2,34,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,49,21,20,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,40,41,42,43,44,45]))),Kn=r.lazy(()=>R(()=>import("./FamilyAssignmentDialog-CR05kTll.js"),__vite__mapDeps([75,1,2,48,26,49,34,70]))),Hn=r.lazy(()=>R(()=>import("./FamilyManageDialog-DtRbtaEF.js"),__vite__mapDeps([76,1,2,47,48,26,49,77,34,78,10,79,40]))),Tt=["id","full_name","first_name","last_name","phone","email","birth_date","gender","status","registration_status","registration_source","registration_type","registered_at","added_at","family_role","family_id","family_name","street","house_number","neighborhood","national_id","budget","category","notes","custom_fields","is_deleted","created_date","updated_date"],$t=["group_id","resident_id"],ye=6,qn=100,Jn=t=>typeof window<"u"&&typeof window.requestIdleCallback=="function"?window.requestIdleCallback(t,{timeout:1500}):setTimeout(t,0);function Lt(){return s.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 xl:grid-cols-8 gap-3 mb-4","aria-busy":"true","aria-label":"×××¢× × ×ª×× × ×ª×ש×××",children:["ס××´× ×ª×ש×××","×שפ××ת","××××× (×¢× ××× 18)","×××× ×ש××ש×","××ר××","× ×©××","××××× ××××ש","ער×××"].map(t=>s.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[s.jsx("div",{className:"h-7 w-12 rounded-md bg-slate-200 animate-pulse"}),s.jsx("div",{className:"text-xs text-slate-500 mt-1",children:t})]},t))})}function Yn(){const{id:t}=$s(),i=Ls(),[c]=zs(),[d,o]=r.useState([]),[l,u]=r.useState([]),[v,h]=r.useState([]),[_,C]=r.useState([]),[p,S]=r.useState(!0),[k,F]=r.useState(!0),[re,V]=r.useState(!1),[Jt,ve]=r.useState(!0),[Je,P]=r.useState(!0),[m,le]=r.useState(Et.mode),[y,E]=r.useState(null),[b,D]=r.useState({}),[M,X]=r.useState(""),[O,Ce]=r.useState(Et.statusView),[Ye,ae]=r.useState(!1),[oe,Yt]=r.useState("filters"),[Se,de]=r.useState(()=>xe(m)),[T,Qe]=r.useState([]),[B,K]=r.useState(null),[We,ce]=r.useState(!1),[Ne,J]=r.useState(null),[Xe,Me]=r.useState(""),[Ze,et]=r.useState(!1),[tt,st]=r.useState(!1),[Qt,Z]=r.useState(!1),[Wt,nt]=r.useState(null),[N,A]=r.useState([]),[it,rt]=r.useState(!1),[Re,lt]=r.useState(null),[ue,Fe]=r.useState(null),[H,Ae]=r.useState([]),[Ie,me]=r.useState([]),[at,Ee]=r.useState(new Map),[ot,dt]=r.useState(null),[Xt,De]=r.useState(!1),[Zt,ct]=r.useState(!1),ee=r.useCallback(async()=>{const e=await g.rpc("resident_group_member_counts",{p_community_id:t});return new Map((e||[]).map(n=>[n.group_id,Number(n.member_count||0)]))},[t]),I=r.useCallback(async()=>{S(!1),F(!0),V(!0),ve(!0),P(!0);try{const e=x=>x.catch(()=>null),[n,a,f]=await Promise.all([g.entities.ResidentCategory.filter({kibbutz_id:t},"order"),g.entities.ResidentField.filter({kibbutz_id:t},"order"),g.entities.Kibbutz.get(t).catch(()=>null)]);if(dt((f==null?void 0:f.residents_dashboard)||null),(n||[]).length===0){await g.entities.ResidentCategory.bulkCreate(un.map(L=>({...L,kibbutz_id:t})));const x=await g.entities.ResidentCategory.filter({kibbutz_id:t},"order");h(x)}else h(n);if((a||[]).length===0){await g.entities.ResidentField.bulkCreate(mn.map(L=>({...L,kibbutz_id:t})));const x=await g.entities.ResidentField.filter({kibbutz_id:t},"order");C(x)}else C(a);const w={kibbutz_id:t,is_deleted:jt};await Promise.all([e(g.entities.Resident.filterFields(w,Tt,"full_name",qn)).then(x=>{o((x||[]).filter(L=>{var ie;return!((ie=L.custom_fields)!=null&&ie.is_demo)})),F(!1)}),e(g.entities.Family.filterAll({kibbutz_id:t,is_deleted:jt},"name",1e3,ye)).then(x=>{u(x||[]),ve(!1)})]),Jn(async()=>{const x=await e(g.entities.Resident.filterAllFields(w,Tt,"full_name",1e3,ye));o((x||[]).filter(L=>{var ie;return!((ie=L.custom_fields)!=null&&ie.is_demo)})),V(!1)})}catch(e){console.error("Load error:",e),V(!1)}finally{F(!1),ve(!1),S(!1)}try{const[e,n]=await Promise.all([g.entities.ResidentGroup.filter({kibbutz_id:t,is_active:!0},"order",200),ee()]);Ae(e),Ee(n),me([])}catch(e){console.error("Group membership load error:",e)}finally{P(!1)}},[t,ee]),fe=r.useCallback(async()=>
2{if(t){P(!0);try{await an(t).catch(()=>{});const[e,n]=await Promise.all([g.entities.ResidentGroup.filter({kibbutz_id:t,is_active:!0},"order",200),ee()]);Ae(e),Ee(n)}catch{}finally{P(!1)}}},[t,ee]);r.useEffect(()=>{I()},[I]),r.useEffect(()=>{const e=Array.isArray(b.groupIds)?b.groupIds.filter(Boolean):[];if(e.length===0){me([]);return}let n=!1;return P(!0),g.entities.ResidentGroupMember.filterAllFields({kibbutz_id:t,is_active:{$notIs:!1},group_id:{$in:e}},$t,null,1e3,ye).then(a=>{n||me(a||[])}).catch(a=>{console.error("Selected group membership load error:",a),n||me([])}).finally(()=>{n||P(!1)}),()=>{n=!0}},[t,b.groupIds]),r.useEffect(()=>{qt().catch(()=>{})},[]);const[es,ts]=r.useState(null);r.useEffect(()=>{if(t)try{const e=`resident-return:${t}`,n=sessionStorage.getItem(e);n&&(ts(n),sessionStorage.removeItem(e))}catch{}},[t]),r.useEffect(()=>{A([])},[m]);const te=r.useCallback(e=>{if(!e.family_id)return"-";const n=d.filter(x=>x.family_id===e.family_id),a=n.find(x=>x.family_role==="head"),f=n.find(x=>x.family_role==="spouse"),w=[a,f].filter(Boolean).map(x=>z(x));return w.length>0?w.join(" ×"):"-"},[d]),he=r.useMemo(()=>{let e=d.filter(He);if(y)if(y.type==="birthday_month"){const n=new Date().getMonth();e=e.filter(a=>a.birth_date&&new Date(a.birth_date).getMonth()===n)}else y.type==="age_range"?e=e.filter(n=>{const a=Ke(n);return!(a===null||y.min!==void 0&&a<y.min||y.max!==void 0&&a>y.max)}):y.type==="no_family"?e=e.filter(n=>!n.family_id):y.field&&(e=e.filter(n=>n[y.field]===y.value));return e=Ht(e,b,{groupMembers:Ie,allResidents:d}),M.trim()&&(e=e.filter(n=>Ge(n,M,m==="children"?te(n):""))),e},[d,m,y,b,M,te,Ie]),se=r.useMemo(()=>we(he,O),[he,O]),$=r.useMemo(()=>vn(se,m),[se,m]),ne=r.useMemo(()=>{let e=l.map(n=>{var w;const a=d.filter(x=>x.family_id===n.id),f=a.find(x=>x.family_role==="head");return{...n,head_first_name:(f==null?void 0:f.first_name)||"-",member_count:a.length,head_id:f==null?void 0:f.id,first_member_id:(w=a[0])==null?void 0:w.id}});if(e=e.filter(n=>n.member_count>0),b.familyStatus&&(e=e.filter(n=>n.status===b.familyStatus)),b.street&&(e=e.filter(n=>n.street===b.street)),b.neighborhood&&(e=e.filter(n=>n.neighborhood===b.neighborhood)),b.memberMin!==null&&b.memberMin!==void 0&&(e=e.filter(n=>n.member_count>=b.memberMin)),b.memberMax!==null&&b.memberMax!==void 0&&(e=e.filter(n=>n.member_count<=b.memberMax)),M.trim()){const n=Vs(M);e=e.filter(a=>{const f=Ps([a.name,a.head_first_name,a.street,a.neighborhood].join(" ")).split(" ");return n.every(w=>f.some(x=>x.startsWith(w)))})}return e},[l,d,b,M]),Y=r.useMemo(()=>T.find(e=>e.id===B)||null,[T,B]),Q=r.useMemo(()=>Y?new Set(Y.memberIds||[]):null,[Y]),be=r.useMemo(()=>Q?$.filter(e=>Q.has(e.id)):$,[$,Q]),ut=r.useMemo(()=>Q?ne.filter(e=>Q.has(e.id)):ne,[ne,Q]),ss=m==="families"?ut.length:be.length,Te=r.useMemo(()=>m==="families"||m==="children"?0:he.length-$.length,[he,$,m]),ns=r.useMemo(()=>JSON.stringify({tableMode:m,search:M,statusView:O,filter:y,advancedFilters:b,activeViewId:B}),[m,M,O,y,b,B]),is=Array.isArray(b.groupIds)&&b.groupIds.length>0,W=m==="families"&&Jt||k||is&&Je,G=r.useMemo(()=>{const e=M.trim();if(!e||m==="families")return[];const n=new Set(be.map(a=>a.id));return d.filter(a=>!n.has(a.id)&&(Ge(a,e)||Ge(a,e,te(a))))},[M,m,d,be,te]),mt=r.useMemo(()=>{if(O!=="active"||!G.length)return"";const e=[...new Set(G.map(n=>{var a;return(a=Os(n))==null?void 0:a.label}).filter(Boolean))];return e.length?`×ס×××: ${e.join(" · ")}.`:""},[G,O]),rs=()=>{Ce("all"),E(null),D({}),K(null),m==="residents"&&G.length>0&&G.every(_e)&&le("children")},ft=r.useMemo(()=>{if(m==="families")return[];const e=m==="children"?"child":null,n=f=>String(f||"").replace(/["'׳״]/g,"").replace(/\s+/g," ").trim().replace(/^×ספר\s+/,""),a=new Set((Gt[m]||[]).map(f=>n(f.label)));return _.filter(f=>f.is_active&&f.is_custom&&(!e||(f.display_stages||[]).includes(e))&&!a.has(n(f.display_name)))},[_,m]),ls=ft.filter(e=>Se.includes(`custom:${e.field_key}`)),ge=e=>{const n=je(e);return le(n.mode),de(xe(n.mode)),Ce(n.statusView),n},$e=(e,n)=>{const f=ge(n||"residents");f.mode==="families"||f.mode==="children"||f.mode==="all"?E(null):E(e||null)},as=e=>{de(e),yn(m,e)},ht=(e,n="shelf")=>{ge(n),E(null),X(""),K(null),D(e)},os=e=>ht({groupIds:[e]}),ds=e=>ht({...e}),cs=async e=>
2{ct(!0);try{await g.entities.Kibbutz.update(t,{residents_dashboard:e}),dt(e),De(!1),j.success("××ש×××¨× ×¢××××")}catch(n){console.error("Save dashboard error:",n),j.error("ש××רת ××ש×××¨× × ×ש××")}finally{ct(!1)}};r.useEffect(()=>{c.get("status")==="pending_approval"&&(le("residents"),de(xe("residents")),E({field:"registration_status",value:"pending_approval"}))},[]),r.useEffect(()=>{Qe(wn(t))},[t]);const pe=e=>{Qe(e),jn(t,e)},us=e=>{if(B===e.id){K(null);return}e.mode&&e.mode!==m&&(le(e.mode),de(xe(e.mode))),X(""),D({}),E(null),K(e.id)},ms=e=>{const n={id:kn(),name:e.trim(),mode:m,memberIds:[...N]};pe([...T,n]),ce(!1),A([]),X(""),D({}),E(null),K(n.id),j.success("×תצ××× × ×צר×")},fs=e=>{const n=T.map(a=>a.id===e?{...a,memberIds:Array.from(new Set([...a.memberIds||[],...N]))}:a);pe(n),ce(!1),A([]),j.success("×רש×××ת × ××¡×¤× ×תצ×××")},hs=e=>{pe(T.filter(n=>n.id!==e)),B===e&&K(null)},bt=()=>{const e=Xe.trim();if(!e||!Ne){J(null);return}pe(T.map(n=>n.id===Ne.id?{...n,name:e}:n)),J(null),Me("")},bs=async e=>{if(window.confirm(`×××××§ ×ת ×שפ×ת ${e.name}?`))try{await g.entities.Family.update(e.id,{is_deleted:!0}),j.success("××שפ×× × ×××§×"),I()}catch{j.error("ש×××× ×××××§×")}},gs=async e=>{const n=Zs(e);if(Object.keys(n).length)try{await g.entities.Resident.update(e.id,n),await g.entities.ResidentActivityLog.create({kibbutz_id:t,resident_id:e.id,family_id:e.family_id,module_key:"residents_families",action_type:"resident_updated",action_title:"×××רת ת××©× ×פע××××",description:`${z(e)} ××××ר/× ×תצ××ת פע×××× (${Object.keys(n).join(", ")})`}).catch(()=>{}),j.success("×ת××©× ××××ר ×פע××××"),I(),fe()}catch{j.error("ש×××× ××××רת ×ת×ש×")}},ps=async(e,n,a)=>{try{await g.entities.Resident.update(e.id,{[n]:a}),await g.entities.ResidentActivityLog.create({kibbutz_id:t,resident_id:e.id,family_id:e.family_id,module_key:"residents_families",action_type:"resident_updated",action_title:"×¢×××× ×¤×¨×× ×ª×ש×",description:`×¢×××× ×©×× ${n} ×ת××©× ${z(e)}`}),n==="registration_status"&&a==="approved"&&e.registration_status!=="approved"&&g.functions.invoke("notifyResidentApproved",{community_id:t,resident_id:e.id}).catch(()=>{}),j.success("×¢××××"),I(),["registration_status","status","phone","email","gender","street","house_number","neighborhood"].includes(n)&&fe()}catch{j.error("ש×××× ××¢××××")}},[xs,gt]=r.useState(!1),ys=async()=>{if(se.length===0){j.error("××× × ×ª×× ×× ×××צ××");return}if(xs)return;gt(!0);const e=j.loading("×××× ×× ×ת ××§×××¥â¦");try{const n=await g.entities.ResidentGroupMember.filterAllFields({kibbutz_id:t,is_active:{$notIs:!1}},$t,null,1e3,ye).catch(()=>[]),{exportResidentsToExcel:a}=await R(async()=>{const{exportResidentsToExcel:f}=await import("./residentExcelExport-Cy2UnxIG.js");return{exportResidentsToExcel:f}},__vite__mapDeps([80,1,2,62]));await a({residents:se,fields:_,groups:H,memberships:n||[]}),j.success(`×××צ×× ${se.length} ת×ש××× Â· ${H.length} ×§××צ×ת`,{id:e})}catch(n){console.error("Resident export error:",n),j.error("ש×××× ××פקת ××§×××¥",{id:e})}finally{gt(!1)}},_s=()=>{et(!1),nt(null),I(),fe()},q=r.useMemo(()=>new Set(N),[N]),ws=e=>{A(n=>n.includes(e)?n.filter(a=>a!==e):[...n,e])},js=e=>{const n=new Set(e),a=e.length>0&&e.every(f=>q.has(f));A(a?f=>f.filter(w=>!n.has(w)):f=>[...new Set([...f,...e])])},ks=()=>{if(N.length!==0){if(m==="children"){const e=$.filter(w=>q.has(w.id)),{parents:n,unresolvedCount:a,duplicatesRemoved:f}=Fn(e,d);if(n.length===0){j.error(`×× × ×צ×× ×¤×¨×× ××ר×× ×¢××ר ${e.length} ×××××`);return}j.success(`× ×××¨× ${e.length} ××××× â¢ × ×צ×× ${n.length} ××ר×× ×××××××× â¢ ×××¡×¨× ${f} ×פ×××××ת`),a>0&&setTimeout(()=>j(`×× × ×צ×× ×¤×¨×× ××ר×× ×¢××ר ${a} ×××××`,{icon:"â ï¸"}),500),i(`/kibbutz/${t}/send-message`,{state:{preloadedRecipients:n,sourceLabel:"×××¨× ××××× ×ס××× ××"}})}else if(m==="families"){const e=ne.filter(a=>q.has(a.id)),n=An(e,d);if(n.length===0){j.error("×× × ×צ×× ×¤×¨×× ×§×©×¨ ×¢××ר ××שפ××ת ×©× ××ר×");return}i(`/kibbutz/${t}/send-message`,{state:{preloadedRecipients:n,sourceLabel:"ת×ש××× ×ס××× ××"}})}else{const e=$.filter(a=>q.has(a.id)),n=Rn(e);i(`/kibbutz/${t}/send-message`,{state:{preloadedRecipients:n,sourceLabel:"ת×ש××× ×ס××× ××"}})}A([])}},vs=()=>{N.length!==0&&rt(!0)},Cs=async()=>{const e=$.filter(a=>q.has(a.id));if(e.length===0||!window.confirm(`×××××§ ${e.length} ת×ש××× ×ס××× ××?`))return;let n=0;for(const a of e)try{await g.entities.Resident.update(a.id,{is_deleted:!0}
2),g.entities.ResidentActivityLog.create({kibbutz_id:t,resident_id:a.id,family_id:a.family_id,module_key:"residents_families",action_type:"resident_deleted",action_title:"×××קת ת×ש×",description:`ת××©× ${z(a)} × ×××§`}).catch(()=>{}),n++}catch{}n&&j.success(`${n} ת×ש××× × ×××§×`),n<e.length&&j.error(`${e.length-n} ת×ש××× ×× × ×××§×`),A([]),I(),n&&fe()},Ss=r.useMemo(()=>d.filter(e=>q.has(e.id)),[d,q]),Le=r.useMemo(()=>m==="families"?Dt(l,d):[],[m,l,d]),Ns=async()=>{const e=Dt(l,d);if(!e.length){j("×× × ×צ×× ×שפ××ת ×פ×××ת",{icon:"â¹ï¸"});return}const{residentUpdates:n,familyDeletes:a,familyHeadUpdates:f}=Tn(e,d);if(window.confirm(`× ×צ×× ${e.length} ×§××צ×ת ×©× ×שפ××ת ×פ×××ת (${a.length} ×פ×××××ת ×××××§×). 3×פע××× ×ª×¢××ר ${n.length} ×× × ×שפ×× ××שפ×× ×ר×ש×ת ××× ×§××צ×, תס×× ${a.length} ×שפ××ת ×××××§×ת, ××× ×ª××× ××£ ש×××. ×××ש××?`))try{for(const w of n){const{id:x,...L}=w;await g.entities.Resident.update(x,L)}for(const w of f)await g.entities.Family.update(w.id,{head_of_family_id:w.head_of_family_id});for(const w of a)await g.entities.Family.update(w,{is_deleted:!0});j.success(`××××× ${a.length} ×שפ××ת ×פ×××ת`),I()}catch(w){console.error("merge duplicates failed",w),j.error("ש×××× ×××××× ××שפ××ת ××פ×××ת")}},pt=e=>{N.length&<(e)},Ms=()=>{const e=l.find(n=>n.id===N[0]);e&&Fe(e)},Rs=()=>(A([]),I()),Fs=()=>{async function e(){P(!0);try{const[n,a]=await Promise.all([g.entities.ResidentGroup.filter({kibbutz_id:t,is_active:!0},"order",200),ee()]);Ae(n),Ee(a)}catch{}finally{P(!1)}}e(),A([])},ze=Object.values(b).filter(e=>e!=null&&e!=="").length,As=m==="families"?ne.length:$.length,Ve=r.useMemo(()=>d.filter(e=>e.registration_status==="pending_approval").length,[d]),Is=m==="residents"&&(y==null?void 0:y.field)==="registration_status"&&(y==null?void 0:y.value)==="pending_approval",Pe=r.useMemo(()=>d.filter(e=>!e.family_id).length,[d]),xt=r.useMemo(()=>dn(we(d,je("children").statusView)).length,[d]),Oe=m==="residents"&&(y==null?void 0:y.type)==="no_family",Es=T.length>0||Ve>0||m!=="families"||Le.length>0||Te>0,yt=()=>{if(Oe){E(null);return}$e({type:"no_family"},"residents")};return p?s.jsx(kt,{moduleKey:"residents_families",children:s.jsxs("div",{children:[s.jsx("div",{className:"flex mb-6",children:s.jsx(vt,{title:"ת×ש××× ××שפ××ת",items:Ct(t,i,{onDataTransfer:()=>Z(!0)})})}),s.jsx("div",{className:"flex items-center justify-center h-64",children:s.jsx("div",{className:"w-8 h-8 border-4 border-primary/20 border-t-primary rounded-full animate-spin"})})]})}):s.jsx(kt,{moduleKey:"residents_families",children:s.jsxs("div",{children:[s.jsx("div",{className:"flex mb-6",children:s.jsx(vt,{title:"ת×ש××× ××שפ××ת",items:Ct(t,i,{onDataTransfer:()=>Z(!0)})})}),k||re?s.jsx(Lt,{}):s.jsx(r.Suspense,{fallback:s.jsx(Lt,{}),children:s.jsx($n,{residents:d,familiesCount:l.length,onStatClick:$e,activeFilter:y,activeMode:m,config:ot,groups:H,groupMembers:Ie,groupMemberCounts:at,advancedFilters:b,canManage:!0,onEditDashboard:()=>De(!0),onSelectGroup:os,onSelectFilter:ds})}),Xt&&s.jsx(r.Suspense,{fallback:null,children:s.jsx(Bn,{open:!0,onClose:()=>De(!1),config:ot,groups:H,onSave:cs,saving:Zt})}),s.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm px-3 py-3 mb-4 space-y-2.5",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx(cn,{placeholder:m==="families"?"××פ×ש ×שפ××...":"××פ×ש: ×©× Â· ××פ×× Â· ××ת 15/01 · ×ª×´× Â· תפק×× Â· ש××× ×â¦",value:M,onChange:e=>X(e.target.value),className:"flex-1 min-w-[18rem] sm:min-w-[22rem] max-w-xl",inputClassName:"h-11 text-[0.9375rem] font-bold"}),s.jsxs("button",{onClick:()=>ae(!0),className:`inline-flex items-center gap-2 h-9 px-4 rounded-full bg-white border shadow-sm transition-all hover:shadow-md text-sm font-medium text-foreground cursor-pointer whitespace-nowrap ${Ye?"border-blue-300 bg-blue-50":"border-border hover:border-slate-300"}`,children:[s.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center bg-blue-50",children:s.jsx(St,{className:"w-3 h-3 text-blue-600"})}),"ס×× ×× ×תצ×××ת",ze>0&&s.jsx("span",{className:"bg-blue-100 text-blue-700 px-1.5 py-0.5 rounded-full text-xs",children:ze})]}),m!=="families"&&s.jsx("div",{className:"inline-flex items-center rounded-full bg-slate-100 p-1 h-9",children:[{k:"active",l:"פע××××"},{k:"inactive",l:"×× ×¤×¢××××"},{k:"all",l:"××××"}].map(e=>s.jsx("button",{onClick:()=>Ce(e.k),className:`px-3 h-7 rounded-full text-xs font-bold transition-all whitespace-nowrap ${O===e.k?"bg-white text-blue-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:e.l},e.k))}),(M.trim()||ze>0||y)&&s.jsxs("button",{onClick:()=>{X(""),D({}),E(null)}
3,className:"inline-flex items-center gap-1.5 h-9 px-4 rounded-full bg-red-50 border border-red-200 text-red-600 text-sm font-medium hover:bg-red-100 transition-colors cursor-pointer whitespace-nowrap",title:"× ××§×× ×× ×ס×× ×× ××××פ×ש",children:[s.jsx(Ue,{className:"w-4 h-4"})," × ×§× ×××"]}),s.jsx("span",{className:"inline-flex items-center gap-1.5 h-9 px-4 rounded-full bg-blue-50 border border-blue-200 text-blue-700 text-sm font-bold whitespace-nowrap",title:W?"×××¢× × ×ª×× ××â¦":"×ספר ×רש×××ת ×××צ××ת ×××××","aria-busy":W||void 0,children:W?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"w-4 h-4 border-2 border-blue-200 border-t-blue-600 rounded-full animate-spin","aria-hidden":"true"}),"×××¢× ",m==="families"?"×שפ××ת":"ת×ש×××","â¦"]}):s.jsxs(s.Fragment,{children:[s.jsx(zt,{className:"w-4 h-4"}),ss.toLocaleString("he-IL")," ",m==="families"?"×שפ××ת":"ת×ש×××",m==="all"&&O==="all"&&s.jsx("span",{className:"font-medium text-blue-500",children:"· ×× ×ת×ש×××"})]})})]}),Es&&s.jsxs("div",{className:"flex items-center gap-2 flex-wrap pt-2.5 border-t border-slate-100",children:[T.map(e=>{const n=B===e.id;return s.jsxs("span",{className:`inline-flex items-center h-9 rounded-full shadow-sm overflow-hidden border ${n?"bg-blue-600 border-blue-600":"bg-white border-slate-200"}`,children:[s.jsxs("button",{onClick:()=>us(e),className:`inline-flex items-center gap-1.5 h-full pr-3 pl-2 text-sm font-medium ${n?"text-white":"text-slate-700 hover:bg-slate-50"}`,title:"×צ×ת ×תצ×××",children:[s.jsx(Nt,{className:`w-3.5 h-3.5 ${n?"text-white":"text-blue-600"}`})," ",e.name,s.jsx("span",{className:`text-xs ${n?"text-blue-100":"text-slate-400"}`,children:(e.memberIds||[]).length})]}),s.jsxs(Gs,{dir:"rtl",children:[s.jsx(Us,{asChild:!0,children:s.jsx("button",{className:`h-full px-2 ${n?"text-blue-100 hover:bg-blue-500":"text-slate-400 hover:text-slate-600 hover:bg-slate-50"}`,title:"×¢××",children:s.jsx(fn,{className:"w-3.5 h-3.5"})})}),s.jsxs(Bs,{align:"start",className:"w-40 p-1.5 rounded-xl",children:[s.jsxs(wt,{onClick:()=>{J(e),Me(e.name)},className:"rounded-lg px-2.5 py-1.5 gap-2 cursor-pointer",children:[s.jsx(hn,{className:"w-4 h-4 text-slate-500"})," ",s.jsx("span",{className:"text-sm flex-1 text-right",children:"ש×× ×× ×©×"})]}),s.jsxs(wt,{onClick:()=>hs(e.id),className:"rounded-lg px-2.5 py-1.5 gap-2 cursor-pointer text-red-600",children:[s.jsx(Ks,{className:"w-4 h-4"})," ",s.jsx("span",{className:"text-sm flex-1 text-right",children:"×××קת תצ×××"})]})]})]})]},e.id)}),Ve>0&&s.jsxs("button",{onClick:()=>$e({field:"registration_status",value:"pending_approval"},"residents"),className:`inline-flex items-center gap-2 h-9 px-4 rounded-full shadow-sm transition-all hover:shadow-md text-sm font-medium cursor-pointer whitespace-nowrap ${Is?"bg-orange-100 border border-orange-300 text-orange-800":"bg-white border border-orange-200 text-orange-700 hover:bg-orange-50"}`,title:"××¦× ×ª×ש××× ×××ת×× ×× ×××ש×ר",children:[s.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center bg-orange-50",children:s.jsx(Hs,{className:"w-3 h-3 text-orange-600"})}),"××ת×× ×× ×××ש×ר",s.jsx("span",{className:"bg-orange-100 text-orange-700 px-1.5 py-0.5 rounded-full text-xs",children:Ve})]}),m!=="families"&&Pe>0&&s.jsxs("button",{onClick:yt,className:`inline-flex items-center gap-2 h-9 px-4 rounded-full shadow-sm transition-all hover:shadow-md text-sm font-medium cursor-pointer whitespace-nowrap ${Oe?"bg-rose-100 border border-rose-300 text-rose-800":"bg-white border border-rose-200 text-rose-700 hover:bg-rose-50"}`,title:"××¦× ×ª×ש××× ×©××× × ×ש×××××× ××שפ×× â ×× ×××× ×ש×××",children:[s.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center bg-rose-50",children:s.jsx(bn,{className:"w-3 h-3 text-rose-600"})}),"××× ×©××× ×שפ×ת×",s.jsx("span",{className:"bg-rose-100 text-rose-700 px-1.5 py-0.5 rounded-full text-xs",children:Pe})]}),m==="families"&&Le.length>0&&s.jsxs("button",{onClick:Ns,className:"inline-flex items-center gap-2 h-9 px-4 roun
3ded-full bg-amber-50 border border-amber-300 shadow-sm transition-all hover:bg-amber-100 text-sm font-medium text-amber-800 cursor-pointer whitespace-nowrap",title:"××××× ×שפ××ת ×פ×××ת ×©× ××¦×¨× ×××¢×ת",children:[s.jsx(gn,{className:"w-4 h-4"}),"××××× ×שפ××ת ×פ×××ת",s.jsx("span",{className:"bg-amber-200 text-amber-800 px-1.5 py-0.5 rounded-full text-xs",children:Le.length})]}),m!=="families"&&s.jsxs("div",{className:"flex items-center gap-1.5 h-9 px-3 rounded-full bg-white border border-border shadow-sm",children:[s.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"×××"}),s.jsx("input",{type:"number",min:"0",value:b.ageMin??"",onChange:e=>D(n=>({...n,ageMin:e.target.value===""?null:Number(e.target.value)})),placeholder:"×",className:"w-10 h-7 text-sm text-center rounded-md border border-slate-200 bg-slate-50 focus:outline-none focus:ring-1 focus:ring-blue-200 focus:bg-white"}),s.jsx("span",{className:"text-xs text-muted-foreground",children:"-"}),s.jsx("input",{type:"number",min:"0",value:b.ageMax??"",onChange:e=>D(n=>({...n,ageMax:e.target.value===""?null:Number(e.target.value)})),placeholder:"×¢×",className:"w-10 h-7 text-sm text-center rounded-md border border-slate-200 bg-slate-50 focus:outline-none focus:ring-1 focus:ring-blue-200 focus:bg-white"})]}),m==="children"&&xt>0&&!W&&s.jsxs("button",{onClick:()=>ge("all"),className:"inline-flex items-center gap-2 h-9 px-4 rounded-full bg-white border border-amber-200 text-amber-700 text-sm font-medium shadow-sm transition-all hover:bg-amber-50 hover:shadow-md cursor-pointer whitespace-nowrap",title:"רש×××ת שס××× × ××´××××´ ×× ××× ××× ×ª×ר×× ××××. ××ש×× ×ת ××× ××× ××× ×ת×ת ×-18, ×××× ×× ××פ××¢×ת ת×ת ×´×× ×ת×ש××××´ ×¢× ×©××ש×× ×ת×ר××. ×××¦× ××× ×פת×× ×©×.",children:[s.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center bg-amber-50",children:s.jsx(Mt,{className:"w-3 h-3 text-amber-600"})}),"×ס××× ×× ×××× ××× ×ª×ר×× ××××",s.jsx("span",{className:"bg-amber-100 text-amber-800 px-1.5 py-0.5 rounded-full text-xs",children:xt.toLocaleString("he-IL")})]}),Te>0&&!W&&s.jsxs("button",{onClick:()=>ge("all"),className:"inline-flex items-center gap-2 h-9 px-4 rounded-full bg-white border border-slate-200 text-slate-600 text-sm font-medium shadow-sm transition-all hover:bg-slate-50 hover:shadow-md cursor-pointer whitespace-nowrap",title:"×תצ××× ×× ××××ת ×סת××¨× ×¨×©×××ת שס××× × ××´××××´ ×× ×©××× × ×ס××× ×ת ×פע×××ת. ×××¦× ××× ××צ×× ×ת ×× ×ת×ש×××.",children:[s.jsx("span",{className:"w-5 h-5 rounded-full flex items-center justify-center bg-slate-100",children:s.jsx(Mt,{className:"w-3 h-3 text-slate-500"})}),"××סתר×× ×תצ××× ××",s.jsx("span",{className:"bg-slate-100 text-slate-700 px-1.5 py-0.5 rounded-full text-xs",children:Te.toLocaleString("he-IL")})]})]})]}),Ye&&s.jsxs(ln,{open:!0,onClose:()=>ae(!1),title:"ס×× ×× ×תצ×××ת",subtitle:"×¡× × × ×ת ×× ×ª×× ××, ×××¨× ×¢××××ת ×תצ××× ×× ×××××× ××§××צ×ת ת×ש×××",icon:St,tone:"blue",align:"top",maxWidth:"max-w-4xl",hideFooter:!0,tabs:[{key:"filters",label:"ס×× ×× × ×ª×× ××"},{key:"columns",label:"×¢××××ת ×תצ×××"},{key:"groups",label:"×§××צ×ת ת×ש×××"}],activeTab:oe,onTabChange:Yt,children:[s.jsx(r.Suspense,{fallback:s.jsx("div",{className:"py-8 text-center text-sm text-slate-400",children:"×××¢×â¦"}),children:oe==="filters"&&s.jsx(Vn,{mode:m,filters:b,onChange:D,onClose:()=>ae(!1),residents:d,families:l,groups:H,resultCount:As,noFamilyCount:Pe,noFamilyActive:Oe,onShowNoFamily:yt,hideGroups:!0})}),oe==="columns"&&s.jsx(_n,{mode:m,visibleColumns:Se,onChange:as,onClose:()=>ae(!1),customFields:ft}),oe==="groups"&&s.jsx(Qn,{groups:H,selected:Array.isArray(b.groupIds)?b.groupIds:[],onChange:e=>D(n=>({...n,groupIds:e.length?e:null}))})]}),Y&&s.jsxs("div",{className:"flex items-center justify-between gap-3 bg-blue-50 border border-blue-200 rounded-xl px-4 py-2.5 mb-3",dir:"rtl",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[s.jsx(Nt,{className:"w-4 h-4 text-blue-600"}),s.jsxs("span",{className:"font-bold text-blue-700",children:["תצ×××: ",Y.name]}),s.jsxs("span",{className:"text-blue-500",children:["· ",(Y.memberIds||[]).length," רש×××ת"]})]}),s.jsxs("button",{onClick:()=>K(null),className:"inline-flex items-center gap-1.5 h-8 px-3 rounded-full bg-white border border-blue-200 text-blue-700 text-sm font-medium hover:bg-blue-50",children:[s.jsx(Ue,{className:"w-4 h-4"})," ×צ××× ××תצ×××"]})]}),s.jsx(r.Suspense,{fallback:null,children:s.jsx(On,{selectedCount:N.length,onSendMessage:ks,onClearSelection:()=>A([]),onAddToGroup:vs,showAddToGroup:m!=="children",showFamilyActions:m==="residents",onCreateFamily:()=>pt("new"),onAttachFamily:()=>pt("existing"),showManageFamily:m==="families"&&N.length===1,onManageFamily:Ms,onManageViews:()=>ce(!0),showDelete:m!=="families",onDeleteSelected:Cs})}),G.length>0&&s.jsxs("div",{className:"mb-3 flex items-start sm:items-center justify-between gap-3 flex-wrap rounded-xl border border-amber-200 bg-amber-50 px-4 py-3",children:[s.jsxs("p",{className:"text-sm text-amber-800",children:[G.length===1?"ת××©× ××× ×ª××× ×××פ×ש ×× ××סתר ×¢×Ö¾××× ×¡×× ×× ×¤×¢×× (ס×××ס / ס×× ×× ×תק×× / תצ×××).":`${G.length} ת×ש××× ×ª××××× ×××פ×ש ×× ××סתר×× ×¢×Ö¾××× ×¡×× ×× ×¤×¢×× (ס×××ס / ס×× ×× ×תק×× / תצ×××).`,mt&&s.jsx("span",{className:"block mt-0.5 font-bold",children:mt})]}),s.jsx("button",{onClick:rs,className:"inline-flex items-center gap-1.5 h-9 px-4 roun
3ded-full text-sm font-bold bg-amber-600 text-white hover:bg-amber-700 flex-none",children:"× ×§× ×¡×× ×× ×××¦× ×ת ××××"})]}),re&&!k&&s.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-xl border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-800",dir:"rtl",children:[s.jsx("span",{className:"w-4 h-4 rounded-full border-2 border-blue-200 border-t-blue-600 animate-spin flex-none"}),s.jsx("span",{className:"font-medium",children:"×צ×××× ×¨×©××× ×¨×ש×× ×ת â ×××¢× ×× ×רקע ×ת ×× ×ת×ש×××, ×ס×× ×× ×× ××××צ×× ××××."})]}),s.jsx(r.Suspense,{fallback:s.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-6 text-sm text-slate-400",children:"×××¢× ××××â¦"}),children:s.jsx(Ln,{mode:m,residents:be,families:ut,kibbutzId:t,onQuickEdit:ps,onReactivate:gs,onFamilyDelete:bs,onOpenFamily:Fe,getParentNames:te,visibleColumns:Se,customColumns:ls,selectedIds:N,onToggleId:ws,onToggleAllVisible:js,highlightId:es,loading:W,paginationKey:ns})}),s.jsxs(r.Suspense,{fallback:null,children:[Ze&&s.jsx(zn,{open:Ze,resident:Wt,kibbutzId:t,families:l,categories:v,fields:_,onSaved:_s,onClose:()=>{et(!1),nt(null)}}),tt&&s.jsx(Pn,{open:tt,kibbutzId:t,onClose:()=>st(!1),onChanged:I})]}),s.jsx(qs,{open:Qt,onOpenChange:Z,children:s.jsxs(Js,{className:"max-w-md",dir:"rtl",children:[s.jsx(Ys,{children:s.jsx(Qs,{className:"text-right",children:"××צ×× ××××× × ×ª×× ××"})}),s.jsx("div",{className:"space-y-2.5 pt-1",children:[{label:"××××× ×ª×ש××× ××קס×",desc:"××¢××ת ×§×××¥ ××§×¡× ×××ספת ת×ש××× ××ת ××ת",icon:Ws,bg:"bg-emerald-50",color:"text-emerald-600",onClick:()=>i(`/kibbutz/${t}/residents/import`)},{label:"××ס××ר××ת ×××××",desc:"צפ××× ××××××× ×§××××× ×ש×××ר",icon:pn,bg:"bg-purple-50",color:"text-purple-600",onClick:()=>{Z(!1),st(!0)}},{label:"××צ×× ××קס×",desc:"×§×××¥ xlsx ×¢× ×× × ×ª×× × ×ת×ש×××, ×ש××ת ×××ת×××× ××¢×××× ××× ×§××צ×",icon:Xs,bg:"bg-cyan-50",color:"text-cyan-600",onClick:()=>{Z(!1),ys()}}].map(e=>{const n=e.icon;return s.jsxs("button",{onClick:e.onClick,className:"w-full flex items-center gap-3 rounded-xl border border-slate-200 bg-white p-3.5 text-right transition-all hover:border-slate-300 hover:shadow-sm",children:[s.jsx("span",{className:`w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0 ${e.bg}`,children:s.jsx(n,{className:`w-5 h-5 ${e.color}`})}),s.jsxs("span",{className:"flex-1",children:[s.jsx("span",{className:"block text-sm font-bold text-slate-800",children:e.label}),s.jsx("span",{className:"block text-xs text-slate-500 mt-0.5",children:e.desc})]}),s.jsx(xn,{className:"w-4 h-4 text-slate-300 flex-shrink-0"})]},e.label)})})]})}),s.jsxs(r.Suspense,{fallback:null,children:[Re&&s.jsx(Kn,{open:!!Re,mode:Re,residents:Ss,families:l,kibbutzId:t,onClose:()=>lt(null),onComplete:Rs}),ue&&s.jsx(Hn,{open:!!ue,family:l.find(e=>e.id===ue.id)||ue,residents:d,families:l,kibbutzId:t,onClose:()=>Fe(null),onChanged:I}),it&&s.jsx(Un,{open:it,onClose:()=>rt(!1),kibbutzId:t,selectedCount:N.length,selectedIds:N,groups:H,groupMemberCounts:at,countsLoading:Je,onComplete:Fs}),We&&s.jsx(Gn,{open:We,selectedCount:N.length,views:T,mode:m,onCreate:ms,onAddToExisting:fs,onClose:()=>ce(!1)})]}),Ne&&s.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:()=>J(null),children:s.jsxs("div",{className:"bg-white rounded-2xl shadow-xl w-full max-w-sm",onClick:e=>e.stopPropagation(),dir:"rtl",children:[s.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[s.jsx("h3",{className:"text-base font-bold text-slate-900",children:"ש×× ×× ×©× ×תצ×××"}),s.jsx("button",{onClick:()=>J(null),className:"w-8 h-8 rounded-lg hover:bg-accent flex items-center justify-center",children:s.jsx(Ue,{className:"w-5 h-5"})})]}),s.jsx("div",{className:"p-4",children:s.jsx("input",{autoFocus:!0,value:Xe,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),bt())},className:"w-full h-10 rounded-xl border border-slate-200 bg-slate-50 px-3 text-sm focus:outline-none focus:ring-2 focus:ring-blue-100 focus:bg-white"})}),s.jsxs("div",{className:"flex gap-2 p-4 border-t border-border",children:[s.jsxs("button",{onClick:bt,className:"flex-1 h-10 rounded-xl bg-blue-600 text-white text-sm font-semibold hover:bg-blue-700 inline-flex items-center justify-center gap-1.5",children:[s.jsx(Vt,{className:"w-4 h-4"})," ש××ר×"]}),s.jsx("button",{onClick:()=>J(null),className:"h-10 px-6 rounded-xl border border-border text-sm font-medium hover:bg-accent",children:"×××××"})]})]})})]})})}function Qn({groups:t=[],selected:i=[],onChange:c}){const d=o=>{const l=i.includes(o)?i.filter(u=>u!==o):[...i,o];c(l)};return!t||t.length===0?s.jsx("p",{className:"text-sm text-slate-400 text-center py-8",children:"××× ×§××צ×ת ת×ש××× ××××ר×ת."}):s.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-slate-50/70 p-4 space-y-4",dir:"rtl",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"w-7 h-7 rounded-lg bg-blue-100 flex items-center justify-center",children:s.jsx(zt,{className:"w-4 h-4 text-blue-600"})}),s.jsx("h3",{className:"text-sm font-bold text-slate-700",children:"×××¨× ×§×××¦× ××ת ×× ××תר ×××××ת ×××××"})]}),i.length>0&&s.jsxs("button",{type:"button",onClick:()=>c([]),className:"inline-flex items-center gap-1 text-xs font-semibold text-blue-600 hover:underline",children:["× ××§×× ×××××¨× (",i.length,")"]})]}),s.jsx("div",{className:"flex flex-wrap gap-2.5",children:t.map(o=>{const l=i.includes(o.id);return s.jsxs("button",{type:"button",onClick:()=>d(o.id),className:`inline-flex items-center gap-1.5 h-10 px-4 roun
3ded-xl text-sm font-semibold border-2 transition-all ${l?"bg-blue-600 border-blue-600 text-white shadow-md scale-[1.02]":"bg-white border-slate-200 text-slate-700 hover:border-blue-300 hover:bg-blue-50 hover:shadow-sm"}`,children:[o.title||o.name||"×§××צ×",l&&s.jsx(Vt,{className:"w-4 h-4"})]},o.id)})})]})}const vi=Object.freeze(Object.defineProperty({__proto__:null,default:Yn},Symbol.toStringTag,{value:"Module"}));export{vi as R,qe as S,Kt as a,wi as b,Cn as c,ji as d,Mn as m,Sn as n,ki as r};
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.