/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{inherits as t,createSuper as i,classCallCheck as e,defineProperty as a,assertThisInitialized as n,createClass as s,objectSpread2 as o}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"../../utils/util.js";import{LOAD_START as g,LOADED_DATA as u,SEEKING as T,SEEKED as d,DESTROY as _,URL_CHANGE as l,PLAYING as m,CANPLAY as c,WAITING as S,ERROR as p,RESET as h,AUTOPLAY_STARTED as f,TIME_UPDATE as y,XGLOG as v}from"../../events.js";import w from"../../utils/debug.js";import F from"../../plugin/plugin.js";function L(){/* @__PURE__ */
return(new Date).getTime()}var k={LOAD_START:"loadstart",LOADED_DATA:"loadeddata",FIRST_FRAME:"firstFrame",WAIT_START:"waitingStart",WAIT_END:"waitingEnd",SEEK_START:"seekStart",SEEK_END:"seekEnd"},A=/* @__PURE__ */function(){t(W,F);var A=i(W);function W(){var t;e(this,W);for(var i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];return t=A.call.apply(A,[this].concat(s)),a(n(t),"_onTimeupdate",function(){t._state.isTimeUpdate=!0,t._state.autoplayStart&&(w.logInfo("[xgLogger]".concat(t.player.playerId," _onTimeupdate")),t._sendFF("onTimeupdate"))}),a(n(t),"_onAutoplayStart",function(){w.logInfo("[xgLogger]".concat(t.player.playerId," _onAutoplayStart")),t._state.autoplayStart=!0,t.vt&&t._sendFF("onAutoplayStart")}),a(n(t),"_onReset",function(){t._state={autoplayStart:!1,isFFLoading:!1,isTimeUpdate:!1,isFFSend:!1,isLs:!1},t.vt=0,t.pt=0,t.fvt=0,t.newPointTime=L(),t.loadedCostTime=0,t.startCostTime=0,t._isSeeking=!1,t.seekingStart=0,t.waitingStart=0,t.fixedWaitingStart=0,t._isWaiting=!1,t._waitTimer&&r.clearTimeout(n(t),t._waitTimer),t._waittTimer&&r.clearTimeout(n(t),t._waittTimer),t._waitTimer=null,t._waittTimer=null,t._waitType=0}),a(n(t),"_onSeeking",function(){t.seekingStart||(t.suspendWaitingStatus("seek"),t.seekingStart=L(),t.emitLog(k.SEEK_START,{start:L()}))}),a(n(t),"_onSeeked",function(){t.suspendSeekingStatus("seeked")}),a(n(t),"_onWaitingLoadStart",function(){t._isWaiting||t.vt||(t._isWaiting=!0,t.waitingStart=L(),t.fixedWaitingStart=L(),t._waitType=1,t.emitLog(k.WAIT_START,{fixedStart:t.fixedWaitingStart,start:t.waitingStart,type:1,endType:"loadstart"}))}),a(n(t),"_onWaiting",function(){!t._isWaiting&&t.vt&&(t._isWaiting=!0,t.vt?t.seekingStart?t._waitType=2:t._waitType=0:t._waitType=1,t.fixedWaitingStart=L(),t._waitTimer=r.setTimeout(n(t),function(){t._isWaiting&&(t.waitingStart=L(),r.clearTimeout(n(t),t._waitTimer),t._waitTimer=null,t._startWaitTimeout(),t.emitLog(k.WAIT_START,{fixedStart:t.fixedWaitingStart,start:t.waitingStart,type:t._waitType,endType:2===t._waitType?"seek":"playing"}))},200))}),a(n(t),"_onError",function(){t.suspendSeekingStatus("error"),t.suspendWaitingStatus("error")}),a(n(t),"_onPlaying",function(){t._isWaiting&&t.suspendWaitingStatus("playing")}),t}return s(W,[{key:"afterCreate",value:function(){var t=this;this._onReset(),this._waitType="firstFrame",this._initOnceEvents(),this.newPointTime=L(),this.loadedCostTime=0,this.startCostTime=0,this.on(g,function(){var i=t._state,e=i.autoplayStart,a=i.isFFSend;t.startCostTime=L()-t.newPointTime,w.logInfo("[xgLogger]".concat(t.player.playerId," LOAD_START"),"autoplayStart:".concat(e," isFFSend:").concat(a," startCostTime:").concat(t.startCostTime," newPointTime").concat(t.newPointTime)),a||(!i.isLs&&t.emitLog(k.LOAD_START,{}),i.isLs=!0,i.isTimeUpdate=!1,i.isFFLoading=!0,t.pt=L(),t.vt=0,t.fvt=0,t._initOnceEvents(),t._onWaitingLoadStart())}),this.on(u,function(){t.vt=L(),t.fvt=t.vt-t.pt,t.loadedCostTime=t.vt-t.newPointTime;var i=t._state,e=i.isTimeUpdate,a=i.isFFSend,n=i.autoplayStart;w.logInfo("[xgLogger]".concat(t.player.playerId," LOADED_DATA"),"fvt:".concat(t.fvt," isTimeUpdate:").concat(t._state.isTimeUpdate," loadedCostTime:").concat(t.loadedCostTime)),(e||n)&&t._sendFF("loadedData"),a||t.emitLog(k.LOADED_DATA,{}),t.suspendWaitingStatus("loadeddata")}),this.on(T,this._onSeeking),this.on(d,this._onSeeked),this.on(_,function(){t.endState("destroy")}),this.on(l,function(){t.endState("urlChange"),w.logInfo("[xgLogger]".concat(t.player.playerId," URL_CHANGE")),t._state.isFFSend&&t._onReset()}),this.on([m,c],this._onPlaying),this.on(S,this._onWaiting),this.on(p,this._onError),this.on(h,function(){w.logInfo("[xgLogger]".concat(t.player.playerId," RESET")),t.endState("reset"),t._initOnceEvents(),t._onReset()})}},{key:"_initOnceEvents",value:function(){this.off(f,this._onAutoplayStart),this.off(y,this._onTimeupdate),this.once(f,this._onAutoplayStart),this.once(y,this._onTimeupdate)}},{key:"_sendFF",value:function(t){this.s=L();var i=this._state,e=i.isFFLoading,a=i.isFFSend;w.logInfo("[xgLogger]".concat(this.player.playerId," _sendFF"),"".concat(t," fvt:").concat(this.fvt," isFFLoading:").concat(e," !isFFSend:").concat(!a)),this.vt>0&&e&&!a&&(w.logInfo("[xgLogger]".concat(this.player.playerId," emitLog_firstFrame"),t),this._state.isFFLoading=!1,this._state.isFFSend=!0,this.emitLog(k.FIRST_FRAME,{fvt:this.fvt,costTime:this.fvt,vt:this.vt,startCostTime:this.startCostTime,loadedCostTime:this.loadedCostTime}))}},{key:"_startWaitTimeout",value:function(){var t=this;this._waittTimer&&r.clearTimeout(this,this._waittTimer),this._waittTimer=r.setTimeout(this,function(){t.suspendWaitingStatus("timeout"),r.clearTimeout(t,t._waittTimer),t._waittTimer=null},this.config.waitTimeout)}},{key:"endState",value:function(t){this.suspendWaitingStatus(t),this.suspendSeekingStatus(t)}},{key:"suspendSeekingStatus",value:function(t){if(this.seekingStart){var i=L(),e=i-this.seekingStart;this.seekingStart=0,this.emitLog(k.SEEK_END,{end:i,costTime:e,endType:t})}}},{key:"suspendWaitingStatus",value:function(t){if(this._waitTimer&&(r.clearTimeout(this,this._waitTimer),this._waitTimer=null),this._waittTimer&&(r.clearTimeout(this,this._waittTimer),this._waittTimer=null),this._isWaiting=!1,this.waitingStart){var i=L(),e=i-this.waitingStart,a=i-this.fixedWaitingStart,n=this.config.waitTimeout;this._isWaiting=!1,this.waitingStart=0,this.fixedWaitingStart=0,this.emitLog(k.WAIT_END,{fixedCostTime:a>n?n:a,costTime:e>n?n:e,type:"loadeddata"===t?1:this._waitType,endType:2===this._waitType?"seek":t})}}},{key:"emitLog",value:function(t,i){var e=this.player;this.emit(v,o({t:L(),host:r.getHostFromUrl(e.currentSrc),vtype:e.vtype,eventType:t,currentTime:this.player.currentTime,readyState:e.video.readyState,networkState:e.video.networkState},i))}}],[{key:"pluginName",get:function(){return"xgLogger"}},{key:"defaultConfig",get:function(){return{waitTimeout:1e4}}}]),W}();export{k as LOG_TYPES,A as default};