1import{u as je,b as he,j as e,r as Ce,d as Se,a as ke,c as le,f as Fe}from"./index-D_T1XJ3U.js";import{r as y}from"./vendor-react-Bxgxa9T6.js";import{u as ce}from"./useMetaApi-BKzBf-1H.js";import{u as we}from"./useAutoRefresh-80V06G0k.js";import{u as Ae,P as Re}from"./PlatformLoadingState-DJXH2Kfu.js";import{E as de}from"./auditEngine-imzxif6R.js";import{r as _e,d as _,l as $e}from"./meta-DVwYyRHl.js";import{R as M,A as Te,C as I,X as L,Y as G,a as ze,T as W,b as Pe,B as ae,c as re,d as V,P as Be,e as Me,S as We,Z as Oe,f as Ee}from"./vendor-recharts-BYQpxUtL.js";import"./planAccounts-jrtXKEQ1.js";import"./anti-flash-DA3E_D6W.js";import"./coDates-BxYjNlB-.js";const De={SHOP_NOW:"Comprar ahora",LEARN_MORE:"Más información",SIGN_UP:"Registrarse",GET_OFFER:"Recibir oferta",ORDER_NOW:"Pedir ahora",CONTACT_US:"Contactarnos",WHATSAPP_MESSAGE:"Enviar WhatsApp",MESSAGE_PAGE:"Enviar mensaje",SEE_MORE:"Ver más",NO_BUTTON:"Sin botón"};function Ie(s){return s?De[s]||String(s).replace(/_/g," ").toLowerCase().replace(/\b\w/g,l=>l.toUpperCase()):"â"}function Le(s){return!s||s<1?"$0":s>=1e6?`$${(s/1e6).toFixed(1)}M`:s>=1e3?`$${(s/1e3).toFixed(0)}k`:`$${Math.round(s)}`}function Ge(s){const l=new Map;for(const r of s){if(!r.videoId)continue;const a=r.videoId,c=l.get(a)||{video_id:a,thumbnail:r.thumbnail,ads_count:0,spend:0,purchases:0,revenue:0,roas:0,sample_ad_name:r.adName,topAdConv:-1,topAdSpend:-1};c.ads_count+=1,c.spend+=r.spend,c.purchases+=r.purchases,c.revenue+=r.revenue,!c.thumbnail&&r.thumbnail&&(c.thumbnail=r.thumbnail),(r.purchases>c.topAdConv||r.purchases===c.topAdConv&&r.spend>c.topAdSpend)&&(c.topAdConv=r.purchases,c.topAdSpend=r.spend,c.topAdCta=r.cta||null,c.topAdBody=r.body||null),l.set(a,c)}const p=[...l.values()].map(r=>({video_id:r.video_id,thumbnail:r.thumbnail,ads_count:r.ads_count,spend:r.spend,purchases:r.purchases,revenue:r.revenue,roas:r.spend>0?r.revenue/r.spend:0,sample_ad_name:r.sample_ad_name,top_cta:r.topAdCta,top_body:r.topAdBody}));return p.sort((r,a)=>a.purchases-r.purchases||a.spend-r.spend),p}function Ne(){const s=je(),{getQueryParams:l}=he(),[p,r]=y.useState([]),[a,c]=y.useState([]),[h,v]=y.useState(!0),[b,m]=y.useState(null);return y.useEffect(()=>{let u=!1;v(!0),m(null);const k=l();return Promise.allSettled([s(`/api/tiktok/materials/top?${k}&limit=10`).then(x=>x.json()),s("/api/creatives/overview?days=30&platform=meta").then(x=>x.json())]).then(([x,f])=>{if(!u){if(x.status==="fulfilled"&&x.value&&!x.value.error){const F=Array.isArray(x.value.materials)?x.value.materials:[];r(F.slice(0,5))}else r([]);if(f.status==="fulfilled"&&f.value&&Array.isArray(f.value.items)){const F=f.value.items.filter(d=>d.platform==="meta"),o=Ge(F);c(o.slice(0,5))}else c([])}}).catch(x=>{u||m(String(x))}).finally(()=>{u||v(!1)}),()=>{u=!0}},[l,s]),h?e.jsxs("div",{style:pe,children:[e.jsx(ue,{}),e.jsx("div",{style:{fontSize:12,color:"var(--text-muted)",textAlign:"center",padding:20},children:"Calculandoâ¦"})]}):!h&&p.length===0&&a.length===0?null:e.jsxs("div",{style:pe,children:[e.jsx(ue,{error:b}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(280px, 100%), 1fr))",gap:14,marginTop:12},children:[e.jsx(me,{platform:"meta",accent:"#0866FF",items:a.map(u=>({video_id:u.video_id,thumbnail:u.thumbnail||void 0,sample_ad_name:u.sample_ad_name,ads_count:u.ads_count,spend:u.spend,conversions:u.purchases,roas:u.roas,cta:u.top_cta||void 0,body:u.top_body||void 0}))}),e.jsx(me,{platform:"tiktok",accent:"#FE2C55",items:p.map(u=>({video_id:u.video_id,thumbnail:u.thumbnail_url,sample_ad_name:u.sample_ad_name,ads_count:u.ads_count,spend:u.spend,conversions:u.conversions,roas:u.roas}))})]})]})}const pe={background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:12,padding:"14px 18px",marginBottom:14};function ue({error:s}){return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:18},children:"ð"}),e.jsx("div",{style:{fontWeight:700,fontSize:14,color:"var(--text-primary)"},children:"Top videos por ventas"})]}),e.jsx("div",{style:{fontSize:11.5,color:"var(--text-muted)",marginTop:4},children:"Tus mejores videos en Meta + TikTok â con el CTA y copy del ad que más vendió. Agrupa ads por video_id para ver qué creativo gana, no qué ad."}),s&&e.jsx("div",{style:{fontSize:11,color:"#EF4444",marginTop:4},children:s})]})}function me({platform:s,accent:l,items:p}){const r=s==="meta"?"Meta":"TikTok";return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:11.5,fontWeight:700,color:l,textTransform:"uppercase",letterSpacing:"0.06em"},children:r}),p.length===0?e.jsx("div",{style:{fontSize:11.5,color:"var(--text-muted)",fontStyle:"italic",padding:10,background:"var(--bg-tertiary)",borderRadius:6},children:"Sin videos con data en este perÃodo"}):p.map((a,c)=>e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"10px 12px",borderRadius:8,background:"var(--bg-tertiary)",borderLeft:`3px solid ${l}`},children:[e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs("span",{style:{fontSize:11,fontWeight:700,color:l,width:22,flexShrink:0},children:["#",c+1]}),a.thumbnail?e.jsx("img",{src:a.thumbnail,alt:"",style:{width:36,height:46,objectFit:"cover",borderRadius:4,flexShrink:0,background:"#0F172A"},onError:h=>{h.currentTarget.style.display="none"}}):e.jsx("div",{style:{width:36,height:46,background:"#0F172A",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,fontSize:16},children:"ð¬"}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--text-primary)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:a.sample_ad_name||`Video #${a.video_id.slice(-8)}`}),e.jsxs("div",{style:{fontSize:10.5,color:"var(--text-muted)"},children:[a.ads_count," ",a.ads_count===1?"ad":"ads"," · ",a.conversions," ventas · ",Le(a.spend)]})]}),a.roas>0&&e.jsxs("div",{style:{fontSize:12,fontWeight:800,color:a.roas>=2?"#10B981":a.roas>=1?"#F59E0B":"var(--text-muted)",flexShrink:0},children:[a.roas.toFixed(1),"x"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:3,paddingLeft:30,fontSize:11},children:[a.cta&&a.cta!=="NO_BUTTON"&&e.jsxs("div",{style:{color:"var(--text-secondary)"},children:[e.jsx("span",{style:{color:"var(--text-muted)",fontWeight:600,fontSize:10,textTransform:"uppercase"},children:"CTA: "}),e.jsx("span",{style:{fontWeight:600},children:Ie(a.cta)})]}),a.body?e.jsxs("div",{style:{color:"var(--text-secondary)",lineHeight:1.4},children:[e.jsx("span",{style:{color:"var(--text-muted)",fontWeight:600,fontSize:10,textTransform:"uppercase"},children:"Copy: "}),e.jsxs("span",{style:{fontStyle:"italic"},children:['"',a.body.length>100?a.body.slice(0,100)+"â¦":a.body,'"']})]}
1):a.isSpark&&a.tiktokItemId?e.jsxs("div",{style:{color:"var(--text-muted)",fontSize:10.5,lineHeight:1.4},children:["â¡ Spark Ad â el copy vive en el"," ",e.jsx("a",{href:`https://www.tiktok.com/@user/video/${a.tiktokItemId}`,target:"_blank",rel:"noreferrer",style:{color:"#FE2C55",textDecoration:"none",fontWeight:600},children:"post original â"})]}):null]})]},a.video_id))]})}const n={blue:"#3b82f6",green:"#10B981",yellow:"#F59E0B",red:"#EF4444",purple:"#8B5CF6",orange:"#FB923C",teal:"#06B6D4",pink:"#F472B6",muted:"#64748B",metaBlue:"#1877F2"},X=[n.metaBlue,n.green,n.purple,n.orange,n.teal,n.yellow,n.pink,n.red];function R(s){return s>=1e6?`$${(s/1e6).toFixed(1)}M`:s>=1e3?`$${(s/1e3).toFixed(0)}K`:`$${s.toFixed(0)}`}const j=Fe;function E(s){return s.toLocaleString("es-CO")}function Q(s){return s>=3?n.green:s>=1.5?n.yellow:s>0?n.red:n.muted}const N={spend:{label:"Inversión",color:n.metaBlue,unit:"cop",benchmark:null},purchases:{label:"Compras",color:n.green,unit:"num",benchmark:null},cpm:{label:"CPM",color:n.yellow,unit:"cop",benchmark:7500},cpc:{label:"CPC",color:n.purple,unit:"cop",benchmark:2500},cpa:{label:"CPA",color:n.red,unit:"cop",benchmark:2e4},linkClicks:{label:"Clics destino",color:n.teal,unit:"num",benchmark:null}};function Ke(s){const p=(s.actions||[]).find(r=>r.action_type==="link_click");return parseFloat(p==null?void 0:p.value)||0}function qe(s){const l=s.actions||[],p=["purchase","offsite_conversion.fb_pixel_purchase","omni_purchase"];for(const r of p){const a=l.find(c=>c.action_type===r);if(a)return parseFloat(a.value)||0}return 0}function He(s){const l=new Map;for(const p of s){const r=p.date_start,a=l.get(r)||{fecha:r.slice(5),spend:0,purchases:0,clicks:0,linkClicks:0,impressions:0},c=(a.spend||0)+(parseFloat(p.spend)||0),h=(a.impressions||0)+(parseFloat(p.impressions)||0),v=(a.clicks||0)+(parseFloat(p.clicks)||0),b=(a.linkClicks||0)+Ke(p),m=(a.purchases||0)+qe(p),u=h>0?c/h*1e3:0,k=v>0?c/v:0,x=m>0?c/m:0;l.set(r,{date:r,fecha:r.slice(5),spend:c,purchases:m,cpm:u,cpc:k,cpa:x,clicks:v,linkClicks:b,impressions:h})}return[...l.values()].sort((p,r)=>p.date.localeCompare(r.date))}function Ue(s,l,p,r){const a=[],c=s.filter(o=>(parseFloat(o.spend)||0)>0);if(!c.length)return a;const h=c.reduce((o,d)=>o+(parseFloat(d.spend)||0),0),v=[...c].sort((o,d)=>(parseFloat(d.spend)||0)-(parseFloat(o.spend)||0));if(p.length>=2){const o=p[p.length-1],d=p[p.length-2];d.cpm>0&&o.cpm/d.cpm>1.3&&o.cpm>5500&&a.push({priority:"warning",title:`CPM subió ${Math.round((o.cpm/d.cpm-1)*100)}% hoy`,desc:`CPM pasó de ${j(d.cpm)} a ${j(o.cpm)} en un dÃa. Señal de mayor competencia o audiencia saturándose.`,action:"Revisa frecuencia. Si supera 2.5, rota creativos o amplÃa audiencia hoy mismo.",metric:`CPM hoy: ${R(o.cpm)}`}),d.cpa>0&&o.cpa>0&&o.cpa/d.cpa>1.25&&o.cpa>15e3&&a.push({priority:"warning",title:`CPA empeoró ${Math.round((o.cpa/d.cpa-1)*100)}% vs ayer`,desc:`Ayer CPA ${j(d.cpa)}, hoy ${j(o.cpa)}. El costo por compra se está disparando.`,action:"Pausa los adsets con peor CPA. Reasigna presupuesto a los adsets con ROAS ⥠3x.",metric:`CPA hoy: ${R(o.cpa)}`}),d.linkClicks>0&&o.linkClicks/d.linkClicks<.65&&a.push({priority:"warning",title:`Clics al destino cayeron ${Math.round((1-o.linkClicks/d.linkClicks)*100)}% vs ayer`,desc:`Ayer: ${E(d.linkClicks)} clics â hoy: ${E(o.linkClicks)}. CaÃda brusca puede ser fatiga de audiencia o problema técnico en la landing.`,action:"Verifica que la URL de destino carga correctamente. Si funciona, cambia el creative o el hook.",metric:`${E(o.linkClicks)} clics hoy`})}c.some(o=>_(o)>0)||a.push({priority:"critical",title:"Sin seguimiento de conversiones",desc:"No hay ROAS ni compras. Meta no puede optimizar sin P
1ixel o Conversions API.",action:"Instalar Meta Pixel + CAPI en la página de gracias del pedido",metric:"â Sin ROAS"});const b=c.filter(o=>{const d=_(o);return d>0&&d<1&&(parseFloat(o.spend)||0)>h*.05});if(b.length>0){const o=b.reduce((d,T)=>d+_(T),0)/b.length;a.push({priority:"critical",title:`${b.length} campaña${b.length>1?"s":""} con ROAS < 1x`,desc:`Gastas más de lo que retornas: ${b.slice(0,2).map(d=>le(d.campaign_name||"",r)).join(", ")}.`,action:"Pausar urgentemente o cambiar objetivo, creativos y audiencia",metric:`ROAS: ${o.toFixed(2)}x`})}const m=l.filter(o=>(parseFloat(o.frequency)||0)>4.5&&(parseFloat(o.impressions)||0)>1e3);if(m.length>0){const o=Math.max(...m.map(d=>parseFloat(d.frequency)||0));a.push({priority:"warning",title:`Fatiga de audiencia â ${m.length} conjunto${m.length>1?"s":""}`,desc:"Frecuencia > 4.5 en Colombia indica saturación.",action:"Ampliar audiencias, agregar exclusiones o rotar creativos",metric:`Frec. máx: ${o.toFixed(1)}`})}const u=c.filter(o=>(parseFloat(o.impressions)||0)>5e3&&(parseFloat(o.ctr)||0)<.5);if(u.length>0){const o=Math.min(...u.map(d=>parseFloat(d.ctr)||0));a.push({priority:"warning",title:"Creativos con CTR bajo",desc:`${u.length} campaña${u.length>1?"s":""} con CTR < 0.5% (benchmark Colombia: 0.8â2%).`,action:"Probar videos UGC cortos (15â30s) y testimonios de clientes colombianos",metric:`CTR mÃn: ${o.toFixed(2)}%`})}if(v.length>2){const o=(parseFloat(v[0].spend)||0)/h*100;o>65&&a.push({priority:"warning",title:"Alta concentración de presupuesto",desc:`"${le((v[0].campaign_name||"").slice(0,35),r)}" concentra el ${o.toFixed(0)}% del gasto.`,action:"Distribuir en 3â5 campañas. Ninguna deberÃa superar el 40%",metric:`${o.toFixed(0)}% en 1 campaña`})}const k=c.filter(o=>_(o)>=3);if(k.length>0){const o=k.reduce((d,T)=>d+(parseFloat(T.spend)||0),0)/h*100;o<40&&a.push({priority:"opportunity",title:"Escalar campañas ganadoras (ROAS ⥠3x)",desc:`Solo el ${o.toFixed(0)}% del presupuesto está en campañas rentables.`,action:"Aumentar presupuesto 20â30% cada 3â4 dÃas sin cambiar nada más",metric:`${k.length} campaña${k.length>1?"s":""} ROAS ⥠3x`})}const x=c.reduce((o,d)=>o+(parseFloat(d.impressions)||0),0),f=c.reduce((o,d)=>o+(parseFloat(d.spend)||0),0),F=x>0?f/x*1e3:0;return F>25e3&&a.push({priority:"info",title:"CPM alto vs benchmark Colombia",desc:`CPM promedio ${j(F)} supera el rango normal ($8Kâ$20K COP).`,action:"Usar Advantage+ Audiences o ampliar a ciudades secundarias",metric:`CPM: ${R(F)}`}),a.sort((o,d)=>({critical:0,warning:1,opportunity:2,info:3})[o.priority]-{critical:0,warning:1,opportunity:2,info:3}[d.priority])}function K({title:s,subtitle:l,children:p,fullWidth:r=!1,guia:a}){return e.jsxs("div",{"data-guia":a,style:{background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:12,padding:"20px 22px",gridColumn:r?"1 / -1":void 0},children:[e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontWeight:700,fontSize:"0.93em",color:"var(--text-primary)"},children:s}),l&&e.jsx("div",{style:{fontSize:"0.75em",color:"var(--text-muted)",marginTop:3},children:l})]}),p]})}function Ve({ins:s}){const l={critical:{color:n.red,bg:"rgba(239,68,68,0.07)",icon:"!",badge:"CrÃtico"},warning:{color:n.yellow,bg:"rgba(245,158,11,0.07)",icon:"â ",badge:"Atención"},opportunity:{color:n.green,bg:"rgba(16,185,129,0.07)",icon:"â",badge:"Oportunidad"},info:{color:n.blue,bg:"rgba(59,130,246,0.07)",icon:"i",badge:"Info"}}[s.priority];return e.jsxs("div",{style:{background:l.bg,borderRadius:10,border:`1px solid ${l.color}35`,borderLeft:`4px solid ${l.color}`,padding:"13px 16px"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:8,marginBottom:6},children:[e.jsxs("div",{style:{fontWeight:700,fontSize:"0.87em",color:"var(--text-primary)",display:"flex",gap:6,alignItems:"center"},children:[e.jsx("span",{style:{width:16,height:16,borderRadius:"50%",background:l.color,color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:900,flexShrink:0},children:l.icon}),e.jsx("span",{children:s.title})]}),s.metric&&e.jsx("span",{style:{fontSize:"0.70em",color:l.color,fontWeight:700,background:`${l.color}20`,padding:"2px 8px",borderRadius:20,whiteSpace:"nowrap",flexShrink:0},children:s.metric})]}),e.jsx("div",{style:{fontSize:"0.80em",color:"var(--text-secondary)",lineHeight:1.55,marginBottom:8},children:s.desc}),e.jsxs("div",{style:{fontSize:"0.76em",color:l.color,fontWeight:700},children:["â ",s.action]})]})}function Xe({current:s,previous:l,unit:p,invertGood:r=!1}){if(!l||l===0)return e.jsx("span",{style:{fontSize:11,color:"var(--text-muted)"},children:"â"});const a=(s-l)/l*100,c=r?a<0:a>0,h=Math.abs(a)<1?n.muted:c?n.green:n.red,v=a>0?"â":a<0?"â":"â";return e.jsxs("span",{style:{fontSize:11,fontWeight:700,color:h,background:`${h}18`,borderRadius:20,padding:"2px 7px"},children:[v," ",Math.abs(a).toFixed(1),"% vs ayer"]})}const O={background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:8,fontSize:"0.82em"},$={fontSize:10,fill:"var(--text-muted)"};function lt(){var ne;const{selectedAccounts:s}=Ce(),{getQueryParams:l}=he(),{refreshKey:p}=Se(),{isHidden:r}=ke(),a=we(3e4),{data:c,loading:h}=ce("campaigns"),{data:v,loading:b}=ce("adsets"),[m,u]=y.useState([]),[k,x]=y.useState(!1);Ae("meta",h||b||k);const[f,F]=y.useState("spend"),[o,d]=y.useState(!1);y.useEffect(()=>{const t=i=>{const g=i.detail;(g==null?void 0:g.tipo)==="analytics-consejos"&&(d(!0),g.consumido=!0)};return window.addEventListener("lumy:guia-ir",t),()=>window.removeEventListener("lumy:guia-ir",t)},[]);const T=y.useRef(!1);y.useEffect(()=>{if(!s.length)return;T.current||x(!0);const t=l();Promise.all(s.map(i=>fetch(`/api/accounts/${i.id}/insights/timeseries?${t}`).then(g=>g.json()).then(g=>g.data||[]).catch(()=>[]))).then(i=>{u(He(i.flat()))}).finally(()=>{x(!1),T.current=!0})},[s.map(t=>
1t.id).join(","),l,p,a]);const z=c||[],oe=v||[],Y=y.useMemo(()=>Ue(z,oe,m,r),[z,oe,m,r]),w=y.useMemo(()=>z.filter(t=>(parseFloat(t.spend)||0)>0),[z]),D=w.reduce((t,i)=>t+(parseFloat(i.spend)||0),0),se=w.reduce((t,i)=>t+(parseFloat(i.impressions)||0),0),Z=w.reduce((t,i)=>t+(parseFloat(i.clicks)||0),0),P=_e(w),xe=P.mezcla?0:P.value,B=(()=>{const t=w.filter(i=>_(i)>0);return t.length?t.reduce((i,g)=>i+_(g),0)/t.length:0})(),q=se>0?Z/se*100:0,ge=Z>0?D/Z:0,ie=P.mezcla?0:P.cost,C=y.useMemo(()=>[...w].sort((t,i)=>(parseFloat(i.spend)||0)-(parseFloat(t.spend)||0)).slice(0,12).map(t=>({name:(t.campaign_name||"Sin nombre").slice(0,28),gasto:parseFloat(t.spend)||0,ctr:parseFloat(t.ctr)||0,roas:_(t),resultados:$e(t).value})),[w]),J=y.useMemo(()=>C.slice(0,8).map(t=>({name:t.name,value:t.gasto,pct:D>0?(t.gasto/D*100).toFixed(1):"0"})),[C,D]),ee=y.useMemo(()=>w.filter(t=>(parseFloat(t.impressions)||0)>500).map(t=>({name:(t.campaign_name||"").slice(0,22),ctr:parseFloat(t.ctr)||0,cpc:parseFloat(t.cpc)||0,gasto:parseFloat(t.spend)||0,roas:_(t)})),[w]),H=m.length>=1?m[m.length-1]:null,U=m.length>=2?m[m.length-2]:null,S=N[f],fe=m.map(t=>({...t,value:t[f]}));
1return(h||b)&&!z.length?e.jsx(Re,{platform:"meta"}):z.length?e.jsxs("div",{style:{paddingBottom:48},children:[e.jsx(Ne,{}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 150px), 1fr))",gap:12,marginBottom:20},children:[{label:"Gasto Total",value:j(D),sub:`${w.length} campañas activas`,color:void 0},{label:"ROAS Promedio",value:B>0?`${B.toFixed(2)}x`:"â",sub:B>=3?"â Rentable":B>1?"â Mejorar":"â Sin datos",color:B>=3?n.green:B>0?n.yellow:n.muted},{label:"CTR Promedio",value:`${q.toFixed(2)}%`,sub:q>=1.5?"â Buen creativo":"â Mejorar creativos",color:q>=1.5?n.green:q>=.8?n.yellow:n.red},{label:"CPC Promedio",value:j(ge),sub:"por click",color:void 0},{label:"Costo / Resultado",value:ie>0?j(ie):"â",sub:P.mezcla?"Resultados de tipos distintos: mira cada campaña":`${xe.toLocaleString("es-CO")} ${(P.label||"resultados").toLowerCase()}`,color:void 0}].map(t=>e.jsxs("div",{style:{background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:10,padding:"14px 16px"},children:[e.jsx("div",{style:{fontSize:"0.69em",color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:6},children:t.label}),e.jsx("div",{style:{fontSize:"1.35em",fontWeight:800,color:t.color||"var(--text-primary)",lineHeight:1.1},children:t.value}),e.jsx("div",{style:{fontSize:"0.71em",color:t.color||"var(--text-secondary)",marginTop:5},children:t.sub})]},t.label))}),m.length>1&&e.jsxs("div",{"data-guia":"analytics.tendencia",style:{background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:12,padding:"20px 22px",marginBottom:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,marginBottom:16,flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:700,fontSize:"0.95em",color:"var(--text-primary)"},children:"Tendencia de métricas"}),e.jsxs("div",{style:{fontSize:"0.75em",color:"var(--text-muted)",marginTop:2},children:["Evolución diaria · Datos desde ",(ne=m[0])==null?void 0:ne.date]})]}),H&&U&&e.jsx(Xe,{current:H[f],previous:U[f],unit:S.unit,invertGood:f==="cpm"||f==="cpc"||f==="cpa"})]}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginBottom:16},children:Object.keys(N).map(t=>{const i=N[t],g=f===t;return e.jsx("button",{onClick:()=>F(t),style:{padding:"5px 13px",borderRadius:20,fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:"inherit",border:`1px solid ${g?i.color:"var(--border)"}`,background:g?`${i.color}15`:"transparent",color:g?i.color:"var(--text-muted)",transition:"all 0.15s"},children:i.label},t)})}),e.jsx(M,{width:"100%",height:230,children:e.jsxs(Te,{data:fe,margin:{top:6,right:20,bottom:0,left:10},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"metricGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:S.color,stopOpacity:.25}),e.jsx("stop",{offset:"95%",stopColor:S.color,stopOpacity:0})]})}),e.jsx(I,{strokeDasharray:"3 3",stroke:"var(--border)"}),e.jsx(L,{dataKey:"fecha",tick:$}),e.jsx(G,{tickFormatter:t=>S.unit==="cop"?R(t):E(t),tick:$,width:72}),S.benchmark&&e.jsx(ze,{y:S.benchmark,stroke:n.red,strokeDasharray:"5 3",strokeOpacity:.7,label:{value:`LÃmite ${R(S.benchmark)}`,fill:n.red,fontSize:10,position:"insideTopRight"}}),e.jsx(W,{formatter:t=>[S.unit==="cop"?j(t):E(t),S.label],contentStyle:O,labelStyle:{color:"var(--text-primary)",fontWeight:600}}),e.jsx(Pe,{type:"monotone",dataKey:"value",stroke:S.color,strokeWidth:2.5,fill:"url(#metricGrad)",dot:{r:3,fill:S.color,strokeWidth:0},activeDot:{r:5}})]})}),H&&U&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 105px), 1fr))",gap:10,marginTop:16,paddingTop:14,borderTop:"1px solid var(--border)"},children:Object.keys(N).map(t=>{const i=N[t],g=H[t],te=U[t],A=te>0?(g-te)/te*100:null,ye=A!==null&&(t==="cpm"||t==="cpc"||t==="cpa"?A<0:A>0),ve=A===null||Math.abs(A)<1?n.muted:ye?n.green:n.red,be=A===null?"":A>.5?"â":A<-.5?"â":"â";return e.jsxs("div",{onClick:()=>F(t),style:{textAlign:"center",cursor:"pointer",padding:"8px 4px",borderRadius:8,background:f===t?`${i.color}10`:"transparent",border:`1px solid ${f===t?i.color+"40":"transparent"}`,transition:"all 0.15s"}
1,children:[e.jsx("div",{style:{fontSize:10,color:"var(--text-muted)",marginBottom:3},children:i.label}),e.jsx("div",{style:{fontSize:13,fontWeight:800,color:i.color},children:i.unit==="cop"?R(g):E(g)}),e.jsx("div",{style:{fontSize:10,fontWeight:700,color:ve,marginTop:2},children:A!==null?`${be} ${Math.abs(A).toFixed(1)}%`:"â"})]},t)})})]}),Y.length>0&&e.jsxs("div",{"data-guia":"analytics.alertas",style:{marginBottom:16},children:[e.jsxs("div",{style:{fontWeight:800,fontSize:"0.95em",color:"var(--text-primary)",marginBottom:10,display:"flex",alignItems:"center",gap:8},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent-blue)",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 8v4l3 3"})]}),"Alertas de rendimiento",e.jsxs("span",{style:{fontSize:"0.73em",color:"var(--text-muted)",fontWeight:400},children:[Y.length," basadas en tu data de hoy"]})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(100%, 330px), 1fr))",gap:10},children:Y.map((t,i)=>e.jsx(Ve,{ins:t},i))})]}),e.jsxs("div",{style:{marginBottom:20},children:[e.jsxs("button",{"data-guia":"analytics.consejos",onClick:()=>d(t=>!t),style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 16px",background:"var(--bg-card)",border:"1px solid var(--border)",borderRadius:o?"10px 10px 0 0":10,cursor:"pointer",fontFamily:"inherit"},children:[e.jsxs("span",{style:{fontWeight:700,fontSize:"0.88em",color:"var(--text-primary)",display:"flex",alignItems:"center",gap:7},children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:n.metaBlue,strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4M12 8h.01"})]}),"Consejos de expertos â Colombia COD",e.jsxs("span",{style:{fontSize:11,fontWeight:400,color:"var(--text-muted)"},children:[de.length," reglas esenciales"]})]}),e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-muted)",strokeWidth:"2",style:{transform:o?"rotate(180deg)":"none",transition:"transform 0.2s",flexShrink:0},children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),o&&e.jsx("div",{style:{background:"var(--bg-card)",border:"1px solid var(--border)",borderTop:"none",borderRadius:"0 0 10px 10px",padding:"12px 16px",display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(min(100%, 300px), 1fr))",gap:10},children:de.map(t=>e.jsxs("div",{style:{background:"rgba(24,119,242,0.05)",border:"1px solid rgba(24,119,242,0.15)",borderLeft:`4px solid ${n.metaBlue}`,borderRadius:8,padding:"11px 14px"},children:[e.jsx("div",{style:{fontWeight:700,fontSize:"0.84em",color:"var(--text-primary)",marginBottom:5},children:t.title}),e.jsx("div",{style:{fontSize:"0.77em",color:"var(--text-secondary)",lineHeight:1.5,marginBottom:7},children:t.description}),e.jsxs("div",{style:{fontSize:"0.74em",color:n.metaBlue,fontWeight:700},children:["â ",t.action]})]},t.id))})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 340px), 1fr))",gap:16},children:[e.jsx(K,{guia:"analytics.ranking",title:"Ranking de Campañas por Gasto",subtitle:"Color = ROAS: verde ⥠3x | amarillo 1.5â3x | rojo < 1.5x",children:e.jsx(M,{width:"100%",height:Math.max(220,C.length*34),children:e.jsxs(ae,{data:C,layout:"vertical",margin:{left:4,right:52},children:[e.jsx(I,{strokeDasharray:"3 3",stroke:"var(--border)",horizontal:!1}),e.jsx(L,{type:"number",tickFormatter:t=>R(t),tick:$}),e.jsx(G,{type:"category",dataKey:"name",tick:{fontSize:10.5,fill:"var(--text-secondary)"},width:134}),e.jsx(W,{formatter:t=>[j(t),"Gasto"],contentStyle:O}),e.jsx(re,{dataKey:"gasto",radius:[0,5,5,0],label:{position:"right",formatter:t=>R(t),fontSize:10,fill:"var(--text-muted)"},children:C.map((t,i)=>e.jsx(V,{fill:Q(t.roas)},i))})]})})}),e.jsx(K,{guia:"analytics.presupuesto",title:"Distribución del Presupuesto",subtitle:"Porcentaje del gasto total por campaña",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:20},children:[e.jsx(M,{width:180,height:180,style:{flexShrink:0},children:e.jsxs(Be,{children:[e.jsx(Me,{data:J,dataKey:"value",cx:"50%",cy:"50%",innerRadius:46,outerRadius:80,paddingAngle:2,children:J.map((t,i)=>e.jsx(V,{fill:X[i%X.length]},i))}),e.jsx(W,{formatter:t=>j(t),contentStyle:O})]})}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:7},children:J.map((t,i)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:"0.78em"},children:[e.jsx("span",{style:{width:9,height:9,borderRadius:"50%",background:X[i%X.length],flexShrink:0}}),e.jsx("span",{className:"censor-blur",style:{color:"var(--text-secondary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.name}),e.jsxs("span",{style:{color:"var(--text-primary)",fontWeight:700,marginLeft:4},children:[t.pct,"%"]})]},i))})]})}),e.jsx(K,{guia:"analytics.ctr",title:"CTR por Campaña",subtitle:"Benchmark Colombia: 0.8â2% | Verde ⥠1.5% | Amarillo 0.8â1.5% | Rojo < 0.8%",children:e.jsx(M,{width:"100%",height:Math.max(220,C.length*34),children:e.jsxs(ae,{data:C,layout:"vertical",margin:{left:4,right:52},children:[e.jsx(I,{strokeDasharray:"3 3",stroke:"var(--border)",horizontal:!1}),e.jsx(L,{type:"number",tickFormatter:t=>`${t.toFixed(1)}%`,tick:$}),e.jsx(G,{type:"category",dataKey:"name",tick:{fontSize:10.5,fill:"var(--text-secondary)"},width:134}),e.jsx(W,{formatter:t=>[`${t.toFixed(2)}%`,"CTR"],contentStyle:O}
1),e.jsx(re,{dataKey:"ctr",radius:[0,5,5,0],label:{position:"right",formatter:t=>`${t.toFixed(1)}%`,fontSize:10,fill:"var(--text-muted)"},children:C.map((t,i)=>e.jsx(V,{fill:t.ctr>=1.5?n.green:t.ctr>=.8?n.yellow:n.red},i))})]})})}),ee.length>1&&e.jsx(K,{guia:"analytics.eficiencia",title:"Eficiencia: CTR vs CPC",subtitle:"Ideal = alto CTR + bajo CPC (esquina sup. izquierda). Tamaño = gasto. Color = ROAS",fullWidth:!0,children:e.jsx(M,{width:"100%",height:280,children:e.jsxs(We,{margin:{top:10,right:30,bottom:20,left:10},children:[e.jsx(I,{strokeDasharray:"3 3",stroke:"var(--border)"}),e.jsx(L,{type:"number",dataKey:"ctr",name:"CTR",unit:"%",label:{value:"CTR (%)",position:"insideBottom",offset:-10,fill:"var(--text-muted)",fontSize:11},tick:$}),e.jsx(G,{type:"number",dataKey:"cpc",name:"CPC",tickFormatter:t=>R(t),label:{value:"CPC (COP)",angle:-90,position:"insideLeft",fill:"var(--text-muted)",fontSize:11,offset:10},tick:$}),e.jsx(Oe,{type:"number",dataKey:"gasto",range:[60,700]}),e.jsx(W,{content:({payload:t})=>{if(!(t!=null&&t.length))return null;const i=t[0].payload;return e.jsxs("div",{style:{...O,padding:"10px 14px"},children:[e.jsx("div",{className:"censor-blur",style:{fontWeight:700,color:"var(--text-primary)",marginBottom:5,fontSize:"0.85em"},children:i.name}),e.jsxs("div",{style:{color:"var(--text-secondary)"},children:["CTR: ",e.jsxs("b",{style:{color:"var(--text-primary)"},children:[i.ctr.toFixed(2),"%"]})]}),e.jsxs("div",{style:{color:"var(--text-secondary)"},children:["CPC: ",e.jsx("b",{style:{color:"var(--text-primary)"},children:j(i.cpc)})]}),e.jsxs("div",{style:{color:"var(--text-secondary)"},children:["Gasto: ",e.jsx("b",{style:{color:"var(--text-primary)"},children:j(i.gasto)})]}),i.roas>0&&e.jsxs("div",{style:{color:Q(i.roas)},children:["ROAS: ",e.jsxs("b",{children:[i.roas.toFixed(2),"x"]})]})]})}}),e.jsx(Ee,{data:ee,fillOpacity:.85,children:ee.map((t,i)=>e.jsx(V,{fill:Q(t.roas)!==n.muted?Q(t.roas):n.blue},i))})]})})}),C.some(t=>t.resultados>0)&&e.jsx(K,{guia:"analytics.resultados",title:"Resultados por Campaña",subtitle:"Compras, leads o mensajes según el objetivo de cada campaña",fullWidth:!0,children:e.jsx(M,{width:"100%",height:Math.max(200,C.filter(t=>t.resultados>0).length*34),children:e.jsxs(ae,{data:C.filter(t=>t.resultados>0),layout:"vertical",margin:{left:4,right:52},children:[e.jsx(I,{strokeDasharray:"3 3",stroke:"var(--border)",horizontal:!1}),e.jsx(L,{type:"number",tick:$}),e.jsx(G,{type:"category",dataKey:"name",tick:{fontSize:10.5,fill:"var(--text-secondary)"},width:134}),e.jsx(W,{formatter:t=>[t.toLocaleString("es-CO"),"Resultados"],contentStyle:O}),e.jsx(re,{dataKey:"resultados",fill:n.metaBlue,radius:[0,5,5,0],label:{position:"right",formatter:t=>t.toLocaleString("es-CO"),fontSize:10,fill:"var(--text-muted)"}})]})})})]})]}):e.jsxs("div",{className:"empty-state",style:{margin:24},children:[e.jsx("div",{className:"empty-state-icon",children:"ð"}),e.jsx("div",{className:"empty-state-text",children:"No hay datos para el periodo seleccionado"})]})}export{lt as AnalyticsTab};
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.