1import{a as P,j as e,I as X,S as _,b as L,d as C,e as S,f as d,C as E,g as T,B as D,h as Z,M as $,P as H,R as Q,T as W,i as q,r as u,k as te,F as U,l as ae,E as re,m as le,n as z,L as ne,o as y,u as ee,p as I,A as de,q as A,s as R,t as M,v as O,w as V,x as ie,y as ce,z as xe,D as oe,G as J,H as me,J as ue,K as he,N as je,O as pe,Q as ge,U as fe,V as be,W as Ne}from"./index-DP1X1DJb.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ve=[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]],Y=P("Crown",ve);/** 7 * @license lucide-react v0.475.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ye=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],we=P("Save",ye);/** 12 * @license lucide-react v0.475.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const _e=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],se=P("Search",_e);function Le({filters:s,onFilterChange:n}){return e.jsxs("div",{className:"flex flex-wrap gap-3 mb-6",children:[e.jsxs("div",{className:"relative flex-1 min-w-[200px]",children:[e.jsx(se,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(X,{placeholder:"××פ×ש ××¤× ×©× ×× ××××××...",value:s.search,onChange:r=>n({...s,search:r.target.value}),className:"pr-10 rounded-xl"})]}),e.jsxs(_,{value:s.status,onValueChange:r=>n({...s,status:r}),children:[e.jsx(L,{className:"w-36 rounded-xl",children:e.jsx(C,{placeholder:"ס×××ס"})}),e.jsxs(S,{children:[e.jsx(d,{value:"all",children:"×× ×ס×××ס××"}),e.jsx(d,{value:"new",children:"××ש"}),e.jsx(d,{value:"contacted",children:"× ×צר קשר"}),e.jsx(d,{value:"in_progress",children:"×××פ××"}),e.jsx(d,{value:"converted",children:"××¤× ×××§××"}),e.jsx(d,{value:"closed",children:"ס××ר"})]})]}),e.jsxs(_,{value:s.urgency,onValueChange:r=>n({...s,urgency:r}),children:[e.jsx(L,{className:"w-36 rounded-xl",children:e.jsx(C,{placeholder:"×××פ×ת"})}),e.jsxs(S,{children:[e.jsx(d,{value:"all",children:"×× ××××פ×××ת"}),e.jsx(d,{value:"high",children:"×××××"}),e.jsx(d,{value:"medium",children:"××× ×× ×ת"}),e.jsx(d,{value:"low",children:"× ××××"})]})]}),e.jsxs(_,{value:s.budget,onValueChange:r=>n({...s,budget:r}),children:[e.jsx(L,{className:"w-40 rounded-xl",children:e.jsx(C,{placeholder:"תקצ××"})}),e.jsxs(S,{children:[e.jsx(d,{value:"all",children:"×× ×תקצ××××"}),e.jsx(d,{value:"under_50k",children:"×¢× 50K"}),e.jsx(d,{value:"50k_100k",children:"50K-100K"}),e.jsx(d,{value:"100k_200k",children:"100K-200K"}),e.jsx(d,{value:"200k_350k",children:"200K-350K"}),e.jsx(d,{value:"over_350k",children:"350K+"})]})]})]})}const Ce={low:"bg-emerald-100 text-emerald-700",medium:"bg-amber-100 text-amber-700",high:"bg-red-100 text-red-700"},Se={new:"bg-blue-100 text-blue-700",contacted:"bg-purple-100 text-purple-700",in_progress:"bg-amber-100 text-amber-700",converted:"bg-emerald-100 text-emerald-700",closed:"bg-gray-100 text-gray-600"};function ke({lead:s,onClick:n}){return e.jsx(E,{className:"rounded-2xl cursor-pointer hover:shadow-md transition-all border-border/50",onClick:()=>n(s),children:e.jsxs(T,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:s.full_name}),s.is_premium&&e.jsx(Y,{className:"w-4 h-4 text-amber-500"})]}),e.jsx(D,{className:`text-xs ${Se[s.status]||""}`,children:Z[s.status]||s.status})]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground mb-3",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($,{className:"w-3 h-3"})," ",s.email]}),e.jsxs("span",{className:"flex items-center gap-1",dir:"ltr",children:[e.jsx(H,{className:"w-3 h-3"})," ",s.phone]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.urgency&&e.jsxs(D,{variant:"outline",className:`text-xs ${Ce[s.urgency]||""}`,children:[s.urgency==="high"&&e.jsx(W,{className:"w-3 h-3 ml-1"}),"×××פ×ת: ",Q[s.urgency]]}),s.recommended_service&&e.jsx(D,{variant:"outline",className:"text-xs",children:q[s.recommended_service]}),s.risk_level&&e.jsxs(D,{variant:"outline",className:"text-xs",children:["ס××××: ",Q[s.risk_level]]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:new Date(s.created_date).toLocaleDateString("he-IL")})]})})}const G=u.forwardRef(({className:s,...n},r)=>
16e.jsx("textarea",{className:te("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",s),ref:r,...n}));G.displayName="Textarea";const Ee={image:ae,floor_plan:U,document:U,other:U};function Te({file:s,onUpdated:n}){const[r,h]=u.useState(s.status||"pending"),[g,N]=u.useState(s.admin_feedback||""),[j,l]=u.useState(!1),a=Ee[s.file_type]||U,i=async()=>{l(!0);try{await y.entities.UploadedFile.update(s.id,{status:r,admin_feedback:g}),n==null||n()}catch(m){console.error(m)}l(!1)},c=r!==(s.status||"pending")||g!==(s.admin_feedback||"");return e.jsxs("div",{className:"rounded-2xl border border-border/50 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-accent/60 flex items-center justify-center flex-shrink-0",children:e.jsx(a,{className:"w-4 h-4 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:s.file_name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(s.created_date).toLocaleDateString("he-IL")})]})]}),e.jsx("a",{href:s.file_url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-center w-8 h-8 rounded-lg border border-border/50 hover:bg-muted/50 transition-colors flex-shrink-0",children:e.jsx(re,{className:"w-3.5 h-3.5 text-muted-foreground"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[140px_1fr] gap-3 items-start",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground block mb-1",children:"ס×××ס"}),e.jsxs(_,{value:r,onValueChange:h,children:[e.jsx(L,{className:"rounded-xl",children:e.jsx(C,{})}),e.jsx(S,{children:Object.entries(le).map(([m,x])=>e.jsx(d,{value:m,children:x.label},m))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground block mb-1",children:"×ש×× ×××§××"}),e.jsx(G,{value:g,onChange:m=>N(m.target.value),placeholder:"×ת×× ××× ×ער×ת ×¢× ×ת××× ×ת...",className:"rounded-xl resize-none",rows:2})]})]}),c&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(z,{size:"sm",onClick:i,disabled:j,className:"rounded-xl gap-1.5",children:[j?e.jsx(ne,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(we,{className:"w-3.5 h-3.5"}),"ש××ר"]})})]})}function De({lead:s,onBack:n}){var k,w,K;const r=ee(),[h,g]=u.useState(""),[N,j]=u.useState("general"),{data:l=[]}=I({queryKey:["lead-questionnaire",s.questionnaire_id],queryFn:()=>y.entities.Questionnaire.filter({id:s.questionnaire_id}),enabled:!!s.questionnaire_id}),a=l[0],i=a==null?void 0:a.diagnosis_result,{data:c=[]}=I({queryKey:["lead-files",s.id],queryFn:()=>y.entities.UploadedFile.filter({lead_id:s.id})}),{data:m=[]}=I({queryKey:["lead-notes",s.id],queryFn:()=>y.entities.AdminNote.filter({lead_id:s.id},"-created_date")}),x=async t=>{await y.entities.Lead.update(s.id,t),r.invalidateQueries({queryKey:["leads"]})},F=async()=>{h.trim()&&(await y.entities.AdminNote.create({lead_id:s.id,content:h,note_type:N}),g(""),r.invalidateQueries({queryKey:["lead-notes"]}))};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(z,{variant:"ghost",onClick:n,className:"gap-2 mb-2",children:[e.jsx(de,{className:"w-4 h-4"})," ×××¨× ×רש×××"]}),e.jsxs("div",{className:"flex items-start justify-between flex-wrap gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h2",{className:"font-frank text-2xl font-bold",children:s.full_name}),s.is_premium&&e.jsx(Y,{className:"w-5 h-5 text-amber-500"})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($,{className:"w-3.5 h-3.5"}),s.email]}),e.jsxs("span",{className:"flex items-center gap-1",dir:"ltr",children:[e.jsx(H,{className:"w-3.5 h-3.5"}),s.phone]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(_,{value:s.status,onValueChange:t=>x({status:t}),children:[e.jsx(L,{className:"w-36 rounded-xl",children:e.jsx(C,{})}),e.jsx(S,{children:Object.entries(Z).map(([t,o])=>e.jsx(d,{value:t,children:o},t))})]}),e.jsxs(_,{value:s.recommended_service||"",onValueChange:t=>x({recommended_service:t}),children:[e.jsx(L,{className:"w-36 rounded-xl",children:e.jsx(C,{placeholder:"ש×ר×ת"})}),e.jsx(S,{children:Object.entries(q).map(([t,o])=>e.jsx(d,{value:t,children:o},t))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a&&e.jsxs(E,{className:"rounded-2xl",children:[e.jsx(A,{children:e.jsx(R,{className:"text-base",children:"פר×× ×ש××××"})}),e.jsxs(T,{className:"space-y-3",children:[e.jsx(b,{label:"×××× ××ר×",value:a.apartment_size?`${a.ap
16artment_size} ×״ר`:"â"}),e.jsx(b,{label:"××ר××",value:a.num_rooms||"â"}),e.jsx(b,{label:"ש××",value:M[a.project_phase]||"â"}),e.jsx(b,{label:"תקצ××",value:O[a.budget_range]||"â"}),e.jsx(b,{label:"ס×× ××",value:V[a.style_preference]||"â"}),e.jsx(b,{label:"ר×ת ש×ר×ת",value:q[a.need_level]||"â"}),((k=a.priorities)==null?void 0:k.length)>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"תע××פ××"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:a.priorities.map(t=>e.jsx(D,{variant:"secondary",className:"text-xs",children:ie[t]||t},t))})]}),e.jsx(b,{label:"ת××× ××ת",value:a.has_plans?"××":"××"}),e.jsx(b,{label:"× ×ר×ת",value:a.wants_carpentry?"××":"××"}),e.jsx(b,{label:"ש×× ××× ×§×××",value:a.wants_contractor_changes?"××":"××"}),e.jsx(b,{label:"×××××ת",value:a.needs_visualizations?"××":"××"})]})]}),i&&e.jsxs(E,{className:"rounded-2xl",children:[e.jsx(A,{children:e.jsx(R,{className:"text-base",children:"ת×צ××ת ×××××"})}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"ר×ת ס××××:"}),e.jsx(D,{variant:"outline",children:Q[i.riskLevel]})]}),((w=i.redFlags)==null?void 0:w.length)>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1 mb-2",children:[e.jsx(W,{className:"w-3 h-3"})," ××××× ××××××"]}),e.jsx("ul",{className:"space-y-1",children:i.redFlags.map((t,o)=>e.jsx("li",{className:"text-xs text-red-700 bg-red-50 rounded-lg p-2",children:t},o))})]}),((K=i.opportunities)==null?void 0:K.length)>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1 mb-2",children:[e.jsx(ce,{className:"w-3 h-3"})," ××××× ×××ת"]}),e.jsx("ul",{className:"space-y-1",children:i.opportunities.map((t,o)=>e.jsx("li",{className:"text-xs text-amber-700 bg-amber-50 rounded-lg p-2",children:t},o))})]})]})]})]}),e.jsxs(E,{className:"rounded-2xl",children:[e.jsxs(A,{className:"flex flex-row items-center justify-between",children:[e.jsx(R,{className:"text-base",children:"ת××× ××ת ××ש××"}),e.jsx(xe,{leadId:s.id,onUpload:()=>r.invalidateQueries({queryKey:["lead-files"]})})]}),e.jsx(T,{children:c.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"××× ×§×צ××"}):e.jsx("div",{className:"space-y-3",children:c.map(t=>e.jsx(Te,{file:t,onUpdated:()=>r.invalidateQueries({queryKey:["lead-files"]})},t.id))})})]}),e.jsxs(E,{className:"rounded-2xl",children:[e.jsx(A,{children:e.jsx(R,{className:"text-base",children:"×ער×ת"})}),e.jsxs(T,{children:[e.jsxs("div",{className:"flex gap-2 mb-4",children:[e.jsx(G,{placeholder:"××ס××¤× ×ער×...",value:h,onChange:t=>g(t.target.value),className:"rounded-xl resize-none",rows:2}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(_,{value:N,onValueChange:j,children:[e.jsx(L,{className:"w-28 rounded-xl text-xs",children:e.jsx(C,{})}),e.jsxs(S,{children:[e.jsx(d,{value:"general",children:"××××"}),e.jsx(d,{value:"follow_up",children:"××¢×§×"}),e.jsx(d,{value:"important",children:"×ש××"})]})]}),e.jsxs(z,{size:"sm",onClick:F,className:"rounded-xl",children:[e.jsx(oe,{className:"w-4 h-4 ml-1"})," ××סף"]})]})]}),e.jsx("div",{className:"space-y-2",children:m.map(t=>e.jsxs("div",{className:`p-3 rounded-xl border ${t.note_type==="important"?"border-red-200 bg-red-50/30":t.note_type==="follow_up"?"border-amber-200 bg-amber-50/30":"border-border/50 bg-muted/30"}`,children:[e.jsx("p",{className:"text-sm",children:t.content}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:new Date(t.created_date).toLocaleDateString("he-IL")})]},t.id))})]})]})]})}function b({label:s,value:n}){return e.jsxs("div",{className:"flex justify-between items-center py-1 border-b border-border/30 last:border-0",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s}),e.jsx("span",{className:"text-sm font-medium",children:n})]})}function Ie({leads:s,questionnaires:n,onSelectLead:r}){const[h,g]=u.useState(""),N=u.useMemo(()=>{const l={};
16return n.forEach(a=>{l[a.lead_id]=a}),s.map(a=>{const i=n.find(c=>c.id===a.questionnaire_id)||l[a.id];return i?{lead:a,q:i}:null}).filter(Boolean)},[s,n]),j=N.filter(({lead:l,q:a})=>{var c,m,x;if(!h)return!0;const i=h.toLowerCase();return((c=l.full_name)==null?void 0:c.toLowerCase().includes(i))||((m=l.email)==null?void 0:m.toLowerCase().includes(i))||((x=l.phone)==null?void 0:x.includes(i))||(V[a.style_preference]||"").toLowerCase().includes(i)});return N.length===0?e.jsx("div",{className:"text-center py-16 text-muted-foreground",children:e.jsx("p",{children:"××× ××§×××ת ש×ש×××× ×©×××× ×¢××××"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative max-w-sm",children:[e.jsx(se,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(X,{value:h,onChange:l=>g(l.target.value),placeholder:"××פ×ש ××¤× ×©×, ××פ××, ×××××× ×× ×¡×× ××...",className:"rounded-xl pr-10"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[j.length," ××§×××ת ×ש×××× ×©××××"]}),e.jsx("div",{className:"hidden lg:block overflow-x-auto rounded-2xl border border-border/50",children:e.jsxs("table",{className:"w-full text-right",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-muted/50 border-b border-border/50",children:[e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"ש×"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"××פ××"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"××××××"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"ס×× ×× ×¢×צ××"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"תקצ××"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"ש××"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground",children:"ת×ר×× ×©××××"}),e.jsx("th",{className:"py-3 px-4 text-xs font-semibold text-muted-foreground"})]})}),e.jsx("tbody",{children:j.map(({lead:l,q:a})=>e.jsxs("tr",{onClick:()=>r(l),className:"border-b border-border/30 hover:bg-muted/30 cursor-pointer transition-colors",children:[e.jsx("td",{className:"py-3 px-4 text-sm font-medium",children:l.full_name}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground",dir:"ltr",children:l.phone}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground",children:l.email}),e.jsx("td",{className:"py-3 px-4 text-sm",children:a.style_preference?e.jsx("span",{className:"inline-block bg-primary/10 text-primary px-2 py-0.5 rounded-full text-xs font-medium",children:V[a.style_preference]||a.style_preference}):"â"}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground",children:O[a.budget_range]||"â"}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground",children:M[a.project_phase]||"â"}),e.jsx("td",{className:"py-3 px-4 text-sm text-muted-foreground",children:new Date(a.created_date).toLocaleDateString("he-IL")}),e.jsx("td",{className:"py-3 px-4",children:e.jsx(J,{className:"w-4 h-4 text-muted-foreground"})})]},l.id))})]})}),e.jsx("div",{className:"lg:hidden space-y-3",children:j.map(({lead:l,q:a})=>e.jsxs("button",{onClick:()=>r(l),className:"w-full text-right rounded-2xl border border-border/50 bg-card p-4 hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"font-medium text-sm",children:l.full_name}),e.jsx(J,{className:"w-4 h-4 text-muted-foreground"})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground mb-3",children:[e.jsxs("span",{className:"flex items-center gap-1",dir:"ltr",children:[e.jsx(H,{className:"w-3 h-3"}),l.phone]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($,{className:"w-3 h-3"}),l.email]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(me,{className:"w-3 h-3"}),new Date(a.created_date).toLocaleDateString("he-IL")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.style_preference&&e.jsxs("span",{className:"inline-flex items-center gap-1 bg-primary/10 text-primary px-2 py-0.5 rounded-full text-xs font-medium",children:[e.jsx(ue,{className:"w-3 h-3"}),V[a.style_preference]||a.style_preference]}),a.budget_range&&e.jsx("span",{className:"bg-muted text-muted-foreground px-2 py-0.5 rounded-full text-xs",children:O[a.budget_range]}),a.project_phase&&e.jsx("span",{className:"bg-muted text-muted-foreground px-2 py-0.5 rounded-full text-xs",children:M[a.project_phase]}),a.need_level&&e.jsx("span",{className:"bg-muted text-muted-foreground px-2 py-0.5 rounded-full text-xs",children:q[a.need_level]})]})]},l.id))})]})}function Ke(){const s=he(),n=ee(),[r,h]=u.useState(null),{ref:g,isRefreshing:N}=je(()=>n.invalidateQueries()),[j,l]=u.useState(null),[a,i]=u.useState("leads"),[c,m]=u.useState({search:"",status:"all",urgency:"all",budget:"all"});u.useEffect(()=>{y.auth.me().then(t=>{h(t),t.role!=="admin"&&s("/")})},[s]);const{data:x=[]}=I({queryKey:["leads"],queryFn:()=>y.entities.Lead.list("-created_date"),enabled:(r==null?void 0:r.role)==="admin"}),{data:F=[]}=I({queryKey:["all-questionnaires"],queryFn:()=>y.entities.Questionnaire.list(),enabled:(r==null?void 0:r.role)==="admin"}),k=x.filter(t=>{var o,v;if(c.search){const f=c.search.toLowerCase();if(!((o=t.full_name)!=null&&o.toLowerCase().includes(f))&&!((v=t.email)!=null&&v.toLowerCase().includes(f)))return!1}if(c.status!=="all"&&t.status!==c.status||c.urgency!=="all"&&t.urgency!==c.urgency)return!1;if(c.budget!=="all"){const f=F.find(p=>p.id===t.questionnaire_id);if((f==null?void 0:f.budget_range)!==c.budget)return!1}return!0}),w={total:x.length,premium:x.filter(t=>t.is_premium).length,highUrgency:x.filter(t=>t.urgency==="high").length,newThisWeek:x.filter(t=>{const o=new Date(t.created_date),v=new Date;return v.setDate(v.getDate()-7),o>=v}).length},K=()=>{const t=["ש×,××××××,××פ××,ס×××ס,×××פ×ת,ש×ר×ת ×××××¥,פר×××××,ר×ת ס××××,ת×ר××"];
16k.forEach(p=>{t.push([p.full_name,p.email,p.phone,p.status,p.urgency,p.recommended_service,p.is_premium,p.risk_level,new Date(p.created_date).toLocaleDateString("he-IL")].join(","))});const o=new Blob(["\uFEFF"+t.join(` 17`)],{type:"text/csv;charset=utf-8;"}),v=URL.createObjectURL(o),f=document.createElement("a");f.href=v,f.download="leads.csv",f.click(),URL.revokeObjectURL(v)};return(r==null?void 0:r.role)!=="admin"?null:j?e.jsx("div",{className:"min-h-screen py-20 px-4",children:e.jsx("div",{className:"max-w-5xl mx-auto",children:e.jsx(De,{lead:j,onBack:()=>l(null)})})}):e.jsxs("div",{ref:g,className:"min-h-screen py-20 px-4",children:[e.jsx(pe,{noindex:!0}),N&&e.jsx("div",{className:"fixed top-20 left-0 right-0 flex justify-center z-50",children:e.jsxs("div",{className:"bg-primary text-primary-foreground text-sm px-4 py-2 rounded-full shadow-lg flex items-center gap-2",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-primary-foreground border-t-transparent rounded-full animate-spin"}),"××¨×¢× ×..."]})}),e.jsx("div",{className:"max-w-6xl mx-auto",children:e.jsxs(ge.div,{initial:{opacity:0,y:15},animate:{opacity:1,y:0},children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-frank text-3xl font-bold",children:"××× × ××××"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"× ×××× ××××× ×××¢×§× ××ר ××§×××ת"})]}),e.jsxs(z,{variant:"outline",onClick:K,className:"rounded-xl gap-2",children:[e.jsx(fe,{className:"w-4 h-4"})," ××צ×× CSV"]})]}),e.jsxs("div",{className:"flex gap-2 mb-6",children:[e.jsx("button",{onClick:()=>i("leads"),className:`px-4 py-2 rounded-xl text-sm font-medium transition-colors ${a==="leads"?"bg-primary text-primary-foreground":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:"×××××"}),e.jsx("button",{onClick:()=>i("clients"),className:`px-4 py-2 rounded-xl text-sm font-medium transition-colors ${a==="clients"?"bg-primary text-primary-foreground":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:"×ר×× ××§×××ת"})]}),a==="leads"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[e.jsx(B,{icon:be,label:"ס××´× ×××××",value:w.total}),e.jsx(B,{icon:Y,label:"פר×××××",value:w.premium}),e.jsx(B,{icon:W,label:"×××פ×ת ×××××",value:w.highUrgency}),e.jsx(B,{icon:Ne,label:"×ש×××¢",value:w.newThisWeek})]}),e.jsx(Le,{filters:c,onFilterChange:m}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:k.map(t=>e.jsx(ke,{lead:t,onClick:l},t.id))}),k.length===0&&e.jsx("div",{className:"text-center py-16 text-muted-foreground",children:e.jsx("p",{children:"×× × ×צ×× ×××××"})})]}):e.jsx(Ie,{leads:x,questionnaires:F,onSelectLead:l})]})})]})}function B({icon:s,label:n,value:r}){return e.jsx(E,{className:"rounded-2xl",children:e.jsxs(T,{className:"p-5 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-accent/60 flex items-center justify-center",children:e.jsx(s,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold text-foreground",children:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]})]})})}export{Ke 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.