import{r as i,h as t,a as s}from"./p-BxRAfMA5.js";import{i as l}from"./p-EuTDjLsB.js";const o=":host{display:block;overflow:hidden}presto-player{opacity:0;visibility:hidden;transition:0.35s opacity, 0.35s visibility}presto-player.ready{opacity:1;visibility:visible}",e=class{constructor(t){i(this,t),this.transitionDuration=5,this.playing=!1}rewatch(){this.handlePlay()}next(){this.handleNext()}handleCurrentPlay(t,i){var e;t&&(this.addOverlay(),this.currentPlyr.elements.container.getRootNode().host.style=this.currentPlaylistItem.config.styles,"youtube"===this.currentPlyr.provider&&l()||void 0!==i&&("youtube"===this.currentPlyr.provider&&!this.currentPlyr.muted&&(null===(e=this.currentPlyr)||void 0===e?void 0:e.embed)&&this.currentPlyr.embed.unMute(),this.currentPlyr.play()))}resetPlayingStateOnItemChange(){this.playing=!1}addOverlay(){var t,i;this.overlay=document.createElement("presto-playlist-overlay"),this.overlay.nextItemTitle=this.getNextItemTitle(),this.overlay.isLastItem=this.isLastItem(),this.overlay.nextItemString=(null==this?void 0:this.listTextSingular)||"Video",this.overlay.transitionDuration=this.transitionDuration,null===(i=null===(t=this.currentPlyr.elements)||void 0===t?void 0:t.container)||void 0===i||i.closest(".presto-player__wrapper").append(this.overlay)}componentWillLoad(){var t;this.currentPlaylistItem=(null===(t=null==this?void 0:this.items)||void 0===t?void 0:t[0])||null}handleItemClick(t){this.overlay&&(this.overlay.show=!1),this.el.style.height=this.el.offsetHeight+"px",this.el.style.width=this.el.offsetWidth+"px",this.currentPlaylistItem=t}handleNext(){this.overlay.show=!1,this.currentPlaylistItem=this.getNextItem()||this.currentPlaylistItem}handlePlay(){this.overlay&&(this.overlay.show=!1),this.currentPlyr.play()}handlePause(){this.overlay.show=!1,this.currentPlyr.pause()}getNextItem(){var t,i,e,l;if(this.isLastItem())return this.items[0];let s;for(let r=0;r<(null===(t=this.items)||void 0===t?void 0:t.length);r++)if((null===(i=this.items[r])||void 0===i?void 0:i.id)===(null===(e=this.currentPlaylistItem)||void 0===e?void 0:e.id)&&(null===(l=this.items)||void 0===l?void 0:l.length)!==r+1){s=this.items[r+1];break}return s}isLastItem(){var t,i,e;const l=(null===(t=this.items)||void 0===t?void 0:t.length)-1;return(null===(i=this.items[l])||void 0===i?void 0:i.id)===(null===(e=this.currentPlaylistItem)||void 0===e?void 0:e.id)}getNextItemTitle(){var t;const i=this.getNextItem();return void 0!==i?(null==i?void 0:i.title)||(null===(t=null==i?void 0:i.config)||void 0===t?void 0:t.title):""}render(){var i,e,l,s,r,n,o,a,d;if(!(null===(i=this.items)||void 0===i?void 0:i.length))return"";const h=this.listTextSingular?this.listTextSingular:"Video",u=this.listTextPlural?this.listTextPlural:"Videos";return t("presto-playlist-ui",null,(null===(e=this.currentPlaylistItem.config)||void 0===e?void 0:e.src)?t("presto-player",{slot:"preview",src:null===(l=this.currentPlaylistItem.config)||void 0===l?void 0:l.src,...this.currentPlaylistItem.config,videoId:null===(s=this.currentPlaylistItem.config)||void 0===s?void 0:s.id,id:`presto-player-${null===(r=this.currentPlaylistItem.config)||void 0===r?void 0:r.id}`,"media-title":null===(n=this.currentPlaylistItem.config)||void 0===n?void 0:n.title,class:null===(o=this.currentPlaylistItem.config)||void 0===o?void 0:o.playerClass,key:null===(a=this.currentPlaylistItem.config)||void 0===a?void 0:a.id,provider:null===(d=this.currentPlaylistItem.config)||void 0===d?void 0:d.provider,onPlayerReady:t=>{this.currentPlyr=t.detail,this.el.style.height=null,this.el.style.width=null},onPlayedMedia:()=>this.playing=!0,onPausedMedia:()=>this.playing=!1,onEndedMedia:()=>this.overlay.show=!0}):t("slot",{name:"unauthorized",slot:"preview"}),t("div",{slot:"title"},this.heading||"Playlist"),t("div",{slot:"count"},this.items.length," ",this.items.length>1?u:h),this.items.map(i=>{var e,l,s,r;return t("presto-playlist-item",{slot:"list",onClick:()=>this.handleItemClick(i),active:(null===(e=this.currentPlaylistItem)||void 0===e?void 0:e.id)===(null==i?void 0:i.id),playing:(null===(l=this.currentPlaylistItem)||void 0===l?void 0:l.id)===(null==i?void 0:i.id)&&this.playing,class:(null===(s=this.currentPlaylistItem)||void 0===s?void 0:s.id)===(null==i?void 0:i.id)?"active":"",key:null==i?void 0:i.id,onTriggerPause:()=>this.handlePause(),onTriggerPlay:()=>this.handlePlay()},t("span",{slot:"item-title"},t("span",null,(null==i?void 0:i.title)||(null===(r=null==i?void 0:i.config)||void 0===r?void 0:r.title))),t("span",{slot:"item-duration"},t("span",null,null==i?void 0:i.duration)))}))}get el(){return s(this)}static get watchers(){return{currentPlyr:["handleCurrentPlay"],currentPlaylistItem:["resetPlayingStateOnItemChange"]}}};e.style=o;export{e as presto_playlist};