1import{r as l,j as e,u as ve,c as Ue}from"./index-L9AYrVUw.js";import{A as qe}from"./FloatingTopMenu-CIhwk2RR.js";import{S as Je}from"./StudioChatPanel-CTMIdRq6.js";import{m as ye}from"./ArrowsClockwise.es-CX8V1pij.js";import{s as Ke}from"./CalendarCheck.es-B4cslHqB.js";import{s as Xe}from"./CheckCircle.es-PkF6a2W-.js";import{p as Ze,u as he,aE as ae,a as re,aX as Qe,b as et}from"./PlanAccessModal-P_W2GThH.js";import{s as tt}from"./Copy.es-BkRzHo-W.js";import{l as nt}from"./Trash.es-D2Zs5Rpt.js";import{k as $e,h as Re,m as Se}from"./App-DyVHSnY3.js";import{I as be}from"./Image.es-BLTC_PgL.js";import{c as ot}from"./TrendUp.es-DExjYOFc.js";import{l as je}from"./UploadSimple.es-BDJIa312.js";import{s as Te}from"./VideoCamera.es-CCLoNiT_.js";import{m as Ie}from"./WarningCircle.es-CHfqKWRY.js";import{E as it,B as st,b as at}from"./BatchGroupRow-CbfhUn1q.js";import{C as rt}from"./CampaignWizardModal-5H-1ksX3.js";import{m as lt}from"./MagicWand.es-CAihBnXI.js";import{m as dt}from"./Minus.es-Dn8w88Wl.js";import{n as De}from"./Plus.es-BeVefyFz.js";import{s as Me}from"./productFunnel-DiJFcMU2.js";import{b as ct,c as pt}from"./antiStock-CfefI4TX.js";import{M as mt}from"./modal-close-button-BhLoO4jQ.js";import{M as ut}from"./index-BFnbqzYg.js";import{r as ht}from"./index-C7qqVJo6.js";import{s as gt}from"./CaretDoubleLeft.es-C52M4NEJ.js";import{loadStoreContext as xt}from"./KnowledgeBasePage-DJT9Fkps.js";import{g as ft}from"./historyKey-GcKgTVWl.js";import{d as yt}from"./seasonalDateDetection-D803in5N.js";import"./locale-Cctu0V3Y.js";import"./SnewLogo-Cg53XTnQ.js";import"./productHeight-D88Bzh8q.js";import"./ArrowCounterClockwise.es-B3mF2JQM.js";import"./ArrowUp.es-sg_sCqx1.js";import"./FrameCorners.es-DEsKEYQB.js";import"./Package.es-CyLjTX4J.js";import"./Palette.es-Dd5ZEM4v.js";import"./ThumbsDown.es-CGNKh3eu.js";import"./ThumbsUp.es-D_c5yKbs.js";import"./ChatSubmitButton-Bm0hHp2J.js";import"./SearchInput-h5gAN-Be.js";import"./round-icon-button-DJH-lznp.js";import"./pill-dropdown-menu-CmrSXir-.js";import"./aspectRatios-DDqw6bsx.js";import"./ThumbCard-ZN7h4mu8.js";import"./ProductPickerModal-DZV-fDl_.js";import"./firstAsset-DWUwvZpm.js";import"./tabs-CmDZA0dx.js";import"./index-BKpKuXmL.js";import"./index-Eo00qZvG.js";import"./ImageSquare.es-Ckk4CjAE.js";import"./overImage-BfLII5AZ.js";import"./boardChromeCopy-DnmOEM-I.js";import"./welcomeBoard-4xJYHWeA.js";import"./index-p7aFGi8o.js";import"./dissolve-CQo8GAUH.js";import"./ChatCircle.es-ys8V5LKI.js";import"./FloppyDisk.es-DCGe340Q.js";import"./Globe.es-5iBT42E4.js";import"./Target.es-Ds7XP-fd.js";import"./hydrateStoreContext-CnRDd9GD.js";const bt=new Map([["bold",l.createElement(l.Fragment,null,l.createElement("path",{d:"M244,128v64a12,12,0,0,1-12,12H168a12,12,0,0,1,0-24h35l-67-67-31.51,31.52a12,12,0,0,1-17,0l-72-72a12,12,0,0,1,17-17L96,119l31.51-31.52a12,12,0,0,1,17,0L220,163V128a12,12,0,0,1,24,0Z"}))],["duotone",l.createElement(l.Fragment,null,l.createElement("path",{d:"M232,128v64H168Z",opacity:"0.2"}),l.createElement("path",{d:"M235.06,120.61a8,8,0,0,0-8.72,1.73L200,148.69,141.66,90.34a8,8,0,0,0-11.32,0L96,124.69,29.66,58.34A8,8,0,0,0,18.34,69.66l72,72a8,8,0,0,0,11.32,0L136,107.31,188.69,160l-26.35,26.34A8,8,0,0,0,168,200h64a8,8,0,0,0,8-8V128A8,8,0,0,0,235.06,120.61ZM224,184H187.31L224,147.31Z"}))],["fill",l.createElement(l.Fragment,null,l.createElement("path",{d:"M240,128v64a8,8,0,0,1-8,8H168a8,8,0,0,1-5.66-13.66L188.69,160,136,107.31l-34.34,34.35a8,8,0,0,1-11.32,0l-72-72A8,8,0,0,1,29.66,58.34L96,124.69l34.34-34.35a8,8,0,0,1,11.32,0L200,148.69l26.34-26.35A8,8,0,0,1,240,128Z"}))],["light",l.createElement(l.Fragment,null,l.createElement("path",{d:"M238,128v64a6,6,0,0,1-6,6H168a6,6,0,0,1,0-12h49.52L136,104.49l-35.76,35.75a6,6,0,0,1-8.48,0l-72-72a6,6,0,0,1,8.48-8.48L96,127.51l35.76-35.75a6,6,0,0,1,8.48,0L226,177.52V128a6,6,0,0,1,12,0Z"}))],["regular",l.createElement(l.Fragment,null,l.createElement("path",{d:"M240,128v64a8,8,0,0,1-8,8H168a8,8,0,0,1,0-16h44.69L136,107.31l-34.34,34.35a8,8,0,0,1-11.32,0l-72-72A8,8,0,0,1,29.66,58.34L96,124.69l34.34-34.35a8,8,0,0,1,11.32,0L224,172.69V128a8,8,0,0,1,16,0Z"}))],["thin",l.createElement(l.Fragment,null,l.createElement("path",{d:"M236,128v64a4,4,0,0,1-4,4H168a4,4,0,0,1,0-8h54.34L136,101.66,98.83,138.83a4,4,0,0,1-5.66,0l-72-72a4,4,0,0,1,5.66-5.66L96,130.34l37.17-37.17a4,4,0,0,1,5.66,0L228,182.34V128a4,4,0,0,1,8,0Z"}
1))]]),We=l.forwardRef((t,n)=>l.createElement(Ze,{ref:n,...t,weights:bt}));We.displayName="TrendDownIcon";const jt=We,xe=t=>{const n=t.toLowerCase();return n.includes("carrossel")||n.includes("carousel")?"carousel":n.includes("reel")||n.includes("vÃdeo")||n.includes("video")||n.includes("transição")||n.includes("transições")?"video":n.includes("story")||n.includes("stories")?"story":n.includes("copy")||n.includes("legenda")||n.includes("texto")?"copy":"image"},Fe=t=>{var x,i,g,A;if(!t||typeof t!="string")return[];try{const p=JSON.parse(((x=t.match(/\{[\s\S]*\}/))==null?void 0:x[0])??"");if(p.type==="calendar"&&((i=p.data)!=null&&i.days))return p.data.days.flatMap((f,d)=>{const r=xe(`${f.content??""} ${f.label??""}`),m=Array.isArray(f.channels)?f.channels[0]:f.channels,u=typeof m=="string"?m:m&&typeof m=="object"?Object.keys(m).join(", "):"instagram";return[{id:`task-${d}-0`,day:d+1,date:f.date,type:r,canal:u,content:f.content??"",copy:f.copy??"",theme:f.label??"",status:"pending"}]})}catch{}const n=[],o=t.split(` 2`);let c=-1,a={};for(let p=0;p<o.length;p++){const f=o[p];if(!f.includes("|"))continue;const d=f.split("|").map(y=>y.trim()).filter(Boolean),r=d.map(y=>y.toLowerCase()),m=r.some(y=>y.includes("dia")||y.includes("day")||y==="#"||y==="nº"),u=r.some(y=>y.includes("tema")||y.includes("conteúdo")||y.includes("conteudo")||y.includes("assunto")||y.includes("tÃtulo"));if(m&&u){c=p,d.forEach((y,S)=>{const h=y.toLowerCase();h.includes("dia")||h==="#"||h==="nº"||h==="day"?a.day=S:h.includes("data")||h.includes("date")?a.date=S:h.includes("tema")||h.includes("conteúdo")||h.includes("conteudo")||h.includes("assunto")||h.includes("tÃtulo")?a.theme=S:h.includes("canal")||h.includes("channel")||h.includes("rede")||h.includes("plataforma")?a.canal=S:h.includes("copy")||h.includes("legenda")||h.includes("caption")?a.copy=S:(h.includes("imagem")||h.includes("visual")||h.includes("image")||h.includes("tipo")||h.includes("formato")||h.includes("descrição"))&&(a.image=S)});break}}if(c>=0)for(let p=c+1;p<o.length;p++){const f=o[p];if(!f.includes("|")||/^\s*\|[\s\-|]+\|\s*$/.test(f))continue;const d=f.split("|").map(U=>U.trim()).filter(Boolean);if(d.length<2)continue;const r=a.day!==void 0?d[a.day]??"":"",m=parseInt(r)||n.length+1,u=a.date!==void 0?d[a.date]??"":void 0,y=a.theme!==void 0?d[a.theme]??"":"",S=a.canal!==void 0?d[a.canal]??"":"instagram",h=a.copy!==void 0?d[a.copy]??"":"",D=a.image!==void 0?d[a.image]??"":"";if(!y&&!h&&!D)continue;const B=`${y} ${D}`.trim(),N=xe(`${B} ${S}`);n.push({id:`task-${m}-${n.length}`,day:m,date:u,type:N,canal:((g=S.toLowerCase().split(",")[0])==null?void 0:g.trim())||"instagram",content:B||y,copy:h.replace(/^[""]|[""]$/g,""),theme:y,status:"pending"})}if(n.length===0){let p=0;for(const f of o){const d=f.match(/\|\s*(\d+)\s*\|/)??f.match(/^Dia\s+(\d+)/i);d&&(p=parseInt(d[1]));const r=f.match(/(Carrossel|Reel|Foto|Story|VÃdeo|Post|Video)[:\s]/i),m=f.match(/Instagram|TikTok|Facebook|LinkedIn|WhatsApp/i),u=f.match(/"([^"]+)"/);r&&p>0&&n.push({id:`task-${p}-${n.length}`,day:p,type:xe(r[1]),canal:((A=m==null?void 0:m[0])==null?void 0:A.toLowerCase())??"instagram",content:f.replace(/\|/g,"").trim(),copy:(u==null?void 0:u[1])??"",status:"pending"})}}return n.slice(0,30)},vt={image:"",carousel:"",video:"",copy:"",story:""},St={image:"Imagem",carousel:"Carrossel",video:"VÃdeo",copy:"Copy",story:"Story"};function Ft({tasks:t,onExecuteTask:n,onExecuteAll:o,onNavigateToStudio:c}){const[a,x]=l.useState(new Set(t.map(p=>p.id))),i=t.filter(p=>p.status==="pending").length,g=t.filter(p=>p.status==="done"||p.status==="approved").length,A=t.length>0?Math.round(g/t.length*100):0;return e.jsxs("div",{style:{marginTop:24},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:16},children:[e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:14,fontWeight:700,color:"#1A1A1A",margin:"0 0 3px"},children:"Plano de execução"}),e.jsxs("p",{style:{fontSize:11,color:"#999",margin:0},children:[i," assets para gerar · ",g," prontos"]})]}),e.jsxs("div",{style:{width:120},children:[e.jsx("div",{style:{height:4,borderRadius:99,background:"#E8E6E0"},children:e.jsx("div",{style:{height:"100%",borderRadius:99,background:"#1A1A1A",width:`${A}%`,transition:"width 0.4s ease"}})}
2),e.jsxs("p",{style:{fontSize:10,color:"#AAA",margin:"4px 0 0",textAlign:"right"},children:[A,"%"]})]})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6,maxHeight:360,overflowY:"auto",marginBottom:16},children:t.map(p=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",borderRadius:10,background:p.status==="done"?"#F0FDF4":p.status==="approved"?"#EFF6FF":p.status==="generating"?"#FFFBEB":"#FAFAF8",border:`1px solid ${p.status==="done"?"#BBF7D0":p.status==="approved"?"#BFDBFE":p.status==="generating"?"#FDE68A":"#EEECEA"}`,transition:"all 0.2s"},children:[e.jsx("input",{type:"checkbox",checked:a.has(p.id),onChange:f=>{const d=new Set(a);f.target.checked?d.add(p.id):d.delete(p.id),x(d)},style:{flexShrink:0,cursor:"pointer",accentColor:"#1A1A1A"}}),e.jsxs("span",{style:{fontSize:10,fontWeight:700,color:"#AAA",flexShrink:0,minWidth:28},children:["D",p.day]}),e.jsx("span",{style:{fontSize:14,flexShrink:0},children:vt[p.type]}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("p",{style:{fontSize:12,fontWeight:500,color:"#1A1A1A",margin:"0 0 2px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[St[p.type]," · ",typeof p.canal=="string"?p.canal:Object.keys(p.canal??{}).join(", "),p.theme?` · ${typeof p.theme=="string"?p.theme:""}`:""]}),e.jsx("p",{style:{fontSize:10,color:"#888",margin:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:p.copy||p.content})]}),p.status==="pending"&&e.jsx("button",{className:"snew-main-action",onClick:()=>n(p),style:{padding:"4px 10px",borderRadius:6,border:"none",fontSize:10,fontWeight:600,cursor:"pointer",fontFamily:"inherit",flexShrink:0,whiteSpace:"nowrap"},children:"Gerar"}),p.status==="generating"&&e.jsx("span",{style:{fontSize:10,color:"#D97706",flexShrink:0,fontWeight:600},children:"Gerando..."}),p.status==="done"&&e.jsx("button",{onClick:()=>c(p),style:{padding:"4px 8px",borderRadius:6,border:"1px solid #BBF7D0",background:"#F0FDF4",fontSize:10,color:"#059669",cursor:"pointer",fontFamily:"inherit",flexShrink:0},children:"Ver"})]},p.id))}),e.jsxs("button",{onClick:()=>o(a),disabled:a.size===0,style:{width:"100%",padding:"11px 0",borderRadius:10,border:"none",background:a.size>0?"#1A1A1A":"#E0DDD8",color:a.size>0?"#FFF":"#AAA",fontSize:13,fontWeight:700,cursor:a.size>0?"pointer":"default",fontFamily:"inherit",display:"flex",alignItems:"center",justifyContent:"center",gap:8,transition:"all 0.15s"},children:["Gerar ",a.size," assets selecionados"]})]})}function V({value:t,onChange:n,multiline:o=!1,placeholder:c="",style:a,as:x="p"}){const i=l.useRef(null),[g,A]=l.useState(!1),[p,f]=l.useState(!1);l.useEffect(()=>{!g&&i.current&&i.current.innerText!==t&&(i.current.innerText=t)},[t,g]);const d={outline:"none",borderRadius:6,padding:"2px 6px",margin:"-2px -6px",cursor:"text",transition:"background 0.12s, box-shadow 0.12s",background:g?"rgba(37, 99, 235, 0.06)":p?"rgba(0, 0, 0, 0.03)":"transparent",boxShadow:g?"inset 0 0 0 1px rgba(37, 99, 235, 0.4)":"none",whiteSpace:o?"pre-wrap":"normal",minHeight:"1em",...a};return e.jsx(x,{ref:i,contentEditable:!0,suppressContentEditableWarning:!0,"data-placeholder":c,onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),onFocus:()=>A(!0),onBlur:r=>{A(!1);const m=r.currentTarget.innerText.trim();m!==t&&n(m)},onKeyDown:r=>{!o&&r.key==="Enter"&&(r.preventDefault(),r.currentTarget.blur()),r.key==="Escape"&&(r.currentTarget.innerText=t,r.currentTarget.blur())},style:d,children:t})}function At(t,n){const o=[];return n&&o.push(n),t.theme&&t.theme!==n&&o.push(t.theme),t.content&&o.push(t.content),o.filter(Boolean).join(" â ")}const Et=[{title:"Capa principal",suffix:"imagem hero impactante, foco no produto",type:"image"},{title:"Lifestyle",suffix:"cena lifestyle natural com modelo usando o produto",type:"image"},{title:"Detalhe macro",suffix:"close-up do produto com textura e iluminação suave",type:"image"},{title:"Story vertical",suffix:"composição vertical 9:16 com headline visual",type:"story"},{title:"Carrossel slide 1",suffix:"primeira tela do carrossel com hook visual",type:"carousel"},{title:"Anúncio performance",suffix:"anúncio com produto em destaque e CTA visual",type:"image"}],fe={image:{w:240,h:320},carousel:{w:240,h:320},story:{w:200,h:360},video:{w:240,h:320},copy:{w:240,h:200}};function kt(t){const i=fe.image.w,g=Array(4).fill(60);return t.map((A,p)=>{const f=p%4,d=fe[A.type]??fe.image,r=60+f*(i+36)+(i-d.w)/2,m=g[f];return g[f]=m+d.h+44,{...A,x:r,y:m,w:d.w,h:d.h}})}function wt(t){const n=t||"Campanha";return Et.map((o,c)=>
2({id:`fallback-${c}`,title:o.title,prompt:`${n} â ${o.suffix}`,channel:"instagram",type:o.type}))}const zt={image:"1:1",carousel:"1:1",story:"9:16",video:"9:16",copy:"1:1"};function Ct({node:t,state:n,onGenerate:o,onOpenInStudio:c}){const[a,x]=l.useState(!1),i=n.status==="loading",g=n.status==="ready"&&!!n.imageUrl,A=n.status==="error";return e.jsxs("div",{"data-node":!0,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),style:{width:t.w,height:t.h,background:"#FFFFFF",border:`1.5px solid ${a?"#1A1A1A":"#EBEBEB"}`,borderRadius:14,overflow:"hidden",display:"flex",flexDirection:"column",boxShadow:a?"0 8px 28px rgba(0,0,0,0.12)":"0 2px 8px rgba(0,0,0,0.06)",transform:a?"translateY(-2px)":"none",transition:"border-color .12s, box-shadow .12s, transform .12s",cursor:"default"},children:[e.jsxs("div",{style:{position:"relative",width:"100%",flex:"0 0 60%",background:g?"#000":"repeating-linear-gradient(45deg, #F5F4F0, #F5F4F0 8px, #EFEEE9 8px, #EFEEE9 16px)",display:"flex",alignItems:"center",justifyContent:"center",borderBottom:"1px solid #EEEDE9",overflow:"hidden"},children:[g&&e.jsx("img",{src:n.imageUrl,alt:t.title,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}),!g&&!i&&!A&&e.jsx("div",{style:{width:44,height:44,borderRadius:12,background:"rgba(255,255,255,0.85)",display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(4px)"},children:e.jsx(be,{size:18,style:{color:"#999"}})}),i&&e.jsxs("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:8,background:"rgba(255,255,255,0.7)",backdropFilter:"blur(2px)"},children:[e.jsx(ae,{size:20,className:"animate-spin",style:{color:"#1A1A1A"}}),e.jsx("span",{style:{fontSize:10,color:"#555",fontWeight:500},children:"gerandoâ¦"})]}),A&&e.jsxs("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:6,padding:12,textAlign:"center",background:"rgba(255,240,240,0.92)"},children:[e.jsx(Ie,{size:18,style:{color:"#C0392B"}}),e.jsx("span",{style:{fontSize:10,color:"#812",fontWeight:500,lineHeight:1.3},children:n.error??"Falha ao gerar"})]}),e.jsx("span",{style:{position:"absolute",top:8,left:8,fontSize:9,fontWeight:600,color:"#666",background:"rgba(255,255,255,0.9)",padding:"3px 7px",borderRadius:6,textTransform:"uppercase",letterSpacing:"0.05em"},children:t.type}),g&&e.jsx("button",{onClick:p=>{p.stopPropagation(),c()},title:"Abrir no Studio",style:{position:"absolute",top:8,right:8,width:26,height:26,borderRadius:7,border:"none",background:"rgba(0,0,0,0.55)",color:"#FFF",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(4px)"},children:e.jsx($e,{size:12})})]}),e.jsxs("div",{style:{padding:12,display:"flex",flexDirection:"column",gap:6,flex:1,minHeight:0},children:[e.jsx("p",{style:{fontSize:13,fontWeight:600,color:"#1A1A1A",margin:0,lineHeight:1.3,overflow:"hidden",display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical"},children:t.title}),e.jsx("p",{style:{fontSize:11,color:"#888",margin:0,lineHeight:1.45,overflow:"hidden",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",flex:1},children:t.prompt}),e.jsx("button",{onClick:p=>{p.stopPropagation(),o()},disabled:i,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"7px 10px",borderRadius:7,background:i?"#EEE":a?"var(--snew-action-primary)":"#FAFAF8",border:`1px solid ${a?"var(--snew-action-primary)":"#E8E8E4"}`,color:i?"#999":a?"var(--snew-action-primary-foreground)":"#1A1A1A",fontSize:12,fontWeight:500,cursor:i?"wait":"pointer",fontFamily:"inherit",transition:"background 0.12s, color 0.12s, border-color 0.12s"},children:i?e.jsxs(e.Fragment,{children:[e.jsx(ae,{size:11,className:"animate-spin"})," Gerandoâ¦"]}):g?e.jsxs(e.Fragment,{children:[e.jsx(ye,{size:11})," Regenerar"]}):A?e.jsxs(e.Fragment,{children:[e.jsx(ye,{size:11})," Tentar novamente"]}):e.jsxs(e.Fragment,{children:[e.jsx(lt,{size:11})," Gerar imagem"]})})]})]})}function Tt({artifact:t,theme:n,campaignTasks:o}){const c=ve(),a=l.useRef(null),[x,i]=l.useState({x:40,y:40}),[g,A]=l.useState(1),[p,f]=l.useState(!1),d=l.useRef({x:0,y:0,ox:0,oy:0}),[r,m]=l.useState({}),[u,y]=l.useState(!1),S=l.useMemo(()=>{const F=(o&&o.length>0?o:t?Fe(t):[]).filter($=>$.type!=="copy"),w=n??"",C=F.length===0?wt(w):F.slice(0,16).map(($,R)=>({id:$.id??`task-${R}`,title:$.theme||`Dia ${$.day}`,prompt:At($,w),channel:$.canal||"instagram",type:$.type}));return kt(C)},[t,n,o]),h=l.useCallback(()=>
2{if(!S.length||!a.current)return;const b=Math.min(...S.map(I=>I.x)),F=Math.min(...S.map(I=>I.y)),w=Math.max(...S.map(I=>I.x+I.w)),C=Math.max(...S.map(I=>I.y+I.h)),{offsetWidth:$,offsetHeight:R}=a.current,_=80,H=Math.min(1,Math.min(($-_)/(w-b),(R-_)/(C-F)));A(H),i({x:($-(w-b)*H)/2-b*H,y:(R-(C-F)*H)/2-F*H})},[S]);l.useEffect(()=>{const b=setTimeout(h,50);return()=>clearTimeout(b)},[h]);const D=b=>{b.target.closest("[data-node]")||(f(!0),d.current={x:b.clientX,y:b.clientY,ox:x.x,oy:x.y})},B=l.useCallback(b=>{p&&i({x:d.current.ox+b.clientX-d.current.x,y:d.current.oy+b.clientY-d.current.y})},[p]),N=()=>f(!1),U=l.useCallback(b=>{if(!a.current)return;b.preventDefault();const F=b.deltaY<0?1.08:.92,w=a.current.getBoundingClientRect(),C=b.clientX-w.left,$=b.clientY-w.top;A(R=>{const _=Math.min(3,Math.max(.2,R*F));return i(H=>({x:C-(C-H.x)*(_/R),y:$-($-H.y)*(_/R)})),_})},[]);l.useEffect(()=>{const b=F=>{const w=F.target;w&&(w.tagName==="INPUT"||w.tagName==="TEXTAREA"||w.isContentEditable)||(F.key==="+"||F.key==="="?A(C=>Math.min(3,C*1.15)):F.key==="-"||F.key==="_"?A(C=>Math.max(.2,C*.87)):F.key==="0"&&h())};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[h]);const q=l.useCallback(async b=>{m(F=>({...F,[b.id]:{status:"loading"}}));try{const F=zt[b.type]??"1:1",w=ct(["IMPORTANT: NO text, typography, watermark, captions or letters of any kind.",b.prompt,"Credible editorial product photography. Use controlled off-camera directional light and a continuous, materially resolved background."].join(" ")),{data:C,error:$}=await Me.functions.invoke("gemini-generate",{body:{prompt:w,model:"gemini-2.5-flash-image",aspectRatio:F,negativePrompt:pt.join(", ")}});if($)throw $;const R=(C==null?void 0:C.imageUrl)||(C==null?void 0:C.image_url)||(C==null?void 0:C.url)||(C!=null&&C.image?C.image.startsWith("data:")?C.image:`data:image/png;base64,${C.image}`:void 0);if(!R)throw new Error("Sem imagem na resposta");m(_=>({..._,[b.id]:{status:"ready",imageUrl:R}}))}catch(F){const w=(F==null?void 0:F.message)??"Falha ao gerar";console.error("BoardPlaceholders generate error",F),m(C=>({...C,[b.id]:{status:"error",error:w}})),he.error(`Erro ao gerar "${b.title}": ${w}`)}},[]),ie=b=>{q(b)},le=b=>{c("/snew-studio",{state:{autoPrompt:b.prompt,openBoard:!1,_ts:Date.now()}})},P=async()=>{if(!S.length||u)return;y(!0);const b=S.filter($=>{var R;return((R=r[$.id])==null?void 0:R.status)!=="ready"}),F=3;let w=0;const C=Array.from({length:Math.min(F,b.length)},async()=>{for(;w<b.length;){const $=w++,R=b[$];R&&await q(R)}});await Promise.all(C),y(!1),he.success("Geração concluÃda")},Q={width:32,height:32,borderRadius:8,border:"1px solid #E8E8E8",background:"rgba(255,255,255,0.95)",fontSize:13,color:"#555",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",fontFamily:"inherit",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"};return e.jsxs("div",{style:{width:"100%",height:"100%",minHeight:500,position:"relative",display:"flex",flexDirection:"column",background:"#F0EFEC",borderRadius:14,overflow:"hidden",border:"1px solid #EAE9E5"},children:[e.jsxs("div",{style:{position:"absolute",top:12,left:12,zIndex:5,display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderRadius:10,background:"rgba(255,255,255,0.95)",border:"1px solid #EAE9E5",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",backdropFilter:"blur(8px)"},children:[e.jsx("span",{style:{fontSize:10,fontWeight:600,color:"#999",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Board"}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{width:3,height:3,borderRadius:99,background:"#CCC"}}),e.jsx("span",{style:{fontSize:12,fontWeight:500,color:"#1A1A1A"},children:n})]}),e.jsx("span",{style:{width:3,height:3,borderRadius:99,background:"#CCC"}}),e.jsxs("span",{style:{fontSize:11,color:"#999"},children:[S.length," placeholder",S.length===1?"":"s"]})]}),S.length>0&&e.jsxs("button",{className:"snew-main-action",onClick:P,disabled:u,style:{position:"absolute",top:12,right:56,zIndex:5,display:"flex",alignItems:"center",gap:6,padding:"8px 14px",borderRadius:10,border:"none",fontSize:12,fontWeight:500,cursor:u?"wait":"pointer",fontFamily:"inherit",boxShadow:"0 2px 8px rgba(0,0,0,0.16)",opacity:u?.85:1},children:[u?e.jsx(ae,{size:12,className:"animate-spin"}):e.jsx(re,{size:12}),u?"Gerandoâ¦":"Gerar todas"]}),e.jsxs("div",{ref:a,onMouseDown:D,onMouseMove:B,onMouseUp:N,onMouseLeave:N,onWheel:U,style:{position:"relative",flex:1,overflow:"hidden",cursor:p?"grabbing":"grab",userSelect:"none"},children:[e.jsxs("svg",{width:"100%",height:"100%",style:{position:"absolute",inset:0,pointerEvents:"none"},children:[e.jsx("defs",{children:e.jsx("pattern",{id:"board-placeholder-dots",width:20*g,height:20*g,x:x.x,y:x.y,patternUnits:"userSpaceOnUse",children:e.jsx("circle",{cx:1,cy:1,r:Math.max(.7,g*.85),fill:"rgba(0,0,0,0.10)"})})}),e.jsx("rect",{width:"100%",height:"100%",fill:"url(#board-placeholder-dots)"})]}),e.jsx("div",{style:{position:"absolute",inset:0,transform:`translate(${x.x}px, ${x.y}px) scale(${g})`,transformOrigin:"0 0",willChange:"transform"},children:S.map(b=>e.jsx("div",{style:{position:"absolute",left:b.x,top:b.y},children:e.jsx(Ct,{node:b,state:r[b.id]??{status:"idle"},onGenerate:()=>ie(b),onOpenInStudio:()=>le(b)})},b.id))}),e.jsxs("div",{style:{position:"absolute",bottom:16,right:16,display:"flex",flexDirection:"column",gap:4,zIndex:5},children:[e.jsx("button",{onClick:()=>A(b=>Math.min(3,b*1.2)),style:Q,title:"Zoom in (+)",children:e.jsx(De,{size:14})}),e.jsxs("div",{style:{...Q,cursor:"default",fontSize:10,fontWeight:600},children:[Math.round(g*100),"%"]}),e.jsx("button",{onClick:()=>A(b=>Math.max(.2,b*.83)),style:Q,title:"Zoom out (-)",children:e.jsx(dt,{size:14})}),e.jsx("button",{onClick:h,style:Q,title:"Fit all (0)",children:e.jsx($e,{size:12})})]})]})]})}function $t(t){var o;try{const c=t.match(/\{[\s\S]*\}/);if(c){const a=JSON.parse(c[0]);if(a.type&&a.data)return a}}catch{}const n=t.match(/^#\s+(.+)$/m);return{type:"markdown",title:((o=n==null?void 0:n[1])==null?void 0:o.trim())??"Documento",data:{content:t}}}const se=({label:t,value:n,change:o,trend:c})=>e.jsxs("div",{style:{background:"#FFFFFF",borderRadius:12,padding:"16px 20px",border:"1px solid #EEEDE9",flex:1,minWidth:140},children:[e.jsx("p",{style:{fontSize:11,color:"#999",margin:"0 0 6px",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:600},children:t}),e.jsx("p",{style:{fontSize:22,fontWeight:600,color:"#1A1A1A",margin:"0 0 4px",letterSpacing:"-0.02em"},children:n}),o&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[c==="up"?e.jsx(ot,{size:12,style:{color:"#22C55E"}}):e.jsx(jt,{size:12,style:{color:"#EF4444"}}),e.jsx("span",{style:{fontSize:12,color:c==="up"?"#22C55E":"#EF4444",fontWeight:600},children:o})]})]}),Rt=({labels:t,values:n,accent:o})=>{const c=Math.max(...n,1);return e.jsx("div",{style:{display:"flex",alignItems:"flex-end",gap:6,height:80},children:t.map((a,x)=>e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",gap:4,height:"100%"},children:[e.jsx("div",{style:{flex:1,display:"flex",alignItems:"flex-end",width:"100%"},children:e.jsx("div",{style:{width:"100%",height:`${n[x]/c*100}%`,background:o,borderRadius:"3px 3px 0 0",opacity:.85,minHeight:4,transition:"height 0.5s ease"}})}),e.jsx("span",{style:{fontSize:9,color:"#AAA",fontWeight:500},children:a})]},x))})},It=({data:t,accent:n})=>{var o,c,a,x;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[((o=t.kpis)==null?void 0:o.length)>0&&e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:t.kpis.map((i,g)=>e.jsx(se,{...i},g))}),t.chart&&e.jsxs("div",{style:{background:"#FFFFFF",borderRadius:12,padding:"20px 24px",border:"1px solid #EEEDE9"},children:[e.jsx("p",{style:{fontSize:12,fontWeight:600,color:"#555",margin:"0 0 16px",textTransform:"uppercase",letterSpacing:"0.06em"},children:t.chart.title??"Receita por dia"}),e.jsx(Rt,{labels:t.chart.labels,values:t.chart.values,accent:n})]}),((c=t.topProducts)==null?void 0:c.length)>0&&e.jsxs("div",{style:{background:"#FFFFFF",borderRadius:12,padding:"20px 24px",border:"1px solid #EEEDE9"},children:[e.jsx("p",{style:{fontSize:12,fontWeight:600,color:"#555",margin:"0 0 14px",textTransform:"uppercase",letterSpacing:"0.06em"},children:"Top produtos"}),t.topProducts.map((i,g)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"10px 0",borderBottom:g<t.topProducts.length-1?"1px solid #F5F4F0":"none"},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:8,background:"#F5F4F0",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Re,{size:14,style:{color:"#999"}})}),e.jsxs("div",{style:{flex:1},children:[e.jsx("p",{style:{fontSize:13,fontWeight:500,color:"#1A1A1A",margin:"0 0 2px"},children:i.name}),i.units&&e.jsxs("p",{style:{fontSize:11,color:"#999",margin:0},children:[i.units," unidades"]})]}),e.jsx("p",{style:{fontSize:14,fontWeight:600,color:"#1A1A1A",margin:0},children:i.revenue})]},g))]}),((a=t.alerts)==null?void 0:a.length)>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:t.alerts.map((i,g)=>
2e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"12px 16px",borderRadius:10,background:i.level==="success"?"#F0FDF4":"#FFFBEB",border:`1px solid ${i.level==="success"?"#BBF7D0":"#FDE68A"}`},children:[i.level==="success"?e.jsx(Xe,{size:14,style:{color:"#22C55E",flexShrink:0,marginTop:1}}):e.jsx(Ie,{size:14,style:{color:"#F59E0B",flexShrink:0,marginTop:1}}),e.jsx("p",{style:{fontSize:13,color:"#333",margin:0,lineHeight:1.5},children:i.text})]},g))}),((x=t.actions)==null?void 0:x.length)>0&&e.jsxs("div",{style:{background:"#1A1A1A",borderRadius:12,padding:"20px 24px"},children:[e.jsx("p",{style:{fontSize:11,fontWeight:600,color:"hsl(var(--color-modal-text-dim))",textTransform:"uppercase",letterSpacing:"0.08em",margin:"0 0 12px"},children:"Proximas acoes"}),t.actions.map((i,g)=>e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"flex-start",padding:"8px 0",borderBottom:g<t.actions.length-1?"1px solid rgba(255,255,255,0.08)":"none"},children:[e.jsx("span",{style:{fontSize:12,fontWeight:600,color:n,flexShrink:0,marginTop:1},children:g+1}),e.jsx("p",{style:{fontSize:13,color:"hsl(var(--color-modal-text))",margin:0,lineHeight:1.5},children:i})]},g))]})]})},Dt=({data:t,accent:n})=>{var x;const[o,c]=l.useState(null),a={campaign:n,holiday:"#F59E0B",organic:"#22C55E",default:"#888"};return e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:6},children:(x=t.days)==null?void 0:x.map((i,g)=>{var A;return e.jsxs("button",{onClick:()=>c(i),style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",borderRadius:10,border:`1px solid ${(o==null?void 0:o.date)===i.date?n:"#EEEDE9"}`,background:(o==null?void 0:o.date)===i.date?`${n}12`:"#FFFFFF",cursor:"pointer",fontFamily:"inherit",textAlign:"left",transition:"all 0.12s",width:"100%"},children:[e.jsx("div",{style:{width:4,height:36,borderRadius:99,flexShrink:0,background:a[i.type]??a.default}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("p",{style:{fontSize:12,fontWeight:600,color:"#1A1A1A",margin:"0 0 2px"},children:[(()=>{try{return new Date(i.date+"T12:00:00").toLocaleDateString("pt-BR",{day:"numeric",month:"short"})}catch{return i.date}})()," â ",i.label]}),e.jsx("p",{style:{fontSize:11,color:"#888",margin:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i.content})]}),e.jsx("div",{style:{display:"flex",gap:3,flexShrink:0},children:(A=i.channels)==null?void 0:A.slice(0,3).map(p=>e.jsx("span",{style:{fontSize:9,padding:"2px 4px",borderRadius:4,background:"#F0F0EE",color:"#666",fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em"},children:p.slice(0,2)},p))})]},g)})}),o&&e.jsxs("div",{style:{width:240,flexShrink:0,background:"#FFFFFF",borderRadius:12,padding:"16px 20px",border:"1px solid #EEEDE9",alignSelf:"flex-start"},children:[e.jsx("p",{style:{fontSize:13,fontWeight:600,color:"#1A1A1A",margin:"0 0 4px"},children:o.label}),e.jsx("p",{style:{fontSize:11,color:"#AAA",margin:"0 0 14px"},children:(()=>{try{return new Date(o.date+"T12:00:00").toLocaleDateString("pt-BR",{dateStyle:"long"})}catch{return o.date}})()}),e.jsx("p",{style:{fontSize:12,color:"#555",margin:"0 0 12px",lineHeight:1.6},children:o.content}),o.copy&&e.jsxs("div",{style:{background:"#F7F6F3",borderRadius:8,padding:"10px 12px"},children:[e.jsx("p",{style:{fontSize:10,fontWeight:600,color:"#AAA",textTransform:"uppercase",letterSpacing:"0.06em",margin:"0 0 6px"},children:"Copy sugerida"}),e.jsxs("p",{style:{fontSize:12,color:"#333",margin:0,lineHeight:1.6,fontStyle:"italic"},children:['"',o.copy,'"']})]})]})]})},Mt=({data:t,accent:n,onUpdate:o})=>{var p,f,d;const c=r=>o==null?void 0:o({...t,...r}),a=(r,m,u,y)=>{if(!o)return;const S=[...t[r]??[]];S[m]={...S[m],[u]:y},o({...t,[r]:S})},[x,i]=l.useState({}),g=async(r,m)=>{if(o){i(u=>({...u,[r]:!0}));try{const u=m.channel||"InstagramLogo",y=m.text||m.body||m.headline||"",S=/stories|reel|tiktok/i.test(u)?"9:16":/feed|instagram/i.test(u)?"1:1":/email/i.test(u)?"16:9":"1:1",h=`Imagem editorial premium para ${u} de uma campanha de marketing. Mensagem da campanha: "${t.message||t.objective||""}". Público: ${t.audience||"consumidor brasileiro"}. Copy do post: "${y.slice(0,200)}". Estética: fotografia profissional, iluminação suave, composição limpa, sem texto sobreposto, sem mar
2ca d'água, sem letras na imagem.`,{data:D,error:B}=await Me.functions.invoke("gemini-generate",{body:{prompt:h,aspectRatio:S,model:"google/gemini-2.5-flash-image"}});if(B)throw B;const N=D==null?void 0:D.imageUrl;if(!N)throw new Error((D==null?void 0:D.error)||"Sem imagem retornada");const U=[...t.copies??[]];U[r]={...U[r],imageUrl:N},o({...t,copies:U}),he.success(`Imagem gerada para ${u}`)}catch(u){he.error((u==null?void 0:u.message)||"Falha ao gerar imagem")}finally{i(u=>({...u,[r]:!1}))}}},A=({label:r,children:m})=>e.jsxs("div",{style:{marginTop:28},children:[e.jsx("p",{style:{fontSize:15,fontWeight:600,color:"#1A1A1A",margin:"0 0 10px",letterSpacing:"-0.01em"},children:r}),e.jsx("div",{children:m})]});return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0},children:[t.message&&e.jsx("div",{style:{marginBottom:36},children:e.jsx(V,{as:"h1",multiline:!0,value:t.message,onChange:r=>c({message:r}),style:{fontFamily:'"Instrument Serif", "Cormorant Garamond", "Playfair Display", Georgia, serif',fontSize:38,fontWeight:400,lineHeight:1.18,letterSpacing:"-0.015em",color:"#1A1A1A",margin:0}})}),t.objective&&e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:15,fontWeight:600,color:"#1A1A1A",margin:"0 0 8px",letterSpacing:"-0.01em"},children:"Objetivo"}),e.jsx(V,{as:"p",multiline:!0,value:t.objective,onChange:r=>c({objective:r}),style:{fontSize:14,color:"#444",margin:0,lineHeight:1.7}})]}),t.audience&&e.jsxs("div",{style:{marginTop:28},children:[e.jsx("p",{style:{fontSize:15,fontWeight:600,color:"#1A1A1A",margin:"0 0 8px",letterSpacing:"-0.01em"},children:"Público"}),e.jsx(V,{as:"p",multiline:!0,value:t.audience,onChange:r=>c({audience:r}),style:{fontSize:14,color:"#444",margin:0,lineHeight:1.7}})]}),((p=t.timeline)==null?void 0:p.length)>0&&e.jsx(A,{label:"Timeline",children:t.timeline.map((r,m)=>e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start",padding:"6px 0"},children:[e.jsx(V,{as:"span",value:r.date,onChange:u=>a("timeline",m,"date",u),style:{fontSize:13,fontWeight:600,color:"#1A1A1A",flexShrink:0,minWidth:60}}),e.jsx(V,{as:"p",multiline:!0,value:r.task,onChange:u=>a("timeline",m,"task",u),style:{fontSize:14,color:"#444",margin:0,lineHeight:1.7,flex:1}})]},m))}),((f=t.kpis)==null?void 0:f.length)>0&&e.jsx(A,{label:"KPIs alvo",children:e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:t.kpis.map((r,m)=>e.jsx(V,{as:"p",value:r,onChange:u=>{const y=[...t.kpis];y[m]=u,o==null||o({...t,kpis:y})},style:{fontSize:14,color:"#444",margin:0,lineHeight:1.7}},m))})}),((d=t.copies)==null?void 0:d.length)>0&&e.jsx(A,{label:"Copies por canal",children:t.copies.map((r,m)=>{const u=r.text??[r.headline,r.body,r.cta].filter(Boolean).join(` 3`)??r.subject??"",y=r.text!==void 0?"text":r.body!==void 0?"body":r.headline!==void 0?"headline":"text",S=!!x[m];return e.jsxs("div",{style:{padding:"6px 0",marginBottom:14},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsx("p",{style:{fontSize:13,fontWeight:600,color:"#1A1A1A",margin:0},children:r.channel}),e.jsxs("button",{onClick:()=>g(m,r),disabled:S,style:{display:"flex",alignItems:"center",gap:4,padding:"3px 8px",borderRadius:6,border:"1px solid #E0E0DC",background:"#FFFFFF",fontSize:11,color:"#555",cursor:S?"wait":"pointer",fontFamily:"inherit",opacity:S?.6:1},onMouseEnter:h=>{S||(h.currentTarget.style.borderColor="#1A1A1A")},onMouseLeave:h=>h.currentTarget.style.borderColor="#E0E0DC",children:[S?e.jsx(ae,{size:11,className:"animate-spin"}):e.jsx(re,{size:11}),S?"Gerandoâ¦":r.imageUrl?"Regerar imagem":"Gerar imagem"]})]}),e.jsx(V,{as:"p",multiline:!0,value:u||"",onChange:h=>a("copies",m,y,h),style:{fontSize:14,color:"#444",margin:0,lineHeight:1.7}}),r.imageUrl&&e.jsx("div",{style:{marginTop:10},children:e.jsx("img",{src:r.imageUrl,alt:`Imagem para ${r.channel}`,style:{maxWidth:360,width:"100%",height:"auto",borderRadius:8,border:"1px solid #EEEDE9",display:"block"}})})]},m)})}),t.budget&&e.jsxs("div",{style:{marginTop:28,display:"flex",alignItems:"baseline",gap:12},children:[e.jsx("p",{style:{fontSize:15,fontWeight:600,color:"#1A1A1A",margin:0,letterSpacing:"-0.01em"},children:"Budget"}),e.jsx("span",{style:{fontSize:14,color:"#444"},children:t.budget})]})]})},Ae=({size:t=28})=>e.jsx("div",{style:{width:t,height:t,borderRadius:"50%",background:"linear-gradient(135deg, #833AB4, #E1306C, #F77737)",flexShrink:0}}),Wt=({headline:t,body:n,cta:o})=>e.jsxs("div",{style:{width:"100%",background:"#FFF",borderRadius:12,border:"1px solid #EEEDE9",overflow:"hidden",fontSize:13},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px"},children:[e.jsx(Ae,{size:24}),e.jsxs("div",{style:{flex:1},children:[e.jsx("p",{style:{margin:0,fontSize:12,fontWeight:600,color:"#1A1A1A"},children:"sua_loja"}),e.jsx("p",{style:{margin:0,fontSize:9,color:"#999"},children:"Patrocinado"})]}),e.jsx("span",{style:{color:"#999",fontSize:14},children:"···"})]}),e.jsx("div",{style:{width:"100%",aspectRatio:"1/1",background:"#F5F4F0",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("span",{style:{fontSize:28,opacity:.2}})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",padding:"8px 12px"},children:[e.jsx("div",{style:{display:"flex",gap:12},children:["","",""].map((c,a)=>e.jsx("span",{style:{fontSize:16,cursor:"pointer"},children:c},a))}),e.jsx("span",{style:{fontSize:16}})]}),e.jsxs("div",{style:{padding:"0 12px 12px"},children:[t&&e.jsxs("p",{style:{margin:"0 0 4px",fontSize:12,lineHeight:1.5},children:[e.jsx("strong",{children:"sua_loja"})," ",t]}),n&&e.jsx("p",{style:{margin:0,fontSize:12,color:"#555",lineHeight:1.5},children:n}),o&&e.jsx("p",{style:{margin:"6px 0 0",fontSize:11,fontWeight:600,color:"#2563EB"},children:o})]})]}),Lt=({headline:t,body:n})=>e.jsxs("div",{style:{width:180,height:320,borderRadius:16,background:"linear-gradient(180deg, #1A1A1A 0%, #333 100%)",position:"relative",overflow:"hidden",flexShrink:0},children:[e.jsx("div",{style:{display:"flex",gap:3,padding:"10px 10px 0"},children:[1,.3,.3].map((o,c)=>e.jsx("div",{style:{flex:1,height:2,borderRadius:1,background:`rgba(255,255,255,${o})`}},c))}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"8px 10px"},children:[e.jsx(Ae,{size:20}
3),e.jsx("span",{style:{fontSize:10,color:"#FFF",fontWeight:500},children:"sua_loja"})]}),e.jsxs("div",{style:{position:"absolute",bottom:60,left:14,right:14},children:[t&&e.jsx("p",{style:{fontSize:14,fontWeight:700,color:"#FFF",margin:"0 0 4px",textShadow:"0 1px 4px rgba(0,0,0,0.5)"},children:t}),n&&e.jsx("p",{style:{fontSize:10,color:"hsl(var(--color-modal-text))",margin:0,lineHeight:1.4},children:n})]}),e.jsx("div",{style:{position:"absolute",bottom:16,left:0,right:0,textAlign:"center"},children:e.jsx("span",{style:{fontSize:10,color:"#FFF",fontWeight:500},children:"â Ver mais"})})]}),Bt=({body:t})=>e.jsxs("div",{style:{width:"100%",borderRadius:12,overflow:"hidden",border:"1px solid #EEEDE9"},children:[e.jsxs("div",{style:{background:"#075E54",padding:"10px 12px",display:"flex",alignItems:"center",gap:8},children:[e.jsx(Ae,{size:24}),e.jsxs("div",{children:[e.jsx("p",{style:{margin:0,fontSize:12,fontWeight:600,color:"#FFF"},children:"Sua Loja"}),e.jsx("p",{style:{margin:0,fontSize:9,color:"hsl(var(--color-modal-text-dim))"},children:"online"})]})]}),e.jsx("div",{style:{background:"#ECE5DD",padding:"16px 12px",minHeight:80},children:e.jsxs("div",{style:{background:"#DCF8C6",borderRadius:"0 10px 10px 10px",padding:"8px 10px",maxWidth:"85%",position:"relative"},children:[t&&e.jsx("p",{style:{margin:0,fontSize:12,color:"#111",lineHeight:1.5},children:t}),e.jsx("span",{style:{fontSize:9,color:"#999",position:"absolute",bottom:2,right:8},children:"09:41 "})]})})]}),Pt=({subject:t,headline:n,body:o,cta:c})=>e.jsxs("div",{style:{width:"100%",borderRadius:12,overflow:"hidden",border:"1px solid #EEEDE9",background:"#FFF"},children:[e.jsxs("div",{style:{padding:"10px 14px",borderBottom:"1px solid #EEEDE9"},children:[e.jsx("p",{style:{margin:0,fontSize:10,color:"#999"},children:"De: Sua Loja <[email protected]>"}),e.jsx("p",{style:{margin:"4px 0 0",fontSize:12,fontWeight:600,color:"#1A1A1A"},children:t??n})]}),e.jsxs("div",{style:{padding:"16px 14px"},children:[n&&e.jsx("p",{style:{margin:"0 0 8px",fontSize:16,fontWeight:700,color:"#1A1A1A"},children:n}),o&&e.jsx("p",{style:{margin:"0 0 12px",fontSize:12,color:"#555",lineHeight:1.6},children:o}),c&&e.jsx("div",{style:{display:"inline-block",padding:"8px 20px",borderRadius:6,background:"#1A1A1A",color:"#FFF",fontSize:12,fontWeight:600},children:c})]})]}),Ot=({headline:t,body:n})=>e.jsxs("div",{style:{width:180,height:320,borderRadius:16,background:"#000",position:"relative",overflow:"hidden",flexShrink:0},children:[e.jsx("div",{style:{position:"absolute",inset:0,background:"linear-gradient(0deg, rgba(0,0,0,0.7) 0%, transparent 50%)"}}),e.jsx("div",{style:{position:"absolute",right:10,top:"40%",display:"flex",flexDirection:"column",gap:14,alignItems:"center"},children:[{i:"",l:"12.4K"},{i:"",l:"843"},{i:"",l:"2.1K"}].map((o,c)=>e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("p",{style:{margin:0,fontSize:16,color:"#FFF"},children:o.i}),e.jsx("p",{style:{margin:0,fontSize:8,color:"hsl(var(--color-modal-text-dim))"},children:o.l})]},c))}),e.jsxs("div",{style:{position:"absolute",bottom:32,left:10,right:40},children:[e.jsx("p",{style:{margin:"0 0 4px",fontSize:11,fontWeight:700,color:"#FFF"},children:"@sualoja"}),t&&e.jsx("p",{style:{margin:"0 0 2px",fontSize:11,fontWeight:600,color:"#FFF"},children:t}),n&&e.jsxs("p",{style:{margin:0,fontSize:9,color:"hsl(var(--color-modal-text))",lineHeight:1.3},children:[n.slice(0,80),n.length>80?"â¦":""]})]}),e.jsxs("div",{style:{position:"absolute",bottom:10,left:10,display:"flex",alignItems:"center",gap:4},children:[e.jsx("span",{style:{fontSize:10}}),e.jsx("span",{style:{fontSize:8,color:"hsl(var(--color-modal-text-dim))"},children:"Som original â sua_loja"})]})]}),Nt=t=>{const n=(t.channel??"").toLowerCase();return n.includes("feed")||n.includes("instagram f")?e.jsx(Wt,{headline:t.headline,body:t.body,cta:t.cta}):n.includes("stor")?e.jsx(Lt,{headline:t.headline,body:t.body}):n.includes("whats")?e.jsx(Bt,{body:t.body}):n.includes("email")?e.jsx(Pt,{subject:t.subject,headline:t.headline,body:t.body,cta:t.cta}):n.includes("tiktok")?e.jsx(Ot,{headline:t.hook??t.headline,body:t.body}):null},Ht=({open:t,onClose:n,mode:o,channel:c})=>t?e.jsx("div",{style:{position:"fixed",inset:0,zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.5)",backdropFilter:"blur(4px)"},onClick:n,children:e.jsxs("div",{onClick:a=>a.stopPropagation(),style:{width:"90%",maxWidth:720,maxHeight:"85vh",background:"#FFF",borderRadius:16,overflow:"hidden",boxShadow:"0 20px 60px rgba(0,0,0,0.3)",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 20px",borderBottom:"1px solid #EEEDE9"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[o==="image"?e.jsx(be,{size:16,style:{color:"#555"}}):e.jsx(Te,{size:16,style:{color:"#555"}}),e.jsxs("span",{style:{fontSize:14,fontWeight:600,color:"#1A1A1A"},children:[o==="image"?"Gerar Imagem":"Gerar VÃdeo"," â ",c]})]}),e.jsx(mt,{onClick:n})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:32,gap:20,minHeight:400,background:"#F7F6F3"},children:[e.jsx("div",{style:{width:o==="video"?280:320,height:o==="video"?500:320,borderRadius:16,background:"#EEEDE9",display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed #DDD"},children:o==="image"?e.jsx(be,{size:40,style:{color:"#CCC"}}):e.jsx(Te,{size:40,style:{color:"#CCC"}})}),e.jsxs("div",{style:{display:"flex",gap:10},children:[e.jsxs("button",{style:{display:"flex",alignItems:"center",gap:6,padding:"10px 24px",borderRadius:10,border:"1px solid #E0E0DC",background:"#FFF",fontSize:13,fontWeight:500,color:"#555",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(je,{size:14}),o==="image"?"UploadSimple imagem":"UploadSimple vÃdeo"]}),e.jsxs("button",{className:"snew-main-action",style:{display:"flex",alignItems:"center",gap:6,padding:"10px 24px",borderRadius:10,border:"none",fontSize:13,fontWeight:500,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(re,{size:14}),o==="image"?"Gerar com IA":"Gerar vÃdeo com IA"]})]})]})]})}):null,Z=({icon:t,label:n,onClick:o,variant:c="ghost"})=>e.jsxs("button",{className:c==="solid"?"snew-main-action":void 0,onClick:o,style:{display:"flex",alignItems:"center",gap:4,padding:"4px 10px",borderRadius:6,border:c==="ghost"?"1px solid #E0E0DC":"none",background:c==="ghost"?"transparent":void 0,color:c==="ghost"?"#666":void 0,fontSize:11,fontWeight:500,cursor:"pointer",fontFamily:"inherit",transition:"all 0.12s"},children:[t,n]}),Gt=({data:t,onUpdate:n})=>{var f;const[o,c]=l.useState(null),[a,x]=l.useState({open:!1,mode:"image",channel:""}),i=(d,r,m)=>{if(!n)return;const u={...t,copies:[...t.copies??[]]};u.copies[d]={...u.copies[d],[r]:m},n(u)},g={"InstagramLogo Feed":"#E1306C",Stories:"#833AB4",TiktokLogo:"#010101",WhatsappLogo:"#25D366",Email:"#2563EB",LinkedinLogo:"#0A66C2"},A=d=>{const r=d.toLowerCase();return r.includes("feed")||r.includes("stor")||r.includes("tiktok")||r.includes("instagram")},p=d=>{const r=d.toLowerCase();return r.includes("tiktok")||r.includes("reels")||r.includes("stor")};return e.jsxs(e.Fragment,{children:[e.jsx(Ht,{open:a.open,onClose:()=>x(d=>({...d,open:!1})),mode:a.mode,channel:a.channel}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:20},children:(f=t.copies)==null?void 0:f.map((d,r)=>{const m=Nt(d),u=d.channel??"";return e.jsxs("div",{style:{background:"#FFFFFF",borderRadius:14,border:"1px solid #EEEDE9",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 20px",borderBottom:"1px solid #F5F4F0"},children:[e.jsx("span",{style:{fontSize:11,fontWeight:700,color:g[u]??"#555",textTransform:"uppercase",letterSpacing:"0.06em"},children:u}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx(Z,{icon:e.jsx(tt,{size:11}),label:o===r?"Copiado":"Copiar",onClick:()=>{navigator.clipboard.writeText([d.subject,d.hook,d.headline,d.body,d.cta].filter(
3Boolean).join(` 4`)),c(r),setTimeout(()=>c(null),2e3)}}),e.jsx(Z,{icon:e.jsx(Se,{size:11}),label:"Editar"}),e.jsx(Z,{icon:e.jsx(ye,{size:11}),label:"Regenerar"})]})]}),e.jsxs("div",{style:{display:"flex",minHeight:200},children:[m&&e.jsx("div",{style:{width:"40%",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"#FAFAF8",borderRight:"1px solid #F5F4F0"},children:e.jsx("div",{style:{width:"100%"},children:m})}),e.jsxs("div",{style:{flex:1,padding:"18px 22px",display:"flex",flexDirection:"column",gap:6},children:[d.subject&&e.jsxs("div",{style:{fontSize:11,color:"#999",display:"flex",gap:4},children:[e.jsx("strong",{style:{color:"#555"},children:"Assunto:"}),e.jsx(V,{as:"span",value:d.subject,onChange:y=>i(r,"subject",y),style:{flex:1,color:"#555"}})]}),d.hook&&e.jsxs("div",{style:{fontSize:11,color:"#999",display:"flex",gap:4},children:[e.jsx("strong",{style:{color:"#555"},children:"Hook:"}),e.jsx(V,{as:"span",value:d.hook,onChange:y=>i(r,"hook",y),style:{flex:1,color:"#555"}})]}),d.headline&&e.jsx(V,{as:"p",value:d.headline,onChange:y=>i(r,"headline",y),style:{fontSize:15,fontWeight:600,color:"#1A1A1A",margin:"4px 0 2px"}}),e.jsx(V,{as:"p",multiline:!0,value:d.body??"",onChange:y=>i(r,"body",y),placeholder:"Adicione o corpo da mensagem...",style:{fontSize:13,color:"#555",margin:0,lineHeight:1.7,flex:1}}),d.cta&&e.jsx(V,{as:"p",value:d.cta,onChange:y=>i(r,"cta",y),style:{fontSize:12,fontWeight:600,color:"#2563EB",margin:"6px 0 0"}})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 20px",borderTop:"1px solid #F5F4F0",background:"#FAFAF8"},children:[e.jsxs("div",{style:{display:"flex",gap:6},children:[A(u)&&e.jsxs(e.Fragment,{children:[e.jsx(Z,{icon:e.jsx(je,{size:11}),label:"Carregar imagem",onClick:()=>{}}),e.jsx(Z,{icon:e.jsx(re,{size:11}),label:"Gerar imagem",onClick:()=>x({open:!0,mode:"image",channel:u})})]}),p(u)&&e.jsxs(e.Fragment,{children:[e.jsx(Z,{icon:e.jsx(je,{size:11}),label:"UploadSimple vÃdeo",onClick:()=>{}}),e.jsx(Z,{icon:e.jsx(re,{size:11}),label:"Gerar vÃdeo",onClick:()=>x({open:!0,mode:"video",channel:u})})]})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx(Z,{icon:e.jsx(Ke,{size:11}),label:"Agendar"}),e.jsx(Z,{icon:e.jsx(Qe,{size:11}),label:"Publicar",variant:"solid"})]})]})]},r)})})]})},_t=({data:t,accent:n})=>{var o,c;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.summary&&e.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap"},children:[e.jsx(se,{label:"Total em risco",value:t.summary.total,change:"",trend:"down"}),e.jsx(se,{label:"Alto risco",value:t.summary.high,change:"",trend:"down"}),e.jsx(se,{label:"Medio risco",value:t.summary.medium,change:"",trend:"down"}),e.jsx(se,{label:"Baixo risco",value:t.summary.low,change:"",trend:"up"})]}),(o=t.segments)==null?void 0:o.map((a,x)=>{var i;return e.jsxs("div",{style:{background:"#FFFFFF",borderRadius:12,padding:"20px 24px",border:"1px solid #EEEDE9"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:a.name.includes("Alto")?"#EF4444":a.name.includes("Medio")||a.name.includes("Médio")?"#F59E0B":"#22C55E"}}),e.jsxs("p",{style:{fontSize:14,fontWeight:600,color:"#1A1A1A",margin:0},children:[a.name," (",a.count,")"]})]}),e.jsx("p",{style:{fontSize:12,color:"#888",margin:"0 0 8px"},children:a.description}),e.jsx("div",{style:{background:`${n}10`,borderRadius:8,padding:"10px 14px",marginBottom:10},children:e.jsxs("p",{style:{fontSize:12,fontWeight:600,color:n,margin:0},children:["Acao: ",a.action]})}),(i=a.clients)==null?void 0:i.map((g,A)=>{var p;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"8px 0",borderBottom:A<a.clients.length-1?"1px solid #F5F4F0":"none"},children:[e.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:"#F0F0EE",display:"flex",alignItems:"center",justifyContent:"center",fontSize:11,fontWeight:600,color:"#888",flexShrink:0},children:((p=g.name)==null?void 0:p[0])??"?"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("p",{style:{fontSize:13,fontWeight:500,color:"#1A1A1A",margin:0},children:g.name}),e.jsxs("p",{style:{fontSize:11,color:"#999",margin:0},children:["Ultima compra: ",g.lastPurchase]})]}),e.jsx("span",{style:{fontSize:12,fontWeight:600,color:"#1A1A1A"},children:g.ltv})]},A)})]},x)}),((c=t.actions)==null?void 0:c.length)>0&&e.jsxs("div",{style:{background:"#1A1A1A",borderRadius:12,padding:"20px 24px"},children:[e.jsx("p",{style:{fontSize:11,fontWeight:600,color:"hsl(var(--color-modal-text-dim))",textTransform:"uppercase",letterSpacing:"0.08em",margin:"0 0 12px"},children:"Plano de acao"}),t.actions.map((a,x)=>e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start",padding:"10px 0",borderBottom:x<t.actions.length-1?"1px solid rgba(255,255,255,0.08)":"none"},children:[e.jsxs("span",{style:{fontSize:11,fontWeight:600,color:n,flexShrink:0,background:`${n}20`,borderRadius:4,padding:"2px 6px"},children:["P",a.priority]}),e.jsxs("div",{style:{flex:1},children:[e.jsx("p",{style:{fontSize:13,color:"hsl(var(--color-modal-text))",margin:0,lineHeight:1.5},children:a.action}),a.deadline&&e.jsx("p",{style:{fontSize:11,color:"hsl(var(--color-modal-text-mute))",margin:"2px 0 0"},children:a.deadline})]})]},x))]})]})},Yt=({content:t,onChange:n})=>{const[o,c]=l.useState(!1),[a,x]=l.useState(t);return l.useEffect(()=>{x(t)},[t]),o?e.jsxs("div",{style:{background:"transparent",borderRadius:0,padding:"20px 24px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:6,marginBottom:12},children:[e.jsx("button",{onClick:()=>{x(t),c(!1)},style:{padding:"4px 12px",borderRadius:7,border:"1px solid #E0E0DC",background:"#FFF",fontSize:12,color:"#555",cursor:"pointer",fontFamily:"inherit"},children:"Cancelar"}),e.jsx("button",{className:"snew-main-action",onClick:()=>{n(a),c(!1)},style:{padding:"4px 12px",borderRadius:7,border:"none",fontSize:12,cursor:"pointer",fontFamily:"inherit",fontWeight:500},children:"Salvar"})]}),e.jsx("textarea",{value:a,onChange:i=>x(i.target.value),autoFocus:!0,style:{width:"100%",minHeight:360,border:"1px solid #E8E8E4",borderRadius:10,padding:"14px 16px",fontSize:14,fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",color:"#1A1A1A",lineHeight:1.6,outline:"none",resize:"vertical",background:"#FAFAF8"}})]}):e.jsxs("div",{style:{position:"relative"},children:[e.jsxs("button",{onClick:()=>c(!0),style:{position:"absolute",top:14,right:14,zIndex:2,display:"flex",alignItems:"center",gap:4,padding:"4px 10px",borderRadius:7,border:"1px solid #E0E0DC",background:"#FFF",fontSize:11,color:"#555",cursor:"pointer",fontFamily:"inherit"},children:[e.jsx(Se,{size:11})," Editar"]}),e.jsx(Vt,{content:t})]})},Vt=({content:t})=>e.jsx("div",{style:{background:"transparent",borderRadius:0,padding:"44px 56px"},children:e.jsx(ut,{remarkPlugins:[ht],components:{h1:({children:n})=>e.jsx("h1",{style:{fontSize:24,fontWeight:600,color:"#1A1A1A",margin:"0 0 24px",lineHeight:1.3,letterSpacing:"-0.02em"},children:n}),h2:({children:n})=>e.jsx("h2",{style:{fontSize:16,fontWeight:600,color:"#1A1A1A",margin:"32px 0 10px",lineHeight:1.3,paddingTop:8,borderTop:"1px solid #F0F0EE"},children:n}),h3:({children:n})=>e.jsx("h3",{style:{fontSize:14,fontWeight:600,color:"#333",margin:"20px 0 8px"},children:n}),p:({children:n})=>e.jsx("p",{style:{fontSize:14,color:"#444",lineHeight:1.75,margin:"0 0 14px"},children:n}),ul:({children:n})=>e.jsx("ul",{style:{paddingLeft:20,margin:"0 0 14px"},children:n}),ol:({children:n})=>e.jsx("ol",{style:{paddingLeft:20,margin:"0 0 14px"},children:n}),li:({children:n})=>e.jsx("li",{style:{fontSize:14,color:"#444",lineHeight:1.7,marginBottom:4},children:n}),table:({children:n})=>e.jsx("div",{style:{overflowX:"auto",margin:"0 0 20px",borderRadius:8,border:"1px solid #F0F0EE"},children:e.jsx("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:n})}),thead:({children:n})=>e.jsx("thead",{style:{background:"#F7F6F3"},children:n}),th:({children:n})=>e.jsx("th",{style:{padding:"9px 14px",textAlign:"left",fontWeight:600,color:"#555",fontSize:11,borderBottom:"1px solid #E8E8E4",textTransform:"uppercase",letterSpacing:"0.05em"},children:n}),td:({children:n})=>e.jsx("td",{style:{padding:"9px 14px",borderBottom:"1px solid #F5F5F3",color:"#444",fontSize:13,lineHeight:1.5},children:n}),strong:({children:n})=>e.jsx("strong",{style:{fontWeight:600,color:"#1A1A1A"},children:n}),blockquote:({children:n})=>e.jsx("blockquote",{style:{borderLeft:"3px solid #E0E0DC",margin:"0 0 14px",paddingLeft:16,color:"#666",background:"#FAFAF8",borderRadius:"0 6px 6px 0",padding:"10px 10px 10px 16px"},children:n}),code:({children:n,className:o})=>!!o?e.jsx("pre",{style:{background:"#F7F6F3",borderRadius:8,padding:"14px 16px",overflowX:"auto",margin:"0 0 14px",border:"1px solid #EBEBEB"},children:e.jsx("code",{style:{fontSize:12,fontFamily:"monospace",color:"#333"},children:n})}):e.jsx("code",{style:{background:"#F0F0EE",borderRadius:4,padding:"1px 4px",fontSize:12,fontFamily:"monospace",color:"#D63031"},children:n}),hr:()=>e.jsx("hr",{style:{border:"none",borderTop:"1px solid #E8E8E4",margin:"24px 0"}})},children:t})});function Ut({artifact:t,title:n,isGenerating:o,onExpandChat:c,campaignTasks:a,onExecuteTask:x,onExecuteAll:i,onNavigateToStudio:g,storeCtx:A,onArtifactAction:p,pipelineSteps:f,showPipeline:d,onPipelineStepClick:r,batchGroups:m,onGenerateImage:u,onGenerateTexts:y,onApproveImage:S,onAddSlot:h,showCampaignWizard:D,onCampaignWizardComplete:B,onCampaignWizardCancel:N,campaignWizardInitialTheme:U,campaignWizardContextLabel:q}){const[ie,le]=l.useState(!1);ve();const[P,Q]=l.useState(()=>{try{return localStorage.getItem("snew:agent-tab")==="board"?"board":"documentos"}catch{return"documentos"}}),b=M=>{Q(M);try{localStorage.setItem("snew:agent-tab",M)}catch{}},F=l.useMemo(()=>t?$t(t):null,[t]),w=(F==null?void 0:F.type)??"markdown",C=(F==null?void 0:F.title)??n??"Documento",$=!!t,R=$?P:"documentos",[_,H]=l.useState((F==null?void 0:F.data)??{});l.useEffect(()=>{H((F==null?void 0:F.data)??{})},[F]);const I=_,G=l.useMemo(()=>t?w==="markdown"?I.content??t:JSON.stringify({type:w,title:C,data:I},null,2):"",[t,w,C,I]),te={report:"#2563EB",calendar:"#059669",brief:"#0891B2",copy:"#D97706",churn:"#7C3AED",markdown:"#1A1A1A"}[w]??"#1A1A1A",de=()=>{if(!t)return;const M=w==="markdown"?"md":"json",J=new Blob([G],{type:"text/plain"}),Y=URL.createObjectURL(J),X=document.createElement("a");X.href=Y,X.download=`${C.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").slice(0,40)}.${M}`,X.click(),setTimeout(()=>URL.revokeObjectURL(Y),3e3)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,position:"relative",minWidth:0,background:"#F2F2F2",overflow:"hidden"},children:[$&&e.jsxs("div",{style:{flexShrink:0,display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px 0",background:"transparent"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx("button",{onClick:()=>b("board"),style:{padding:"8px 14px",borderRadius:8,background:P==="board"?"#FFFFFF":"transparent",fontSize:13,fontWeight:P==="board"?600:500,color:P==="board"?"#1A1A1A":"#888",cursor:"pointer",fontFamily:"inherit",boxShadow:P==="board"?"0 1px 2px rgba(0,0,0,0.04)":"none",border:P==="board"?"1px solid #EEEDE9":"1px solid transparent",transition:"background 0.12s, color 0.12s"},children:"Board"}),e.jsx("button",{onClick:()=>b("documentos"),style:{padding:"8px 14px",borderRadius:8,background:P==="documentos"?"#FFFFFF":"transparent",fontSize:13,fontWeight:P==="documentos"?600:500,color:P==="documentos"?"#1A1A1A":"#888",cursor:"pointer",fontFamily:"inherit",boxShadow:P==="documentos"?"0 1px 2px rgba(0,0,0,0.04)":"none",border:P==="documentos"?"1px solid #EEEDE9":"1px solid transparent",transition:"background 0.12s, color 0.12s"},children:"Documentos"})]}),R==="documentos"&&!o&&t&&e.jsx("div",{style:{display:"flex",gap:6,flexShrink:0},children:e.jsxs("button",{className:"snew-main-action",onClick:de,style:{display:"flex",alignItems:"center",gap:4,padding:"6px 12px",borderRadius:7,border:"none",fontSize:12,cursor:"pointer",fontFamily:"inherit",whiteSpace:"nowrap"},children:[e.jsx(nt,{size:12}),"Baixar"]})})]}),e.jsxs("div",{style:{flex:1,overflowY:R==="board"?"hidden":"auto",overflowX:"hidden",padding:R==="board"?"12px 16px 16px":D?0:"16px 24px 40px",display:"flex",flexDirection:"column",alignItems:R==="board"?"stretch":"center",justifyContent:R==="board"?"flex-start":o||!t&&!D||D?"center":"flex-start",minHeight:0},children:[R==="board"&&e.jsx(Tt,{artifact:t,theme:U??C,campaignTasks:a}),R==="documentos"&&e.jsxs(e.Fragment,{children:[!t&&!o&&D&&e.jsx("div",{style:{width:"100%"}
4,children:e.jsx(rt,{open:!0,inline:!0,onClose:()=>N==null?void 0:N(),onComplete:M=>B==null?void 0:B(M),initialTheme:U,initialContextLabel:q})}),!t&&!o&&!D&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[e.jsx("div",{style:{width:52,height:52,borderRadius:14,background:"#EBEBEB",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Re,{size:22,style:{color:"#AAAAAA"}})}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("p",{style:{fontSize:15,fontWeight:500,color:"#1A1A1A",margin:"0 0 6px"},children:"Documento aparece aqui"}),e.jsx("p",{style:{fontSize:13,color:"#999",margin:0},children:"Escolha uma acao rapida ou escreva o que precisa"})]})]}),o&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:12},children:[e.jsx(ae,{size:28,style:{color:"#999",animation:"spin 1s linear infinite"}}),e.jsx("p",{style:{fontSize:13,color:"#888",margin:0},children:"Gerando documento..."})]}),!o&&t&&e.jsxs("div",{style:{width:"100%",maxWidth:800,animation:"fadeIn 0.3s ease"},children:[d&&f&&f.length>0&&e.jsx(it,{steps:f,currentStep:f.findIndex(M=>M.status==="active"),onStepClick:M=>r==null?void 0:r(M)}),e.jsx("p",{style:{fontSize:11,color:"#9A9A95",margin:"4px 4px 10px",fontWeight:500,letterSpacing:"0.01em"},children:C}),e.jsxs("div",{style:{background:"#FFFFFF",borderRadius:16,padding:w==="markdown"?0:"44px 56px",boxShadow:"0 1px 2px rgba(0,0,0,0.03), 0 8px 28px rgba(0,0,0,0.04)",border:"1px solid #EEEDE9",overflow:"hidden"},children:[w!=="markdown"&&(I.period||I.month)&&e.jsx("p",{style:{fontSize:11,color:"#AAA",margin:"0 0 24px",textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:600},children:I.period??I.month}),w==="report"&&e.jsx(It,{data:I,accent:te}),w==="calendar"&&e.jsx(Dt,{data:I,accent:te}),w==="brief"&&e.jsx(Mt,{data:I,accent:te,onUpdate:H}),w==="copy"&&e.jsx(Gt,{data:I,onUpdate:H}),w==="churn"&&e.jsx(_t,{data:I,accent:te}),w==="markdown"&&e.jsx(Yt,{content:I.content??t,onChange:M=>H({...I,content:M})})]}),(w==="calendar"||w==="markdown")&&(()=>{const M=a&&a.length>0?a:t?Fe(t):[];return M.length===0?null:e.jsx("div",{style:{marginTop:20,padding:"20px 24px",background:"#FAFAF8",borderRadius:12,border:"1px solid #EEECEA"},children:e.jsx(Ft,{tasks:M,onExecuteTask:J=>x==null?void 0:x(J),onExecuteAll:J=>i==null?void 0:i(J),onNavigateToStudio:J=>g==null?void 0:g(J)})})})(),m&&m.length>0&&e.jsxs("div",{style:{marginTop:28,display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:14,fontWeight:700,color:"hsl(var(--foreground))",margin:"0 0 3px"},children:"Assets da campanha"}),e.jsxs("p",{style:{fontSize:11,color:"hsl(var(--muted-foreground))",margin:0},children:[m.filter(M=>M.status==="done").length," de ",m.length," grupos prontos"]})]}),e.jsxs("div",{style:{fontSize:20,fontWeight:800,color:"hsl(var(--foreground))",letterSpacing:"-0.03em"},children:[m.length>0?Math.round(m.filter(M=>M.status==="done").length/m.length*100):0,"%"]})]}),m.map((M,J)=>e.jsx(st,{group:M,index:J,onGenerateImage:(Y,X)=>u==null?void 0:u(Y,X),onGenerateTexts:Y=>y==null?void 0:y(Y),onApproveImage:(Y,X)=>S==null?void 0:S(Y,X),onAddSlot:Y=>h==null?void 0:h(Y)},M.id))]})]})]})]})]})}const qt=t=>{var n;return`You are the Snew Agent â a strategic marketing and operations assistant for e-commerce stores. 5 6You generate structured documents: reports, calendars, briefs, copy packages, analysis. 7NOT images or visual assets â those are handled by Snew Studio. 8 9## CRITICAL: Always respond with structured JSON, never plain text 10 11Your response must ALWAYS be a valid JSON object with this structure: 12{ 13 "type": "report" | "calendar" | "brief" | "copy" | "churn" | "markdown", 14 "title": "Document title", 15 "data": { ...type-specific data... } 16} 17 18## Document types and their data structure: 19 20### type: "report" â Performance report with KPIs and charts 21{ 22 "type": "report", 23 "title": "Relatório de Performance Semanal", 24 "data": { 25 "period": "01/04 â 07/04/2026", 26 "kpis": [ 27 { "label": "Receita", "value": "R$ 48.320", "change": "+12%", "trend": "up" }, 28 { "label": "Conversão", "value": "3.2%", "change": "+0.4pp", "trend": "up" }, 29 { "label": "Ticket Médio", "value": "R$ 187", "change": "-3%", "trend": "down" }, 30 { "label": "Carrinhos Abandonados", "value": "847", "change": "+5%", "trend": "down" } 31 ], 32 "chart": { 33 "type": "bar", 34 "labels": ["Seg", "Ter", "Qua", "Qui", "Sex", "Sáb", "Dom"], 35 "values": [6200, 5800, 7100, 6900, 8200, 9100, 5020] 36 }, 37 "topProducts": [ 38 { "name": "Produto A", "revenue": "R$ 12.400", "units": 66 }, 39 { "name": "Produto B", "revenue": "R$ 9.800", "units": 42 } 40 ], 41 "alerts": [ 42 { "level": "warning", "text": "Taxa de churn subiu 2pp esta semana" }, 43 { "level": "success", "text": "Campanha gerou R$ 8.200" } 44 ], 45 "actions": [ 46 "Ativar campanha de recuperação de carrinho", 47 "Revisar precificação", 48 "Escalar campanha com melhor ROAS" 49 ] 50 } 51} 52 53### type: "calendar" â Editorial calendar with dates and content 54{ 55 "type": "calendar", 56 "title": "Calendário Editorial â Maio 2026", 57 "data": { 58 "month": "Maio 2026", 59 "days": [ 60 { 61 "date": "2026-05-01", 62 "label": "Dia do Trabalho", 63 "type": "holiday", 64 "content": "Post institucional: valores da marca", 65 "channels": ["instagram", "whatsapp"], 66 "copy": "Hoje celebramos quem faz acontecer..." 67 } 68 ] 69 } 70} 71 72### type: "brief" â Campaign brief with sections 73{ 74 "type": "brief", 75 "title": "Brief: Campanha Dia das Mães", 76 "data": { 77 "objective": "Aumentar receita 30% vs semana anterior", 78 "audience": "Mulheres 25-45, presentes, ticket R$ 150-300", 79 "message": "O presente perfeito para a mãe que cuida de tudo", 80 "channels": ["InstagramLogo", "WhatsappLogo", "Email"], 81 "timeline": [ 82 { "date": "D-14", "task": "Briefing de criativo e copies" }, 83 { "date": "D-7", "task": "Assets aprovados e agendados" }, 84 { "date": "D-0", "task": "Campanha ao vivo" } 85 ], 86 "kpis": ["ROAS > 4x", "Receita > R$ 45.000"], 87 "budget": "R$ 3.500", 88 "copies": [ 89 { "channel": "InstagramLogo", "text": "Para a mãe que merece o melhor..." } 90 ] 91 } 92} 93 94### type: "copy" â Multi-channel copy package 95{ 96 "type": "copy", 97 "title": "Copy Pack: Campanha X", 98 "data": { 99 "copies": [ 100 { "channel": "InstagramLogo Feed", "headline": "...", "body": "...", "cta": "Ver coleção" }, 101 { "channel": "Stories", "headline": "...", "body": "...", "cta": "Deslize" }, 102 { "channel": "WhatsappLogo", "headline": null, "body": "Oi! Já pensou...", "cta": null }, 103 { "channel": "Email", "subject": "Assunto do email", "body": "...", "cta": "Comprar agora" }, 104 { "channel": "TiktokLogo", "hook": "POV: ...", "body": "...", "cta": null } 105 ] 106 } 107} 108
109### type: "churn" â Churn analysis with client list 110{ 111 "type": "churn", 112 "title": "Análise de Churn â Plano de Retenção", 113 "data": { 114 "summary": { "total": 47, "high": 12, "medium": 23, "low": 12 }, 115 "segments": [ 116 { 117 "name": "Alto Risco", 118 "count": 12, 119 "description": "Sem compra há 90+ dias, LTV > R$ 800", 120 "action": "Oferta exclusiva 20% + contato pessoal", 121 "clients": [ 122 { "name": "Maria S.", "lastPurchase": "Jan 2026", "ltv": "R$ 1.240", "risk": "high" } 123 ] 124 } 125 ], 126 "actions": [ 127 { "priority": 1, "action": "WhatsappLogo personalizado para clientes alto risco", "deadline": "Hoje" }, 128 { "priority": 2, "action": "Email com cupom para médio risco", "deadline": "Esta semana" } 129 ] 130 } 131} 132 133### type: "markdown" â Fallback for other documents 134{ "type": "markdown", "title": "...", "data": { "content": "# Title\\n\\n..." } } 135 136## Rules 137- Always return valid JSON only â no text before or after the JSON object 138- Use realistic mock data when no real data is available 139- Always respond in Brazilian Portuguese for labels and content 140- Use the store context provided when available 141- Personality: direct, data-driven, proactive. Always connect to revenue. 142${t?` 143## Primary Context â THIS IS YOUR STORE 144You are the strategic AI for ${t.name}. 145- Storefront: ${t.name} 146- Description: ${t.description} 147- Niche: ${t.niche} 148- Audience: ${t.audience} 149- Tone: ${t.tone} 150- Product types: ${t.productTypes.join(", ")} 151- Keywords: ${t.keywords.join(", ")} 152${(n=t.colors)!=null&&n.length?`- Brand colors: ${t.colors.slice(0,3).join(", ")}`:""} 153 154EVERY document, report, calendar, brief and copy you generate 155MUST be specific to ${t.name}. Never use generic placeholders. 156Always use real store data from this context. 157Always tailor reports, briefs and calendars specifically for this store. 158Use the store name, niche and audience in every document you generate. 159`:""} 160When the user asks for a report, brief, calendar, analysis or copy: 1611. Generate the full document immediately â don't ask clarifying questions 1622. Use realistic mock data if no real data is available 1633. Make it actionable and ready to use 164 165Respond ONLY with the JSON object. No additional text.`},Jt=(t,n)=>{var o,c,a,x,i,g,A,p,f,d;try{const r=ft(),m=JSON.parse(localStorage.getItem(r)??"[]");let u="";try{const h=JSON.parse(((o=t.match(/\{[\s\S]*\}/))==null?void 0:o[0])??"");h.type&&h.title&&(n=h.title,(c=h.data)!=null&&c.objective?u=h.data.objective:(a=h.data)!=null&&a.period?u=h.data.period:(x=h.data)!=null&&x.month?u=h.data.month:(A=(g=(i=h.data)==null?void 0:i.copies)==null?void 0:g[0])!=null&&A.body?u=h.data.copies[0].body.slice(0,120):(p=h.data)!=null&&p.content&&(u=((f=h.data.content.split(` 166`).filter(B=>B.trim()&&!B.startsWith("#"))[0])==null?void 0:f.slice(0,120))??""))}catch{u=((d=t.split(` 167`).filter(D=>D.trim()&&!D.startsWith("#"))[0])==null?void 0:d.slice(0,120))??""}const S=[{id:`doc-${Date.now()}`,createdAt:new Date().toISOString(),imageUrl:"",heading:n,description:u,cta:"",channel:"document",styleId:null,isCarousel:!1,sessionTitle:n,type:"document",documentMarkdown:t,documentTitle:n,documentExcerpt:u},...m].slice(0,50);localStorage.setItem(r,JSON.stringify(S));try{window.dispatchEvent(new Event("snew:history-updated"))}catch{}}catch(r){console.warn("saveDocToHistory failed:",r)}},Kt={channel:"",heading:"",description:"",cta:"",style:null,product:"",campaign:"",isCarouselMode:!1,textColor:"#FFFFFF",ctaColor:"#FFFFFF",overlayOpacity:0,font:"Inter"},Xt=(t,n)=>{if(!t||t.length===0)return[];const o=(n==null?void 0:n.name)??"a marca",c=new Map;return t.forEach(a=>{const x=a.day??0;c.has(x)||c.set(x,[]),c.get(x).push(a)}),Array.from(c.entries()).map(([a,x])=>{var f;const i=x[0],g=`batch-d${a}-${Date.now()}`,A=x.filter(d=>d.type!=="copy").map((d,r)=>{var m,u,y,S;return{id:`${g}-img-${r}`,label:d.canal||`Versão ${r+1}`,status:"pending",prompt:`${d.content??d.copy??i.content} para ${o}. Canal: ${d.canal}. ${d.theme?`Tema: ${d.theme}`:""}
167`.trim(),ratio:(m=d.canal)!=null&&m.includes("story")||(u=d.canal)!=null&&u.includes("reel")||(y=d.canal)!=null&&y.includes("tiktok")?"9:16":(S=d.canal)!=null&&S.includes("feed")?"4:5":"1:1"}});A.length===0&&A.push({id:`${g}-img-0`,label:"Feed",status:"pending",prompt:`${i.content??i.copy??""} para ${o}`,ratio:"1:1"});const p=[{id:`${g}-txt-prompt`,type:"prompt",label:"Prompt",content:((f=A[0])==null?void 0:f.prompt)??"",status:"done"},{id:`${g}-txt-caption`,type:"caption",label:"Legenda",content:i.copy??"",status:i.copy?"done":"pending"},{id:`${g}-txt-whatsapp`,type:"whatsapp",label:"WhatsappLogo",content:"",status:"pending"}];return{id:g,title:i.content||i.copy||`Dia ${a}`,day:a,type:i.type,canal:x.map(d=>d.canal).filter(Boolean).join(", "),images:A,texts:p,status:"pending"}})};function ao(){var Ee,ke;const t=ve(),n=Ue(),o=(Ee=n.state)==null?void 0:Ee.creativeEntry,c=l.useMemo(()=>o?{productName:o.product.name,productImageUrl:o.product.image,starterProductId:o.product.id}:{},[o]),a=((ke=n.state)==null?void 0:ke.autoPrompt)??"",x=!!a.trim()&&!/campanha/i.test(a),i=l.useMemo(()=>xt(),[]),g=l.useMemo(()=>qt(i),[i]),[A,p]=l.useState(!0),[f,d]=l.useState(!1),[r,m]=l.useState("snew agent"),[u,y]=l.useState(!1),[S,h]=l.useState(null),[D,B]=l.useState("Documento"),[N,U]=l.useState(!1),[q,ie]=l.useState([]),[le,P]=l.useState([]),[Q,b]=l.useState(!1),[F,w]=l.useState([]),[C,$]=l.useState(!o&&!x),[R,_]=l.useState(void 0),[H,I]=l.useState(void 0),G=l.useRef(null),ge=l.useRef(!1),te=l.useRef(null);l.useEffect(()=>{try{localStorage.setItem("snew:agent-tab","documentos")}catch{}},[]),l.useEffect(()=>{const s=j=>{var v;(v=te.current)!=null&&v.contains(j.target)||y(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const de=l.useCallback(s=>{m("nova campanha"),_(s==null?void 0:s.initialTheme),I(s==null?void 0:s.contextLabel),$(!0)},[]),M=l.useCallback(s=>{var ee,O,ne;$(!1),m(s.label.toLowerCase().slice(0,60));const j=(i==null?void 0:i.name)??"a loja",v=(o==null?void 0:o.product.name)??((ee=i==null?void 0:i.productTypes)==null?void 0:ee[0])??"produtos em alta",E=(i==null?void 0:i.audience)??"público-alvo",z=(i==null?void 0:i.tone)??"emocional",W=s.type==="sazonal",L=s.type==="briefing",K=W?`Gerar campanha sazonal completa para ${j}. 168Data: ${s.theme||"data sazonal"} 169Produto destaque: ${s.objective||v} 170Canal: ${s.channels||"Todos os canais"} 171Público-alvo: ${E} 172Tom de voz: ${z} 173 174Retorne um documento type:"brief" com: objective, audience, message, channels, timeline (D-14, D-7, D-0), kpis, budget e copies multi-canal. 175 176IMPORTANTE para o array "copies": cada item DEVE ter { "channel": string, "text": string } com o texto COMPLETO da copy pronto para publicar (mÃnimo 2 frases para Feed/Email, 1 frase punchy para Stories/WhatsappLogo). Inclua os 4 canais: "InstagramLogo Feed", "InstagramLogo Stories", "WhatsappLogo", "Email". NUNCA retorne text vazio ou null.`:L?`Gerar briefing de campanha para ${j}. 177Objetivo: ${s.theme||"aumentar vendas"} 178Público: ${((O=s.objective)==null?void 0:O.split(" · ")[0])||E} 179KPI principal: ${((ne=s.objective)==null?void 0:ne.split(" · ")[1])||"ROAS"} 180Canais: ${s.channels||"Todos"} 181Tom: ${z} 182 183Retorne um documento type:"brief" completo com objective, audience, message, channels, timeline, kpis, budget e copies. 184 185IMPORTANTE para o array "copies": cada item DEVE ter { "channel": string, "text": string } com o texto COMPLETO pronto para publicar. Inclua "InstagramLogo Feed", "InstagramLogo Stories", "WhatsappLogo" e "Email". NUNCA retorne text vazio.`:`Gerar campanha ${s.label} para ${j}. 186Tema: ${s.theme||"tema livre"} 187Objetivo: ${s.objective||"aumentar vendas"} 188Canais: ${s.channels||"Todos"} 189Produto principal: ${v} 190Público: ${E} 191Tom: ${z} 192 193Retorne um documento type:"brief" com plano completo, copies multi-canal, timeline e KPIs. 194 195IMPORTANTE para o array "copies": cada item DEVE ter { "channel": string, "text": string } com o texto COMPLETO pronto para publicar. Inclua "InstagramLogo Feed", "InstagramLogo Stories", "WhatsappLogo" e "Email". NUNCA retorne text vazio.`;setTimeout(()=>{var k,T;(T=(k=G.current)==null?void 0:k.sendMessage)==null||T.call(k,K,{skipIntentDetection:!0}
195)},150)},[i]),J=l.useCallback(()=>{$(!1)},[]);l.useEffect(()=>{!S&&!N&&r==="nova campanha"&&$(!0)},[S,N,r]),l.useEffect(()=>{var ne;if(o){$(!1),m(o.product.name);const k=setTimeout(()=>{var T;ge.current||!((T=G.current)!=null&&T.sendMessage)||(ge.current=!0,G.current.sendMessage(`Criar um plano de campanha para ${o.product.name}. 196${o.prompt} 197Marca: ${(i==null?void 0:i.name)||"não informada"}. Público informado: ${(i==null?void 0:i.audience)||"não informado"}. Use apenas evidências fornecidas; não invente métricas comerciais.`))},600);return()=>clearTimeout(k)}const s=i!=null&&i.name?` para ${i.name}`:"",j=(a==null?void 0:a.trim())&&/campanha/i.test(a);if(a!=null&&a.trim()&&!j){m(a.slice(0,60));const k=setTimeout(()=>{var T,oe;(oe=(T=G.current)==null?void 0:T.sendMessage)==null||oe.call(T,a)},600);return()=>clearTimeout(k)}j&&(m("nova campanha"),$(!0));const E=(j?yt(a):null)??"Dia das Mães",z=E.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,""),W=((ne=i==null?void 0:i.productTypes)==null?void 0:ne[0])??"produtos em alta",L=G,K=()=>{var k,T;(T=(k=L.current)==null?void 0:k.pushAssistantMessage)==null||T.call(k,{content:"Posso te ajudar com:",chips:[{label:"Calendário editorial",action:"quick:calendar"},{label:"Brief de produto",action:"quick:brief"},{label:"Relatório semanal",action:"quick:report"},{label:"Outra campanha",action:"wizard:campaign"}],onChipClick:oe=>{var pe,we,me,ze,ue,Ce;oe.action==="wizard:campaign"?de():oe.action==="quick:calendar"?(we=(pe=L.current)==null?void 0:pe.sendMessage)==null||we.call(pe,`Criar calendário editorial mensal${s}`):oe.action==="quick:brief"?(ze=(me=L.current)==null?void 0:me.sendMessage)==null||ze.call(me,`Criar brief de produto${s}`):oe.action==="quick:report"&&((Ce=(ue=L.current)==null?void 0:ue.sendMessage)==null||Ce.call(ue,`Gerar relatório de performance da última semana${s}`))}})},ee=[],O=(k,T)=>{ee.push(setTimeout(k,T))};return O(()=>{var k,T;return(T=(k=L.current)==null?void 0:k.pushBriefingPart)==null?void 0:T.call(k,{kind:"typing"})},350),O(()=>{var k,T;return(T=(k=L.current)==null?void 0:k.pushBriefingPart)==null?void 0:T.call(k,{kind:"paragraph",content:e.jsxs(e.Fragment,{children:["Verificamos alguns pontos que chamaram nossa atenção essa semana. Sua taxa de abandono está em ",e.jsx("strong",{children:"71%"})," e há ",e.jsx("strong",{children:"23 carrinhos"})," dos últimos 2 dias ainda em aberto. Com o ",e.jsx("strong",{children:E})," em 18 dias e o ",e.jsx("strong",{children:W})," em alta, a janela é ideal."]})},{replaceLastTyping:!0})},1400),O(()=>{var k,T;return(T=(k=L.current)==null?void 0:k.pushBriefingPart)==null?void 0:T.call(k,{kind:"typing"})},1900),O(()=>{var k,T;return(T=(k=L.current)==null?void 0:k.pushBriefingPart)==null?void 0:T.call(k,{kind:"paragraph",content:e.jsx(e.Fragment,{children:"Por isso, recomendamos uma campanha de recuperação sazonal â aproveitar o momentum do produto e a data para criar urgência genuÃna."})},{replaceLastTyping:!0})},3e3),O(()=>{var k,T;return(T=(k=L.current)==null?void 0:k.pushBriefingPart)==null?void 0:T.call(k,{kind:"typing"})},3500),O(()=>{var k,T;return(T=(k=L.current)==null?void 0:k.pushBriefingPart)==null?void 0:T.call(k,{kind:"card",card:{title:`Recuperação sazonal · ${E}`,meta:"WhatsappLogo + InstagramLogo · 23 clientes em risco",description:`Mensagem personalizada conectando o carrinho abandonado ao contexto do ${E}. Taxa de conversão 3à maior nas primeiras 48h.`,primaryLabel:"Gerar essa campanha",secondaryLabel:"Outras sugestões",onPrimary:()=>{$(!1),t(`/campaigns/${z||"dia-das-maes"}`)},onSecondary:K}},{replaceLastTyping:!0})},4400),()=>{ee.forEach(clearTimeout)}},[]);const Y=l.useCallback(async()=>null,[]),X=l.useCallback((s,j)=>{let v=j;try{const z=s.match(/\{[\s\S]*\}/);if(z){const W=JSON.parse(z[0]);W.title&&(v=W.title)}}catch{}h(s),B(v),Jt(s,v);const E=Fe(s);ie(E)},[]);l.useEffect(()=>{const s=sessionStorage.getItem("snew:restore-doc");if(s)try{const{markdown:j,title:v}=JSON.parse(s);h(j),B(v),m(v.slice(0,60).toLowerCase()),sessionStorage.removeItem("snew:restore-doc")}catch{}},[]);const Le=l.useCallback(s=>{r==="snew agent"&&m(s.slice(0,60).toLowerCase())},[r]),ce=l.useCallback(s=>{const j=(i==null?void 0:i.name)??"a marca",v=(i==null?void 0:i.niche)??"",E=s.canal,z=E.includes("story")||E.includes("reel")?"9:16":"1:1";return[s.content,`para ${j}`,v&&`(${v})`,s.copy&&`Copy: "${s.copy}"`,`Canal: ${E}, formato ${z}`,s.theme&&`Tema: ${s.theme}
197`].filter(Boolean).join(". ")},[i]),Be=l.useCallback(s=>{var j,v;if(ie(E=>E.map(z=>z.id===s.id?{...z,status:"generating"}:z)),s.type==="copy"){const E=`Escrever copy para ${s.canal} do Dia ${s.day}: ${s.content}. ${s.copy?`Copy sugerida: "${s.copy}".`:""} Adaptar para ${(i==null?void 0:i.name)??"a marca"}.`;(v=(j=G.current)==null?void 0:j.sendMessage)==null||v.call(j,E),ie(z=>z.map(W=>W.id===s.id?{...W,status:"done"}:W))}else t("/generate-image",{state:{...c,autoPrompt:ce(s),sessionTitle:`Dia ${s.day} · ${s.canal}`,fromCampaign:!0,taskId:s.id,...s.type==="carousel"?{carouselType:"campaign"}:{}}})},[i,t,ce,c]),Pe=l.useCallback(s=>{const j=q.filter(E=>s.has(E.id)),v=j.length>0?j:q;t("/campaign/batch",{state:{...c,tasks:v,docTitle:D}})},[q,t,D,c]),Oe=l.useCallback(s=>{t("/generate-image",{state:{...c,autoPrompt:ce(s),sessionTitle:`Dia ${s.day} · ${s.canal}`}})},[t,ce,c]),Ne=l.useCallback((s,j,v)=>{var E,z,W,L,K,ee;if(s.dest==="pipeline"){b(!0),P(at());const O=Xt(q,i);w(O);return}if(s.dest==="studio"){const O=((E=s.buildPrompt)==null?void 0:E.call(s,v,i))??`Criar asset visual para ${(i==null?void 0:i.name)??"a loja"}`;t("/generate-image",{state:{...c,autoPrompt:O}});return}if(s.dest==="agent"||s.dest==="whatsapp"||s.dest==="email"||s.dest==="schedule"){const O=((z=s.buildPrompt)==null?void 0:z.call(s,v,i))??"";if(O)(L=(W=G.current)==null?void 0:W.sendMessage)==null||L.call(W,O);else{const ne=s.dest==="schedule"?`Criar cronograma de publicações para a campanha de ${(i==null?void 0:i.name)??"a loja"}`:`${s.label} para ${(i==null?void 0:i.name)??"a loja"}`;(ee=(K=G.current)==null?void 0:K.sendMessage)==null||ee.call(K,ne)}return}},[i,t,q,c]),He=l.useCallback(s=>{var j,v;s.type==="asset"?t("/generate-image",{state:{...c,autoPrompt:`Gerar ${s.label} para ${(i==null?void 0:i.name)??"a loja"}`}}):s.type==="doc"&&((v=(j=G.current)==null?void 0:j.sendMessage)==null||v.call(j,`Gerar ${s.label} para a campanha`)),P(E=>E.map(z=>z.id===s.id?{...z,status:"active"}:z))},[i,t,c]),Ge=l.useCallback((s,j)=>{w(z=>z.map(W=>W.id===s?{...W,images:W.images.map(L=>L.id===j?{...L,status:"generating"}:L)}:W));const v=F.find(z=>z.id===s),E=v==null?void 0:v.images.find(z=>z.id===j);E&&t("/generate-image",{state:{...c,autoPrompt:E.prompt,productName:o==null?void 0:o.product.name,productImageUrl:o==null?void 0:o.product.image,starterProductId:o==null?void 0:o.product.id,sessionTitle:`${(v==null?void 0:v.title)??"Asset"} · ${E.label??""}`,fromCampaign:!0,batchGroupId:s,batchSlotId:j}})},[F,t,o,c]),_e=l.useCallback(s=>{var E,z;const j=F.find(W=>W.id===s);if(!j)return;const v=`Gerar textos para a campanha "${j.title}" de ${(i==null?void 0:i.name)??"a loja"}: legenda para ${j.canal}, copy para WhatsappLogo e email. Tom ${(i==null?void 0:i.tone)??"envolvente"}.`;(z=(E=G.current)==null?void 0:E.sendMessage)==null||z.call(E,v),w(W=>W.map(L=>L.id===s?{...L,texts:L.texts.map(K=>({...K,status:"done",content:K.content||"Gerando via Agent..."}))}:L))},[F,i]),Ye=l.useCallback((s,j)=>{w(v=>v.map(E=>E.id===s?{...E,images:E.images.map(z=>z.id===j?{...z,status:"approved"}:z),status:E.images.every(z=>z.id===j||z.status==="approved"||z.status==="done")&&E.texts.every(z=>z.status==="done")?"done":E.status}:E))},[]),Ve=l.useCallback(s=>{w(j=>j.map(v=>{var E;return v.id===s?{...v,images:[...v.images,{id:`slot-${Date.now()}`,label:`Versão ${v.images.length+1}`,status:"pending",prompt:((E=v.images[0])==null?void 0:E.prompt)??v.title,ratio:"1:1"}]}:v}))},[]);return e.jsxs("div",{style:{display:"flex",width:"100vw",height:"100vh",overflow:"hidden"},children:[e.jsx(qe,{collapsed:A,onToggleCollapse:()=>p(s=>!s)}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"grid",gridTemplateColumns:f?"1fr":"380px 1fr",background:"#F2F2F2",transition:"grid-template-columns 0.25s ease",overflow:"hidden"},children:[!f&&e.jsx("div",{style:{height:"100%",padding:"12px 0 12px 12px",boxSizing:"border-box",display:"flex",flexDirection:"column",minHeight:0},children:e.jsxs("div",{style:{flex:1,minHeight:0,background:"transparent",borderRadius:16,border:"none",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:0},children:[o&&e.jsxs("div",{className:"flex items-center gap-3 rounded-xl bg-neutral-50 p-3",children:[e.jsx("img",{src:o.product.image,alt:o.product.name,className:"h-16 w-16 rounded-lg object-cover"}),e.jsx("span",{className:"text-sm",children:o.product.name})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 14px",flexShrink:0,background:"#FAFAFA"},children:[e.jsxs("div",{ref:te,style:{position:"relative"},children:[e.jsxs("button",{onClick:()=>y(s=>!s),style:{display:"flex",alignItems:"center",gap:4,background:"transparent",border:"none",cursor:"pointer",padding:"2px 4px",borderRadius:6,fontFamily:"inherit",transition:"background 0.1s"},onMouseEnter:s=>s.currentTarget.style.background="#F5F5F5",onMouseLeave:s=>s.currentTarget.style.background="transparent",children:[e.jsx("span",{style:{fontSize:13,fontWeight:400,color:"#1A1A1A",letterSpacing:"-0.01em",maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r||"snew agent"}),e.jsx(et,{size:12,style:{color:"#BBB",flexShrink:0}})]}),u&&e.jsxs("div",{style:{position:"absolute",top:"calc(100% + 4px)",left:0,background:"#FFFFFF",border:"0.5px solid #E8E8E8",borderRadius:10,boxShadow:"0 4px 16px rgba(0,0,0,0.08)",overflow:"hidden",zIndex:100,minWidth:160},children:[e.jsxs("button",{onClick:()=>{const s=window.prompt("Renomear chat:",r);s!=null&&s.trim()&&m(s.trim().toLowerCase()),y(!1)},style:{width:"100%",padding:"10px 14px",display:"flex",alignItems:"center",gap:8,background:"transparent",border:"none",fontSize:12,fontWeight:400,color:"#555",cursor:"pointer",textAlign:"left",fontFamily:"inherit",transition:"background 0.1s"},onMouseEnter:s=>s.currentTarget.style.background="#F7F7F7",onMouseLeave:s=>s.currentTarget.style.background="transparent",children:[e.jsx(Se,{size:12,style:{color:"#BBB"}}),"renomear"]}),e.jsx("div",{style:{height:1,background:"#F0F0F0"}}),e.jsxs("button",{onClick:()=>{var s,j;m(""),h(null),(j=(s=G.current)==null?void 0:s.clearMessages)==null||j.call(s),y(!1)},style:{width:"100%",padding:"10px 14px",display:"flex",alignItems:"center",gap:8,background:"transparent",border:"none",fontSize:12,fontWeight:400,color:"#555",cursor:"pointer",textAlign:"left",fontFamily:"inherit",transition:"background 0.1s"},onMouseEnter:s=>s.currentTarget.style.background="#F7F7F7",onMouseLeave:s=>s.currentTarget.style.background="transparent",children:[e.jsx(De,{size:12,style:{color:"#BBB"}}),"novo documento"]})]})]}),e.jsx("button",{onClick:()=>d(!0),title:"Minimizar chat",style:{width:28,height:28,borderRadius:7,border:"none",background:"transparent",color:"#CCC",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.1s",flexShrink:0},onMouseEnter:s=>s.currentTarget.style.color="#1A1A1A",onMouseLeave:s=>s.currentTarget.style.color="#CCC",children:e.jsx(gt,{size:15})})]}),e.jsx("div",{style:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:e.jsx(Je,{ref:G,creativeState:{...Kt,...c,product:(o==null?void 0:o.product.name)??"",hasImage:!!(o!=null&&o.product.image),description:(o==null?void 0:o.prompt)??""},onAction:Y,onArtifactReady:()=>{},onSuggestionAction:s=>{var j,v;if(s==="open_campaign_wizard"){de();return}(v=(j=G.current)==null?void 0:j.sendMessage)==null||v.call(j,s)},onFirstMessage:Le,agentMode:!0,agentSystemPrompt:g,onDocumentGenerated:X,suppressWelcome:!!o||!!a.trim(),onAgentHandoff:s=>{t("/generate-image",{state:{...c,autoPrompt:s,sessionTitle:s,fromAgent:!0}})}})})]})}),e.jsx(Ut,{artifact:S,title:D,isGenerating:N,onExpandChat:f?()=>d(!1):void 0,campaignTasks:q,onExecuteTask:Be,onExecuteAll:Pe,onNavigateToStudio:Oe,storeCtx:i,onArtifactAction:Ne,pipelineSteps:le,showPipeline:Q,onPipelineStepClick:He,batchGroups:F,onGenerateImage:Ge,onGenerateTexts:_e,onApproveImage:Ye,onAddSlot:Ve,showCampaignWizard:C,onCampaignWizardComplete:M,onCampaignWizardCancel:J,campaignWizardInitialTheme:R,campaignWizardContextLabel:H})]})]})}export{ao 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.