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