import { redirect } from 'next/navigation';
import { hasAnyUser } from '@/src/lib/db/user';
import LoginForm from '@/src/components/LoginForm';

export const dynamic = 'force-dynamic';

export default async function LoginPage() {
  let hasUser = false;

  try {
    hasUser = await hasAnyUser();
  } catch (error) {
    console.warn('Failed to determine user setup status on /login:', error);
  }

  if (!hasUser && !process.env.ADMIN_PASSWORD_HASH) {
    redirect('/setup');
  }

  return <LoginForm />;
}
