<script lang="ts">
let icon: HTMLDivElement | null;
function toggleLeftPanel(_: Event): void {
  document.querySelector('.published-container')?.classList.toggle('is-left-column-open');
}
function hideLeftPanel(_: Event): void {
  document.querySelector('.published-container')?.classList.remove('is-left-column-open');
}
</script>

<script setup lang="ts">
const { id: project, home, get } = useProject();

if(project.value !== 0 && home.value === null)
{
  await useAsyncData(`project:get:${project}`, get);
}

const toggled = ref(false);

onMounted(() => {
  icon = document.querySelector('.site-nav-bar .clickable-icon');
  icon?.removeEventListener('click', toggleLeftPanel);
  icon?.addEventListener('click', toggleLeftPanel);
});
</script>

<template>
	<div class="site-nav-bar">
		<div>
			<div class="clickable-icon">
				<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
					stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
					class="svg-icon lucide-menu">
					<line x1="4" y1="12" x2="20" y2="12"></line>
					<line x1="4" y1="6" x2="20" y2="6"></line>
					<line x1="4" y1="18" x2="20" y2="18"></line>
				</svg>
			</div>
			<div class="gapx-3 flex align-stretch">
				<NuxtLink @click="hideLeftPanel" class="site-nav-bar-text" aria-label="Accueil" :to="{ path: '/', force: true }">
					<ThemeIcon icon="logo" :width=40 :height=40 />
				</NuxtLink>
				<div class="site-nav-bar-text mobile-hidden">
					<NuxtLink aria-label="Projet"  :to="{ path: project === 0 ? `/explorer` : `/explorer/${project}${home}`, force: true }"
					:class="{'mod-active': $route.path.startsWith('/explorer')}">Projet</NuxtLink>
					<div class="arrow-down" :class="{active: toggled}" @click="toggled = !toggled"></div>
					<div class="arrow-group"  @click="toggled = false">
						<NuxtLink class="arrow-group-item" aria-label="Projets" :to="{ path: '/explorer', force: true }">Liste des projets</NuxtLink>
					</div>
				</div>
				<NuxtLink class="site-nav-bar-text mobile-hidden" aria-label="Editeur" :to="{ path: '/editing', force: true }"
					:class="{'mod-active': $route.path.startsWith('/editing')}">Editeur</NuxtLink>
			</div>
		</div>
		<div class="mobile-bigger">
			<SearchView />
		</div>
		<div class="ps-1 gapx-1 flex align-center">
			<ThemeSwitch class="mobile-hidden" />
			<NuxtLink class="site-login" :to="{ path: '/user/profile', force: true }">
				<ThemeIcon icon="user" :width=32 :height=32 />
			</NuxtLink>
		</div>
	</div>
	<div class="site-body">
        <ExplorerNavigation></ExplorerNavigation>
		<slot></slot>
	</div>
</template>