"use client"; import { Loader2, Music } from "lucide-react"; import { useEffect, useState } from "react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { getCachedSongPickerOptions, invalidateSongPickerCache, loadSongPickerOptions, type SoundtrackOption, } from "@/lib/client-cache/song-picker-cache"; // Re-export so existing `import { invalidateSongPickerCache } from '.../song-picker'` // callsites keep working. New code should import from the lib module directly. export { invalidateSongPickerCache }; interface Props { value: number; onChange: (id: number) => void; disabled?: boolean; } function formatLength(seconds: number): string { if (!seconds || seconds <= 0) return ""; const m = Math.floor(seconds / 60); const s = seconds % 60; return `${m}:${String(s).padStart(2, "0")}`; } export function SongPicker({ value, onChange, disabled }: Props) { const initial = getCachedSongPickerOptions(); const [options, setOptions] = useState(initial ?? []); const [loading, setLoading] = useState(!initial); useEffect(() => { if (getCachedSongPickerOptions()) return; let cancelled = false; loadSongPickerOptions() .then((items) => { if (!cancelled) setOptions(items); }) .catch(() => { if (!cancelled) setOptions([]); }) .finally(() => { if (!cancelled) setLoading(false); }); return () => { cancelled = true; }; }, []); return ( ); }