1import{r as j,j as e}from"./ui-CPW3-RCR.js";import{u as Se}from"./useSmartScroll-Da1xVHwy.js";import{y as U,z as ie,E as ne,a1 as be,J as F,I as fe,B as oe,L as te,aL as je,s as ae,b2 as Te,a as ke,g as Oe,a2 as re,a9 as Ae,a_ as Re,a$ as Pe,b0 as G,b1 as K,V as Ce,k as $e,a3 as Me}from"./index-BraPXa8T.js";import{M as Ee}from"./MermaidChart-DbehVDVk.js";import{S as Xe}from"./SendToTaskManager-ChKH7nnt.js";import{C as Ie}from"./ChatThreadSidebar-CfZe0DLw.js";import{u as ze}from"./useChatThreads-C2aQZPDf.js";import{t as De}from"./autoLearn-CRnZuHOE.js";import{S as Y,a as Z,b as ee,c as se,d as w}from"./select-DubWVshT.js";import{u as ce}from"./useDemoLocale-COy7_g6Y.js";import{M as W}from"./index-BfRVBusC.js";import{S as _e}from"./shield-alert-CSZB8Xzk.js";import{U as ve}from"./user-x-LzgP7RsF.js";import{C as ye}from"./chart-pie-C2dMHTgo.js";import{T as Be}from"./trending-down-BWyGfEbB.js";import"./supabase-B2z4OhLQ.js";import"./charts-DCB9_QAo.js";import"./vendor-CIXof4MH.js";import"./TaskCreateDialog-DKBsfrRz.js";import"./AdvancedDatePicker-ChPu-U4D.js";import"./tag-BX6YVh3F.js";import"./arrow-up-down-CCRYX6WW.js";import"./calendar-Cw1MR1gK.js";import"./en-US-CmMcNpXQ.js";import"./endOfMonth-F9aO6iN7.js";import"./format-DAGnYLwh.js";import"./startOfWeek-Dx_XlaWC.js";import"./isSameYear-CisLDsou.js";import"./subDays-B6CEP03R.js";import"./pt-XXd_e7HC.js";import"./it-Bv9SfiiA.js";import"./he-CneTJ2uI.js";import"./repeat-Bzyo7NvJ.js";import"./useTaskInlineHelpers-C6iIbF2m.js";import"./confetti.module-B5JVzsfH.js";import"./collapsible-CHuAoMFW.js";import"./index-DkD4heWV.js";import"./RichTextEditor-CJcYExHW.js";import"./index-CVizilC1.js";import"./with-selector-BvZ9_Y0X.js";import"./index-BP6EXeue.js";import"./index-BwRZ_Ozi.js";import"./dropdown-menu-ByQNdDT1.js";import"./circle-Bi-mZyos.js";import"./unlink-CAyXBby2.js";import"./heading-2-DPmEGPQt.js";import"./quote-BPj_Y_e6.js";import"./minus-CCCsL8N7.js";import"./table-CUdv-10Z.js";import"./strikethrough-DJ9SUok4.js";import"./link-BKA0FtFv.js";import"./index-BdQq_4o_.js";import"./scroll-area-BQtXZnuf.js";import"./formatDistanceToNow-DrARF4Rk.js";import"./constructNow-DBola7tm.js";import"./endOfDay-DBxpZW_E.js";const Le="https://ecrgkarlfnflbtpqsmun.supabase.co/functions/v1/prophet-chat";function qe({clientId:t,clientName:g,language:d}){const{isEnglishDemo:$,dir:i,tr:a}=ce(),m=d==="en"||$,[p,u]=j.useState(""),[h,k]=j.useState("all"),[S,M]=j.useState("month"),[A,R]=j.useState(""),[E,X]=j.useState(!1),I=`×ת×ר ×ער×ת ××××× ROAS, ×ª× ×× ×ª×××ת ×פ×ר×ת: 2- תקצ××: âª${p} 3- פ××פ×ר××: ${h==="all"?"×× ×פ××פ×ר××ת":h} 4- תק×פ×: ${S==="month"?"×××ש":S==="quarter"?"ר××¢××":"ש×××¢"} 5${g?`- ××§××: ${g}`:""} 6 7×× × ×ª×: 81. ROAS צפ×× (3 תר××ש××) 92. ××צ×× ×¦×¤××× vs ××× ×¡× ×¦×¤××× 103. ×××צ×ת ×ש×פ×ר ROAS 114. ×ש×××× ×××צ××¢×× ×× ×××××× (×× ×ש × ×ª×× ××) 12 13\`\`\`prophet_metrics 14[ 15 {"label": "ROAS צפ×× - תר××ש ××פ××××", "value": "X.XX", "type": "optimistic"}, 16 {"label": "ROAS צפ×× - תר××ש ר××××", "value": "X.XX", "type": "realistic"}, 17 {"label": "ROAS צפ×× - תר××ש פס×××", "value": "X.XX", "type": "pessimistic"} 18] 19\`\`\``,P=async()=>{var c,C,v;if(!(!p||E)){X(!0),R("");try{const{data:{session:T}}=await ae.auth.getSession(),O=T==null?void 0:T.access_token;if(!O)throw new Error(a("×× ××××ר","Not signed in"));const b=await fetch(Le,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${O}`},body:JSON.stringify({messages:[{role:"user",content:I}],client_id:t||null,language:d})});if(!b.ok||!b.body)throw new Error("Failed");const _=b.body.getReader(),s=new TextDecoder;let r="",l="";for(;;){const{done:x,value:n}=await _.read();if(x)break;r+=s.decode(n,{stream:!0});let o;for(;(o=r.indexOf(` 20`))!==-1;){let f=r.slice(0,o);if(r=r.slice(o+1),f.endsWith("\r")&&(f=f.slice(0,-1)),!f.startsWith("data: "))continue;const B=f.slice(6).trim();if(B==="[DONE]")break;try{const J=(v=(C=(c=JSON.parse(B).choices)==null?void 0:c[0])==null?void 0:C.delta)==null?void 0:v.content;J&&(l+=J,R(l))}catch{r=f+` 21`+r;break}}}}catch(T){R(`â ï¸ ${a("ש××××","Error")}: ${T.message}`)}X(!1)}};return e.jsxs("div",{className:"space-y-4",dir:i,children:[e.jsxs(U,{children:[e.jsx(ie,{className:"pb-3",children:e.jsxs(ne,{className:"text-sm flex items-center gap-2",children:[e.jsx(be,{className:"w-4 h-4 text-primary"}),a("××××× ROAS â תש××× ×¦×¤××× ×¢× ××צ××ת פרס××","ROAS forecast â expected return on ad spend")]})}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-muted-foreground",children:a("תקצ×× (âª)","Budget (âª)")}),e.jsx(fe,{type:"number",placeholder:"10000",value:p,onChange:c=>u(c.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-muted-foreground",children:a("פ××פ×ר××","Platform")}),e.jsxs(Y,{value:h,onValueChange:k,children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(w,{value:"all",children:a("×× ×פ××פ×ר××ת","All platforms")}),e.jsx(w,{value:"Google Ads",children:"Google Ads"}),e.jsx(w,{value:"Meta Ads",children:"Meta Ads"}),e.jsx(w,{value:"LinkedIn Ads",children:"LinkedIn Ads"}),e.jsx(w,{value:"TikTok Ads",children:"TikTok Ads"})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-muted-foreground",children:a("תק×פ×","Period")}),e.jsxs(Y,{value:S,onValueChange:M,children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(w,{value:"week",children:a("ש×××¢","Week")}),e.jsx(w,{value:"month",children:a("×××ש","Month")}),e.jsx(w,{value:"quarter",children:a("ר××¢××","Quarter")})]})]})]})]}),e.jsxs(oe,{onClick:P,disabled:E||!p,className:"w-full gap-2",children:[E?e.jsx(te,{className:"h-4 w-4 animate-spin"}):e.jsx(je,{className:"h-4 w-4"}),E?a("×××©× ×ª×××ת...","Generating forecast..."):a("××× ROAS","Forecast ROAS")]})]})]}),A&&e.jsx(U,{children:e.jsx(F,{className:"pt-4",children:e.jsx("div",{className:`prose prose-sm max-w-none dark:prose-invert ${m?"[direction:ltr]":"[direction:rtl]"}`,children:e.jsx(W,{children:A.replace(/```prophet_metrics[\s\S]*?```/g,"")})})})})]})}const We="https://ecrgkarlfnflbtpqsmun.supabase.co/functions/v1/prophet-c
21hat";function Ue({clientId:t,clientName:g,language:d}){const{isEnglishDemo:$,dir:i,tr:a}=ce(),m=d==="en"||$,[p,u]=j.useState("client"),[h,k]=j.useState(""),[S,M]=j.useState(!1),A=async()=>{var X,I,P;if(S)return;M(!0),k("");const R=g?`×¢××ר ×××§×× ${g}`:"××× ×××§×××ת",E=p==="client"?`×ת×ר ×ער×ת ××××× Churn, ×צע × ×ת×× ×¡×××× × ×××©× ${R}: 22 231. **צ××× ×¡×××× × ××ש×** (1-100) ×¢× ×¤×ר×× ×××ר××× 242. **ס××× × ×××ר×** â ×× ××¢×× ×¢× ×¡×××× (×ר××× ×××צ××¢××, ××סר תקש×רת, ×ר××× ×תקצ××) 253. **××ר×× × ×××©× ×¢×קר×××** â ×× ×ס×××ת ×ס××ר×ת 264. **פע×××ת ×× ××¢×** â ×× ×עש×ת ×¢×ש×× ××× ×××§××× ×ת ×ס×××× 275. **צ×ר ×××** â ת×× ××× ××× ×¦×¤××× ×× ×××©× ×× ×× × ×¤×¢× 28 29\`\`\`prophet_metrics 30[ 31 {"label": "ס×××× × ×××©× - תר××ש ××××", "value": "XX%", "type": "pessimistic"}, 32 {"label": "ס×××× × ×××©× - תר××ש ס××ר", "value": "XX%", "type": "realistic"}, 33 {"label": "ס×××× ×©×××ר ×¢× ×¤×¢×××", "value": "XX%", "type": "optimistic"} 34] 35\`\`\``:`×ת×ר ×ער×ת ××××× Churn, ×צע × ×ת×× ×¡×××× × ××שת ×××ש××/××××× ${R}: 36 371. **ש××¢×ר × ×××©× ×¦×¤××** ××תר/×××¤× × ×××ª× 382. **× ×§×××ת ×××××** â ×××× ×××ש×× × ××ש×× (××¤× × ×ª×× × Pixel/Analytics ×× ×§×××××) 393. **ס××× ××× ×ס××××** â ×××× ×§×××× × ××ש×× ××תר 404. **×××צ×ת ××פ×תת × ××ש×** â ש×× ×××× ××תר, ×פרס××, ×-UX 415. **ROI צפ××** â ××× × ×¨×××× ×× × ×¤××ת ×ת ×× ×××©× ×-X% 42 43\`\`\`prophet_metrics 44[ 45 {"label": "ש××¢×ר × ×××©× ×¦×¤×× - ××××", "value": "XX%", "type": "pessimistic"}, 46 {"label": "ש××¢×ר × ×××©× ×¦×¤×× - ס××ר", "value": "XX%", "type": "realistic"}, 47 {"label": "ש××¢×ר × ×××©× ×××¨× ××פ×××××צ××", "value": "XX%", "type": "optimistic"} 48] 49\`\`\``;try{const{data:{session:c}}=await ae.auth.getSession(),C=c==null?void 0:c.access_token;if(!C)throw new Error(a("×× ××××ר","Not signed in"));const v=await fetch(We,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${C}`},body:JSON.stringify({messages:[{role:"user",content:E}],client_id:t||null,language:d})});if(!v.ok||!v.body)throw new Error("Failed");const T=v.body.getReader(),O=new TextDecoder;let b="",_="";for(;;){const{done:s,value:r}=await T.read();if(s)break;b+=O.decode(r,{stream:!0});let l;for(;(l=b.indexOf(` 50`))!==-1;){let x=b.slice(0,l);if(b=b.slice(l+1),x.endsWith("\r")&&(x=x.slice(0,-1)),!x.startsWith("data: "))continue;const n=x.slice(6).trim();if(n==="[DONE]")break;try{const o=(P=(I=(X=JSON.parse(n).choices)==null?void 0:X[0])==null?void 0:I.delta)==null?void 0:P.content;o&&(_+=o,k(_))}catch{b=x+` 51`+b;break}}}}catch(c){k(`â ï¸ ${a("ש××××","Error")}: ${c.message}`)}M(!1)};return e.jsxs("div",{className:"space-y-4",dir:i,children:[e.jsxs(U,{children:[e.jsx(ie,{className:"pb-3",children:e.jsxs(ne,{className:"text-sm flex items-center gap-2",children:[e.jsx(_e,{className:"w-4 h-4 text-destructive"}),a("××××× × ×××©× (Churn Prediction)","Churn prediction")]})}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-muted-foreground",children:a("ס×× × ×ת××","Analysis type")}),e.jsxs(Y,{value:p,onValueChange:u,children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(w,{value:"client",children:a("× ××שת ××§×× (Client Churn)","Client churn")}),e.jsx(w,{value:"visitor",children:a("× ××שת ×××ש××/××××× (Visitor Churn)","Visitor churn")})]})]})]}),e.jsxs(oe,{onClick:A,disabled:S,variant:"destructive",className:"w-full gap-2",children:[S?e.jsx(te,{className:"h-4 w-4 animate-spin"}):e.jsx(ve,{className:"h-4 w-4"}),S?a("×× ×ª× ×¡×××× × ××ש×...","Analyzing churn risk..."):a("×רץ × ×ת×× Churn","Run churn analysis")]})]})]}),h&&e.jsx(U,{children:e.jsx(F,{className:"pt-4",children:e.jsx("div",{className:`prose prose-sm max-w-none dark:prose-invert ${m?"[direction:ltr]":"[direction:rtl]"}`,children:e.jsx(W,{children:h.replace(/```prophet_metrics[\s\S]*?```/g,"")})})})})]})}const Fe="https://ecrgkarlfnflbtpqsmun.supabase.co/functions/v1/prophet-c
51hat";function Je({clientId:t,clientName:g,language:d}){const{isEnglishDemo:$,dir:i,tr:a}=ce(),m=d==="en"||$,[p,u]=j.useState(""),[h,k]=j.useState("leads"),[S,M]=j.useState(""),[A,R]=j.useState(!1),E=async()=>{var P,c,C;if(!p||A)return;R(!0),M("");const I=`×ת×ר ×ער×ת ××פ×××××צ×× ×©× ×ª×§×¦×× ×¤×¨×¡××, ×ª× ××××¦× ×פ×ר×ת: 52 53- תקצ×× ××××: âª${p} 54- ××ר×: ${{leads:"×קס×× ×××××/×¤× ××ת",revenue:"×קס×× ××× ×¡×ת/ROAS",awareness:"×קס×× ×ש××¤× ×××××¢×ת",balanced:"××××× ××× ×××××, ××× ×¡×ת ××ש×פ×"}[h]} 55${g?`- ××§××: ${g}`:""} 56 57×× × ×ª×: 581. **×××קת תקצ×× ××××צת** â ××× ××קצ×ת ××× ×¤××פ×ר×× (Google Ads, Meta Ads, LinkedIn, TikTok, SEO, ת×××) ×¢× ×××××× ××ספר×× 592. **×× ××§×** â ××× ××××§× ×××××§× ×××, ××ת×× ×× ×ª×× ×× ××§××××× 603. **ת×××ת ת×צ××ת** â ×× ×¦×¤×× ××××ת ×ת×צ×× ××× ×¤××פ×ר×× 614. **××××§× ×××פ×ת** â ××פצ×× ×©× ××× ×¢× ×תר×× ×ת/×סר×× ×ת 625. **××פ×× ×××ס×××** â ×××¤× ×פשר ××ס×× ××× ×פ×××¢ ×××צ××¢×× 63 64××¦× ×ת ×××××§× ×× ×××××: 65| פ××פ×ר×× | תקצ×× ×××××¥ | % ××תקצ×× | ת×צ×× ×¦×¤××× | 66|-----------|-------------|-----------|-------------| 67 68\`\`\`prophet_metrics 69[ 70 {"label": "ROI צפ×× - תר××ש ××פ××××", "value": "X.XX", "type": "optimistic"}, 71 {"label": "ROI צפ×× - תר××ש ר××××", "value": "X.XX", "type": "realistic"}, 72 {"label": "ROI צפ×× - תר××ש פס×××", "value": "X.XX", "type": "pessimistic"} 73] 74\`\`\``;try{const{data:{session:v}}=await ae.auth.getSession(),T=v==null?void 0:v.access_token;if(!T)throw new Error(a("×× ××××ר","Not signed in"));const O=await fetch(Fe,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${T}`},body:JSON.stringify({messages:[{role:"user",content:I}],client_id:t||null,language:d})});if(!O.ok||!O.body)throw new Error("Failed");const b=O.body.getReader(),_=new TextDecoder;let s="",r="";for(;;){const{done:l,value:x}=await b.read();if(l)break;s+=_.decode(x,{stream:!0});let n;for(;(n=s.indexOf(` 75`))!==-1;){let o=s.slice(0,n);if(s=s.slice(n+1),o.endsWith("\r")&&(o=o.slice(0,-1)),!o.startsWith("data: "))continue;const f=o.slice(6).trim();if(f==="[DONE]")break;try{const B=(C=(c=(P=JSON.parse(f).choices)==null?void 0:P[0])==null?void 0:c.delta)==null?void 0:C.content;B&&(r+=B,M(r))}catch{s=o+` 76`+s;break}}}}catch(v){M(`â ï¸ ${a("ש××××","Error")}: ${v.message}`)}R(!1)};return e.jsxs("div",{className:"space-y-4",dir:i,children:[e.jsxs(U,{children:[e.jsx(ie,{className:"pb-3",children:e.jsxs(ne,{className:"text-sm flex items-center gap-2",children:[e.jsx(ye,{className:"w-4 h-4 text-primary"}),a("××פ×××××צ××ת תקצ×× â ××××§× ×××× ×©× ××צ××ת פרס××","Budget optimization â smart ad spend allocation")]})}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-muted-foreground",children:a("תקצ×× ×××× (âª)","Total budget (âª)")}),e.jsx(fe,{type:"number",placeholder:"50000",value:p,onChange:X=>u(X.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs text-muted-foreground",children:a("×××¨× ×¢×קר×ת","Primary goal")}),e.jsxs(Y,{value:h,onValueChange:k,children:[e.jsx(Z,{children:e.jsx(ee,{})}),e.jsxs(se,{children:[e.jsx(w,{value:"leads",children:a("×קס×× ×××××/×¤× ××ת","Maximize leads")}),e.jsx(w,{value:"revenue",children:a("×קס×× ××× ×¡×ת (ROAS)","Maximize revenue (ROAS)")}),e.jsx(w,{value:"awareness",children:a("×קס×× ×ש××¤× ×××××¢×ת","Maximize awareness")}),e.jsx(w,{value:"balanced",children:a("××××× ××××","Balanced mix")})]})]})]})]}),e.jsxs(oe,{onClick:E,disabled:A||!p,className:"w-full gap-2",children:[A?e.jsx(te,{className:"h-4 w-4 animate-spin"}):e.jsx(Te,{className:"h-4 w-4"}),A?a("×××©× ××××§× ××פ×××××ת...","Optimizing allocation..."):a("×צע ××פ×××××צ××","Run optimization")]})]})]}),S&&e.jsx(U,{children:e.jsx(F,{className:"pt-4",children:e.jsx("div",{className:`prose prose-sm max-w-none dark:prose-invert ${m?"[direction:ltr]":"[direction:rtl]"}`,children:e.jsx(W,{children:S.replace(/```prophet_metrics[\s\S]*?```/g,"")})})})})]})}const Ve="https://ecrgkarlfnflbtpqsmun.supabase.co/functions/v1/prophet-c
76hat",xe={he:{suggestions:["×× ××§×¨× ×¢× ×××צ××¢×× ×©×× × ××××ש ××× ×× × ×ש×× ××××ª× ×ס×ר××××?","×ª× ×× ×ª×××ת ROI ×ר××¢×× ××× ×¢× ×תקצ×× ×× ××××","×× ××סת×ר×ת ×©× ×©×¤×¨ ×ת ×-CPA ×-20% ××××ש××× ×קר××××?","×××× ×¡×××× ×× ×©××××§××× ×¦×¤×××× ×× × ×תק××¤× ×קר×××?"],authRequired:"×× ××××ר â ×ש ××ת××ר ×××ש",streamFailed:"×× × ××ª× ××§×× ×ª×××ת ×ר××¢",forecastUnavailable:"ש××××",chatTab:"צ'×× ×××××",roasTab:"××××× ROAS",churnTab:"××××× × ××ש×",budgetTab:"××פ×××××צ××ת תקצ××",optimistic:"××פ××××",pessimistic:"פס×××",realistic:"ר××××",probability:"×סת×ר×ת",sendToTaskManager:"××¢×ר ××× ×× ××ש×××ת",inputPlaceholder:"ש×× ×©××× ××××××ת ×× ××ר ×צע×...",sendMessage:"ש×× ××××¢×"},en:{suggestions:["What will happen to our performance next month if we continue with the same strategy?","Give me an ROI forecast for next quarter with the current budget","What is the probability we improve CPA by 20% in the next two months?","What marketing risks are likely in the near term?"],authRequired:"Not signed in â please sign in again",streamFailed:"Unable to generate a forecast right now",forecastUnavailable:"Error",chatTab:"Prediction chat",roasTab:"ROAS forecast",churnTab:"Churn forecast",budgetTab:"Budget optimization",optimistic:"Optimistic",pessimistic:"Pessimistic",realistic:"Realistic",probability:"Probability",sendToTaskManager:"Send to task manager",inputPlaceholder:"Ask a predictive question or choose a suggestion...",sendMessage:"Send message"},it:{suggestions:["Cosa succederà alle nostre performance il mese prossimo se continuiamo con la stessa strategia?","Dammi una previsione del ROI per il prossimo trimestre con il budget attuale","Qual è la probabilità di migliorare il CPA del 20% nei prossimi due mesi?","Quali rischi marketing sono probabili nel prossimo periodo?"],authRequired:"Accesso mancante â effettua di nuovo il login",streamFailed:"Impossibile generare una previsione in questo momento",forecastUnavailable:"Errore",chatTab:"Chat predittiva",roasTab:"Previsione ROAS",churnTab:"Previsione churn",budgetTab:"Ottimizzazione budget",optimistic:"Ottimistico",pessimistic:"Pessimistico",realistic:"Realistico",probability:"Probabilità ",sendToTaskManager:"Invia al task manager",inputPlaceholder:"Fai una domanda predittiva o scegli un suggerimento...",sendMessage:"Invia messaggio"},fr:{suggestions:["Que se passera-t-il avec nos performances le mois prochain si nous continuons avec la même stratégie ?","Donne-moi une prévision de ROI pour le prochain trimestre avec le budget actuel","Quelle est la probabilité d'améliorer le CPA de 20 % dans les deux prochains mois ?","Quels risques marketing sont probables dans la période à venir ?"],authRequired:"Non connecté â veuillez vous reconnecter",streamFailed:"Impossible de générer une prévision pour le moment",forecastUnavailable:"Erreur",chatTab:"Chat prédictif",roasTab:"Prévision ROAS",churnTab:"Prévision du churn",budgetTab:"Optimisation du budget",optimistic:"Optimiste",pessimistic:"Pessimiste",realistic:"Réaliste",probability:"Probabilité",sendToTaskManager:"Envoyer au gestionnaire de tâches",inputPlaceholder:"Posez une question prédictive ou choisissez une suggestion...",sendMessage:"Envoyer le message"},pt:{suggestions:["O que vai acontecer com nosso desempenho no próximo mês se continuarmos com a mesma estratég
76ia?","Me dê uma previsão de ROI para o próximo trimestre com o orçamento atual","Qual é a probabilidade de melhorarmos o CPA em 20% nos próximos dois meses?","Quais riscos de marketing são prováveis no curto prazo?"],authRequired:"Sessão ausente â faça login novamente",streamFailed:"Não foi possÃvel gerar uma previsão agora",forecastUnavailable:"Erro",chatTab:"Chat preditivo",roasTab:"Previsão de ROAS",churnTab:"Previsão de churn",budgetTab:"Otimização de orçamento",optimistic:"Otimista",pessimistic:"Pessimista",realistic:"Realista",probability:"Probabilidade",sendToTaskManager:"Enviar para o gerenciador de tarefas",inputPlaceholder:"Faça uma pergunta preditiva ou escolha uma sugestão...",sendMessage:"Enviar mensagem"}},Qe={optimistic:[/תר××ש\s+××פ××××[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/optimistic\s+scenario[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/scenario\s+optimiste[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/scenario\s+ottimistico[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/cen[aá]rio\s+otimista[^:]*:?\s*\**\s*([^\n]{5,80})/gi],realistic:[/תר××ש\s+ר××××(?:ס××)?[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/realistic\s+scenario[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/scenario\s+r[ée]aliste[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/scenario\s+realistico[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/cen[aá]rio\s+realista[^:]*:?\s*\**\s*([^\n]{5,80})/gi],pessimistic:[/תר××ש\s+פס×××(?:ס××)?[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/pessimistic\s+scenario[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/scenario\s+pessimiste[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/scenario\s+pessimistico[^:]*:?\s*\**\s*([^\n]{5,80})/gi,/cen[aá]rio\s+pessimista[^:]*:?\s*\**\s*([^\n]{5,80})/gi],neutral:[]};function He(t){const g=[...t].reverse().find(a=>a.role==="assistant");if(!g)return[];const d=g.content,$=d.match(/```prophet_metrics\s*\n?([\s\S]*?)```/);if($)try{const a=JSON.parse($[1].trim());if(Array.isArray(a))return a.filter(m=>m.label&&m.value&&m.type).map(m=>({label:String(m.label).substring(0,60),value:String(m.value),type:["optimistic","realistic","pessimistic"].includes(m.type)?m.type:"neutral"})).slice(0,6)}catch{}const i=[];for(const[a,m]of Object.entries(Qe))for(const p of m){const u=p.exec(d);if(!u)continue;const h=u[1].replace(/\*+/g,"").trim(),k=d.substring(u.index,u.index+200).match(/(\d{1,3})%/);i.push({label:h.substring(0,60),value:k?`${k[1]}%`:h.substring(0,30),type:a});break}return i.slice(0,6)}function ge(t){return t.replace(/```prophet_metrics[\s\S]*?```/g,"").trim()}function Ge({type:t}){switch(t){case"optimistic":return e.jsx(je,{className:"w-4 h-4 text-emerald-500"});case"pessimistic":return e.jsx(Be,{className:"w-4 h-4 text-red-500"});case"realistic":return e.jsx(Me,{className:"w-4 h-4 text-blue-500"});default:return e.jsx(re,{className:"w-4 h-4 text-amber-500"})}}function Ke(t){switch(t){case"optimistic":return"border-emerald-500/30";case"pessimistic":return"border-red-500/30";case"realistic":return"border-blue-500/30";default:return"border-amber-500/30"}}function Ye(t){switch(t){case"optimistic":return"bg-emerald-500/5";case"pessimistic":return"bg-red-500/5";case"realistic":return"bg-blue-500/5";default:return"bg-amber-500/5"}}function tt(){const{selectedClient:t}=ke(),{t:g,language:d}=Oe(),$=d==="he",i=xe[d]??xe.en,a=ze({chatType:"prophet",clientId:(t==null?void 0:t.id)||null}),{threads:m,activeThreadId:p,messages:u,setMessages:h,loadingThreads:k,selectThread:S,createThread:M,persistMessage:A,saveAssistantDebounced:R,startNewChat:E,deleteThread:X}=a,[I,P]=j.useState(""),[c,C]=j.useState(!1),{bottomRef:v}=Se([u]),T=j.useMemo(()=>c?[]:He(u),[u,c]),O=async s=>{var f,B,J,le,de,me;const r=s||I.trim();if(!r||c)return;const l={role:"user",content:r},x=[...u,l];h(x),P(""),C(!0);let n=p;n||(n=await M(r)),n&&A(n,"user",r);let o="";try{const{data:{session:q}}=await ae.auth.getSession(),V=q==null?void 0:q.access_token;if(!V)throw new Error(i.authRequired);const Q=await fetch(Ve,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${V}`},body:JSON.stringify({messages:x,client_id:(t==null?void 0:t.id)||null,language:d})});if(!Q.ok||!Q.body){const y=await Q.json().catch(()=>({}));throw new Error(y.error||i.streamFailed)}const Ne=Q.body.getReader(),we=new TextDecoder;let D="";const ue=y=>{o+=y,h(z=>{const L=z[z.length-1];return(L==null?void 0:L.role)==="assistant"?z.map((N,H)=>H===z.length-1?{...N,content:o}:N):[...z,{role:"assistant",content:o}]})};let pe=!1;for(;!pe;){const{done:y,value:z}=await Ne.read();if(y)break;D+=we.decode(z,{stream:!0});let L;for(;(L=D.indexOf(` 77`))!==-1;){let N=D.slice(0,L);if(D=D.slice(L+1),N.endsWith("\r")&&(N=N.slice(0,-1)),N.startsWith(":")||N.trim()===""||!N.startsWith("data: "))continue;const H=N.slice(6).trim();if(H==="[DONE]"){pe=!0;break}try{const he=(J=(B=(f=JSON.parse(H).choices)==null?void 0:f[0])==null?void 0:B.delta)==null?void 0:J.content;he&&ue(he)}catch{D=N+` 78`+D;break}}}if(D.trim())for(let y of D.split(` 79`)){if(!y||(y.endsWith("\r")&&(y=y.slice(0,-1)),y.startsWith(":")||y.trim()==="")||!y.startsWith("data: "))continue;const z=y.slice(6).trim();if(z!=="[DONE]")try{const N=(me=(de=(le=JSON.parse(z).choices)==null?void 0:le[0])==null?void 0:de.delta)==null?void 0:me.content;N&&ue(N)}catch{}}n&&o&&R(n,o),De({userMessage:r,aiResponse:o,clientId:t==null?void 0:t.id,chatSource:"prophet-c
79hat"})}catch(q){console.error("Prophet stream error:",q),h(V=>[...V,{role:"assistant",content:`â ï¸ ${i.forecastUnavailable}: ${q.message||i.streamFailed}`}])}C(!1)},b=(s,r)=>{const l=ge(s);return r?e.jsx(W,{children:l}):l.split(/(```mermaid[\s\S]*?```)/g).map((n,o)=>{const f=n.match(/```mermaid\n([\s\S]*?)```/);return f?e.jsx(Ee,{chart:f[1]},o):e.jsx(W,{children:n},o)})},_=T.length>0;return e.jsxs("div",{className:"flex h-[calc(100vh-80px)] overflow-x-hidden",children:[e.jsx(Ie,{threads:m,activeThreadId:p,onSelect:S,onNew:E,onDelete:X,loading:k}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-4 overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-amber-500 to-orange-600 flex items-center justify-center shadow-lg",children:e.jsx(re,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold",children:g("prophet.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g("prophet.subtitle")})]})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsx(Ae,{className:"w-4 h-4 text-amber-500 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed",children:g("prophet.disclaimer")})]}),e.jsxs(Re,{defaultValue:"chat",className:"w-full",children:[e.jsxs(Pe,{className:"grid w-full grid-cols-2 gap-1 sm:grid-cols-4",children:[e.jsxs(G,{value:"chat",className:"gap-1.5 text-xs",children:[e.jsx(re,{className:"w-3.5 h-3.5"})," ",i.chatTab]}),e.jsxs(G,{value:"roas",className:"gap-1.5 text-xs",children:[e.jsx(be,{className:"w-3.5 h-3.5"})," ",i.roasTab]}),e.jsxs(G,{value:"churn",className:"gap-1.5 text-xs",children:[e.jsx(ve,{className:"w-3.5 h-3.5"})," ",i.churnTab]}),e.jsxs(G,{value:"budget",className:"gap-1.5 text-xs",children:[e.jsx(ye,{className:"w-3.5 h-3.5"})," ",i.budgetTab]})]}),e.jsx(K,{value:"chat",className:"mt-4",children:e.jsxs("div",{className:"flex min-h-[calc(100vh-260px)] flex-col gap-4",dir:$?"rtl":"ltr",children:[e.jsx("div",{className:"flex-1 space-y-4 overflow-y-auto",children:u.length===0?e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:i.suggestions.map(s=>e.jsx("button",{type:"button",onClick:()=>O(s),className:"rounded-xl border border-border bg-card p-4 text-left text-sm text-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:s},s))}):e.jsxs("div",{className:"space-y-4",children:[u.map((s,r)=>{const l=s.role==="assistant",x=l&&c&&r===u.length-1,n=l?ge(s.content):s.content;return e.jsx("div",{className:`flex ${l?"justify-start":"justify-end"}`,children:e.jsxs("div",{className:`max-w-[90%] rounded-2xl px-4 py-3 shadow-sm ${l?"bg-secondary text-secondary-foreground":"bg-primary text-primary-foreground"}`,children:[e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none break-words",children:l?b(s.content,x):e.jsx(W,{children:n})}),l&&n&&!n.startsWith("â ï¸")&&e.jsx("div",{className:"mt-3 flex justify-end",children:e.jsx(Xe,{context:n,size:"sm",label:i.sendToTaskManager})})]})},`${s.role}-${r}`)}),_&&e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-3",children:T.map((s,r)=>e.jsxs("div",{className:`rounded-xl border p-3 ${Ke(s.type)} ${Ye(s.type)}`,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(Ge,{type:s.type}),e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:s.type==="optimistic"?i.optimistic:s.type==="pessimistic"?i.pessimistic:s.type==="realistic"?i.realistic:i.probability})]}),e.jsx("p",{className:"text-xl font-bold text-foreground",children:s.value}),e.jsx("p",{className:"mt-0.5 text-[11px] leading-tight text-muted-foreground",children:s.label})]},`${s.label}-${r}`))}),e.jsx("div",{ref:v})]})}),e.jsx("div",{className:"rounded-2xl border border-border bg-card p-2 shadow-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{onTranscript:s=>P(r=>r?`${r} ${s}`:s)}),e.jsx("input",{value:I,onChange:s=>P(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),O())}
79,placeholder:i.inputPlaceholder,disabled:c,className:"flex-1 bg-transparent px-2 py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground"}),e.jsx("button",{type:"button",onClick:()=>void O(),disabled:c||!I.trim(),className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary text-primary-foreground transition-opacity hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50","aria-label":i.sendMessage,children:c?e.jsx(te,{className:"h-4 w-4 animate-spin"}):e.jsx($e,{className:"h-4 w-4"})})]})})]})}),e.jsx(K,{value:"roas",className:"mt-4",children:e.jsx(qe,{clientId:t==null?void 0:t.id,clientName:t==null?void 0:t.name,language:d})}),e.jsx(K,{value:"churn",className:"mt-4",children:e.jsx(Ue,{clientId:t==null?void 0:t.id,clientName:t==null?void 0:t.name,language:d})}),e.jsx(K,{value:"budget",className:"mt-4",children:e.jsx(Je,{clientId:t==null?void 0:t.id,clientName:t==null?void 0:t.name,language:d})})]})]})]})}export{tt 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.