import React, { useContext } from 'react';
import { Link } from 'react-router-dom';
import { AuthContext } from '../context/AuthContext';

const Navbar = () => {
  const { auth, logout } = useContext(AuthContext);

  const authLinks = (
    <ul className="navbar-nav ml-auto">
      <li className="nav-item">
        <Link className="nav-link" to="/map" data-testid="nav-map">Map</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/tasks" data-testid="nav-tasks">Tasks</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/feed" data-testid="nav-feed">Feed</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/events" data-testid="nav-events">Events</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/rewards" data-testid="nav-rewards">Rewards</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/leaderboard" data-testid="nav-leaderboard">Leaderboard</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/analytics" data-testid="nav-analytics">Analytics</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/profile" data-testid="nav-profile">Profile</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/premium" data-testid="nav-premium">Premium</Link>
      </li>
      <li className="nav-item">
        <a onClick={logout} href="#!" className="nav-link" data-testid="logout-button">Logout</a>
      </li>
    </ul>
  );

  const guestLinks = (
    <ul className="navbar-nav ml-auto">
      <li className="nav-item">
        <Link className="nav-link" to="/register" data-testid="nav-register">Register</Link>
      </li>
      <li className="nav-item">
        <Link className="nav-link" to="/login" data-testid="nav-login">Login</Link>
      </li>
    </ul>
  );

  return (
    <nav className="navbar navbar-expand-sm navbar-dark bg-dark mb-4" data-testid="navbar">
      <div className="container">
        <Link className="navbar-brand" to="/" data-testid="navbar-brand">Adopt-a-Street</Link>
        <div className="collapse navbar-collapse">
          {auth.isAuthenticated ? authLinks : guestLinks}
        </div>
      </div>
    </nav>
  );
};

export default Navbar;
