import{ResourceLogStream as e}from"@clevercloud/client/esm/streams/resource-logs.js";import{LogsStream as t}from"./lib/logs/logs-stream.js";import{defineSmartComponent as o}from"./lib/smart/define-smart-component.js";import{dateRangeSelectionToDateRange as n}from"./date-range-selection.js";import"./cc-smart-container.js";import"./cc-logs-addon-runtime.js";o({selector:"cc-logs-addon-runtime-beta",params:{apiConfig:{type:Object},ownerId:{type:String},realAddonId:{type:String},dateRangeSelection:{type:Object,optional:!0}},onContextUpdate({component:e,context:t,onEvent:o,updateComponent:n,signal:s}){const{apiConfig:i,ownerId:r,realAddonId:d,dateRangeSelection:p}=t;null!=p&&n("dateRangeSelection",p);const c=new a({apiConfig:i,ownerId:r,addonId:d,component:e,updateComponent:n});s.onabort=()=>{c.stop()},o("cc-logs-date-range-selection-change",(({range:e})=>{c.setNewDateRange(e)})),o("cc-logs-loading-pause",(()=>{c.pause()})),o("cc-logs-loading-resume",(()=>{c.resume()})),o("cc-logs-loading-overflow-accept",(()=>{c.acceptOverflow()})),o("cc-logs-loading-overflow-discard",(()=>{c.discardOverflow()})),c.init()}});class a extends t{constructor({apiConfig:e,ownerId:t,addonId:o,component:a,updateComponent:s}){super(a.limit),this._apiConfig=e,this._ownerId=t,this._addonId=o,this._component=a,this._updateComponent=s,this._dateRange=n(this._component.dateRangeSelection)}setNewDateRange(e){this.stop(),this._dateRange=e,this.init()}_createStream(t,o,n,a){return new e({apiHost:this._apiConfig.API_HOST,tokens:this._apiConfig,ownerId:this._ownerId,addonId:this._addonId,since:t.since,until:t.until,retryConfiguration:{enabled:!0,maxRetryCount:o},throttleElements:n,throttlePerInMilliseconds:a})}_convertLog(e){return function(e){const{id:t,date:o}=e;return{id:t,date:o,message:e.message,metadata:[]}}(e)}_updateStreamState(e){super._updateStreamState(e),this._updateComponent("state",{type:"loaded",streamState:e})}stop(){super.stop(),this._component.clear()}_appendLogs(e){super._appendLogs(e),this._component.appendLogs(e)}init(){this.openLogsStream(this._dateRange)}}
//# sourceMappingURL=cc-logs-addon-runtime.smart.js.map
