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 s}from"./lib/smart/define-smart-component.js";import{i18n as a}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/otoroshi");s({selector:"cc-addon-header[smart-mode=otoroshi]",params:{apiConfig:{type:Object},ownerId:{type:String},addonId:{type:String},logsUrlPattern:{type:String},productStatus:{type:String,optional:!0}},onContextUpdate({context:e,updateComponent:s,onEvent:i,signal:c}){const{apiConfig:l,ownerId:p,addonId:m,productStatus:u}=e,g=new d({apiConfig:l,ownerId:p,addonId:m,providerId:"otoroshi",signal:c});let h="";s("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 a=r.resources.entrypoint;h=e.logsUrlPattern.replace(":id",a),s("state",{type:"loaded",providerId:t.provider.name,providerLogoUrl:t.provider.logoUrl,name:t.name,id:t.realId,zone:o,logsUrl:h,openLinks:[{name:"OTOROSHI",url:r.accessUrl}],actions:{restart:!0,rebuildAndRestart:!0},productStatus:u})})).catch((e=>{console.error(e),s("state",{type:"error"})})),i("cc-addon-restart",(()=>{s("state",(e=>{e.type="restarting"})),g.restartAddon().then((()=>{r({intent:"success",message:a("cc-addon-header.restart.success.message",{logsUrl:h,docsUrl:n}),title:a("cc-addon-header.restart.success.title"),options:{timeout:0,closeable:!0}})})).catch((e=>{console.error(e),o(a("cc-addon-header.restart.error"))})).finally((()=>{s("state",(e=>{e.type="loaded"}))}))})),i("cc-addon-rebuild",(()=>{s("state",(e=>{e.type="rebuilding"})),g.rebuildAndRestartAddon().then((()=>{r({intent:"success",message:a("cc-addon-header.rebuild.success.message",{logsUrl:h,docsUrl:n}),title:a("cc-addon-header.rebuild.success.title"),options:{timeout:0,closeable:!0}})})).catch((e=>{console.error(e),o(a("cc-addon-header.rebuild.error"))})).finally((()=>{s("state",(e=>{e.type="loaded"}))}))}))}});
//# sourceMappingURL=cc-addon-header.smart-otoroshi.js.map
