'use client';

import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useMe } from '@/lib/auth';

export default function HomePage() {
  const { data: user, isLoading, error } = useMe();
  const router = useRouter();

  useEffect(() => {
    if (isLoading) return;
    if (error || !user) {
      router.replace('/login');
      return;
    }
    if (user.isCaptain && user.isVolunteer) router.replace('/role');
    else if (user.isCaptain) router.replace('/captain');
    else router.replace('/volunteer');
  }, [user, isLoading, error, router]);

  return (
    <div className="min-h-screen flex items-center justify-center bg-paper">
      <div className="text-center space-y-3">
        <div className="font-display text-4xl text-ink">Vihar Sewa</div>
        <div className="saffron-rule mx-auto" />
        <div className="text-sm text-ink-400">Loading…</div>
      </div>
    </div>
  );
}
