1import{aa as te,u as ae,t as ne,r as c,j as s,F as le,l as re,L as oe,B as K,Z as de,P as ce,w as T,X as me,b as ue,d as x,z as u,E as be}from"./index-BuF13C9R.js";import{P as xe}from"./PageHeader-BJWwaOi_.js";import{I as k}from"./input-B1pb-EbS.js";import{L as _}from"./label-CZGaFvV8.js";import{S as he,a as fe,b as pe,c as _e,d as F}from"./select-J0viKo_P.js";import{S as ge}from"./searchable-select-9WMt8E_f.js";import{M as ve}from"./ModulePermissionsGrid-j9ZpBFJp.js";import{A as w}from"./AdminSection-DFy117-w.js";import{P as je}from"./pencil-CoE4mwuD.js";import{U as ke}from"./user-x-B6i_gmPw.js";import{S as ze}from"./sliders-horizontal-D0cjPgOh.js";import{S as ye}from"./save-C6cWy1UE.js";import"./index-BGaOrCq_.js";import"./chevron-up-CCjitxk2.js";import"./popover-C_zx7N8-.js";import"./chevrons-up-down-DxohBJfN.js";import"./switch-9kzbE2Dl.js";function Ve(){var U;const{id:o}=te(),[R]=ae(),r=!!o,j=ne(),{log:C}=be(),[z,P]=c.useState(!1),[H,V]=c.useState(!0),[h,X]=c.useState([]),[M,y]=c.useState({}),[D,A]=c.useState({}),[g,$]=c.useState([]),[b,G]=c.useState(""),[O,I]=c.useState(null),[l,N]=c.useState(!1),Z=new URLSearchParams(window.location.search).get("kibbutz")||"",S=R.get("community")||"",[i,v]=c.useState({full_name:"",email:"",phone:"",kibbutz_id:Z,role:"kibbutz_manager",status:"active"}),E=e=>{v({full_name:(e==null?void 0:e.full_name)||"",email:(e==null?void 0:e.email)||"",phone:(e==null?void 0:e.phone)||"",kibbutz_id:(e==null?void 0:e.kibbutz_id)||"",role:(e==null?void 0:e.role)||"kibbutz_manager",status:(e==null?void 0:e.status)||"active"})};c.useEffect(()=>{async function e(){const t=await x.entities.Kibbutz.filter({is_deleted:!1});if(X(t),r){const a=await x.entities.AdminMembership.filter({profile_id:o});if(a.length===0){u.error("×× ×× ×× ×× × ×צ×"),j("/managers");return}$(a);const m=a.find(n=>n.kibbutz_id===S)||a[0];G(m.kibbutz_id||""),E(m),N(!1);try{const n=await x.entities.AdminModulePermission.filter({admin_user_id:o,kibbutz_id:m.kibbutz_id}),d={};n.forEach(p=>{d[p.module_key]=p.is_enabled}),A(d),y(d)}catch{}}V(!1)}e()},[o,S]);const f=(e,t)=>v(a=>({...a,[e]:t})),q=()=>{N(!0),v(e=>({...e,kibbutz_id:"",status:"active"})),A({}),y({})},J=()=>{N(!1);const e=g.find(t=>t.kibbutz_id===S)||g[0];E(e)},Q=async()=>{const e=await x.entities.AdminMembership.filter({profile_id:o});return $(e),e},W=async e=>{var a;const t=e.status==="active"?"inactive":"active";I(e.kibbutz_id);try{await x.functions.invoke("setManagerStatus",{id:o,community_id:e.kibbutz_id,status:t}),await C({action:t==="inactive"?"×ש×תת ×× ××":"×פע×ת ×× ××",targetType:"AdminUser",targetId:o,details:`${e.full_name} · ${((a=h.find(m=>m.id===e.kibbutz_id))==null?void 0:a.name)||e.kibbutz_id}`,kibbutzId:e.kibbutz_id}),u.success(t==="inactive"?"×××ר×ת ××§×××× ××ש×ת×":"×××ר×ת ××§×××× ××פע××"),await Q(),e.kibbutz_id===i.kibbutz_id&&f("status",t)}catch{u.error("×××¨×¢× ×©×××× ××¢×××× ×ס×××ס")}finally{I(null)}},Y=async e=>{var m;e.preventDefault();const t=String(i.email||"").replace(/\s+/g,""),a=String(i.full_name||"").trim();if(!a||!t||!i.kibbutz_id){u.error("×ש ×××× ×©× ×××, ×××××× ××§××××");return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)){v(n=>({...n,email:t})),u.error("×ת××ת ××××××× ××× × ×ª×§×× × â ×××§× ×¨××××× ×× ×ª×××× ×©××××× ××ת××ת");return}(t!==i.email||a!==i.full_name)&&v(n=>({...n,email:t,full_name:a})),P(!0);try{const n=r&&!l&&b&&i.kibbutz_id!==b,{data:d}=n?await x.functions.invoke("moveManagerCommunity",{id:o,from_community_id:b,to_community_id:i.kibbutz_id,role:i.role,status:i.status,module_permissions:M}):await x.functions.invoke("saveManager",{id:r?o:void 0,full_name:a,email:t,phone:i.phone,kibbutz_id:i.kibbutz_id,role:i.role,status:i.status,module_permissions:M});await C({action:n?"××¢×רת ×× ×× ××§×××× ××רת":r?l?"××ספת ×× ×× ××§×××× × ×ספת":"ער××ת ×× ××":"××ספת ×× ××",targetType:"AdminUser",targetId:(d==null?void 0:d.id)||o,details:i.full_name,kibbutzId:i.kibbutz_id});const p=((m=h.find(ie=>ie.id===i.kibbutz_id))==null?void 0:m.name)||"××§×××× ×©× ××ר×";u.success(n?`${i.full_name} ×××¢×ר ×× ×××× ${p}; ×××ר×ת ××§×××ת ××ש×ת×`:r?l?`${i.full_name} × ×סף ××× ×× ×¢××ר ${p} ×× ×סף ××§××××ת ××§××××ת ש××`:`×פר××× ×××רש××ת ×©× ${i.full_name} ×¢×××× × ××צ×××`:`${i.full_name} × ×סף ××× ×× ×§×××× ×¢××ר ${p}. × ××ª× ××שת ×××שק ××§×××× ×©×× ××¨× ×פת×ר "×ת××ר" ×רש××ת ××§××××ת.`,{duration:6e3}),j("/managers")}catch(n){const d=String((n==null?void 0:n.message)||"").trim();console.error("saveManager failed:",n),/already\s*(been)?\s*registered|already exists|duplicate/i.test(d)?u.error("×§××× ××ר ×שת×ש ×¢× ×ת××ת ×××××× ×× ××ער×ת. ×××× ×©××ת××ת ××××קת, ×× ×¤× × ×ת×××× ×ש××× ××שת×ש ××§××× ××§×××× × ×ספת."):u.error(d?`ש××רת ××× ×× × ×ש××: ${d}`:"×××¨×¢× ×©×××× ×ש××רת ××× ××. × ×¡× ×©××.",{duration:8e3})}finally{P(!1)}};if(H)return s.jsx("div",{className:"flex items-center justify-center h-64",children:s.jsx("div",{className:"w-8 h-8 border-4 border-primary/20 border-t-primary rounded-full animate-spin"})});const B=h.find(e=>e.id===i.kibbutz_id),L=r&&!l&&b&&i.kibbutz_id!==b,ee=new Set(g.filter(e=>l||e.kibbutz_id!==b).map(e=>e.kibbutz_id)),se=h.filter(e=>!ee.has(e.id));return s.jsxs("div",{dir:"rtl",children:[s.jsx(xe,{title:r?"ער××ת ×× ××":"××ספת ×× ×× ××ש",description:r?"×¢×××× ×¤×¨×× ×× ×× ××§××××"
1:"××× ×ת ×פר××× ×××ספת ×× ×× ××ש",action:s.jsxs("button",{onClick:()=>j("/managers"),className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full border border-slate-200 text-sm font-medium text-slate-600 hover:bg-slate-50 transition-colors",children:[s.jsx(le,{className:"w-4 h-4"})," ××ר×"]})}),r&&g.length>0&&s.jsx(w,{icon:re,iconBg:"bg-blue-50",iconColor:"text-blue-600",title:"×§××××ת ×ש××××ת",className:"mb-6 max-w-4xl",action:!l&&s.jsxs("button",{type:"button",onClick:q,className:"inline-flex items-center gap-1.5 h-9 px-4 rounded-full border border-slate-200 text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:[s.jsx(ce,{className:"w-4 h-4"})," ×××¡×¤× ××§×××× × ×ספת"]}),children:s.jsx("div",{className:"space-y-2",children:g.map(e=>{var a;const t=!l&&e.kibbutz_id===b;return s.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-xl border px-4 py-3 ${t?"border-primary bg-primary/5":"border-border"}`,children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"font-medium truncate",children:((a=h.find(m=>m.id===e.kibbutz_id))==null?void 0:a.name)||e.kibbutz_id}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.role==="kibbutz_manager"||e.role==="community_manager"?"×× ×× ×§××××":e.role," · ",s.jsx("span",{className:e.status==="active"?"text-emerald-600":"text-red-600",children:e.status==="active"?"פע××":"××ש×ת"})]})]}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[!t&&s.jsx(oe,{to:`/managers/${o}/edit?community=${e.kibbutz_id}`,children:s.jsx(K,{type:"button",variant:"ghost",size:"icon",title:"ער×××",children:s.jsx(je,{className:"w-4 h-4"})})}),s.jsx(K,{type:"button",variant:"ghost",size:"icon",disabled:O===e.kibbutz_id,title:e.status==="active"?"×ש×ת×":"×פע××",onClick:()=>W(e),children:e.status==="active"?s.jsx(ke,{className:"w-4 h-4 text-red-500"}):s.jsx(de,{className:"w-4 h-4 text-emerald-600"})})]})]},e.kibbutz_id)})})}),s.jsxs("form",{onSubmit:Y,className:"space-y-6 max-w-4xl",children:[s.jsxs(w,{icon:T,iconBg:"bg-indigo-50",iconColor:"text-indigo-600",title:l?"פר×× ××ר×ת ××ש×":"פר×× ××× ××",action:l&&s.jsxs("button",{type:"button",onClick:J,className:"inline-flex items-center gap-1.5 h-9 px-4 rounded-full text-sm font-medium text-slate-500 hover:bg-slate-50 transition-colors",children:[s.jsx(me,{className:"w-4 h-4"})," ××××× ×××ספ×"]}),children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-5",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx(_,{children:"×©× ××× *"}),s.jsx(k,{value:i.full_name,onChange:e=>f("full_name",e.target.value),placeholder:"×©× ×××",disabled:l})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(_,{children:"×××××× *"}),s.jsx(k,{value:i.email,onChange:e=>f("email",e.target.value),placeholder:"[email protected]",dir:"ltr",className:"text-left",disabled:r}),r&&s.jsx("p",{className:"text-xs text-muted-foreground",children:"××× ×ת××ת ××ת××ר×ת ×פ××¢× ×©× ××× ×× ××תע××× ×ª ×××××××ת ××× × â ×× × ××ª× ××©× ×ת ×××ª× ×××."})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(_,{children:"××פ××"}),s.jsx(k,{value:i.phone,onChange:e=>f("phone",e.target.value),placeholder:"050-0000000",dir:"ltr",className:"text-left",disabled:l})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(_,{children:"×§×××× *"}),s.jsx(ge,{value:i.kibbutz_id,onChange:e=>f("kibbutz_id",e),options:se.map(e=>({value:e.id,label:e.name})),placeholder:"××ר ×§××××",searchPlaceholder:"××פ×ש ×§××××â¦",emptyText:"×× × ×צ×× ×§××××"}),L&&s.jsxs("p",{className:"text-xs text-amber-600",children:["ש×× ×× ×× ××¢××ר ×ת ×× ×××× ×",((U=h.find(e=>e.id===i.kibbutz_id))==null?void 0:U.name)||"××§×××× ×©× ××ר×"," ××ש××ת ×ת ×××ר×ת ××§×××ת â ×× ××צר ××ר×ת ×פ×××."]})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(_,{children:"תפק××"}),s.jsx(k,{value:i.role==="kibbutz_manager"||i.role==="community_manager"?"×× ×× ×§××××"
1:i.role,disabled:!0})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(_,{children:"ס×××ס"}),s.jsxs(he,{value:i.status,onValueChange:e=>f("status",e),children:[s.jsx(fe,{children:s.jsx(pe,{})}),s.jsxs(_e,{children:[s.jsx(F,{value:"active",children:"פע××"}),s.jsx(F,{value:"inactive",children:"×× ×¤×¢××"})]})]})]})]}),B&&s.jsxs("div",{className:"mt-4 flex items-center gap-2 text-sm text-muted-foreground bg-muted/50 rounded-lg px-3 py-2",children:[s.jsx(T,{className:"w-4 h-4 text-primary"}),l?"××ר×ת ×××©× ×¢××ר ×§××××: ":"×ש××× ××§××××: ",s.jsx("span",{className:"font-medium text-foreground",children:B.name})]})]}),s.jsx(w,{icon:ze,iconBg:"bg-emerald-50",iconColor:"text-emerald-600",title:"×רש××ת ×××××××× ×× ××××",subtitle:"××ר ×××× ××××××× ××× ×× ×××× ×ר××ת ××× ××. ××ר×רת ×××× ×× ×××××××× ×¤×¢××××.",children:s.jsx(ve,{communityId:l?void 0:i.kibbutz_id,initialPermissions:D,onPermissionsChange:y},l?"new":i.kibbutz_id)}),s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("button",{type:"submit",disabled:z,className:"inline-flex items-center gap-2 h-11 px-7 rounded-full bg-emerald-600 text-white text-sm font-bold shadow-md hover:bg-emerald-700 active:scale-[0.98] transition-all disabled:opacity-60",children:[z?s.jsx(ue,{className:"w-4 h-4 animate-spin"}):s.jsx(ye,{className:"w-4 h-4"}),z?"ש××ר...":l?"×××¡×¤× ××§××××":L?"××¢×רת × ××××":r?"×¢××××":"ש××ר×"]}),s.jsx("button",{type:"button",onClick:()=>j("/managers"),className:"inline-flex items-center h-11 px-6 rounded-full border border-slate-200 text-sm font-bold text-slate-600 hover:bg-slate-50 transition-colors",children:"×××××"})]})]})]})}export{Ve 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.