/*!
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 e,classCallCheck as a,defineProperty as n,objectSpread2 as s,assertThisInitialized as i,createClass as r}from"../../_virtual/_rollupPluginBabelHelpers.js";import{USER_ACTION as o,STATS_EVENTS as l}from"../../events.js";import f from"../../plugin/basePlugin.js";import"../../../../../_virtual/delegate.js";var u="info",c=l,d=/* @__PURE__ */function(){t(d,f);var l=e(d);function d(){var t;a(this,d);for(var e=arguments.length,r=new Array(e),o=0;o<e;o++)r[o]=arguments[o];return t=l.call.apply(l,[this].concat(r)),n(i(t),"_recordUserActions",function(e){var a=t._getTime(),n=Object.assign({},e,{msg:e.msg||e.action});t._stats[u].push(s(s({type:"userAction"},a),{},{payload:n}))}),n(i(t),"_onReset",function(){t.reset()}),n(i(t),"_recordInfo",function(e){t.info(e)}),n(i(t),"_downloadStats",function(){var e=t.getStats(),a=new Blob([JSON.stringify(e)],{type:"application/json"}),n=window.URL.createObjectURL(a),s=document.createElement("a");s.style.display="none",s.href=n,s.download="player.txt",s.disabled=!1,s.click()}),t}return r(d,[{key:"_getTime",value:function(){return{timestamp:Date.now(),timeFormat:/* @__PURE__ */(new Date).toISOString()}}},{key:"afterCreate",value:function(){this.reset(),this.on(o,this._recordUserActions),this.on(c.STATS_INFO,this._recordInfo),this.on(c.STATS_DOWNLOAD,this._downloadStats),this.on(c.STATS_RESET,this._onReset)}},{key:"destroy",value:function(){this.offAll()}},{key:"downloadStats",value:function(){this._downloadStats()}},{key:"info",value:function(t){t.profile?this._infoProfile(t):this._info(t)}},{key:"_info",value:function(t){var e=this._getTime();this._stats[u].push(s(s({},e),{},{payload:t}))}},{key:"_infoProfile",value:function(t){if(t&&t.startMs){var e=Date.now()-t.startMs,a=s({cat:"function",dur:e,name:t.name||t.msg,ph:"X",pid:0,tid:0,ts:t.startMs,profile:!0},t);this._info(a)}else console.warn("infoProfile need object data, include startMs")}},{key:"reset",value:function(){var t;this._stats=(n(t={},u,[]),n(t,"media",{}),t)}},{key:"getStats",value:function(){for(var t=this.player.media,e=[],a=0;a<t.buffered.length;a++)e.push({start:t.buffered.start(a),end:t.buffered.end(a)});var n={currentTime:t.currentTime,readyState:t.readyState,buffered:e,paused:t.paused,ended:t.ended};return this._stats.media=n,{raw:this._stats,timestat:this._getTimeStats(),profile:this._getProfile()}}},{key:"_getTimeStats",value:function(){return this._stats[u].map(function(t){var e=t.payload.data,a="";try{e instanceof Error?a=e.msg:void 0!==e&&(a=JSON.stringify(e))}catch(n){console.log("err",n)}return"[".concat(t.timeFormat,"] : ").concat(t.payload.msg," ").concat(a," ")})}},{key:"_getProfile",value:function(){var t={traceEvents:[]};return this._stats[u].forEach(function(e){e.payload.profile&&t.traceEvents.push(e.payload)}),t}}],[{key:"pluginName",get:function(){return"stats"}},{key:"defaultConfig",get:function(){return{}}}]),d}();export{d as default};