"use client";

import { useAppSelector } from "@/lib/hooks";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { getAvatarUrl } from "@/lib/utils";

export default function DashboardPage() {
    const { user } = useAppSelector((state) => state.auth);

    return (
        <div className="space-y-6">
            <div>
                <h3 className="text-lg font-medium">Hoşgeldin, {user?.username}</h3>
                <p className="text-sm text-muted-foreground">
                    Admin paneli kontrol merkezi.
                </p>
            </div>
            <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
                <Card>
                    <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                        <CardTitle className="text-sm font-medium">Toplam Kullanıcı</CardTitle>
                    </CardHeader>
                    <CardContent>
                        <div className="text-2xl font-bold">128</div>
                        <p className="text-xs text-muted-foreground">
                            +4% geçen aydan beri
                        </p>
                    </CardContent>
                </Card>
                <Card>
                    <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
                        <CardTitle className="text-sm font-medium">Aktif Roller</CardTitle>
                    </CardHeader>
                    <CardContent>
                        <div className="text-2xl font-bold">
                            {user?.roles?.map(r => r.name).join(", ") || "Yok"}
                        </div>
                    </CardContent>
                </Card>
            </div>

            <Card>
                <CardHeader>
                    <CardTitle>Profil Bilgileri</CardTitle>
                </CardHeader>
                <CardContent className="flex items-center gap-4">
                    <Avatar className="h-20 w-20">
                        <AvatarImage src={getAvatarUrl(user?.avatar_url)} />
                        <AvatarFallback>{user?.username?.slice(0, 2).toUpperCase()}</AvatarFallback>
                    </Avatar>
                    <div>
                        <div className="font-semibold text-lg">{user?.username}</div>
                        <div className="text-muted-foreground">{user?.email}</div>
                        <div className="text-xs text-muted-foreground mt-1">ID: {user?.id}</div>
                    </div>
                </CardContent>
            </Card>
        </div>
    );
}
