'use client';

import { useAuthStore } from '@/stores/auth.store';
import { useEffect } from 'react';

export default function Home() {
  const { user, isAuthenticated, isLoading, fetchUser } = useAuthStore();

  useEffect(() => {
    if (!isAuthenticated && !isLoading) {
      fetchUser();
    }
  }, [isAuthenticated, isLoading, fetchUser]);

  if (isLoading) {
    return <div className="p-8">Loading...</div>;
  }

  return (
    <main className="min-h-screen p-8">
      <h1 className="text-4xl font-bold mb-4">GoodGo Platform</h1>
      {isAuthenticated && user ? (
        <div>
          <p>Welcome, {user.email}!</p>
          <p>Role: {user.role}</p>
        </div>
      ) : (
        <div>
          <p>Please log in to continue.</p>
        </div>
      )}
    </main>
  );
}
