// components/MyUserButton.tsx

'use client';

import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';

const MyUserButton = () => {
  const [isLoggedIn, setIsLoggedIn] = useState(false);
  const router = useRouter();

  useEffect(() => {
    // Check if the user is logged in (assuming token is stored in localStorage or cookies)
    const token = localStorage.getItem('access_token'); // Or use cookies if you store the token there
    if (token) {
      setIsLoggedIn(true);
    }
  }, []);

  const handleNavigation = () => {
    if (isLoggedIn) {
      router.push('/dashboard');
    } else {
      router.push('/user/register');
    }
  };

  return (
    <button
      onClick={handleNavigation} className='hover:text-gray-400'>
      My User
    </button>
  );
};

export default MyUserButton;
