/*!
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 t,createSuper as e,classCallCheck as a,defineProperty as i,assertThisInitialized as s,createClass as n}from"../../_virtual/_rollupPluginBabelHelpers.js";import o from"../../utils/util.js";import{READY as r,AUTOPLAY_STARTED as l,AUTOPLAY_PREVENTED as u,PLAY as h,PAUSE as d,RESET as c}from"../../events.js";import p from"../../plugin/plugin.js";import{STATES as f}from"../../state.js";import y from"../assets/play.js";import v from"../assets/pause.js";var m={};function g(t){t?window.clearTimeout(t):Object.keys(m).map(function(t){window.clearTimeout(m[t].id),delete m[t]})}var w=/* @__PURE__ */function(){t(k,p);var w=e(k);function k(t){var e;return a(this,k),e=w.call(this,t),i(s(e),"onPlayerReset",function(){e.autoPlayStart=!1;var t="auto"===e.config.mode?"auto-hide":"hide";e.setAttr("data-state","play"),o.removeClass(e.root,t),e.show()}),i(s(e),"onAutoplayStart",function(){if(!e.autoPlayStart){var t="auto"===e.config.mode?"auto-hide":"hide";o.addClass(e.root,t),e.autoPlayStart=!0,e.toggleTo("play")}}),e.autoPlayStart=!1,e}return n(k,[{key:"afterCreate",value:function(){var t=this.playerConfig;this.initIcons(),this.listenEvents(),this.bindClickEvents(),t.autoplay||this.show()}},{key:"listenEvents",value:function(){var t=this,e=this.player,a=this.playerConfig;this.once(r,function(){a&&(a.lang&&"en"===a.lang?o.addClass(e.root,"lang-is-en"):"jp"===a.lang&&o.addClass(e.root,"lang-is-jp"))}),this.on(l,this.onAutoplayStart),this.on(u,function(){var e="auto"===t.config.mode?"auto-hide":"hide";t.setAttr("data-state","play"),o.removeClass(t.root,e),t.show()}),this.on(h,function(){t.toggleTo("play")}),this.on(d,function(){t.toggleTo("pause")}),this.on(c,function(){t.onPlayerReset()})}},{key:"bindClickEvents",value:function(){var t=this;this.clickHandler=this.hook("startClick",this.switchPausePlay,{pre:function(e){e.cancelable&&e.preventDefault(),e.stopPropagation();var a=t.player.paused;t.emitUserAction(e,"switch_play_pause",{props:"paused",from:a,to:!a})}}),this.bind(["click","touchend"],this.clickHandler)}},{key:"registerIcons",value:function(){return{startPlay:{icon:y,class:"xg-icon-play"},startPause:{icon:v,class:"xg-icon-pause"}}}},{key:"initIcons",value:function(){var t=this.icons;this.appendChild("xg-start-inner",t.startPlay),this.appendChild("xg-start-inner",t.startPause)}},{key:"hide",value:function(){o.addClass(this.root,"hide")}},{key:"show",value:function(t){o.removeClass(this.root,"hide")}},{key:"focusHide",value:function(){o.addClass(this.root,"focus-hide")}},{key:"recover",value:function(){o.removeClass(this.root,"focus-hide")}},{key:"switchStatus",value:function(t){t?this.setAttr("data-state",this.player.paused?"pause":"play"):this.setAttr("data-state",this.player.paused?"play":"pause")}},{key:"animate",value:function(t){var e=this;this._animateId=function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{start:null,end:null};return m[t]&&window.clearTimeout(m[t].id),m[t]={},a.start&&a.start(),m[t].id=window.setTimeout(function(){a.end&&a.end(),window.clearTimeout(m[t].id),delete m[t]},e),m[t].id}("pauseplay",400,{start:function(){o.addClass(e.root,"interact"),e.show(),e.switchStatus(!0)},end:function(){o.removeClass(e.root,"interact"),!t&&e.hide(),e._animateId=null}})}},{key:"endAnimate",value:function(){o.removeClass(this.root,"interact"),g(this._animateId),this._animateId=null}},{key:"switchPausePlay",value:function(t){var e=this.player;(t.cancelable&&t.preventDefault(),t.stopPropagation(),e.state<f.READY)||(this.player.paused||e.state!==f.RUNNING?e.play():e.pause())}},{key:"onPlayPause",value:function(t){this.toggleTo(t)}},{key:"toggleTo",value:function(t){var e=this.config,a=this.player;if(a&&!(a.state<f.RUNNING)&&this.autoPlayStart){if("show"===e.mode)return this.switchStatus(),void this.show();if("auto"!==e.mode){if(e.isShowPause&&a.paused&&!a.ended||e.isShowEnd&&a.ended)return this.switchStatus(),this.show(),void this.endAnimate();if(e.disableAnimate)return this.switchStatus(),void this.hide();if("play"===t)this.autoPlayStart?this.animate():this.hide();else{if(!this.autoPlayStart||a.ended)return;this.animate()}}else this.switchStatus()}}},{key:"destroy",value:function(){this.unbind(["click","touchend"],this.clickHandler),g(this._animateId)}},{key:"render",value:function(){var t=this.playerConfig.autoplay?"auto"===this.config.mode?"auto-hide":"hide":"";return'\n    <xg-start class="xgplayer-start '.concat(t,'">\n    <xg-start-inner></xg-start-inner>\n    </xg-start>')}}],[{key:"pluginName",get:function(){return"start"}},{key:"defaultConfig",get:function(){return{isShowPause:!1,isShowEnd:!1,disableAnimate:!1,mode:"hide"}}}]),k}();export{w as default};