import{r as o,j as n,a as L,f as d,ai as O,a0 as b,i as j,Q as w,aj as R}from"./index-B-YXshIJ.js";import{I as U,E as P}from"./Icons-C9UDsqhh.js";import{T,g as y}from"./TinyAreaGraph-CpO36t7S.js";import{u as M}from"./Drawer-B-IR3T8V.js";import{b as l,c as F}from"./query-hooks-C0Pc4MKj.js";import{u as q}from"./Filters-DsROmhj9.js";const C=({title:s,value:e,tooltip:r,onClick:t,...a})=>{const[i,c,m]=M(),[p,$]=o.useState({heading:"Loading...",children:"Loading..."}),x=o.useCallback(()=>{t&&t.open==="drawer"&&($({heading:t.heading,children:n.jsx(o.Suspense,{fallback:n.jsx(L,{}),children:t.body}),downloadUrl:t.downloadUrl}),m())},[t,m]),S=o.useMemo(()=>n.jsxs("h3",{className:"font-semibold mb-3 flex items-start",children:[s,r===void 0?null:n.jsx("span",{className:"text-theme-icon hover:text-theme-icon-active","data-tooltip-id":"react-tooltip","data-tooltip-html":r||void 0,children:n.jsx(U,{className:"inline-block ml-1.5 w-4 h-4"})})]}),[s,r]),h=o.useMemo(()=>{var u;return n.jsxs("div",{className:"text-2xl font-bold transition-opacity ease-in-out duration-500 ".concat(e===null?"opacity-0":""),children:[e||".",(t==null?void 0:t.open)==="drawer"&&((u=t==null?void 0:t.enabledIf)==null||u)?n.jsx("button",{onClick:x,"aria-label":"More information about this stat",children:n.jsx(P,{className:"w-5 mx-2 link-text"})}):null]})},[t==null?void 0:t.enabledIf,t==null?void 0:t.open,x,e]),f=o.useMemo(()=>{if(!a.graphPosition)return null;const{graphData:u,graphColor:v,graphPosition:N,graphDataPointLabel:E,graphItemToValue:I}=a;return n.jsx(T,{data:u,itemToValue:I,itemTooltipLabel:E,color:v,graphConfig:N==="bottom"?y.large:y.medium,className:"w-full h-auto self-end block"})},[a]),g=o.useCallback(u=>n.jsxs(n.Fragment,{children:[n.jsx(i,{...p,...c}),u]}),[i,p,c]);return a.graphPosition?a.graphPosition==="bottom"?g(n.jsxs("div",{className:"grid grid-rows-2 gap-6 h-full",children:[n.jsxs("div",{children:[S,h]}),n.jsx("div",{className:"self-end",children:f})]})):g(n.jsxs("div",{className:"grid grid-cols-2",children:[n.jsx("div",{className:"col-span-2",children:S}),h,n.jsx("div",{className:"grid items-end",children:f})]})):g(n.jsxs(n.Fragment,{children:[S,h]}))},H=({children:s,className:e})=>n.jsx("div",{className:"rounded border border-theme-seperator bg-theme-page-content p-6 ".concat(e||""),style:{boxShadow:"0px 4px 8px rgba(30, 41, 59, 0.05)"},children:s}),A=(s,e,r,t="done")=>{const a=new EventSource(s,{withCredentials:!0});return a.addEventListener("message",i=>{i.data===t?(a.close(),r==null||r()):e(i)}),a.addEventListener("error",a.close),a},J=(s,e)=>{const[r,t]=o.useState({}),a=o.useRef();return o.useEffect(()=>(a.current&&(a.current.close(),a.current=void 0),a.current||(a.current=A(s,i=>{t(c=>({...c,...JSON.parse(i.data)}))})),()=>{a.current&&(a.current.close(),a.current=void 0)}),[s,e]),r},D=()=>{const s=l(),[e]=d("search",b),[r]=d("sortBy",j),[t]=d("sort",j),[a]=d("pageSize",w),[i]=d("pageSize",w),[c]=d("teams",b);return{queryContext:s,searchTerms:e==null?void 0:e.map(O).filter(m=>m.length>0),teams:c,pageSize:a||10,pageNumber:i||0,sortBy:r?r.replace(" ","-").toLowerCase():"builds",sortDirection:t&&t==="asc"?"asc":"desc"}},Y=s=>{const e=l(),{selectedFilters:r}=q();return o.useMemo(()=>"/api/".concat(e[0],"/").concat(e[1],"/").concat(s,"?").concat(new URLSearchParams({startDate:e[2].toISOString(),endDate:e[3].toISOString(),...r.length?{filters:R(r)}:{}}).toString()),[e,r,s])},K=s=>{const e=D(),r=l();return o.useMemo(()=>{var t,a;return"/api/".concat(r[0],"/").concat(r[1],"/").concat(s,"?").concat(new URLSearchParams({startDate:e.queryContext[2].toISOString(),endDate:e.queryContext[3].toISOString(),...(t=e.searchTerms)!=null&&t.length?{search:(a=e.searchTerms)==null?void 0:a.join(",")}:{},...e.teams?{teams:e.teams.join(",")}:{}}).toString())},[e.queryContext,e.searchTerms,e.teams,r,s])},W=s=>{const e=l(),r=D();return o.useMemo(()=>"/api/".concat(e[0],"/").concat(e[1],"/").concat(s,"?").concat(new URLSearchParams({startDate:e[2].toISOString(),endDate:e[3].toISOString(),...r.teams?{teams:r.teams.join(",")}:{}}).toString()),[r.teams,e,s])},X=s=>{const e=F(),r=t=>t.length===2;return o.useMemo(()=>r(e)?"".concat({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1,LEGACY:!1}.VITE_REACT_APP_NAME==="specmatic"?"/demo":"","/api/").concat(s,"?").concat(new URLSearchParams({startDate:e[0].toISOString(),endDate:e[1].toISOString()}).toString()):"/api/".concat(e[0],"/").concat(e[1],"/").concat(s,"?").concat(new URLSearchParams({startDate:e[2].toISOString(),endDate:e[3].toISOString()}).toString()),[e,s])};export{H as S,J as a,C as b,K as c,D as d,Y as e,X as f,W as u};
