<template>
  <div>
    <!-- Menu Overlay -->
    <div
      class="slide-menu-overlay"
      :class="{ open: isOpen }"
      @click="closeMenu"
    ></div>

    <!-- Slide Menu -->
    <nav class="slide-menu" :class="{ open: isOpen }">
      <!-- Navigation Section -->
      <div class="menu-section">
        <h3 class="menu-title">Navigare</h3>
        <ul class="menu-list">
          <li class="menu-item">
            <router-link
              to="/reports/dashboard"
              class="menu-link"
              :class="{ active: $route.name === 'Dashboard' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-home"></i>
              <span>Dashboard</span>
            </router-link>
          </li>
          <li class="menu-item">
            <router-link
              to="/reports/invoices"
              class="menu-link"
              :class="{ active: $route.name === 'Invoices' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-file"></i>
              <span>Facturi</span>
            </router-link>
          </li>
          <li class="menu-item">
            <router-link
              to="/reports/bank-cash"
              class="menu-link"
              :class="{ active: $route.name === 'BankCash' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-money-bill"></i>
              <span>Casa și Banca</span>
            </router-link>
          </li>
          <li class="menu-item">
            <router-link
              to="/reports/trial-balance"
              class="menu-link"
              :class="{ active: $route.name === 'TrialBalance' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-calculator"></i>
              <span>Balanță de Verificare</span>
            </router-link>
          </li>
        </ul>
      </div>

      <!-- System Section -->
      <div class="menu-section">
        <h3 class="menu-title">Sistem</h3>
        <ul class="menu-list">
          <li class="menu-item">
            <router-link
              to="/reports/cache-stats"
              class="menu-link"
              :class="{ active: $route.name === 'CacheStats' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-chart-bar"></i>
              <span>Statistici cache</span>
            </router-link>
          </li>
          <li class="menu-item">
            <router-link
              to="/reports/server-logs"
              class="menu-link"
              :class="{ active: $route.name === 'ServerLogs' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-file-edit"></i>
              <span>Server Logs</span>
            </router-link>
          </li>
        </ul>
      </div>

      <!-- Profile Section (at bottom) -->
      <div class="menu-section menu-profile">
        <div class="profile-info">
          <i class="pi pi-user"></i>
          <span>{{ currentUser?.username || 'Utilizator' }}</span>
        </div>
        <ul class="menu-list">
          <li class="menu-item">
            <router-link
              to="/reports/telegram"
              class="menu-link"
              :class="{ active: $route.name === 'Telegram' }"
              @click="closeMenu"
            >
              <i class="menu-icon pi pi-telegram"></i>
              <span>Telegram Bot</span>
            </router-link>
          </li>
          <li class="menu-item">
            <a href="#" class="menu-link" @click.prevent="handleLogout">
              <i class="menu-icon pi pi-sign-out"></i>
              <span>Deconectare</span>
            </a>
          </li>
        </ul>
      </div>
    </nav>
  </div>
</template>

<script>
import { computed } from "vue";
import { useRouter } from "vue-router";
import { useAuthStore } from "@reports/stores/sharedStores";

export default {
  name: "HamburgerMenu",
  props: {
    isOpen: {
      type: Boolean,
      default: false,
    },
  },
  emits: ["close"],
  setup(props, { emit }) {
    console.log('[HamburgerMenu] Component loaded - Server Logs should be visible in Sistem section');

    const router = useRouter();
    const authStore = useAuthStore();

    const currentUser = computed(() => authStore.currentUser);

    const closeMenu = () => {
      emit("close");
    };

    const handleLogout = async () => {
      try {
        authStore.logout();
        closeMenu();
        await router.push("/login");
      } catch (error) {
        console.error("Logout error:", error);
      }
    };

    return {
      currentUser,
      closeMenu,
      handleLogout,
    };
  },
};
</script>
