<?php
// includes/sidebar.php - Side navigation for desktop + mobile
$user = $user ?? currentUser();
$initials = $user ? e(strtoupper(substr($user['full_name'], 0, 2))) : 'JP';
$currentPage = $currentPage ?? '';
?>
<!-- DESKTOP SIDEBAR -->
<aside class="sidebar" id="sidebar">
  <div class="sidebar-logo">
    <div class="logo-circle-sm">
      <img src="/space_php/assets/img/logo.svg" alt="SPACE" width="28">
    </div>
    <span class="sidebar-brand">SPACE</span>
  </div>

  <nav class="sidebar-nav">
    <div class="nav-section-label">ORGANIZATION</div>
    <a href="/space_php/dashboard.php" class="nav-link <?= $currentPage === 'dashboard' ? 'active' : '' ?>">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>
      Dashboard
    </a>
    <a href="/space_php/notes.php" class="nav-link <?= $currentPage === 'notes' ? 'active' : '' ?>">
      <svg viewBox="0 0 20 20" fill="currentColor"><path d="M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4z"/></svg>
      Notes
    </a>
    <a href="/space_php/tasks.php" class="nav-link <?= $currentPage === 'tasks' ? 'active' : '' ?>">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"/></svg>
      Tasks
    </a>

    <div class="nav-section-label">STUDY</div>
    <a href="/space_php/ai.php" class="nav-link <?= $currentPage === 'ai' ? 'active' : '' ?>">
      <svg viewBox="0 0 24 24" fill="none" stroke="#ec4899" stroke-width="2" stroke-linecap="round"><path d="M12 2a10 10 0 100 20"/><path d="M22 12A10 10 0 0012 2v10z"/></svg>
      Astro AI
    </a>

    <div class="nav-section-label">TIME</div>
    <a href="/space_php/pomodoro.php" class="nav-link <?= $currentPage === 'pomodoro' ? 'active' : '' ?>">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"/><path stroke-linecap="round" d="M12 7v5l3 3"/></svg>
      Pomodoro
    </a>
    <a href="/space_php/calendar.php" class="nav-link <?= $currentPage === 'calendar' ? 'active' : '' ?>">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
      Calendar
    </a>
  </nav>

  <div class="sidebar-profile">
    <div class="profile-avatar-sm"><?= $initials ?></div>
    <div class="profile-info">
      <span class="profile-name-sm"><?= e($user['full_name'] ?? 'User') ?></span>
      <span class="profile-course-sm"><?= e($user['course'] ?? '') ?></span>
    </div>
    <a href="/space_php/logout.php" class="logout-btn" title="Logout">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/></svg>
    </a>
  </div>
</aside>

<!-- MOBILE OVERLAY MENU -->
<div class="menu-overlay" id="menu-overlay"></div>
<div class="side-menu" id="side-menu">
  <div class="menu-header">
    <div class="menu-header-left">
      <img src="/space_php/assets/img/logo.svg" alt="S" width="26">
      <span>TOOLS</span>
    </div>
    <button class="menu-close-btn" id="menu-close-btn">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="20"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
    </button>
  </div>
  <div class="menu-content">
    <div class="menu-group">
      <div class="group-title">ORGANIZATION</div>
      <a href="/space_php/dashboard.php" class="menu-item">Dashboard</a>
      <a href="/space_php/notes.php" class="menu-item">Notes</a>
      <a href="/space_php/tasks.php" class="menu-item">Tasks</a>
    </div>
    <div class="menu-group">
      <div class="group-title">STUDY</div>
      <a href="/space_php/ai.php" class="menu-item">AI Chat (Astro)</a>
    </div>
    <div class="menu-group">
      <div class="group-title">TIME MANAGEMENT</div>
      <a href="/space_php/pomodoro.php" class="menu-item">POMODORO Timer</a>
      <a href="/space_php/calendar.php" class="menu-item">Calendar of Activities</a>
    </div>
  </div>
  <div class="menu-profile">
    <div class="profile-avatar"><?= $initials ?></div>
    <div class="profile-details">
      <span class="profile-name"><?= e($user['full_name'] ?? 'User') ?></span>
      <span class="profile-course"><?= e(($user['course'] ?? '') . ' · ' . ($user['school'] ?? '')) ?></span>
      <a href="/space_php/logout.php" style="font-size:9px;color:#888;text-decoration:none;">Logout</a>
    </div>
  </div>
</div>
