import { redirect } from 'next/navigation'
import { getSession } from '@/lib/auth'
import { prisma } from '@/lib/prisma'
import { ResetPasswordForm } from './reset-form'

export default async function ResetPasswordPage() {
  const session = await getSession()
  if (!session.userId) {
    redirect('/login')
  }

  const user = await prisma.user.findUnique({
    where: { id: session.userId },
    select: { must_reset_password: true },
  })

  if (!user?.must_reset_password) {
    redirect('/dashboard')
  }

  return (
    <main className="min-h-screen bg-background flex items-center justify-center p-4">
      <div className="w-full max-w-sm space-y-6">
        <div className="text-center space-y-1">
          <h1 className="text-2xl font-medium text-foreground">Wachtwoord wijzigen</h1>
          <p className="text-sm text-muted-foreground">
            Kies een nieuw wachtwoord om verder te gaan.
          </p>
        </div>

        <div className="bg-surface-container-low rounded-xl p-6 space-y-4 border border-border">
          <ResetPasswordForm />
        </div>
      </div>
    </main>
  )
}
