import{getAppMetrics as e,getGrafanaOrganisation as t}from"./lib/api-helpers.js";import{defineSmartComponent as a}from"./lib/define-smart-component.js";import{sendToApi as n}from"./lib/send-to-api.js";import"./cc-smart-container.js";import"./cc-tile-metrics.js";function i(e,t){return(e?.find((e=>e.name===t))?.data??[]).map((({timestamp:e,value:t})=>({timestamp:e/1e3,value:parseFloat(t)})))}a({selector:"cc-tile-metrics",params:{apiConfig:{type:Object},ownerId:{type:String},appId:{type:String},consoleGrafanaLink:{type:String},grafanaBaseLink:{type:String}},onContextUpdate({component:a,context:r,onEvent:p,updateComponent:o,signal:s}){const{apiConfig:c,ownerId:m,appId:l,grafanaBaseLink:d,consoleGrafanaLink:g}=r;o("state",{type:"loading"}),function({apiConfig:t,ownerId:a,appId:r,signal:p}){return e({id:a,appId:r}).then(n({apiConfig:t,signal:p})).then((e=>({cpuMetrics:i(e,"cpu"),memMetrics:i(e,"mem")})))}({apiConfig:c,ownerId:m,appId:l,signal:s}).then((({cpuMetrics:e,memMetrics:t})=>{0===e.length||0===t.length||24===e.filter((e=>0===e.value)).length?o("metricsState",{type:"empty"}):o("metricsState",{type:"loaded",metricsData:{cpuMetrics:e,memMetrics:t}})})).catch((e=>{console.error(e),o("metricsState",{type:"error"})})),function({apiConfig:e,ownerId:a,appId:i,grafanaBaseLink:r,signal:p}){return t({id:a}).then(n({apiConfig:e,signal:p})).then((e=>{const t=new URL("/d/runtime/application-runtime",r);return t.searchParams.set("orgId",e.id),t.searchParams.set("var-SELECT_APP",i),t.toString()}))}({apiConfig:c,ownerId:m,appId:l,grafanaBaseLink:d,signal:s}).then((e=>{o("grafanaLinkState",{type:"loaded",link:e})})).catch((()=>{o("grafanaLinkState",{type:"loaded",link:g})}))}});
//# sourceMappingURL=cc-tile-metrics.smart.js.map
