(function(n,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n.MagicLottery={}))})(this,function(n){"use strict";var u=Object.defineProperty;var a=(n,s,f)=>s in n?u(n,s,{enumerable:!0,configurable:!0,writable:!0,value:f}):n[s]=f;var l=(n,s,f)=>(a(n,typeof s!="symbol"?s+"":s,f),f);class s{constructor(e,t={}){l(this,"entries",[]);l(this,"shuffledEntries",[]);l(this,"shuffle");l(this,"channelName");l(this,"replacement");this.entries=e,this.shuffle=t.shuffle||this.defaultShuffle,this.shuffledEntries=this.shuffle([...this.entries]),this.channelName=t.channelName,this.replacement=t.replacement||!0}setChannelName(e){this.channelName=e}getChannelName(){return this.channelName}add(e){this.entries.push(...e),this.shuffledEntries=this.shuffle([...this.entries])}draw(){return[...this.shuffledEntries]}drawOriginal(){return[...this.entries]}drawWinner(e={replacement:this.replacement}){const{replacement:t}=e;if(this.shuffledEntries.length>0){const i=this.shuffledEntries[0];return t||this.remove(i),i}else throw new Error("At least one entry is required.")}drawWinners(e,t={replacement:this.replacement}){const{replacement:i}=t;if(e<=this.shuffledEntries.length){const h=this.shuffledEntries.slice(0,e);return i||h.forEach(r=>this.remove(r)),h}else throw new Error("Requested number of winners exceeds the total entries.")}setShuffle(e){this.shuffle=e,this.shuffledEntries=this.shuffle([...this.entries])}getShuffle(){return this.shuffle}remove(e){const t=this.entries.indexOf(e);t>-1&&(this.entries.splice(t,1),this.shuffledEntries=this.shuffle([...this.entries]))}hasEntry(e){return this.entries.includes(e)}size(){return this.entries.length}isEmpty(){return this.entries.length===0}reset(){this.entries=[],this.shuffledEntries=[]}async nextWinner(e={replacement:this.replacement}){const{replacement:t}=e;return new Promise((i,h)=>{if(this.shuffledEntries.length>0){const r=this.shuffledEntries[0];t||this.remove(r),i(r)}else h("No more entries left.")})}defaultShuffle(e){const t=[...e];let i=t.length,h,r;for(;i!==0;)r=Math.floor(Math.random()*i),i-=1,h=t[i],t[i]=t[r],t[r]=h;return t}}n.Lottery=s,n.MagicLottery=s,n.default=s,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); //# sourceMappingURL=index.umd.cjs.map