import{v as i,c as m,T as y}from"./CanLAf7a.chunk.js";import{j as l,aT as h}from"./app-BgLa5dit.js";const f=i.getPlugin("plugin"),x=10;class v extends f{constructor(t,e){if(super(t),e.startTime===void 0)throw Error("Invalid clip start");if(e.endTime===void 0)throw Error("Invalid clip end");if(e.startTime>e.endTime)throw Error("Clip start cannot be greater than clip end");this._clipStart=parseFloat(e.startTime.toPrecision(4)),this._clipEnd=parseFloat(e.endTime.toPrecision(4)),this.playerEndedFn=this.player.ended.bind(t),this.playerDurationFn=this.player.duration.bind(t),this.playerCurrentTimeFn=this.player.currentTime.bind(t),this.playerbufferedFn=this.player.buffered.bind(t),this.player.ended=this.ended.bind(this),this.player.duration=this.duration.bind(this),this.player.currentTime=this.currentTime.bind(this),this.player.buffered=this.buffered.bind(this),this.initialize(),this.player.ready(()=>{this.player.trigger("durationchange")})}get clipStart(){const t=this.playerDurationFn();return this._clipStart>t?t:this._clipStart}get clipEnd(){const t=this.playerDurationFn();return t<=0?this._clipEnd:this._clipEnd>t?t:this._clipEnd}dispose(){this.player.off("timeupdate",this.onTimeUpdate),this.player.off("play",this.onPlay),this.player.ended=this.playerEndedFn,this.player.duration=this.playerDurationFn,this.player.currentTime=this.playerCurrentTimeFn,this.player.buffered=this.playerbufferedFn,this.player.trigger("durationchange"),super.dispose()}initialize(){this.onTimeUpdate=this.onTimeUpdate.bind(this),this.onPlay=this.onPlay.bind(this),this.player.on("timeupdate",this.onTimeUpdate),this.player.on("play",this.onPlay)}onPlay(){this._isEnded&&this.player.currentTime(0)}onTimeUpdate(){const t=this.getCurrentTime(!1);if(t>this.clipEnd){this._isEnded||(this.player.pause(),this.player.trigger("ended"),this._isEnded=!0);return}this._isEnded=!1,t<this.clipStart-x&&this.playerCurrentTimeFn(this.clipStart,!0)}ended(){return this.getCurrentTime(!1)>this.clipEnd}duration(t){return t&&t>0&&(this.playerDurationFn()?console.info("The duration of the player has already been set. This is a no-op."):this.playerDurationFn(t)),this.clipEnd-this.clipStart}currentTime(t,...e){if(typeof t!="number")return this.getCurrentTime(!0);const n=t+this.clipStart;this.playerCurrentTimeFn(n,e)}getCurrentTime(t){const e=this.playerCurrentTimeFn();let n=0;return e>=this.clipStart&&(n=e-this.clipStart),this.player.getCache().currentTime=n,t?n:e}buffered(){const t=this.playerbufferedFn(),e=[];for(let n=0;n<t.length;n++)e[n]=[Math.max(0,t.start(n)-this.clipStart),Math.min(Math.max(0,t.end(n)-this.clipStart),this.player.duration())];return i.createTimeRanges(e)}}i.registerPlugin("clipPlugin",v);var a=(s=>(s.None="None",s.Complete="Complete",s.Incomplete="Incomplete",s))(a||{});const C=i.getComponent("Button");class u extends C{constructor(t,e){super(t,e),this.update()}update(){this.options_.activityStatus===a.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===a.None||this.options_.activityStatus===a.Incomplete)return a.Complete;if(this.options_.activityStatus===a.Complete)return a.Incomplete}}u.prototype.controlText_="Complete";const T=i.getPlugin("plugin");class P extends T{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 u(this.player,{activityStatus:this.activityStatus,clickHandler:this.onToggleStatus}),this.player.addChild(this.button)}}i.registerPlugin("activityStatusPlugin",P);const N=i.getComponent("MenuItem");let S=class extends N{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,n){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 o=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>`},n);return o.children[1].appendChild(this.toggleEl),o}dispose(){this.player_.off("cv:loopvideo",this.onLoopVideoChange),super.dispose()}};i.registerComponent("LoopVideoMenuItem",S);const E=i.getPlugin("plugin");i.getComponent("MenuItem");const b=i.getComponent("LoopVideoMenuItem");class I extends E{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:b,name:"LoopVideoMenuItem"})}onEnded(){this.player.loop()&&this.player.play()}loop(t){var e,n,r;if(typeof t!="boolean")return this.player.loop();t&&((r=(n=(e=this.player).nextVideoPlugin)==null?void 0:n.call(e))==null||r.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",I);function V(s){var o;const[t,e]=h.useState(5);if(h.useEffect(()=>{const c=setInterval(()=>{e(g=>g-1)},1e3);return()=>{clearInterval(c)}},[]),h.useEffect(()=>{t===0&&s.onPlayNext()},[t]),!s.nextVideo||!s.onPlayNext)return l.jsx(l.Fragment,{});const n=Math.ceil(t),r=n===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:s.onCancel,children:"×"}),l.jsxs("div",{className:"cv-up-next-heading",children:["Up next in ",n," ",r,":"]}),l.jsx("div",{className:"cv-up-next-image cursor-pointer",onClick:s.onPlayNext,style:{backgroundImage:`url(${(o=s.nextVideo)==null?void 0:o.thumbnailUrl})`}}),l.jsx("div",{className:"cv-up-next-title",children:s.nextVideo.name})]})})}i.registerComponent("UpNext",m((s,t)=>l.jsx(V,{player:s,...t})));const L=i.getComponent("MenuItem");let _=class extends L{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,n){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 o=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>`},n);return o.children[1].appendChild(this.toggleEl),o}dispose(){this.player_.off("cv:playnext",this.onPlayNextChange),super.dispose()}};i.registerComponent("NextVideoMenuItem",_);const d="cv-persisttest",p="cv-play-next-video",M=i.getPlugin("plugin");i.getComponent("MenuItem");const U=i.getComponent("NextVideoMenuItem");class F extends M{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(p);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,n){var o;this.nextVideo=t,this.callback=n,e&&this.setShouldPlayNext(!0),((o=this.player.getChild("collapserator"))==null?void 0:o.getChild("cogButton")).addItem({ctor:U,name:"NextVideoMenuItem"})}getShouldPlayNext(){return this.shouldPlayNextVideo}setShouldPlayNext(t,e){this.shouldPlayNextVideo=t,this.player.trigger("cv:playnext",t),this.hasLocalStorage&&e&&window.localStorage.setItem(p,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(d,"persistPlayNext"),window.localStorage.removeItem(d),!0}catch{return!1}}}i.registerPlugin("nextVideoPlugin",F);
//# sourceMappingURL=VIUZq4Vp.chunk.js.map
