import{hP as c,db as m,hQ as u,cK as x,a as f,a$ as g,r as d,j as b,hG as C,hH as h,hI as v,hJ as M,hK as S,hL as q,hN as L,hM as $,hR as D}from"./index-DxWYYOj0.js";import{L as E}from"./index-COns9WGJ.js";import{d as T}from"./FeatureViewLazyExport-8nsrSDh2.js";import"./FeatureStaleDialog-cdEqxBnj.js";import"./StrategyItemContainer-BlDhu_Ki.js";const j=(e,l,s)=>{const a={label:"Total requests",borderColor:e.palette.primary.main,backgroundColor:e.palette.primary.main,data:p(l,s,o=>o.yes+o.no),elements:{point:{radius:6,pointStyle:"circle"},line:{borderDash:[8,4]}}},t={label:"Exposed",borderColor:e.palette.success.main,backgroundColor:e.palette.success.main,data:p(l,s,o=>o.yes),elements:{point:{radius:6,pointStyle:"triangle"}}},r={label:"Not exposed",borderColor:e.palette.error.main,backgroundColor:e.palette.error.main,data:p(l,s,o=>o.no),elements:{point:{radius:6,pointStyle:"triangle",pointRotation:180}}};return{datasets:[t,r,a]}},p=(e,l,s)=>e.map(a=>({x:a.timestamp,y:s(a),variants:a.variants||{}})),P=(e,l)=>{if(l===0)return"";const[s,a]=e,t=Math.floor(Number(a)/l*100);return`${a} (${t}%) - ${s}`},R=(e,l,s,a)=>({locale:a.locale,responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},color:e.palette.text.secondary,plugins:{tooltip:{backgroundColor:e.palette.background.paper,bodyColor:e.palette.text.primary,titleColor:e.palette.text.secondary,borderColor:e.palette.primary.main,borderWidth:1,padding:10,boxPadding:5,usePointStyle:!0,itemSort:(t,r)=>{const o=["Total requests","Exposed","Not exposed"],n=o.indexOf(t.dataset.label),i=o.indexOf(r.dataset.label);return n-i},callbacks:{label:t=>`${t.formattedValue} - ${t.dataset.label}`,afterLabel:t=>{const r=t.dataset.data[t.dataIndex];if(t.dataset.label!=="Exposed"||r.variants===void 0)return"";const{disabled:o,...n}=r.variants;return Object.entries(n).map(i=>P(i,r.y)).join(`
`)},title:t=>`Time: ${s>48?m(t[0].parsed.x,a.locale,"UTC"):u(t[0].parsed.x,a.locale)}`}},legend:{position:"top",align:"end",labels:{boxWidth:10,boxHeight:10,usePointStyle:!0}},title:{text:k(s),position:"top",align:"start",display:!0,font:{size:16,weight:"400"},color:e.palette.text.primary}},scales:{y:{type:"linear",title:{display:!0,text:"Number of requests",color:e.palette.text.secondary},suggestedMin:0,ticks:{precision:0,color:e.palette.text.secondary},grid:{color:e.palette.divider,borderColor:e.palette.divider}},x:{type:"time",time:{unit:s>48?"day":"hour"},grid:{display:!1},ticks:{callback:(t,r,o)=>s>48?x(o[r].value,a.locale,"UTC"):u(o[r].value,a.locale),color:e.palette.text.secondary}}}}),k=e=>e===1?"Requests in the last hour":`Requests in the last ${T(e)}`;c.font={...c.font,family:"Sen",size:13,weight:"400"};const w=({metrics:e,hoursBack:l,statsSectionId:s})=>{const a=f(),{locationSettings:t}=g(),r=d.useMemo(()=>[...e].sort((i,y)=>i.timestamp.localeCompare(y.timestamp)),[e]),o=d.useMemo(()=>R(a,r,l,t),[a,r,l,t]),n=d.useMemo(()=>j(a,r,t),[a,r,t]);return b.jsx("div",{style:{height:400},children:b.jsx(E,{options:o,data:n,"aria-label":"A feature metrics line chart, with three lines: all requests, positive requests, and negative requests.","aria-describedby":s})})};C.register(h,v,M,S,q,L,$,D);export{w as FeatureMetricsChart,w as default};
