1import{r as u,aX as ns,j as e,q as k,L as as,U as rs,o as ls,s as is,g as os,a9 as cs,a6 as ds,I as ms,B as S,a7 as Pe,ab as Ie,S as xs,D as us,F as H}from"./index-pfB80LZ_.js";import{M as ps}from"./more-menu-CSGduzYA.js";import{L as fs}from"./LeadTableLoading-BQISFAzF.js";import{a as hs,s as gs}from"./page-header-BeTQ4iuJ.js";import{H as vs,I as js,J as bs,v as Le,D as pe,m as fe,n as he,b as ge,c as ve,o as je}from"./mermaid-VLURNSYL-BRJe-tcx.js";import{D as ys}from"./data-pagination-LQlXB6LK.js";import{C as Ns,S as Me,a as Oe,b as De,c as Ee,d as _e}from"./select-CK6kec0b.js";import{T as ws,a as ks,b as be,c as $,d as Cs,e as R}from"./table-Kxl-gIZu.js";import{u as Ss}from"./store-DA0bRDRs.js";import{E as As}from"./empty-state-D1TurLxT.js";import{e as Ps,u as Is,f as Ls}from"./use-experiment-mutations-BcCqIu6e.js";import{e as Ms,d as Os,a as ie,E as Ds,f as Es}from"./evolution-data-7NQiNBTv.js";import{C as _s,a as Rs}from"./chart-BTWvkXT8.js";import{S as L}from"./skeleton-DB92Nqm1.js";import{a as $s}from"./thinking-orb-inline-CA4wR67f.js";import{C as He}from"./chevron-down-C8CCelD7.js";import{g as Fs}from"./avatar-jSUOJRFW.js";import{A as Ts}from"./arrow-down-right-DRQBElak.js";import{C as zs}from"./ComposedChart-BPEftnuR.js";import{r as Ws,D as Bs,a3 as Vs,a4 as Hs,a5 as Ks,u as Us,a6 as Gs,z as ne,a7 as Xs,a8 as Ys,a9 as Re,aa as qs,X as Zs,Z as Js,L as Qs,ab as et,ac as st,$ as U,ad as $e,ae as tt,a0 as nt,a1 as at,a2 as rt}from"./CartesianChart-CegFjpyj.js";import{A as lt}from"./Area-CbmJRz-p.js";import{L as ae}from"./Line-B7buH5qI.js";import{F as it}from"./funnel-BYYOIjC_.js";import{P as ot}from"./sparkles-V4b0UAHq.js";import{S as Fe}from"./square-D8bea2F4.js";import{R as ct}from"./refresh-cw-RRAMv8cy.js";import{F as ye}from"./flask-conical-12rMkhJW.js";import{P as dt}from"./play-b-HIaMtd.js";import{P as mt}from"./pause-Ylw1yM0g.js";import"./ellipsis-vertical-BIwDvsat.js";import"./shimmer-skeleton-CsIAjN9Z.js";import"./badge-BmAMyJR9.js";import"./index-TTvjtAtl.js";import"./index-DkhtWE6G.js";import"./checkout-confirmation-BFSlV5Y1.js";import"./users-BL6lkWG9.js";import"./arrow-right-ChtUm7we.js";import"./useGetCreditPool-Cch1Cy8O.js";import"./type-CAspDw_N.js";import"./format-Nkvq8IQd.js";import"./label-DaMwjltI.js";import"./index-CcCgRlET.js";import"./rows-per-page-BbCfyTry.js";import"./field-EsuXmdQX.js";import"./ellipsis-k-sY_dBy.js";import"./index-BdQq_4o_.js";import"./empty-7FwrhJCE.js";import"./use-get-campaign-experiments-ClmBKuAm.js";import"./index-Bz0qjLJ5.js";import"./string-KMAbY2Yt.js";import"./with-selector-C2akZ2Re.js";import"./band-CquvqAHh.js";import"./init-Dmth1JHB.js";import"./ordinal-DILIJJjt.js";import"./linear-QSfljTOU.js";import"./defaultLocale-C4B-KCzX.js";import"./time-KIvIk5pv.js";import"./math-CRUJxRjv.js";class xt{constructor(s){var{x:a,y:n}=s;this.xAxisScale=a,this.yAxisScale=n}map(s,a){var n,l,{position:o}=a;return{x:(n=this.xAxisScale.map(s.x,{position:o}))!==null&&n!==void 0?n:0,y:(l=this.yAxisScale.map(s.y,{position:o}))!==null&&l!==void 0?l:0}}mapWithFallback(s,a){var n,l,{position:o,fallback:x}=a,m,i;return x==="rangeMin"?m=this.yAxisScale.rangeMin():x==="rangeMax"?m=this.yAxisScale.rangeMax():m=0,x==="rangeMin"?i=this.xAxisScale.rangeMin():x==="rangeMax"?i=this.xAxisScale.rangeMax():i=0,{x:(n=this.xAxisScale.map(s.x,{position:o}))!==null&&n!==void 0?n:i,y:(l=this.yAxisScale.map(s.y,{position:o}))!==null&&l!==void 0?l:m}}isInRange(s){var{x:a,y:n}=s,l=a==null||this.xAxisScale.isInRange(a),o=n==null||this.yAxisScale.isInRange(n);return l&&o}}function Te(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);s&&(n=n.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),a.push.apply(a,n)}return a}function ze(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Te(Object(a),!0).forEach(function(n){ut(t,n,a[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Te(Object(a)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(a,n))})}return t}function ut(t,s,a){return(s=pt(s))in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function pt(t){var s=ft(t,"string");return typeof s=="symbol"?s:s+""}function ft(t,s){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var n=a.call(t,s);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function oe(){return oe=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var a=arguments[s];for(var n in a)({}).hasOwnProperty.call(a,n)&&(t[n]=a[n])}return t},oe.apply(null,arguments)}var ht=(t,s)=>{var a;if(u.isValidElement(t))a=u.cloneElement(t,s);else if(typeof t=="function")a=t(s);else{if(!U(s.x1)||!U(s.y1)||!U(s.x2)||!U(s.y2))return null;a=u.createElement("line",oe({},s,{className:"recharts-reference-line-line"}))}return a},gt=(t,s,a,n,l,o)=>{var{x,width:m}=o,i=l.map(t,{position:a});if(!U(i)||s==="discard"&&!l.isInRange(i))return null;var c=[{x:x+m,y:i},{x,y:i}];return n==="left"?c.reverse():c},vt=(t,s,a,n,l,o)=>{var{y:x,height:m}=o,i=l.map(t,{position:a});if(!U(i)||s==="discard"&&!l.isInRange(i))return null;var c=[{x:i,y:x+m},{x:i,y:x}];return n==="top"?c.reverse():c},jt=(t,s,a,n)=>{var l=[n.mapWithFallback(t[0],{position:a,fallback:"rangeMin"}),n.mapWithFallback(t[1],{position:a,fallback:"rangeMax"})];return s==="discard"&&l.some(o=>!n.isInRange(o))?null:l},bt=(t,s,a,n,l,o,x)=>{var{x:m,y:i,segment:c,ifOverflow:f}=x,O=$e(m),b=$e(i);return b?gt(i,f,n,o,s,a):O?vt(m,f,n,l,t,a):c!=null&&c.length===2?jt(c,f,n,new xt({x:t,y:s})):null};function yt(t){var s=Vs();return u.useEffect(()=>(s(Hs(t)),()=>{s(Ks(t))})),null}function Nt(t){var{xAxisId:s,yAxisId:a,shape:n,className:l,ifOverflow:o}=t,x=Us(),m=Gs(),i=ne(w=>Xs(w,s)),c=ne(w=>Ys(w,a)),f=ne(w=>Re(w,"xAxis",s,x)),O=ne(w=>Re(w,"yAxis",a,x)),b=qs();if(!m||!b||i==null||c==null||f==null||O==null)return null;var F=bt(f,O,b,t.position,i.orientation,c.orientation,t);if(!F)return null;var A=F[0],P=F[1];if(A==null||P==null)return null;var{x:I,y:g}=A,{x:j,y:D}=P,z=o==="hidden"?"url(#".concat(m,")"):void 0,d=ze(ze({clipPath:z},Zs(t)),{},{x1:I,y1:g,x2:j,y2:D}),T=tt({x1:I,y1:g,x2:j,y2:D});return u.createElement(Js,{zIndex:t.zIndex},u.createElement(Qs,{className:ns("recharts-reference-line",l)},ht(n,d),u.createElement(et,oe({},T,{lowerWidth:T.width,upperWidth:T.width}),u.createElement(st,{label:t.label}),t.children)))}var wt={ifOverflow:"discard",xAxisId:0,yAxisId:0,fill:"none",label:!1,stroke:"#ccc",fillOpacity:1,strokeWidth:1,position:"middle",zIndex:Bs.line};function Ke(t){var s=Ws(t,wt);return u.createElement(u.Fragment,null,u.createElement(yt,{yAxisId:s.yAxisId,xAxisId:s.xAxisId,ifOverflow:s.ifOverflow,x:s.x,y:s.y,segment:s.segment}),u.createElement(Nt,s))}Ke.displayName="ReferenceLine";const M="var(--primary-text, var(--primary))",Ne=8;function re({label:t,value:s,unit:a,deltaStrong:n,deltaTone:l,deltaMuted:o,visual:x,first:m,last:i}){const c=l==="up"?Fs:Ts;return e.jsxs("div",{className:k("flex min-w-44 flex-1 flex-col gap-1.5 py-2",!m&&"border-l pl-5",!i&&"pr-5"),children:[e.jsx("span",{className:"text-2xs font-medium tracking-[0.06em] text-muted-foreground uppercase",children:t}),e.jsxs("div",{className:"flex items-end justify-between gap-3",children:[e.jsxs("span",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-[26px] leading-[30px] font-display tracking-[-0.01em] text-foreground tabular-nums",children:s}),a?e.jsx("span",{className:"text-2xs text-muted-foreground",children:a}):null]}),e.jsx("span",{className:"shrink-0",children:x})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l!=="flat"?e.jsx(c,{className:k("size-2.5",l==="up"?"text-success":"text-danger"),strokeWidth:2.5}):null,e.jsx("span",{className:k("text-2xs font-medium",l==="up"&&"text-success",l==="down"&&"text-danger",l==="flat"&&"text-foreground"),children:n}),e.jsx("span",{className:"truncate text-2xs text-faint-foreground",children:o})]})]})}function We({values:t}){const s=Math.max(1,...t),a=Math.max(0,t.length-8);return e.jsx("div",{className:"flex h-6 items-end gap-[2px]",children:t.map((n,l)=>e.jsx("span",{className:k("w-[3px] rounded-full",l<a?"bg-muted":"bg-primary/85",l===t.length-1&&"bg-primary"),style:{height:`${Math.max(8,Math.round(n/s*100))}%`}},l))})}function kt({values:t}){if(t.length<2)return null;const s=64,a=28,n=3,l=Math.min(...t),x=Math.max(...t)-l||1,m=(s-n*2)/(t.length-1),i=f=>a-n-(f-l)/x*(a-n*2);let c=`M${n} ${i(t[0])}`;
1return t.slice(1).forEach((f,O)=>{const b=n+(O+1)*m;c+=` H${b} V${i(f)}`}),e.jsxs("svg",{width:s,height:a,"aria-hidden":"true",children:[e.jsx("path",{d:c,fill:"none",stroke:M,strokeWidth:2,strokeLinejoin:"round"}),e.jsx("circle",{cx:s-n,cy:i(t[t.length-1]),r:2.5,fill:M})]})}function Ct({rounds:t}){return t.length===0?null:e.jsx("div",{className:"flex items-center gap-1",children:t.map((s,a)=>e.jsx("span",{className:k("size-[7px] rounded-full",s.live?"border-[1.5px] border-primary bg-primary/15":s.promoted?"bg-primary":"bg-muted")},a))})}const le=(t,s=0)=>`${t>=0?"+":"â"}${Math.abs(t).toFixed(s)}`,we=t=>t>0?"up":t<0?"down":"flat";function St({daily:t,totals:s,entries:a}){const n=t.slice(-8),l=t.slice(-16,-8),o=(g,j)=>g.reduce((D,z)=>D+z[j],0),x=o(n,"visitors"),m=o(l,"visitors"),i=o(n,"conversions"),c=o(l,"conversions"),f=x>0?i/x:0,O=m>0?c/m:0,b=(f-O)*100,F=u.useMemo(()=>{let g=0;return n.map(j=>(j.visitors>0&&(g=j.conversions/j.visitors),g))},[n]),A=u.useMemo(()=>a.filter(g=>g.experiment.status!=="draft").slice(0,8).reverse().map(g=>({promoted:g.experiment.outcome==="promoted",live:g.experiment.status!=="completed"})),[a]),P=(s==null?void 0:s.promoted)??0,I=(s==null?void 0:s.rounds_tested)??0;return e.jsxs("div",{className:"flex items-stretch overflow-x-auto",children:[e.jsx(re,{first:!0,last:!1,label:"Traffic",value:x.toLocaleString(),unit:"visitors",deltaStrong:le(x-m),deltaTone:we(x-m),deltaMuted:"vs. past week",visual:e.jsx(We,{values:t.map(g=>g.visitors)})}),e.jsx(re,{first:!1,last:!1,label:"Conversions",value:i.toLocaleString(),unit:"conversions",deltaStrong:le(i-c),deltaTone:we(i-c),deltaMuted:"vs. past week",visual:e.jsx(We,{values:t.map(g=>g.conversions)})}),e.jsx(re,{first:!1,last:!1,label:"Conversion rate",value:`${(f*100).toFixed(1)}%`,deltaStrong:`${le(b,1)} pts`,deltaTone:we(b),deltaMuted:"vs. past week",visual:e.jsx(kt,{values:F})}),e.jsx(re,{first:!1,last:!0,label:"Rounds",value:P.toLocaleString(),unit:"promoted",deltaStrong:`${I} rounds`,deltaTone:"flat",deltaMuted:"tested all-time",visual:e.jsx(Ct,{rounds:A})})]})}function At({active:t,payload:s}){var l;const a=(l=s==null?void 0:s[0])==null?void 0:l.payload;if(!t||!a)return null;const n=a.champion??a.pending;return e.jsxs("div",{className:"rounded-lg border border-border bg-popover px-2.5 py-2 text-xs shadow-md",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"font-medium text-foreground",children:["Round ",a.round]}),e.jsx("span",{className:"text-2xs text-muted-foreground",children:a.decided?a.promoted!=null?"Challenger promoted":"Champion held":"Running"})]}),n!=null?e.jsxs("div",{className:"mt-0.5 font-semibold text-foreground tabular-nums",children:[ie(n),e.jsx("span",{className:"ml-1.5 text-2xs font-normal text-muted-foreground",children:"champion rate"})]}):null,a.change?e.jsx("p",{className:"mt-1 max-w-[220px] text-2xs leading-snug text-muted-foreground",children:a.change}):null]})}function ke({children:t,swatch:s}){return e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs text-muted-foreground",children:[s,t]})}function Pt({points:t}){var n,l;const s=u.useMemo(()=>{const o=t.map(c=>c.champion??c.pending).filter(c=>c!=null);if(o.length===0)return[0,1];const x=Math.min(...o),m=Math.max(...o),i=Math.max((m-x)*.4,.003);return[Math.max(0,x-i),m+i]},[t]),a=((n=t[0])==null?void 0:n.champion)??((l=t[0])==null?void 0:l.pending)??null;return e.jsx(_s,{config:{champion:{label:"Champion",color:M}},className:"mt-2.5 min-h-[190px] w-full flex-1",children:e.jsxs(zs,{data:t,margin:{top:8,right:12,left:4},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"autopilot-champion",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:M,stopOpacity:.14}),e.jsx("stop",{offset:"100%",stopColor:M,stopOpacity:.02})]})}),e.jsx(nt,{vertical:!1,stroke:"var(--border)"}),e.jsx(at,{dataKey:"label",tickLine:!1,axisLine:!1,tickMargin:8,tick:{fontSize:10,fill:"var(--faint-foreground)"}}),e.jsx(rt,{domain:s,tickLine:!1,axisLine:!1,width:46,tick:{fontSize:10,fill:"var(--faint-foreground)"},tickFormatter:o=>ie(o)}),e.jsx(Rs,{cursor:{stroke:"var(--border)"},content:e.jsx(At,{})}),a!=null?e.jsx(Ke,{y:a,stroke:"var(--muted-foreground)",strokeOpacity:.5,strokeDasharray:"4 4"}):null,e.jsx(lt,{dataKey:"champion",type:"stepAfter",stroke:"none",fill:"url(#autopilot-champion)",connectNulls:!0,isAnimationActive:!1}),e.jsx(ae,{dataKey:"champion",type:"stepAfter",stroke:M,strokeWidth:2,dot:!1,activeDot:!1,connectNulls:!0,isAnimationActive:!1}),e.jsx(ae,{dataKey:"pending",type:"stepAfter",stroke:M,strokeWidth:2,strokeOpacity:.6,strokeDasharray:"3 4",dot:!1,activeDot:!1,connectNulls:!0,isAnimationActive:!1}),e.jsx(ae,{dataKey:"promoted",stroke:"none",activeDot:!1,isAnimationActive:!1,dot:{r:3.5,fill:M,stroke:"var(--card)",strokeWidth:1.5}}),e.jsx(ae,{dataKey:"live",stroke:"none",activeDot:!1,isAnimationActive:!1,dot:{r:4,fill:M,stroke:M,strokeWidth:6,strokeOpacity:.18}})]})})}function Be({letter:t,name:s,value:a,fill:n,leading:l}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:k("flex h-[18px] min-w-[18px] shrink-0 items-center justify-center rounded px-0.5 text-2xs font-bold",l?"bg-primary text-primary-foreground":"border border-border bg-background text-foreground"),children:t}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[e.jsx("span",{className:k("truncate text-2xs",l?"font-semibold text-foreground":"text-foreground"),title:s,children:s}),n!=null?e.jsx("span",{className:"h-[3px] overflow-hidden rounded-full bg-muted",children:e.jsx("span",{className:k("block h-full rounded-full",l?"bg-primary":"bg-muted-foreground
1/45"),style:{width:`${Math.round(n*100)}%`}})}):null]}),e.jsx("span",{className:k("shrink-0 font-mono text-2xs tabular-nums",l?"font-semibold text-primary":"text-muted-foreground"),children:a})]})}function It({entry:t,chain:s,workspaceSlug:a}){var w,G,X,Z,Y,W,B;const{experiment:n}=t,l=u.useMemo(()=>Ms(s),[s]),o=l[l.length-1],x=(o==null?void 0:o.champion)??(o==null?void 0:o.pending)??null,m=((w=l[0])==null?void 0:w.champion)??((G=l[0])==null?void 0:G.pending)??null,i=x!=null&&m!=null&&m>0?(x-m)/m:null,c=n.variants.find(v=>v.role==="control"),f=n.variants.filter(v=>v.role==="challenger").map((v,C)=>{var _;return{variant:v,letter:Os(C+1),prob:((_=v.stats)==null?void 0:_.prob_beats_control)??null}}).sort((v,C)=>(C.prob??-1)-(v.prob??-1)),O=(X=f.find(({prob:v})=>v!=null))==null?void 0:X.variant.id,[b,F]=u.useState(!1),A=f.length>Ne+1,P=b||!A?f:f.slice(0,Ne),I=((Z=n.verdict)==null?void 0:Z.sessions)??n.variants.reduce((v,C)=>{var _;return v+(((_=C.stats)==null?void 0:_.visitors)??0)},0),g=((Y=n.verdict)==null?void 0:Y.sessions_target)??n.sessions_per_round??null,j=g&&g>0?Math.min(1,I/g):null,D=t.total_rounds??n.total_rounds??null,z=n.variants.length||1,d=c&&/champion/i.test(c.name)?c.name:`${(c==null?void 0:c.name)??"Champion"} â champion`,T=c!=null&&c.stats&&c.stats.visitors>0?ie(c.stats.conversion_rate):"â";return e.jsxs("section",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"flex items-center justify-end gap-3",children:e.jsxs(as,{to:`/workspaces/${a}/autopilot/${n.product_id}`,className:"flex shrink-0 items-center gap-1 text-2xs font-medium text-muted-foreground hover:text-foreground",children:["View experiment",e.jsx($s,{className:"size-3"})]})}),e.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:gap-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"text-2xs font-medium tracking-[0.06em] text-muted-foreground uppercase",children:"Conversion rate by round"}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-[26px] leading-[30px] font-display tracking-[-0.01em] text-foreground tabular-nums",children:x!=null?ie(x):"â"}),i!=null&&l.length>1?e.jsxs("span",{className:k("text-2xs font-semibold tabular-nums",i>0?"text-success":i<0?"text-danger":"text-muted-foreground"),children:[le(i*100),"% since round ",l[0].round]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3.5 gap-y-1 pt-1",children:[e.jsx(ke,{swatch:e.jsx("span",{className:"h-0.5 w-3.5 rounded-full",style:{background:M}}),children:"Champion lineage"}),e.jsx(ke,{swatch:e.jsx("span",{className:"size-2 rounded-full ring-2",style:{background:M,boxShadow:`0 0 0 2px color-mix(in oklab, ${M} 20%, transparent)`}}),children:"Promotion"}),e.jsxs(ke,{swatch:e.jsx("span",{className:"w-3.5 border-t-2 border-dashed border-muted-foreground/60"}),children:["Round ",((W=l[0])==null?void 0:W.round)??1," baseline"]})]})]}),l.length>1?e.jsx(Pt,{points:l}):e.jsx("div",{className:"mt-3 flex h-[190px] items-center justify-center rounded-lg border border-dashed border-border px-6 text-center",children:e.jsx("p",{className:"max-w-xs text-xs text-muted-foreground",children:"The curve appears once a round has been decided â this experiment is still measuring its first one."})})]}),e.jsxs("aside",{className:"flex w-full shrink-0 flex-col gap-3 border-t border-border pt-4 lg:w-80 lg:border-t-0 lg:border-l lg:pt-0 lg:pl-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-2xs font-medium tracking-[0.06em] text-muted-foreground uppercase",children:"This round"}),e.jsxs("span",{className:"text-2xs text-muted-foreground tabular-nums",children:["Round ",n.round,D?` of ${D}`:""]})]}),j!=null?e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"h-1.5 overflow-hidden rounded-full bg-muted",children:e.jsx("span",{className:"block h-full rounded-full bg-primary transition-[width] duration-700",style:{width:`${Math.round(j*100)}%`}})}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsxs("span",{className:"font-mono text-2xs text-muted-foreground tabular-nums",children:[I.toLocaleStr
1ing()," /"," ",g==null?void 0:g.toLocaleString()," sessions"]}),((B=n.verdict)==null?void 0:B.days_running)!=null?e.jsxs("span",{className:"text-2xs text-muted-foreground",children:["day ",n.verdict.days_running]}):null]})]}):e.jsxs("span",{className:"font-mono text-2xs text-muted-foreground tabular-nums",children:[I.toLocaleString()," sessions collected"]}),e.jsx("span",{className:"h-px bg-border"}),e.jsx("span",{className:"text-2xs font-medium tracking-[0.06em] text-muted-foreground uppercase",children:"Chance to beat champion"}),c?e.jsx(Be,{letter:"A",name:d,value:T,fill:null,leading:!1}):null,f.length>0?e.jsx("div",{className:k("flex flex-col gap-2.5",b&&A&&"max-h-80 overflow-y-auto pr-1"),children:P.map(({variant:v,letter:C,prob:_})=>e.jsx(Be,{letter:C,name:v.name,value:_!=null?`${Math.round(_*100)}%`:"â",fill:_,leading:v.id===O},v.id))}):null,A?e.jsx("button",{type:"button",onClick:()=>F(v=>!v),className:"flex items-center gap-1 self-start text-2xs font-medium text-muted-foreground transition-colors hover:text-foreground",children:b?e.jsxs(e.Fragment,{children:["Show top ",Ne,e.jsx(Ns,{className:"size-3"})]}):e.jsxs(e.Fragment,{children:["Show all ",f.length," arms",e.jsx(He,{className:"size-3"})]})}):null,f.every(({prob:v})=>v==null)?e.jsx("p",{className:"text-2xs leading-snug text-muted-foreground",children:"Win probabilities appear once this round has collected enough traffic to tell the arms apart."}):null,e.jsxs("p",{className:"mt-auto pt-1 text-2xs text-muted-foreground",children:["Traffic splits evenly â ",Math.floor(100/z),"% per arm."]})]})]})]})}function Lt(){return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx("div",{className:"flex items-stretch overflow-x-auto",children:Array.from({length:4},(t,s)=>e.jsxs("div",{className:k("flex min-w-44 flex-1 flex-col gap-1.5 py-2",s>0&&"border-l pl-5",s<3&&"pr-5"),children:[e.jsx(L,{className:"h-3 w-20 rounded-md"}),e.jsx(L,{className:"h-[30px] w-24 rounded-md"}),e.jsx(L,{className:"h-3 w-28 rounded-md"})]},s))}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(L,{className:"h-4 w-56 rounded-md"}),e.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:gap-6",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[e.jsx(L,{className:"h-3 w-40 rounded-md"}),e.jsx(L,{className:"h-[30px] w-24 rounded-md"}),e.jsx(L,{className:"mt-1 h-[190px] rounded-lg"})]}),e.jsxs("div",{className:"flex w-full shrink-0 flex-col gap-3 border-t border-border pt-4 lg:w-80 lg:border-t-0 lg:border-l lg:pt-0 lg:pl-6",children:[e.jsx(L,{className:"h-3 w-24 rounded-md"}),e.jsx(L,{className:"h-1.5 w-full rounded-full"}),e.jsx(L,{className:"h-3 w-36 rounded-md"}),e.jsx(L,{className:"mt-2 h-3 w-32 rounded-md"}),e.jsx(L,{className:"h-8 w-full rounded-md"}),e.jsx(L,{className:"h-8 w-full rounded-md"})]})]})]})]})}function Mt({prob:t}){const s=Math.round(t*100),a=s>=95;return e.jsxs("span",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{className:"h-1 w-16 overflow-hidden rounded-full bg-muted",children:e.jsx("span",{className:k("block h-full rounded-full",a?"bg-success":s>=50?"bg-primary":"bg-muted-foreground/45"),style:{width:`${s}%`}})}),e.jsxs("span",{className:k("w-9 text-right font-medium tabular-nums",a?"text-success":"text-foreground"),children:[s,"%"]})]})}const Ot=t=>t.reduce((s,a)=>{var n;return s+(((n=a.stats)==null?void 0:n.visitors)??0)},0),Dt=t=>t.filter(s=>s.role==="challenger").reduce((s,a)=>{var n,l;return(((n=a.stats)==null?void 0:n.prob_beats_control)??-1)>(((l=s==null?void 0:s.stats)==null?void 0:l.prob_beats_control)??-1)?a:s},null),Et=t=>{const s=new Map;for(const a of t){const n=s.get(a.experiment.product_id);
1n?n.push(a):s.set(a.experiment.product_id,[a])}return[...s.entries()].map(([a,n])=>{var x,m;const l=n.find(({experiment:i})=>i.status!=="completed")??n[0],o=Dt(l.experiment.variants);return{campaignId:a,entry:l,rounds:n,visitors:n.reduce((i,c)=>i+Ot(c.experiment.variants),0),prob:((x=o==null?void 0:o.stats)==null?void 0:x.prob_beats_control)??null,lift:((m=o==null?void 0:o.stats)==null?void 0:m.adjusted_lift)??null}})},Ve={status:"Status",outcome:"Outcome",metric:"Metric"},_t={status:[{value:"running",label:"Running"},{value:"draft",label:"Draft"},{value:"paused",label:"Paused"},{value:"completed",label:"Completed"}],outcome:[{value:"promoted",label:"Promoted"},{value:"no_winner",label:"No winner"},{value:"stopped",label:"Stopped"}],metric:[{value:"form_submissions",label:"Form submissions"},{value:"button_clicks",label:"Button clicks"}]};function Wn(){Ss();const{workspaceSlug:t}=rs(ls({workspaceSlug:is()}),{workspaceSlug:localStorage.getItem("slug")??""}),s=os(),a=()=>s.push(`/workspaces/${t}/autopilot/new-experiment`),[n,l]=u.useState(""),[o,x]=u.useState(!1),[m,i]=u.useState([]),[c,f]=u.useState([]),[O,b]=u.useState(!1),[F,A]=u.useState(!1),[P,I]=u.useState(null),[g,j]=u.useState(1),[D,z]=u.useState(25),{data:d,isLoading:T,refetch:w,isRefetching:G}=Ps({workspaceSlug:t},{refetchInterval:r=>{var h;return(((h=r.state.data)==null?void 0:h.totals.running)??0)>0?15e3:!1}}),{mutateAsync:X,isPending:Z}=Is(),{mutateAsync:Y,isPending:W}=Ls(),B=d==null?void 0:d.totals,v=u.useMemo(()=>(d==null?void 0:d.daily)??[],[d==null?void 0:d.daily]),C=u.useMemo(()=>[...(d==null?void 0:d.active)??[],...(d==null?void 0:d.recent)??[]],[d==null?void 0:d.active,d==null?void 0:d.recent]),_=(B==null?void 0:B.running)??0,q=u.useMemo(()=>((d==null?void 0:d.active)??[]).find(r=>r.experiment.status==="running")??((d==null?void 0:d.active)??[])[0]??((d==null?void 0:d.recent)??[])[0]??null,[d==null?void 0:d.active,d==null?void 0:d.recent]),Ue=u.useMemo(()=>q?C.filter(r=>r.experiment.product_id===q.experiment.product_id).map(r=>r.experiment):[],[C,q]),ce=u.useMemo(()=>Et(C),[C]),de=u.useMemo(()=>m.filter(r=>r.field&&r.value),[m]),me=de.length,J=u.useMemo(()=>{const r=n.trim().toLowerCase();return ce.filter(h=>{const{experiment:p,campaign:E}=h.entry;for(const y of de)if(y.field==="status"&&p.status!==y.value||y.field==="outcome"&&(p.status!=="completed"||p.outcome!==y.value)||y.field==="metric"&&p.primary_metric!==y.value)return!1;return!(r&&![(E==null?void 0:E.name)??"",...h.rounds.flatMap(({experiment:N})=>[N.name,N.hypothesis??""])].join(" ").toLowerCase().includes(r))})},[ce,n,de]),Ce=Math.max(1,Math.ceil(J.length/D)),Q=Math.min(g,Ce),ee=J.slice((Q-1)*D,Q*D),se=ee.map(r=>r.campaignId),Ge=se.length>0&&se.every(r=>c.includes(r)),Xe=r=>{typeof r!="string"&&f(h=>r?[...new Set([...h,...se])]:h.filter(p=>!se.includes(p)))},Ye=(r,h)=>f(p=>r?[...p,h]:p.filter(E=>E!==h)),K=ce.filter(r=>c.includes(r.campaignId)),V=K.filter(r=>r.entry.experiment.status!=="completed"),qe=async()=>{b(!1);try{for(const r of V)await X({workspaceSlug:t,campaignId:r.campaignId,experimentId:r.entry.experiment.id,action:"stop"});H.success(`Stopped ${V.length} experiment${V.length===1?"":"s"}.`),f([]),w()}catch{H.error("Some experiments could not be stopped â try again.")}},Ze=async()=>{A(!1);const r=K;try{for(const h of r)await Y({workspaceSlug:t,campaignId:h.campaignId});H.success(`Deleted ${r.length} experiment${r.length===1?"":"s"}.`),f([]),w()}catch{H.error("Some experiments could not be deleted â try again."),w()}},Je=async r=>{try{await Y({workspaceSlug:t,campaignId:r.campaignId}),H.success("Experiment deleted.")}catch{H.error("Could not delete the experiment.")}finally{I(null),f(h=>h.filter(p=>p!==r.campaignId)),w()}},xe=(r,h)=>X({workspaceSlug:t,campaignId:r.campaignId,experimentId:r.entry.experiment.id,action:h}).then(()=>w()).catch(()=>H.error("That didn't work â try again.")),Qe=()=>i(r=>[...r,{id:crypto.randomUUID(),field:"",value:""}]),es=r=>{i(h=>h.filter(p=>p.id!==r)),j(1)},ss=()=>{i([]),j(1)},ts=r=>r?new Date(r).toLocaleDateString("en-US",{month:"short",day:"numeric"}):"â",Se=r=>
1s.push(`/workspaces/${t}/autopilot/${r.campaignId}`);return e.jsxs("section",{className:"relative flex min-h-0 flex-1 flex-col bg-background",children:[e.jsx("div",{className:"flex w-full flex-col items-start",children:e.jsx(cs,{title:"Autopilot",counts:_})}),e.jsxs("div",{className:hs,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ds,{className:"absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ms,{value:n,onChange:r=>{l(r.target.value),j(1)},placeholder:"Search experimentsâ¦",className:"w-52 pl-8"})]}),e.jsxs(vs,{open:o,onOpenChange:x,children:[e.jsx(js,{asChild:!0,children:e.jsxs(S,{variant:"outline",className:"gap-2",children:[e.jsx(it,{className:"size-4"}),"Filters",me>0&&e.jsx("span",{className:"flex size-5 items-center justify-center rounded-full bg-primary text-2xs font-medium text-primary-foreground",children:me}),e.jsx(He,{className:"size-4"})]})}),e.jsxs(bs,{align:"start",className:"w-auto min-w-[380px] p-0",sideOffset:8,children:[e.jsx("div",{className:"max-h-[400px] overflow-y-auto p-3",children:m.length===0?e.jsx("div",{className:"py-4 text-center text-xs text-muted-foreground",children:'No filters applied. Click "Add filter" to get started.'}):e.jsx("div",{className:"space-y-2",children:m.map((r,h)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-12 shrink-0 text-xs text-muted-foreground",children:h===0?"Where":"and"}),e.jsxs(Me,{value:r.field,onValueChange:p=>{i(E=>E.map(y=>y.id===r.id?{...y,field:p,value:""}:y)),j(1)},children:[e.jsx(Oe,{className:"w-[120px]",children:e.jsx(De,{placeholder:"Select field"})}),e.jsx(Ee,{children:Object.keys(Ve).map(p=>e.jsx(_e,{value:p,children:Ve[p]},p))})]}),e.jsxs(Me,{value:r.value,onValueChange:p=>{i(E=>E.map(y=>y.id===r.id?{...y,value:p}:y)),j(1)},disabled:!r.field,children:[e.jsx(Oe,{className:"w-[170px]",children:e.jsx(De,{placeholder:"Select value"})}),e.jsx(Ee,{children:r.field&&_t[r.field].map(p=>e.jsx(_e,{value:p.value,children:p.label},p.value))})]}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>es(r.id),children:e.jsx(Pe,{className:"size-4"})})]},r.id))})}),e.jsxs("div",{className:"flex items-center gap-2 border-t px-3 py-2",children:[e.jsxs(S,{type:"button",variant:"ghost",size:"sm",onClick:Qe,children:[e.jsx(ot,{className:"size-3.5"}),"Add Filter"]}),me>0&&e.jsxs(S,{type:"button",variant:"ghost",size:"sm",onClick:ss,className:"text-destructive hover:text-destructive",children:[e.jsx(Pe,{className:"size-3.5"}),"Clear Filters"]})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[V.length>0?e.jsxs(S,{variant:"outline",className:"gap-1.5 text-destructive hover:text-destructive",disabled:Z,onClick:()=>b(!0),children:[e.jsx(Fe,{className:"size-3"}),"Stop Selected (",V.length,")"]}):null,K.length>0?e.jsxs(S,{variant:"outline",className:"gap-1.5 text-destructive hover:text-destructive",disabled:W,onClick:()=>A(!0),children:[e.jsx(Ie,{className:"size-3.5"}),W?"Deletingâ¦":`Delete selected (${K.length})`]}):null,e.jsxs(S,{variant:"outline",className:"gap-1.5",disabled:G,onClick:()=>w(),children:[G?e.jsx(xs,{className:"size-3.5"}):e.jsx(ct,{className:"size-3.5"}),"Refresh"]}),e.jsxs(S,{className:"gap-1.5",onClick:a,children:[e.jsx(ye,{className:"size-3.5"}),"New Experiment"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-auto",children:[e.jsx("div",{className:"flex flex-col gap-5 border-b border-border px-shell py-shell",children:T?e.jsx(Lt,{}):e.jsxs(e.Fragment,{children:[e.jsx(St,{daily:v,totals:B,entries:C}),q?e.jsx(It,{entry:q,chain:Ue,workspaceSlug:t}):null]})}),T?e.jsx(fs,{}):C.length===0?e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsx(As,{from:"experiments",search:n,icon:e.jsx(ye,{className:"text-muted-foreground","aria-hidden":"true"}),firstText:"Run your first experiment",secondText:"Your live page is the champion. Test a challenger against it â traffic decides, and you promote the winner.",buttonText:"New experiment",onButtonClick:a,showBackgroun
1dImages:!1})}):e.jsxs(e.Fragment,{children:[e.jsxs(ws,{className:`w-full ${gs}`,children:[e.jsx(ks,{children:e.jsxs(be,{className:"group",children:[e.jsx($,{className:"px-4",children:ee.length>0&&e.jsx("div",{className:"flex items-center",children:e.jsx(Le,{checked:Ge,onCheckedChange:Xe})})}),e.jsx($,{className:"px-4",children:"Experiment"}),e.jsx($,{className:"px-4",children:"Status"}),e.jsx($,{className:"px-4",children:"Page"}),e.jsx($,{className:"px-4 text-right",children:"Rounds"}),e.jsx($,{className:"px-4 text-right",children:"Visitors"}),e.jsx($,{className:"px-4 text-right",children:"Chance to win"}),e.jsx($,{className:"px-4 text-right",children:"Lift"}),e.jsx($,{className:"px-4 text-right",children:"Date"}),e.jsx($,{className:"sticky right-0 w-12 bg-background px-2 text-center",children:e.jsx("span",{className:"sr-only",children:"Actions"})})]})}),e.jsx(Cs,{children:ee.length===0?e.jsx(be,{className:"hover:bg-transparent",children:e.jsx(R,{colSpan:10,className:"py-10 text-center text-muted-foreground",children:"No experiments match these filters."})}):ee.map((r,h)=>{const{entry:p,visitors:E,prob:y}=r,{experiment:N,campaign:ue}=p,Ae=N.status==="completed";return e.jsxs(be,{className:"cursor-pointer",onClick:te=>{te.target.closest("a,button,input,[role='checkbox'],[role='menuitem']")||Se(r)},children:[e.jsx(R,{className:"px-4 py-2 leading-none text-nowrap text-foreground",children:e.jsx(Le,{name:"select-one",id:`experiment-${h}`,checked:c.includes(r.campaignId),onCheckedChange:te=>{typeof te!="string"&&Ye(te,r.campaignId)}})}),e.jsxs(R,{className:"max-w-[260px] px-4 py-2",children:[e.jsx("div",{className:"flex items-baseline gap-1.5",children:e.jsx("span",{className:"truncate font-medium text-foreground",children:N.name})}),N.hypothesis?e.jsx("div",{className:"truncate text-2xs text-muted-foreground",title:N.hypothesis,children:N.hypothesis}):null]}),e.jsx(R,{className:"px-4 py-2",children:e.jsx(Ds,{experiment:p.experiment})}),e.jsx(R,{className:"max-w-[180px] px-4 py-2",children:e.jsx("span",{className:"block truncate text-muted-foreground",children:(ue==null?void 0:ue.name)??"Deleted campaign"})}),e.jsxs(R,{className:"px-4 py-2 text-right tabular-nums",children:[N.round,p.total_rounds?e.jsxs("span",{className:"text-muted-foreground",children:[" ","of ",p.total_rounds]}):null]}),e.jsx(R,{className:"px-4 py-2 text-right tabular-nums",children:E>0?E.toLocaleString():"â"}),e.jsx(R,{className:"px-4 py-2 text-right tabular-nums",children:y!=null&&N.status!=="draft"?e.jsx(Mt,{prob:y}):"â"}),e.jsx(R,{className:"px-4 py-2 text-right",children:N.status!=="draft"&&r.lift!=null?e.jsx("span",{className:k("font-medium tabular-nums",r.lift>.005?"text-success":r.lift<-.005?"text-danger":"text-muted-foreground"),children:Es(r.lift)}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(R,{className:"px-4 py-2 text-right whitespace-nowrap text-muted-foreground tabular-nums",children:ts(Ae?N.ended_at:N.started_at??N.created_at)}),e.jsx(R,{className:"sticky right-0 w-12 bg-background px-2",children:e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(ps,{className:"bg-transparent hover:bg-accent",items:[{icon:us,label:"View Experiment",onClick:()=>Se(r)},...N.status==="draft"||N.status==="paused"?[{icon:dt,label:N.status==="draft"?"Start":"Resume",onClick:()=>void xe(r,"start")}]:[],...N.status==="running"?[{icon:mt,label:"Pause",onClick:()=>void xe(r,"pause")}]:[],...Ae?[{icon:ye,label:"Continue Experiment",onClick:()=>s.push(`/workspaces/${t}/autopilot/new-experiment?campaign=${r.campaignId}&round=1`)}]:[{icon:Fe,label:"Stop",type:"destructive",onClick:()=>void xe(r,"stop")}],{icon:Ie,label:"Delete Experiment",type:"destructive",onClick:()=>I(r)}]})})})]},r.campaignId)})})]}),e.jsx(ys,{tableId:"experiments",currentPage:Q,totalPages:Ce,totalRecords:J.length,perPage:D,onPageChange:r=>j(r),onPerPageChange:r=>{const h=r,p=Math.ceil(J.length/h);z(h),j(Math.min(Q,p||1))},loading:T})]})]}),e.jsx(pe,{open:P!==null,onOpenChange:r=>!r&&I(null),children:e.jsxs(fe,{className:"sm:max-w-sm",children:[e.jsxs(he,{children:[e.jsxs(ge,{children:["Delete â",P==null?void 0:P.entry.experiment.name,"â?"]}
1),e.jsx(ve,{children:"Every round of this experiment and its frozen variants are removed permanently. The live page is not affected â visitors keep seeing the deployed champion."})]}),e.jsxs(je,{children:[e.jsx(S,{variant:"outline",onClick:()=>I(null),children:"Cancel"}),e.jsx(S,{variant:"destructive",disabled:W,onClick:()=>P&&void Je(P),children:"Delete Experiment"})]})]})}),e.jsx(pe,{open:F,onOpenChange:A,children:e.jsxs(fe,{className:"sm:max-w-sm",children:[e.jsxs(he,{children:[e.jsxs(ge,{children:["Delete ",K.length," experiment",K.length===1?"":"s","?"]}),e.jsx(ve,{children:"Every round they contain and its frozen variants are removed permanently. Live pages are not affected â visitors keep seeing the deployed champion."})]}),e.jsxs(je,{children:[e.jsx(S,{variant:"outline",onClick:()=>A(!1),children:"Cancel"}),e.jsx(S,{variant:"destructive",disabled:W,onClick:()=>void Ze(),children:"Delete Experiments"})]})]})}),e.jsx(pe,{open:O,onOpenChange:b,children:e.jsxs(fe,{className:"sm:max-w-sm",children:[e.jsxs(he,{children:[e.jsx(ge,{children:"Stop selected experiments?"}),e.jsxs(ve,{children:[V.length," experiment",V.length===1?"":"s"," will stop splitting traffic. The live champion keeps serving; results are archived without a winner."]})]}),e.jsxs(je,{children:[e.jsx(S,{variant:"outline",onClick:()=>b(!1),children:"Cancel"}),e.jsx(S,{variant:"destructive",onClick:()=>void qe(),children:"Stop Experiments"})]})]})})]})}export{Wn 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.