1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-DBYZKSRA.js","assets/index-BH8Hq4fF.js","assets/index-AOxdnY9t.css","assets/CaravanReports-C6geTtVg.js","assets/money-CmD9E_V-.js","assets/generateCategoricalChart-BdpZagc6.js","assets/isEqual-JxrnfUIG.js","assets/tiny-invariant-BaFNuDhB.js","assets/PieChart-BecCKbda.js","assets/BarChart-BcX6CtaQ.js","assets/CartesianGrid-v8Vrjjuo.js","assets/CaravanMap-DoD3fl-5.js"])))=>i.map(i=>d[i]); 2import{aT as Ce,ac as qe,r as h,d as k,z as y,j as e,P as De,H as ve,aI as He,bB as Ye,c1 as Ze,$ as Ge,l as Ie,C as Pe,W as Re,y as Qe,T as fe,F as Ue,a9 as Xe,ao as et,Z as R,b as xe}from"./index-BH8Hq4fF.js";import{f as ye}from"./money-CmD9E_V-.js";import{N as tt}from"./softDelete-X2GBluex.js";import{P as st}from"./PageTitleMenu-CMXtRh6s.js";import{R as at}from"./ResponsibleAssignmentManager-BPQO-EsD.js";import{U as me}from"./upload-DtbdHLAK.js";import{S as lt}from"./settings-2-CQkCCTmF.js";import{C as nt}from"./calendar-clock-DVPPNrp2.js";import{P as oe}from"./pencil-DlA_FTEn.js";import{C as rt}from"./chevron-left-DaNP-hnR.js";import{F as it}from"./file-spreadsheet-Bhwtsba1.js";import{I as Le}from"./image-DgoP-ctX.js";import"./useActionVisibility-oACH4aDh.js";import"./input-RnZK1Sdh.js";import"./residentGroupUtils-CFDJNblj.js";import"./bell-ring-Db0rTCDW.js";const ee=l=>{const o=String(l||"").slice(0,10);if(!o)return"";const[p,c,n]=o.split("-");return`${n}/${c}/${p}`},we=l=>{const o=String(l||"").match(/^#?([0-9a-fA-F]{6})$/);return o?`FF${o[1].toUpperCase()}`:"FFD97706"};function Ne(l,o,p,c,n){const d=l.addWorksheet(o,{views:[{rightToLeft:!0,state:"frozen",ySplit:2}]}),f=c.length;
2c.forEach((b,a)=>{d.getColumn(a+1).width=b.width}),d.mergeCells(1,1,1,f);const m=d.getCell(1,1);m.value=o,m.font={bold:!0,size:15,color:{argb:"FFFFFFFF"}},m.alignment={horizontal:"right",vertical:"middle",readingOrder:"rtl"},m.fill={type:"pattern",pattern:"solid",fgColor:{argb:p}},d.getRow(1).height=26;const r=d.getRow(2);c.forEach((b,a)=>{const x=r.getCell(a+1);x.value=b.header,x.font={bold:!0,size:11,color:{argb:"FFFFFFFF"}},x.alignment={horizontal:"center",vertical:"middle",wrapText:!0,readingOrder:"rtl"},x.fill={type:"pattern",pattern:"solid",fgColor:{argb:p}}}),r.height=20,n.forEach((b,a)=>{const x=d.getRow(3+a);c.forEach((g,i)=>{const u=x.getCell(i+1);u.value=b[g.key]??"",u.font={size:10,color:{argb:"FF1E293B"}},u.alignment={horizontal:g.right?"right":"center",vertical:"middle",readingOrder:"rtl"},a%2===1&&(u.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFF8FAFC"}}),u.border={bottom:{style:"hair",color:{argb:"FFE2E8F0"}}}})})}async function ot({caravans:l,rentals:o,tickets:p},{fileName:c="קר×××× ××.xlsx"}={}){const n=(await Ce(async()=>{const{default:i}=await import("./exceljs.min-DBYZKSRA.js").then(u=>u.e);return{default:i}},__vite__mapDeps([0,1,2]))).default,d=new n.Workbook;d.creator="Eshuv";const f=i=>{var u;return((u=l.find(N=>N.id===i))==null?void 0:u.caravan_number)||""},m=i=>o.find(u=>u.caravan_id===i&&u.status==="פע×××"),r=i=>p.filter(u=>u.caravan_id===i&&u.status!=="××ש××"&&u.status!=="××××").length;Ne(d,"קר×××× ××",we("#d97706"),[{key:"num",header:"×ספר",width:10},{key:"owner",header:"××¢××ת",width:12},{key:"size",header:"××××",width:8},{key:"status",header:"ס×××ס",width:12},{key:"settlement",header:"××ש××",width:14,right:!0},{key:"tenant",header:"ש××ר פע××",width:18,right:!0},{key:"phone",header:"××פ××",width:14},{key:"end",header:"ס××× ×©××ר×ת",width:12},{key:"open",header:"קר×××ת פת×××ת",width:12},{key:"notes",header:"×ער×ת",width:24,right:!0}],[...l].sort((i,u)=>String(i.caravan_number).localeCompare(String(u.caravan_number),"he",{numeric:!0})).map(i=>{const u=m(i.id);return{num:i.caravan_number,owner:i.owner_type||"",size:i.size||"",status:i.status||"",settlement:i.settlement||"",tenant:(u==null?void 0:u.tenant_name)||"",phone:(u==null?void 0:u.tenant_phone)||"",end:ee(u==null?void 0:u.end_date),open:r(i.id)||"",notes:i.notes||""}})),Ne(d,"ש××ר×××ת",we("#059669"),[{key:"num",header:"קר××××",width:10},{key:"tenant",header:"ש××ר",width:18,right:!0},{key:"phone",header:"××פ××",width:14},{key:"start",header:"×ת×××",width:12},{key:"end",header:"ס×××",width:12},{key:"status",header:"ס×××ס",width:10},{key:"rent",header:'ש×"× (âª)',width:10},{key:"deposit",header:"פ××§××× (âª)",width:10}],[...o].map(i=>({num:f(i.caravan_id),tenant:i.tenant_name||"",phone:i.tenant_phone||"",start:ee(i.start_date),end:ee(i.end_date),status:i.status||"",rent:i.monthly_rent??"",deposit:i.deposit??""}))),Ne(d,"קר×××ת ת××××§×",we("#e11d48"),[{key:"num",header:"קר××××",width:10},{key:"title",header:"× ×ש×",width:22,right:!0},{key:"type",header:"ס××",width:12},{key:"priority",header:"×××פ×ת",width:10},{key:"status",header:"ס×××ס",width:12},{key:"opened",header:"× ×¤×ª×",width:12},{key:"target",header:"××¢×",width:12},{key:"completed",header:"××ש××",width:12},{key:"assigned",header:"××ר××",width:14,right:!0},{key:"cost",header:"×¢××ת (âª)",width:10}],[...p].map(i=>({num:f(i.caravan_id),title:i.title||"",type:i.ticket_type||"",priority:i.priority||"",status:i.status||"",opened:ee(i.opened_date),target:ee(i.target_date),completed:ee(i.completed_date),assigned:i.assigned_to||"",cost:i.cost??""})));const b=await d.xlsx.writeBuffer(),a=new Blob([b],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),x=URL.createObjectURL(a),g=document.createElement("a");g.href=x,g.download=c,document.body.appendChild(g),g.click(),g.remove(),setTimeout(()=>URL.revokeObjectURL(x),1e3)}const ct=h.lazy(()=>Ce(()=>import("./CaravanReports-C6geTtVg.js"),__vite__mapDeps([3,1,2,4,5,6,7,8,9,10]))),dt=h.lazy(()=>Ce(()=>import("./CaravanMap-DoD3fl-5.js"),__vite__mapDeps([11,1,2]))),ce={×¤× ××:{cls:"bg-emerald-50 text-emerald-700",dot:"bg-emerald-500"},××ש×ר:{cls:"bg-sky-50 text-sky-700",dot:"bg-sky-500"}
2,×ת××××§×:{cls:"bg-amber-50 text-amber-700",dot:"bg-amber-500"},"×× ××××":{cls:"bg-slate-100 text-slate-500",dot:"bg-slate-400"}},mt={פת××:"bg-amber-50 text-amber-700",×××פ××:"bg-sky-50 text-sky-700","××ת×× ××××§":"bg-purple-50 text-purple-700",××ש××:"bg-emerald-50 text-emerald-700",××××:"bg-slate-100 text-slate-500"},Se=["×§××","××××"],Fe=["×¤× ××","××ש×ר","×ת××××§×","×× ××××"],xt=["פע×××","×סת××××","×××××"],ut=["תק××","ת××××§× ××× ×¢×ª","××××§×","ש×ר××"],ht=["פת××","×××פ××","××ת×× ××××§","××ש××","××××"],bt=["× ××××","××× ×× ×ת","×××××"],pt=["ש××ר","××/×ת ×××","×××/×","××ר×","××ר"],v="w-full h-11 rounded-xl border border-slate-200 bg-white px-3 text-sm text-right focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 focus-visible:ring-offset-1 focus:border-amber-400",te=l=>{const o=String(l||"").slice(0,10);if(!o)return"â";const[p,c,n]=o.split("-");return`${n}/${c}/${p}`},de=()=>new Date().toISOString().slice(0,10),_e=l=>l.status==="פע×××"&&l.end_date&&(new Date(l.end_date)-new Date)/864e5<=30&&new Date(l.end_date)>=new Date;async function Te(l){const o=[];for(const p of l){const{file_url:c}=await k.integrations.Core.UploadFile({file:p});c&&o.push(c)}return o}function Mt(){const{id:l}=qe(),[o,p]=h.useState([]),[c,n]=h.useState([]),[d,f]=h.useState([]),[m,r]=h.useState([]),[b,a]=h.useState([]),[x,g]=h.useState([]),[i,u]=h.useState([]),[N,w]=h.useState(""),[I,B]=h.useState(!0),[q,H]=h.useState(""),[$,L]=h.useState(null),[M,ae]=h.useState(null),[K,T]=h.useState(""),[Y,le]=h.useState(!1),[Z,ne]=h.useState(!1),[ue,E]=h.useState(null),[he,re]=h.useState(null),[je,G]=h.useState(!1),[V,t]=h.useState(!1),[C,S]=h.useState(!1),[P,A]=h.useState("list"),O=h.useCallback(async()=>{B(!0);try{const[s,_,F,J,U,D]=await Promise.all([k.entities.Caravan.filterAll({kibbutz_id:l},"-created_date"),k.entities.CaravanRental.filterAll({kibbutz_id:l},"-created_date"),k.entities.CaravanOccupant.filterAll({kibbutz_id:l},"-created_date"),k.entities.CaravanMaintenanceTicket.filterAll({kibbutz_id:l},"-created_date"),k.entities.CaravanDocument.filterAll({kibbutz_id:l},"-created_date").catch(()=>[]),k.entities.CaravanOwnerType.filter({kibbutz_id:l},"sort",200).catch(()=>[])]);p(s||[]),n(_||[]),f(F||[]),r(J||[]),a(U||[]),g(D||[])}catch(s){console.error(s),y.error("ש×××× ×××¢×× ×ª ×× ×ª×× ××")}finally{B(!1)}},[l]);h.useEffect(()=>{O()},[O]),h.useEffect(()=>{k.entities.Resident.filterAll({kibbutz_id:l,is_deleted:tt},"full_name").then(u).catch(()=>{}),k.auth.me().then(s=>w((s==null?void 0:s.email)||"")).catch(()=>{})},[l]);const Ee=s=>c.find(_=>_.caravan_id===s&&_.status==="פע×××"),Oe=s=>m.filter(_=>_.caravan_id===s&&_.status!=="××ש××"&&_.status!=="××××"),be=x.length?x.map(s=>s.name):[...new Set(o.map(s=>s.owner_type).filter(Boolean))],Q=h.useMemo(()=>({total:o.length,available:o.filter(s=>s.status==="×¤× ××").length,rented:o.filter(s=>s.status==="××ש×ר").length,maintenance:o.filter(s=>s.status==="×ת××××§×").length,openTickets:m.filter(s=>s.status!=="××ש××"&&s.status!=="××××").length,endingSoon:c.filter(_e).length}),[o,m,c]),ze=o.filter(s=>{const _=q.trim(),F=Ee(s.id);return!(!(!_||String(s.caravan_number).includes(_)||(s.notes||"").includes(_)||(s.address||"").includes(_)||((F==null?void 0:F.tenant_name)||"").includes(_))||$&&s.status!==$||M&&s.size!==M||K&&s.owner_type!==K||Y&&Oe(s.id).length===0||Z&&!c.some(U=>U.caravan_id===s.id&&_e(U)))}),Ke=$||M||K||Y||Z||q,Ve=()=>{L(null),ae(null),T(""),le(!1),ne(!1),H("")},Je=async s=>{try{s.id?await k.entities.Caravan.update(s.id,s):await k.entities.Caravan.create({...s,kibbutz_id:l}),y.success("× ×©×ר"),re(null),O()}catch(_){console.error(_),y.error("ש×××× ×ש××ר×")}},We=async s=>{if(window.confirm(`×××××§ ×ת קר×××× ${s.caravan_number}? ×פע××× ×ª×××§ ×× ×©××ר×××ת, ×××ר×× ×קר×××ת ת××××§×.`))try{await Promise.all([...c.filter(_=>_.caravan_id===s.id).map(_=>k.entities.CaravanRental.delete(_.id)),...d.filter(_=>_.caravan_id===s.id).map(_=>k.entities.CaravanOccupant.delete(_.id)),...m.filter(_=>_.caravan_id===s.id).map(_=>k.entities.CaravanMaintenanceTicket.delete(_.id))]),await k.entities.Caravan.delete(s.id),y.success("× ×××§"),E(null),O()}catch(_){console.error(_),y.error("ש×××× ×××××§×")}};if(I)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"w-8 h-8 border-4 border-amber-200 border-t-amber-500 rounded-full animate-spin"})});const X=ue?o.find(s=>s.id===ue):null;return e.jsxs("div",{dir:"rtl",children:[e.jsx("div",{className:"flex mb-6",children:e.jsx(st,{title:"קר×××× ×× ×ת××××§×",items:[{label:"××סף קר××××",icon:De,iconBg:"bg-amber-50",iconColor:"text-amber-600",onClick:()=>re({status:"×¤× ××"})}
2,{label:"רש××ת קר×××× ××",icon:ve,iconBg:"bg-slate-100",iconColor:"text-slate-600",onClick:()=>{A("list"),E(null),S(!1)}},{label:"××××ת",icon:He,iconBg:"bg-indigo-50",iconColor:"text-indigo-600",onClick:()=>{A("reports"),E(null),S(!1)}},{label:"×פ×",icon:Ye,iconBg:"bg-teal-50",iconColor:"text-teal-600",onClick:()=>{A("map"),E(null),S(!1)}},{label:"××××× × ×ª×× ×× (×-Base44)",icon:me,iconBg:"bg-blue-50",iconColor:"text-blue-600",separatorBefore:!0,onClick:()=>G(!0)},{label:"××צ×× ××קס×",icon:Ze,iconBg:"bg-emerald-50",iconColor:"text-emerald-600",onClick:()=>ot({caravans:o,rentals:c,tickets:m},{fileName:`קר×××× ××-${de()}.xlsx`}).catch(()=>y.error("ש×××× ×××צ××"))},{label:"×××ר ת××©× ××ר××",icon:Ge,iconBg:"bg-fuchsia-50",iconColor:"text-fuchsia-600",separatorBefore:!0,onClick:()=>{S(!0),E(null)}},{label:"ס××× ××¢××ת",icon:lt,iconBg:"bg-slate-100",iconColor:"text-slate-600",onClick:()=>t(!0)}]})}),C?e.jsx(at,{inline:!0,kibbutzId:l,moduleKey:"caravans",title:"×××ר ת××©× ××ר×× ×קר××××",subtitle:"××× ×§×¨×××× × ××ª× ×××××ר ת××©× ××ר×× â ××× ××§×× ×תר×× ×¢× ×§×¨××ת ת××××§× ×××©× ××××× ×××¤× ×× ×××××ר ×××ש×",scopes:o.map(s=>({id:s.id,label:`קר×××× #${s.caravan_number}`})),onOpenChange:s=>{s||S(!1)}}):X?e.jsx(gt,{communityId:l,me:N,residents:i,ownerNames:be,caravan:X,rentals:c.filter(s=>s.caravan_id===X.id),occupants:d.filter(s=>s.caravan_id===X.id),tickets:m.filter(s=>s.caravan_id===X.id),documents:b.filter(s=>s.caravan_id===X.id),onChanged:O,onBack:()=>E(null)}):P==="reports"?e.jsxs(e.Fragment,{children:[e.jsx(Be,{onBack:()=>A("list"),label:"××××ת קר×××× ××"}),e.jsx(h.Suspense,{fallback:e.jsx(Ae,{}),children:e.jsx(ct,{caravans:o,rentals:c,tickets:m})})]}):P==="map"?e.jsxs(e.Fragment,{children:[e.jsx(Be,{onBack:()=>A("list"),label:"×פת קר×××× ××"}),e.jsx(h.Suspense,{fallback:e.jsx(Ae,{}),children:e.jsx(dt,{caravans:o})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-6 gap-3 mb-6",children:[{label:'ס×"× ×§×¨×××× ××',value:Q.total,icon:Ie,color:"text-slate-600",bg:"bg-slate-50",st:null},{label:"×¤× ××××",value:Q.available,icon:Pe,color:"text-emerald-600",bg:"bg-emerald-50",st:"×¤× ××"},{label:"××ש×ר××",value:Q.rented,icon:ve,color:"text-sky-600",bg:"bg-sky-50",st:"××ש×ר"},{label:"×ת××××§×",value:Q.maintenance,icon:Re,color:"text-amber-600",bg:"bg-amber-50",st:"×ת××××§×"},{label:"קר×××ת פת×××ת",value:Q.openTickets,icon:Re,color:"text-rose-600",bg:"bg-rose-50",st:"open"},{label:"ש××ר×××ת ×סת××××ת",value:Q.endingSoon,icon:nt,color:"text-orange-600",bg:"bg-orange-50",st:"ending"}].map((s,_)=>{const F=s.st==="open"&&Y||s.st==="ending"&&Z||s.st&&s.st!=="open"&&s.st!=="ending"&&$===s.st,J=s.icon,U=()=>{s.st==="open"?le(D=>!D):s.st==="ending"?ne(D=>!D):s.st&&L(F?null:s.st)};return e.jsxs("button",{onClick:U,disabled:s.st===null,className:`bg-white rounded-2xl border p-4 text-right transition-all ${s.st!==null?"hover:shadow-md cursor-pointer":"cursor-default"} ${F?"ring-2 ring-amber-300 border-amber-300":"border-slate-100"}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-lg ${s.bg} flex items-center justify-center mb-2`,children:e.jsx(J,{className:`w-5 h-5 ${s.color}`})}),e.jsx("p",{className:"text-2xl font-bold text-slate-800",children:s.value}),e.jsx("p",{className:"text-xs text-slate-500",children:s.label})]},_)})}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 shadow-sm p-3 mb-5 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative w-full sm:w-80 flex-none",children:[e.jsx(Qe,{className:"absolute right-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{value:q,onChange:s=>H(s.target.value),placeholder:"××פ×ש ×ספר / ש××ר / ×ת××ת / ×ער×...",className:"w-full h-11 rounded-full border border-slate-200 bg-slate-50 pr-10 pl-4 text-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 focus-visible:ring-offset-1 focus:border-amber-400 focus:bg-white"})]}),Ke&&e.jsx("button",{onClick:Ve,className:"text-sm font-bold text-slate-500 hover:text-slate-700 mr-auto",children:"× ×§× ×¡×× ××"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2",children:[e.jsx(pe,{label:"ס×××ס",children:Fe.map(s=>{var _;return e.jsx(ie,{active:$===s,dot:(_=ce[s])==null?void 0:_.dot,onClick:()=>L($===s?null:s),children:s},s)})}),e.jsx(ke,{}),e.jsx(pe,{label:"××××",children:Se.map(s=>e.jsx(ie,{active:M===s,onClick:()=>ae(M===s?null:s),children:s},s))}),be.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{}),e.jsx(pe,{label:"××¢××ת",children:be.map(s=>e.jsx(ie,{active:K===s,onClick:()=>T(K===s?"":s),children:s},s))})]}),e.jsx(ke,{}),e.jsxs(pe,{label:"ת××××§×",children:[e.jsx(ie,{active:Y,dot:"bg-rose-500",onClick:()=>le(s=>!s),children:"×¢× ×§×¨×××ת פת×××ת"}),e.jsx(ie,{active:Z,dot:"bg-orange-500",onClick:()=>ne(s=>!s),children:"ש××ר×ת ×סת×××ת"})]})]})]}),ze.length===0?e.jsxs("div",{className:"text-center py-20 bg-white rounded-2xl border border-slate-100",children:[e.jsx(ve,{className:"w-12 h-12 text-slate-300 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:o.length?"×× × ×צ×× ×§×¨×××× ×× ×ס×× ××":"××× ×§×¨×××× ×× ×¢××××"}),o.length===0&&e.jsxs("button",{onClick:()=>G(!0),className:"inline-flex items-center gap-2 h-11 px-6 rounded-full bg-blue-600 text-white text-sm font-bold shadow-md hover:bg-blue-700",children:[e.jsx(me,{className:"w-4 h-4"})," ××××× × ×ª×× ××"]})]}):e.jsx("div",{className:"bg-white rounded-2xl border border-slate-100 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",{children:e.jsxs("tr",{className:"border-b border-slate-100 bg-slate-50 text-slate-500 text-xs",children:[e.jsx("th",{className:"text-right font-semibold px-4 py-3",children:"×ספר קר××××"}),e.jsx("th",{className:"text-right font-semibold px-4 py-3",children:"×ת××ת"}),e.jsx("th",{className:"text-right font-semibold px-4 py-3",children:"××××"}),e.jsx("th",{className:"text-right font-semibold px-4 py-3",children:"ס×××ס"}),e.jsx("th",{className:"text-right font-semibold px-4 py-3",children:"ש××ר"}),e.jsx("th",{className:"text-right font-semibold px-4 py-3",children:"ת×ר×× ×¡×××"}),e.jsx("th",{className:"text-center font-semibold px-4 py-3",children:"ת××××§×"}),e.jsx("th",{className:"text-center font-semibold px-4 py-3",children:"פע×××ת"})]})}),e.jsx("tbody",{children:ze.map(s=>{const _=ce[s.status]||ce.×¤× ××,F=Ee(s.id),J=Oe(s.id).length,U=F&&_e(F);return e.jsxs("tr",{className:"border-b border-slate-50 last:border-0 hover:bg-amber-50/40 cursor-pointer",onClick:()=>E(s.id),children:[e.jsxs("td",{className:"px-4 py-2.5 font-bold text-slate-800 whitespace-nowrap",children:["#",s.caravan_number]}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:s.address||"â"}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:s.size||"â"}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full ${_.cls}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${_.dot}`}),s.status]})}),e.jsx("td",{className:"px-4 py-2.5 text-slate-600",children:(F==null?void 0:F.tenant_name)||"â"}),e.jsx("td",{className:`px-4 py-2.5 whitespace-nowrap ${U?"text-orange-600 font-bold":"text-slate-600"}`,children:F?te(F.end_date):"â"}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:J>0?e.jsx("span",{className:"inline-block bg-rose-50 text-rose-700 text-xs font-bold rounded-full px-2 py-0.5",children:J}):"â"}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx("button",{onClick:D=>{D.stopPropagation(),E(s.id)},className:"w-8 h-8 rounded-lg hover:bg-amber-100 text-amber-600 flex items-center justify-center",title:"× ××××",children:e.jsx(oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:D=>{D.stopPropagation(),We(s)},className:"w-8 h-8 rounded-lg hover:bg-rose-100 text-rose-500 flex items-center justify-center",title:"××××§×",children:e.jsx(fe,{className:"w-4 h-4"})}),e.jsx(rt,{className:"w-4 h-4 text-slate-300"})]})})]},s.id)})})]})})})]}),he&&e.jsx(Nt,{caravan:he,ownerNames:be,onSave:Je,onClose:()=>re(null)}),je&&e.jsx(_t,{communityId:l,onClose:()=>G(!1),onDone:O}),V&&e.jsx(kt,{communityId:l,ownerTypes:x,caravans:o,onClose:()=>t(!1),onDone:O})]})}const ie=({active:l,onClick:o,children:p,dot:c})=>e.jsxs("button",{onClick:o,className:`inline-flex items-center gap-1.5 h-9 px-3.5 rounded-full text-sm font-bold border transition-all ${l?"bg-amber-500 text-white border-amber-500 shadow-sm":"bg-white text-slate-600 border-slate-200 hover:border-amber-300"}`,children:[c&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${l?"bg-white":c}`}),p]}),pe=({label:l,children:o})=>e.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs font-bold text-slate-400 ml-0.5",children:[l,":"]}
2),o]}),ke=()=>e.jsx("span",{className:"w-px h-6 bg-slate-200 mx-0.5 hidden sm:inline-block"}),Be=({onBack:l,label:o})=>e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsxs("button",{onClick:l,className:"inline-flex items-center gap-1.5 h-9 px-3.5 rounded-full bg-white border border-slate-200 shadow-sm text-sm font-bold text-slate-600 hover:border-amber-300",children:[e.jsx(Ue,{className:"w-4 h-4"})," ×××¨× ×רש×××"]}),e.jsx("h3",{className:"text-base font-bold text-slate-700",children:o})]});function $e({children:l,onClose:o,wide:p}){return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",dir:"rtl",children:[e.jsx("div",{className:"absolute inset-0 bg-slate-900/50 backdrop-blur-sm",onClick:o}),e.jsx("div",{className:`relative bg-white rounded-3xl shadow-2xl w-full ${p?"max-w-3xl":"max-w-lg"} max-h-[92vh] overflow-hidden flex flex-col`,children:l})]})}const se=({children:l})=>e.jsx("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-md overflow-hidden mb-3",children:l}),j=({label:l,children:o})=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-bold text-slate-500 mb-1.5",children:l}),o]}),ge=({text:l})=>e.jsx("div",{className:"text-center py-8 text-sm text-slate-400",children:l}),Ae=()=>e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"w-8 h-8 border-4 border-amber-200 border-t-amber-500 rounded-full animate-spin"})});function z({label:l,value:o,type:p="text",options:c,onSave:n,full:d}){const[f,m]=h.useState(!1),[r,b]=h.useState(o??""),[a,x]=h.useState(!1);h.useEffect(()=>{f||b(o??"")},[o,f]);const g=async()=>{if(String(r??"")===String(o??"")){m(!1);return}x(!0);const w=await n(r);x(!1),m(!1),w===!1&&b(o??"")},i=()=>{b(o??""),m(!1)},u=w=>{w.key==="Enter"&&p!=="textarea"&&(w.preventDefault(),g()),w.key==="Escape"&&i()},N="w-full rounded-lg border border-amber-300 bg-white px-2 text-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-400 focus-visible:ring-offset-1";return e.jsxs("div",{className:`relative overflow-hidden rounded-xl border border-amber-100 bg-amber-50/40 pr-4 pl-3 py-2.5 transition-colors hover:border-amber-300 hover:bg-amber-50/70 ${d?"col-span-2":""}`,children:[e.jsx("span",{className:"absolute inset-y-0 right-0 w-1 bg-amber-300/70"}),e.jsxs("p",{className:"text-[0.625rem] font-bold uppercase tracking-wider text-amber-600/80 mb-1 flex items-center gap-1",children:[l,a&&e.jsx(xe,{className:"w-3 h-3 animate-spin"})]}),f?c?e.jsxs("select",{autoFocus:!0,className:`${N} h-9`,value:r,onChange:w=>b(w.target.value),onBlur:g,onKeyDown:u,children:[e.jsx("option",{value:"",children:"â"}),c.map(w=>e.jsx("option",{value:w,children:w},w))]}):p==="textarea"?e.jsx("textarea",{autoFocus:!0,className:`${N} py-1.5 h-16`,value:r,onChange:w=>b(w.target.value),onBlur:g,onKeyDown:u}):e.jsx("input",{autoFocus:!0,className:`${N} h-9`,value:r,onChange:w=>b(w.target.value),onBlur:g,onKeyDown:u}):e.jsxs("button",{onClick:()=>m(!0),className:"group w-full text-right flex items-center justify-between gap-2",children:[e.jsx("span",{className:`text-[0.9375rem] font-extrabold break-words leading-tight ${o?"text-slate-800":"text-slate-300 font-bold"}`,children:o||"××סף"}),e.jsx(oe,{className:"w-3 h-3 text-amber-400 opacity-0 group-hover:opacity-100 transition-opacity flex-none"})]})]})}function Me({residents:l,onPick:o}){const[p,c]=h.useState(""),n=p.trim()?l.filter(d=>(d.full_name||"").includes(p.trim())||String(d.phone||"").includes(p.trim())).slice(0,8):[];return e.jsxs("div",{className:"relative",children:[e.jsx("input",{className:v,value:p,onChange:d=>c(d.target.value),placeholder:"××פ×ש ת××©× ××¤× ×©×/××פ×× (×× ××××)"}),n.length>0&&e.jsx("div",{className:"absolute z-30 mt-1 w-full rounded-xl border border-slate-200 bg-white shadow-lg max-h-56 overflow-y-auto",children:n.map(d=>e.jsxs("button",{onClick:()=>{o(d),c("")},className:"w-full text-right px-3 py-2 text-sm hover:bg-slate-50 flex items-center justify-between",children:[e.jsx("span",{className:"font-medium text-slate-700",children:d.full_name}),e.jsx("span",{className:"text-xs text-slate-400",dir:"ltr",children:d.phone})]},d.id))})]})}function gt({communityId:l,me:o,residents:p,ownerNames:c,caravan:n,rentals:d,occupants:f,tickets:m,documents:r,onChanged:b,onBack:a}){const[x,g]=h.useState("rental"),[i,u]=h.useState(null),[N,w]=h.useState(null),[I,B]=h.useState(null),[q,H]=h.useState(null),[$,L]=h.useState(null),M=[["rental",`ש××ר×××ת (${d.length})`],["occupants",`×××ר×× (${f.length})`],["maintenance",`ת××××§× (${m.length})`],["documents",`×ס×××× (${r.length})`]],ae=async t=>{try{await k.entities.Caravan.update(n.id,{status:t})}catch{}},K=async t=>{try{await k.entities.Caravan.update(n.id,{status:t}),y.success("×ס×××ס ×¢××××"),b()}catch{y.error("ש××××")}},T=async(t,C)=>{const S=C===""?null:C;if(t==="caravan_number"&&(S==null||!String(S).trim()))return y.error("×ספר קר×××× ××× ×©×× ××××"),!1;try{return await k.entities.Caravan.update(n.id,{[t]:S}
2),y.success("× ×©×ר"),b(),!0}catch(P){return console.error(P),y.error("ש×××× ×ש××ר×"),!1}},Y=async t=>{try{const C={...t,caravan_id:n.id,kibbutz_id:l};t.id?await k.entities.CaravanRental.update(t.id,C):await k.entities.CaravanRental.create(C),t.status==="פע×××"&&await ae("××ש×ר"),y.success("× ×©×ר"),u(null),b()}catch(C){console.error(C),y.error("ש×××× ×ש××ר×")}},le=async t=>{if(window.confirm("×ס××× ×ת ×ש××ר×ת?"))try{await k.entities.CaravanRental.update(t.id,{status:"×סת××××"}),d.some(S=>S.id!==t.id&&S.status==="פע×××")||await ae("×¤× ××"),y.success("×ש××ר×ת ×סת××××"),b()}catch(C){console.error(C),y.error("ש××××")}},Z=async t=>{if(window.confirm("×××××§ ש××ר×ת ××?"))try{await k.entities.CaravanRental.delete(t.id),b()}catch{y.error("ש××××")}},ne=async t=>{var C;try{const S={...t,caravan_id:n.id,kibbutz_id:l,rental_id:t.rental_id||((C=d.find(P=>P.status==="פע×××"))==null?void 0:C.id)||null};t.id?await k.entities.CaravanOccupant.update(t.id,S):await k.entities.CaravanOccupant.create(S),y.success("× ×©×ר"),w(null),b()}catch(S){console.error(S),y.error("ש×××× ×ש××ר×")}},ue=async t=>{if(window.confirm("×××××§ ×××ר ××?"))try{await k.entities.CaravanOccupant.delete(t.id),b()}catch{y.error("ש××××")}},E=async t=>{try{const C={...t,caravan_id:n.id,kibbutz_id:l};if(t.id)await k.entities.CaravanMaintenanceTicket.update(t.id,C);else{const S=await k.entities.CaravanMaintenanceTicket.create({...C,opened_date:t.opened_date||de(),status:t.status||"פת××"});S!=null&&S.id&&k.functions.invoke("notifyResponsibleItem",{community_id:l,module_key:"caravans",item_id:S.id}).catch(()=>{})}y.success("× ×©×ר"),B(null),b()}catch(C){console.error(C),y.error("ש×××× ×ש××ר×")}},he=async t=>{try{const C={...t,caravan_id:n.id,kibbutz_id:l,related_type:"קר××××",related_id:n.id};t.id?await k.entities.CaravanDocument.update(t.id,C):await k.entities.CaravanDocument.create(C),y.success("× ×©×ר"),L(null),b()}catch(C){console.error(C),y.error("ש×××× ×ש××ר×")}},re=async t=>{if(window.confirm("×××××§ ×ס×× ××?"))try{await k.entities.CaravanDocument.delete(t.id),b()}catch{y.error("ש××××")}},je=async(t,{status:C,note:S,imagesAfter:P})=>{try{const A={date:new Date().toISOString(),user:o,action:`ס×××ס: ${C}`,details:S||""},O={status:C,activity_log:[...Array.isArray(t.activity_log)?t.activity_log:[],A],images_after:[...Array.isArray(t.images_after)?t.images_after:[],...P||[]]};C==="××ש××"&&!t.completed_date&&(O.completed_date=de()),await k.entities.CaravanMaintenanceTicket.update(t.id,O),y.success("×קר××× ×¢×××× ×"),H(null),b()}catch(A){console.error(A),y.error("ש×××× ××¢××××")}},G=ce[n.status]||ce.×¤× ××,V={rental:{label:"ש××ר×ת ××ש×",cls:"bg-emerald-600 hover:bg-emerald-700",open:!!i,onClick:()=>u({status:"פע×××",start_date:de()})},occupants:{label:"××סף ×××ר",cls:"bg-sky-600 hover:bg-sky-700",open:!!N,onClick:()=>w({relationship:"ש××ר"})},maintenance:{label:"קר××× ××ש×",cls:"bg-rose-600 hover:bg-rose-700",open:!!I,onClick:()=>B({ticket_type:"תק××",priority:"××× ×× ×ת",status:"פת××"})},documents:{label:"××¢×× ×ס××",cls:"bg-slate-700 hover:bg-slate-800",open:!!$,onClick:()=>L({document_type:"××××"})}}[x];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-gradient-to-l from-amber-600 to-amber-500 text-white rounded-2xl shadow-sm px-4 py-3.5 flex items-center gap-3",children:[e.jsx("button",{onClick:a,className:"w-9 h-9 rounded-lg bg-white/15 hover:bg-white/25 flex items-center justify-center flex-none",title:"×××¨× ×רש×××",children:e.jsx(Ue,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-bold leading-tight",children:["קר×××× #",n.caravan_number]}),e.jsx("p",{className:"text-xs text-white/85",children:[n.owner_type,n.size,n.settlement].filter(
2Boolean).join(" · ")||"× ×××× ×קר××××"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4 items-start",children:[e.jsx("div",{className:"lg:col-span-1",children:e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 shadow-sm p-4",children:[e.jsxs("h4",{className:"text-sm font-bold text-slate-700 mb-3 flex items-center gap-1.5",children:[e.jsx(Ie,{className:"w-4 h-4 text-amber-500"})," פר×× ×קר×××× ",e.jsx("span",{className:"text-[0.6875rem] font-normal text-slate-400",children:"· ×××¦× ×ער×××"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(z,{label:"×ספר קר××××",value:n.caravan_number,onSave:t=>T("caravan_number",t)}),e.jsx(z,{label:"××¢××ת",value:n.owner_type,options:[...new Set([...c,n.owner_type].filter(Boolean))],onSave:t=>T("owner_type",t)}),e.jsx(z,{label:"××××",value:n.size,options:Se,onSave:t=>T("size",t)}),e.jsx(z,{label:"××ש××",value:n.settlement,onSave:t=>T("settlement",t)}),e.jsx(z,{label:"××עצ×",value:n.council,onSave:t=>T("council",t)}),e.jsx(z,{label:"×××ת × ××§×××",value:n.identity_nokedim,onSave:t=>T("identity_nokedim",t)}),e.jsx(z,{label:"×××ת ××עצ×",value:n.identity_council,onSave:t=>T("identity_council",t)}),e.jsx(z,{label:"×××ת ××× ×",value:n.identity_amana,onSave:t=>T("identity_amana",t)}),e.jsx(z,{label:"×ת××ת",value:n.address,onSave:t=>T("address",t),full:!0}),e.jsx(z,{label:"×ער×ת",value:n.notes,type:"textarea",onSave:t=>T("notes",t),full:!0})]})]})}),e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 pt-3 border-b border-slate-100 flex-wrap",children:[e.jsx("div",{className:"flex gap-1 flex-wrap",children:M.map(([t,C])=>e.jsx("button",{onClick:()=>g(t),className:`px-3.5 py-2 text-sm font-bold rounded-t-lg ${x===t?"text-amber-700 border-b-2 border-amber-500":"text-slate-500 hover:text-slate-700"}`,children:C},t))}),V&&!V.open&&e.jsxs("button",{onClick:V.onClick,className:`inline-flex items-center gap-1.5 h-9 px-4 rounded-full text-white text-sm font-bold shadow-sm mb-2 ${V.cls}`,children:[e.jsx(De,{className:"w-4 h-4"})," ",V.label]})]}),e.jsxs("div",{className:"p-4",children:[x==="rental"&&e.jsxs("div",{children:[i&&e.jsx(jt,{rental:i,residents:p,onSave:Y,onClose:()=>u(null)}),e.jsx("div",{className:"space-y-2",children:d.length?d.map(t=>e.jsxs("div",{className:`rounded-xl border p-3 ${t.status==="פע×××"?"border-emerald-200 bg-emerald-50/40":"border-slate-100"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-bold text-slate-800",children:[t.tenant_name||"â"," ",t.resident_id&&e.jsx("span",{className:"text-[0.625rem] bg-sky-50 text-sky-700 rounded-full px-1.5 py-0.5",children:"ת×ש×"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-slate-500",children:t.status}),e.jsx("button",{onClick:()=>u(t),className:"text-slate-400 hover:text-slate-600",children:e.jsx(oe,{className:"w-3.5 h-3.5"})}),t.status==="פע×××"&&e.jsx("button",{onClick:()=>le(t),className:"text-xs font-bold text-amber-600 hover:underline",children:"ס×××"}),e.jsx("button",{onClick:()=>Z(t),className:"text-rose-400 hover:text-rose-600",children:e.jsx(fe,{className:"w-3.5 h-3.5"})})]})]}),e.jsxs("div",{className:"text-xs text-slate-500 mt-1",children:[te(t.start_date)," â ",te(t.end_date)," · ",t.tenant_phone||"â"," ",t.monthly_rent?`· ${ye(t.monthly_rent)}`:""," ",t.deposit?`· פ××§××× ${ye(t.deposit)}`:""]})]},t.id)):e.jsx(ge,{text:"××× ×©××ר×××ת"})})]}),x==="occupants"&&e.jsxs("div",{children:[N&&e.jsx(vt,{occupant:N,residents:p,onSave:ne,onClose:()=>w(null)}),e.jsx("div",{className:"space-y-2",children:f.length?f.map(t=>e.jsxs("div",{className:"rounded-xl border border-slate-100 p-3 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-slate-700",children:t.full_name}),e.jsx("span",{className:"text-xs text-slate-500 block",children:[t.relationship,t.phone,t.id_number].filter(
2Boolean).join(" · ")})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>w(t),className:"text-slate-400 hover:text-slate-600",children:e.jsx(oe,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:()=>ue(t),className:"text-rose-400 hover:text-rose-600",children:e.jsx(fe,{className:"w-3.5 h-3.5"})})]})]},t.id)):e.jsx(ge,{text:"××× ×××ר××"})})]}),x==="maintenance"&&e.jsxs("div",{children:[I&&e.jsx(yt,{ticket:I,onSave:E,onClose:()=>B(null)}),q&&e.jsx(wt,{ticket:q,onSave:je,onClose:()=>H(null)}),e.jsx("div",{className:"space-y-2",children:m.length?m.map(t=>e.jsxs("div",{className:"rounded-xl border border-slate-100 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-bold text-slate-800",children:t.title}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`text-xs font-medium px-2 py-0.5 rounded-full ${mt[t.status]||"bg-slate-100 text-slate-500"}`,children:t.status}),e.jsx("button",{onClick:()=>B(t),className:"text-slate-400 hover:text-slate-600",children:e.jsx(oe,{className:"w-3.5 h-3.5"})})]})]}),e.jsx("div",{className:"text-xs text-slate-500 mt-1",children:[t.ticket_type,t.priority,t.opened_date&&`× ×¤×ª× ${te(t.opened_date)}`,t.assigned_to&&`××ר××: ${t.assigned_to}`,t.cost&&ye(t.cost)].filter(Boolean).join(" · ")}),t.description&&e.jsx("p",{className:"text-sm text-slate-600 mt-1",children:t.description}),(Array.isArray(t.images_before)&&t.images_before.length>0||Array.isArray(t.images_after)&&t.images_after.length>0)&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:[...t.images_before||[],...t.images_after||[]].map((C,S)=>e.jsx("a",{href:C,target:"_blank",rel:"noopener noreferrer",children:e.jsx("img",{src:C,alt:"",className:"w-12 h-12 rounded-lg object-cover ring-1 ring-slate-200"})},S))}),t.status!=="××ש××"&&t.status!=="××××"&&e.jsx("button",{onClick:()=>H(t),className:"mt-2 text-xs font-bold text-amber-700 hover:underline",children:"×¢××× ×¡×××ס"})]},t.id)):e.jsx(ge,{text:"××× ×§×¨×××ת ת××××§×"})})]}),x==="documents"&&e.jsxs("div",{children:[$&&e.jsx(ft,{doc:$,onSave:he,onClose:()=>L(null)}),r.length?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:r.map(t=>e.jsxs("div",{className:"rounded-xl border border-slate-100 p-3 flex items-center gap-3",children:[e.jsx("span",{className:"w-9 h-9 rounded-lg bg-slate-100 flex items-center justify-center flex-none",children:e.jsx(Xe,{className:"w-4.5 h-4.5 text-slate-500"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-semibold text-slate-700 truncate",children:t.name}),e.jsx("p",{className:"text-xs text-slate-400",children:[t.document_type,te(t.document_date)!=="â"&&te(t.document_date)].filter(Boolean).join(" · ")})]}),t.file_url&&e.jsx("a",{href:t.file_url,target:"_blank",rel:"noopener noreferrer",className:"text-amber-600 hover:text-amber-700",children:e.jsx(et,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>re(t),className:"text-rose-400 hover:text-rose-600",children:e.jsx(fe,{className:"w-4 h-4"})})]},t.id))}):e.jsx(ge,{text:"××× ×ס××××"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-slate-100 shadow-sm p-3.5 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-bold text-slate-700",children:"ס×××ס × ××××"}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full ${G.cls}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${G.dot}`}),n.status]})]}),e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:Fe.map(t=>e.jsx("button",{onClick:()=>K(t),disabled:n.status===t,className:`h-9 px-4 rounded-full text-xs font-bold border transition-all ${n.status===t?"bg-amber-500 text-white border-amber-500":"bg-white text-slate-600 border-slate-200 hover:border-amber-300"}`,children:t},t))})]})]})]})]})}function ft({doc:l,onSave:o,onClose:p}){const c=["××××","× ×¡×¤×","×§×××","×צעת ×××ר","××× ××× ××","ת××× ×","××ר"],[n,d]=h.useState({name:"",document_type:"××××",document_date:"",file_url:"",notes:"",...l}),[f,m]=h.useState(!1),r=(x,g)=>d(i=>({...i,[x]:g})),b=async x=>{var i;const g=(i=x.target.files)==null?void 0:i[0];if(x.target.value="",!!g){m(!0);try{const[u]=await Te([g]);d(N=>({...N,file_url:u,name:N.name||g.name}))}catch{y.error("ש×××× ×××¢×××")}finally{m(!1)}}},a=()=>{var x;if(!((x=n.name)!=null&&x.trim())){y.error("×ש ××××× ×©× ×ס××");return}if(!n.file_url){y.error("×ש ×××¢××ת ×§×××¥");return}o(n)};return e.jsxs(se,{children:[e.jsxs("div",{className:"px-5 py-3 bg-gradient-to-l from-slate-700 to-slate-600 text-white flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-bold",children:l!=null&&l.id?"ער××ת ×ס××":"××¢××ת ×ס××"}),e.jsx("button",{"aria-label":"ס××ר×",onClick:p,className:"w-8 h-8 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-4.5 h-4.5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsx(j,{label:"×§×××¥ *",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5 h-11 px-4 roun
2ded-full border-2 border-slate-200 text-sm font-bold text-slate-600 hover:bg-slate-50 cursor-pointer",children:[e.jsx("input",{type:"file",accept:".pdf,.doc,.docx,.xls,.xlsx,image/*",className:"hidden",onChange:b}),f?e.jsx(xe,{className:"w-4 h-4 animate-spin"}):e.jsx(me,{className:"w-4 h-4"})," ××ר ×§×××¥"]}),n.file_url&&e.jsx("a",{href:n.file_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-emerald-600 font-bold",children:"××§×××¥ ×××¢×× â"})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(j,{label:"×©× ×ס×× *",children:e.jsx("input",{className:v,value:n.name,onChange:x=>r("name",x.target.value)})}),e.jsx(j,{label:"ס××",children:e.jsx("select",{className:v,value:n.document_type,onChange:x=>r("document_type",x.target.value),children:c.map(x=>e.jsx("option",{value:x,children:x},x))})}),e.jsx(j,{label:"ת×ר×× ×ס××",children:e.jsx("input",{type:"date",className:v,value:n.document_date||"",onChange:x=>r("document_date",x.target.value)})})]}),e.jsx(j,{label:"×ער×ת",children:e.jsx("textarea",{className:`${v} h-16 py-2`,value:n.notes||"",onChange:x=>r("notes",x.target.value)})})]}),e.jsx(W,{onClose:p,onSubmit:a,tone:"amber",disabled:f})]})}function jt({rental:l,residents:o,onSave:p,onClose:c}){const[n,d]=h.useState({tenant_name:"",tenant_phone:"",tenant_email:"",start_date:de(),end_date:"",status:"פע×××",monthly_rent:"",deposit:"",notes:"",resident_id:null,...l}),f=(r,b)=>d(a=>({...a,[r]:b})),m=()=>{var r;if(!((r=n.tenant_name)!=null&&r.trim())){y.error("×ש ××××× ×©× ×©××ר");return}p({...n,monthly_rent:n.monthly_rent===""?null:Number(n.monthly_rent),deposit:n.deposit===""?null:Number(n.deposit)})};return e.jsxs(se,{children:[e.jsxs("div",{className:"px-5 py-3 bg-gradient-to-l from-emerald-600 to-emerald-500 text-white flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-bold",children:l!=null&&l.id?"ער××ת ש××ר×ת":"ש××ר×ת ××ש×"}),e.jsx("button",{"aria-label":"ס××ר×",onClick:c,className:"w-8 h-8 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-4.5 h-4.5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsx(j,{label:"×××רת ת××©× ×××××ר",children:e.jsx(Me,{residents:o,onPick:r=>d(b=>({...b,resident_id:r.id,tenant_name:r.full_name||b.tenant_name,tenant_phone:r.phone||b.tenant_phone}))})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(j,{label:"×©× ×©××ר *",children:e.jsx("input",{className:v,value:n.tenant_name,onChange:r=>f("tenant_name",r.target.value)})}),e.jsx(j,{label:"××פ××",children:e.jsx("input",{className:v,value:n.tenant_phone||"",onChange:r=>f("tenant_phone",r.target.value),dir:"ltr"})}),e.jsx(j,{label:'×××"×',children:e.jsx("input",{className:v,value:n.tenant_email||"",onChange:r=>f("tenant_email",r.target.value),dir:"ltr"})}),e.jsx(j,{label:"ס×××ס",children:e.jsx("select",{className:v,value:n.status,onChange:r=>f("status",r.target.value),children:xt.map(r=>e.jsx("option",{value:r,children:r},r))})}),e.jsx(j,{label:"ת×ר×× ×ת×××",children:e.jsx("input",{type:"date",className:v,value:n.start_date||"",onChange:r=>f("start_date",r.target.value)})}),e.jsx(j,{label:"ת×ר×× ×¡×××",children:e.jsx("input",{type:"date",className:v,value:n.end_date||"",onChange:r=>f("end_date",r.target.value)})}),e.jsx(j,{label:"ש××ר×ת ×××ש×ת (âª)",children:e.jsx("input",{type:"number",className:v,value:n.monthly_rent??"",onChange:r=>f("monthly_rent",r.target.value)})}),e.jsx(j,{label:"פ××§××× (âª)",children:e.jsx("input",{type:"number",className:v,value:n.deposit??"",onChange:r=>f("deposit",r.target.value)})})]}),e.jsx(j,{label:"×ער×ת",children:e.jsx("textarea",{className:`${v} h-16 py-2`,value:n.notes||"",onChange:r=>f("notes",r.target.value)})})]}),e.jsx(W,{onClose:c,onSubmit:m,tone:"emerald"})]})}function vt({occupant:l,residents:o,onSave:p,onClose:c}){const[n,d]=h.useState({full_name:"",id_number:"",relationship:"ש××ר",phone:"",entry_date:"",exit_date:"",notes:"",resident_id:null,...l}),f=(r,b)=>d(a=>({...a,[r]:b})),m=()=>{var r;if(!((r=n.full_name)!=null&&r.trim())){y.error("×ש ××××× ×©×");return}p(n)};return e.jsxs(se,{children:[e.jsxs("div",{className:"px-5 py-3 bg-gradient-to-l from-sky-600 to-sky-500 text-white flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-bold",children:l!=null&&l.id?"ער××ת ×××ר":"×××ר ××ש"}),e.jsx("button",{"aria-label":"ס××ר×",onClick:c,className:"w-8 h-8 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-4.5 h-4.5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsx(j,{label:"×××רת ת××©× ×××××ר",children:e.jsx(Me,{residents:o,onPick:r=>d(b=>({...b,resident_id:r.id,full_name:r.full_name||b.full_name,phone:r.phone||b.phone}))})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(j,{label:"×©× ××× *",children:e.jsx("input",{className:v,value:n.full_name,onChange:r=>f("full_name",r.target.value)})}),e.jsx(j,{label:"×ספר ×××ת",children:e.jsx("input",{className:v,value:n.id_number||"",onChange:r=>f("id_number",r.target.value),dir:"ltr"})}),e.jsx(j,{label:"קר××",children:e.jsxs("select",{className:v,value:n.relationship||"",onChange:r=>f("relationship",r.target.value),children:[e.jsx("option",{value:"",children:"â"}),pt.map(r=>e.jsx("option",{value:r,children:r},r))]})}),e.jsx(j,{label:"××פ××",children:e.jsx("input",{className:v,value:n.phone||"",onChange:r=>f("phone",r.target.value),dir:"ltr"})}),e.jsx(j,{label:"ת×ר×× ×× ×ס×",children:e.jsx("input",{type:"date",className:v,value:n.entry_date||"",onChange:r=>f("entry_date",r.target.value)})}),e.jsx(j,{label:"ת×ר×× ×צ×××",children:e.jsx("input",{type:"date",className:v,value:n.exit_date||"",onChange:r=>f("exit_date",r.target.value)})})]})]}),e.jsx(W,{onClose:c,onSubmit:m,tone:"sky"})]})}function yt({ticket:l,onSave:o,onClose:p}){const[c,n]=h.useState({ticket_type:"תק××",title:"",description:"",priority:"××× ×× ×ת",status:"פת××",target_date:"",assigned_to:"",external_provider:"",cost:"",images_before:[],...l}),[d,f]=h.useState(!1),m=(a,x)=>n(g=>({...g,[a]:x})),r=async a=>{const x=[...a.target.files||[]];if(a.target.value="",!!x.length){f(!0);try{const g=await Te(x);n(i=>({...i,images_before:[...i.images_before||[],...g]}))}catch{y.error("ש×××× ×××¢×××")}finally{f(!1)}}},b=()=>{var a;if(!((a=c.title)!=null&&a.trim())){y.error("×ש ××××× × ×ש×");return}o({...c,cost:c.cost===""?null:Number(c.cost)})};return e.jsxs(se,{children:[e.jsxs("div",{className:"px-5 py-3 bg-gradient-to-l from-rose-600 to-rose-500 text-white flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-bold",children:l!=null&&l.id?"ער××ת קר×××":"קר××ת ת××××§× ××ש×"}),e.jsx("button",{"aria-label":"ס××ר×",onClick:p,className:"w-8 h-8 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-4.5 h-4.5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(j,{label:"ס××",children:e.jsx("select",{className:v,value:c.ticket_type,onCh
2ange:a=>m("ticket_type",a.target.value),children:ut.map(a=>e.jsx("option",{value:a,children:a},a))})}),e.jsx(j,{label:"×××פ×ת",children:e.jsx("select",{className:v,value:c.priority,onChange:a=>m("priority",a.target.value),children:bt.map(a=>e.jsx("option",{value:a,children:a},a))})})]}),e.jsx(j,{label:"× ××©× *",children:e.jsx("input",{className:v,value:c.title,onChange:a=>m("title",a.target.value)})}),e.jsx(j,{label:"ת×××ר",children:e.jsx("textarea",{className:`${v} h-20 py-2`,value:c.description||"",onChange:a=>m("description",a.target.value)})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(j,{label:"×××§×¦× ×××פ××",children:e.jsx("input",{className:v,value:c.assigned_to||"",onChange:a=>m("assigned_to",a.target.value)})}),e.jsx(j,{label:"ספק ××צ×× ×",children:e.jsx("input",{className:v,value:c.external_provider||"",onChange:a=>m("external_provider",a.target.value)})}),e.jsx(j,{label:"ת×ר×× ××¢×",children:e.jsx("input",{type:"date",className:v,value:c.target_date||"",onChange:a=>m("target_date",a.target.value)})}),e.jsx(j,{label:"×¢××ת (âª)",children:e.jsx("input",{type:"number",className:v,value:c.cost??"",onChange:a=>
2m("cost",a.target.value)})})]}),e.jsx(j,{label:"ת××× ×ת (××¤× ×)",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[(c.images_before||[]).map((a,x)=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{src:a,alt:"",className:"w-14 h-14 rounded-lg object-cover ring-1 ring-slate-200"}),e.jsx("button",{onClick:()=>m("images_before",c.images_before.filter((g,i)=>i!==x)),className:"absolute -top-1.5 -left-1.5 w-5 h-5 rounded-full bg-rose-500 text-white flex items-center justify-center",children:e.jsx(R,{className:"w-3 h-3"})})]},x)),e.jsxs("label",{className:"w-14 h-14 rounded-lg border-2 border-dashed border-slate-200 flex items-center justify-center cursor-pointer hover:border-amber-400",children:[e.jsx("input",{type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:r}),d?e.jsx(xe,{className:"w-4 h-4 animate-spin text-slate-400"}):e.jsx(Le,{className:"w-5 h-5 text-slate-300"})]})]})})]}),e.jsx(W,{onClose:p,onSubmit:b,tone:"rose",disabled:d})]})}function wt({ticket:l,onSave:o,onClose:p}){const[c,n]=h.useState(l.status),[d,f]=h.useState(""),[m,r]=h.useState([]),[b,a]=h.useState(!1),x=async g=>{const i=[...g.target.files||[]];if(g.target.value="",!!i.length){a(!0);try{const u=await Te(i);r(N=>[...N,...u])}catch{y.error("ש×××× ×××¢×××")}finally{a(!1)}}};return e.jsxs(se,{children:[e.jsxs("div",{className:"px-5 py-3 bg-gradient-to-l from-amber-600 to-amber-500 text-white flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-bold",children:["×¢×××× ×§×¨××× â ",l.title]}),e.jsx("button",{"aria-label":"ס××ר×",onClick:p,className:"w-8 h-8 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-4.5 h-4.5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsx(j,{label:"ס×××ס ××ש",children:e.jsx("select",{className:v,value:c,onChange:g=>n(g.target.value),children:ht.map(g=>e.jsx("option",{value:g,children:g},g))})}),e.jsx(j,{label:"ת××¢×× / ×ער×",children:e.jsx("textarea",{className:`${v} h-20 py-2`,value:d,onChange:g=>f(g.target.value),placeholder:"×× ××צע..."})}),e.jsx(j,{label:"ת××× ×ת (××ר×)",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[m.map((g,i)=>e.jsx("img",{src:g,alt:"",className:"w-14 h-14 rounded-lg object-cover ring-1 ring-slate-200"},i)),e.jsxs("label",{className:"w-14 h-14 rounded-lg border-2 border-dashed border-slate-200 flex items-center justify-center cursor-pointer hover:border-amber-400",children:[e.jsx("input",{type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:x}),b?e.jsx(xe,{className:"w-4 h-4 animate-spin text-slate-400"}):e.jsx(Le,{className:"w-5 h-5 text-slate-300"})]})]})})]}),e.jsx(W,{onClose:p,onSubmit:()=>o(l,{status:c,note:d,imagesAfter:m}),tone:"amber",label:"×¢××××",disabled:b})]})}function W({onClose:l,onSubmit:o,tone:p="amber",label:c="ש××ר×",disabled:n}){const d={emerald:"linear-gradient(90deg,#059669,#10b981)",sky:"linear-gradient(90deg,#0284c7,#0ea5e9)",rose:"linear-gradient(90deg,#e11d48,#f43f5e)",amber:"linear-gradient(90deg,#d97706,#f59e0b)"}[p];return e.jsxs("div",{className:"px-5 py-3.5 border-t border-slate-100 flex justify-end gap-2 bg-slate-50/60",children:[e.jsx("button",{onClick:l,className:"h-10 px-4 rounded-full text-sm font-bold text-slate-500 hover:bg-slate-100",children:"×××××"}),e.jsx("button",{onClick:o,disabled:n,className:"h-10 px-5 rounded-full text-white text-sm font-bold shadow-sm hover:brightness-110 disabled:opacity-50",style:{backgroundImage:d},children:c})]})}function Nt({caravan:l,ownerNames:o,onSave:p,onClose:c,inline:n}){const[d,f]=h.useState({caravan_number:"",owner_type:"",size:"",status:"×¤× ××",settlement:"",council:"",identity_nokedim:"",identity_council:"",identity_amana:"",address:"",notes:"",...l}),m=(a,x)=>f(g=>({...g,[a]:x})),r=()=>{if(!String(d.caravan_number).trim()){y.error("×ש ××××× ×ספר קר××××");return}p(d)},b=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-5 py-3 bg-gradient-to-l from-amber-600 to-amber-500 text-white flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-bold",children:l!=null&&l.id?"ער××ת פר×× ×§×¨××××":"קר×××× ××ש"}),e.jsx("button",{"aria-label":"ס××ר×",onClick:c,className:"w-8 h-8 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-4.5 h-4.5"})})]}),e.jsxs("div",{className:"p-5 grid grid-cols-2 md:grid-cols-3 gap-3",children:[e.jsx(j,{label:"×ספר קר×××× *",children:e.jsx("input",{className:v,value:d.caravan_number,onChange:a=>
2m("caravan_number",a.target.value)})}),e.jsxs(j,{label:"××¢××ת",children:[e.jsx("input",{className:v,list:"owner-types",value:d.owner_type||"",onChange:a=>m("owner_type",a.target.value)}),e.jsx("datalist",{id:"owner-types",children:o.map(a=>e.jsx("option",{value:a},a))})]}),e.jsx(j,{label:"××××",children:e.jsxs("select",{className:v,value:d.size||"",onChange:a=>m("size",a.target.value),children:[e.jsx("option",{value:"",children:"â"}),Se.map(a=>e.jsx("option",{value:a,children:a},a))]})}),e.jsx(j,{label:"ס×××ס",children:e.jsx("select",{className:v,value:d.status||"×¤× ××",onChange:a=>m("status",a.target.value),children:Fe.map(a=>e.jsx("option",{value:a,children:a},a))})}),e.jsx(j,{label:"××ש××",children:e.jsx("input",{className:v,value:d.settlement||"",onChange:a=>m("settlement",a.target.value)})}),e.jsx(j,{label:"××עצ×",children:e.jsx("input",{className:v,value:d.council||"",onChange:a=>m("council",a.target.value)})}),e.jsx(j,{label:"×××ת × ××§×××",children:e.jsx("input",{className:v,value:d.identity_nokedim||"",onChange:a=>m("identity_nokedim",a.target.value)})}),e.jsx(j,{label:"×××ת ××עצ×",children:e.jsx("input",{className:v,value:d.identity_council||"",onChange:a=>m("identity_council",a.target.value)})}),e.jsx(j,{label:"×××ת ××× ×",children:e.jsx("input",{className:v,value:d.identity_amana||"",onChange:a=>m("identity_amana",a.target.value)})}),e.jsx("div",{className:"col-span-2 md:col-span-3",children:e.jsx(j,{label:"×ת××ת",children:e.jsx("input",{className:v,value:d.address||"",onChange:a=>m("address",a.target.value)})})}),e.jsx("div",{className:"col-span-2 md:col-span-3",children:e.jsx(j,{label:"×ער×ת",children:e.jsx("textarea",{className:`${v} h-20 py-2`,value:d.notes||"",onChange:a=>m("notes",a.target.value)})})})]}),e.jsx(W,{onClose:c,onSubmit:r,tone:"amber"})]});return n?e.jsx(se,{children:b}):e.jsx($e,{onClose:c,wide:!0,children:b})}function _t({communityId:l,onClose:o,onDone:p}){const[c,n]=h.useState(null),[d,f]=h.useState(""),[m,r]=h.useState(!1),[b,a]=h.useState(null),x=async N=>{var I;const w=(I=N.target.files)==null?void 0:I[0];if(N.target.value="",!!w)try{const B=JSON.parse(await w.text());n(B),f(w.name)}catch{y.error("×§×××¥ JSON ×× ×ª×§××")}},g=c?c.entities||c:null,i=async()=>{if(c){r(!0);try{const N=await k.functions.invoke("importCaravans",{community_id:l,data:c}),w=N==null?void 0:N.data;w!=null&&w.success?(a(w.summary),y.success("×××××× ××ש××"),p==null||p()):y.error("ש×××× ××××××")}catch(N){console.error(N),y.error((N==null?void 0:N.message)||"ש×××× ××××××")}finally{r(!1)}}},u=N=>{var w;return((w=g==null?void 0:g[N])==null?void 0:w.length)??0};return e.jsxs($e,{onClose:m?void 0:o,children:[e.jsxs("div",{className:"px-5 py-4 bg-gradient-to-l from-blue-600 to-sky-500 text-white flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl bg-white/20 flex items-center justify-center",children:e.jsx(me,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold",children:"××××× × ×ª×× ×× ×-Base44"}),e.jsx("p",{className:"text-xs text-white/80",children:"××¢×× ×ת ×§×××¥ ×××צ×× (JSON) â ×× ×ª×× ×× ××××¢× × ××§×××× ×× ××××"})]})]}),e.jsx("button",{"aria-label":"ס××ר×",onClick:m?void 0:o,className:"w-9 h-9 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"p-5 space-y-4",children:b?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-bold text-emerald-600 flex items-center gap-1.5",children:[e.jsx(Pe,{className:"w-4 h-4"})," ×××××× ××ש××"]}),Object.entries(b).map(([N,w])=>e.jsxs("div",{className:"flex items-center justify-between text-sm rounded-lg bg-slate-50 px-3 py-2",children:[e.jsx("span",{className:"text-slate-600",children:N}),e.jsxs("span",{className:"font-bold text-slate-800",children:["× ××¦×¨× ",w.created," · ××××× ",w.skipped]})]},N))]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5 h-11 px-5 rounded-full border-2 border-blue-200 text-sm font-bold text-blue-700 hover:bg-blue-50 cursor-pointer",children:[e.jsx("input",{type:"file",accept:".json,application/json",className:"hidden",onChange:x}),e.jsx(it,{className:"w-4 h-4"})," ×××¨× ×§×××¥ JSON"]}),d&&e.jsx("p",{className:"text-xs text-slate-500",children:d}),g&&e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[["caravans","קר×××× ××"],["rentals","ש××ר×××ת"],["occupants","×××ר××"],["maintenance_tickets","קר×××ת"],["documents","×ס××××"]].map(([N,w])=>e.jsxs("div",{className:"rounded-xl border border-slate-100 bg-slate-50/60 p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold text-slate-800",children:u(N)}),e.jsx("p",{className:"text-xs text-slate-500",children:w})]},N))})]})}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-slate-100 flex justify-end gap-2 bg-slate-50/60",children:[e.jsx("button",{onClick:o,disabled:m,className:"h-10 px-4 roun
2ded-full text-sm font-bold text-slate-500 hover:bg-slate-100",children:b?"ס××ר×":"×××××"}),!b&&e.jsxs("button",{onClick:i,disabled:m||!c,className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full text-white text-sm font-bold shadow-sm hover:brightness-110 disabled:opacity-50",style:{backgroundImage:"linear-gradient(90deg,#2563eb,#0ea5e9)"},children:[m?e.jsx(xe,{className:"w-4 h-4 animate-spin"}):e.jsx(me,{className:"w-4 h-4"})," ×××××"]})]})]})}function kt({communityId:l,ownerTypes:o,caravans:p,onClose:c,onDone:n}){const[d,f]=h.useState(o.length?o.map(i=>i.name):[...new Set(p.map(i=>i.owner_type).filter(Boolean))]),[m,r]=h.useState(""),[b,a]=h.useState(!1),x=()=>{const i=m.trim();i&&!d.includes(i)&&(f([...d,i]),r(""))},g=async()=>{a(!0);try{const i=o.map(u=>u.name);await Promise.all([...d.filter(u=>!i.includes(u)).map((u,N)=>k.entities.CaravanOwnerType.create({kibbutz_id:l,name:u,sort:i.length+N})),...o.filter(u=>!d.includes(u.name)).map(u=>k.entities.CaravanOwnerType.delete(u.id))]),y.success("× ×©×ר"),n==null||n(),c()}catch(i){console.error(i),y.error("ש×××× ×ש××ר×")}finally{a(!1)}};return e.jsxs($e,{onClose:c,children:[e.jsxs("div",{className:"px-5 py-4 bg-gradient-to-l from-fuchsia-600 to-purple-500 text-white flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-bold",children:"ס××× ××¢××ת (××ר×)"}),e.jsx("button",{"aria-label":"ס××ר×",onClick:c,className:"w-9 h-9 rounded-lg flex items-center justify-center hover:bg-white/15",children:e.jsx(R,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"p-5 space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:v,value:m,onChange:i=>r(i.target.value),onKeyDown:i=>i.key==="Enter"&&x(),placeholder:"×©× ×¡×× ××¢××ת"}),e.jsx("button",{onClick:x,className:"h-11 px-4 rounded-xl bg-fuchsia-600 text-white text-sm font-bold",children:"××סף"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(i=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-slate-100 rounded-full px-3 py-1.5 text-sm font-medium text-slate-700",children:[i,e.jsx("button",{onClick:()=>f(d.filter(u=>u!==i)),children:e.jsx(R,{className:"w-3.5 h-3.5 text-slate-400"})})]},i))})]}),e.jsx(W,{onClose:c,onSubmit:g,tone:"amber",disabled:b})]})}export{Mt 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.