const PublicSiteDB=function(){"use strict";const t="undefined"!=typeof SunoCore?SunoCore:window.SunoCore;let e=null,n=!1,o=null;function a(){if(!n)throw new Error("Library not loaded. Call loadLibrary() first.")}const r=t?.normalizeTitle||function(t){return t&&t.trim()||"Untitled"},i=t?.getParentId||function(t){return t?.metadata?.upsample_clip_id||t?.metadata?.edited_clip_id||t?.metadata?.source_clip_id||null},l=t?.getModelLabel||function(t){return"upload"===t?.metadata?.type?"📤 Upload":"v?"},u=t?.isInstrumental||function(t){return!0===t?.is_instrumental},s=t?.findLineageRoot||function(t,e){let n=t;for(;n;){const t=i(n);if(!t)return n;const o=e.get(t);if(!o)return n;n=o}return t},c=t?.traceAncestry||function(t,e){const n=[t];let o=t;for(;;){const t=i(o);if(!t)break;const a=e.get(t);if(!a)break;n.push(a),o=a}return n},d=t?.buildLineageMap||function(t){const e=new Map,n=new Map;for(const o of t){const t=i(o);t&&(e.has(t)||e.set(t,[]),e.get(t).push(o.id),n.set(o.id,t))}return{parentToChildren:e,childToParent:n}};return{loadLibrary:async function(t="/data/library.json"){return o||(o=(async()=>{try{const o=await fetch(t);if(!o.ok)throw new Error(`Failed to load library: ${o.status}`);return e=await o.json(),n=!0,e}catch(t){throw t}})(),o)},isLoaded:()=>n,getAllClips:function(){return a(),e.clips||[]},getClipById:function(t){return a(),e.clips?.find(e=>e.id===t)||null},getClipCount:function(){return a(),e.clips?.length||0},normalizeTitle:r,groupClipsBySong:function(t){const e=new Map;for(const n of t){const t=r(n.title);e.has(t)||e.set(t,{baseTitle:t,clips:[],likedCount:0,totalPlayCount:0,oldestDate:n.created_at,newestDate:n.created_at,hasUpload:!1,isUploadGroup:!1});const o=e.get(t);o.clips.push(n),n.is_liked&&o.likedCount++,o.totalPlayCount+=n.play_count||0,n.created_at<o.oldestDate&&(o.oldestDate=n.created_at),n.created_at>o.newestDate&&(o.newestDate=n.created_at),"upload"===n.metadata?.type&&(o.hasUpload=!0,o.isUploadGroup=!0)}for(const t of e.values())t.clips.sort((t,e)=>new Date(e.created_at)-new Date(t.created_at));return Array.from(e.values()).sort((t,e)=>new Date(e.newestDate)-new Date(t.newestDate))},getCustomName:function(t){return a(),e.customNames?.[t]||null},getDefinitiveVersion:function(t,n="overall"){a();const o="overall"===n?t:`${t}:${n}`;return e.definitiveVersions?.[o]||null},getParentId:i,buildLineageMap:d,findLineageRoot:s,traceAncestry:c,isInstrumental:u,getModelLabel:l,formatDuration:t?.formatDuration||function(t){return t?`${Math.floor(t/60)}:${Math.floor(t%60).toString().padStart(2,"0")}`:"--:--"},detectPlatform:t?.detectPlatform||function(t){return{icon:"🔗",name:"Link"}},getMeta:function(){return a(),e.meta||{}},getConfig:function(){return a(),e.config||{mode:"public-site"}}}}();"undefined"!=typeof module&&module.exports&&(module.exports=PublicSiteDB);