/*!
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
*/
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("../../_virtual/_rollupPluginBabelHelpers.js"),i=require("../../utils/util.js"),e=require("../../events.js"),a=require("../../utils/debug.js"),n=require("../../plugin/plugin.js");function s(){return(new Date).getTime()}var o={LOAD_START:"loadstart",LOADED_DATA:"loadeddata",FIRST_FRAME:"firstFrame",WAIT_START:"waitingStart",WAIT_END:"waitingEnd",SEEK_START:"seekStart",SEEK_END:"seekEnd"},r=function(n){t.inherits(d,n);var r=t.createSuper(d);function d(){var e;t.classCallCheck(this,d);for(var n=arguments.length,u=new Array(n),T=0;T<n;T++)u[T]=arguments[T];return e=r.call.apply(r,[this].concat(u)),t.defineProperty(t.assertThisInitialized(e),"_onTimeupdate",function(){e._state.isTimeUpdate=!0,e._state.autoplayStart&&(a.default.logInfo("[xgLogger]".concat(e.player.playerId," _onTimeupdate")),e._sendFF("onTimeupdate"))}),t.defineProperty(t.assertThisInitialized(e),"_onAutoplayStart",function(){a.default.logInfo("[xgLogger]".concat(e.player.playerId," _onAutoplayStart")),e._state.autoplayStart=!0,e.vt&&e._sendFF("onAutoplayStart")}),t.defineProperty(t.assertThisInitialized(e),"_onReset",function(){e._state={autoplayStart:!1,isFFLoading:!1,isTimeUpdate:!1,isFFSend:!1,isLs:!1},e.vt=0,e.pt=0,e.fvt=0,e.newPointTime=s(),e.loadedCostTime=0,e.startCostTime=0,e._isSeeking=!1,e.seekingStart=0,e.waitingStart=0,e.fixedWaitingStart=0,e._isWaiting=!1,e._waitTimer&&i.default.clearTimeout(t.assertThisInitialized(e),e._waitTimer),e._waittTimer&&i.default.clearTimeout(t.assertThisInitialized(e),e._waittTimer),e._waitTimer=null,e._waittTimer=null,e._waitType=0}),t.defineProperty(t.assertThisInitialized(e),"_onSeeking",function(){e.seekingStart||(e.suspendWaitingStatus("seek"),e.seekingStart=s(),e.emitLog(o.SEEK_START,{start:s()}))}),t.defineProperty(t.assertThisInitialized(e),"_onSeeked",function(){e.suspendSeekingStatus("seeked")}),t.defineProperty(t.assertThisInitialized(e),"_onWaitingLoadStart",function(){e._isWaiting||e.vt||(e._isWaiting=!0,e.waitingStart=s(),e.fixedWaitingStart=s(),e._waitType=1,e.emitLog(o.WAIT_START,{fixedStart:e.fixedWaitingStart,start:e.waitingStart,type:1,endType:"loadstart"}))}),t.defineProperty(t.assertThisInitialized(e),"_onWaiting",function(){!e._isWaiting&&e.vt&&(e._isWaiting=!0,e.vt?e.seekingStart?e._waitType=2:e._waitType=0:e._waitType=1,e.fixedWaitingStart=s(),e._waitTimer=i.default.setTimeout(t.assertThisInitialized(e),function(){e._isWaiting&&(e.waitingStart=s(),i.default.clearTimeout(t.assertThisInitialized(e),e._waitTimer),e._waitTimer=null,e._startWaitTimeout(),e.emitLog(o.WAIT_START,{fixedStart:e.fixedWaitingStart,start:e.waitingStart,type:e._waitType,endType:2===e._waitType?"seek":"playing"}))},200))}),t.defineProperty(t.assertThisInitialized(e),"_onError",function(){e.suspendSeekingStatus("error"),e.suspendWaitingStatus("error")}),t.defineProperty(t.assertThisInitialized(e),"_onPlaying",function(){e._isWaiting&&e.suspendWaitingStatus("playing")}),e}return t.createClass(d,[{key:"afterCreate",value:function(){var t=this;this._onReset(),this._waitType="firstFrame",this._initOnceEvents(),this.newPointTime=s(),this.loadedCostTime=0,this.startCostTime=0,this.on(e.LOAD_START,function(){var i=t._state,e=i.autoplayStart,n=i.isFFSend;t.startCostTime=s()-t.newPointTime,a.default.logInfo("[xgLogger]".concat(t.player.playerId," LOAD_START"),"autoplayStart:".concat(e," isFFSend:").concat(n," startCostTime:").concat(t.startCostTime," newPointTime").concat(t.newPointTime)),n||(!i.isLs&&t.emitLog(o.LOAD_START,{}),i.isLs=!0,i.isTimeUpdate=!1,i.isFFLoading=!0,t.pt=s(),t.vt=0,t.fvt=0,t._initOnceEvents(),t._onWaitingLoadStart())}),this.on(e.LOADED_DATA,function(){t.vt=s(),t.fvt=t.vt-t.pt,t.loadedCostTime=t.vt-t.newPointTime;var i=t._state,e=i.isTimeUpdate,n=i.isFFSend,r=i.autoplayStart;a.default.logInfo("[xgLogger]".concat(t.player.playerId," LOADED_DATA"),"fvt:".concat(t.fvt," isTimeUpdate:").concat(t._state.isTimeUpdate," loadedCostTime:").concat(t.loadedCostTime)),(e||r)&&t._sendFF("loadedData"),n||t.emitLog(o.LOADED_DATA,{}),t.suspendWaitingStatus("loadeddata")}),this.on(e.SEEKING,this._onSeeking),this.on(e.SEEKED,this._onSeeked),this.on(e.DESTROY,function(){t.endState("destroy")}),this.on(e.URL_CHANGE,function(){t.endState("urlChange"),a.default.logInfo("[xgLogger]".concat(t.player.playerId," URL_CHANGE")),t._state.isFFSend&&t._onReset()}),this.on([e.PLAYING,e.CANPLAY],this._onPlaying),this.on(e.WAITING,this._onWaiting),this.on(e.ERROR,this._onError),this.on(e.RESET,function(){a.default.logInfo("[xgLogger]".concat(t.player.playerId," RESET")),t.endState("reset"),t._initOnceEvents(),t._onReset()})}},{key:"_initOnceEvents",value:function(){this.off(e.AUTOPLAY_STARTED,this._onAutoplayStart),this.off(e.TIME_UPDATE,this._onTimeupdate),this.once(e.AUTOPLAY_STARTED,this._onAutoplayStart),this.once(e.TIME_UPDATE,this._onTimeupdate)}},{key:"_sendFF",value:function(t){this.s=s();var i=this._state,e=i.isFFLoading,n=i.isFFSend;a.default.logInfo("[xgLogger]".concat(this.player.playerId," _sendFF"),"".concat(t," fvt:").concat(this.fvt," isFFLoading:").concat(e," !isFFSend:").concat(!n)),this.vt>0&&e&&!n&&(a.default.logInfo("[xgLogger]".concat(this.player.playerId," emitLog_firstFrame"),t),this._state.isFFLoading=!1,this._state.isFFSend=!0,this.emitLog(o.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&&i.default.clearTimeout(this,this._waittTimer),this._waittTimer=i.default.setTimeout(this,function(){t.suspendWaitingStatus("timeout"),i.default.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=s(),e=i-this.seekingStart;this.seekingStart=0,this.emitLog(o.SEEK_END,{end:i,costTime:e,endType:t})}}},{key:"suspendWaitingStatus",value:function(t){if(this._waitTimer&&(i.default.clearTimeout(this,this._waitTimer),this._waitTimer=null),this._waittTimer&&(i.default.clearTimeout(this,this._waittTimer),this._waittTimer=null),this._isWaiting=!1,this.waitingStart){var e=s(),a=e-this.waitingStart,n=e-this.fixedWaitingStart,r=this.config.waitTimeout;this._isWaiting=!1,this.waitingStart=0,this.fixedWaitingStart=0,this.emitLog(o.WAIT_END,{fixedCostTime:n>r?r:n,costTime:a>r?r:a,type:"loadeddata"===t?1:this._waitType,endType:2===this._waitType?"seek":t})}}},{key:"emitLog",value:function(a,n){var o=this.player;this.emit(e.XGLOG,t.objectSpread2({t:s(),host:i.default.getHostFromUrl(o.currentSrc),vtype:o.vtype,eventType:a,currentTime:this.player.currentTime,readyState:o.video.readyState,networkState:o.video.networkState},n))}}],[{key:"pluginName",get:function(){return"xgLogger"}},{key:"defaultConfig",get:function(){return{waitTimeout:1e4}}}]),d}(n.default);exports.LOG_TYPES=o,exports.default=r;