import Link from 'next/link'
import { redirect } from 'next/navigation'
import { getCurrentUser } from '@/lib/session'

export const dynamic = 'force-dynamic'

const SECTIONS = [
  { href: '/docker', title: 'Docker', desc: 'Containers en status' },
  { href: '/git', title: 'Git', desc: 'Repo checkouts en diffs' },
  { href: '/systemd', title: 'systemd', desc: 'Services en journals' },
  { href: '/caddy', title: 'Caddy', desc: 'Config en certs' },
  { href: '/flows', title: 'Flows', desc: 'Multi-step deployments' },
  { href: '/audit', title: 'Audit', desc: 'Command-log en runs' },
  { href: '/settings', title: 'Settings', desc: 'Backups en config' },
]

export default async function Home() {
  const user = await getCurrentUser()
  if (!user) redirect('/login')

  return (
    <div className="min-h-screen bg-background p-6">
      <div className="mx-auto max-w-6xl space-y-6">
        <div>
          <h1 className="text-2xl font-semibold tracking-tight">Ops Dashboard</h1>
          <p className="text-sm text-muted-foreground">Welkom {user.email}</p>
        </div>
        <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
          {SECTIONS.map((s) => (
            <Link
              key={s.href}
              href={s.href}
              className="block rounded-lg border bg-card p-5 transition-colors hover:bg-accent"
            >
              <h2 className="text-lg font-medium">{s.title}</h2>
              <p className="mt-1 text-sm text-muted-foreground">{s.desc}</p>
            </Link>
          ))}
        </div>
      </div>
    </div>
  )
}
