---
import { FaGithub, FaLinkedin, FaEnvelope } from "react-icons/fa";

const navItems = [
  { label: "About", href: "#about" },
  { label: "Work", href: "#work" },
  { label: "Blog", href: "#blog" },
  { label: "Contact", href: "#contact" }
];
---

<div class="mobile-menu-container">
  <button 
    id="menu-toggle" 
    class="p-2 theme-accent rounded-xl flex flex-col justify-center items-center gap-1.5 border theme-border overflow-hidden"
    aria-label="Toggle mobile menu"
    aria-expanded="false"
    aria-controls="mobile-nav"
  >
    <span class="block w-5 h-0.5 theme-primary transition-all duration-300 transform bar-1"></span>
    <span class="block w-5 h-0.5 theme-primary transition-all duration-300 transform bar-2"></span>
    <span class="block w-5 h-0.5 theme-primary transition-all duration-300 transform bar-3"></span>
  </button>
  
  <div 
    id="mobile-nav" 
    class="fixed inset-0 z-50 invisible opacity-0 flex flex-col justify-start items-stretch pt-24 nav-glass transition-all duration-300 transform translate-x-full"
    aria-hidden="true"
  >
    <nav class="px-6 sm:px-8 pt-6 pb-12 flex flex-col gap-4">
      {navItems.map((item) => (
        <a 
          href={item.href} 
          class="mobile-nav-item py-3 px-6 theme-secondary text-lg font-medium rounded-xl theme-accent border theme-border transition-all duration-300 hover:theme-primary"
          aria-label={`Go to ${item.label} section`}
        >
          {item.label}
        </a>
      ))}
    </nav>
    
    <div class="px-6 sm:px-8 py-6 mt-auto border-t theme-border flex flex-col gap-5">
      <a 
        href="mailto:jleibl@proton.me" 
        class="flex items-center justify-center gap-2 py-3 bg-white/10 text-white rounded-xl hover:bg-white/15 transition-all duration-300 shadow-sm"
        aria-label="Contact me via email"
      >
        <span class="p-1 rounded-lg bg-white/5">
          <FaEnvelope className="w-5 h-5" />
        </span>
        <span class="text-base font-medium font-['Instrument_Sans']">Contact Me</span>
      </a>
      
      <div class="flex gap-4 justify-center mt-2">
        <a 
          href="https://github.com/AtomicWasTaken" 
          target="_blank" 
          rel="noopener noreferrer"
          aria-label="GitHub profile"
          class="p-3 rounded-xl bg-black/10 hover:bg-black/15 transition-all"
        >
          <FaGithub className="w-5 h-5 text-white" />
        </a>
        <a 
          href="https://www.linkedin.com/in/janmarlonleibl/" 
          target="_blank" 
          rel="noopener noreferrer"
          aria-label="LinkedIn profile"
          class="p-3 rounded-xl bg-black/10 hover:bg-black/15 transition-all"
        >
          <FaLinkedin className="w-5 h-5 text-white" />
        </a>
      </div>
    </div>
  </div>
</div>

<script>
  document.addEventListener('DOMContentLoaded', () => {
    const menuToggle = document.getElementById('menu-toggle');
    const mobileNav = document.getElementById('mobile-nav');
    const mobileNavItems = document.querySelectorAll('.mobile-nav-item');
    let isMenuOpen = false;
    
    function toggleMenu() {
      isMenuOpen = !isMenuOpen;
      
      if (menuToggle) {
        menuToggle.setAttribute('aria-expanded', isMenuOpen.toString());
        menuToggle.classList.toggle('active', isMenuOpen);
      }
      
      if (mobileNav) {
        mobileNav.setAttribute('aria-hidden', (!isMenuOpen).toString());
        
        if (isMenuOpen) {
          mobileNav.classList.remove('invisible', 'opacity-0', 'translate-x-full');
          mobileNav.classList.add('opacity-100', 'translate-x-0');
          document.body.style.overflow = 'hidden';
          
          mobileNavItems.forEach((item, index) => {
            setTimeout(() => {
              item.classList.add('show');
            }, 100 + (index * 50));
          });
        } else {
          mobileNav.classList.remove('opacity-100', 'translate-x-0');
          mobileNav.classList.add('opacity-0', 'translate-x-full');
          document.body.style.overflow = '';
          
          setTimeout(() => {
            if (!isMenuOpen) {
              mobileNav.classList.add('invisible');
              mobileNavItems.forEach(item => {
                item.classList.remove('show');
              });
            }
          }, 300);
        }
      }
    }
    
    menuToggle?.addEventListener('click', toggleMenu);
    
    mobileNavItems.forEach(item => {
      item.addEventListener('click', () => {
        toggleMenu();
      });
    });
    
    document.addEventListener('click', (e) => {
      if (isMenuOpen && mobileNav && e.target instanceof Node && !mobileNav.contains(e.target) && e.target !== menuToggle) {
        toggleMenu();
      }
    });
    
    document.addEventListener('keydown', (e) => {
      if (isMenuOpen && e.key === 'Escape') {
        toggleMenu();
      }
    });
  });
</script>

<style>
  #menu-toggle.active .bar-1 {
    transform: translateY(8px) rotate(45deg);
  }
  
  #menu-toggle.active .bar-2 {
    opacity: 0;
  }
  
  #menu-toggle.active .bar-3 {
    transform: translateY(-8px) rotate(-45deg);
  }
  
  .mobile-nav-item {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s ease, color 0.3s ease;
  }
  
  .mobile-nav-item.show {
    opacity: 1;
    transform: translateY(0);
  }
</style> 