1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TestDailyChart-c-9JH-NV.js","assets/vendor-react-87lNhmqv.js","assets/vendor-chartjs-CgShpUIc.js","assets/vendor-utils-CSdigHS_.js","assets/entry-index-B4RPR3dx.js","assets/vendor-router-redux-Do1y_xNy.js","assets/vendor-coreui-Cc5WkQnZ.js","assets/vendor-bootstrap-bijw23mo.js","assets/vendor-coreui-icons-react-DfZWo1Q6.js","assets/vendor-coreui-icons-free-ZIJJcQni.js","assets/vendor-coreui-DU-Z7rcY.css","assets/vendor-pdf-Dmcacx79.js","assets/vendor-babel-runtime-IHHeZ7Hj.js","assets/vendor-6ao90-wn.js","assets/vendor-antv-RN0G9Fj6.js","assets/vendor-B3iFcTj7.css","assets/vendor-firebase-core-DW6o-vOC.js","assets/vendor-firebase-auth-CBjaag58.js","assets/vendor-firebase-firestore--_xCzqNR.js","assets/vendor-react-icons-BvLNRFpc.js","assets/index-B3ZRnGq7.css","assets/useClipboard-Dq5X1go9.js","assets/vendor-coreui-icons-pro-CrW9ZyFZ.js","assets/vendor-ui-aux-DCdKH07M.js","assets/useClipboard-BvAs5NN-.css","assets/financialFormulas-BWNpQuoi.js","assets/Eduzz-BnMy8cX5.js"])))=>i.map(i=>d[i]); 2import{r as m,j as e}from"./vendor-react-87lNhmqv.js";import{c as B,b as ze,S as qe,A as Fe,a as Ve}from"./AdminChurnRisk-BwlvrEQf.js";import{P as i}from"./vendor-utils-CSdigHS_.js";import{e as $,f as I}from"./financialFormulas-BWNpQuoi.js";import{O as Be,P as Me,Q as We,S as Ee,l as R,E,ah as ue,n as me,F as pe,p as he,t as ee,v as te,w as F,x as f,y as re,z as _,C as K,g as Oe}from"./vendor-coreui-Cc5WkQnZ.js";import{_ as Ie}from"./vendor-pdf-Dmcacx79.js";import{r as He}from"./entry-index-B4RPR3dx.js";import{c as Ue,p as Ge,E as Xe}from"./useClipboard-Dq5X1go9.js";const L="https://bff.roigenius.ai",Ke=t=>{const r=new URLSearchParams;return Object.entries(t||{}).forEach(([s,n])=>{n!=null&&n!==""&&r.set(s,String(n))}),r.size?`?${r}`:""},Je=async t=>{const r=await fetch(`${L}/admin-testeab${Ke(t)}`);if(!r.ok)throw Object.assign(new Error("fetch-tests"),{status:r.status});return r.json()},Qe=async t=>{const r=await fetch(`${L}/admin-testeab/${encodeURIComponent(t)}`);if(!r.ok)throw Object.assign(new Error("fetch-test-detail"),{status:r.status});return r.json()},Ye=async t=>{const r=await fetch(`${L}/admin-testeab/${encodeURIComponent(t)}/export`);if(!r.ok)throw Object.assign(new Error("export-test-detail"),{status:r.status});return r.blob()},Ze=async()=>{const t=await fetch(`${L}/admin-testeab/snapshot-dates`);if(!t.ok)throw Object.assign(new Error("fetch-snapshot-dates"),{status:t.status});return t.json()},et=async()=>{const t=await fetch(`${L}/admin-testeab/head-to-head`);if(!t.ok)throw Object.assign(new Error("fetch-head-to-head"),{status:t.status});return t.json()},tt=async()=>{const t=await fetch(`${L}/admin-testeab/benchmark`);if(!t.ok)throw Object.assign(new Error("fetch-benchmark"),{status:t.status});return t.json()},rt=async t=>{const s=await fetch(`${L}/admin-testeab/cron/snapshot`,{method:"POST"});if(!s.ok)throw Object.assign(new Error("trigger-snapshot"),{status:s.status});return s.json()},st=(t,r)=>{const s=["Teste","Seller","Plataforma Focal","Plataforma Concorrente","Status","Cliques","Conv%","RPC Focal","RPC Concorrente","Veredicto","Anomaly Score","Divergência CR vs RPC"],n=d=>`"${String(d??"").replace(/"/g,'""')}"`,a=[s.map(n).join(","),...t.map(d=>[d.test_name||d.test_id,d.seller_name||d.user_id,d.focal_platform,d.competitor_platform,d.status,d.total_clicks,d.conv_pct??"",d.rpc_focal??"",d.rpc_competitor??"",d.verdict_label??"",d.anomaly_score??"",d.coherence_flag?"sim":"nao"].map(n).join(","))],l=new Blob(["\uFEFF"+a.join(` 3`)],{type:"text/csv;charset=utf-8;"}),o=URL.createObjectURL(l),c=document.createElement("a");c.href=o,c.download=`testeab-snapshot-${r??"export"}.csv`,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(o)},ae={status:"",platform:"",seller:"",search:"",order_by:"total_clicks",direction:"desc"},nt=()=>{const[t,r]=m.useState(ae),[s,n]=m.useState(null),[a,l]=m.useState([]),[o,c]=m.useState(!1),d=a[0]??(s==null?void 0:s.snapshot_date)??null,[j,p]=m.useState(null),[u,x]=m.useState(null),[b,h]=m.useState(!1),[C,N]=m.useState(null),[k,S]=m.useState(!1),w=m.useRef(null),v=m.useCallback(async g=>{c(!0),p(null);try{const P={...t,...g},D=await Je(P);n(D)}catch(P){p(P)}finally{c(!1)}},[t]),y=m.useCallback(async()=>{try{const g=await Ze();l(g.dates||[])}catch(g){p(g)}},[]);m.useEffect(()=>{y()},[y]),m.useEffect(()=>
3{v()},[v]);const T=(g,P)=>{if(g==="search"){clearTimeout(w.current),w.current=setTimeout(()=>{r(D=>({...D,search:P,offset:"0"}))},300);return}r(D=>({...D,[g]:P}))},z=()=>r(ae),V=m.useCallback(async g=>Qe(g),[]),H=m.useCallback(async()=>{h(!0);try{const g=await et();x(g)}catch{x(null)}finally{h(!1)}},[]),U=m.useCallback(async()=>{S(!0);try{const g=await tt();N(g)}catch{N(null)}finally{S(!1)}},[]);return{filters:t,updateFilter:T,resetFilters:z,data:s,latestSnapshotDate:d,loading:o,error:j,reload:v,loadDetail:V,headToHead:u,headToHeadLoading:b,loadHeadToHead:H,benchmark:C,benchmarkLoading:k,loadBenchmark:U}},M=t=>{if(t==null||t==="")return null;const r=Number(t);return Number.isFinite(r)?r:null},se=t=>{const r=M(t==null?void 0:t.total_clicks);if(!r||r<=0)return null;const s=M(t==null?void 0:t.rpc_focal),n=M(t==null?void 0:t.rpc_competitor);return s===null||n===null?null:s>n?"focal":s<n?"competitor":"tie"},at=(t=[])=>{let r=0,s=0;for(const a of t){const l=se(a);l==="focal"?r+=1:l==="competitor"&&(s+=1)}const n=r+s;return n===0?null:r/n*100},ot=(t=[])=>t.reduce((r,s)=>r+(M(s==null?void 0:s.total_clicks)>0?1:0),0),lt=(t=[])=>{const r=new Map;for(const s of t){const n=se(s);if(n===null)continue;const a=(s==null?void 0:s.focal_platform)||null,l=(s==null?void 0:s.competitor_platform)||null;if(!a||!l)continue;const o=`${a}\0${l}`;r.has(o)||r.set(o,{focal_platform:a,competitor_platform:l,focal_wins:0,competitor_wins:0,ties:0,n_decided:0});const c=r.get(o);n==="focal"?c.focal_wins+=1:n==="competitor"?c.competitor_wins+=1:c.ties+=1,c.n_decided+=1}return Array.from(r.values()).sort((s,n)=>n.n_decided-s.n_decided)},it=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`${r.toFixed(1)}%`},fe=({totals:t=null,snapshotDate:r=null,rows:s=[]})=>{if(!t)return null;const n=t.active??0,a=t.finished??0,l=t.rpc_avg!=null?$(t.rpc_avg):"â",o=ot(s),c=at(s);return e.jsxs("div",{className:"admin-kpi-grid",children:[e.jsx(B,{label:"Testes ativos",value:n,tooltip:`snapshot ${r||"â"}`}),e.jsx(B,{label:"Testes finalizados",value:a}),e.jsx(B,{label:"Testes com tráfego",value:o,tooltip:"Testes com pelo menos 1 clique â os demais não têm sinal ainda"}),e.jsx(B,{label:"RPC médio",value:l,tooltip:"Receita por Clique â média global dos testes"}),e.jsx(B,{label:"Win-rate direcional",value:c!=null?it(c):"â",tooltip:"Preliminar â % de testes decididos em que a plataforma focal tem RPC maior. Não é teste de significância (dados de variância ainda ausentes no backend)."})]})};fe.propTypes={totals:i.object,snapshotDate:i.string,rows:i.array};const ct=[{value:"",label:"Todos os status"},{value:"active",label:"Ativo"},{value:"finished",label:"Finalizado"},{value:"paused",label:"Pausado"}],dt=[{value:"",label:"Todas as plataformas"},{value:"meta",label:"Meta Ads"},{value:"google",label:"Google Ads"},{value:"tiktok",label:"TikTok Ads"},{value:"bing",label:"Bing Ads"}],xe=({filters:t,latestSnapshotDate:r,updateFilter:s,resetFilters:n})=>e.jsxs("div",{className:"admin-testeab__filters",children:[e.jsxs("span",{className:"admin-testeab__snapshot-indicator",title:"Data da última atualização dos dados",children:["Ãltima atualização: ",e.jsx("strong",{children:r??"â"})]}),e.jsx("select",{value:t.status||"",onChange:a=>s("status",a.target.value),children:ct.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx("select",{value:t.platform||"",onChange:a=>s("platform",a.target.value),children:dt.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx("input",{type:"search",placeholder:"Buscar teste ou seller","aria-label":"Buscar teste ou seller",value:t.search||"",onChange:a=>s("search",a.target.value),style:{flex:"1 1 200px",minWidth:160}}),e.jsx("input",{type:"text",placeholder:"Seller","aria-label":"Filtrar por seller",value:t.seller||"",onChange:a=>s("seller",a.target.value),style:{width:140}}),e.jsx("button",{type:"button",onClick:n,className:"btn btn-sm btn-outline-secondary",children:"Limpar"})]});xe.propTypes={filters:i.object.isRequired,latestSnapshotDate:i.string,updateFilter:i.func.isRequired,resetFilters:i.func.isRequired};const ge="admin-testeab-columns",oe=t=>
3Number(t??0).toLocaleString("pt-BR",{style:"currency",currency:"BRL",maximumFractionDigits:2}),be=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":r===0?"0%":r<.01?"<0.01%":r<.1?`${r.toFixed(3)}%`:`${r.toFixed(2)}%`},le={danger:.7,warn:.4},_e=({score:t=null})=>{if(t==null)return e.jsx("span",{style:{color:"var(--cui-secondary-color)"},children:"â"});const r=Number(t);if(Number.isNaN(r))return e.jsx("span",{style:{color:"var(--cui-secondary-color)"},children:"â"});const s=r>=le.danger?"var(--cui-danger)":r>=le.warn?"var(--cui-warning)":"var(--cui-success)";return e.jsx("span",{style:{color:s,fontWeight:600,fontVariantNumeric:"tabular-nums"},title:`Anomaly score: ${r.toFixed(2)}`,children:r.toFixed(2)})};_e.propTypes={score:i.oneOfType([i.string,i.number])};const ut={focal:{label:"Focal lidera",color:"var(--cui-success)"},competitor:{label:"Concorrente lidera",color:"var(--cui-danger)"},tie:{label:"Empate",color:"var(--cui-secondary-color)"}},je=({row:t})=>{const r=se(t);if(r===null)return e.jsx("span",{style:{color:"var(--cui-secondary-color)"},children:"Sem dados"});const{label:s,color:n}=ut[r];return e.jsxs("span",{style:{color:n,fontWeight:600,fontSize:"0.78rem"},title:"Leitura direcional preliminar (RPC focal vs concorrente) â não é teste de significância",children:[s,e.jsx("span",{style:{color:"var(--cui-secondary-color)",fontWeight:400},children:" · prelim"})]})};je.propTypes={row:i.object.isRequired};const J=({value:t})=>!t||String(t).toLowerCase()==="unknown"?e.jsx("span",{style:{color:"var(--cui-secondary-color)",fontStyle:"italic"},title:"Plataforma de checkout não identificada a partir da URL",children:"Não identificada"}):t;J.propTypes={value:i.string};const ye=({value:t})=>{const r=Number(t),s=be(t);return!Number.isNaN(r)&&r>100?e.jsxs("span",{style:{color:"var(--cui-warning)",fontWeight:600},title:"Conv% > 100%: cliques contam apenas redirects do Worker (Cloudflare DO), mas aprovações incluem tráfego orgânico que chega diretamente à URL de checkout â fontes incommensuráveis.",children:[s," â "]}):s};
3ye.propTypes={value:i.oneOfType([i.string,i.number])};const mt=t=>Number(t.total_clicks??0)<=0&&!t.focal_platform&&!t.competitor_platform,pt=t=>{if(!(!t||!t.length))return t.map(r=>`${r.arm_label||r.variant_url||`Braço ${r.arm_index}`} â ${r.n_clicks??"?"} cliques`).join(` 4`)},W=({arms:t,getValue:r})=>!t||!t.length?e.jsx("span",{style:{color:"var(--cui-secondary-color)"},children:"â"}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:1},children:t.map((s,n)=>{const a=s.arm_label||s.variant_url||`Braço ${s.arm_index}`,l=a.length>20?a.slice(0,18)+"â¦":a;return e.jsxs("div",{style:{fontSize:"0.72rem",lineHeight:1.4},title:a,children:[e.jsxs("span",{style:{color:"var(--cui-secondary-color)"},children:[l,": "]}),e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:r(s)})]},n)})});W.propTypes={arms:i.array,getValue:i.func.isRequired};const ve=[{id:"arm_clicks",label:"Cliques por variante",column:{key:"arm_clicks",label:"Cliques/var.",render:t=>e.jsx(W,{arms:t.arms,getValue:r=>r.n_clicks??"â"})}},{id:"arm_conv",label:"Conv% por variante",column:{key:"arm_conv",label:"Conv%/var.",render:t=>e.jsx(W,{arms:t.arms,getValue:r=>r.conv_pct!=null?be(Number(r.conv_pct)):"â"})}},{id:"arm_rpc",label:"RPC por variante",column:{key:"arm_rpc",label:"RPC/var.",render:t=>e.jsx(W,{arms:t.arms,getValue:r=>{if(r.rpc==null)return"â";const s=Number(r.rpc);return Number.isFinite(s)?I(s):"â"}})}}],ht=()=>{try{const t=localStorage.getItem(ge);return t?JSON.parse(t):{}}catch{return{}}},ft=t=>{try{localStorage.setItem(ge,JSON.stringify(t))}catch{}},Ne=({enabled:t,prefs:r,onToggle:s})=>e.jsxs(Be,{children:[e.jsx(Me,{color:"secondary",variant:"outline",size:"sm",title:"Selecionar colunas opcionais por variante",children:"Colunas"}),e.jsx(We,{children:ve.map(n=>e.jsxs(Ee,{onClick:()=>s(n.id),title:t?void 0:"Requer backend atualizado (campo arms ausente)",style:{cursor:t?"pointer":"not-allowed",opacity:t?1:.5},children:[e.jsx("input",{type:"checkbox",checked:!!r[n.id],onChange:()=>{},disabled:!t,style:{marginRight:6},tabIndex:-1,"aria-label":n.label}),n.label]},n.id))})]});Ne.propTypes={enabled:i.bool.isRequired,prefs:i.object.isRequired,onToggle:i.func.isRequired};const xt=[{key:"test_name",label:"Teste / Seller",render:t=>e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontWeight:600},children:t.test_name||t.test_id}),e.jsx("div",{style:{fontSize:"0.72rem",color:"var(--cui-secondary-color)"},children:t.seller_name||t.user_id})]})},{key:"platforms",label:"Plataformas",render:t=>{const r=pt(t.arms);return e.jsxs("div",{style:{fontSize:"0.8rem"},title:r,children:[e.jsx("strong",{children:e.jsx(J,{value:t.focal_platform})}),e.jsx("span",{style:{color:"var(--cui-secondary-color)"},children:" vs "}),e.jsx(J,{value:t.competitor_platform}),r&&e.jsx("span",{style:{marginLeft:4,fontSize:"0.7rem",color:"var(--cui-secondary-color)",cursor:"help"},title:r,children:"â"})]})}},{key:"total_clicks",label:"Cliques",numeric:!0,sortable:!0,render:t=>t.total_clicks??"â"},{key:"conv_pct",label:"Conv%",numeric:!0,sortable:!0,render:t=>e.jsx(ye,{value:t.conv_pct})},{key:"rpc_focal",label:"RPC Focal",numeric:!0,sortable:!0,render:t=>t.rpc_focal!=null?oe(t.rpc_focal):"â"},{key:"rpc_competitor",label:"RPC Concorrente",numeric:!0,sortable:!0,render:t=>t.rpc_competitor!=null?oe(t.rpc_competitor):"â"},{key:"verdict",label:"Veredicto direcional",headerTitle:"Leitura preliminar por RPC â não é teste de significância",render:t=>e.jsx(je,{row:t})},{key:"anomaly_score",label:"Saúde",numeric:!0,sortable:!0,render:t=>e.jsx(_e,{score:t.anomaly_score})},{key:"coherence_flag",label:"Divergência",headerTitle:"Vencedor por CR difere do vencedor por RPC",render:t=>t.coherence_flag?e.jsx("span",{title:"Vencedor por CR difere do vencedor por RPC",style:{color:"var(--cui-warning)",fontWeight:700},children:"ð©"}):null}],Ce=({rows:t,filters:r,updateFilter:s,onRowClick:n,loading:a})=>{const[l,o]=m.useState(ht),c=t.some(u=>Array.isArray(u.arms)&&u.arms.length>0),d=u=>{c&&o(x=>{const b={...x,[u]:!x[u]};return ft(b),b})},j=[...xt,...ve.filter(u=>c&&l[u.id]).map(u=>u.column)],p=u=>{r.order_by===u?s("direction",r.direction==="asc"?"desc":"asc"):(s("order_by",u),s("direction","desc"))};return e.jsxs("div",{children:[e.jsx("div",{style:{display:"flex",justifyContent:"flex-end",marginBottom:8},children:e.jsx(Ne,{enabled:c,prefs:l,onToggle:d})}),e.jsx(ze,{columns:j,rows:t,loading:a,orderBy:r.order_by,direction:r.direction,onSort:p,onRowClick:u=>n(u.test_id),rowKey:u=>u.test_id,rowClassName:u=>[mt(u)?"admin-table__row--muted":"",u.coherence_flag?"admin-testeab__row--divergence":""].filter(
4Boolean).join(" "),emptyMessage:"Nenhum teste encontrado para os filtros aplicados.",resetKey:`${r.search}|${r.status}|${r.platform}|${r.seller}`})]})};Ce.propTypes={rows:i.array.isRequired,filters:i.object.isRequired,updateFilter:i.func.isRequired,onRowClick:i.func.isRequired,loading:i.bool};const G=t=>{const r=Number(t);return Number.isFinite(r)?r:0},gt=t=>{const r=1/(1+.2316419*Math.abs(t)),n=.3989423*Math.exp(-t*t/2)*r*(.3193815+r*(-.3565638+r*(1.781478+r*(-1.821256+r*1.330274))));return t>0?1-n:n},bt=()=>{let t=Math.random();const r=Math.random();return t<1e-12&&(t=1e-12),Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*r)},_t=(t=[])=>{const r=new Map;for(const s of t){const n=Number(s.arm_index);r.has(n)||r.set(n,{arm_index:n,platform:null,arm_label:null,variant_url:null,clicks:0,netRev:0,sumsq:0});const a=r.get(n);a.clicks+=G(s.n_clicks),a.netRev+=G(s.net_revenue),a.sumsq+=G(s.sum_net_rev_sq),!a.platform&&s.checkout_platform&&s.checkout_platform!=="unknown"&&(a.platform=s.checkout_platform),!a.arm_label&&s.arm_label&&String(s.arm_label).trim()!==""&&(a.arm_label=String(s.arm_label).trim()),!a.variant_url&&s.variant_url&&String(s.variant_url).trim()!==""&&(a.variant_url=String(s.variant_url).trim())}return Array.from(r.values()).filter(s=>s.clicks>0).map(s=>{const n=s.netRev/s.clicks,a=Math.max(0,s.sumsq/s.clicks-n*n);return{arm_index:s.arm_index,platform:s.platform,arm_label:s.arm_label,variant_url:s.variant_url,n:s.clicks,rpc:n,variance:a,seMean:Math.sqrt(a/s.clicks)}}).sort((s,n)=>s.arm_index-n.arm_index)},jt=(t,r=5e3)=>{const s=t.length;if(s===0)return[];const n=new Array(s).fill(0);if(t.every(l=>l.seMean===0)){let l=0;for(let o=1;o<s;o++)t[o].rpc>t[l].rpc&&(l=o);n[l]=r}else for(let l=0;l<r;l++){let o=0,c=-1/0;for(let d=0;d<s;d++){const j=t[d].rpc+t[d].seMean*bt();j>c&&(c=j,o=d)}n[o]+=1}return n.map(l=>l/r)},yt=(t,r)=>{const s=Math.sqrt(t.seMean*t.seMean+r.seMean*r.seMean);if(s===0)return null;const n=Math.abs(t.rpc-r.rpc)/s;return 2*(1-gt(n))},vt=t=>{const s=[...t.filter(l=>l.p!=null)].sort((l,o)=>l.p-o.p),n=s.length;let a=0;return s.forEach((l,o)=>{const c=Math.min(1,(n-o)*l.p);a=Math.max(a,c),l.p_adj=a}),t},Nt=(t=[])=>{const r=_t(t);if(r.length<2)return null;const s=jt(r),n=r.map((l,o)=>({...l,prob_best:s[o]})).sort((l,o)=>o.prob_best-l.prob_best||o.rpc-l.rpc),a=[];for(let l=0;l<r.length;l++)for(let o=l+1;o<r.length;o++)a.push({a:r[l].arm_index,b:r[o].arm_index,platform_a:r[l].platform,platform_b:r[o].platform,arm_label_a:r[l].arm_label,arm_label_b:r[o].arm_label,variant_url_a:r[l].variant_url,variant_url_b:r[o].variant_url,p:yt(r[l],r[o]),p_adj:null});return vt(a),{arms:n,pairwise:a,n_arms:r.length,hasVariance:r.some(l=>l.variance>0)}},Ct=t=>t?t.charAt(0).toUpperCase()+t.slice(1):"â",Se=t=>t==null?"â":`${(t*100).toFixed(1)}%`,Q=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":r===0?"0%":r<.01?"<0.01%":r<.1?`${r.toFixed(3)}%`:`${r.toFixed(2)}%`},St=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":r<.001?"<0.001":r.toFixed(3)},kt=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`${(r*100).toFixed(0)}%`},O=t=>t?t.charAt(0).toUpperCase()+t.slice(1):"â",ne=t=>{if(t.arm_label&&String(t.arm_label).trim()!=="")return{label:String(t.arm_label).trim(),title:t.variant_url??void 0};if(t.variant_url&&String(t.variant_url).trim()!=="")try{const r=new URL(t.variant_url),s=r.hostname+r.pathname;return{label:s.length>35?s.slice(0,18)+"â¦"+s.slice(s.length-14):s,title:t.variant_url}}catch{}return{label:`Braço ${t.arm_index}`,title:void 0}},ie=(t,r)=>{let s=0,n=0;for(const a of t)Number(a.arm_index)===r&&(s+=Number(a.n_clicks??0),n+=Number(a.n_approved??0));return{clicks:s,approved:n,convPct:s>0?n/s*100:null}},wt=(t,r)=>{const[s,n]=m.useState(null),[a,l]=m.useState(!0),[o,c]=m.useState(null);m.useEffect(()=>{let y=!1;return l(!0),n(null),c(null),r(t).then(T=>{y||n(T)}).catch(T=>{y||c(T)}).finally(()=>{y||l(!1)}),()=>{y=!0}},[t,r]);const d=(s==null?void 0:s.verdict)??null,j=(s==null?void 0:s.anomaly)??null,p=m.useMemo(()=>(s==null?void 0:s.armsDaily)??[],[s]),u=m.useMemo(()=>ie(p,0),[p]),x=m.useMemo(()=>ie(p,1),[p]),b=m.useMemo(()=>Nt(p),[p]),h=b!=null&&b.n_arms>2,C=d&&Number(d.rpc_focal)>=Number(d.rpc_competitor)?d.focal_platform:d==null?void 0:d.competitor_platform,N=(d==null?void 0:d.cr_winner_platform)??null,k=d?Number(d.total_clicks_focal??0)+Number(d.total_clicks_competitor??0):null,S=d?Number(d.rpc_competitor):NaN,w=(()=>
4{if(!d||d.rpc_lift_pct==null)return null;const y=Number(d.rpc_lift_pct);return Number.isFinite(y)?`${y>=0?"+":""}${y.toFixed(1)}%`:null})(),v=d&&d.rpc_lift_pct==null&&S===0;return{detail:s,loading:a,error:o,verdict:d,anomaly:j,armsDaily:p,focalArm:u,competitorArm:x,multiArm:b,isMultiArm:h,rpcWinner:C,crWinner:N,totalClicks:k,rpcLiftDisplay:w,rpcLiftUnavailable:v,rpcCompetitorNum:S}},ke=({multiArm:t})=>{if(!t)return null;const{arms:r,pairwise:s,hasVariance:n}=t,a=s.some(l=>l.p_adj!=null);return e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsxs("h4",{style:{display:"flex",alignItems:"center",gap:8},children:["Análise multi-braço (Bayesiano)",!n&&e.jsx(R,{color:"secondary",style:{fontSize:"0.68rem"},children:"PRELIMINAR â argmax(RPC), sem variância"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:r.map((l,o)=>{const{label:c,title:d}=ne(l);return e.jsxs("div",{style:{fontSize:"0.8rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:2},children:[e.jsxs("span",{style:{fontWeight:o===0?700:500},children:[e.jsx("span",{title:d,children:c}),l.platform&&l.platform!==c.toLowerCase()&&e.jsxs("span",{style:{color:"var(--cui-secondary-color)",fontWeight:400},children:[" ","(",l.platform,")"]})," ",e.jsxs("span",{style:{color:"var(--cui-secondary-color)",fontWeight:400},children:["(braço ",l.arm_index,")"]})]}),e.jsx("span",{style:{fontVariantNumeric:"tabular-nums",fontWeight:600},children:Se(l.prob_best)})]}),e.jsx("div",{style:{height:6,borderRadius:3,background:"var(--cui-border-color)",overflow:"hidden"},children:e.jsx("div",{style:{width:`${Math.round((l.prob_best??0)*100)}%`,height:"100%",background:o===0?"var(--cui-success)":"var(--cui-info)"}})})]},l.arm_index)})}),e.jsxs("small",{style:{display:"block",marginTop:8,color:"var(--cui-secondary-color)"},children:["P(melhor braço) por Monte Carlo sobre a distribuição do RPC médio de cada braço.",!n&&" Sem variância reportada pelo backend â resultado é argmax(RPC), não probabilÃstico."]}),a?e.jsxs("div",{style:{marginTop:10},children:[e.jsx("div",{style:{fontSize:"0.74rem",color:"var(--cui-secondary-color)",marginBottom:4},children:"Comparações par-a-par (Welch · Holm-Bonferroni)"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:3},children:s.map((l,o)=>{const c=l.p_adj!=null&&l.p_adj<.05,d=(u,x,b)=>{if(u&&String(u).trim()!=="")return String(u).trim();if(x)try{const h=new URL(x);return h.hostname+h.pathname}catch{return x}return Ct(b)},j=d(l.arm_label_a,l.variant_url_a,l.platform_a),p=d(l.arm_label_b,l.variant_url_b,l.platform_b);return e.jsxs("div",{style:{fontSize:"0.76rem",display:"flex",justifyContent:"space-between"},children:[e.jsxs("span",{children:[j," vs ",p]}),e.jsxs("span",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs("span",{style:{color:"var(--cui-secondary-color)",fontVariantNumeric:"tabular-nums"},children:["p~",l.p_adj!=null?l.p_adj.toFixed(3):"â"]}),e.jsx(R,{color:c?"success":"secondary",style:{fontSize:"0.66rem"},children:c?"Significativo":"n.s."})]})]},o)})})]}):e.jsx("div",{style:{marginTop:10,fontSize:"0.74rem",color:"var(--cui-secondary-color)",fontStyle:"italic"},children:"Comparações par-a-par indisponÃveis â variância por braço ainda não populada no backend."})]})};ke.propTypes={multiArm:i.shape({arms:i.array,pairwise:i.array,hasVariance:i.bool})};const we=({arms:t})=>!t||t.length===0?null:e.jsx("div",{style:{overflowX:"auto",marginTop:10},children:e.jsxs("table",{style:{width:"100%",fontSize:"0.8rem",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsxs("tr",{style:{borderBottom:"1px solid var(--cui-border-color)"},children:[e.jsx("th",{style:{textAlign:"left",padding:"4px 6px",fontWeight:600},children:"Braço"}),e.jsx("th",{style:{textAlign:"right",padding:"4px 6px",fontWeight:600},children:"Cliques"}),e.jsx("th",{style:{textAlign:"right",padding:"4px 6px",fontWeight:600},children:"Conv%"}),e.jsx("th",{style:{textAlign:"right",padding:"4px 6px",fontWeight:600},children:"RPC"}),e.jsx("th",{style:{textAlign:"right",padding:"4px 6px",fontWeight:600},children:"P(melhor)"})]})}),e.jsx("tbody",{children:t.map(r=>{const{label:s,title:n}=ne(r),a=r.conv_pct!=null?Number(r.conv_pct):r.n>0&&r.n_approved!=null?Number(r.n_approved)/r.n*100:null,l=Number(r.rpc),o=Number.isFinite(l)?I(l):"â";return e.jsxs("tr",{style:{borderBottom:"1px solid var(--cui-border-color-translucent)"},children:[e.jsxs("td",{style:{padding:"5px 6px"},title:n??void 0,children:[s,r.platform&&e.jsxs("span",{style:{marginLeft:4,color:"var(--cui-secondary-color)",fontSize:"0.72rem"},children:["(",r.platform,")"]})]}),e.jsx("td",{style:{textAlign:"right",padding:"5px 6px",fontVariantNumeric:"tabular-nums"},children:r.n??"â"}),e.jsx("td",{style:{textAlign:"right",padding:"5px 6px",fontVariantNumeric:"tabular-nums"},children:a!=null?Q(a):"â"}),e.jsx("td",{style:{textAlign:"right",padding:"5px 6px",fontVariantNumeric:"tabular-nums"},children:o}),e.jsx("td",{style:{textAlign:"right",padding:"5px 6px",fontVariantNumeric:"tabular-nums"},children:r.prob_best!=null?Se(r.prob_best):"â"})]},r.arm_index)})})]})});
4we.propTypes={arms:i.array};const Y=({label:t,winner:r,sublabel:s,pValue:n,power:a,isSignificant:l})=>{const o=l!==void 0;return e.jsxs("div",{style:{border:"1px solid var(--cui-border-color)",borderRadius:6,padding:"10px 12px",flex:1,minWidth:180},children:[e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cui-secondary-color)",marginBottom:4,textTransform:"uppercase",letterSpacing:"0.05em"},children:t}),e.jsx("div",{style:{fontWeight:700,fontSize:"1rem",marginBottom:6},children:O(r)}),e.jsx("div",{style:{fontSize:"0.78rem",display:"flex",gap:8,flexWrap:"wrap"},children:o?e.jsxs(e.Fragment,{children:[e.jsxs("span",{title:"p-value do teste de Welch sobre RPC",children:["p-value:"," ",e.jsx("strong",{style:{fontVariantNumeric:"tabular-nums"},children:St(n)})]}),e.jsxs("span",{title:"Poder estatÃstico (1 - β)",children:["Poder:"," ",e.jsx("strong",{style:{fontVariantNumeric:"tabular-nums"},children:kt(a)})]}),e.jsx(R,{color:l?"success":"warning",style:{fontSize:"0.7rem",alignSelf:"center"},children:l?"Significativo":"Não significativo"})]}):e.jsx("span",{style:{color:"var(--cui-secondary-color)"},children:s})})]})};Y.propTypes={label:i.string.isRequired,winner:i.string,sublabel:i.string,pValue:i.oneOfType([i.string,i.number]),power:i.oneOfType([i.string,i.number]),isSignificant:i.bool};const Re=({anomaly:t})=>{if(!t)return null;const r=t.bot_ratio!=null?Number(t.bot_ratio):null,s=t.unique_ratio!=null?Number(t.unique_ratio):null,n=Number(t.allocation_churn_count??0),a=[{key:"splitter",label:"Splitter ϲ enviesado",value:!!t.splitter_biased},{key:"refund",label:"Spike de reembolso",value:!!t.refund_spike},{key:"chargeback",label:"Spike de chargeback",value:!!t.chargeback_spike},{key:"divergence",label:"Divergência CR/RPC",value:!!t.verdict_divergence},{key:"conv_outlier",label:"Outlier de conversão",value:!!t.conv_outlier}];return e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsx("h4",{children:"Flags de anomalia"}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginBottom:8},children:[a.map(({key:l,label:o,value:c})=>e.jsxs(R,{color:c?"danger":"success",style:{fontSize:"0.75rem"},children:[o,": ",c?"SIM":"não"]},l)),n>0&&e.jsxs(R,{color:"warning",style:{fontSize:"0.75rem"},children:["Churn de alocação: ",n]}),r!=null&&r>0&&e.jsxs(R,{color:"warning",style:{fontSize:"0.75rem"},children:["Bot ratio: ",(r*100).toFixed(1),"%"]}),s!=null&&s>0&&e.jsxs(R,{color:"info",style:{fontSize:"0.75rem"},children:["Ãnicos: ",(s*100).toFixed(1),"%"]})]})]})};Re.propTypes={anomaly:i.shape({splitter_biased:i.bool,refund_spike:i.bool,chargeback_spike:i.bool,verdict_divergence:i.bool,conv_outlier:i.bool,allocation_churn_count:i.oneOfType([i.string,i.number]),bot_ratio:i.oneOfType([i.string,i.number]),unique_ratio:i.oneOfType([i.string,i.number])})};const A=t=>{const r=Number(t);return t==null||t===""||Number.isNaN(r)?"â":r.toLocaleString("pt-BR")},Rt=t=>{if(t==null||t==="")return"â";const r=Number(t);return Number.isNaN(r)?"â":`${r.toFixed(2).replace(".",",")}%`},Tt=t=>t?Ue(t).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit"}):"â",X=t=>{const r=Number(t);if(!(t==null||t===""||Number.isNaN(r)))return`Receita: ${$(t)}`},Te=({rows:t})=>!t||t.length===0?null:e.jsx("div",{className:"admin-testeab__micro-wrap",children:e.jsxs("table",{className:"admin-testeab__micro-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"left",children:"Dia"}),e.jsx("th",{className:"left",children:"Braço"}),e.jsx("th",{className:"left",children:"Plataforma"}),e.jsx("th",{children:"Cliques"}),e.jsx("th",{children:"Aprovadas"}),e.jsx("th",{children:"Vendas Produto"}),e.jsx("th",{children:"Vendas OB"}),e.jsx("th",{children:"Gross"}),e.jsx("th",{children:"Net"}),e.jsx("th",{children:"RPC"}),e.jsx("th",{children:"Conv%"}),e.jsx("th",{title:"Visitas ao checkout â proxy = cliques quando a coluna real é 0",children:"Visitas Checkout"}),e.jsx("th",{title:"Transações PIX distintas atribuÃdas ao braço (tooltip: receita)",children:"PIX"}),e.jsx("th",{title:"Transações de cartão distintas atribuÃdas ao braço (tooltip: receita)",children:"Cartão"}),e.jsx("th",{title:"Transações de boleto distintas atribuÃdas ao braço (tooltip: receita)",children:"Boleto"}),e.jsx("th",{title:"PIX gerado aguardando pagamento",children:"PIX Gerados"})]})}),e.jsx("tbody",{children:t.map((r,s)=>{const{label:n,title:a}=ne(r);return e.jsxs("tr",{children:[e.jsx("td",{className:"left",children:Tt(r.day)}),e.jsx("td",{className:"left",title:a??void 0,children:n}),e.jsx("td",{className:"left",children:O(r.checkout_platform)}),e.jsx("td",{children:A(r.n_clicks)}),e.jsx("td",{children:A(r.n_approved)}),e.jsx("td",{children:A(r.sales_entry)}),e.jsx("td",{children:A(r.sales_ob)}),e.jsx("td",{children:$(r.gross_revenue)}),e.jsx("td",{children:$(r.net_revenue)}),e.jsx("td",{children:$(r.rpc)}),e.jsx("td",{children:Rt(r.conv_pct)}),e.jsx("td",{children:A(r.checkout_access)}),e.jsx("td",{title:X(r.pix_revenue),children:A(r.pix_count)}),e.jsx("td",{title:X(r.card_revenue),children:A(r.card_count)}),e.jsx("td",{title:X(r.boleto_revenue),children:A(r.boleto_count)}),e.jsx("td",{children:A(r.pix_generated)})]},`${r.day}-${r.arm_index}-${r.checkout_platform}-${s}`)})})]})});Te.propTypes={rows:i.array};const Pt=m.lazy(()=>Ie(()=>import("./TestDailyChart-c-9JH-NV.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]))),ce=t=>{const r=Number(t);return r>=.7?"var(--cui-danger)":r>=.4?"var(--cui-warning)":"var(--cui-success)"},Pe=({testId:t,loadDetail:r,onClose:s})=>{const{detail:n,loading:a,error:l,verdict:o,anomaly:c,armsDaily:d,focalArm:j,competitorArm:p,multiArm:u,isMultiArm:x,rpcWinner:b,crWinner:h,totalClicks:C,rpcLiftDisplay:N,rpcLiftUnavailable:k,rpcCompetitorNum:S}=wt(t,r),w=He(),[v,y]=m.useState(!1),T=async()=>
4{if(!(v||!n)){y(!0);try{const z=await Ye(t),V=n.snapshot_date||new Date().toISOString().slice(0,10);Ge(z,`testeab-${t}-${V}.csv`),w({color:"success",title:"Exportação concluÃda",message:"O CSV micro (dia à braço à plataforma) foi baixado."})}catch{w({color:"danger",title:"Falha na exportação",message:"Não foi possÃvel exportar o CSV. Tente novamente."})}finally{y(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"admin-testeab__drawer-backdrop",onClick:s,"aria-hidden":"true"}),e.jsxs("aside",{className:"admin-testeab__drawer",role:"dialog","aria-modal":"true","aria-label":`Detalhes do teste ${t}`,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsx("h3",{style:{margin:0,fontSize:"1.15rem"},children:"Detalhes do Teste"}),e.jsx("button",{type:"button",className:"btn btn-sm btn-link",onClick:s,children:"Fechar"})]}),a&&e.jsxs("div",{children:[e.jsx(E,{size:"sm",className:"me-2"}),"Carregandoâ¦"]}),l&&e.jsxs("div",{style:{color:"var(--cui-danger)"},children:["Erro: ",l.message]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsx("h4",{children:"Identificação"}),e.jsxs("div",{style:{fontSize:"0.85rem",display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsxs("div",{children:["Seller: ",e.jsx("strong",{children:(o==null?void 0:o.seller_name)||(o==null?void 0:o.user_id)||"â"})]}),e.jsxs("div",{children:["Status: ",e.jsx("strong",{children:(o==null?void 0:o.status)||"â"})]}),e.jsxs("div",{children:["Snapshot: ",e.jsx("strong",{children:n.snapshot_date||"â"})]}),e.jsxs("div",{children:["Duração:"," ",e.jsx("strong",{children:(o==null?void 0:o.test_duration_days)!=null?`${o.test_duration_days} dias${o.matured?" (maturado)":""}`:"â"})]})]})]}),e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsx("h4",{children:"Resultados agregados"}),x?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{fontSize:"0.82rem",marginBottom:6,display:"flex",gap:16},children:[e.jsxs("span",{children:["Cliques totais: ",e.jsx("strong",{children:C??"â"})]}),e.jsxs("span",{children:["Anomaly score:"," ",e.jsx("strong",{style:{color:ce(c==null?void 0:c.anomaly_score)},children:(c==null?void 0:c.anomaly_score)!=null?Number(c.anomaly_score).toFixed(2):"â"})]})]}),e.jsx(we,{arms:u.arms})]}):e.jsxs("div",{style:{fontSize:"0.85rem",display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsxs("div",{children:["Plataforma focal:"," ",e.jsx("strong",{style:{textTransform:"capitalize"},children:O(o==null?void 0:o.focal_platform)})]}),e.jsxs("div",{children:["Concorrente:"," ",e.jsx("strong",{style:{textTransform:"capitalize"},children:O(o==null?void 0:o.competitor_platform)})]}),e.jsxs("div",{children:["Cliques totais: ",e.jsx("strong",{children:C??"â"})]}),e.jsxs("div",{children:["Lift RPC:"," ",e.jsx("strong",{children:N??e.jsx("span",{title:k?"Lift indisponÃvel â RPC concorrente é zero (divisão por zero)":"Lift indisponÃvel",style:{color:"var(--cui-secondary-color)"},children:"â"})})]}),e.jsxs("div",{children:["Conv% focal: ",e.jsx("strong",{children:Q(j.convPct)})]}),e.jsxs("div",{children:["Conv% concorrente: ",e.jsx("strong",{children:Q(p.convPct)})]}),e.jsxs("div",{children:["RPC focal:"," ",e.jsx("strong",{children:(o==null?void 0:o.rpc_focal)!=null?$(o.rpc_focal):"â"})]}),e.jsxs("div",{children:["RPC concorrente:"," ",e.jsx("strong",{children:(o==null?void 0:o.rpc_competitor)!=null?S===0?e.jsx("span",{title:"RPC concorrente é zero â possÃvel ausência de vendas ou dados ainda não populados",style:{color:"var(--cui-secondary-color)"},children:"R$ 0,00"}):$(o.rpc_competitor):"â"})]}),e.jsxs("div",{children:["Anomaly score:"," ",e.jsx("strong",{style:{color:ce(c==null?void 0:c.anomaly_score)},children:(c==null?void 0:c.anomaly_score)!=null?Number(c.anomaly_score).toFixed(2):"â"})]})]})]}),o&&!x&&e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsxs("h4",{style:{display:"flex",alignItems:"center",gap:8},children:["Veredicto",o.coherence_flag&&e.jsx(R,{color:"warning",style:{fontSize:"0.7rem"},children:"Divergência CR vs RPC â possÃvel Simpson"})]}),e.jsxs("div",{style:{display:"flex",gap:10,flexWrap:"wrap"},children:[e.jsx(Y,{label:"Vencedor por RPC (Welch)",winner:b,pValue:o.p_value,power:o.power,isSignificant:!!o.is_significant}),e.jsx(Y,{label:"Vencedor por conversão",winner:h,sublabel:"direcional â sem teste de significância"})]}),!o.is_significant&&e.jsx("div",{style:{marginTop:10,fontSize:"0.78rem",color:"var(--cui-secondary-color)",padding:"6px 10px",border:"1px solid var(--cui-border-color)",borderRadius:5},children:"O teste de Welch ainda não atingiu significância â o vencedor por RPC acima é direcional. Significância exige mais volume/variância de receita."}),o.coherence_flag&&e.jsx("div",{style:{marginTop:10,fontSize:"0.78rem",color:"var(--cui-danger)",padding:"6px 10px",border:"1px solid var(--cui-danger)",borderRadius:5},children:"Vencedor por conversão difere do vencedor por RPC. Revisar atribuição de receita antes de tomar decisão operacional."})]}),e.jsx(ke,{multiArm:u}
4),e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsx("h4",{children:"Série diária â Cliques, Conv e RPC"}),d.length>0?e.jsx(m.Suspense,{fallback:e.jsxs("div",{children:[e.jsx(E,{size:"sm",className:"me-2"}),"Carregando gráficoâ¦"]}),children:e.jsx(Pt,{armsDaily:d,focalPlatform:o==null?void 0:o.focal_platform,competitorPlatform:o==null?void 0:o.competitor_platform})}):e.jsx("div",{style:{fontSize:"0.78rem",color:"var(--cui-secondary-color)"},children:"Série diária indisponÃvel â execute o snapshot diário para habilitar."})]}),e.jsxs("div",{className:"admin-testeab__drawer-section",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6,gap:8},children:[e.jsx("h4",{style:{margin:0},children:"Micro dados â dia à braço à plataforma"}),e.jsx(ue,{color:"secondary",size:"sm",loading:v,disabled:v||d.length===0,onClick:T,title:"Baixar CSV completo (44 colunas) do teste",children:v?"Exportando...":"Exportar CSV"})]}),d.length>0?e.jsx(Te,{rows:d}):e.jsx("div",{style:{fontSize:"0.78rem",color:"var(--cui-secondary-color)"},children:"Micro dados indisponÃveis â execute o snapshot diário para habilitar."})]}),e.jsx(Re,{anomaly:c}),e.jsxs("div",{style:{fontSize:"0.72rem",color:"var(--cui-secondary-color)",marginTop:16},children:["ID: ",t]})]})]})]})};Pe.propTypes={testId:i.string.isRequired,loadDetail:i.func.isRequired,onClose:i.func.isRequired};const de=t=>t?t.charAt(0).toUpperCase()+t.slice(1):"â",Ae=({rows:t})=>{const r=lt(t);return r.length===0?null:e.jsxs("div",{style:{marginTop:16},children:[e.jsxs("div",{style:{fontSize:"0.85rem",fontWeight:600,marginBottom:8,display:"flex",alignItems:"center",gap:8},children:["Head-to-Head direcional",e.jsx(R,{color:"secondary",style:{fontSize:"0.68rem"},children:"PRELIMINAR"})]}),e.jsxs(ee,{small:!0,hover:!0,responsive:!1,children:[e.jsx(te,{children:e.jsxs(F,{children:[e.jsx(f,{children:"Par de plataformas"}),e.jsx(f,{className:"text-center",children:"Vitórias focal"}),e.jsx(f,{className:"text-center",children:"Vitórias concorrente"}),e.jsx(f,{className:"text-center",children:"Empates"}),e.jsx(f,{className:"text-center",children:"Win-rate focal"}),e.jsx(f,{className:"text-center",children:"Decididos"})]})}),e.jsx(re,{children:r.map((s,n)=>{const a=s.focal_wins+s.competitor_wins,l=a>0?s.focal_wins/a*100:null;return e.jsxs(F,{children:[e.jsxs(_,{children:[e.jsx("strong",{children:de(s.focal_platform)}),e.jsxs("span",{style:{color:"var(--cui-secondary-color)",fontSize:"0.82rem"},children:[" ","vs ",de(s.competitor_platform)]})]}),e.jsx(_,{className:"text-center",style:{color:"var(--cui-success)"},children:s.focal_wins}),e.jsx(_,{className:"text-center",style:{color:"var(--cui-danger)"},children:s.competitor_wins}),e.jsx(_,{className:"text-center",style:{color:"var(--cui-secondary-color)"},children:s.ties}),e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums",fontWeight:600},children:l!=null?`${l.toFixed(0)}%`:"â"}),e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums"},children:s.n_decided})]},`${s.focal_platform}-${s.competitor_platform}-${n}`)})})]}),e.jsx("small",{style:{display:"block",marginTop:6,color:"var(--cui-secondary-color)"},children:"Direcional = quem tem RPC maior por teste, sem teste de significância. Empates não contam no win-rate."})]})};Ae.propTypes={rows:i.array};const At=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`${r.toFixed(1)}%`},Dt=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`+${r.toFixed(1)}%`},$t=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`-${r.toFixed(1)}%`},De=({pair:t})=>{const{focal_platform:r,competitor_platform:s,win_rate_by_test:n,win_rate_by_seller:a,win_rate_by_gmv:l,median_lift_when_winning:o,median_gap_when_losing:c,n_wins:d,n_losses:j,coherence_flag:p}=t,u=[{label:"Por teste",value:n},{label:"Por seller",value:a},{label:"Por GMV",value:l}],x=p?{borderLeft:"3px solid var(--cui-danger)"}:{},b=h=>h?h.charAt(0).toUpperCase()+h.slice(1):"â";return e.jsxs(F,{style:x,children:[e.jsxs(_,{children:[e.jsx("strong",{children:b(r)}),e.jsxs("span",{style:{color:"var(--cui-secondary-color)",fontSize:"0.82rem"},children:[" ","vs ",b(s)]}),p&&e.jsx(R,{color:"danger",className:"ms-2",style:{fontSize:"0.72rem",verticalAlign:"middle"},title:"As leituras de win-rate divergem mais de 15pp â possÃvel Paradox
4o de Simpson",children:"DIVERGÃNCIA â investigar Simpson"})]}),u.map(({label:h,value:C})=>{const N=Number(C),k=!Number.isNaN(N)&&N>=60,S=!Number.isNaN(N)&&N<=40;return e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums",fontWeight:600,color:k?"var(--cui-success)":S?"var(--cui-danger)":"var(--cui-body-color)"},children:At(C)},h)}),e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums",color:"var(--cui-success)"},children:Dt(o)}),e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums",color:"var(--cui-danger)"},children:$t(c)}),e.jsxs(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums"},children:[e.jsx("span",{style:{color:"var(--cui-success)"},children:d??"â"})," / ",e.jsx("span",{style:{color:"var(--cui-danger)"},children:j??"â"})]})]})};De.propTypes={pair:i.shape({focal_platform:i.string,competitor_platform:i.string,win_rate_by_test:i.string,win_rate_by_seller:i.string,win_rate_by_gmv:i.string,median_lift_when_winning:i.string,median_gap_when_losing:i.string,n_wins:i.number,n_losses:i.number,coherence_flag:i.bool}).isRequired};const $e=({headToHead:t,loading:r,onLoad:s,rows:n=[]})=>{const a=(t==null?void 0:t.pairs)??[],l=a.some(c=>c.coherence_flag),o=a.some(c=>(Number(c.n_wins)||0)+(Number(c.n_losses)||0)>0);return e.jsxs(me,{className:"mb-4",children:[e.jsxs(pe,{className:"d-flex align-items-center gap-2 flex-wrap",children:[e.jsx("strong",{children:"Head-to-Head â Win-Rate por Plataforma"}),r&&e.jsx(E,{size:"sm"}),!r&&!t&&e.jsx("button",{type:"button",className:"btn btn-sm btn-outline-secondary ms-auto",onClick:s,children:"Carregar"}),l&&e.jsx(R,{color:"danger",className:"ms-auto",style:{fontSize:"0.78rem"},children:"Paradoxo de Simpson detectado"})]}),e.jsxs(he,{style:{overflowX:"auto"},children:[!r&&!t&&e.jsx("p",{style:{color:"var(--cui-secondary-color)",fontSize:"0.85rem",margin:0},children:'Clique em "Carregar" para buscar os dados head-to-head.'}),!r&&t&&!o&&e.jsx(Xe,{icon:"ð",message:"Nenhum teste atingiu significância estatÃstica ainda",suggestion:"Os win-rates oficiais exigem dados de variância ainda ausentes no backend. Veja a leitura direcional preliminar abaixo."}),o&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{small:!0,hover:!0,responsive:!1,children:[e.jsx(te,{children:e.jsxs(F,{children:[e.jsx(f,{children:"Par de plataformas"}),e.jsx(f,{className:"text-center",children:"Win-rate por teste"}),e.jsx(f,{className:"text-center",children:"Win-rate por seller"}),e.jsx(f,{className:"text-center",children:"Win-rate por GMV"}),e.jsx(f,{className:"text-center",title:"Lift mediano quando a plataforma focal vence",children:"Lift mediano (vitória)"}),e.jsx(f,{className:"text-center",title:"Gap mediano quando a plataforma focal perde",children:"Gap mediano (derrota)"}),e.jsx(f,{className:"text-center",children:"Vitórias / Derrotas"})]})}),e.jsx(re,{children:a.map((c,d)=>e.jsx(De,{pair:c},`${c.focal_platform}-${c.competitor_platform}-${d}`))})]}),l&&e.jsxs("div",{style:{marginTop:12,padding:"8px 12px",border:"1px solid var(--cui-danger)",borderRadius:6,fontSize:"0.8rem",color:"var(--cui-danger)",background:"rgba(var(--cui-danger-rgb, 220,53,69), 0.06)"},children:[e.jsx("strong",{children:"Paradoxo de Simpson detectado:"})," as leituras de win-rate divergem mais de 15pp entre dimensões (teste, seller, GMV). Isso pode indicar viés de seleção â sellers maiores concentrando em uma plataforma distorce o agregado. Recomenda-se análise estratificada antes de tomar decisões."]}),e.jsx("small",{style:{display:"block",marginTop:10,color:"var(--cui-secondary-color)"},children:"Win-rates e lifts em %. Linhas com borda vermelha à esquerda indicam divergência entre dimensões (>15pp)."})]}),!r&&e.jsx(Ae,{rows:n})]})]})};$e.propTypes={headToHead:i.shape({pairs:i.array}),loading:i.bool,onLoad:i.func.isRequired,rows:i.array};const Lt=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`${r.toFixed(2)}%`},zt=t=>{if(t==null)return"â";const r=Number(t);return Number.isNaN(r)?"â":`${r.toFixed(2)}%`},qt=t=>t?String(t).toLowerCase()==="unknown"?"Não identificada":t.charAt(0).toUpperCase()+t.slice(1):"â",Z=({median:t,p25:r,p75:s,isBrl:n=!1})=>{const a=n?I:Lt;return e.jsxs(_,{style:{fontVariantNumeric:"tabular-nums"},children:[e.jsx("div",{style:{fontWeight:600},children:a(t)}),e.jsxs("div",{style:{fontSize:"0.75rem",color:"var(--cui-secondary-color)"},children:["P25: ",a(r)," â P75: ",a(s)]})]})};Z.propTypes={median:i.string,p25:i.string,p75:i.string,isBrl:i.bool};const Le=({benchmark:t,loading:r,onLoad:s})=>{const n=(t==null?void 0:t.rows)??[];return e.jsxs(me,{className:"mb-4",children:[e.jsxs(pe,{className:"d-flex align-items-center gap-2 flex-wrap",children:[e.jsx("strong",{children:"Benchmark de Mercado â Plataformas de Checkout"}),r&&e.jsx(E,{size:"sm"}),!r&&!t&&e.jsx("button",{type:"button",className:"btn btn-sm btn-outline-secondary ms-auto",onClick:s,children:"Carregar"})]}),e.jsxs(he,{style:{overflowX:"auto"},children:[e.jsx(K,{color:"warning",className:"mb-3 py-2",style:{fontSize:"0.82rem"},children:"Reflete performance DENTRO de testes A/B (viés de seleção) â não é o mercado geral."}),!r&&!t&&e.jsx("p",{style:{color:"var(--cui-secondary-color)",fontSize:"0.85rem",margin:0},children:'Clique em "Carregar" para buscar os dados de benchmark.'}),!r&&t&&n.length===0&&e.jsx("p",{style:{color:"var(--cui-secondary-color)",fontSize:"0.85rem",margin:0},children:"Nenhum dado de benchmark encontrado para o perÃodo."}),n.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{small:!0,hover:!0,responsive:!1,children:[e.jsx(te,{children:e.jsxs(F,{children:[e.jsx(f,{children:"Plataforma"}),e.jsx(f,{children:"Mês"}),e.jsx(f,{className:"text-center",children:"Testes observados"}),e.jsxs(f,{children:["Conv. mediana",e.jsx("div",{style:{fontSize:"0.72rem",fontWeight:400,color:"var(--cui-secondary-color)"},children:"(P25 â P75)"})]}),e.jsxs(f,{children:["Ticket médio",e.jsx("div",{style:{fontSize:"0.72rem",fontWeight:400,color:"var(--cui-secondary-color)"},children:"(mediana)"})]}),e.jsxs(f,{children:["RPC mediano",e.jsx("div",{style:{fontSize:"0.72rem",fontWeight:400,color:"var(--cui-secondary-color)"},children:"(P25 â P75)"})]}),e.jsx(f,{className:"text-center",title:"Spread observado entre receita bruta e lÃquida (1 â lÃquida/bruta) nos testes â inclui taxa da plataforma, reembolsos e chargebacks. Não é a taxa pura cobrada pela plataforma.",children:"Spread lÃq./bruto"})]})}),e.jsx(re,{children:n.map((a,l)=>{const o=String(a.checkout_platform).toLowerCase()==="unknown";return e.jsxs(F,{style:o?{opacity:.6}:void 0,children:[e.jsx(_,{children:e.jsx("strong",{style:o?{fontStyle:"italic"}:void 0,children:qt(a.checkout_platform)})}),e.jsx(_,{style:{whiteSpace:"nowrap"},children:a.month??"â"}),e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums"},children:a.n_tests_observed??"â"}),e.jsx(Z,{median:a.conv_rate_median,p25:a.conv_rate_p25,p75:a.conv_rate_p75,isBrl:!1}),e.jsx(_,{style:{fontVariantNumeric:"tabular-nums",fontWeight:600},children:I(a.avg_ticket_median)}),e.jsx(Z,{median:a.rpc_median,p25:a.rpc_p25,p75:a.rpc_p75,isBrl:!0}),e.jsx(_,{className:"text-center",style:{fontVariantNumeric:"tabular-nums"},children:zt(a.effective_fee_pct)})]},`${a.checkout_platform}-${a.month}-${l}`)})})]}),e.jsxs("small",{style:{display:"block",marginTop:10,color:"var(--cui-secondary-color)"},children:["RPC = Receita por Clique. Valores BRL em formato compacto (",e.jsx("em",{children:"mil"})," / ",e.jsx("em",{children:"M"}),"). P25âP75 = faixa interquartil."]}
4)]})]})]})};Le.propTypes={benchmark:i.shape({rows:i.array}),loading:i.bool,onLoad:i.func.isRequired};const Ft=new Date().toISOString().slice(0,10),Ut=()=>{var P,D;const{filters:t,updateFilter:r,resetFilters:s,data:n,latestSnapshotDate:a,loading:l,error:o,reload:c,loadDetail:d,headToHead:j,headToHeadLoading:p,loadHeadToHead:u,benchmark:x,benchmarkLoading:b,loadBenchmark:h}=nt(),[C,N]=m.useState(null),[k,S]=m.useState(!1),[w,v]=m.useState(null);m.useEffect(()=>{Promise.allSettled([u(),h()])},[u,h]);const y=m.useCallback(q=>{N(q)},[]),T=m.useCallback(()=>{N(null)},[]),z=m.useCallback(async()=>{S(!0),v(null);try{const q=await rt();v({ok:!0,text:`Snapshot gerado: ${q.saved??0} testes em ${q.duration_ms??0}ms`}),c()}catch(q){v({ok:!1,text:`Erro ao gerar snapshot: ${q.message}`})}finally{S(!1)}},[c]),V=(n==null?void 0:n.snapshot_date)&&n.snapshot_date<Ft,H=!l&&!((P=n==null?void 0:n.rows)!=null&&P.length)&&!o,U=e.jsxs(e.Fragment,{children:[e.jsx(qe,{snapshotDate:n==null?void 0:n.snapshot_date,message:`Snapshot desatualizado â dados de ${n==null?void 0:n.snapshot_date}. Clique em "Gerar Snapshot" para atualizar.`}),H&&!V&&e.jsx(K,{color:"info",className:"mb-2 py-2",children:"Nenhum dado encontrado. Execute o snapshot para popular esta tela."}),w&&e.jsx(K,{color:w.ok?"success":"danger",className:"mb-2 py-2",dismissible:!0,onClose:()=>v(null),children:w.text})]}),g=e.jsxs(e.Fragment,{children:[e.jsx(Oe,{color:"secondary",size:"sm",disabled:!((D=n==null?void 0:n.rows)!=null&&D.length),onClick:()=>st(n.rows,n.snapshot_date),children:"Exportar CSV"}),e.jsx(ue,{color:"primary",size:"sm",loading:k,disabled:k,onClick:z,className:"admin-testeab__snapshot-btn",children:k?"Gerando...":"Gerar Snapshot"})]});return e.jsxs(Fe,{className:"admin-testeab",title:"Testes A/B â Checkout",subtitle:"Comparação de plataformas de checkout por teste. Snapshot diário; veredictos oficiais exigem significância estatÃstica.",alerts:U,actions:g,children:[e.jsx(fe,{totals:n==null?void 0:n.totals,snapshotDate:n==null?void 0:n.snapshot_date,rows:(n==null?void 0:n.rows)??[]}),e.jsx(xe,{filters:t,latestSnapshotDate:a,updateFilter:r,resetFilters:s}),o&&e.jsx(Ve,{error:o,onRetry:c}),e.jsx(Ce,{rows:(n==null?void 0:n.rows)??[],filters:t,updateFilter:r,onRowClick:y,loading:l}),e.jsx($e,{headToHead:j,loading:p,onLoad:u,rows:(n==null?void 0:n.rows)??[]}),e.jsx(Le,{benchmark:x,loading:b,onLoad:h}),C&&e.jsx(Pe,{testId:C,loadDetail:d,onClose:T})]})};export{Ut 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.