import{getDocUrl as e}from"./lib/dev-hub-url.js";import{fakeString as t}from"./lib/fake-strings.js";import{notify as r,notifyError as o}from"./lib/notifications.js";import{defineSmartComponent as a}from"./lib/smart/define-smart-component.js";import{i18n as s}from"./translation.js";import"./cc-smart-container.js";import{CcAddonHeaderClient as d}from"./cc-addon-header.client.js";import"./cc-addon-header.js";const n=e("/addons/metabase");a({selector:"cc-addon-header[smart-mode=metabase]",params:{apiConfig:{type:Object},ownerId:{type:String},addonId:{type:String},logsUrlPattern:{type:String},productStatus:{type:String,optional:!0}},onContextUpdate({context:e,updateComponent:a,onEvent:c,signal:i}){const{apiConfig:l,ownerId:p,addonId:m,productStatus:u}=e,g=new d({apiConfig:l,ownerId:p,addonId:m,providerId:"metabase",signal:i});let b="";a("state",{type:"loading",logsUrl:t(15),openLinks:[{url:t(15),name:t(5)}],actions:{restart:!0,rebuildAndRestart:!0},productStatus:t(4)}),g.getAddonWithOperatorAndZone().then((({rawAddon:t,operator:r,zone:o})=>{const s=r.resources.entrypoint;b=e.logsUrlPattern.replace(":id",s),a("state",{type:"loaded",providerId:t.provider.name,providerLogoUrl:t.provider.logoUrl,name:t.name,id:t.realId,zone:o,logsUrl:b,openLinks:[{name:"METABASE",url:r.accessUrl}],actions:{restart:!0,rebuildAndRestart:!0},productStatus:u})})).catch((e=>{console.error(e),a("state",{type:"error"})})),c("cc-addon-restart",(()=>{a("state",(e=>{e.type="restarting"})),g.restartAddon().then((()=>{r({intent:"success",message:s("cc-addon-header.restart.success.message",{logsUrl:b,docsUrl:n}),title:s("cc-addon-header.restart.success.title"),options:{timeout:0,closeable:!0}})})).catch((e=>{console.error(e),o(s("cc-addon-header.restart.error"))})).finally((()=>{a("state",(e=>{e.type="loaded"}))}))})),c("cc-addon-rebuild",(()=>{a("state",(e=>{e.type="rebuilding"})),g.rebuildAndRestartAddon().then((()=>{r({intent:"success",message:s("cc-addon-header.rebuild.success.message",{logsUrl:b,docsUrl:n}),title:s("cc-addon-header.rebuild.success.title"),options:{timeout:0,closeable:!0}})})).catch((e=>{console.error(e),o(s("cc-addon-header.rebuild.error"))})).finally((()=>{a("state",(e=>{e.type="loaded"}))}))}))}});
//# sourceMappingURL=cc-addon-header.smart-metabase.js.map
