import { auth, signOut } from "@/lib/auth"
import { redirect } from "next/navigation"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"
import { MessageSquare, FolderGit2, Users } from "lucide-react"
import Link from "next/link"

export default async function DashboardPage() {
    const session = await auth()

    if (!session?.user) {
        redirect("/admin/login")
    }

    return (
        <div className="p-8 space-y-8 max-w-7xl mx-auto">
            <div className="flex items-center justify-between">
                <h1 className="text-3xl font-bold">Admin Dashboard</h1>
                <form
                    action={async () => {
                        "use server"
                        await signOut()
                    }}
                >
                    <Button variant="outline">Sign Out</Button>
                </form>
            </div>

            <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
                <Card>
                    <CardHeader>
                        <CardTitle>Welcome back, {session.user.name || session.user.email}</CardTitle>
                    </CardHeader>
                    <CardContent>
                        <p className="text-sm text-gray-500">
                            Role: <span className="font-mono">{session.user.role}</span>
                        </p>
                    </CardContent>
                </Card>
            </div>

            <h2 className="text-2xl font-bold mt-12 mb-6">Quick Links</h2>
            <div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
                <Link href="/admin/inquiries">
                    <Card className="hover:border-primary/50 transition-colors h-full flex flex-col items-center justify-center p-6 text-center">
                        <MessageSquare className="h-12 w-12 text-primary mb-4" />
                        <CardTitle>Inquiries</CardTitle>
                        <CardDescription className="mt-2">Manage quote requests and leads</CardDescription>
                    </Card>
                </Link>

                <Link href="/admin/blog">
                    <Card className="hover:border-primary/50 transition-colors h-full flex flex-col items-center justify-center p-6 text-center">
                        <FolderGit2 className="h-12 w-12 text-primary mb-4" />
                        <CardTitle>Blog Posts</CardTitle>
                        <CardDescription className="mt-2">Write, edit, and schedule articles</CardDescription>
                    </Card>
                </Link>

                <Link href="/admin/portfolio">
                    <Card className="hover:border-primary/50 transition-colors h-full flex flex-col items-center justify-center p-6 text-center">
                        <FolderGit2 className="h-12 w-12 text-primary mb-4" />
                        <CardTitle>Portfolio</CardTitle>
                        <CardDescription className="mt-2">Manage case studies and projects</CardDescription>
                    </Card>
                </Link>

                <Link href="/admin/testimonials">
                    <Card className="hover:border-primary/50 transition-colors h-full flex flex-col items-center justify-center p-6 text-center">
                        <Users className="h-12 w-12 text-primary mb-4" />
                        <CardTitle>Testimonials</CardTitle>
                        <CardDescription className="mt-2">Approve and manage client reviews</CardDescription>
                    </Card>
                </Link>
            </div>
        </div>
    )
}
