import { prisma } from "@/lib/prisma"
import Navigation from "@/components/Navigation"
import Link from "next/link"
import { notFound } from "next/navigation"

interface PageProps {
  params: Promise<{
    id: string
  }>
}

export const dynamic = "force-dynamic"

export default async function TournamentSchedulePage({ params }: PageProps) {
  const { id } = await params
  const tournamentId = parseInt(id, 10)

  if (isNaN(tournamentId)) {
    notFound()
  }

  const tournament = await prisma.event.findUnique({
    where: { id: tournamentId },
    include: {
      participants: {
        include: {
          player: true,
        },
      },
    },
  })

  if (!tournament) {
    notFound()
  }

  return (
    <div className="min-h-screen bg-gray-50">
      <Navigation />

      <main className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
        <div className="px-4 py-6 sm:px-0">
          <div className="mb-6">
            <Link
              href={`/admin/tournaments/${tournamentId}`}
              className="text-green-600 hover:text-green-900"
            >
              ← Back to Tournament
            </Link>
          </div>

          <h1 className="text-3xl font-bold text-gray-900 mb-6">
            Schedule - {tournament.name}
          </h1>

          <div className="bg-white shadow rounded-lg p-6">
            <div className="flex justify-between items-center mb-6">
              <h2 className="text-xl font-bold text-gray-900">
                Tournament Schedule
              </h2>
              <button className="bg-green-600 text-white px-4 py-2 rounded-md text-sm font-medium hover:bg-green-700">
                Generate Schedule
              </button>
            </div>

            <p className="text-gray-500">
              No schedule has been generated yet. Click "Generate Schedule" to create round matchups.
            </p>
          </div>
        </div>
      </main>
    </div>
  )
}