import{r,j as t}from"./vendor-react-wBh_31cN.js";import{C as M}from"./callout-BFSXVeMz.js";import{u as H,a as K}from"./index-CcynNqTL.js";import{o as k}from"./index-DnLCKZiK.js";import{a as O,S as U,q as Y,G as J,r as W}from"./index-dNe6i2rS.js";import{C as X}from"./combobox-QqI9aNup.js";import{T as R,a as G,b as A}from"./tabs-BZDPsi5L.js";import{u as Z}from"./useProjectNavigate-BM67yKhl.js";import{e as V}from"./monitoring-config-utils-Di6JXNMn.js";import{s as ee,M as te}from"./selectAll-CSk4sGi6.js";import{b as se}from"./time-utils-CQYZ5msB.js";const he=({projectId:m,modelName:c,modelVersion:u})=>{const{configs:g}=k({projectId:m,modelName:c,modelVersion:u},{skip:!c||!u,selectFromResult:({data:i})=>({configs:O([],"items",i)})}),s=g[0],p=s==null?void 0:s.featureStoreId,S=s==null?void 0:s.featureGroupId,x=r.useMemo(()=>g.map(i=>i.id).filter(i=>i!=null),[g]),{shiftsByConfigId:v={}}=H({pId:m,fsId:String(p),fgId:String(S),configIds:x},{skip:x.length===0||p===void 0||S===void 0,selectFromResult:({data:i})=>({shiftsByConfigId:i??{}})}),n=r.useMemo(()=>{const i=Object.values(v),h=new Set;return i.forEach(l=>((l==null?void 0:l.shiftedFeatureNames)??[]).forEach(f=>h.add(f))),h.size>0?h.size:i.reduce((l,f)=>l+((f==null?void 0:f.shiftedFeatureCount)??0),0)},[v]);return n===0?null:t.jsx(M,{type:"error",content:`Shift detected on ${n} feature${n!==1?"s":""}`})},P=[{label:"5 min",diff:{minutes:5}},{label:"15 min",diff:{minutes:15}},{label:"30 min",diff:{minutes:30}},{label:"1 hr",diff:{hours:1}},{label:"5 hr",diff:{hours:5}},{label:"24 hr",diff:{hours:24}}],D=[{label:"1 day",diff:{days:1}},{label:"7 days",diff:{weeks:1}},{label:"30 days",diff:{months:1}},{label:"90 days",diff:{months:3}}],oe="24 hr",pe=({projectId:m,modelName:c,modelVersion:u})=>{var L,N;const g=Z(),{data:s=[],isFetching:p,isLoading:S,isError:x}=k({projectId:m,modelName:c,modelVersion:u},{skip:!c||!u,selectFromResult:({data:e,isFetching:d,isLoading:I,isError:F})=>({data:O([],"items",e),isFetching:d,isLoading:I,isError:F})}),v=r.useMemo(()=>s.map(({name:e,id:d})=>({label:e,value:`${d}`})),[s]),[n,i]=r.useState(void 0),[h,l]=r.useState(!1),[f,$]=r.useState(!0),[b,E]=r.useState(oe),j=r.useMemo(()=>{const d=[...P,...D].find(F=>F.label===b);if(!d)return;const I=Date.now();return{from:se(d.diff,new Date(I)).getTime(),to:I}},[b]);r.useEffect(()=>{n===void 0&&s.length>0&&i(`${s[0].id}`)},[s,n]);const a=n?+n:void 0,o=s.find(e=>e.id===a),T=o==null?void 0:o.featureStoreId,w=o==null?void 0:o.featureGroupId,y=r.useMemo(()=>a===void 0?[]:V(a)(s),[s,a]),B=r.useMemo(()=>ee(y,o==null?void 0:o.featureMonitoringType),[y,o==null?void 0:o.featureMonitoringType]),{data:z=[],isFetching:Q}=K({pId:m,fsId:String(T),fgId:String(w),configId:a,query:j?{filter_by:[`monitoring_time_gte:${j.from}`,`monitoring_time_lt:${j.to}`]}:{}},{skip:!w||T===void 0||a===void 0});if(S)return t.jsx("div",{className:"flex justify-center py-10",children:t.jsx(U,{size:"lg"})});if(x)return t.jsxs(M,{type:"error",children:["Failed to load monitoring configurations for ",c," v",u,"."]});if(!p&&Y(s))return t.jsxs(M,{type:"info",children:["No feature monitoring configured for this model. Create one via"," ",t.jsx("code",{className:"font-mono",children:"feature_view.create_model_monitoring(...)"})," ","in the SDK."]});const C=(o==null?void 0:o.featureStoreId)??((L=s[0])==null?void 0:L.featureStoreId),_=(o==null?void 0:o.featureGroupId)??((N=s[0])==null?void 0:N.featureGroupId),q=C!==void 0&&_!==void 0;return t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(X,{className:"w-[320px]",placeholder:"Select a monitoring config",value:n??"",options:v,onChange:e=>i(e??void 0)}),q&&t.jsx(J,{variant:"outline",size:"sm",onClick:()=>g(W.project.featureGroup.featureMonitoringList,{fsId:String(C),fgId:String(_)}),children:"See all"})]}),a!==void 0&&t.jsxs("div",{className:"ml-4 flex flex-wrap items-center gap-4",children:[t.jsx(R,{value:b,onValueChange:e=>e&&E(e),children:t.jsx(G,{children:P.map(e=>t.jsx(A,{value:e.label,children:e.label},e.label))})}),t.jsx(R,{value:b,onValueChange:e=>e&&E(e),children:t.jsx(G,{children:D.map(e=>t.jsx(A,{value:e.label,children:e.label},e.label))})})]})]}),a!==void 0&&t.jsx(te,{data:z,isFetching:Q,featureOptions:y,selectedConfigs:B,onlyDetection:!0,showThreshold:h,setShowThreshold:l,showShift:f,setShowShift:$,controlLayout:"compact"})]})};export{pe as M,he as S};
