/* recording-platforms.jsx ─────────────────────────────────────────────
   Track-level DSP popularity scores. Mirrors astro.recordings columns
   (spotify_popularity, tidal_popularity, qobuz_popularity, apple_score,
   plus per-platform metadata: spotify_explicit, tidal_audio_quality,
   qobuz_hires, qobuz_maximum_bit_depth/sampling_rate, apple_has_atmos).

   Surfaces a "PLATFORM POPULARITY" strip in the recording drawer.
   Recordings without an entry fall back to release-level scores
   (dimmed by ~6 pts) via recordingPlatformDetails().
*/

try {
const RECORDING_PLATFORM_DETAILS = {
  // ── Cranes In The Sky · Solange ──────────────────────────────
  r_01: { spotifyPopularity:79, tidalPopularity:74, qobuzPopularity:71, appleMusicScore:84,
    qobuzHires:true, qobuzMaximumBitDepth:24, qobuzMaximumSamplingRate:96, appleHasAtmos:true,
    tidalQuality:'HI-RES LOSSLESS', spotifyExplicit:false, lastUpdated:'1 hour ago' },
  r_01b: { spotifyPopularity:42, tidalPopularity:39, qobuzPopularity:37, appleMusicScore:44,
    qobuzHires:false, qobuzMaximumBitDepth:16, qobuzMaximumSamplingRate:44.1,
    tidalQuality:'LOSSLESS', lastUpdated:'4 hours ago' },
  r_01c: { spotifyPopularity:28, tidalPopularity:24, qobuzPopularity:22, appleMusicScore:30,
    qobuzHires:false, tidalQuality:'LOSSLESS', lastUpdated:'12 hours ago' },

  // ── Birds · Floating Points ──────────────────────────────────
  r_02: { spotifyPopularity:62, tidalPopularity:58, qobuzPopularity:64, appleMusicScore:55,
    qobuzHires:true, qobuzMaximumBitDepth:24, qobuzMaximumSamplingRate:96,
    tidalQuality:'HI-RES LOSSLESS', lastUpdated:'2 hours ago' },

  // ── Bunny Is A Rider · Caroline Polachek ─────────────────────
  r_03: { spotifyPopularity:84, tidalPopularity:80, qobuzPopularity:77, appleMusicScore:89,
    qobuzHires:true, qobuzMaximumBitDepth:24, qobuzMaximumSamplingRate:96, appleHasAtmos:true,
    tidalQuality:'HI-RES LOSSLESS', spotifyExplicit:false, lastUpdated:'1 hour ago' },
  r_03b: { spotifyPopularity:51, tidalPopularity:47, qobuzPopularity:45, appleMusicScore:53,
    qobuzHires:false, tidalQuality:'LOSSLESS', lastUpdated:'6 hours ago' },

  // ── Send Me · Tirzah ─────────────────────────────────────────
  r_04: { spotifyPopularity:54, tidalPopularity:51, qobuzPopularity:49, appleMusicScore:53,
    qobuzHires:false, qobuzMaximumBitDepth:16, qobuzMaximumSamplingRate:44.1,
    tidalQuality:'LOSSLESS', lastUpdated:'5 hours ago' },

  // ── Far In · Helado Negro ────────────────────────────────────
  r_05: { spotifyPopularity:48, tidalPopularity:44, qobuzPopularity:51, appleMusicScore:46,
    qobuzHires:true, qobuzMaximumBitDepth:24, qobuzMaximumSamplingRate:48,
    tidalQuality:'HI-RES LOSSLESS', lastUpdated:'7 hours ago' },

  // ── 10% · KAYTRANADA · Kali Uchis ────────────────────────────
  r_06: { spotifyPopularity:88, tidalPopularity:84, qobuzPopularity:75, appleMusicScore:92,
    qobuzHires:true, qobuzMaximumBitDepth:24, qobuzMaximumSamplingRate:96, appleHasAtmos:true,
    tidalQuality:'HI-RES LOSSLESS', spotifyExplicit:true, lastUpdated:'30 min ago' },
  r_06b: { spotifyPopularity:34, tidalPopularity:30, qobuzPopularity:28, appleMusicScore:36,
    qobuzHires:false, tidalQuality:'LOSSLESS', spotifyExplicit:true, lastUpdated:'1 day ago' },

  // ── Raingurl · Yaeji ─────────────────────────────────────────
  r_07: { spotifyPopularity:71, tidalPopularity:66, qobuzPopularity:62, appleMusicScore:68,
    qobuzHires:false, qobuzMaximumBitDepth:16, qobuzMaximumSamplingRate:44.1,
    tidalQuality:'LOSSLESS', lastUpdated:'3 hours ago' },

  // ── Wildfires · Sault ────────────────────────────────────────
  r_08: { spotifyPopularity:73, tidalPopularity:69, qobuzPopularity:66, appleMusicScore:75,
    qobuzHires:true, qobuzMaximumBitDepth:24, qobuzMaximumSamplingRate:48, appleHasAtmos:true,
    tidalQuality:'HI-RES LOSSLESS', lastUpdated:'2 hours ago' },

  // ── Two Face · L'Rain ────────────────────────────────────────
  r_10: { spotifyPopularity:38, tidalPopularity:35, qobuzPopularity:32, appleMusicScore:39,
    qobuzHires:false, tidalQuality:'LOSSLESS', lastUpdated:'9 hours ago' },
};

// Lookup helper that falls back to release-level scores if no per-track entry
function recordingPlatformDetails(rec) {
  if (!rec) return null;
  const direct = RECORDING_PLATFORM_DETAILS[rec.id];
  if (direct) return direct;
  // Fallback: derive from parent release(s)
  const releases = window.RELEASE_PLATFORM_DETAILS || {};
  const parentId = (rec.releaseIds || []).find(rid => releases[rid]);
  if (!parentId) return null;
  const p = releases[parentId];
  // Tone down release-level scores by ~6 pts to indicate "track ≤ album avg"
  const dim = (v) => typeof v === 'number' ? Math.max(5, v - 6) : v;
  return {
    spotifyPopularity: dim(p.spotifyPopularity),
    tidalPopularity:   dim(p.tidalPopularity),
    qobuzPopularity:   dim(p.qobuzPopularity),
    appleMusicScore:   dim(p.appleMusicScore),
    qobuzHires: p.qobuzHires, qobuzMaximumBitDepth: p.qobuzMaximumBitDepth,
    qobuzMaximumSamplingRate: p.qobuzMaximumSamplingRate,
    tidalQuality: p.tidalQuality, appleHasAtmos: p.appleHasAtmos,
    lastUpdated: p.lastUpdated, fromRelease: true,
  };
}

window.RECORDING_PLATFORM_DETAILS = RECORDING_PLATFORM_DETAILS;
window.recordingPlatformDetails  = recordingPlatformDetails;
} catch(e) { console.warn('[recording-platforms] init skipped:', e.message); }
