import { sql } from "@/lib/db"
import { type NextRequest, NextResponse } from "next/server"

export async function GET(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  try {
    const { id } = await params

    const tracks = await sql`
      SELECT t.*, a.name as artist_name
      FROM liked_tracks lt
      JOIN tracks t ON lt.track_id = t.id
      LEFT JOIN artists a ON t.artist_id = a.id
      WHERE lt.user_id = ${id}
      ORDER BY lt.created_at DESC
    `

    return NextResponse.json({ tracks })
  } catch (error) {
    console.error("Get liked tracks error:", error)
    return NextResponse.json({ error: "Erreur lors de la recuperation" }, { status: 500 })
  }
}
