const SunoPlayer=function(){"use strict";const n="undefined"!=typeof SunoCore?SunoCore:window.SunoCore;let e=null,t=null,r=null,u=[],o=-1,i=!1,l=null,a=null,c=null,d=null,s=null,f=null;function m(){l&&l(t,r)}function p(){a&&a(t,r)}function h(){if(!e)return;const t=e.currentTime,r=e.duration||0;c&&c({currentTime:t,duration:r,percent:r>0?t/r*100:0,formattedTime:n.formatTime(t),formattedDuration:n.formatTime(r)})}function y(){d&&d(t,r),u.length>0&&o<u.length-1&&E()}function g(n){s&&s(n,t)}function v(n,u=null){return!(!i||!e||!n||!n.audio_url||(t=n,r=u,e.src=n.audio_url,e.play().catch(e=>{s&&s(e,n)}),f&&f(n,u),0))}function T(){e&&!e.paused&&e.pause()}function P(){e&&e.paused&&e.src&&e.play().catch(n=>{})}function E(){return 0!==u.length&&o<u.length-1&&(o++,v(u[o],r),!0)}return{init:function(n,t={}){return!!n&&(e=n,l=t.onPlay||null,a=t.onPause||null,c=t.onTimeUpdate||null,d=t.onEnded||null,s=t.onError||null,f=t.onClipChange||null,e.addEventListener("play",m),e.addEventListener("pause",p),e.addEventListener("timeupdate",h),e.addEventListener("ended",y),e.addEventListener("error",g),i=!0,!0)},destroy:function(){e&&(e.removeEventListener("play",m),e.removeEventListener("pause",p),e.removeEventListener("timeupdate",h),e.removeEventListener("ended",y),e.removeEventListener("error",g),e.pause(),e.src=""),e=null,t=null,r=null,u=[],o=-1,i=!1},play:v,pause:T,resume:P,toggle:function(){e&&(e.paused?P():T())},stop:function(){e&&(e.pause(),e.currentTime=0,e.src=""),t=null,r=null},seek:function(n){if(!e||!e.duration)return;const t=Math.max(0,Math.min(100,n));e.currentTime=t/100*e.duration},seekTo:function(n){e&&(e.currentTime=Math.max(0,Math.min(n,e.duration||0)))},setPlaylist:function(n,e=0){u=n||[],o=Math.max(0,Math.min(e,u.length-1)),u.length>0&&o>=0&&v(u[o])},playNext:E,playPrev:function(){return 0!==u.length&&(e&&e.currentTime>3?(e.currentTime=0,!0):o>0&&(o--,v(u[o],r),!0))},playFromPlaylist:function(n){return n>=0&&n<u.length&&(o=n,v(u[o],r),!0)},getCurrentClip:function(){return t},getCurrentSong:function(){return r},isPlaying:function(){return e&&!e.paused},getProgress:function(){if(!e)return{currentTime:0,duration:0,percent:0};const n=e.currentTime||0,t=e.duration||0;return{currentTime:n,duration:t,percent:t>0?n/t*100:0}},getPlaylistInfo:function(){return{playlist:u,index:o,length:u.length,hasNext:o<u.length-1,hasPrev:o>0}}}}();"undefined"!=typeof module&&module.exports&&(module.exports=SunoPlayer),"undefined"!=typeof window&&(window.SunoPlayer=SunoPlayer);