PageSourceSearch

https://tsofit.org.il/assets/DigitalFormsModule-03tHtfdJ.js

js tsofit.org.il collected 2026-09-25 02:13:57 UTC 57,926 bytes, 6 lines download raw bytes

1import{ae as Ee,r as u,d as A,z as _,j as e,N as Ne,b as V,C as ue,ar as ge,W as Ue,aK as Oe,w as Re,y as Fe,bK as Pe,aJ as Ie,aa as Be,t as Ze,i as Ge,a1 as Je,aL as $e,ao as Ke,x as qe,a7 as We,G as Xe,aj as He,ad as Ve,T as Ye,I as Qe}from"./index-BuF13C9R.js";import{K as et}from"./KibbutzModuleGuard-ervrt65z.js";import{C as tt}from"./CategoryManagerDialog-CNC7kEFs.js";import{K as st,L as at,H as pe,I as Ae,w as Le,B as ye,D as rt,N as we,S as nt,G as ve}from"./formUtils-BlMmq8D0.js";import{M as ie}from"./ManagerDialog-CsFlI9xO.js";import{F as it}from"./FormSection-DgtCTxGQ.js";import{F as je}from"./file-json-PtVyaYdE.js";import{U as Me}from"./upload-DeFZlL4S.js";import{r as lt,C as _e,P as ot,B as dt,A as ct}from"./AdoptMediaDialog-BBiU2L17.js";import{F as mt}from"./file-archive-DG5HXvE8.js";import{F as ut}from"./file-plus-2-CSm2IEB1.js";import{S as fe}from"./sparkles-Bk9eJtR5.js";import{P as xt}from"./PageTitleMenu-DlabIv_d.js";import{R as ht}from"./ResponsibleAssignmentManager-CuJ8-GH5.js";import{g as pt}from"./formsMenu-CjM7AOnD.js";import{c as ft}from"./submissionAnswers-vQlmy5XG.js";import{P as bt}from"./pencil-CoE4mwuD.js";import{F as gt}from"./folder-tree-zXRRDRDZ.js";import{C as jt}from"./copy-BClGV4nG.js";import"./refresh-cw-DvPS6Mu1.js";import"./formStyles-CzLsWpb8.js";import"./ConfirmDialog-B9VWyx7W.js";import"./alert-dialog-BrDEU3Wj.js";import"./switch-9kzbE2Dl.js";import"./index-BGaOrCq_.js";import"./utensils-crossed-BDlbt8gO.js";import"./heart-pulse-0qDeLO71.js";import"./pill-SxQlWn91.js";import"./utensils-r-GP3VfR.js";import"./mic-g0118XVV.js";import"./film-BOiDnw57.js";import"./party-popper-gcJ6l8qF.js";import"./pizza-CgCuv15f.js";import"./tree-pine-B7Qmh7nY.js";import"./trophy-DMauxpio.js";import"./leaf-BxZ8PRn4.js";import"./graduation-cap-D9zn9IjR.js";import"./baby-BUG_dxit.js";import"./dumbbell-BjAgLDIP.js";import"./palette-CUQSS43O.js";import"./music-2TdapQX4.js";import"./chrome-C-CLIr-i.js";import"./clipboard-copy-Dqk03lsZ.js";import"./hard-drive-download-i8da1WU5.js";import"./stethoscope-BhSP9jag.js";import"./useActionVisibility-DLgqAw2q.js";import"./softDelete-X2GBluex.js";import"./input-B1pb-EbS.js";import"./residentGroupUtils-B9NnnkMJ.js";import"./bell-ring-DHDlhRvf.js";import"./chevron-left-D2IUBEPa.js";import"./image-down-Bw2HiufN.js";function Nt({kibbutzId:t,onClose:r}){const{t:n}=Ee(),[l,s]=u.useState(null),[i,c]=u.useState(!1);u.useEffect(()=>{g()},[t]);async function g(){try{const o=await A.entities.DigitalFormSettings.filter({kibbutz_id:t},null,1);if(o.length>0)s(o[0]);else{const j=await A.entities.DigitalFormSettings.create({kibbutz_id:t,...st});s(j)}}catch{_.error("שגיאה בטעינת הגדרות")}}function b(o,j){s(S=>({...S,[o]:j}))}async function x(){c(!0);try{await A.entities.DigitalFormSettings.update(l.id,l),_.success("ההגדרות נשמרו"),r()}catch{_.error("שגיאה בשמירה")}finally{c(!1)}}if(!l)return e.jsx(ie,{onClose:r,title:"הגדרות טפסים דיגיטליים",icon:Ne,tone:"blue",maxWidth:"max-w-md",hideFooter:!0,children:e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(V,{className:"w-6 h-6 text-slate-400 animate-spin"})})});const d=[{key:"show_search",label:"הצג חיפוש"},{key:"show_categories",label:"הצג קטגוריות"}];return e.jsxs(ie,{onClose:r,title:"הגדרות טפסים דיגיטליים",icon:Ne,tone:"blue",maxWidth:"max-w-md",onSave:x,saving:i,saveLabel:"שמור הגדרות",saveIcon:null,children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["הגדרות עמוד האתר (תמונה, כותרת, תיאור, תפריטים) מנוהלות דרך אתר ",n("community_noun_definite")," ← ניהול עמודים."]}),e.jsx(it,{children:d.map(o=>e.jsx(yt,{label:o.label,value:l[o.key],onChange:j=>b(o.key,j)},o.key))})]})}function yt({label:t,value:r,onChange:n}){return e.jsxs("div",{className:"flex items-center justify-between py-1.5",children:[e.jsx("span",{className:"text-sm font-medium",children:t}),e.jsx("button",{onClick:()=>n(!r),className:`w-11 h-6 rounded-full transition-colors ${r?"bg-blue-600":"bg-slate-200"}`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transition-transform ${r?"translate-x-0.5":"translate-x-5"}`})})]})}function wt({kibbutzId:t,categories:r,onClose:n,onImported:l}){const[s,i]=u.useState("upload"),[c,g]=u.useState(""),[b,x]=u.useState(""),[d,o]=u.useState(null),[j,S]=u.useState(null),[v,M]=u.useState(!1);function D(w){var N;const C=(N=w.target.files)==null?void 0:N[0];if(!C)return;x(C.name);const $=new FileReader;$.onload=O=>{g(O.target.result),i("ready")},$.readAsText(C)}async function P(){M(!0);try{const w=JSON.parse(c),C=at(w);if(!C.valid){_.error(C.error),M(!1);return}(await A.entities.DigitalForm.filter({kibbutz_id:t,slug:pe(C.form.title)},null,1)).length>0?o({...C,isDuplicate:!0}):o({...C,isDuplicate:!1}),i("preview")}catch(w){_.error("שגיאה בפענוח JSON: "+w.message)}finally{M(!1)}}async function B(){M(!0);try{const w=d.form,C=Ae((w.fields||[]).map(O=>({...Le(O.type||"text"),label:O.label||O.title||"",description:O.description||"",required:O.required||!1,options:O.options||[]}))),$=pe(w.title),N=await A.entities.DigitalForm.create({kibbutz_id:t,title:w.title,de
1scription:w.description||"",slug:$,category_id:w.category_id||null,status:w.status||"draft",fields:C,steps_enabled:w.steps_enabled||!1,steps:w.steps||[],show_on_website:!0,show_on_app:!0,show_on_homepage:!1,is_private:!1,require_login:!1,require_approval:!1,thank_you_message:"תודה על השליחה!",color:"blue",sort_order:0,is_active:!0});S({success:!0,form:N,fieldsCount:C.length,stepsCount:(w.steps||[]).length}),i("results"),_.success("הטופס נוצר")}catch(w){_.error("שגיאה בטעינה: "+w.message)}finally{M(!1)}}function p(){s==="results"&&(j!=null&&j.success)&&l(j.form),n()}const f=e.jsx("button",{type:"button",onClick:p,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:"ביטול"});let T=null;return s==="upload"?T=f:s==="ready"?T=e.jsxs(e.Fragment,{children:[f,e.jsxs("button",{type:"button",onClick:P,disabled:v,className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full bg-blue-600 hover:bg-blue-700 text-white text-sm font-bold disabled:opacity-50 transition-colors",children:[v?e.jsx(V,{className:"w-4 h-4 animate-spin"}):null," בדוק קובץ"]})]}):s==="preview"?T=e.jsxs(e.Fragment,{children:[f,e.jsxs("button",{type:"button",onClick:B,disabled:v,className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full bg-emerald-600 hover:bg-emerald-700 text-white text-sm font-bold disabled:opacity-50 transition-colors",children:[v?e.jsx(V,{className:"w-4 h-4 animate-spin"}):null," טען למערכת"]})]}):s==="results"&&(T=e.jsx("button",{type:"button",onClick:p,className:"inline-flex items-center h-10 px-5 rounded-full bg-blue-600 hover:bg-blue-700 text-white text-sm font-bold transition-colors",children:"סגור"})),e.jsxs(ie,{onClose:p,title:"טעינת טופס מ־JSON",icon:je,tone:"blue",maxWidth:"max-w-lg",footer:T,children:[(s==="upload"||s==="ready")&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:'העלה קובץ JSON עם מבנה טופס. הפורמט הנתמך: { "form": { "title", "description", "fields": [] } }'}),e.jsxs("label",{className:"flex flex-col items-center justify-center gap-2 h-32 rounded-2xl border-2 border-dashed border-slate-200 hover:border-blue-300 hover:bg-blue-50/30 cursor-pointer transition-all",children:[e.jsx(Me,{className:"w-8 h-8 text-slate-400"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:b||"בחר קובץ JSON"}),e.jsx("input",{type:"file",accept:".json",className:"hidden",onChange:D})]}),c&&e.jsxs("div",{className:"text-xs text-emerald-600 font-medium flex items-center gap-1",children:[e.jsx(ue,{className:"w-4 h-4"})," הקובץ נקרא (",(c.length/1024).toFixed(1)," KB)"]})]}),s==="preview"&&d&&e.jsxs("div",{className:"space-y-4",children:[d.isDuplicate&&e.jsxs("div",{className:"bg-amber-50 rounded-xl p-3 flex items-center gap-2",children:[e.jsx(ge,{className:"w-4 h-4 text-amber-600"}),e.jsx("p",{className:"text-sm text-amber-700",children:"קיים כבר טופס עם שם זה. ייווצר slug חדש."})]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-4 space-y-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"שם הטופס:"})," ",e.jsx("span",{className:"text-sm font-medium",children:d.form.title})]}),d.form.description&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"תיאור:"})," ",e.jsx("span",{className:"text-sm",children:d.form.description})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"מספר שדות:"})," ",e.jsx("span",{className:"text-sm font-medium",children:d.form.fields.length})]}),d.form.steps_enabled&&e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"שלבים:"})," ",e.jsx("span",{className:"text-sm font-medium",children:(d.form.steps||[]).length})]})]}),e.jsx("div",{className:"bg-white rounded-xl border border-border overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto max-h-48",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",children:[e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"שדה"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"סוג"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"חובה"})]})}),e.jsx("tbody",{children:d.form.fields.map((w,C)=>e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"px-3 py-2",children:w.label||w.title||"(ללא שם)"}),e.jsx("td",{className:"px-3 py-2 text-muted-foreground text-xs",children:w.type||"text"}),e.jsx("td",{className:"px-3 py-2",children:w.required?"✓":"—"})]},C))})]})})})]}),s==="results"&&j&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-emerald-50 rounded-xl p-4 flex items-center gap-2",children:[e.jsx(ue,{className:"w-5 h-5 text-emerald-600"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-emerald-700",children:"הטופס נוצר בהצלחה"}),e.jsxs("p",{className:"text-xs text-emerald-600",children:["נוצרו ",j.fieldsCount," שדות, ",j.stepsCount," שלבים"]})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"ניתן לערוך את הטופס ולהוסיף שדות בעמוד העריכה."})]})]})}const vt=101010256,_t=117853008,St=101075792,kt=33639248,Ct=67324752,Ft=0,$t=8,At=65577,Lt=65535,ne=4294967295;
1class q extends Error{constructor(r){super(r),this.name="ZipError"}}const le=async(t,r,n)=>new DataView(await t.slice(r,Math.min(n,t.size)).arrayBuffer());function Q(t,r){const n=t.getUint32(r,!0),s=t.getUint32(r+4,!0)*4294967296+n;if(!Number.isSafeInteger(s))throw new q("הקובץ גדול מכדי להיקרא בדפדפן");return s}const Mt=t=>new TextDecoder("utf-8").decode(t);async function Dt(t){if(t.size<22)throw new q("הקובץ אינו ארכיון ZIP תקין");const r=Math.max(0,t.size-At),n=await le(t,r,t.size);for(let l=n.byteLength-22;l>=0;l-=1)if(n.getUint32(l,!0)===vt)return{at:r+l,view:n,rel:l};throw new q("הקובץ אינו ארכיון ZIP תקין (לא נמצא אינדקס)")}async function Tt(t){const{view:r,rel:n,at:l}=await Dt(t);let s=r.getUint16(n+10,!0),i=r.getUint32(n+12,!0),c=r.getUint32(n+16,!0);if(!(s===Lt||i===ne||c===ne))return{entries:s,size:i,offset:c};const b=l-20;if(b<0)throw new q("הארכיון מוצהר כ-ZIP64 אך חסר בו האינדקס המורחב");const x=await le(t,b,b+20);if(x.getUint32(0,!0)!==_t)throw new q("הארכיון מוצהר כ-ZIP64 אך חסר בו האינדקס המורחב");const d=Q(x,8),o=await le(t,d,d+56);if(o.getUint32(0,!0)!==St)throw new q("אינדקס ZIP64 פגום");return s=Q(o,32),i=Q(o,40),c=Q(o,48),{entries:s,size:i,offset:c}}function zt(t,r,n,l){let s=r;const i=r+n;for(;s+4<=i;){const c=t.getUint16(s,!0),g=t.getUint16(s+2,!0);if(c===1){let b=s+4;l.size===ne&&(l.size=Q(t,b),b+=8),l.compressedSize===ne&&(l.compressedSize=Q(t,b),b+=8),l.offset===ne&&(l.offset=Q(t,b),b+=8);return}s+=4+g}}async function Et(t){const{entries:r,size:n,offset:l}=await Tt(t),s=await le(t,l,l+n),i=[];let c=0;for(let g=0;g<r;g+=1){if(c+46>s.byteLength)throw new q("אינדקס הארכיון נקטע");if(s.getUint32(c,!0)!==kt)throw new q("אינדקס הארכיון פגום");const b=s.getUint16(c+28,!0),x=s.getUint16(c+30,!0),d=s.getUint16(c+32,!0),o={method:s.getUint16(c+10,!0),compressedSize:s.getUint32(c+20,!0),size:s.getUint32(c+24,!0),offset:s.getUint32(c+42,!0)},j=c+46;o.name=Mt(new Uint8Array(s.buffer,s.byteOffset+j,b)),zt(s,j+b,x,o),o.directory=o.name.endsWith("/"),i.push(o),c=j+b+x+d}return i}async function De(t,r){const n=await le(t,r.offset,r.offset+30);if(n.byteLength<30||n.getUint32(0,!0)!==Ct)throw new q(`רשומה פגומה בארכיון: ${r.name}`);const l=n.getUint16(26,!0),s=n.getUint16(28,!0),i=r.offset+30+l+s,c=t.slice(i,i+r.compressedSize);if(r.method===Ft)return c;if(r.method!==$t)throw new q(`הארכיון משתמש בדחיסה שאיננו קוראים (${r.method}) — נא לייצא כ-ZIP רגיל`);const g=c.stream().pipeThrough(new DecompressionStream("deflate-raw"));return new Response(g).blob()}async function Ut(t,r){return(await De(t,r)).text()}const Ot=/^https?:$/,Rt=/\.[a-z0-9]{1,5}$/i,Pt=/\.(?:asp|aspx|php|jsp|cgi|do|html?)$/i;function It(t){const r=String(t||"");return Rt.test(r)&&!Pt.test(r)}function Se(t){const r=String(t??"");try{return decodeURIComponent(r)}catch{return r}}function Bt(t){return String(t||"").replace(/\\/g,"/").replace(/\/{2,}/g,"/")}function Zt(t,r){const n=String(t??"").trim();if(!n||n.startsWith("#"))return null;const l=n.replace(/\\/g,"/");let s;try{s=new URL(l,r||void 0)}catch{return null}if(!Ot.test(s.protocol))return null;s.hash="",s.pathname=Bt(s.pathname),It(s.pathname)&&(s.search="");const i=`${s.host}${Se(s.pathname)}${Se(s.search)}`.toLowerCase();return{url:s.href,key:i}}function ke(t){const r=Number(t)||0;return r<=0?"":r<1024?`${r} B`:r<1024*1024?`${Math.round(r/1024)} KB`:`${(r/1048576).toFixed(1)} MB`}function Gt(t){const r=(t||[]).filter(s=>s&&!s.directory),n=r.find(s=>s.name==="export.json");if(n)return n;const l=r.filter(s=>/^[^/]+\/export\.json$/.test(s.name));return l.length===1?l[0]:null}const Jt=t=>{const r=String((t==null?void 0:t.name)||"").lastIndexOf("/");return r===-1?"":String(t.name).slice(0,r+1)};function Kt(t){const r=new Map,n=Array.isArray(t==null?void 0:t.submissions)?t.submissions:[];for(const l of n)for(const s of Array.isArray(l==null?void 0:l.files)?l.files:[]){const i=String((typeof s=="string"?s:s==null?void 0:s.url)||"").trim();!i||/^data:/i.test(i)||r.has(i)||r.set(i,{url:i,path:typeof s=="string"?"":String((s==null?void 0:s.path)||""),name:typeof s=="string"?"":String((s==null?void 0:s.name)||""),mime:typeof s=="string"?"":String((s==null?void 0:s.mime)||""),size:typeof s=="string"?null:Number.isFinite(s==null?void 0:s.size)?s.size:null})}return[...r.values()]}function qt(t,r,n=""){var x;const l=new Map((r||[]).filter(d=>d&&!d.directory).map(d=>[d.name,d])),s=Kt(t),i=[],c=[],g=new Set;for(const d of s){const o=((x=Zt(d.url))==null?void 0:x.key)||"",j=d.path?l.get(n+d.path)||l.get(d.path):null;if(!j||!o){c.push(d);continue}g.add(j.name),i.push({...d,key:o,entry:j})}const b=[...l.keys()].filter(d=>d!==`${n}export.json`&&d!=="export.json"&&!g.has(d));return{ready:i,missing:c,extra:b,declared:s.length}}function Wt(t,r,n=""){const l=qt(t,r,n),s=(Array.isArray(t==null?void 0:t.submissions)?t.submissions:[]).flatMap(i=>Array.isArray(i==null?void 0:i.files)?i.files:[]).filter(i=>/^data:/i.test(String((typeof i=="string"?i:i==null?void 0:i.url)||""))).length;return{...l,embedded:s,bytes:l.ready.reduce((i,c)=>{var g;return i+(((g=c.entry)==null?void 0:g.size)||0)},0)}}const Xt=4;async function Ht({files:t,readBytes:r,upload:n,concurrency:l=Xt,onProgress:s,stopped:i}){const c=Array.isArray(t)?t:[],g={uploaded:0,skipped:0,failed:0,failures:[]};let b=0,x=0;const d=async()=>{for(;;){if(i!=null&&i.current)return;const o=x;if(x+=1,o>=c.length)return;const j=c[o];try{const S=await r(j.entry),v=await n(j,S);v!=null&&v.skipped?g.skipped+=1:g.uploaded+=1}catch(S){g.failed+=1,g.failures.push({name:j.name||j.key,error:String((S==null?void 0:S.message)||S).slice(0,200)})}b+=1,s==null||s(b,c.length)}};return await Promise.all(Array.from({length:Math.max(1,Math.min(l,c.length))},d)),g}function Vt(t){for(const r of t||[])try{return new URL(r.url).host}catch{}return""}function Yt({communityId:t,onClose:r,onImported:n}){var me;const[l,s]=u.useState("upload"),[i,c]=u.useState(""),[g,b]=u.useState(null),[x,d]=u.useState(null),[o,j]=u.useState(null),[S,v]=u.useState(!1),[M,D]=u.useState(!1),[P,B]=u.useState(null),[p,f]=u.useState(""),[T,w]=u.useState(null),[C,$]=u.useState(null),[N,O]=u.useState(null),X=async m=>{const h=await A.functions.invoke("formsImport",{...m,community_id:t});if(!(h!=null&&h.data))throw new Error("הפעולה נכשלה");return h.data},oe=m=>{c(m),d(null),D(!1),w(null),$(null),s("upload")};async function de(m){var U;const h=(U=m.target.files)==null?void 0:U[0];if(h){v(!0);try{const k=new Uint8Array(await h.slice(0,2).arrayBuffer());if(!(k[0]===80&&k[1]===75)){oe(h.name),O(null),b(JSON.parse(await h.text()));return}const z=await Et(h),Z=Gt(z);if(!Z)throw new Error("לא נמצא export.json בתוך הארכיון");const J=Jt(Z),K=JSON.parse(await Ut(h,Z));oe(h.name),b(K),O({file:h,root:J,...Wt(K,z,J)})}catch(k){_.error((k==null?void 0:k.message)||"לא ניתן לקרוא את הקובץ"),b(null),O(null)}finally{v(!1)}}}async function xe(){v(!0);try{const m=await X({payload:g,mode:"audit"});d(m.report),s("checked")}catch(m){_.error((m==null?void 0:m.message)||"שגיאה בבדיקת הקובץ")}finally{v(!1)}}async function ce(){v(!0);try{B(await X({mode:"clean_text",dry_run:!0}))}catch(m){_.error((m==null?void 0:m.message)||"שגיאה בבדיקה")}finally{v(!1)}}async function ae(){v(!0);try{const m=await X({mode:"clean_text"});_.success(`תוקנו ${m.cleaned} תיאורים`),B(null),n==null||n()}catch(m){_.error((m==null?void 0:m.message)||"שגיאה בתיקון")}finally{v(!1)}}async function he(){var J,K,I;const m="https://new-api.eshuv.com".replace(/\/+$/,""),h=N.ready.length;f(`שולח ${h} קבצים מהארכיון…`);const U=Vt(N.ready),k=await A.functions.invoke("knMigration",{mode:"create",purpose:"repair",s
1ource_domain:U,community_id:t});if(!((J=k==null?void 0:k.data)!=null&&J.ok))throw new Error(((K=k==null?void 0:k.data)==null?void 0:K.error)||"לא ניתן לפתוח העברת קבצים");const Y=k.data.token,z=await Ht({files:N.ready,readBytes:F=>De(N.file,F),upload:async(F,R)=>{const H=await fetch(`${m}/kn/upload`,{method:"POST",headers:{"X-KN-Token":Y,"X-KN-Source":F.key,"X-Filename":(F.name||"file").slice(0,120),"Content-Type":F.mime||R.type||"application/octet-stream"},body:R}),a=await H.json().catch(()=>({}));if(!H.ok||a.ok===!1)throw new Error((a==null?void 0:a.error)||`ההעלאה נכשלה (${H.status})`);return a},onProgress:F=>f(`נשלחו ${F}/${h} קבצים…`)});f("מעדכן את ההגשות…");let Z=0;for(let F=0;F<100;F+=1){const R=await A.functions.invoke("knMigration",{mode:"repair",community_id:t,source_domain:U});if(!((I=R==null?void 0:R.data)!=null&&I.ok))throw new Error("עדכון ההגשות נכשל");if(Z+=R.data.rows_updated,!R.data.rows_remaining)break}f(""),w({fromArchive:!0,pending:h+N.missing.length,host:U,rows:Z,copied:z.uploaded+z.skipped,failed:z.failed+N.missing.length,uploadFailures:z.failures,missingInZip:N.missing.length}),n==null||n(),z.failed||N.missing.length?_(`${z.uploaded} קבצים נשמרו · ${z.failed+N.missing.length} לא`,{icon:"⚠️"}):_.success("הייבוא והקבצים הושלמו")}async function ee(){var m,h,U,k,Y,z,Z,J,K;v(!0);try{const I=await X({payload:g,mode:"import",force:M});if(I.blocked){d(I.report),_.error("הייבוא נעצר — יש בעיות בקובץ");return}if(j(I),s("done"),n==null||n(),(m=N==null?void 0:N.ready)!=null&&m.length){await he();return}f("בודק אילו קבצים עדיין במערכת הישנה…");const F=await A.functions.invoke("adoptExternalMedia",{community_id:t,mode:"survey"}),R=((U=(h=F==null?void 0:F.data)==null?void 0:h.totals)==null?void 0:U.files)||0,H=((z=(Y=(k=F==null?void 0:F.data)==null?void 0:k.hosts)==null?void 0:Y[0])==null?void 0:z.host)||"";if(!R){f(""),w({pending:0,copied:0,failed:0,host:H}),_.success("הייבוא הושלם");return}const a=await lt({invoke:(y,L)=>A.functions.invoke(y,L),communityId:t,target:R,batch:((J=(Z=F==null?void 0:F.data)==null?void 0:Z.totals)==null?void 0:J.batch)||25,onProgress:y=>f(y)});if(f(""),w({pending:R,host:H,copied:a.copied,failed:a.failed,byKind:a.byKind,hostDown:a.hostDown}),n==null||n(),a.failed){try{const y=await A.functions.invoke("adoptExternalMedia",{community_id:t,mode:"probe"});(K=y==null?void 0:y.data)!=null&&K.success&&$(y.data)}catch{}_(`הועתקו ${a.copied} קבצים · ${a.failed} לא הצליחו`,{icon:"⚠️"})}else _.success("הייבוא והקבצים הושלמו")}catch(I){f(""),_.error((I==null?void 0:I.message)||"שגיאה בייבוא")}finally{v(!1)}}const re=e.jsx("button",{type:"button",onClick:r,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:"סגור"});let te=re;if(l==="upload"&&g)te=e.jsxs(e.Fragment,{children:[re,e.jsxs("button",{type:"button",onClick:xe,disabled:S,className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full bg-blue-600 hover:bg-blue-700 text-white text-sm font-bold disabled:opacity-50 transition-colors",children:[S?e.jsx(V,{className:"w-4 h-4 animate-spin"}):e.jsx(Re,{className:"w-4 h-4"})," בדוק את הקובץ"]})]});else if(l==="checked"&&x){const m=!x.ok&&!M;te=e.jsxs(e.Fragment,{children:[re,e.jsxs("button",{type:"button",onClick:ee,disabled:S||m,className:"inline-flex items-center gap-1.5 h-10 px-5 rounded-full bg-emerald-600 hover:bg-emerald-700 text-white text-sm font-bold disabled:opacity-40 transition-colors",children:[S?e.jsx(V,{className:"w-4 h-4 animate-spin"}):null," ייבא לקהילה"]})]})}const se=(m,h)=>e.jsxs("div",{className:"flex items-center justify-between text-sm py-1",children:[e.jsx("span",{className:"text-muted-foreground",children:m}),e.jsxs("span",{className:`font-medium ${Number.isFinite(h.declared)&&h.declared!==h.found?"text-red-600":""}`,children:[h.found,Number.isFinite(h.declared)&&h.declared!==h.found?` מתוך ${h.declared}`:""]})]});return e.jsxs(ie,{onClose:r,title:"ייבוא טפסים ממערכת אחרת",icon:je,tone
1:"blue",maxWidth:"max-w-2xl",footer:te,children:[l==="upload"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"קובץ ייצוא אחד של קהילה — הטפסים, הקטגוריות וכל ההגשות. אם הייצוא הוא ארכיון ZIP, הוא מכיל גם את הקבצים עצמם והם יישמרו אצלנו באותה לחיצה. שום דבר לא נכתב עד שתאשר."}),e.jsxs("label",{className:"flex flex-col items-center justify-center gap-2 h-32 rounded-2xl border-2 border-dashed border-slate-200 hover:border-blue-300 hover:bg-blue-50/30 cursor-pointer transition-all",children:[S?e.jsx(V,{className:"w-8 h-8 text-slate-400 animate-spin"}):e.jsx(Me,{className:"w-8 h-8 text-slate-400"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:i||"בחר קובץ ZIP או JSON"}),e.jsx("input",{type:"file",accept:".zip,.json,application/zip,application/json",className:"hidden",onChange:de})]}),N&&e.jsxs("div",{className:"rounded-xl border border-cyan-200 bg-cyan-50 p-3 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-bold text-cyan-900",children:[e.jsx(mt,{className:"w-4 h-4"})," ארכיון עם הקבצים בפנים"]}),e.jsxs("p",{className:"text-xs text-cyan-800",children:[e.jsx("b",{children:N.ready.length})," קבצים מוכנים לשמירה אצלנו",ke(N.bytes)?` (${ke(N.bytes)})`:"",N.embedded?` · ${N.embedded} חתימות כבר מוטבעות בקובץ`:""]}),N.missing.length>0&&e.jsxs("p",{className:"text-xs text-rose-700",children:[e.jsx("b",{children:N.missing.length})," קבצים מוזכרים בהגשות אך אינם בארכיון — הם יישארו מקושרים למערכת הישנה. ",N.missing.slice(0,3).map(m=>m.name||m.url).join(" · ")]}),N.extra.length>0&&e.jsxs("p",{className:"text-[11px] text-cyan-700/80",children:[N.extra.length," קבצים בארכיון שאף הגשה אינה מפנה אליהם — יידלגו."]})]}),g&&e.jsxs("div",{className:"text-xs text-emerald-600 font-medium flex items-center gap-1",children:[e.jsx(ue,{className:"w-4 h-4"}),' הקובץ נקרא. לחץ "בדוק את הקובץ" כדי לראות מה ייכנס.']}),e.jsxs("div",{className:"rounded-xl border border-border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ue,{className:"w-4 h-4 text-slate-500"})," תיקון תיאורים שנשמרו כקוד"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"טפסים שיובאו עם תיאור שמכיל תגיות HTML — התיאור יומר לטקסט, בלי קובץ."}),P?e.jsxs("div",{className:"text-sm",children:[e.jsxs("p",{className:"text-muted-foreground",children:["מתוך ",P.total," טפסים, ",e.jsx("strong",{className:"text-foreground",children:P.dirty})," צריכים תיקון."]}),P.dirty>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:(P.sample||[]).join(" · ")}),e.jsxs("button",{type:"button",onClick:ae,disabled:S,className:"mt-2 h-9 px-4 rounded-full bg-slate-800 text-white text-xs font-bold disabled:opacity-50",children:["תקן ",P.dirty," תיאורים"]})]})]}):e.jsx("button",{type:"button",onClick:ce,disabled:S,className:"h-9 px-4 rounded-full border border-border text-xs font-medium hover:bg-slate-50 disabled:opacity-50",children:"בדוק כמה צריכים תיקון"})]})]}),l==="checked"&&x&&e.jsxs("div",{className:"space-y-4",children:[((me=x.community)==null?void 0:me.name)&&e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"קהילת המקור: "}),e.jsx("span",{className:"font-medium",children:x.community.name})]}),e.jsxs("div",{className:"bg-slate-50 rounded-xl p-4",children:[se("קטגוריות",x.totals.categories),se("טפסים",x.totals.forms),se("הגשות",x.totals.submissions),e.jsxs("div",{className:"flex items-center justify-between text-sm py-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"קבצים במערכת הישנה"}),e.jsx("span",{className:"font-medium",children:x.files.found})]}),x.files.embedded>0&&e.jsxs("div",{className:"flex items-center justify-between text-sm py-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"חתימות מוטבעות בהגשה"}),e.jsx("span",{className:"font-medium text-emerald-600",children:x.files.embedded})]})]}),e.jsx("div",{className:"bg-white rounded-xl border border-border overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto max-h-64",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",children:[e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"טופס"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"שדות"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"הגשות"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"תשובות מזוהות"})]})}),e.jsx("tbody",{children:x.forms.map(m=>{const h=m.answerKeys,U=m.submissions>0&&h.matched===0&&h.byLabel===0;return e.jsxs("tr",{className:"border-b border-border last:border-0",children:[e.jsx("td",{className:"px-3 py-2",children:m.title||m.source_id}),e.jsx("td",{className:"px-3 py-2",children:m.fields}),e.jsx("td",{className:"px-3 py-2",children:m.submissions}),e.jsxs("td",{className:`px-3 py-2 font-medium ${U?"text-red-600":h.orphan.length?"text-amber-600":"text-emerald-600"}`,children:[U?"אף אחת":h.matched+h.byLabel,h.orphan.length?` (${h.orphan.length} ללא שדה)`:""]})]},m.source_id)})})]})})}),x.problems.length>0&&e.jsxs("div",{className:"bg-red-50 rounded-xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-700 font-medium text-sm",children:[e.jsx(Oe,{className:"w-4 h-4"})," בעיות שעוצרות את הייבוא"]}),e.jsx("ul",{className:"text-sm text-red-700 space-y-1 pr-6 list-disc",children:x.problems.map((m,h)=>e.jsx("li",{children:m},h))}),e.jsxs("label",{className:"flex items-start gap-2 text-xs text-red-700 pt-1 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:M,onChange:m=>D(m.target.checked),className:"mt-0.5"}),e.jsx("span",{children:"קראתי את הרשימה ואני מבין את המשמעות — ייבא בכל זאת"})]})]}),x.warnings.length>0&&e.jsxs("div",{className:"bg-amber-50 rounded-xl p-3 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-700 font-medium text-sm",children:[e.jsx(ge,{className:"w-4 h-4"})," שווה לשים לב"]}),e.jsx("ul",{className:"text-sm text-amber-700 space-y-1 pr-6 list-disc",children:x.warnings.map((m,h)=>e.jsx("li",{children:m},h))})]}),x.ok&&x.warnings.length===0&&e.jsxs("div",{className:"bg-emerald-50 rounded-xl p-3 flex items-center gap-2 text-sm text-emerald-700",children:[e.jsx(ue,{className:"w-4 h-4"})," הקובץ תקין. אפשר לייבא."]})]}),l==="done"&&o&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-emerald-50 rounded-xl p-4 space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-emerald-700",children:"הייבוא הושלם"}),e.jsxs("p",{className:"text-xs text-emerald-600",children:[o.forms_created," טפסים חדשים, ",o.forms_updated," עודכנו, ",o.submissions_created," הגשות נכנסו",o.submissions_skipped_existing?`, ${o.submissions_skipped_existing} כבר היו כאן`:""]})]}),(o.submissions_skipped_no_id>0||o.submissions_skipped_no_form>0)&&e.jsxs("div",{className:"bg-amber-50 rounded-xl p-3 text-sm text-amber-700 space-y-1",children:[e.jsx("div",{className:"font-medium",children:"הגשות שלא נכנסו"}),o.submissions_skipped_no_id>0&&e.jsxs("p",{children:[o.submissions_skipped_no_id," ללא מזהה מקור — לא נכנסו, כי ייבוא חוזר לא היה יכול לזהות אותן ושכפל אותן."]}),o.submissions_skipped_no_form>0&&e.jsxs("p",{children:[o.submissions_skipped_no_form," מפנות לטופס שאינו בקובץ."]})]}),o.remaining>0&&e.jsxs("div",{className:"bg-blue-50 rounded-xl p-3 text-sm text-blue-700",children:["נותרו ",o.remaining,' הגשות. לחץ שוב על "ייבא לקהילה" — מה שכבר נכנס לא ייכנס פעמיים.',e.jsx("div",{className:"pt-2",children:e.jsx("button",{type:"button",onClick:ee,disabled:S,className:"h-9 px-4 roun
1ded-full bg-blue-600 text-white text-xs font-bold disabled:opacity-50",children:"המשך"})})]}),p&&e.jsx("div",{className:"bg-cyan-50 rounded-xl p-3 text-sm text-cyan-800",children:p}),T&&e.jsx(Qt,{media:T,probe:C,communityId:t,onDone:n}),o.submissions_failed>0&&e.jsxs("div",{className:"bg-red-50 rounded-xl p-3 text-sm text-red-700 space-y-1",children:[e.jsxs("p",{className:"font-medium",children:[o.submissions_failed," הגשות לא נכתבו"]}),(o.submission_failures||[]).map((m,h)=>e.jsxs("p",{className:"text-xs",children:[(m.names||[]).join(", ")," — ",m.error]},h)),e.jsx("p",{className:"text-xs",children:'אפשר ללחוץ שוב על "ייבא לקהילה" — מה שכבר נכנס לא ייכנס פעמיים.'})]})]})]})}function Qt({media:t,probe:r,communityId:n,onDone:l}){const{pending:s=0,copied:i=0,failed:c=0,byKind:g={},hostDown:b,host:x}=t;return t.fromArchive?e.jsxs("div",{className:`rounded-xl p-3 text-sm space-y-1 ${c?"bg-amber-50 text-amber-900":"bg-emerald-50 text-emerald-800"}`,children:[e.jsx("p",{className:"font-medium",children:c?`${i} מתוך ${s} קבצים נשמרו אצלנו`:`כל ${i} הקבצים נשמרו אצלנו, מתוך הארכיון`}),e.jsxs("p",{className:"text-xs",children:[t.rows," הגשות עודכנו ומצביעות עכשיו אלינו."]}),t.missingInZip>0&&e.jsxs("p",{className:"text-xs",children:[t.missingInZip," קבצים מוזכרים בהגשות ואינם בארכיון — הם עדיין מקושרים ",x?`ל-${x}`:"למערכת הישנה","."]}),(t.uploadFailures||[]).slice(0,5).map((d,o)=>e.jsxs("p",{className:"text-xs",children:["· ",d.name," — ",d.error]},o)),!c&&e.jsx("p",{className:"text-xs",children:"אפשר לסגור את המערכת הישנה — שום הגשה אינה תלויה בה."})]}):s?c?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-rose-50 rounded-xl p-3 text-sm text-rose-800 space-y-1",children:[e.jsx("p",{className:"font-medium",children:i?`הועתקו ${i} מתוך ${s} קבצים`:`אף אחד מ-${s} הקבצים לא הועתק`}),e.jsxs("p",{className:"text-xs",children:["הקובץ עצמו אינו בקובץ הייצוא — יש בו רק הכתובת שלו ",x?`ב-${x}`:"במערכת הישנה",". כדי שיהיה אצלנו צריך להוריד אותו משם, וזה מה שלא הצליח:"]}),e.jsx("div",{className:"text-xs space-y-0.5 pt-1",children:Object.entries(g).sort((d,o)=>o[1]-d[1]).map(([d,o])=>e.jsxs("p",{children:["· ",e.jsx("b",{children:o})," — ",_e[d]||_e.other]},d))}),b&&e.jsx("p",{className:"text-xs pt-1",children:"עצרנו באמצע: המערכת הישנה הפסיקה לענות. מה שהועתק נשמר, וההרצה הבאה תמשיך מכאן."})]}),r&&e.jsx(ot,{probe:r}),e.jsx(dt,{communityId:n,defaultDomain:x,onDone:l})]}):e.jsxs("div",{className:"bg-emerald-50 rounded-xl p-3 text-sm text-emerald-800",children:["כל ",i," הקבצים הועתקו אלינו. ההגשות כבר לא תלויות ",x?`ב-${x}`:"במערכת הישנה","."]}):e.jsx("div",{className:"bg-emerald-50 rounded-xl p-3 text-sm text-emerald-800",children:"כל הקבצים כבר שמורים אצלנו. סגירת המערכת הישנה לא תפגע בשום הגשה."})}const es=[{key:"ai",label:"יצירה עם AI",desc:"תארו במילים מה הטופס צריך לכלול — והעוזר יבנה שדות, שלבים ולוגיקה.",icon:fe,tone:"from-violet-500 to-blue-600"},{key:"json",label:"טעינת טופס מ־JSON",desc:"יש לכם כבר טופס כקובץ? העלו אותו והמערכת תייבא את השדות כמו שהם.",icon:je,tone:"from-amber-500 to-orange-500"}];function ts({onClose:t,onPick:r}){return e.jsx(ie,{onClose:t,title:"טופס / סקר חדש",subtitle:"איך תרצו להתחיל?",icon:ut,tone:"blue",maxWidth:"max-w-xl",hideFooter:!0,children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",dir:"rtl",children:es.map(n=>{const l=n.icon;return e.jsxs("button",{type:"button",onClick:()=>r(n.key),className:"text-right rounded-2xl border-2 border-slate-200 bg-white p-4 hover:border-blue-300 hover:shadow-md transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-300",children:[e.jsx("span",{className:`w-11 h-11 rounded-xl bg-gradient-to-br ${n.tone} text-white grid place-items-center mb-2.5`,children:e.jsx(l,{className:"w-5 h-5","aria-hidden":"true"})}),e.jsx("span",{className:"block text-sm font-bold text-slate-800",children:n.label}),e.jsx("span",{className:"block text-xs text-slate-500 leading-snug mt-1",children:n.desc})]},n.key)})})})}function be(t,r){const n=new Set((Array.isArray(r)?r:[]).map(i=>
1i==null?void 0:i.id).filter(Boolean)),l=[],s=[];for(const i of Array.isArray(t)?t:[])i&&(i.form_id&&n.has(i.form_id)?l:s).push(i);return{live:l,orphan:s}}const ss=500;function as(t,r){const n=t!=null&&t.data&&typeof t.data=="object"?Object.values(t.data):[];return[t.submitter_name,t.phone,t.email,t.location_address,t.notes,r,...n.map(l=>l==null?"":typeof l=="object"?JSON.stringify(l):String(l))].join(" ").toLowerCase()}function Ce({kibbutzId:t,forms:r=[],status:n="",emptyText:l="אין רישומים להצגה"}){const[s,i]=u.useState([]),[c,g]=u.useState(!0),[b,x]=u.useState(""),[d,o]=u.useState("all");u.useEffect(()=>{let p=!1;g(!0);const f={kibbutz_id:t,...n?{status:n}:{}};return A.entities.DigitalFormRegistration.filter(f,"-created_date",ss).then(T=>{p||i(T||[])}).catch(()=>{p||(i([]),_.error("שגיאה בטעינת הרישומים"))}).finally(()=>{p||g(!1)}),()=>{p=!0}},[t,n]);const j=u.useMemo(()=>{const p=new Map((r||[]).map(f=>[f.id,f.title||"טופס"]));return f=>p.get(f)||"טופס שנמחק"},[r]),{live:S,orphan:v}=u.useMemo(()=>be(s,r),[s,r]),M=d==="orphan"?v:S,D=u.useMemo(()=>{const p=b.trim().toLowerCase();return M.filter(f=>d!=="all"&&d!=="orphan"&&f.form_id!==d?!1:p?as(f,j(f.form_id)).includes(p):!0)},[M,b,d,j]),P=u.useMemo(()=>{const p=new Set(S.map(f=>f.form_id));return(r||[]).filter(f=>p.has(f.id))},[S,r]);function B(){if(!D.length){_("אין מה לייצא",{icon:"ℹ️"});return}const p=["טופס","שם","טלפון",'דוא"ל',"סטטוס","תאריך"],f=D.map($=>[j($.form_id),$.submitter_name||"",$.phone||"",$.email||"",ye($.status),$.created_date?new Date($.created_date).toLocaleString("he-IL"):""]),T=[p,...f].map($=>$.map(N=>`"${String(N).replace(/"/g,'""')}"`).join(",")).join(`
2`),w=new Blob(["\uFEFF"+T],{type:"text/csv;charset=utf-8;"}),C=document.createElement("a");C.href=URL.createObjectURL(w),C.download="רישומים.csv",C.click(),URL.revokeObjectURL(C.href)}return e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm overflow-hidden",dir:"rtl",children:[e.jsxs("div",{className:"p-3 border-b border-border space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-[220px]",children:[e.jsx(Fe,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400","aria-hidden":"true"}),e.jsx("input",{type:"text",value:b,onChange:p=>x(p.target.value),placeholder:"חיפוש בשם, בטלפון, בדוא״ל, בשם הטופס — או בתוך התשובות…","aria-label":"חיפוש ברישומים",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("button",{onClick:B,className:"h-10 px-4 rounded-full border border-slate-200 text-sm font-medium hover:bg-slate-50 inline-flex items-center gap-1.5",children:[e.jsx(Pe,{className:"w-4 h-4"})," ייצוא"]})]}),(P.length>1||v.length>0)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("button",{onClick:()=>o("all"),className:`h-8 px-3.5 rounded-full text-xs font-bold border transition-all ${d==="all"?"bg-blue-600 border-blue-600 text-white":"bg-white border-slate-200 text-slate-600 hover:border-blue-300"}`,children:"כל הטפסים"}),P.map(p=>e.jsx("button",{onClick:()=>o(p.id),className:`h-8 px-3.5 rounded-full text-xs font-bold border transition-all ${d===p.id?"bg-blue-600 border-blue-600 text-white":"bg-white border-slate-200 text-slate-600 hover:border-blue-300"}`,children:p.title},p.id)),v.length>0&&e.jsxs("button",{onClick:()=>o("orphan"),className:`h-8 px-3.5 rounded-full text-xs font-bold border transition-all ${d==="orphan"?"bg-amber-600 border-amber-600 text-white":"bg-amber-50 border-amber-200 text-amber-700 hover:border-amber-400"}`,children:["טפסים שנמחקו (",v.length,")"]})]})]}),c?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(V,{className:"w-6 h-6 text-blue-600 animate-spin"})}):D.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-14 text-center px-6",children:[e.jsx(Ie,{className:"w-8 h-8 text-slate-300 mb-3","aria-hidden":"true"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:M.length===0?l:"אין רישומים התואמים לחיפוש"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-[11px] text-slate-400 px-4 py-2",children:[D.length," רישומים",D.length!==M.length?` מתוך ${M.length}`:""]}),e.jsx("div",{className:"overflow-auto max-h-[32rem]",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 sticky top-0",children:[e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"שם"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"טופס"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2 hidden sm:table-cell",children:"טלפון"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2 hidden md:table-cell",children:'דוא"ל'}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2 hidden lg:table-cell",children:"תאריך"}),e.jsx("th",{className:"text-right font-medium text-muted-foreground px-3 py-2",children:"סטטוס"})]})}),e.jsx("tbody",{children:D.map(p=>e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-slate-50/50",children:[e.jsx("td",{className:"px-3 py-2 font-medium",children:p.submitter_name||"ללא שם"}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-600",children:j(p.form_id)}),e.jsx("td",{className:"px-3 py-2 hidden sm:table-cell text-xs text-muted-foreground",dir:"ltr",children:p.phone||"—"}),e.jsx("td",{className:"px-3 py-2 hidden md:table-cell text-xs text-muted-foreground",children:p.email||"—"}),e.jsx("td",{className:"px-3 py-2 hidden lg:table-cell text-xs text-muted-foreground",children:p.created_date?new Date(p.created_date).toLocaleDateString("he-IL"):"—"}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-xs font-medium ${rt(p.status)}`,children:ye(p.status)})})]}
2,p.id))})]})})]})]})}const rs=["blue","emerald","amber","purple","cyan","rose","slate"],ns=[{key:"active",label:"פעילים",desc:"פתוחים לציבור",icon:Je,color:"text-emerald-600",bg:"bg-emerald-50"},{key:"draft",label:"טיוטות",desc:"לא פורסמו",icon:bt,color:"text-slate-600",bg:"bg-slate-50"},{key:"templates",label:"תבניות",desc:"מוכנות לשימוש",icon:$e,color:"text-purple-600",bg:"bg-purple-50"},{key:"categories",label:"קטגוריות",desc:"הוספה והסרה",icon:gt,color:"text-blue-600",bg:"bg-blue-50"},{key:"alerts",label:"התראות",desc:"ממתינים לטיפול",icon:Ke,color:"text-amber-600",bg:"bg-amber-50"},{key:"registrations",label:"נרשמים",desc:"בכל הטפסים",icon:qe,color:"text-cyan-600",bg:"bg-cyan-50"}];function is(){const{id:t}=Be(),r=Ze(),{user:n}=Ge(),l=!!(n!=null&&n.is_super_admin||(n==null?void 0:n.role)==="platform_admin"),[s,i]=u.useState([]),[c,g]=u.useState([]),[b,x]=u.useState(0),[d,o]=u.useState(0),[j,S]=u.useState(!0),[v,M]=u.useState(""),[D,P]=u.useState("all"),[B,p]=u.useState("all"),[f,T]=u.useState("all"),[w,C]=u.useState(!1),[$,N]=u.useState(!1),[O,X]=u.useState(!1),[oe,de]=u.useState(!1),[xe,ce]=u.useState(!1),[ae,he]=u.useState(new Map),[ee,re]=u.useState(0),[te,se]=u.useState(!1),[me,m]=u.useState(!1),[h,U]=u.useState(!1);u.useEffect(()=>{k()},[t]);async function k(){S(!0);try{const[a,y,L,W]=await Promise.all([A.entities.DigitalForm.filter({kibbutz_id:t},"-updated_date",500),A.entities.DigitalFormCategory.filter({kibbutz_id:t},"sort_order",100),A.entities.DigitalFormRegistration.filter({kibbutz_id:t,status:"pending"},"-created_date",1e3),A.entities.DigitalFormRegistration.filter({kibbutz_id:t},"-created_date",1e3)]);i(a),g(y);const{live:E,orphan:G}=be(W,a);x(be(L,a).live.length),o(E.length),re(G.length),he(ft(E))}catch{_.error("שגיאה בטעינת נתונים")}finally{S(!1)}}const Y=u.useMemo(()=>({active:s.filter(a=>a.status==="active").length,draft:s.filter(a=>a.status==="draft").length,templates:we.length,categories:c.filter(a=>a.is_active!==!1).length,alerts:b,registrations:d}),[s,c,b,d]),z=u.useMemo(()=>s.filter(a=>{var y,L,W;if(f==="active"&&a.status!=="active"||f==="draft"&&a.status!=="draft"||D!=="all"&&a.status!==D||B!=="all"&&a.category_id!==B)return!1;if(v.trim()){const E=v.toLowerCase();if(!((y=a.title)!=null&&y.toLowerCase().includes(E))&&!((L=a.description)!=null&&L.toLowerCase().includes(E))&&!((W=a.slug)!=null&&W.toLowerCase().includes(E)))return!1}return!0}),[s,f,D,B,v]),Z=a=>{var y;return((y=c.find(L=>L.id===a))==null?void 0:y.title)||""};async function J(a){var W;const y=ae.get(a.id)||0,L=y?`למחוק את "${a.title}"?
3
4יימחקו גם ${y} ההגשות שהתקבלו בו, על כל הקבצים שצורפו להן. הפעולה אינה הפיכה.`:`למחוק את "${a.title}"?`;if(confirm(L))try{const E=await A.functions.invoke("formsCleanup",{mode:"delete_form",form_id:a.id});if(!((W=E==null?void 0:E.data)!=null&&W.success))throw new Error("מחיקה נכשלה");i(Te=>Te.filter(ze=>ze.id!==a.id));const G=E.data.submissions_removed||0;_.success(G?`הטופס נמחק, ועמו ${G} הגשות`:"הטופס נמחק"),k()}catch{_.error("שגיאה במחיקה")}}async function K(){var a;if(confirm(`למחוק סופית ${ee} הגשות של טפסים שכבר נמחקו?
5
6הן כוללות שמות, טלפונים וקבצים שצורפו. הפעולה אינה הפיכה.`)){se(!0);try{const y=await A.functions.invoke("formsCleanup",{mode:"purge_orphans"});if(!((a=y==null?void 0:y.data)!=null&&a.success))throw new Error("מחיקה נכשלה");_.success(`${y.data.removed||0} הגשות נמחקו`),k()}catch{_.error("שגיאה במחיקה")}finally{se(!1)}}}function I(a){return Qe(t,`/kibbutz-site/${t}/forms/${a.id}`,window.location.origin)}function F(a){navigator.clipboard.writeText(I(a)),_.success("הקישור הועתק")}function R(a){window.open(I(a),"_blank","noopener")}async function H(a){U(!0);try{const y=Ae(a.fields.map(G=>({...Le(G.type),label:G.label,required:G.required,options:G.options||[]}))),L=c==null?void 0:c.find(G=>G.title===a.category),W=pe(a.name),E=await A.entities.DigitalForm.create({kibbutz_id:t,title:a.name,description:a.description,slug:W,category_id:(L==null?void 0:L.id)||null,status:"draft",fields:y,steps_enabled:!1,steps:[],show_on_website:!0,show_on_app:!0,show_on_homepage:!1,is_private:!1,require_login:!1,require_approval:!1,thank_you_message:"תודה על השליחה! ניצור איתך קשר בהקדם.",color:"blue",sort_order:0,is_active:!0});_.success("הטופס נוצר מתבנית"),E!=null&&E.id&&r(`/kibbutz/${t}/forms/${E.id}/edit`)}catch(y){_.error("שגיאה: "+y.message)}finally{U(!1)}}return j?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"})}):e.jsxs("div",{dir:"rtl",children:[e.jsx("div",{className:"flex mb-6",children:e.jsx(xt,{title:"טפסים דיגיטליים",items:pt(t,r,{onNew:()=>X(!0),onCategories:()=>T("categories"),onSettings:()=>C(!0),onResponsible:()=>m(!0),onMigrate:()=>de(!0),onAdoptMedia:()=>
6ce(!0),canMigrate:l})})}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3 mb-6",children:ns.map(a=>{const y=a.icon,L=f===a.key;return e.jsxs("button",{onClick:()=>T(L?"all":a.key),"aria-pressed":L,className:`text-right bg-white rounded-2xl border p-3 transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-300 ${L?"border-blue-300 shadow-md ring-2 ring-blue-100":"border-border shadow-sm hover:shadow-md"}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-lg ${a.bg} flex items-center justify-center mb-1.5`,children:e.jsx(y,{className:`w-4 h-4 ${a.color}`})}),e.jsx("p",{className:"text-xl font-bold text-foreground",children:Y[a.key]||0}),e.jsx("p",{className:"text-xs font-medium text-foreground",children:a.label}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:a.desc})]},a.key)})}),ee>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 mb-6",children:[e.jsx(ge,{className:"w-4 h-4 text-amber-600 shrink-0","aria-hidden":"true"}),e.jsxs("p",{className:"text-sm text-amber-900 flex-1 min-w-[220px]",children:[e.jsxs("span",{className:"font-bold",children:[ee," הגשות"]}),' שייכות לטפסים שכבר נמחקו. הן אינן נספרות בכרטיסיות, אך עדיין שמורות אצלנו על הקבצים שצורפו להן — ניתן לראותן תחת "נרשמים" ולמחוק אותן סופית.']}),e.jsxs("button",{onClick:K,disabled:te,className:"h-9 px-4 rounded-full bg-white border border-amber-300 text-amber-800 text-sm font-bold hover:bg-amber-100 disabled:opacity-50 inline-flex items-center gap-1.5",children:[te&&e.jsx(V,{className:"w-4 h-4 animate-spin","aria-hidden":"true"}),"מחיקה סופית"]})]}),me?e.jsx(ht,{inline:!0,kibbutzId:t,moduleKey:"forms",title:"הגדר תושב אחראי לטופס",subtitle:"לכל טופס ניתן להגדיר תושב אחראי אחד או יותר — הם יקבלו את ההגשות וינהלו אותן מהאזור האישי",scopes:(s||[]).map(a=>({id:a.id,label:a.title||a.name||"טופס"})),onOpenChange:a=>{a||m(!1)}}):e.jsx(e.Fragment,{children:f==="categories"?e.jsx(tt,{inline:!0,title:"ניהול קטגוריות טפסים",entityName:"DigitalFormCategory",kibbutzId:t,categories:c,colorOptions:rs,accentColor:"blue",onUpdate:k,onClose:()=>T("all")}):f==="alerts"?e.jsx(Ce,{kibbutzId:t,forms:s,status:"pending",emptyText:"אין רישומים שממתינים לטיפול"}):f==="registrations"?e.jsx(Ce,{kibbutzId:t,forms:s,emptyText:"אף אחד עוד לא מילא טופס"}):e.jsxs(e.Fragment,{children:[f==="templates"&&e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4 mb-6",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-purple-50 flex items-center justify-center",children:e.jsx($e,{className:"w-4 h-4 text-purple-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-foreground",children:"תבניות מוכנות לשימוש"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"בחרו תבנית כדי ליצור טופס חדש במהירות"})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3",children:we.map((a,y)=>e.jsxs("div",{className:"bg-slate-50 rounded-xl p-4 flex flex-col",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-50 flex items-center justify-center mb-2",children:e.jsx(We,{className:"w-5 h-5 text-blue-600"})}),e.jsx("p",{className:"text-sm font-bold mb-1",children:a.name}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2 flex-1",children:a.description}),e.jsxs("div",{className:"flex items-center gap-2 mb-3 text-xs text-muted-foreground",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-blue-50 text-blue-600",children:a.category}),e.jsxs("span",{children:[a.fields.length," שדות"]})]}),e.jsx("button",{onClick:()=>H(a),disabled:h,className:"w-full h-9 rounded-xl bg-blue-600 text-white text-sm font-medium hover:bg-blue-700 disabled:opacity-50",children:"השתמש"})]},y))})]}),e.jsxs("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(Fe,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}
6),e.jsx("input",{type:"text",value:v,onChange:a=>M(a.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:D,onChange:a=>P(a.target.value),className:"h-10 rounded-full border border-slate-200 bg-slate-50 px-4 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-blue-100 appearance-none cursor-pointer",children:[e.jsx("option",{value:"all",children:"כל הסטטוסים"}),e.jsx("option",{value:"active",children:"פעיל"}),e.jsx("option",{value:"draft",children:"טיוטה"}),e.jsx("option",{value:"inactive",children:"לא פעיל"})]})]}),c.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-3 pt-3 border-t border-slate-100",children:[e.jsx("button",{onClick:()=>p("all"),className:`h-8 px-3.5 rounded-full text-xs font-semibold border transition-all ${B==="all"?"bg-blue-600 border-blue-600 text-white":"bg-white border-slate-200 text-slate-600 hover:border-blue-300"}`,children:"כל הקטגוריות"}),c.map(a=>e.jsx("button",{onClick:()=>p(a.id),className:`h-8 px-3.5 rounded-full text-xs font-semibold border transition-all ${B===a.id?"bg-blue-600 border-blue-600 text-white":"bg-white border-slate-200 text-slate-600 hover:border-blue-300"}`,children:a.title},a.id))]})]}),z.length===0?e.jsx("div",{className:"bg-white rounded-2xl border border-border shadow-sm",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center px-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-purple-100 to-blue-100 flex items-center justify-center mb-5",children:e.jsx(fe,{className:"w-8 h-8 text-purple-500"})}),e.jsx("h3",{className:"text-lg sm:text-xl font-extrabold text-slate-800 mb-1.5",children:"צור את הטופס הראשון שלך עם עוזר AI"}),e.jsx("p",{className:"text-sm text-slate-400 mb-5 max-w-sm",children:"תארו במילים מה הטופס צריך לכלול, והעוזר יבנה עבורכם טופס מלא — שדות, שלבים ולוגיקה."}),e.jsxs("button",{onClick:()=>r(`/kibbutz/${t}/forms/ai`),className:"h-11 px-6 rounded-full text-white text-sm font-bold inline-flex items-center gap-2 shadow-md hover:brightness-110 transition-all",style:{backgroundImage:"linear-gradient(90deg,#7c3aed,#2563eb)"},children:[e.jsx(fe,{className:"w-4 h-4"})," צור טופס עם AI"]}),e.jsx("button",{onClick:()=>N(!0),className:"mt-3 text-xs font-semibold text-slate-400 hover:text-slate-600",children:"או טענו טופס מקובץ JSON"})]})}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:z.map(a=>e.jsxs("div",{className:"bg-white rounded-2xl border border-border shadow-sm p-4 flex flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${ve[a.status]||ve.draft}`,children:nt[a.status]||a.status}),a.category_id&&e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-600",children:Z(a.category_id)})]}),e.jsx("p",{className:"text-sm font-bold mb-1 line-clamp-2",children:a.title}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground mb-3 line-clamp-2",children:a.description}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground mb-3",children:[e.jsxs("span",{children:[(a.fields||[]).length," שדות"]}),e.jsxs("span",{className:ae.get(a.id)?"font-semibold text-slate-600":"",children:[ae.get(a.id)||0," הגשות"]}),a.show_on_website&&e.jsx(Xe,{className:"w-3.5 h-3.5 text-emerald-500"}),a.show_on_app&&e.jsx(He,{className:"w-3.5 h-3.5 text-cyan-500"})]}),e.jsxs("div",{className:"flex items-center gap-1 mt-auto pt-2 border-t border-border",children:[e.jsx("button",{onClick:()=>r(`/kibbutz/${t}/forms/${a.id}/edit`),className:"flex-1 h-8 rounded-lg bg-blue-50 text-blue-600 text-xs font-medium hover:bg-blue-100",children:"נהל טופס"}),e.jsx("button",{onClick:()=>R(a),className:"p-1.5 rounded-lg hover:bg-emerald-50 text-emerald-600",title:"צפייה בטופס",children:e.jsx(Ve,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>F(a),className:"p-1.5 rounded-lg hover:bg-slate-100 text-slate-600",title:"העתק קישור",children:e.jsx(jt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>J(a),className:"p-1.5 rounded-lg hover:bg-red-50 text-red-600",title:"מחק",children:e.jsx(Ye,{className:"w-4 h-4"})})]})]},a.id))})]})}),O&&e.jsx(ts,{onClose:()=>X(!1),onPick:a=>{X(!1),a==="ai"?r(`/kibbutz/${t}/forms/ai`):N(!0)}}),w&&e.jsx(Nt,{kibbutzId:t,onClose:()=>C(!1)}),xe&&e.jsx(ct,{communityId:t,onClose:()=>ce(!1),onDone:k}),oe&&e.jsx(Yt,{communityId:t,onClose:()=>de(!1),onImported:()=>k()}),$&&e.jsx(wt,{kibbutzId:t,categories:c,onClose:()=>N(!1),onImported:a=>{k(),N(!1),a!=null&&a.id&&r(`/kibbutz/${t}/forms/${a.id}/edit`)}})]})}function na(){return e.jsx(et,{moduleKey:"forms",children:e.jsx(is,{})})}
6export{na 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.