import{v as i,g as m,T as y}from"./DCUV69GJ.chunk.js";import{dX as d,ao as l,aJ as r}from"./app-k0jcl5PQ.js";const x=i.getComponent("Button");class c extends x{constructor(t,e){super(t,e),this.update()}update(){this.options_.activityStatus===d.Complete?this.addClass("cv-activity-completed"):this.removeClass("cv-activity-completed")}handleClick(...t){this.options_.activityStatus=this.getToggledActivityStatus(),this.update(),this.options_.clickHandler&&this.options_.clickHandler.call(this,t)}buildCSSClass(){return"cv-activity-status-button"}getToggledActivityStatus(){if(this.options_.activityStatus===d.None||this.options_.activityStatus===d.Incomplete)return d.Complete;if(this.options_.activityStatus===d.Complete)return d.Incomplete}}c.prototype.controlText_="Complete";const v=i.getPlugin("plugin");class f extends v{setActivityStatus(t,e){t!==this.activityStatus&&(this.activityStatus=t,this.onToggleStatus=e,this.player.ready(()=>{this.renderActivityStatusButton()}))}renderActivityStatusButton(){this.button&&this.player.removeChild(this.button),this.button=new c(this.player,{activityStatus:this.activityStatus,clickHandler:this.onToggleStatus}),this.player.addChild(this.button)}}i.registerPlugin("activityStatusPlugin",f);function N(o){var n;const[t,e]=r.useState(5);if(r.useEffect(()=>{const u=setInterval(()=>{e(p=>p-1)},1e3);return()=>{clearInterval(u)}},[]),r.useEffect(()=>{t===0&&o.onPlayNext()},[t]),!o.nextVideo||!o.onPlayNext)return l.jsx(l.Fragment,{});const s=Math.ceil(t),a=s===1?"second":"seconds";return l.jsx(l.Fragment,{children:l.jsxs("div",{className:"cv-up-next-container",children:[l.jsx("div",{className:"cv-cancel-up-next cursor-pointer",role:"button",onClick:o.onCancel,children:"×"}),l.jsxs("div",{className:"cv-up-next-heading",children:["Up next in ",s," ",a,":"]}),l.jsx("div",{className:"cv-up-next-image cursor-pointer",onClick:o.onPlayNext,style:{backgroundImage:`url(${(n=o.nextVideo)==null?void 0:n.thumbnailUrl})`}}),l.jsx("div",{className:"cv-up-next-title",children:o.nextVideo.name})]})})}i.registerComponent("UpNext",m((o,t)=>l.jsx(N,{player:o,...t})));const P=i.getComponent("MenuItem");let C=class extends P{constructor(t,e){super(t,e),this.bindListeners(),this.player_.nextVideoPlugin().getShouldPlayNext()&&this.toggleOn()}bindListeners(){this.onPlayNextChange=this.onPlayNextChange.bind(this),this.player_.on("cv:playnext",this.onPlayNextChange)}handleToggle(){const t=this.player_.nextVideoPlugin().getShouldPlayNext();this.player_.nextVideoPlugin().setShouldPlayNext(!t,!0)}onPlayNextChange(t,e){e?this.toggleOn():this.toggleOff()}toggleOn(){i.dom.addClass(this.toggleEl,"on")}toggleOff(){i.dom.removeClass(this.toggleEl,"on")}handleClick(t){t.stopImmediatePropagation()}createEl(t,e,s){this.handlerBound||(this.handleToggle=this.handleToggle.bind(this),this.handlerBound=!0),this.toggleEl&&this.toggleEl.removeEventListener("click",this.handleToggle),this.toggleEl=i.dom.createEl("div",{className:"custom-toggle custom-toggle-info toggle-option float-end",innerHTML:'<span class="handle"></span></div>'}),this.toggleEl.addEventListener("click",this.handleToggle);const n=super.createEl(t,{className:"vjs-menu-item cv-cog-menu-item cv-play-next-toggle",innerHTML:`
      <span class="vjs-menu-item-text">Play next video</span>
      <span class="cv-toggle-container"></span>`},s);return n.children[1].appendChild(this.toggleEl),n}dispose(){this.player_.off("cv:playnext",this.onPlayNextChange),super.dispose()}};i.registerComponent("NextVideoMenuItem",C);const h="cv-persisttest",g="cv-play-next-video",S=i.getPlugin("plugin");i.getComponent("MenuItem");const V=i.getComponent("NextVideoMenuItem");class T extends S{constructor(t){if(super(t),this.setShouldPlayNext=this.setShouldPlayNext.bind(this),this.getShouldPlayNext=this.getShouldPlayNext.bind(this),this.getChapterTrack=this.getChapterTrack.bind(this),this.onTimeUpdate=this.onTimeUpdate.bind(this),this.hasLocalStorage=this.testHasLocalStorage(),this.shouldPlayNextVideo=!1,this.hasLocalStorage){const e=window.localStorage.getItem(g);this.shouldPlayNextVideo=e==="true"}t.ready(()=>{this.initialize()})}initialize(){this.player.isDisposed()||this.bindListeners()}getChapterTrack(){return y.getTrack(this.player,"chapters",null)}setNextVideo(t,e,s){var n;this.nextVideo=t,this.callback=s,e&&this.setShouldPlayNext(!0),((n=this.player.getChild("collapserator"))==null?void 0:n.getChild("cogButton")).addItem({ctor:V,name:"NextVideoMenuItem"})}getShouldPlayNext(){return this.shouldPlayNextVideo}setShouldPlayNext(t,e){this.shouldPlayNextVideo=t,this.player.trigger("cv:playnext",t),this.hasLocalStorage&&e&&window.localStorage.setItem(g,t.toString()),t&&this.player.loopVideoPlugin().loop(!1)}bindListeners(){this.player.on("timeupdate",this.onTimeUpdate)}dispose(){this.player.off("timeupdate",this.onTimeUpdate),this.hideUpNext(),super.dispose()}onTimeUpdate(){if(!(this.player.pictureInPicture&&this.player.isInPictureInPicture())){if(!this.getShouldPlayNext()){this.hideUpNext();return}if(this.upNextRendered&&this.player.currentTime()<this.player.duration()){this.hideUpNext();return}this.player.ended()&&this.showUpNext()}}showUpNext(){this.upNextRendered||(this.upNextRendered=!0,this.player.addChild("UpNext",{nextVideo:this.nextVideo,onPlayNext:this.callback,onCancel:()=>{this.hideUpNext(),this.setShouldPlayNext(!1)}}))}hideUpNext(){if(!this.upNextRendered)return;this.upNextRendered=!1;const t=this.player.getChild("UpNext");t&&(this.player.removeChild(t),t.dispose())}testHasLocalStorage(){try{return window.localStorage.setItem(h,"persistPlayNext"),window.localStorage.removeItem(h),!0}catch{return!1}}}i.registerPlugin("nextVideoPlugin",T);const E=i.getComponent("MenuItem");let L=class extends E{constructor(t,e){super(t,e),this.onLoopVideoChange=this.onLoopVideoChange.bind(this),this.player_.on("cv:loopvideo",this.onLoopVideoChange),this.onLoopVideoChange(null,this.player_.loopVideoPlugin().loop())}onLoopVideoChange(t,e){e?this.toggleOn():this.toggleOff()}handleToggle(){const t=this.player_.loopVideoPlugin().loop();this.player_.loopVideoPlugin().loop(!t)}toggleOn(){i.dom.addClass(this.toggleEl,"on")}toggleOff(){i.dom.removeClass(this.toggleEl,"on")}handleClick(t){t.stopImmediatePropagation()}createEl(t,e,s){this.handlerBound||(this.handleToggle=this.handleToggle.bind(this),this.handlerBound=!0),this.toggleEl&&this.toggleEl.removeEventListener("click",this.handleToggle),this.toggleEl=i.dom.createEl("div",{className:"custom-toggle custom-toggle-info toggle-option float-end",innerHTML:'<span class="handle"></span></div>'}),this.toggleEl.addEventListener("click",this.handleToggle);const n=super.createEl(t,{className:"vjs-menu-item cv-cog-menu-item cv-loop-video-toggle",innerHTML:`
      <span class="vjs-menu-item-text">Loop video</span>
      <span class="cv-toggle-container"></span>`},s);return n.children[1].appendChild(this.toggleEl),n}dispose(){this.player_.off("cv:loopvideo",this.onLoopVideoChange),super.dispose()}};i.registerComponent("LoopVideoMenuItem",L);const I=i.getPlugin("plugin");i.getComponent("MenuItem");const M=i.getComponent("LoopVideoMenuItem");class b extends I{constructor(t,e){super(t),e.allowLoop&&this.player.ready(()=>this.addButton()),this.onEnded=this.onEnded.bind(this),this.player.on("ended",this.onEnded)}addButton(){var e;((e=this.player.getChild("collapserator"))==null?void 0:e.getChild("cogButton")).addItem({ctor:M,name:"LoopVideoMenuItem"})}onEnded(){this.player.loop()&&this.player.play()}loop(t){var e,s,a;if(typeof t!="boolean")return this.player.loop();t&&((a=(s=(e=this.player).nextVideoPlugin)==null?void 0:s.call(e))==null||a.setShouldPlayNext(!1,!1)),this.player.trigger("cv:loopvideo",t),this.player.loop(t)}dispose(){this.player.off("ended",this.onEnded),super.dispose()}}i.registerPlugin("loopVideoPlugin",b);
//# sourceMappingURL=CvO2hNpe.chunk.js.map
