const SUPABASE_CONFIG={url:"https://qznykpcsvkdcrjxhnfst.supabase.co",anonKey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF6bnlrcGNzdmtkY3JqeGhuZnN0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjQ0NjMwODgsImV4cCI6MjA4MDAzOTA4OH0.l8h-UPlCDLN8pIPDxrJYf_4D8nzsCIelJtMP75Td65Q"};class SunoAnalytics{constructor(){this.baseUrl=SUPABASE_CONFIG.url,this.headers={apikey:SUPABASE_CONFIG.anonKey,Authorization:`Bearer ${SUPABASE_CONFIG.anonKey}`,"Content-Type":"application/json",Prefer:"return=minimal"}}async hashUserId(t){const e=(new TextEncoder).encode("suno-offline-v1-"+t),s=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(s)).map(t=>t.toString(16).padStart(2,"0")).join("")}async submitAnalytics(t,e=1){try{const s="sunoAnalyticsLastSubmit",n=localStorage.getItem(s);if(n&&(Date.now()-parseInt(n))/36e5<24)return{success:!0,rateLimited:!0};const o={user_hash:await this.hashUserId(t.userId||"anonymous"),privacy_tier:e,extension_version:chrome.runtime.getManifest?.()?.version||"1.0.0"};e>=2&&(o.total_songs=t.totalSongs||0,o.liked_songs=t.likedSongs||0,o.total_duration_hours=t.totalDurationHours||0,o.unique_song_groups=t.uniqueSongGroups||0,o.genre_counts=t.genreCounts||{},o.model_counts=t.modelCounts||{},o.creation_by_month=t.creationByMonth||{});const r=await fetch(`${this.baseUrl}/rest/v1/analytics_submissions`,{method:"POST",headers:this.headers,body:JSON.stringify(o)});if(409===r.status)return{success:!0,alreadySubmitted:!0};if(!r.ok){const t=await r.text();throw new Error(`Analytics submission failed: ${t}`)}return localStorage.setItem(s,Date.now().toString()),{success:!0}}catch(t){return{success:!1,error:t.message}}}async getGlobalInsights(){try{const t=await fetch(`${this.baseUrl}/rest/v1/global_insights?id=eq.current&select=*`,{method:"GET",headers:this.headers});if(!t.ok)throw new Error("Failed to fetch global insights");return(await t.json())[0]||null}catch(t){return null}}calculatePercentile(t,e){return e?t>=e.p99?1:t>=e.p95?5:t>=e.p90?10:t>=e.p75?25:t>=e.p50?50:100:null}}"undefined"!=typeof window&&(window.SunoAnalytics=SunoAnalytics),"undefined"!=typeof self&&"undefined"==typeof window&&(self.SunoAnalytics=SunoAnalytics,self.SUPABASE_CONFIG=SUPABASE_CONFIG);