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

export const dynamic = 'force-dynamic'

const FLOWS = [
  {
    href: '/flows/redeploy-all',
    title: 'Redeploy All',
    desc: 'Volledige stack-redeploy: scrum4me-web + MCP-worker (cache-busted)',
  },
  {
    href: '/flows/update-scrum4me-web',
    title: 'Update Scrum4Me website',
    desc: 'Pull main, build, restart container, run smoke tests',
  },
  {
    href: '/flows/update-caddy-config',
    title: 'Update Caddy config',
    desc: 'Reload Caddy met nieuwe Caddyfile + cert renewal check',
  },
]

export default async function FlowsIndex() {
  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">Flows</h1>
          <p className="text-sm text-muted-foreground">Multi-step deployments met dry-run en audit-log</p>
        </div>
        <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
          {FLOWS.map((f) => (
            <Link
              key={f.href}
              href={f.href}
              className="block rounded-lg border bg-card p-5 transition-colors hover:bg-accent"
            >
              <h2 className="text-lg font-medium">{f.title}</h2>
              <p className="mt-1 text-sm text-muted-foreground">{f.desc}</p>
            </Link>
          ))}
        </div>
      </div>
    </div>
  )
}
