1import{r,j as e}from"./ui-CPW3-RCR.js";import{u as re}from"./useSmartScroll-Da1xVHwy.js";import{a as le,g as ie,d as o,c as R,h as O,i as q,L as B,j as oe,X as ce,U as de,V as xe,k as me,l as G,m as V,n as K,o as H,T as P,p as W,q as X,B as w,s as m}from"./index-BraPXa8T.js";import{u as ue}from"./useDemoLocale-COy7_g6Y.js";import{t as pe}from"./autoLearn-CRnZuHOE.js";import{M as he}from"./index-BfRVBusC.js";import"./supabase-B2z4OhLQ.js";import"./charts-DCB9_QAo.js";import"./vendor-CIXof4MH.js";function Ce(){const[u,T]=r.useState([]),[C,p]=r.useState(""),[h,M]=r.useState(!1),[U,A]=r.useState(null),[S,f]=r.useState(null),z=r.useRef(null),g=r.useRef(null),{clients:_}=le(),{language:J}=ie(),{isEnglishDemo:E,dir:c,locale:Q,tr:t}=ue(),[Y,j]=r.useState(!1),[Z,y]=r.useState(!1),[d,D]=r.useState(""),[i,x]=r.useState([]),[$,I]=r.useState(""),[b,N]=r.useState(!1),{scrollRef:ee}=re([u]),se=E?["Analyze digital marketing trends for 2026","What are the differences between Meta and Google for different segments?","Give me content strategy ideas"]:["× ×ª× ×× ××××ת ש××××§ ××××××× 2026","×× ××××××× ××× Meta ×-Google ×ס××× ××× ×©×× ××?","×ª× ×× ×¨×¢××× ×ת ××ס×ר××××ת ת×××"],te=r.useCallback(async s=>{var n;const a=(n=s.target.files)==null?void 0:n[0];if(!a)return;const l=5*1024*1024;if(a.size>l){o.error(t("××§×××¥ ×××× ××× (×קס×××× 5MB)","File is too large (max 5MB)"));return}f(a.name);try{const v=await a.text();A(v.substring(0,15e3)),o.success(t(`×§×××¥ "${a.name}" ×××¢×× ××צ×××`,`File "${a.name}" uploaded successfully`))}catch{o.error(t("×× × ××ª× ×קר×× ×ת ××§×××¥","Could not read the file")),f(null)}g.current&&(g.current.value="")},[t]),L=async()=>{const s=C.trim();if(!s||h)return;const a={role:"user",content:s},l=[...u,a];T(l),p(""),M(!0);try{const{data:n,error:v}=await m.functions.invoke("analyst-chat",{body:{messages:l.map(k=>({role:k.role,content:k.content})),file_content:U,file_name:S,language:E?"en":J}});if(v)throw v;if(n!=null&&n.error)throw new Error(n.error);T(k=>[...k,{role:"assistant",content:n.reply,suggestedActions:n.suggested_actions}]),pe({userMessage:s,aiResponse:n.reply,chatSource:"analyst"}),U&&(A(null),f(null))}catch(n){o.error(`${t("ש××××","Error")}: ${n.message}`)}finally{M(!1)}},ae=async()=>{if(!$.trim()||i.length===0){o.error(t("×ש ××××ר ××§×××ת ×××ת×× ××תרת","Select at least one client and enter a title"));return}N(!0);try{const{data:{user:s}}=await m.auth.getUser();if(!s)throw new Error("Not authenticated");for(const a of i)await m.from("tasks").insert({title:$,description:d,client_id:a,created_by:s.id,source:"ai_analyst",source_context:t("× ×צר ×ת×× AI ×× ××ס×","Created from AI Analyst"),priority:"medium",status:"todo"});o.success(t(`× ××¦×¨× ${i.length} ×ש×××ת`,`${i.length} tasks created`)),j(!1),x([]),I("")}catch(s){o.error(`${t("ש××××","Error")}: ${s.message}`)}finally{N(!1)}},ne=async()=>{if(i.length===0||!d.trim()){o.error(t("×ש ××××ר ××§×××ת ×××ת×× ×ª×××","Select at least one client and enter content"));return}N(!0);try{for(const s of i){const{data:a}=await m.from("clients").select("ai_instructions").eq("id",s).maybeSingle(),l=(a==null?void 0:a.ai_instructions)||"",n=l+(l?` 2 3`:"")+`[${new Date().toLocaleDateString(Q)}] ${d}`;await m.from("clients").update({ai_instructions:n}).eq("id",s)}o.success(t(`××× 3 ×¢×××× ×¢××ר ${i.length} ××§×××ת`,`Brain 3 updated for ${i.length} clients`)),y(!1),x([])}catch(s){o.error(`${t("ש××××","Error")}: ${s.message}`)}finally{N(!1)}},F=(s,a)=>{D(a),x([]),I(""),s==="task"?j(!0):y(!0)};return e.jsxs("div",{className:"space-y-5 max-w-4xl mx-auto",dir:c,children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg font-bold flex items-center gap-2",children:[e.jsx(R,{className:"w-5 h-5"}),t("AI ×× ××ס×","AI Analyst")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t("× ×ת×× ×ס××××, ת××× ×ת ש××××§××ת ×××קר â ××× ×ª××ת ×××§×× ×¡×¤×¦×פ×","Document analysis, marketing insights, and research â independent of any specific client")}
3)]}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{ref:ee,className:"min-h-[300px] max-h-[500px] overflow-y-auto px-5 py-4 space-y-4",children:[u.length===0&&e.jsxs("div",{className:"text-center py-8 space-y-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-full gradient-brand flex items-center justify-center mx-auto",children:e.jsx(R,{className:"w-6 h-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:"Viral AI Analyst"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t("××¢×× ×§×××¥ ×× ×©×× ×©××× â ×× × ×× ×ª× ×××ª× ×ª××× ×ת","Upload a file or ask a question â Iâll analyze it and give you insights")})]}),e.jsx("div",{className:"flex flex-wrap justify-center gap-2",children:se.map(s=>e.jsx("button",{onClick:()=>{var a;p(s),(a=z.current)==null||a.focus()},className:"px-3 py-1.5 rounded-full bg-secondary text-[11px] text-muted-foreground hover:text-foreground hover:bg-secondary/80 transition-colors",children:s},s))})]}),u.map((s,a)=>e.jsx("div",{className:`max-w-[85%] px-4 py-3 rounded-lg text-sm leading-relaxed ${s.role==="user"?"gradient-brand text-primary-foreground ms-auto":"bg-secondary text-foreground me-auto"}`,children:s.role==="assistant"?e.jsxs("div",{children:[e.jsx("div",{className:"ai-prose",children:e.jsx(he,{children:s.content})}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 border-t border-border/50 pt-2",children:[e.jsxs("button",{onClick:()=>F("task",s.content),className:"flex items-center gap-1 px-2.5 py-1 rounded bg-primary/10 text-primary text-[11px] hover:bg-primary/20 transition-colors",children:[e.jsx(O,{className:"w-3 h-3"}),t("צ×ר ×ש×××","Create task")]}),e.jsxs("button",{onClick:()=>F("brain3",s.content),className:"flex items-center gap-1 px-2.5 py-1 rounded bg-primary/10 text-primary text-[11px] hover:bg-primary/20 transition-colors",children:[e.jsx(q,{className:"w-3 h-3"}),t("×¢××× ××× 3","Update Brain 3")]})]})]}):s.content},a)),h&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(B,{className:"w-3.5 h-3.5 animate-spin"}),t("×× ×ª×...","Analyzing...")]})]}),S&&e.jsxs("div",{className:"mx-5 mb-2 flex items-center gap-2 px-3 py-1.5 bg-primary/10 rounded-md text-xs text-primary",children:[e.jsx(oe,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate",children:S}),e.jsx("button",{onClick:()=>{A(null),f(null)},className:"hover:text-primary/70",children:e.jsx(ce,{className:"w-3 h-3"})})]}),e.jsx("div",{className:"px-5 py-3 border-t border-border",children:e.jsxs("div",{className:"flex items-end gap-2 bg-secondary rounded-lg px-3 py-2",children:[e.jsx("button",{onClick:()=>{var s;return(s=g.current)==null?void 0:s.click()},className:"text-muted-foreground hover:text-foreground transition-colors pb-0.5",title:t("××¢×× ×§×××¥","Upload file"),children:e.jsx(de,{className:"w-4 h-4"})}),e.jsx("input",{ref:g,type:"file",className:"hidden",accept:"*/*",onChange:te}),e.jsx(xe,{onTranscript:s=>p(s)}),e.jsx("textarea",{ref:z,value:C,onChange:s=>p(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),L())},placeholder:t("ש×× ×©××× ×× ××¢×× ×§×××¥ ×× ×ת××...","Ask a question or upload a file for analysis..."),className:"flex-1 bg-transparent text-sm placeholder:text-muted-foreground outline-none resize-none min-h-[24px] max-h-[80px]",dir:c,disabled:h,rows:1}),e.jsx("button",{onClick:L,disabled:h||!C.trim(),className:"text-primary hover:text-primary/80 transition-colors disabled:opacity-40 pb-0.5",children:e.jsx(me,{className:"w-4 h-4"})})]})})]}),e.jsx(G,{open:Y,onOpenChange:j,children:e.jsxs(V,{className:"max-w-md",dir:c,children:[e.jsx(K,{children:e.jsxs(H,{className:"flex items-center gap-2",children:[e.jsx(O,{className:"w-4 h-4"}),t("×צ×רת ×ש××× ×ת××× ×ª AI","Create task from AI insight")]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1 block",children:t("××תרת ××ש×××","Task title")}),e.jsx("input",{value:$,onChange:s=>I(s.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm",dir:c,placeholder:t("××תרת ××ש×××...","Task title...")})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1 block",children:t("ת××× (××ש×××)","Content (from the chat)")}),e.jsx(P,{value:d,onChange:s=>D(s.target.value),className:"text-xs",rows:3,dir:c})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-2 block",children:t("ש××× ×××§×××ת","Assign to clients")}),e.jsx("div",{className:"max-h-[150px] overflow-y-auto space-y-1.5 border border-border rounded-md p-2",children:_.map(s=>e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer hover:bg-secondary/50 p-1 rounded",children:[e.jsx(W,{checked:i.includes(s.id
3),onCheckedChange:a=>{x(l=>a?[...l,s.id]:l.filter(n=>n!==s.id))}}),s.name]},s.id))})]})]}),e.jsxs(X,{children:[e.jsx(w,{variant:"outline",size:"sm",onClick:()=>j(!1),children:t("×××××","Cancel")}),e.jsx(w,{size:"sm",onClick:ae,disabled:b,children:b?e.jsx(B,{className:"w-3 h-3 animate-spin"}):t("צ×ר ×ש×××ת","Create tasks")})]})]})}),e.jsx(G,{open:Z,onOpenChange:y,children:e.jsxs(V,{className:"max-w-md",dir:c,children:[e.jsx(K,{children:e.jsxs(H,{className:"flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4"}),t("×¢×××× ××× 3 ×ת××× ×ª AI","Update Brain 3 from AI insight")]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-1 block",children:t("ת××× ××¢××××","Content to append")}),e.jsx(P,{value:d,onChange:s=>D(s.target.value),className:"text-xs",rows:4,dir:c})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium mb-2 block",children:t("×¢××× ×¢××ר ××§×××ת","Update for clients")}),e.jsx("div",{className:"max-h-[150px] overflow-y-auto space-y-1.5 border border-border rounded-md p-2",children:_.map(s=>e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer hover:bg-secondary/50 p-1 rounded",children:[e.jsx(W,{checked:i.includes(s.id),onCheckedChange:a=>{x(l=>a?[...l,s.id]:l.filter(n=>n!==s.id))}}),s.name]},s.id))})]})]}),e.jsxs(X,{children:[e.jsx(w,{variant:"outline",size:"sm",onClick:()=>y(!1),children:t("×××××","Cancel")}),e.jsx(w,{size:"sm",onClick:ne,disabled:b,children:b?e.jsx(B,{className:"w-3 h-3 animate-spin"}):t("×¢××× ××× 3","Update Brain 3")})]})]})})]})}export{Ce 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.