import { Head, Link, usePage } from '@inertiajs/react';
import { LayoutDashboard } from 'lucide-react';

type Dash = { slug: string; name: string; description: string | null };

export default function Dashboards() {
    const { dashboards } = usePage().props as unknown as { dashboards: Dash[] };

    return (
        <>
            <Head title="Dashboards" />
            <div className="mx-auto w-full max-w-6xl px-6 py-8">
                <header className="mb-8">
                    <h1 className="text-2xl font-semibold tracking-tight text-foreground">Dashboards</h1>
                    <p className="mt-1 text-sm text-muted-foreground">Dashboards published to your organization.</p>
                </header>

                {dashboards.length === 0 ? (
                    <div className="rounded-xl border border-dashed border-border p-12 text-center">
                        <LayoutDashboard className="mx-auto size-8 text-muted-foreground" />
                        <p className="mt-3 text-sm font-medium text-foreground">No dashboards yet</p>
                        <p className="mt-1 text-sm text-muted-foreground">An administrator will publish dashboards to your organization.</p>
                    </div>
                ) : (
                    <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
                        {dashboards.map((d) => (
                            <Link key={d.slug} href={`/dashboards/${d.slug}`}
                                className="rounded-xl border border-border bg-card p-5 shadow-sm transition hover:shadow-md">
                                <LayoutDashboard className="size-5 text-primary" />
                                <p className="mt-3 font-medium text-foreground">{d.name}</p>
                                {d.description && <p className="mt-1 text-sm text-muted-foreground">{d.description}</p>}
                            </Link>
                        ))}
                    </div>
                )}
            </div>
        </>
    );
}
