import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var IA=function(a,b){return 0<=b&&b<a.a.length},JA=function(a){a.trigger(new _.F(_.df))},KA=class extends _.su{on(a,b,c){return super.on(a,b,c)}one(a,b,c){return super.one(a,b,c)}off(a,b){return super.off(a,b)}constructor(a,b){b=void 0===b?()=>Promise.resolve():b;super();this.m=a;this.l=b;this.f=0;this.a=[];this.h=!1;this.j=this.Aa.bind(this)}getPosition(){return this.f}Eh(){return this.a}hd(){return 0<this.a.length&&IA(this,this.f)?this.a[this.f]:null}Fh(){const a=this.f+1;return 0<
this.a.length&&IA(this,a)?this.a[a]:null}Rh(){return this.h}start(){this.h||(this.h=!0,this.m.on(_.Sd,this.j),this.Td(this.f,!0))}stop(){this.h=!1;this.m.off(_.Sd,this.j)}Aa(){this.next()}next(){const a=this;return _.x(function*(){yield a.Td(Math.min(a.a.length-1,a.f+1))})}ji(){const a=this;return _.x(function*(){yield a.Td(Math.max(0,a.f-1))})}Td(a,b){b=void 0===b?!1:b;const c=this;return _.x(function*(){if(0<c.a.length&&IA(c,a)&&(b||c.f!==a)){c.f=a;var d=c.hd();d&&(yield c.l(d),yield c.m.load(d.configuration),
c.trigger(new _.F(_.cf,{item:d})))}})}append(a){this.a.push(a);JA(this)}Ph(a,b){if(0<=b&&b<=this.a.length){const c=this.hd();this.a.splice(b,0,a);c&&(this.f=this.a.indexOf(c));JA(this)}}remove(a){if(0<this.a.length&&IA(this,a)){if(this.f===a)throw Error("Can't remove the current item");this.a.splice(a,1);JA(this)}}clear(){this.stop();this.f=0;this.a=[];this.h=!1;JA(this)}};_.z("clpp.Playlist",KA);KA.prototype.clear=KA.prototype.clear;KA.prototype.remove=KA.prototype.remove;KA.prototype.insert=KA.prototype.Ph;
KA.prototype.append=KA.prototype.append;KA.prototype.goTo=KA.prototype.Td;KA.prototype.previous=KA.prototype.ji;KA.prototype.next=KA.prototype.next;KA.prototype.onEnded=KA.prototype.Aa;KA.prototype.stop=KA.prototype.stop;KA.prototype.start=KA.prototype.start;KA.prototype.isStarted=KA.prototype.Rh;KA.prototype.getUpcoming=KA.prototype.Fh;KA.prototype.getCurrent=KA.prototype.hd;KA.prototype.getQueue=KA.prototype.Eh;KA.prototype.getPosition=KA.prototype.getPosition;KA.prototype.off=KA.prototype.off;
KA.prototype.one=KA.prototype.one;KA.prototype.on=KA.prototype.on;};f.call(g, window);