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