import{ONE_SECOND as e}from"@clevercloud/client/esm/with-cache.js";import{getAssetUrl as t}from"./lib/assets-url.js";import{fakeString as n}from"./lib/fake-strings.js";import{notify as r,notifyError as o}from"./lib/notifications.js";import{sendToApi as i}from"./lib/send-to-api.js";import{defineSmartComponent as s}from"./lib/smart/define-smart-component.js";import{i18n as a}from"./translation.js";import"./cc-smart-container.js";import"./cc-addon-header.js";s({selector:"cc-addon-header[smart-mode=kubernetes]",params:{apiConfig:{type:Object},ownerId:{type:String},kubernetesId:{type:String},productStatus:{type:String,optional:!0}},onContextUpdate({context:e,updateComponent:i,signal:s}){const{apiConfig:u,ownerId:l,kubernetesId:c,productStatus:g}=e,f=new d({apiConfig:u,ownerId:l,kubernetesId:c,signal:s});i("state",{type:"loading",configLink:{href:n(15),fileName:n(15)},productStatus:n(4)});const p=setInterval((()=>{f.getKubeConfig().then((e=>{i("state",(t=>{t.configLink={fileName:"kubeconfig.yaml",href:e}}))})).catch((e=>{console.error(e),r({intent:"danger",message:a("cc-addon-header.error.fetch-kubeconfig"),options:{timeout:0,closeable:!0}}),i("state",{type:"error"})}))}),3e6);s.addEventListener("abort",(()=>{clearInterval(p)})),f.getKubeInfoWithKubeConfig().then((({kubeInfo:e,kubeConfigUrl:n,zone:r})=>{i("state",{type:"loaded",providerId:"kubernetes",providerLogoUrl:t("/logos/kubernetes.svg"),name:e.name,id:e.id,zone:r,configLink:{href:n,fileName:"kubeconfig.yaml"},productStatus:g,deploymentStatus:e.status.toLowerCase()})})).catch((e=>{console.error(e),o(a("cc-addon-header.error")),i("state",{type:"error"})}))}});class d{constructor({apiConfig:e,ownerId:t,kubernetesId:n,signal:r}){this._apiConfig=e,this._ownerId=t,this._kubernetesId=n,this._signal=r}_getKubeInfo(){return(t={ownerId:this._ownerId,kubernetesId:this._kubernetesId},Promise.resolve({method:"get",url:`/v4/kubernetes/organisations/${t.ownerId}/clusters/${t.kubernetesId}`})).then(i({apiConfig:this._apiConfig,signal:this._signal,cacheDelay:e})).then((e=>{if("DELETED"===e.status||"DELETING"===e.status)throw new Error("This cluster has been deleted");return e}));var t}getKubeConfig(){return(e={ownerId:this._ownerId,kubernetesId:this._kubernetesId},Promise.resolve({method:"get",url:`/v4/kubernetes/organisations/${e.ownerId}/clusters/${e.kubernetesId}/kubeconfig/presigned-url`})).then(i({apiConfig:this._apiConfig,signal:this._signal})).then((({url:e})=>e));var e}async getKubeInfoWithKubeConfig(){return{kubeInfo:await this._getKubeInfo(),kubeConfigUrl:await this.getKubeConfig(),zone:{type:"loaded",name:"par",country:"France",countryCode:"FR",city:"Paris",displayName:null,lat:48.8566,lon:2.3522,tags:["for:applications","for:par-only","infra:clever-cloud"]}}}}
//# sourceMappingURL=cc-addon-header.smart-kubernetes.js.map
