/*!
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("../../utils/util.js");require("../../../../../_virtual/delegate.js");var s=[{tag:"xg-cache",className:"xgplayer-progress-cache",styleKey:"cachedColor"},{tag:"xg-played",className:"xgplayer-progress-played",styleKey:"playedColor"}],n=function(){function n(t){e.classCallCheck(this,n),this.fragments=t.fragments||[],0===this.fragments.length&&this.fragments.push({percent:1}),this._callBack=t.actionCallback,this.fragConfig={fragFocusClass:t.fragFocusClass||"inner-focus-point",fragAutoFocus:!!t.fragAutoFocus,fragClass:t.fragClass||""},this.style=t.style||{playedColor:"",cachedColor:"",progressColor:""},this.duration=0,this.cachedIndex=0,this.playedIndex=0,this.focusIndex=-1}return e.createClass(n,[{key:"updateDuration",value:function(e){var t=this;this.duration=e;var s=0,n=this.fragments;this.fragments=n.map(function(e){return e.start=parseInt(s,10),e.end=parseInt(s+e.percent*t.duration,10),e.duration=parseInt(e.percent*t.duration,10),s+=e.percent*t.duration,e})}},{key:"updateProgress",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"played",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{newIndex:0,curIndex:0,millisecond:0},s=this.progressList,n=this.fragments;if(!(s.length<1)){var r=t.newIndex,i=t.curIndex,a=t.millisecond;r!==i&&s.map(function(t,s){s<r?t[e].style.width="100%":s>r&&(t[e].style.width=0)});var o=n[r],l=0===a?0:(a-o.start)/o.duration;s[r][e].style.width=l<0?0:"".concat(100*l,"%")}}},{key:"updateFocus",value:function(e){if(this.fragConfig.fragAutoFocus&&!(this.fragments.length<2))if(e){var t=this.findIndex(1e3*e.currentTime,this.focusIndex);if(t>=0&&t!==this.focusIndex){this.focusIndex>-1&&this.unHightLight(this.focusIndex),this.setHightLight(t);var s={index:t,preIndex:this.focusIndex,fragment:this.fragments[this.focusIndex]};this.focusIndex=t,this._callBack&&this._callBack(s)}}else if(this.focusIndex>-1){this.unHightLight(this.focusIndex);var n={index:-1,preIndex:this.focusIndex,fragment:null};this._callBack&&this._callBack(n),this.focusIndex=-1}}},{key:"update",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{cached:0,played:0},s=arguments.length>1?arguments[1]:void 0;if(!this.duration||parseInt(1e3*s,10)!==this.duration){if(!s&&0!==s)return;this.updateDuration(parseInt(1e3*s,10))}var n=this.playedIndex,r=this.cachedIndex;if("Undefined"!==t.default.typeOf(e.played)){var i=this.findIndex(1e3*e.played,n);if(i<0)return;this.updateProgress("played",{newIndex:i,curIndex:n,millisecond:parseInt(1e3*e.played,10)}),this.playedIndex=i}if("Undefined"!==t.default.typeOf(e.cached)){var a=this.findIndex(1e3*e.cached,r);if(a<0)return;this.updateProgress("cached",{newIndex:a,curIndex:r,millisecond:parseInt(1e3*e.cached,10)}),this.cachedIndex=a}}},{key:"findIndex",value:function(e,t){var s=this.fragments;if(!s||0===s.length)return-1;if(1===s.length)return 0;if(t>-1&&t<s.length&&e>s[t].start&&e<s[t].end)return t;if(e>s[s.length-1].start)return s.length-1;for(var n=0;n<s.length;n++)if(e>s[n].start&&e<=s[n].end){t=n;break}return t}},{key:"findHightLight",value:function(){for(var e=this.root.children,s=0;s<e.length;s++)if(t.default.hasClass(e[s],this.fragConfig.fragFocusClass))return{dom:e[s],pos:e[s].getBoundingClientRect()}}},{key:"findFragment",value:function(e){var t=this.root.children;return e<0||e>=t.length?null:{dom:t[e],pos:t[e].getBoundingClientRect()}}},{key:"unHightLight",value:function(){for(var e=this.root.children,s=0;s<e.length;s++)t.default.removeClass(e[s],this.fragConfig.fragFocusClass)}},{key:"setHightLight",value:function(e){var s=this.root.children;if(e<s.length)return t.default.addClass(s[e],this.fragConfig.fragFocusClass),{dom:s[e],pos:s[e].getBoundingClientRect()}}},{key:"destroy",value:function(){this.progressList=null,this.fragments=null,this.root.innerHTML=""}},{key:"reset",value:function(e){var t=this;if(Object.keys(this.fragConfig).forEach(function(s){void 0!==e[s]&&(t.fragConfig[s]=e[s])}),e.fragments){if(this.fragments=0===e.fragments.length?[{percent:1}]:e.fragments,this.updateDuration(this.duration),this.playedIndex=0,this.cachedIndex=0,this.root)for(var s=this.root.children;s.length>0;)this.root.removeChild(s[0]);this.render()}}},{key:"render",value:function(){var e=this,n=this.style.progressColor;if(this.root||(this.root=t.default.createDom("xg-inners","",{},"progress-list")),this.fragments){var r=this.fragConfig,i=r.fragClass,a=r.fragFocusClass;this.progressList=this.fragments.map(function(r){var o=t.default.createDom("xg-inner","",{style:n?"background:".concat(n,"; flex: ").concat(r.percent):"flex: ".concat(r.percent)},"".concat(r.isFocus?a:""," xgplayer-progress-inner ").concat(i));return e.root.appendChild(o),s.forEach(function(s){o.appendChild(t.default.createDom(s.tag,"",{style:s.styleKey?"background: ".concat(e.style[s.styleKey],"; width:0;"):"width:0;"},s.className))}),{cached:o.children[0],played:o.children[1]}})}return this.root}}]),n}();exports.default=n;