/*!
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 i,createSuper as t,classCallCheck as e,defineProperty as s,assertThisInitialized as n,createClass as o,typeof as c}from"../../_virtual/_rollupPluginBabelHelpers.js";import h from"../../utils/util.js";import r from"../../utils/sniffer.js";import{VIDEO_RESIZE as l,FULLSCREEN_CHANGE as a,CANPLAY as u,PLAYER_FOCUS as g}from"../../events.js";import f,{POSITIONS as p}from"../../plugin/plugin.js";import d from"./optionList.js";var v="side",m="middle",y="default",L="click",x="hover";var I="mobile"===r.device,k=/* @__PURE__ */function(){i(C,f);var k=t(C);function C(i){var t;return e(this,C),t=k.call(this,i),s(n(t),"onEnter",function(i){i.stopPropagation(),t.emit("icon_mouseenter",{pluginName:t.pluginName}),t.switchActiveState(i)}),s(n(t),"switchActiveState",function(i){i.stopPropagation(),t.config.toggleMode===L?t.toggle(!t.isActive):t.toggle(!0)}),s(n(t),"onLeave",function(i){i.stopPropagation(),t.emit("icon_mouseleave",{pluginName:t.pluginName}),t.config.listType!==v&&t.isActive&&t.toggle(!1)}),s(n(t),"onListEnter",function(i){t.enterType=2}),s(n(t),"onListLeave",function(i){t.enterType=0,t.isActive&&t.toggle(!1)}),t.isIcons=!1,t.isActive=!1,t.curValue=null,t.curIndex=0,t}return o(C,[{key:"updateLang",value:function(i){this.renderItemList(this.config.list,this.curIndex)}},{key:"afterCreate",value:function(){var i=this,t=this.config;this.initIcons(),(I=I||"touch"===this.domEventType)&&"mobile"===r.device&&t.listType===y&&(t.listType=v),t.hidePortrait&&h.addClass(this.root,"portrait"),this.on([l,a],function(){i._resizeList()}),this.once(u,function(){t.list&&t.list.length>0&&(i.renderItemList(t.list),i.show())}),I&&this.on(g,function(){i.isActive&&(i.optionsList&&i.optionsList.hide(),i.isActive=!1)}),I?(t.toggleMode=L,this.activeEvent="touchend"):this.activeEvent=t.toggleMode===L?"click":"mouseenter",t.toggleMode===L?this.bind(this.activeEvent,this.switchActiveState):(this.bind(this.activeEvent,this.onEnter),this.bind("mouseleave",this.onLeave)),this.isIcons&&this.bind("click",this.onIconClick)}},{key:"initIcons",value:function(){var i=this,t=this.icons,e=Object.keys(t),s=!1;e.length>0&&(e.forEach(function(e){i.appendChild(".xgplayer-icon",t[e]),!s&&(s=t[e])}),this.isIcons=s),s||(this.appendChild(".xgplayer-icon",h.createDom("span","",{},"icon-text")),h.addClass(this.find(".xgplayer-icon"),"btn-text"))}},{key:"show",value:function(i){!this.config.list||this.config.list.length<2||h.addClass(this.root,"show")}},{key:"hide",value:function(){h.removeClass(this.root,"show")}},{key:"getTextByLang",value:function(i,t,e){if(void 0===i)return"";var s=this.config.list;!e&&(e=this.player.lang),t=!t||h.isUndefined(i[t])?"text":t,"number"==typeof i&&(i=s[i]);try{return"object"===c(i[t])?i[t][e]||i[t].en:i[t]}catch(n){return console.warn(n),""}}},{key:"toggle",value:function(i){if(i!==this.isActive&&!this.config.disable){var t=this.player.controls,e=this.config.listType;i?(e===v?t.blur():t.focus(),this.optionsList&&this.optionsList.show()):(e===v?t.focus():t.focusAwhile(),this.optionsList&&this.optionsList.hide()),this.isActive=i}}},{key:"onItemClick",value:function(i,t){i.stopPropagation();var e=this.config,s=e.listType,n=e.list;this.curIndex=t.to.index,this.curItem=n[this.curIndex],this.changeCurrentText(),(this.config.isItemClickHide||I||s===v)&&this.toggle(!1)}},{key:"onIconClick",value:function(i){}},{key:"changeCurrentText",value:function(){if(!this.isIcons){var i=this.config.list,t=i[this.curIndex<i.length?this.curIndex:0];t&&(this.find(".icon-text").innerHTML=this.getTextByLang(t,"iconText"))}}},{key:"renderItemList",value:function(i,t){var e=this,s=this.config,n=this.optionsList,o=this.player;if("number"==typeof t&&(this.curIndex=t,this.curItem=s.list[t]),n)return n.renderItemList(i),void this.changeCurrentText();var c,h,r={config:{data:i||[],className:(c=s.listType,h=s.position,c===v?h===p.CONTROLS_LEFT?"xg-side-list xg-left-side":"xg-side-list xg-right-side":""),onItemClick:function(i,t){e.onItemClick(i,t)},domEventType:I?"touch":"mouse"},root:s.listType===v?o.innerContainer||o.root:this.root};if(this.config.isShowIcon){var l=this.player.root.getBoundingClientRect().height,a=s.listType===m?l-50:l;a&&s.heightLimit&&(r.config.maxHeight="".concat(a,"px")),this.optionsList=new d(r),this.changeCurrentText(),this.show()}this._resizeList()}},{key:"_resizeList",value:function(){if(this.config.heightLimit){var i=this.player.root.getBoundingClientRect().height,t=this.config.listType===m?i-50:i;this.optionsList&&this.optionsList.setStyle({maxHeight:"".concat(t,"px")})}}},{key:"destroy",value:function(){this.config.toggleMode===L?this.unbind(this.activeEvent,this.switchActiveState):(this.unbind(this.activeEvent,this.onEnter),this.unbind("mouseleave",this.onLeave)),this.isIcons&&this.unbind("click",this.onIconClick),this.optionsList&&(this.optionsList.destroy(),this.optionsList=null)}},{key:"render",value:function(){if(this.config.isShowIcon)return'<xg-icon class="xg-options-icon '.concat(this.config.className||"",'">\n    <div class="xgplayer-icon">\n    </div>\n   </xg-icon>')}}],[{key:"pluginName",get:function(){return"optionsIcon"}},{key:"defaultConfig",get:function(){return{position:p.CONTROLS_RIGHT,index:100,list:[],listType:"default",listStyle:{},hidePortrait:!0,isShowIcon:!1,isItemClickHide:!0,toggleMode:x,heightLimit:!0}}}]),C}();export{k as default};