1var __IMPORT_META_ENV={};var __PROCESS_ENV={NODE_ENV:"production"}; 2import{a as $}from"/chunks/chunk-5LKAQM72.js";import{a as G,b as u}from"/chunks/chunk-OTUEUC6J.js";import{ad as B,jd as V,kc as K,pc as L,xb as A,y as C,zc as O}from"/chunks/chunk-A6Q5DW52.js";import{a as D}from"/chunks/chunk-A6NSEO7N.js";import{a as M,c as P}from"/chunks/chunk-7G2UIJPM.js";import{a as Z}from"/chunks/chunk-2F2XG2RD.js";import{d as w}from"/chunks/chunk-43M3N6VY.js";var n=w(Z());var e=w(D()),_=["01KN38TP7VA354T7XRH27QGAKX"];function q(a){let l=a.match(/```html\s*([\s\S]*?)```/);return l?l[1].trim():null}function F(a){let l=a.match(/(?:^|\n)(?:Objet|Subject|OBJET)\s*[:ï¼]\s*(.+)/i);return l?l[1].trim():null}var z=[{icon:"\u{1F4E7}",label:"Email de prospection",prompt:'G\xE9n\xE8re un email de prospection commerciale professionnel avec header navy, pr\xE9sentation de valeur, 3 b\xE9n\xE9fices cl\xE9s et un bouton CTA "Planifier un appel".'},{icon:"\u{1F504}",label:"Email de relance",prompt:'G\xE9n\xE8re un email de relance chaleureux et percutant suite \xE0 une proposition, avec un rappel de la valeur et un CTA "Voir la proposition".'},{icon:"\u{1F389}",label:"Onboarding client",prompt:'G\xE9n\xE8re un email de bienvenue pour un nouveau client, avec 3 \xE9tapes de d\xE9marrage num\xE9rot\xE9es, liens ressources et un CTA "Commencer".'},{icon:"\u2728",label:"Am\xE9liore le design",prompt:"Am\xE9liore le design de l'email actuel : header plus impactant, meilleure hi\xE9rarchie typographique, blocs color\xE9s et CTA plus visible."}];function W({context:a,onHtmlUpdate:l,onSubjectUpdate:x}
2){let[o,E]=(0,n.useState)(null),[X,J]=(0,n.useState)(_[0]),[p,h]=(0,n.useState)(!1),[k,v]=(0,n.useState)(null),[c,b]=(0,n.useState)(""),T=(0,n.useRef)(null),N=(0,n.useRef)(null),d=(0,n.useRef)(null),S=(0,n.useRef)(null),{sendMessage:f,messages:i,isConnected:m}=P(X,o);(0,n.useEffect)(()=>{S.current=f},[f]),(0,n.useEffect)(()=>{T.current?.scrollIntoView({behavior:"smooth"})},[i]),(0,n.useEffect)(()=>{let t=N.current;t&&(t.style.height="auto",t.style.height=Math.min(t.scrollHeight,120)+"px")},[c]);let y=(0,n.useRef)("");(0,n.useEffect)(()=>{if(!i.length)return;let t=i[i.length-1];if(t.role!=="assistant")return;let r=q(t.content);r&&r!==y.current&&(y.current=r,l(r));let s=F(t.content);s&&x&&x(s)},[i,l,x]),(0,n.useEffect)(()=>{if(m&&o&&d.current&&i.length===0){let t=d.current;d.current=null,g.current=!0;let r=`${j()} 3 4${t}`;setTimeout(async()=>{try{await S.current?.(r)}catch(s){console.warn(s)}},400)}},[m,o]);let g=(0,n.useRef)(!1);function j(){let t=["[Contexte de l'email en cours]"];return a.contactName&&t.push(`Destinataire : ${a.contactName}${a.contactCompany?` (${a.contactCompany})`:""}`),a.fromName&&t.push(`Exp\xE9diteur : ${a.fromName}`),a.primaryColor&&t.push(`Couleur primaire : ${a.primaryColor}`),a.currentHtml&&a.currentHtml.length>50&&t.push(` 5HTML actuel : 6\`\`\`html 7${a.currentHtml.slice(0,3e3)} 8\`\`\``),t.join(` 9`)}let I=async t=>{h(!0),v(null),t&&(d.current=t);for(let r of _)try{let{conversationId:s}=await M(r);J(r),E(s),h(!1);return}catch(s){console.warn(`Email agent ${r} failed:`,s)}v("Service temporairement indisponible."),d.current=null,console.warn("[EmailAIChat] All email agents failed to start"),h(!1)},R=(0,n.useCallback)(async()=>{let t=c.trim();if(!(!t||!o)){b("");try{let r=t;g.current||(g.current=!0,r=`${j()} 10 11${t}`),await f(r)}catch{$.error("Erreur lors de l'envoi")}}},[c,o,f]),Q=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),R())},U=async()=>{E(null),v(null),d.current=null,y.current="",g.current=!1};if(!o)return(0,e.jsx)("div",{className:"flex flex-col h-full",children:(0,e.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center p-6 gap-4",children:[(0,e.jsx)("div",{className:"w-14 h-14 rounded-2xl bg-gradient-to-br from-indigo-500 to-violet-600 flex items-center justify-center shadow-lg shadow-indigo-500/20",children:(0,e.jsx)(O,{className:"w-7 h-7 text-white"})}),(0,e.jsxs)("div",{className:"text-center",children:[(0,e.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Assistant Email IA"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground leading-relaxed",children:"G\xE9n\xE8re et optimise votre email HTML professionnel en temps r\xE9el."})]}),k&&(0,e.jsx)("div",{className:"w-full p-3 rounded-xl bg-red-500/10 border border-red-500/20 text-xs text-red-400 text-center",children:k}),(0,e.jsxs)("button",{onClick:()=>I(),disabled:p,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl bg-indigo-500 hover:bg-indigo-600 text-white text-sm font-medium transition-all disabled:opacity-60 shadow-md shadow-indigo-500/20",children:[p?(0,e.jsx)(A,{className:"w-4 h-4 animate-spin"}):(0,e.jsx)(V,{className:"w-4 h-4"}),p?"Connexion...":"D\xE9marrer l'assistant"]}),(0,e.jsx)("div",{className:"w-full space-y-2 mt-2",children:z.map(t=>(0,e.jsxs)("button",{onClick:()=>I(t.prompt),disabled:p,className:"w-full flex items-center gap-2.5 p-2.5 rounded-xl border border-border bg-card/50 hover:bg-muted/50 text-left transition-all group disabled:opacity-40",children:[(0,e.jsx)("span",{className:"text-lg shrink-0",children:t.icon}),(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"text-xs font-medium text-foreground group-hover:text-foreground",children:t.label}),(0,e.jsxs)("p",{className:"text-[10px] text-muted-foreground truncate",children:[t.prompt.slice(0,55),"\u2026"]})]})]},t.label))})]})});let H=i.length>0&&i[i.length-1].role==="user";return(0,e.jsxs)("div",{className:"flex flex-col h-full",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border shrink-0",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("div",{className:"w-2 h-2 rounded-full bg-emerald-400 animate-pulse"}),(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:"Assistant Email actif"})]}),(0,e.jsx)("button",{onClick:U,className:"p-1.5 rounded-lg hover:bg-muted/50 text-muted-foreground hover:text-foreground transition-colors",title:"R\xE9initialiser",children:(0,e.jsx)(K,{className:"w-3.5 h-3.5"})})]}),(0,e.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:[i.length<=2&&(0,e.jsxs)("div",{className:"space-y-1.5",children:[(0,e.jsx)("p",{className:"text-xs text-muted-foreground px-1",children:"Suggestions rapides :"}),z.map(t=>(0,e.jsxs)("button",{onClick:()=>{b(t.prompt),N.current?.focus()},className:"w-full flex items-center gap-2 p-2 rounded-xl border border-border bg-card/30 hover:bg-muted/50 text-left transition-all",children:[(0,e.jsx)("span",{className:"text-sm shrink-0",children:t.icon}),(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:t.label})]},t.label))]}),(0,e.jsx)(G,{initial:!1,children:i.map(t=>{if(t.role==="user")return(0,e.jsx)(u.div,{initial:{opacity:0,y:8}
11,animate:{opacity:1,y:0},className:"flex justify-end",children:(0,e.jsxs)("div",{className:"flex items-end gap-2 max-w-[85%]",children:[(0,e.jsx)("div",{className:"bg-indigo-500 text-white rounded-2xl rounded-br-sm px-3 py-2 text-xs leading-relaxed",children:t.content}),(0,e.jsx)("div",{className:"w-6 h-6 rounded-full bg-indigo-500/20 flex items-center justify-center shrink-0",children:(0,e.jsx)(B,{className:"w-3 h-3 text-indigo-400"})})]})},t.id);let r=q(t.content),s=r?t.content.slice(0,t.content.indexOf("```html")).trim():t.content;return(0,e.jsxs)(u.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"flex gap-2",children:[(0,e.jsx)("div",{className:"w-6 h-6 rounded-full bg-gradient-to-br from-indigo-500 to-violet-600 flex items-center justify-center shrink-0 mt-0.5",children:(0,e.jsx)(C,{className:"w-3 h-3 text-white"})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0 space-y-2",children:[s&&(0,e.jsx)("div",{className:"bg-card border border-border rounded-2xl rounded-tl-sm px-3 py-2 text-xs text-foreground leading-relaxed",children:s}),r&&(0,e.jsxs)("div",{className:"flex items-center gap-2 p-2.5 rounded-xl bg-emerald-500/10 border border-emerald-500/20",children:[(0,e.jsx)("div",{className:"w-5 h-5 rounded-full bg-emerald-500 flex items-center justify-center shrink-0",children:(0,e.jsx)("span",{className:"text-white text-[10px]",children:"\u2713"})}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-medium text-emerald-400",children:"Email g\xE9n\xE9r\xE9"}),(0,e.jsx)("p",{className:"text-[10px] text-muted-foreground",children:"Aper\xE7u mis \xE0 jour automatiquement"})]})]})]})]},t.id)})}),H&&(0,e.jsxs)(u.div,{initial:{opacity:0}
11,animate:{opacity:1},className:"flex gap-2",children:[(0,e.jsx)("div",{className:"w-6 h-6 rounded-full bg-gradient-to-br from-indigo-500 to-violet-600 flex items-center justify-center shrink-0",children:(0,e.jsx)(C,{className:"w-3 h-3 text-white"})}),(0,e.jsx)("div",{className:"bg-card border border-border rounded-2xl rounded-tl-sm px-3 py-2",children:(0,e.jsx)("div",{className:"flex gap-1 items-center h-4",children:[0,1,2].map(t=>(0,e.jsx)(u.div,{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground",animate:{opacity:[.3,1,.3]},transition:{duration:1.2,repeat:1/0,delay:t*.2}},t))})})]}),(0,e.jsx)("div",{ref:T})]}),(0,e.jsxs)("div",{className:"p-3 border-t border-border shrink-0",children:[(0,e.jsxs)("div",{className:"flex gap-2 items-end bg-card border border-border rounded-xl p-2 focus-within:border-indigo-500/50 transition-colors",children:[(0,e.jsx)("textarea",{ref:N,value:c,onChange:t=>b(t.target.value),onKeyDown:Q,placeholder:m?"Demandez \xE0 l'IA...":"Connexion...",disabled:!m,rows:1,className:"flex-1 bg-transparent text-xs text-foreground placeholder:text-muted-foreground resize-none outline-none leading-relaxed min-h-[20px] max-h-[80px]"}),(0,e.jsx)("button",{onClick:R,disabled:!c.trim()||!m,className:"w-7 h-7 rounded-lg bg-indigo-500 hover:bg-indigo-600 flex items-center justify-center shrink-0 disabled:opacity-40 transition-all",children:H?(0,e.jsx)(A,{className:"w-3.5 h-3.5 text-white animate-spin"}):(0,e.jsx)(L,{className:"w-3.5 h-3.5 text-white"})})]}),(0,e.jsx)("p",{className:"text-[10px] text-muted-foreground text-center mt-1.5",children:"Entr\xE9e pour envoyer \xB7 Shift+Entr\xE9e pour saut de ligne"})]})]})}export{W as a};
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.