import { NextResponse } from "next/server"
import { deleteVideo } from "@/lib/videos"
import { validateAdminToken } from "@/lib/admin-auth"

export async function DELETE(
  request: Request,
  { params }: { params: Promise<{ id: string }> }
) {
  const authHeader = request.headers.get("Authorization")
  const token = authHeader?.replace("Bearer ", "")

  if (!token || !validateAdminToken(token)) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
  }

  const { id } = await params
  const deleted = deleteVideo(id)

  if (!deleted) {
    return NextResponse.json({ error: "Video not found" }, { status: 404 })
  }

  return NextResponse.json({ success: true })
}
