<template>
  <div class="app-layout">
    <header class="app-header">
      <div class="container header-inner">
        <NuxtLink to="/" class="logo">SejeteralO</NuxtLink>
        <nav class="header-nav">
          <NuxtLink to="/">Accueil</NuxtLink>
          <template v-if="authStore.isAuthenticated">
            <NuxtLink v-if="authStore.isSuperAdmin" to="/admin">Super Admin</NuxtLink>
            <NuxtLink
              v-else-if="authStore.isAdmin && authStore.communeSlug"
              :to="`/admin/communes/${authStore.communeSlug}`"
            >
              Gestion commune
            </NuxtLink>
            <button class="btn btn-secondary btn-sm" @click="logout">Déconnexion</button>
          </template>
        </nav>
      </div>
    </header>
    <main class="app-main container">
      <slot />
    </main>
    <footer class="app-footer">
      <div class="container">
        SejeteralO — Outil de démocratie participative pour la tarification de l'eau
      </div>
    </footer>
  </div>
</template>

<script setup lang="ts">
const authStore = useAuthStore()
const router = useRouter()

function logout() {
  authStore.logout()
  router.push('/')
}
</script>

<style scoped>
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
}

.logo:hover {
  text-decoration: none;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8rem;
}

.app-main {
  flex: 1;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.app-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 1rem 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
</style>
