'use client';

import React, { useEffect, useState } from 'react';
import { account } from '../../lib/appwrite'; // adjust path as needed

const RegisterStudent = () => {
  const [user, setUser] = useState(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    const fetchUser = async () => {
      try {
        const userData = await account.get();
        setUser(userData);
      } catch (error) {
        console.error("Error fetching user:", error);
      } finally {
        setLoading(false);
      }
    };

    fetchUser();
  }, []);

  return (
    <nav className="flex justify-between p-4 bg-white shadow">
      <div>MyApp</div>
      <div>
        {!loading && user ? (
          <div className="flex items-center gap-3">
            <span>{user.name}</span>
            <span className="text-sm text-gray-500">{user.email}</span>
          </div>
        ) : (
          <span>Loading...</span>
        )}
      </div>
    </nav>
  );
};

export default RegisterStudent;
