1import{r as u,d as v,j as e,m as us,n as hs,p as ps,ar as oe,x as De,am as fs,aF as de,C as Ae,a as bs,aI as Te,P as _e,z as S,F as gs,U as Me,y as Pe,bp as js,aH as _s,T as Ne,bN as Ns,aM as qe,aD as Ze,N as Je,ad as vs,aU as ys,ae as ws,t as Cs,bM as Ss,B as ks,a1 as Ue,aG as es,bK as Ts,Z as We,$ as Ds,Y as Ls}from"./index-BuF13C9R.js";import{P as Rs}from"./PageTitleMenu-DlabIv_d.js";import{g as B,P as J,i as Z,b as ce,f as ie,L as Fs,c as Es,W as Os,d as me,e as $e,F as ss,a as Ws,D as $s,T as As,h as Ms}from"./TaskFormDialog-BHB2di_W.js";import{I as Ee}from"./input-B1pb-EbS.js";import{P as ge}from"./paperclip-BMrctHny.js";import{R as ts}from"./rotate-ccw-BudqP26q.js";import{I as Ps}from"./image-BzvPncEw.js";import{C as X}from"./checkbox-a-cH2r5u.js";import{N as qs}from"./softDelete-X2GBluex.js";import{M as U}from"./ManagerDialog-CsFlI9xO.js";import{F as xe}from"./FormSection-DgtCTxGQ.js";import{f as E,l as F,a as Be}from"./formStyles-CzLsWpb8.js";import{P as ve}from"./pencil-CoE4mwuD.js";import{G as Bs}from"./grip-vertical-D-WILyUY.js";import{D as Ks,C as Is,P as Ys}from"./dnd.esm-DGZifSk5.js";import{C as zs}from"./copy-BClGV4nG.js";import{C as Gs}from"./chevron-left-D2IUBEPa.js";import{R as Ge,C as Vs,T as Ve,L as He,B as Oe}from"./generateCategoricalChart-D9kEchEU.js";import{P as Hs,a as Qs}from"./PieChart-knnFYOG7.js";import{B as Xs,X as Zs,Y as Js}from"./BarChart-BV6G5gJY.js";import{R as je}from"./refresh-cw-DvPS6Mu1.js";import{R as Us}from"./repeat-CJHHLdIV.js";import{T as et}from"./table-BNx63gxh.js";import"./useActionVisibility-DLgqAw2q.js";import"./label-CZGaFvV8.js";import"./textarea-xKivmc1W.js";import"./RegField-CR7X7gn1.js";import"./calendar-clock-Dg6I_-A7.js";import"./index-BGaOrCq_.js";import"./tiny-invariant-BaFNuDhB.js";import"./isEqual-Bszk2vQ5.js";const st={status_change:ts,time_report:de,file:ge,comment:Te},tt=a=>(a||"").trim().split(/\s+/).slice(0,2).map(s=>s[0]).join("")||"?";function at({task:a,statuses:s,workers:C,categories:j,settings:o,currentUser:i,onUpdate:n,onClose:p}){var Q,he,se,pe;const[N,D]=u.useState([]),[m,r]=u.useState(!0),[t,_]=u.useState(""),[h,b]=u.useState(""),[g,c]=u.useState(""),[y,A]=u.useState(""),[M,$]=u.useState(!1);if(u.useEffect(()=>{a&&(r(!0),v.entities.TaskLog.filter({kibbutz_id:a.kibbutz_id,task_id:a.id},"-created_date",200).then(D).catch(()=>{}).finally(()=>r(!1)))},[a]),!a)return null;const k=s.find(d=>d.id===a.status_id),z=k?B(k.color):B("gray"),K=J[a.priority]||J.normal,ee=j.find(d=>d.id===a.category_id),G=(a.assignee_ids||[]).map(d=>C.find(L=>L.id===d)).filter(Boolean),ue=Z(a);async function V(d){$(!0);try{const L={kibbutz_id:a.kibbutz_id,task_id:a.id,user_id:i==null?void 0:i.id,worker_id:null,title:d.title||"",content:d.content||"",log_type:d.log_type||"comment",is_internal:d.is_internal||!1};if(d.new_status_id&&(L.log_type="status_change",L.old_status_id=a.status_id,L.new_status_id=d.new_status_id),(d.work_start||d.work_end)&&(L.log_type="time_report",L.work_start=d.work_start,L.work_end=d.work_end,d.work_start&&d.work_end)){const W=(new Date(d.work_end)-new Date(d.work_start))/36e5;L.work_hours=Math.round(W*100)/100}if(await v.entities.TaskLog.create(L),d.new_status_id&&d.new_status_id!==a.status_id){const W=s.find(I=>I.id===d.new_status_id),P={status_id:d.new_status_id};W!=null&&W.is_closed&&(P.closed_at=new Date().toISOString(),(W.title==="××צע"||W.title==="× ×¡×ר")&&(P.completed_at=P.completed_at||new Date().toISOString())),W!=null&&W.requires_manager_approval&&a.requires_manager_approval,await v.entities.TaskItem.update(a.id,P)}S.success("×ת××¢×× × ×סף"),_(""),b(""),c(""),A("");const O=await v.entities.TaskLog.filter({kibbutz_id:a.kibbutz_id,task_id:a.id},"-created_date",200);D(O),n()}catch{S.error("ש×××× ×××ספת ת××¢××")}finally{$(!1)}}async function te(d){let L=null;d==="complete"&&(L=s.find(O=>O.title==="××צע"||O.title==="××ת×× ×××ש×ר")),d==="approve"&&(L=s.find(O=>O.title==="× ×¡×ר")),d==="reopen"&&(L=s.find(O=>O.sort_order===1||O.title==="פת××")),L&&await V({new_status_id:L.id,title:d==="complete"?"ס×××× ××צע":d==="approve"?"××שר ×× ×¡×ר":"× ×¤×ª× ×××ש",content:""})}async function H(d,L){var W;const O=(W=d.target.files)==null?void 0:W[0];if(O)try{const{file_url:P}=await v.integrations.Core.UploadFile({file:O});await v.entities.TaskLog.create({kibbutz_id:a.kibbutz_id,task_id:a.id,user_id:i==null?void 0:i.id,log_type:"file",title:L?"ת××× ×":"×§×××¥",content:O.name,images:L?[P]:[],files:L?[]:[P]}),L?await v.entities.TaskItem.update(a.id,{images:[...a.images||[],P]}):await v.entities.TaskItem.update(a.id,{files:[...a.files||[],P]}),S.success("××§×××¥ ×××¢××");const I=await v.entities.TaskLog.filter({kibbutz_id:a.kibbutz_id,task_id:a.id},"-created_date",200);D(I),n()}catch{S.error("ש×××× ×××¢××ת ×§×××¥")}}const ye=!M&&(t.trim()||h||g);return e.jsx(us,{open:!0,onOpenChange:p,children:e.jsxs(hs,{className:"max-w-2xl max-h-[92vh] overflow-hidden p-0 gap-0",dir:"rtl",children:[e.jsx("div",{className:"px-6 pt-6 pb-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:`w-1.5 self-stretch min-h-[2.75rem] rounded-full ${K.dot} flex-none`}),e.jsxs("div",{className:"flex-1 min-w-0 pl-8",children:[e.jsx(ps,{className:"text-xl font-extrabold text-slate-900 leading-snug",children:a.title}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-2.5 flex-wrap",children:[e.jsx("span",{className:`text-[11px] font-bold px-2.5 py-1 rounded-full ${z.bg} ${z.text}`,children:(k==null?void 0:k.title)||"â"}),e.jsx("span",{className:`text-[11px] font-bold px-2.5 py-1 rounded-full ${K.bg} ${K.text}`,children:ce[a.priority]}),ee&&e.jsx("span",{className:"text-[11px] font-semibold px-2.5 py-1 rounded-full bg-slate-100 text-slate-600",children:ee.title}),a.task_number!=null&&e.jsxs("span",{className:"text-[11px] font-bold px-2 py-1 rounded-full bg-slate-100 text-slate-500 tabular-nums",children:["#",a.task_number]}),ue&&e.jsxs("span",{className:"text-[11px] font-bold px-2.5 py-1 rounded-full bg-red-50 text-red-600 inline-flex items-center gap-1",children:[e.jsx(oe,{className:"w-3 h-3"})," ×××××ר"]})]})]})]})}),e.jsxs("div",{className:"overflow-y-auto px-6 pb-6 pt-4 space-y-4 border-t border-slate-100",children:[a.description&&e.jsxs("div",{className:"rounded-2xl border border-slate-100 bg-slate-50/70 p-4",children:[e.jsx("p",{className:"text-[11px] font-bold text-slate-400 mb-1.5",children:"ת×××ר"}),e.jsx("p",{className:"text-sm text-slate-700 whitespace-pre-wrap leading-relaxed",children:a.description})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"rounded-2xl border border-slate-100 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-bold text-slate-400 mb-2.5",children:[e.jsx(De,{className:"w-3.5 h-3.5"})," ××ר×××"]}),G.length>0?e.jsx("div",{className:"flex flex-col gap-2",children:G.map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-7 h-7 rounded-full bg-blue-50 text-blue-600 grid place-items-center text-[10px] font-extrabold flex-none",children:tt(d.full_name)}),e.jsx("span",{className:"text-sm font-semibold text-slate-700 truncate",children:d.full_name}),d.role&&e.jsxs("span",{className:"text-xs text-slate-400 truncate",children:["· ",d.role]})]},d.id))}):e.jsx("span",{className:"text-sm text-slate-400",children:"×× ×©×××"})]}),e.jsxs("div",{className:"rounded-2xl border border-slate-100 p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-bold text-slate-400 mb-2.5",children:[e.jsx(fs,{className:"w-3.5 h-3.5"})," ת×ר×× ××¢×"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-base font-extrabold ${ue?"text-red-600":"text-slate-800"}`,children:ie(a.due_date)||"â"}),a.due_time&&e.jsxs("span",{className:"text-xs text-slate-400 inline-flex items-center gap-1",children:[e.jsx(de,{className:"w-3 h-3"})," ",a.due_time]})]})]})]}),(((Q=a.images)==null?void 0:Q.length)>0||((he=a.files)==null?void 0:he.length)>0)&&e.jsxs("div",{className:"rounded-2xl border border-slate-100 p-4",children:[e.jsx("p",{className:"text-[11px] font-bold text-slate-400 mb-2.5",children:"×§×צ×× ×ת××× ×ת"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[(se=a.images)==null?void 0:se.map((d,L)=>e.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"block",children:e.jsx("img",{src:d,alt:"",className:"w-16 h-16 object-cover rounded-xl border border-slate-200"})},L)),(pe=a.files)==null?void 0:pe.map((d,L)=>e.jsxs("a",{href:d,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-3 h-10 rounded-xl border border-slate-200 bg-white text-sm hover:bg-slate-50",children:[e.jsx(ge,{className:"w-4 h-4 text-slate-400"}),e.jsx("span",{className:"truncate max-w-[120px] text-slate-600",children:d.split("/").pop()})]},L))]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[!(k!=null&&k.is_closed)&&e.jsxs("button",{onClick:()=>te("complete"),className:"inline-flex items-center gap-2 h-10 px-4 roun
1ded-full bg-emerald-600 text-white text-sm font-bold hover:bg-emerald-700 transition-colors shadow-sm",children:[e.jsx(Ae,{className:"w-4 h-4"})," ס×× ××צע"]}),(k==null?void 0:k.requires_manager_approval)&&e.jsxs("button",{onClick:()=>te("approve"),className:"inline-flex items-center gap-2 h-10 px-4 rounded-full bg-purple-600 text-white text-sm font-bold hover:bg-purple-700 transition-colors shadow-sm",children:[e.jsx(bs,{className:"w-4 h-4"})," ×שר ×ס××ר"]}),(k==null?void 0:k.is_closed)&&e.jsxs("button",{onClick:()=>te("reopen"),className:"inline-flex items-center gap-2 h-10 px-4 rounded-full border border-blue-200 bg-blue-50 text-blue-700 text-sm font-bold hover:bg-blue-100 transition-colors",children:[e.jsx(ts,{className:"w-4 h-4"})," ×¤×ª× ×××ש"]}),e.jsxs("label",{className:"cursor-pointer",children:[e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:d=>H(d,!0)}),e.jsxs("span",{className:"inline-flex items-center gap-2 h-10 px-4 rounded-full border border-slate-200 bg-white text-sm font-semibold text-slate-600 hover:bg-slate-50 cursor-pointer",children:[e.jsx(Ps,{className:"w-4 h-4"})," ת××× ×"]})]}),e.jsxs("label",{className:"cursor-pointer",children:[e.jsx("input",{type:"file",className:"hidden",onChange:d=>H(d,!1)}),e.jsxs("span",{className:"inline-flex items-center gap-2 h-10 px-4 rounded-full border border-slate-200 bg-white text-sm font-semibold text-slate-600 hover:bg-slate-50 cursor-pointer",children:[e.jsx(ge,{className:"w-4 h-4"})," ×§×××¥"]})]})]}),e.jsxs("div",{className:"pt-4 border-t border-slate-100",children:[e.jsxs("h4",{className:"text-sm font-extrabold text-slate-800 mb-3 flex items-center gap-2",children:[e.jsx(Te,{className:"w-4 h-4 text-blue-600"})," ת××¢×× ×××××××××"]}),e.jsxs("div",{className:"rounded-2xl border border-slate-100 bg-slate-50/60 p-3 space-y-2.5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("select",{value:h,onChange:d=>b(d.target.value),className:"h-10 rounded-xl border border-slate-200 bg-white px-3 text-sm text-slate-700 flex-none outline-none focus:border-blue-400",children:[e.jsx("option",{value:"",children:"ש×× ×× ×¡×××ס..."}),s.filter(d=>d.is_active!==!1).map(d=>e.jsx("option",{value:d.id,children:d.title},d.id))]}),e.jsx(Ee,{value:t,onChange:d=>_(d.target.value),placeholder:"××סף ××¢×¨× / ת××¢××...",className:"flex-1 h-10 rounded-xl bg-white"})]}),(o==null?void 0:o.enable_time_reports)&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(Ee,{type:"datetime-local",value:g,onChange:d=>c(d.target.value),className:"text-sm h-10 rounded-xl bg-white"}),e.jsx(Ee,{type:"datetime-local",value:y,onChange:d=>A(d.target.value),className:"text-sm h-10 rounded-xl bg-white"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:()=>V({content:t,new_status_id:h||void 0,work_start:g||void 0,work_end:y||void 0}),disabled:!ye,className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full bg-primary text-white text-sm font-bold hover:opacity-90 transition-opacity disabled:opacity-50 shadow-sm",children:[e.jsx(_e,{className:"w-4 h-4"})," ",M?"××ס××£...":"××סף ת××¢××"]})})]}),e.jsxs("div",{className:"mt-4",children:[m&&e.jsx("p",{className:"text-xs text-slate-400 text-center py-6",children:"×××¢×..."}),!m&&N.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("div",{className:"w-11 h-11 rounded-2xl bg-slate-100 grid place-items-center mx-auto mb-2",children:e.jsx(Te,{className:"w-5 h-5 text-slate-400"})}),e.jsx("p",{className:"text-sm text-slate-400",children:"××× ×ª××¢×× ×¢××××"})]}),N.map((d,L)=>{var we,fe;const O=s.find(Y=>Y.id===d.new_status_id),W=O?B(O.color):null,P=st[d.log_type]||Te,I=L===N.length-1;return e.jsxs("div",{className:"relative flex gap-3 pb-4 last:pb-0",children:[!I&&e.jsx("span",{className:"absolute right-[15px] top-9 bottom-0 w-px bg-slate-200"}),e.jsx("span",{className:`w-8 h-8 rounded-full grid place-items-center flex-none z-10 ${d.is_internal?"bg-amber-100 text-amber-600":"bg-blue-50 text-blue-600"}`,children:e.jsx(P,{className:"w-4 h-4"})}),e.jsxs("div",{className:`flex-1 min-w-0 rounded-xl border p-3 ${d.is_internal?"bg-amber-50/60 border-amber-200":"bg-white border-slate-100"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[e.jsx("span",{className:"text-xs font-bold text-slate-600",children:Fs[d.log_type]||"×ער×"}),d.is_internal&&e.jsx("span",{className:"text-[10px] font-bold text-amber-600 bg-amber-100 rounded px-1.5 py-0.5",children:"×¤× ×××"}),e.jsx("span",{className:"text-[11px] text-slate-400 mr-auto tabular-nums",children:Es(d.created_date)})]}),d.title&&e.jsx("p",{className:"text-sm font-semibold text-slate-800",children:d.title}),d.content&&e.jsx("p",{className:"text-sm text-slate-600 whitespace-pre-wrap leading-relaxed",children:d.content}),W&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("span",{className:"text-xs text-slate-400",children:"ס×××ס ש×× × ×:"}),e.jsx("span",{className:`text-[11px] font-bold px-2 py-0.5 rounded-full ${W.bg} ${W.text}`,children:O.title})]}),d.work_hours>0&&e.jsxs("p",{className:"text-xs font-semibold text-blue-600 mt-1.5 inline-flex items-center gap-1",children:[e.jsx(de,{className:"w-3 h-3"})," שע×ת ×¢××××: ",d.work_hours]}),((we=d.images)==null?void 0:we.length)>0&&e.jsx("div",{className:"flex gap-1.5 mt-2 flex-wrap",children:d.images.map((Y,ae)=>e.jsx("a",{href:Y,target:"_blank",rel:"noopener noreferrer",children:e.jsx("img",{src:Y,alt:"",className:"w-12 h-12 object-cover rounded-lg border border-slate-200"})},ae))}),((fe=d.files)==null?void 0:fe.length)>0&&e.jsx("div",{className:"flex flex-col gap-1 mt-2",children:d.files.map((Y,ae)=>e.jsxs("a",{href:Y,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-600 inline-flex items-center gap-1 hover:underline",children:[e.jsx(ge,{className:"w-3 h-3"}),Y.split("/").pop()]},ae))})]})]},d.id)})]})]})]})]})})}function lt({kibbutzId:a,workers:s,onUpdate:C,onClose:j}){const[o,i]=u.useState(null),[n,p]=u.useState(!1),[N,D]=u.useState(""),m=s.filter(t=>{var _,h,b;return((_=t.full_name)==null?void 0:_.toLowerCase().includes(N.toLowerCase()))||((h=t.role)==null?void 0:h.toLowerCase().includes(N.toLowerCase()))||((b=t.department)==null?void 0:b.toLowerCase().includes(N.toLowerCase()))});async function r(t){if(confirm("××× ×××××§ ×¢××× ××?"))try{await v.entities.TaskWorker.delete(t),S.success("××¢××× × ×××§"),C()}catch{S.error("ש×××× ×××××§×")}}return e.jsxs("div",{dir:"rtl",className:"bg-white rounded-2xl border border-border shadow-sm p-4 sm:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"w-10 h-10 rounded-xl bg-blue-50 flex items-center justify-center",children:e.jsx(De,{className:"w-5 h-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-extrabold text-slate-900",children:"× ×××× ×¢××××× ×××¢×× ×ª×¤×§××××"}),e.jsx("p",{className:"text-xs text-slate-500",children:"×××¡×¤× ×ער××× ×©× ×¢××××× â ת××©× ××רש××× ×× ×¢××× ××צ×× ×"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:j,className:"inline-flex items-center gap-1.5 h-10 px-4 roun
1ded-full border border-border text-sm font-medium hover:bg-slate-50 transition-colors",children:[e.jsx(gs,{className:"w-4 h-4"})," ×××¨× ×× ×××× ×ש×××ת"]}),e.jsxs("button",{type:"button",onClick:()=>{i(null),p(!0)},className:"inline-flex items-center gap-1.5 h-10 px-4 rounded-full text-white text-sm font-bold transition-colors bg-blue-600 hover:bg-blue-700",children:[e.jsx(Me,{className:"w-4 h-4"})," ××סף ×¢×××"]})]})]}),e.jsxs("div",{className:"relative mb-3 max-w-md",children:[e.jsx(Pe,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{value:N,onChange:t=>D(t.target.value),placeholder:"××פ×ש ×¢×××...",className:`${E} pr-9`})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[m.map(t=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl border border-border bg-white hover:shadow-sm transition-shadow",children:[e.jsx("div",{className:`w-9 h-9 rounded-full flex items-center justify-center flex-shrink-0 ${t.worker_type==="resident"?"bg-blue-50":"bg-orange-50"}`,children:e.jsx(js,{className:`w-4 h-4 ${t.worker_type==="resident"?"text-blue-600":"text-orange-600"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:t.full_name}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${t.worker_type==="resident"?"bg-blue-50 text-blue-600":"bg-orange-50 text-orange-600"}`,children:Os[t.worker_type]||""}),t.is_active===!1&&e.jsx("span",{className:"text-xs text-red-500",children:"×× ×¤×¢××"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground mt-0.5",children:[t.role&&e.jsx("span",{className:"truncate",children:t.role}),t.department&&e.jsxs("span",{className:"truncate",children:["⢠",t.department]}),t.phone&&e.jsxs("span",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(_s,{className:"w-3 h-3"}),t.phone]})]})]}),e.jsx("button",{onClick:()=>{i(t),p(!0)},className:"p-1.5 hover:bg-accent rounded flex-shrink-0",children:e.jsx(ve,{className:"w-4 h-4 text-slate-500"})}),e.jsx("button",{onClick:()=>r(t.id),className:"p-1.5 hover:bg-accent rounded flex-shrink-0",children:e.jsx(Ne,{className:"w-4 h-4 text-red-500"})})]},t.id)),m.length===0&&e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8 md:col-span-2",children:'××× ×¢×××××. ×××¦× ×¢× "××סף ×¢×××".'})]}),n&&e.jsx(rt,{kibbutzId:a,worker:o,onSave:async()=>{await C(),p(!1),i(null)},onClose:()=>{p(!1),i(null)}})]})}function rt({kibbutzId:a,worker:s,onSave:C,onClose:j}){const[o,i]=u.useState({worker_type:(s==null?void 0:s.worker_type)||"external",resident_id:(s==null?void 0:s.resident_id)||"",full_name:(s==null?void 0:s.full_name)||"",role:(s==null?void 0:s.role)||"",department:(s==null?void 0:s.department)||"",phone:(s==null?void 0:s.phone)||"",whatsapp:(s==null?void 0:s.whatsapp)||"",email:(s==null?void 0:s.email)||"",can_login:(s==null?void 0:s.can_login)??!1,receives_notifications:(s==null?void 0:s.receives_notifications)??!0,is_active:(s==null?void 0:s.is_active)??!0,notes:(s==null?void 0:s.notes)||""}),[n,p]=u.useState([]),[N,D]=u.useState(""),[m,r]=u.useState(!1),[t,_]=u.useState(!1);u.useEffect(()=>{o.worker_type==="resident"&&!o.resident_id&&(r(!0),v.entities.Resident.filterAll({kibbutz_id:a,is_deleted:qs},"full_name").then(c=>p(c)).catch(()=>{}).finally(()=>r(!1)))},[o.worker_type,a]);function h(c){i(y=>({...y,resident_id:c.id,full_name:c.full_name||y.full_name,phone:c.phone||y.phone,email:c.email||y.email})),D("")}async function b(){if(o.full_name.trim()){_(!0);try{s?(await v.entities.TaskWorker.update(s.id,o),S.success("××¢××× ×¢××××")):(await v.entities.TaskWorker.create({...o,kibbutz_id:a}),S.success("××¢××× × ×סף")),C(o)}catch{S.error("ש×××× ×ש××ר×")}finally{_(!1)}}}const g=u.useMemo(()=>{const c=N.trim().toLowerCase(),y=new Set,A=[];for(const M of n){if(!Ns(M))continue;const $=(M.full_name||"").trim();if(c&&!($.toLowerCase().includes(c)||String(M.phone||"").includes(N.trim())))continue;
1const k=`${$}|${String(M.phone||"").trim()}`;y.has(k)||(y.add(k),A.push(M))}return A},[n,N]);return e.jsx(U,{onClose:j,title:s?"ער××ת ×¢×××":"××ספת ×¢×××",icon:Me,tone:"blue",maxWidth:"max-w-lg",onSave:b,saving:t,saveLabel:"ש××ר",saveDisabled:!o.full_name.trim(),children:e.jsx(xe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>i(c=>({...c,worker_type:"resident",resident_id:""})),className:`flex-1 py-2 rounded-lg border text-sm font-medium transition-all ${o.worker_type==="resident"?"border-blue-300 bg-blue-50 text-blue-700":"border-border bg-white text-muted-foreground"}`,children:"ת××©× ×ת×× ×¨×©×××"}),e.jsx("button",{type:"button",onClick:()=>i(c=>({...c,worker_type:"external",resident_id:""})),className:`flex-1 py-2 rounded-lg border text-sm font-medium transition-all ${o.worker_type==="external"?"border-orange-300 bg-orange-50 text-orange-700":"border-border bg-white text-muted-foreground"}`,children:"×¢××× ××צ×× ×"})]}),o.worker_type==="resident"&&!o.resident_id&&e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××ר ת×ש×"}),e.jsxs("div",{className:"relative",children:[e.jsx(Pe,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{value:N,onChange:c=>D(c.target.value),placeholder:"××פ×ש ת×ש×...",className:`${E} pr-9`})]}),m&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"×××¢× ×ª×ש×××..."}),!m&&e.jsxs("div",{className:"mt-2 max-h-40 overflow-y-auto border border-input rounded-lg bg-white",children:[g.map(c=>e.jsxs("button",{type:"button",onClick:()=>h(c),className:"w-full text-right px-3 py-2 hover:bg-accent text-sm border-b border-border last:border-0",children:[c.full_name,c.phone&&e.jsx("span",{className:"text-xs text-muted-foreground mr-2",children:c.phone})]},c.id)),g.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-3",children:"××× ×ª×צ××ת"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×©× ××× *"}),e.jsx("input",{className:E,value:o.full_name,onChange:c=>i(y=>({...y,full_name:c.target.value})),disabled:!!o.resident_id})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"תפק××"}),e.jsx("input",{className:E,value:o.role,onChange:c=>i(y=>({...y,role:c.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××××§× / ת×××"}),e.jsx("input",{className:E,value:o.department,onChange:c=>i(y=>({...y,department:c.target.value}))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××פ××"}),e.jsx("input",{className:E,value:o.phone,onChange:c=>i(y=>({...y,phone:c.target.value})),dir:"ltr"})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"WhatsApp"}),e.jsx("input",{className:E,value:o.whatsapp,onChange:c=>i(y=>({...y,whatsapp:c.target.value})),dir:"ltr"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:'×××"×'}),e.jsx("input",{type:"email",className:E,value:o.email,onChange:c=>i(y=>({...y,email:c.target.value})),dir:"ltr"})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×ער×ת"}),e.jsx("textarea",{className:Be,value:o.notes,onChange:c=>i(y=>({...y,notes:c.target.value})),rows:2})]}),e.jsxs("div",{className:"flex flex-wrap gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(X,{checked:o.receives_notifications,onCheckedChange:c=>i(y=>({...y,receives_notifications:c}))}),e.jsx("span",{className:"text-sm",children:"××§×× ×תר××ת"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(X,{checked:o.can_login,onCheckedChange:c=>i(y=>({...y,can_login:c}))}),e.jsx("span",{className:"text-sm",children:"×רש×ת ×× ××¡× ×××¡× ×ש×××ת"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(X,{checked:o.is_active,onCheckedChange:c=>i(y=>({...y,is_active:c}
1))}),e.jsx("span",{className:"text-sm",children:"פע××"})]})]})]})})})}const nt=["blue","green","red","orange","purple","gray","yellow","teal"];function it({kibbutzId:a,categories:s,onUpdate:C,onClose:j}){const[o,i]=u.useState(null),[n,p]=u.useState(!1);async function N(r){try{if(o)await v.entities.TaskCategory.update(o.id,r),S.success("××§×××ר×× ×¢×××× ×");else{const t=s.reduce((_,h)=>Math.max(_,h.sort_order||0),0);await v.entities.TaskCategory.create({...r,kibbutz_id:a,sort_order:t+1}),S.success("××§×××ר×× × ×ספ×")}p(!1),i(null),C()}catch{S.error("ש×××× ×ש××ר×")}}async function D(r){if(confirm("××× ×××××§ ×§×××ר×× ××?"))try{await v.entities.TaskCategory.delete(r),S.success("××§×××ר×× × ×××§×"),C()}catch{S.error("ש×××× ×××××§×")}}const m=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:j,className:"inline-flex items-center h-10 px-5 rounded-full border border-border text-sm font-medium hover:bg-slate-50 transition-colors",children:"ס××ר×"}),e.jsxs("button",{type:"button",onClick:()=>{i(null),p(!0)},className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full text-white text-sm font-bold transition-colors bg-blue-600 hover:bg-blue-700",children:[e.jsx(_e,{className:"w-4 h-4"})," ××סף ×§×××ר××"]})]});return e.jsxs(e.Fragment,{children:[e.jsx(U,{onClose:j,title:"× ×××× ×§×××ר××ת ×ש×××ת",icon:qe,tone:"blue",maxWidth:"max-w-lg",footer:m,children:e.jsx("div",{className:"space-y-2",children:s.sort((r,t)=>(r.sort_order||0)-(t.sort_order||0)).map(r=>{const t=B(r.color);return e.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${t.border} ${t.bg}`,children:[e.jsx("span",{className:`w-3 h-3 rounded-full ${t.dot}`}),e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:r.title}),r.description&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r.description})]}),e.jsx("button",{onClick:()=>{i(r),p(!0)},className:"p-1 hover:bg-white/50 rounded",children:e.jsx(ve,{className:"w-3.5 h-3.5 text-slate-500"})}),e.jsx("button",{onClick:()=>D(r.id),className:"p-1 hover:bg-white/50 rounded",children:e.jsx(Ne,{className:"w-3.5 h-3.5 text-red-500"})})]},r.id)})})}),n&&e.jsx(ot,{category:o,onSave:N,onClose:()=>{p(!1),i(null)}})]})}function ot({category:a,onSave:s,onClose:C}){const[j,o]=u.useState({title:(a==null?void 0:a.title)||"",description:(a==null?void 0:a.description)||"",color:(a==null?void 0:a.color)||"blue",default_due_hours:(a==null?void 0:a.default_due_hours)||0});return e.jsx(U,{onClose:C,title:a?"ער××ת ×§×××ר××":"×§×××ר×× ××ש×",icon:qe,tone:"blue",maxWidth:"max-w-sm",onSave:()=>s(j),saveLabel:"ש××ר",saveDisabled:!j.title.trim(),children:e.jsx(xe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×©× ×§×××ר××"}),e.jsx("input",{className:E,value:j.title,onChange:i=>o(n=>({...n,title:i.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ת×××ר"}),e.jsx("textarea",{className:Be,value:j.description,onChange:i=>o(n=>({...n,description:i.target.value})),rows:2})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"צ××¢"}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:nt.map(i=>{const n=B(i);return e.jsx("button",{type:"button",onClick:()=>o(p=>({...p,color:i})),className:`w-8 h-8 rounded-full ${n.dot} ${j.color===i?"ring-2 ring-offset-2 ring-slate-400":""}`},i)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××× ××¢× ×ר×רת ×××× (שע×ת)"}),e.jsx("input",{type:"number",className:E,value:j.default_due_hours,onChange:i=>o(n=>({...n,default_due_hours:Number(i.target.value)}))})]})]})})})}const dt=["blue","green","red","orange","purple","gray","yellow","teal"];function ct({kibbutzId:a,statuses:s,onUpdate:C,onClose:j}){const[o,i]=u.useState(null),[n,p]=u.useState(!1);async function N(r){try{if(o)await v.entities.TaskStatus.update(o.id,r),S.success("×ס×××ס ×¢××××");else{const t=s.reduce((_,h)=>Math.max(_,h.sort_order||0),0);await v.entities.TaskStatus.create({...r,kibbutz_id:a,sort_order:t+1}),S.success("×ס×××ס × ×סף")}p(!1),i(null),C()}catch{S.error("ש×××× ×ש××ר×")}}async function D(r){if(confirm("××× ×××××§ ס×××ס ××?"))try{await v.entities.TaskStatus.delete(r),S.success("×ס×××ס × ×××§"),C()}catch{S.error("ש×××× ×××××§×")}}const m=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:j,className:"inline-flex items-center h-10 px-5 rounded-full border border-border text-sm font-medium hover:bg-slate-50 transition-colors",children:"ס××ר×"}),e.jsxs("button",{type:"button",onClick:()=>{i(null),p(!0)},className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full text-white text-sm font-bold transition-colors bg-blue-600 hover:bg-blue-700",children:[e.jsx(_e,{className:"w-4 h-4"})," ××סף ס×××ס"]})]});return e.jsxs(e.Fragment,{children:[e.jsx(U,{onClose:j,title:"× ×××× ×¡×××ס××",icon:Ze,tone:"blue",maxWidth:"max-w-lg",footer:m,children:e.jsx("div",{className:"space-y-2",children:s.sort((r,t)=>
1(r.sort_order||0)-(t.sort_order||0)).map(r=>{const t=B(r.color);return e.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border ${t.border} ${t.bg}`,children:[e.jsx(Bs,{className:"w-4 h-4 text-slate-400"}),e.jsx("span",{className:`w-3 h-3 rounded-full ${t.dot}`}),e.jsx("span",{className:"text-sm font-medium flex-1",children:r.title}),r.is_open&&e.jsx("span",{className:"text-xs text-blue-600",children:"פת××"}),r.is_closed&&e.jsx("span",{className:"text-xs text-slate-500",children:"ס××ר"}),r.requires_manager_approval&&e.jsx("span",{className:"text-xs text-purple-600",children:"××רש ××ש×ר"}),e.jsx("button",{onClick:()=>{i(r),p(!0)},className:"p-1 hover:bg-white/50 rounded",children:e.jsx(ve,{className:"w-3.5 h-3.5 text-slate-500"})}),e.jsx("button",{onClick:()=>D(r.id),className:"p-1 hover:bg-white/50 rounded",children:e.jsx(Ne,{className:"w-3.5 h-3.5 text-red-500"})})]},r.id)})})}),n&&e.jsx(mt,{status:o,onSave:N,onClose:()=>{p(!1),i(null)}})]})}function mt({status:a,onSave:s,onClose:C}){const[j,o]=u.useState({title:(a==null?void 0:a.title)||"",color:(a==null?void 0:a.color)||"blue",is_open:(a==null?void 0:a.is_open)??!0,is_closed:(a==null?void 0:a.is_closed)??!1,requires_manager_approval:(a==null?void 0:a.requires_manager_approval)??!1,notify_on_change:(a==null?void 0:a.notify_on_change)??!1});return e.jsx(U,{onClose:C,title:a?"ער××ת ס×××ס":"ס×××ס ××ש",icon:Ze,tone:"blue",maxWidth:"max-w-sm",onSave:()=>s(j),saveLabel:"ש××ר",saveDisabled:!j.title.trim(),children:e.jsx(xe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×©× ×¡×××ס"}),e.jsx("input",{className:E,value:j.title,onChange:i=>o(n=>({...n,title:i.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"צ××¢"}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:dt.map(i=>{const n=B(i);return e.jsx("button",{type:"button",onClick:()=>o(p=>({...p,color:i})),className:`w-8 h-8 rounded-full ${n.dot} ${j.color===i?"ring-2 ring-offset-2 ring-slate-400":""}`},i)})})]}),e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer py-1",children:[e.jsx(X,{checked:j.is_open,onCheckedChange:i=>o(n=>({...n,is_open:i}))}),e.jsx("span",{className:"text-sm",children:"× ××©× ×¤×ª××"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer py-1",children:[e.jsx(X,{checked:j.is_closed,onCheckedChange:i=>o(n=>({...n,is_closed:i}))}),e.jsx("span",{className:"text-sm",children:"× ××©× ×¡××ר"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer py-1",children:[e.jsx(X,{checked:j.requires_manager_approval,onCheckedChange:i=>o(n=>({...n,requires_manager_approval:i}))}),e.jsx("span",{className:"text-sm",children:"××רש ××ש×ר ×× ××"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer py-1",children:[e.jsx(X,{checked:j.notify_on_change,onCheckedChange:i=>o(n=>({...n,notify_on_change:i}))}),e.jsx("span",{className:"text-sm",children:"ש×× ×תר×× ×ש×× ××"})]})]})]})})})}function xt({kibbutzId:a,settings:s,statuses:C,onSave:j,onClose:o}){const[i,n]=u.useState(null),[p,N]=u.useState(!1);if(u.useEffect(()=>{n({allow_external_workers:(s==null?void 0:s.allow_external_workers)??!0,enable_recurring_tasks:(s==null?void 0:s.enable_recurring_tasks)??!0,enable_time_reports:(s==null?void 0:s.enable_time_reports)??!1,require_manager_approval_to_close:(s==null?void 0:s.require_manager_approval_to_close)??!1,default_reminder_hours:(s==null?void 0:s.default_reminder_hours)??24,default_status_id:(s==null?void 0:s.default_status_id)||"",default_priority:(s==null?void 0:s.default_priority)||"normal",enable_whatsapp:(s==null?void 0:s.enable_whatsapp)??!1,enable_email:(s==null?void 0:s.enable_email)??!1,worker_can_delete_logs:(s==null?void 0:s.worker_can_delete_logs)??!1,worker_can_change_due_date:(s==null?void 0:s.worker_can_change_due_date)??!1})},[s]),!i)return null;async function D(){N(!0);try{s!=null&&s.id?await v.entities.TaskSettings.update(s.id,i):await v.entities.TaskSettings.create({...i,kibbutz_id:a}),S.success("××××ר×ת × ×©×ר×"),j()}catch{S.error("ש×××× ×ש××רת ×××ר×ת")}finally{N(!1)}}const m=[{key:"allow_external_workers",label:"×פשר ×¢××××× ××צ×× ×××"},{key:"enable_recurring_tasks",label:"×פשר ×ש×××ת ×××ר×ת"},{key:"enable_time_reports",label:"××¤×¢× ××××× ×©×¢×ת ×¢××××"},{key:"require_manager_approval_to_close",label:"× ×רש ××ש×ר ×× ×× ×ס××רת ×ש×××"},{key:"enable_whatsapp",label:"ש×××ת ×תר××ת WhatsApp"},{key:"enable_email",label:'ש×××ת ×תר××ת ×××"×'},{key:"worker_can_delete_logs",label:"×¢××× ×××× ×××××§ ת××¢×× ×©××"},{key:"worker_can_change_due_date",label:"×¢××× ×××× ××©× ×ת ת×ר×× ××¢×"}];return e.jsxs(U,{onClose:o,title:"×××ר×ת × ×××× ×ש×××ת",icon:Je,tone:"blue",maxWidth:"max-w-lg",onSave:D,saving:p,saveLabel:"ש××ר ×××ר×ת",children:[e.jsx(xe,{children:e.jsx("div",{className:"space-y-1",children:m.map(r=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer p-2 rounded-lg hover:bg-white/70",children:[e.jsx(X,{checked:i[r.key],onCheckedChange:t=>n(_=>({..._,[r.key]:t}))}),e.jsx("span",{className:"text-sm",children:r.label})]},r.key))})}),e.jsx(xe,{title:"×ר×ר×ת ××××",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ת×××רת ×ר×רת ×××× (שע×ת ××¤× × ××¢×)"}),e.jsx("input",{type:"number",className:E,value:i.default_reminder_hours,onChange:r=>n(t=>({...t,default_reminder_hours:Number(r.target.value)}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×¢××פ×ת ×ר×רת ××××"}),e.jsx("select",{value:i.default_priority,onChange:r=>n(t=>({...t,default_priority:r.target.value}
1)),className:E,children:Object.entries(ce).map(([r,t])=>e.jsx("option",{value:r,children:t},r))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ס×××ס ×ר×רת ×××× ××ש××× ××ש×"}),e.jsxs("select",{value:i.default_status_id,onChange:r=>n(t=>({...t,default_status_id:r.target.value})),className:E,children:[e.jsx("option",{value:"",children:"××ר ס×××ס"}),C.map(r=>e.jsx("option",{value:r.id,children:r.title},r.id))]})]})]})})]})}function Qe({tasks:a,statuses:s,workers:C,categories:j,onTaskClick:o,onStatusChange:i}){const n=[...s].filter(m=>m.is_active!==!1).sort((m,r)=>(m.sort_order||0)-(r.sort_order||0));function p(m){return a.filter(r=>(r.status_id||"")===m).sort((r,t)=>(me[t.priority]||2)-(me[r.priority]||2))}function N(m){if(!m.destination)return;const r=m.draggableId,t=m.destination.droppableId;i(r,t)}function D(m){return!m||m.length===0?"×× ×©×××":m.map(r=>{var t;return((t=C.find(_=>_.id===r))==null?void 0:t.full_name)||"?"}).join(", ")}return e.jsx(Ks,{onDragEnd:N,children:e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-4",dir:"rtl",children:n.map(m=>{const r=B(m.color),t=p(m.id);return e.jsxs("div",{className:"flex-1 min-w-[12.5rem] max-w-xs",children:[e.jsx("div",{className:`rounded-xl border ${r.border} ${r.bg} p-3 mb-2`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${r.dot} flex-none`}),e.jsx("span",{className:"text-sm font-bold truncate min-w-0",children:m.title}),e.jsx("span",{className:"text-xs text-muted-foreground mr-auto flex-none",children:t.length})]})}),e.jsx(Is,{droppableId:m.id,children:(_,h)=>e.jsxs("div",{ref:_.innerRef,..._.droppableProps,className:`space-y-2 min-h-[100px] p-1 rounded-xl transition-colors ${h.isDraggingOver?"bg-blue-50/50":""}`,children:[t.map((b,g)=>{const c=J[b.priority]||J.normal,y=Z(b);return e.jsx(Ys,{draggableId:b.id,index:g,children:(A,M)=>{var $,k;return e.jsxs("div",{ref:A.innerRef,...A.draggableProps,...A.dragHandleProps,onClick:()=>o(b),className:`bg-white rounded-lg border ${y?"border-red-200":"border-border"} shadow-sm p-3 cursor-pointer hover:shadow-md transition-all ${M.isDragging?"shadow-lg ring-2 ring-blue-200":""}`,children:[e.jsxs("div",{className:"flex items-start gap-2 mb-1.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${c.dot} mt-1.5 flex-shrink-0`}),e.jsx("p",{className:"text-sm font-medium text-foreground line-clamp-2 flex-1",children:b.title})]}),b.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1 mb-2",children:b.description}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-xs text-muted-foreground",children:[b.due_date&&e.jsxs("span",{className:`flex items-center gap-1 ${y?"text-red-600 font-medium":""}`,children:[y?e.jsx(oe,{className:"w-3 h-3"}):e.jsx(de,{className:"w-3 h-3"}),ie(b.due_date)]}),((($=b.files)==null?void 0:$.length)>0||((k=b.images)==null?void 0:k.length)>0)&&e.jsx(ge,{className:"w-3 h-3"})]}),e.jsx("div",{className:"mt-2 pt-2 border-t border-border",children:e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:D(b.assignee_ids)})})]})}},b.id)}),_.placeholder]})})]},m.id)})})})}function ut({tasks:a,statuses:s,workers:C,categories:j,onTaskClick:o,onEdit:i,onDuplicate:n,onDelete:p}){const N=[...a].sort((t,_)=>{const h=me[t.priority]??2,b=me[_.priority]??2;return h!==b?b-h:(t.task_number||0)-(_.task_number||0)});function D(t){return s.find(_=>_.id===t)}function m(t){return j.find(_=>_.id===t)}function r(t){return!t||t.length===0?"â":t.map(_=>{var h;return((h=C.find(b=>b.id===_))==null?void 0:h.full_name)||"?"}).join(", ")}return e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-slate-50 text-muted-foreground",children:[e.jsx("th",{className:"text-right p-3 font-medium",children:"#"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"××תרת"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"×§×××ר××"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"××ר××"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"×¢××פ×ת"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"ס×××ס"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"ת×ר×× ××¢×"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"פע×××ת"})]})}),e.jsxs("tbody",{children:[N.map(t=>{const _=D(t.status_id),h=_?B(_.color):B("gray"),b=J[t.priority]||J.normal,g=m(t.category_id),c=Z(t);return e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-accent/30 transition-colors",children:[e.jsx("td",{className:"p-3 text-muted-foreground",children:t.task_number||""}),e.jsx("td",{className:"p-3",children:e.jsxs("button",{onClick:()=>o(t),className:"text-right",children:[e.jsx("span",{className:"font-medium text-foreground hover:text-blue-600",children:t.title}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:t.description})]})}),e.jsx("td",{className:"p-3 text-muted-foreground",children:(g==null?void 0:g.title)||"â"}),e.jsx("td",{className:"p-3 text-muted-foreground text-xs",children:r(t.assignee_ids)}),e.jsx("td",{className:"p-3",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs ${b.bg} ${b.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${b.dot}`}),ce[t.priority]||""]})}),e.jsx("td",{className:"p-3",children:e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs ${h.bg} ${h.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${h.dot}`}),(_==null?void 0:_.title)||"â"]}
1)}),e.jsx("td",{className:"p-3",children:t.due_date?e.jsxs("span",{className:`flex items-center gap-1 ${c?"text-red-600 font-medium":"text-muted-foreground"}`,children:[c&&e.jsx(oe,{className:"w-3 h-3"}),ie(t.due_date)]}):"â"}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>o(t),className:"p-1.5 hover:bg-accent rounded text-slate-500",children:e.jsx(vs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>i(t),className:"p-1.5 hover:bg-accent rounded text-blue-500",children:e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>n(t),className:"p-1.5 hover:bg-accent rounded text-emerald-500",children:e.jsx(zs,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>p(t),className:"p-1.5 hover:bg-accent rounded text-red-500",children:e.jsx(Ne,{className:"w-4 h-4"})})]})})]},t.id)}),N.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"text-center text-muted-foreground py-12",children:"××× ×ש×××ת ××צ××"})})]})]})})})}const ht=["×","×","×","×","×","×","ש"],pt=["×× ××ר","פ×ר××ר","×רץ","×פר××","×××","××× ×","××××","××××ס×","ספ×××ר","×××§×××ר","× ××××ר","×צ××ר"];function ft({tasks:a,statuses:s,workers:C,onTaskClick:j}){const[o,i]=u.useState(new Date),n=o.getFullYear(),p=o.getMonth(),N=new Date(n,p,1),D=new Date(n,p+1,0),m=N.getDay(),r=D.getDate(),t=[];for(let c=0;c<m;c++)t.push(null);for(let c=1;c<=r;c++)t.push(new Date(n,p,c));function _(c){return c?a.filter(y=>y.due_date?new Date(y.due_date).toDateString()===c.toDateString():!1):[]}function h(){i(new Date(n,p-1,1))}function b(){i(new Date(n,p+1,1))}function g(){i(new Date)}return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",dir:"rtl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{className:"text-base font-bold",children:[pt[p]," ",n]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:h,className:"p-1.5 rounded-lg hover:bg-accent",children:e.jsx(ys,{className:"w-5 h-5"})}),e.jsx("button",{onClick:g,className:"px-3 py-1 text-sm rounded-lg border border-border hover:bg-accent",children:"××××"}),e.jsx("button",{onClick:b,className:"p-1.5 rounded-lg hover:bg-accent",children:e.jsx(Gs,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:ht.map(c=>e.jsx("div",{className:"text-center text-xs font-medium text-muted-foreground py-2",children:c},c))}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:t.map((c,y)=>{const A=_(c),M=c&&c.toDateString()===new Date().toDateString();return e.jsxs("div",{className:`min-h-[80px] border border-border rounded-lg p-1.5 ${c?"bg-white":"bg-slate-50/50"} ${M?"ring-2 ring-blue-200":""}`,children:[c&&e.jsx("span",{className:`text-xs font-medium ${M?"text-blue-600":"text-muted-foreground"}`,children:c.getDate()}),e.jsxs("div",{className:"space-y-1 mt-1",children:[A.slice(0,3).map($=>{const k=s.find(ee=>ee.id===$.status_id),z=k?B(k.color):B("gray"),K=J[$.priority]||J.normal;return e.jsxs("button",{onClick:()=>j($),className:"w-full text-right text-xs px-1.5 py-0.5 rounded truncate hover:shadow-sm transition-shadow",style:{backgroundColor:"transparent"},children:[e.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${K.dot} ml-1`}),e.jsx("span",{className:`${z.text}`,children:$.title})]},$.id)}),A.length>3&&e.jsxs("p",{className:"text-xs text-muted-foreground px-1",children:["+",A.length-3," ×¢××"]})]})]},y)})})]})}const Xe=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#6b7280","#14b8a6","#ec4899"];function bt({tasks:a,workers:s,statuses:C,categories:j,settings:o}){const i=u.useMemo(()=>{const n=C.map(h=>({name:h.title,value:a.filter(b=>b.status_id===h.id).length,color:B(h.color).dot})).filter(h=>h.value>0),p=s.map(h=>({name:h.full_name,total:a.filter(b=>{var g;return(g=b.assignee_ids)==null?void 0:g.includes(h.id)}).length,completed:a.filter(b=>{var g;return((g=b.assignee_ids)==null?void 0:g.includes(h.id))&&b.closed_at}).length,overdue:a.filter(b=>{var g;return((g=b.assignee_ids)==null?void 0:g.includes(h.id))&&Z(b)}).length})).filter(h=>h.total>0).sort((h,b)=>b.total-h.total),N=j.map(h=>({name:h.title,value:a.filter(b=>b.category_id===h.id).length})).filter(h=>h.value>0).sort((h,b)=>b.value-h.value),D=a.filter(h=>Z(h)).length,m=a.filter(h=>$e(h)).length,r=a.length,t=a.filter(h=>{const b=C.find(g=>g.id===h.status_id);return b==null?void 0:b.is_open}).length,_=r>0?Math.round(a.filter(h=>h.closed_at).length/r*100):0;return{byStatus:n,byWorker:p,byCategory:N,overdue:D,completedThisMonth:m,total:r,openCount:t,completionRate:_}},[a,s,C,j]);return e.jsxs("div",{className:"space-y-4",dir:"rtl",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(ke,{icon:De,label:"ס××´× ×ש×××ת",value:i.total,color:"text-blue-600",bg:"bg-blue-50"}),e.jsx(ke,{icon:de,label:"פת×××ת",value:i.openCount,color:"text-teal-600",bg:"bg-teal-50"}),e.jsx(ke,{icon:oe,label:"×××××ר",value:i.overdue,color:"text-red-600",bg:"bg-red-50"}),e.jsx(ke,{icon:Ae,label:"××ש××× ××××ש",value:i.completedThisMonth,color:"text-emerald-600",bg:"bg-emerald-50"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[i.byStatus.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[e.jsx("h3",{className:"text-sm font-bold mb-3",children:"×ש×××ת ××¤× ×¡×××ס"}),e.jsx(Ge,{width:"100%",height:250,children:e.jsxs(Hs,{children:[e.jsx(Qs,{data:i.byStatus,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:80,label:!0,children:i.byStatus.map((n,p)=>e.jsx(Vs,{fill:Xe[p%Xe.length]},p))}),e.jsx(Ve,{}),e.jsx(He,{})]})})]}),i.byWorker.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[e.jsx("h3",{className:"text-sm font-bold mb-3",children:"×ש×××ת ××¤× ×¢×××"}),e.jsx(Ge,{width:"100%",height:250,children:e.jsxs(Xs,{data:i.byWorker.slice(0,8),children:[e.jsx(Zs,{dataKey:"name",tick:{fontSize:11},angle:-20,textAnchor:"end",height:60}),e.jsx(Js,{tick:{fontSize:11}}),e.jsx(Ve,{}),e.jsx(He,{}),e.jsx(Oe,{dataKey:"total",name:"ס××´×",fill:"#3b82f6"}),e.jsx(Oe,{dataKey:"completed",name:"××ש×××",fill:"#10b981"}),e.jsx(Oe,{dataKey:"overdue",name:"×××××ר",fill:"#ef4444"})]})})]})]}),i.byWorker.length>0&&e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",children:[e.jsx("h3",{className:"text-sm font-bold p-4 border-b border-border",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-border bg-slate-50 text-muted-foreground",children:[e.jsx("th",{className:"text-right p-3 font-medium",children:"×¢×××"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"ס××´×"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"××ש×××"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"×××××ר"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"×××× ×ש×××"})]})}),e.jsx("tbody",{children:i.byWorker.map(n=>e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-accent/30",children:[e.jsx("td",{className:"p-3 font-medium",children:n.name}),e.jsx("td",{className:"p-3",children:n.total}),e.jsx("td",{className:"p-3 text-emerald-600",children:n.completed}),e.jsx("td",{className:"p-3 text-red-600",children:n.overdue}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-slate-100 rounded-full overflow-hidden max-w-[100px]",children:e.jsx("div",{className:"h-full bg-emerald-500 rounded-full",style:{width:`${n.total>0?n.completed/n.total*100:0}%`}})}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[n.total>0?Math.round(n.completed/n.total*100):0,"%"]})]})})]},n.name))})]})})]})]})}function ke({icon:a,label:s,value:C,color:j,bg:o}){return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4",children:[e.jsx("div",{className:`w-9 h-9 rounded-lg ${o} flex items-center justify-center mb-2`,children:e.jsx(a,{className:`w-5 h-5 ${j}`})}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:C}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})}const gt=[{value:0,label:"ר×ש××"},{value:1,label:"×©× ×"},{value:2,label:"ש××ש×"},{value:3,label:"ר×××¢×"},{value:4,label:"×××ש×"},{value:5,label:"ש×ש×"},{value:6,label:"ש×ת"}];function jt({kibbutzId:a,recurringTasks:s,categories:C,workers:j,onUpdate:o,onClose:i}){const[n,p]=u.useState(null),[N,D]=u.useState(!1);async function m(t){if(confirm("××× ×××××§ ×ש××× ×××רת?"))try{await v.entities.RecurringTask.delete(t),S.success("××ש××× ××××רת × ×××§×"),o()}catch{S.error("ש×××× ×××××§×")}}const r=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:i,className:"inline-flex items-center h-10 px-5 rounded-full border border-border text-sm font-medium hover:bg-slate-50 transition-colors",children:"ס××ר×"}),e.jsxs("button",{type:"button",onClick:()=>{p(null),D(!0)},className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full text-white text-sm font-bold transition-colors bg-blue-600 hover:bg-blue-700",children:[e.jsx(_e,{className:"w-4 h-4"})," ××סף ×ש××× ×××רת"]})]});return e.jsxs(e.Fragment,{children:[e.jsx(U,{onClose:i,title:"×ש×××ת ×××ר×ת",icon:je,tone
1:"blue",maxWidth:"max-w-2xl",footer:r,children:e.jsxs("div",{className:"space-y-2",children:[s.map(t=>{const _=C.find(h=>h.id===t.category_id);return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-border bg-white",children:[e.jsx(je,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-0.5",children:[e.jsx("span",{children:ss[t.frequency]}),_&&e.jsxs("span",{children:["⢠",_.title]}),t.is_active===!1&&e.jsx("span",{className:"text-red-500",children:"⢠×× ×¤×¢××"})]})]}),e.jsx("button",{onClick:()=>{p(t),D(!0)},className:"p-1.5 hover:bg-accent rounded",children:e.jsx(ve,{className:"w-4 h-4 text-slate-500"})}),e.jsx("button",{onClick:()=>m(t.id),className:"p-1.5 hover:bg-accent rounded",children:e.jsx(Ne,{className:"w-4 h-4 text-red-500"})})]},t.id)}),s.length===0&&e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8",children:"××× ×ש×××ת ×××ר×ת"})]})}),N&&e.jsx(_t,{kibbutzId:a,task:n,categories:C,workers:j,onSave:async()=>{await o(),D(!1),p(null)},onClose:()=>{D(!1),p(null)}})]})}function _t({kibbutzId:a,task:s,categories:C,workers:j,onSave:o,onClose:i}){const[n,p]=u.useState({title:(s==null?void 0:s.title)||"",description:(s==null?void 0:s.description)||"",category_id:(s==null?void 0:s.category_id)||"",assignee_ids:(s==null?void 0:s.assignee_ids)||[],priority:(s==null?void 0:s.priority)||"normal",frequency:(s==null?void 0:s.frequency)||"weekly",start_date:(s==null?void 0:s.start_date)||"",end_date:(s==null?void 0:s.end_date)||"",day_of_week:(s==null?void 0:s.day_of_week)??1,day_of_month:(s==null?void 0:s.day_of_month)??1,create_days_ahead:(s==null?void 0:s.create_days_ahead)??7,is_active:(s==null?void 0:s.is_active)??!0}),[N,D]=u.useState(!1);async function m(){if(n.title.trim()){D(!0);try{s?(await v.entities.RecurringTask.update(s.id,n),S.success("××ש××× ××××רת ×¢×××× ×")):(await v.entities.RecurringTask.create({...n,kibbutz_id:a}),S.success("××ש××× ××××רת × ×ספ×")),o()}catch{S.error("ש×××× ×ש××ר×")}finally{D(!1)}}}return e.jsx(U,{onClose:i,title:s?"ער××ת ×ש××× ×××רת":"×ש××× ×××רת ××ש×",icon:je,tone:"blue",maxWidth:"max-w-lg",onSave:m,saving:N,saveLabel:"ש××ר",saveDisabled:!n.title.trim(),children:e.jsx(xe,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××תרת *"}),e.jsx("input",{className:E,value:n.title,onChange:r=>p(t=>({...t,title:r.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ת×××ר"}),e.jsx("textarea",{className:Be,value:n.description,onChange:r=>p(t=>({...t,description:r.target.value})),rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×§×××ר××"}),e.jsxs("select",{value:n.category_id,onChange:r=>p(t=>({...t,category_id:r.target.value})),className:E,children:[e.jsx("option",{value:"",children:"××ר ×§×××ר××"}),C.map(r=>e.jsx("option",{value:r.id,children:r.title},r.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"×¢××פ×ת"}),e.jsx("select",{value:n.priority,onChange:r=>p(t=>({...t,priority:r.target.value})),className:E,children:Object.entries(ce).map(([r,t])=>e.jsx("option",{value:r,children:t},r))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ת××ר×ת"}),e.jsx("select",{value:n.frequency,onChange:r=>p(t=>({...t,frequency:r.target.value})),className:E,children:Object.entries(ss).map(([r,t])=>e.jsx("option",{value:r,children:t},r))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ת×ר×× ×ת×××"}),e.jsx("input",{type:"date",className:E,value:n.start_date,onChange:r=>p(t=>({...t,start_date:r.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"ת×ר×× ×¡×××"}),e.jsx("input",{type:"date",className:E,value:n.end_date,onChange:r=>p(t=>({...t,end_date:r.target.value}))})]})]}),n.frequency==="weekly"&&e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××× ×ש×××¢"}),e.jsx("select",{value:n.day_of_week,onChange:r=>p(t=>({...t,day_of_week:Number(r.target.value)}
1)),className:E,children:gt.map(r=>e.jsx("option",{value:r.value,children:r.label},r.value))})]}),(n.frequency==="monthly"||n.frequency==="quarterly"||n.frequency==="yearly")&&e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××× ××××ש"}),e.jsx("input",{type:"number",min:1,max:31,className:E,value:n.day_of_month,onChange:r=>p(t=>({...t,day_of_month:Number(r.target.value)}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:F,children:"××× ×××× ×ר×ש ××צ×ר"}),e.jsx("input",{type:"number",className:E,value:n.create_days_ahead,onChange:r=>p(t=>({...t,create_days_ahead:Number(r.target.value)}))})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:n.is_active,onChange:r=>p(t=>({...t,is_active:r.target.checked})),className:"rounded"}),e.jsx("span",{className:"text-sm",children:"פע××"})]})]})})})}const Nt=[{key:"new_task",label:"×צ×רת ×ש××× ××ש×",icon:_e,iconBg:"bg-blue-50",iconColor:"text-blue-600"},{key:"workers",label:"× ×××× ×¢××××× ×××¢×× ×ª×¤×§××××",icon:Me,iconBg:"bg-emerald-50",iconColor:"text-emerald-600",separatorBefore:!0},{key:"categories",label:"× ×××× ×§×××ר××ת ×ש×××ת",icon:qe,iconBg:"bg-orange-50",iconColor:"text-orange-600"},{key:"statuses",label:"× ×××× ×¡×××ס××",icon:Ue,iconBg:"bg-purple-50",iconColor:"text-purple-600"},{key:"recurring",label:"×ש×××ת ×××ר×ת",icon:je,iconBg:"bg-teal-50",iconColor:"text-teal-600"},{key:"reports",label:"××××ת ××צ××¢",icon:es,iconBg:"bg-indigo-50",iconColor:"text-indigo-600"},{key:"export",label:"××צ×× ××קס×",icon:Ts,iconBg:"bg-rose-50",iconColor:"text-rose-600",separatorBefore:!0},{key:"settings",label:"×××ר×ת × ×××× ×ש×××ת",icon:Je,iconBg:"bg-slate-100",iconColor:"text-slate-600"}],vt=[{key:"kanban",label:"××× Kanban",icon:Ds},{key:"table",label:"××××",icon:et},{key:"calendar",label:"××× ×©× ×",icon:Ls},{key:"mine",label:"××ש×××ת ש××",icon:We},{key:"reports",label:"××××ת",icon:es}];function ea({kibbutzId:a}){var ze;const{t:s}=ws(),C=Cs(),{kibbutz:j}=((ze=Ss)==null?void 0:ze())||{},[o,i]=u.useState([]),[n,p]=u.useState([]),[N,D]=u.useState([]),[m,r]=u.useState([]),[t,_]=u.useState(null),[h,b]=u.useState([]),[g,c]=u.useState(null),[y,A]=u.useState(!0),[M,$]=u.useState(!1),[k,z]=u.useState("kanban"),[K,ee]=u.useState(""),[G,ue]=u.useState("all"),[V,te]=u.useState("all"),[H,ye]=u.useState("all"),[Q,he]=u.useState("all"),[se,pe]=u.useState("all"),[d,L]=u.useState(!1),[O,W]=u.useState(null),[P,I]=u.useState(null),[we,fe]=u.useState(!1),[Y,ae]=u.useState(!1),[as,Ke]=u.useState(!1),[ls,Le]=u.useState(!1),[rs,Ie]=u.useState(!1),q=u.useCallback(async()=>{var l;if(a)try{$(!1);const[f,w,T,x,R,le,re]=await Promise.all([v.auth.me().catch(()=>null),v.entities.TaskItem.filter({kibbutz_id:a},"-created_date",500),v.entities.TaskWorker.filter({kibbutz_id:a},"sort_order",200),v.entities.TaskCategory.filter({kibbutz_id:a},"sort_order",100),v.entities.TaskStatus.filter({kibbutz_id:a},"sort_order",50),v.entities.TaskSettings.filter({kibbutz_id:a}),v.entities.RecurringTask.filter({kibbutz_id:a},"-created_date",100)]);c(f);let ne=R;R.length===0&&(ne=await Promise.all(Ws.map(Fe=>v.entities.TaskStatus.create({...Fe,kibbutz_id:a})))),r(ne);let Se=x;x.length===0&&(Se=await Promise.all($s.map(Fe=>v.entities.TaskCategory.create({...Fe,kibbutz_id:a})))),D(Se);let Re=le[0]||null;Re||(Re=await v.entities.TaskSettings.create({kibbutz_id:a,default_status_id:((l=ne[0])==null?void 0:l.id)||""})),_(Re),i(w),p(T),b(re)}catch(f){console.error(f),$(!0)}finally{A(!1)}},[a]);u.useEffect(()=>{q()},[q]);const ns=u.useMemo(()=>{const l=new Set(m.filter(x=>x.is_open&&!x.is_closed).map(x=>x.id)),f=m.find(x=>{var R;return(R=x.title)==null?void 0:R.includes("×××פ××")}),w=m.find(x=>{var R;return((R=x.title)==null?void 0:R.includes("××ת×× ×××ש×ר"))||x.requires_manager_approval}),T=new Set;return o.forEach(x=>(x.assignee_ids||[]).forEach(R=>T.add(R))),{all:o.length,open:o.filter(x=>l.has(x.status_id)&&!x.closed_at).length,in_progress:f?o.filter(x=>x.status_id===f.id).length:0,overdue:o.filter(x=>Z(x)).length,completed_this_month:o.filter(x=>$e(x)).length,pending_approval:w?o.filter(x=>x.status_id===w.id).length:0,recurring:o.filter(x=>x.is_recurring).length,active_workers:n.filter(x=>x.is_active!==!1&&T.has(x.id)).length}},[o,m,n]),is=[{key:"all",label:"×× ××ש×××ת",desc:"×× ××ש×××ת ××ער×ת",icon:Ue,color:"text-blue-600",bg:"bg-blue-50"},{key:"open",label:"פת×××ת",desc:"×ש×××ת שע×××× ×× ×ת××××",icon:de,color:"text-teal-600",bg:"bg-teal-50"}
1,{key:"in_progress",label:"×××פ××",desc:"×ש×××ת ×©× ×צ××ת ×××צ××¢",icon:je,color:"text-amber-600",bg:"bg-amber-50"},{key:"overdue",label:"×××××ר",desc:"×ש×××ת שע××¨× ×ת ת×ר×× ×××¢×",icon:oe,color:"text-red-600",bg:"bg-red-50"},{key:"completed_this_month",label:"××ש××× ××××ש",desc:"×ש×××ת ש×××¦×¢× ××××ש",icon:Ae,color:"text-emerald-600",bg:"bg-emerald-50"},{key:"pending_approval",label:"××ת×× ×ת ×××ש×ר",desc:"××ת×× ×ת ×ס××רת ×× ××",icon:We,color:"text-purple-600",bg:"bg-purple-50"},{key:"recurring",label:"×ש×××ת ×××ר×ת",desc:"×ש×××ת ××××¨× ×××××××ת",icon:Us,color:"text-teal-600",bg:"bg-teal-50"},{key:"active_workers",label:"×¢××××× ×¤×¢××××",desc:"×¢××××× ×¢× ×ש×××ת פע×××ת",icon:De,color:"text-indigo-600",bg:"bg-indigo-50"}],Ce=u.useMemo(()=>g?n.find(l=>l.email===g.email||l.resident_id===g.id):null,[n,g]),be=u.useMemo(()=>{let l=[...o];if(k==="mine"&&Ce&&(l=l.filter(f=>(f.assignee_ids||[]).includes(Ce.id))),se!=="all"){const f=new Set(m.filter(x=>x.is_open&&!x.is_closed).map(x=>x.id)),w=m.find(x=>{var R;return(R=x.title)==null?void 0:R.includes("×××פ××")}),T=m.find(x=>{var R;return((R=x.title)==null?void 0:R.includes("××ת×× ×××ש×ר"))||x.requires_manager_approval});switch(se){case"open":l=l.filter(x=>f.has(x.status_id)&&!x.closed_at);break;case"in_progress":l=w?l.filter(x=>x.status_id===w.id):[];break;case"overdue":l=l.filter(x=>Z(x));break;case"completed_this_month":l=l.filter(x=>$e(x));break;case"pending_approval":l=T?l.filter(x=>x.status_id===T.id):[];break;case"recurring":l=l.filter(x=>x.is_recurring);break}}if(G!=="all"&&(l=l.filter(f=>f.status_id===G)),V!=="all"&&(l=l.filter(f=>(f.assignee_ids||[]).includes(V))),H!=="all"&&(l=l.filter(f=>f.category_id===H)),Q!=="all"&&(l=l.filter(f=>f.priority===Q)),K.trim()){const f=K.toLowerCase();l=l.filter(w=>{var T,x,R;return((T=w.title)==null?void 0:T.toLowerCase().includes(f))||((x=w.description)==null?void 0:x.toLowerCase().includes(f))||((R=w.tags)==null?void 0:R.toLowerCase().includes(f))||(w.assignee_ids||[]).some(le=>{var re,ne;return(ne=(re=n.find(Se=>Se.id===le))==null?void 0:re.full_name)==null?void 0:ne.toLowerCase().includes(f)})})}return l.sort((f,w)=>(me[w.priority]??2)-(me[f.priority]??2))},[o,m,n,k,Ce,se,G,V,H,Q,K]);function os(l){switch(l){case"new_task":C(`/kibbutz/${a}/tasks/new`);break;case"workers":fe(!0);break;case"categories":ae(!0);break;case"statuses":Ke(!0);break;case"recurring":Ie(!0);break;case"reports":z("reports"),pe("all");break;case"export":ds();break;case"settings":Le(!0);break}}function ds(){const l=be.map(f=>{const w=m.find(R=>R.id===f.status_id),T=N.find(R=>R.id===f.category_id),x=(f.assignee_ids||[]).map(R=>{var le;return((le=n.find(re=>re.id===R))==null?void 0:le.full_name)||""}).join("; ");return[f.task_number||"",f.title||"",(T==null?void 0:T.title)||"",x,ce[f.priority]||"",(w==null?void 0:w.title)||"",ie(f.due_date),Z(f)?"××":"××",ie(f.created_date),ie(f.closed_at)]});Ms(`× ××××-×ש×××ת-${(j==null?void 0:j.name)||a}.csv`,["×ס׳","××תרת","×§×××ר××","××ר×××","×¢××פ×ת","ס×××ס","ת×ר×× ××¢×","××××ר","× ×צר","× ×¡×ר"],l),S.success("×××צ×× ××ש××")}async function cs(l){try{if(l.create_separate&&l.assignee_ids.length>1){const f=o.reduce((w,T)=>Math.max(w,T.task_number||0),0);for(let w=0;w<l.assignee_ids.length;w++){const T=f+1+w;await v.entities.TaskItem.create({kibbutz_id:a,task_number:T,title:l.title,description:l.description,category_id:l.category_id,status_id:l.status_id,priority:l.priority,assignee_ids:[l.assignee_ids[w]],due_date:l.due_date,due_time:l.due_time,start_date:l.start_date,requires_manager_approval:l.requires_manager_approval,tags:l.tags,internal_notes:l.internal_notes,is_recurring:l.is_recurring,created_by:(g==null?void 0:g.full_name)||(g==null?void 0:g.email)||""})}S.success(`${l.assignee_ids.length} ×ש×××ת × ×צר×`)}else if(O){const{create_separate:f,...w}=l;await v.entities.TaskItem.update(O.id,w),S.success("××ש××× ×¢×××× ×")}else{const f=o.reduce((w,T)=>Math.max(w,T.task_number||0),0);await v.entities.TaskItem.create({...l,kibbutz_id:a,task_number:f+1,created_by:(g==null?void 0:g.full_name)||(g==null?void 0:g.email)||""}),l.is_recurring&&await v.entities.RecurringTask.create({kibbutz_id:a,title:l.title,de
1scription:l.description,category_id:l.category_id,assignee_ids:l.assignee_ids,priority:l.priority,frequency:l.frequency||"weekly",start_date:l.start_date||l.due_date,is_active:!0}),S.success("××ש××× × ×צר×")}L(!1),W(null),q()}catch(f){S.error("ש×××× ×ש××רת ×ש×××"),console.error(f)}}async function Ye(l,f){var w;try{const T=m.find(R=>R.id===f),x={status_id:f};T!=null&&T.is_closed&&(x.closed_at=new Date().toISOString()),await v.entities.TaskItem.update(l,x),await v.entities.TaskLog.create({kibbutz_id:a,task_id:l,user_id:g==null?void 0:g.id,log_type:"status_change",old_status_id:(w=o.find(R=>R.id===l))==null?void 0:w.status_id,new_status_id:f,title:`ס×××ס ש×× × ×: ${T==null?void 0:T.title}`,content:""}),q()}catch{S.error("ש×××× ×ש×× ×× ×¡×××ס")}}async function ms(l){if(confirm(`××× ×××××§ ×ת ××ש××× "${l.title}"?`))try{await v.entities.TaskItem.delete(l.id),S.success("××ש××× × ×××§×"),q()}catch{S.error("ש×××× ×××××§×")}}async function xs(l){var f;try{const w=o.reduce((T,x)=>Math.max(T,x.task_number||0),0);await v.entities.TaskItem.create({...l,id:void 0,created_date:void 0,updated_date:void 0,task_number:w+1,title:`${l.title} (×עתק)`,status_id:(t==null?void 0:t.default_status_id)||((f=m[0])==null?void 0:f.id),closed_at:null,completed_at:null,created_by:(g==null?void 0:g.full_name)||(g==null?void 0:g.email)||""}),S.success("××ש××× ×©××פ××"),q()}catch{S.error("ש×××× ×ש×פ××")}}return y?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"w-8 h-8 border-4 border-primary/20 border-t-primary rounded-full animate-spin"})}):M?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(oe,{className:"w-12 h-12 text-red-500 mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:"ש×××× ×××¢×× ×ª ×× ×ª×× ××"}),e.jsx(ks,{variant:"outline",onClick:q,children:"× ×¡× ×©××"})]}):e.jsxs("div",{dir:"rtl",children:[e.jsx("div",{className:"flex mb-6",children:e.jsx(Rs,{title:"× ×××× ×ש×××ת",items:Nt.map(l=>({...l,onClick:()=>os(l.key)}))})}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-8 gap-3 mb-6",children:is.map(l=>{const f=l.icon,w=se===l.key;return e.jsxs("button",{onClick:()=>{pe(w?"all":l.key),z(T=>T==="reports"?"kanban":T)},className:`text-right bg-white rounded-2xl border p-4 transition-all ${w?"border-blue-300 shadow-md ring-2 ring-blue-100":"border-border shadow-sm hover:shadow-md"}`,children:[e.jsx("div",{className:`w-9 h-9 rounded-lg ${l.bg} flex items-center justify-center mb-2`,children:e.jsx(f,{className:`w-5 h-5 ${l.color}`})}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:ns[l.key]||0}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:l.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.desc})]},l.key)})}),we?e.jsx(lt,{kibbutzId:a,workers:n,onUpdate:q,onClose:()=>fe(!1)}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-2 mb-4 overflow-x-auto pb-1",children:vt.map(l=>{const f=l.icon,w=k===l.key;return e.jsxs("button",{onClick:()=>z(l.key),className:`flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all whitespace-nowrap ${w?"bg-blue-600 text-white shadow-sm":"bg-white border border-border text-muted-foreground hover:bg-accent"}`,children:[e.jsx(f,{className:"w-4 h-4"}),l.label]},l.key)})}),k!=="reports"&&e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-3 mb-4",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(Pe,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),e.jsx("input",{type:"text",value:K,onChange:l=>ee(l.target.value),placeholder:"××פ×ש ×ש×××...",className:"w-full h-10 rounded-full border border-slate-200 bg-slate-50 pr-10 pl-4 text-sm focus:outline-none focus:ring-2 focus:ring-blue-100 focus:border-blue-300 focus:bg-white transition-all"})]}),e.jsxs("select",{value:G,onChange:l=>ue(l.target.value),className:"h-10 rounded-lg border border-slate-200 bg-white px-3 text-sm",children:[e.jsx("option",{value:"all",children:"×× ×ס×××ס××"}),m.map(l=>e.jsx("option",{value:l.id,children:l.title},l.id))]}),e.jsxs("select",{value:V,onChange:l=>te(l.target.value),className:"h-10 rounded-lg border border-slate-200 bg-white px-3 text-sm",children:[e.jsx("option",{value:"all",children:"×× ××¢×××××"}
1),n.map(l=>e.jsx("option",{value:l.id,children:l.full_name},l.id))]}),e.jsxs("select",{value:H,onChange:l=>ye(l.target.value),className:"h-10 rounded-lg border border-slate-200 bg-white px-3 text-sm",children:[e.jsx("option",{value:"all",children:"×× ××§×××ר××ת"}),N.map(l=>e.jsx("option",{value:l.id,children:l.title},l.id))]}),e.jsxs("select",{value:Q,onChange:l=>he(l.target.value),className:"h-10 rounded-lg border border-slate-200 bg-white px-3 text-sm",children:[e.jsx("option",{value:"all",children:"×× ××¢××פ×××ת"}),Object.entries(ce).map(([l,f])=>e.jsx("option",{value:l,children:f},l))]}),(G!=="all"||V!=="all"||H!=="all"||Q!=="all"||K)&&e.jsx("button",{onClick:()=>{ue("all"),te("all"),ye("all"),he("all"),ee("")},className:"h-10 px-3 rounded-lg border border-slate-200 bg-white text-sm text-muted-foreground hover:bg-accent",children:"× ×§×"})]})}),k==="kanban"&&e.jsx(Qe,{tasks:be,statuses:m,workers:n,categories:N,onTaskClick:I,onStatusChange:Ye}),k==="table"&&e.jsx(ut,{tasks:be,statuses:m,workers:n,categories:N,onTaskClick:I,onEdit:l=>{W(l),L(!0)},onDuplicate:xs,onDelete:ms}),k==="calendar"&&e.jsx(ft,{tasks:be,statuses:m,workers:n,onTaskClick:I}),k==="mine"&&(Ce?e.jsx(Qe,{tasks:be,statuses:m,workers:n,categories:N,onTaskClick:I,onStatusChange:Ye}):e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-12 text-center",children:[e.jsx(We,{className:"w-12 h-12 text-muted-foreground mx-auto mb-3"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["××× × ×ש××× ××¢××× ××ער×ת. ×¤× × ××× ×× ",s("community_noun_definite")," ××××¡×¤×ª× ×רש××ת ××¢×××××."]})]})),k==="reports"&&e.jsx(bt,{tasks:o,workers:n,statuses:m,categories:N,settings:t})]}),d&&e.jsx(As,{kibbutzId:a,task:O,categories:N,statuses:m,workers:n,settings:t,onSave:cs,onClose:()=>{L(!1),W(null)}}),P&&e.jsx(at,{task:P,statuses:m,workers:n,categories:N,settings:t,currentUser:g,onUpdate:q,onClose:()=>I(null)}),Y&&e.jsx(it,{kibbutzId:a,categories:N,onUpdate:q,onClose:()=>ae(!1)}),as&&e.jsx(ct,{kibbutzId:a,statuses:m,onUpdate:q,onClose:()=>Ke(!1)}),ls&&e.jsx(xt,{kibbutzId:a,settings:t,statuses:m,onSave:()=>{Le(!1),q()},onClose:()=>Le(!1)}),rs&&e.jsx(jt,{kibbutzId:a,recurringTasks:h,categories:N,workers:n,onUpdate:q,onClose:()=>Ie(!1)})]})}export{ea 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.