import React from 'react';
import { Link, useLocation } from 'react-router-dom';
import { useAuth0 } from '@auth0/auth0-react';
import './Navigation.css';

function Navigation() {
  const { user, isAuthenticated, isLoading, loginWithRedirect, logout } = useAuth0();
  const location = useLocation();

  const handleLogin = () => loginWithRedirect();
  const handleLogout = () => logout({ returnTo: window.location.origin });

  const isActive = (path) => location.pathname === path;

  if (isLoading) {
    return (
      <nav className="navigation">
        <div className="nav-brand">
          <Link to="/">Container Mom</Link>
        </div>
        <div className="nav-loading">Loading...</div>
      </nav>
    );
  }

  return (
    <nav className="navigation">
      <div className="nav-brand">
        <Link to="/">Container Mom</Link>
      </div>
      
      <div className="nav-links">
        {user && (
          <>
            <Link 
              to="/deployments" 
              className={`nav-link ${isActive('/deployments') ? 'active' : ''}`}
            >
              Deployments
            </Link>
          </>
        )}
      </div>

      {user ? (
        <div className="nav-user">
          <div className="user-menu">
            <button className="user-button">
              {user.email}
              <span className="arrow">▼</span>
            </button>
            <div className="dropdown-menu">
              <Link to="/profile">Profile</Link>
              <button onClick={handleLogout}>
                Log Out
              </button>
            </div>
          </div>
        </div>
      ) : (
        <div className="nav-auth">
          <button onClick={handleLogin} className="login-btn">
            Log In
          </button>
          <button 
            onClick={handleLogin} 
            className="signup-btn"
          >
            Sign Up
          </button>
        </div>
      )}
    </nav>
  );
}

export default Navigation; 