import { auth } from "@/lib/auth";
import { redirect } from "next/navigation";
import { Navbar } from "@/components/Navbar";
import { ClientOnly } from "@/components/ClientOnly";
import { ServerControls } from "@/components/ServerControls";
import { Analytics } from "@/components/Analytics";
import { PlayerManager } from "@/components/PlayerManager";
import { ChatBridge } from "@/components/ChatBridge";
import { ModManager } from "@/components/ModManager";
import { BackupManager } from "@/components/BackupManager";
import { LogViewer } from "@/components/LogViewer";
import Link from "next/link";

export default async function AdminPage() {
  const session = await auth();
  if (!session) redirect("/login");

  return (
    <>
      <Navbar />

      <div className="border-b border-border bg-card py-4 sm:py-6">
        <div className="max-w-5xl mx-auto px-3 sm:px-6">
          <h1 className="text-xl sm:text-2xl font-bold tracking-tight">Admin Panel</h1>
          <p className="text-sm text-muted-foreground mt-1">
            Manage your Minecraft server
          </p>
        </div>
      </div>

      <ClientOnly>
        <div className="max-w-5xl mx-auto px-3 py-4 sm:p-6 space-y-4 sm:space-y-6 w-full overflow-x-hidden">
          <ServerControls />
          <Analytics />
          <PlayerManager />
          <ChatBridge />
          <ModManager />
          <BackupManager />
          <LogViewer />

          <div className="text-center">
            <Link
              href="/"
              className="text-sm text-muted-foreground hover:text-foreground transition"
            >
              Back to dashboard
            </Link>
          </div>
        </div>
      </ClientOnly>
    </>
  );
}
