<script setup>
import Menu from "~/navigation/index.js";
import RSItem from "~/components/layouts/sidemenu/Item.vue";

// Use site settings composable
const { siteSettings } = useSiteSettings();

// Add computed to ensure logo reactivity
const currentLogo = computed(() => {
  return siteSettings.value.siteLogo && siteSettings.value.siteLogo.trim() !== '' 
    ? siteSettings.value.siteLogo 
    : '/assets/img/logo/logo-imigresen.svg';
});

// const menuItem = Menu;

const props = defineProps({
  menuItem: {
    type: Array,
    default: () => Menu,
    required: false,
  },
});

onMounted(() => {
  try {
    const el = document.querySelector(".active-menu").closest(".menu-content");
    const elParent = el.parentElement.parentElement;

    if (elParent) {
      elParent.classList.remove("hide");
      elParent.querySelector("a").classList.add("nav-open");
    }
    if (el) el.classList.remove("hide");
  } catch (e) {
    // console.log(e);
    return;
  }
});
</script>

<template>
  <div class="vertical-menu">
    <div class="py-2 px-4 bg-[rgb(var(--header))]">
      <nuxt-link to="/">
        <div class="flex flex-auto gap-3 justify-center items-center h-[48px]">
          <img
            :src="currentLogo"
            :alt="siteSettings.siteName || 'Site Logo'"
            class="h-8 block"
            @error="$event.target.src = '/assets/img/logo/logo-imigresen.svg'"
          />
          <span v-if="siteSettings.showSiteNameInHeader"
                class="text-xs" 
                :style="{ fontSize: Math.max(10, (siteSettings.siteNameFontSize || 18) * 0.65) + 'px' }">
            {{ siteSettings.siteName || 'Jabatan Imigresen Malaysia' }}
          </span>
        </div>
      </nuxt-link>
    </div>
    <NuxtScrollbar
      class="flex flex-col justify-between my-6"
      style="max-height: 82dvh"
    >
      <RSItem :items="menuItem"></RSItem>
    </NuxtScrollbar>
  </div>
</template>
