/*!
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 t from"../../utils/util.js";import{DURATION_CHANGE as i,VIDEO_RESIZE as s}from"../../events.js";import"../../../../../_virtual/delegate.js";var o={time:0,text:"",id:1,duration:1,color:"#fff",style:{},width:6,height:6};function e(t){Object.keys(o).map(function(i){void 0===t[i]&&(t[i]=o[i])})}var n={_updateDotDom:function(i,s){if(s){var o=this.calcuPosition(i.time,i.duration),e=i.style||{};e.left="".concat(o.left,"%"),e.width="".concat(o.width,"%"),s.setAttribute("data-text",i.text),s.setAttribute("data-time",i.time),o.isMini?t.addClass(s,"mini"):t.removeClass(s,"mini"),Object.keys(e).map(function(t){s.style[t]=e[t]})}},initDots:function(){var t=this;this._ispots.map(function(i){t.createDot(i,!1)}),this.ispotsInit=!0},createDot:function(i){var s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=this.player.plugins.progress;if(o&&(s&&(e(i),this._ispots.push(i)),this.ispotsInit||!s)){var n=this.calcuPosition(i.time,i.duration),a=i.style||{};a.left="".concat(n.left,"%"),a.width="".concat(n.width,"%");var r="xgspot_".concat(i.id," xgplayer-spot");n.isMini&&(r+=" mini");var p=i.template?'<div class="xgplayer-spot-pop">'.concat(i.template,"</div>"):"",l=t.createDom("xg-spot",p,{"data-text":i.text,"data-time":i.time,"data-id":i.id},r);Object.keys(a).map(function(t){l.style[t]=a[t]}),o.outer&&o.outer.appendChild(l),this.positionDot(l,i.id)}},findDot:function(t){if(this.player.plugins.progress){var i=this._ispots.filter(function(i,s){return i.id===t});return i.length>0?i[0]:null}},updateDot:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=this.player.plugins.progress;if(s){var o=this.findDot(t.id);if(o&&Object.keys(t).map(function(i){o[i]=t[i]}),this.ispotsInit){var e=s.find('xg-spot[data-id="'.concat(t.id,'"]'));e&&(this._updateDotDom(t,e),i&&this.showDot(t.id))}}},deleteDot:function(t){var i=this._ispots,s=this.player.plugins.progress;if(s){for(var o=[],e=0;e<i.length;e++)i[e].id===t&&o.push(e);for(var n=o.length-1;n>=0;n--)if(i.splice(o[n],1),this.ispotsInit){var a=s.find('xg-spot[data-id="'.concat(t,'"]'));a&&a.parentElement.removeChild(a)}}},deleteAllDots:function(){var t=this.player.plugins.progress;if(t)if(this.ispotsInit){for(var i=t.root.getElementsByTagName("xg-spot"),s=i.length-1;s>=0;s--)t.outer.removeChild(i[s]);this._ispots=[]}else this._ispots=[]},updateAllDots:function(){var t=this,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=this.player.plugins.progress;if(s)if(this.ispotsInit){this._ispots=[];var o=s.root.getElementsByTagName("xg-spot"),e=o.length;if(e>i.length)for(var n=e-1;n>i.length-1;n--)s.outer.removeChild(o[n]);i.forEach(function(i,s){s<e?(o[s].setAttribute("data-id","".concat(i.id)),t._ispots.push(i),t.updateDot(i)):t.createDot(i)})}else this._ispots=i},positionDots:function(){var t=this,i=this._ispots,s=this.playerSize,o=this.player.sizeInfo,e=this.player.plugins.progress;e&&o.width!==s.width&&(s.width=o.width,s.left=o.left,i.forEach(function(i){var s=e.find('xg-spot[data-id="'.concat(i.id,'"]'));s&&t.positionDot(s,i.id)}))},positionDot:function(i,s){var o=t.findDom(i,".xgplayer-spot-pop");if(o){var e=this.playerSize,n=i.getBoundingClientRect(),a=o.getBoundingClientRect(),r=n.left-e.left,p=e.width-r-n.width/2;if(r<a.width/2||e.width<a.width){var l=a.width/2-r;o.style.left="".concat(l,"px")}else if(p<a.width/2){var d=p-a.width/2+n.width/2;o.style.left="".concat(d,"px")}else o.style.left="50%"}},updateDuration:function(){var t=this,i=this.player.plugins.progress;i&&this._ispots.forEach(function(s){var o=i.find('xg-spot[data-id="'.concat(s.id,'"]'));t._updateDotDom(s,o)})},getAllDotsDom:function(){var t=this.player.plugins.progress;return t?t.root.getElementsByTagName("xg-spot"):[]},getDotDom:function(t){var i=this.player.plugins.progress;if(i)return i.find('xg-spot[data-id="'.concat(t,'"]'))}};function a(t){var o=t.config,a=t.player;Object.keys(n).map(function(i){t[i]=n[i].bind(t)});var r=a.config.progressDot||o.ispots||[];t._ispots=r.map(function(t){return e(t),t}),t.ispotsInit=!1,t.playerSize={left:a.sizeInfo.left,width:a.sizeInfo.width},t.on(i,function(){t.ispotsInit?t.updateDuration():t.initDots()}),t.on(s,function(){t.positionDots()})}export{a as default};