import{ApplicationAccessLogStream as e}from"@clevercloud/client/esm/streams/access-logs.js";import{LogsStream as t}from"./lib/logs/logs-stream.js";import{defineSmartComponent as n}from"./lib/smart/define-smart-component.js";import{dateRangeSelectionToDateRange as o}from"./date-range-selection.js";import"./cc-smart-container.js";import"./cc-logs-app-access.js";n({selector:"cc-logs-app-access-beta",params:{apiConfig:{type:Object},ownerId:{type:String},appId:{type:String},dateRangeSelection:{type:Object,optional:!0}},onContextUpdate({component:e,context:t,onEvent:n,updateComponent:o,signal:s}){const{apiConfig:i,ownerId:p,appId:r,dateRangeSelection:c}=t;null!=c&&o("dateRangeSelection",c);const d=new a({apiConfig:i,ownerId:p,appId:r,component:e,updateComponent:o});s.onabort=()=>{d.stop()},n("cc-logs-date-range-selection-change",(({range:e})=>{d.setNewDateRange(e)})),n("cc-logs-loading-pause",(()=>{d.pause()})),n("cc-logs-loading-resume",(()=>{d.resume()})),n("cc-logs-loading-overflow-accept",(()=>{d.acceptOverflow()})),n("cc-logs-loading-overflow-discard",(()=>{d.discardOverflow()})),d.init()}});class a extends t{constructor({apiConfig:e,ownerId:t,appId:n,component:a,updateComponent:s}){super(a.limit),this._apiConfig=e,this._ownerId=t,this._appId=n,this._component=a,this._updateComponent=s,this._dateRange=o(a.dateRangeSelection)}_createStream(t,n,o,a){return new e({apiHost:this._apiConfig.API_HOST,tokens:this._apiConfig,ownerId:this._ownerId,appId:this._appId,since:t.since,until:t.until,retryConfiguration:{enabled:!0,maxRetryCount:n},throttleElements:o,throttlePerInMilliseconds:a})}_convertLog(e){return function(e){const{id:t,date:n,source:o,http:a}=e;if(null==a)return null;return{id:t,date:new Date(n),message:a.request.path,metadata:[{name:"ip",value:o.ip},{name:"country",value:o.countryCode??""},{name:"city",value:o.city??""},{name:"method",value:a.request.method},{name:"status",value:a.response.statusCode}]}}(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)}setNewDateRange(e){this._dateRange=e,this.init()}init(){this.openLogsStream(this._dateRange)}}
//# sourceMappingURL=cc-logs-app-access.smart.js.map
