import{getAppMetrics as e,getGrafanaOrganisation as t}from"./lib/api-helpers.js";import{sendToApi as a}from"./lib/send-to-api.js";import{defineSmartComponent as n}from"./lib/smart/define-smart-component.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)})))}n({selector:"cc-tile-metrics",params:{apiConfig:{type:Object},ownerId:{type:String},appId:{type:String},consoleGrafanaLink:{type:String},grafanaBaseLink:{type:String}},onContextUpdate({context:n,updateComponent:r,signal:p}){const{apiConfig:o,ownerId:s,appId:c,grafanaBaseLink:m,consoleGrafanaLink:l}=n;r("metricsState",{type:"loading"}),function({apiConfig:t,ownerId:n,appId:r,signal:p}){return e({id:n,appId:r}).then(a({apiConfig:t,signal:p})).then((e=>({cpuMetrics:i(e,"cpu"),memMetrics:i(e,"mem")})))}({apiConfig:o,ownerId:s,appId:c,signal:p}).then((({cpuMetrics:e,memMetrics:t})=>{0===e.length||0===t.length||24===e.filter((e=>0===e.value)).length?r("metricsState",{type:"empty"}):r("metricsState",{type:"loaded",metricsData:{cpuMetrics:e,memMetrics:t}})})).catch((e=>{console.error(e),r("metricsState",{type:"error"})})),function({apiConfig:e,ownerId:n,appId:i,grafanaBaseLink:r,signal:p}){return t({id:n}).then(a({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:o,ownerId:s,appId:c,grafanaBaseLink:m,signal:p}).then((e=>{r("grafanaLinkState",{type:"loaded",link:e})})).catch((()=>{r("grafanaLinkState",{type:"loaded",link:l})}))}});
//# sourceMappingURL=cc-tile-metrics.smart.js.map
