<template>
  <nav class="bg-white border-b border-gray-200 sticky top-0 z-50">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
      <div class="flex justify-between items-center h-16">
        <!-- Logo/Titre -->
        <div class="flex items-center">
          <router-link to="/" class="text-2xl font-bold text-black transition-colors" style="color: black; --hover-color: #6b7280;" onmouseover="this.style.color='#6b7280'" onmouseout="this.style.color='black'">
            Patois Franco-Provençal
          </router-link>
        </div>

        <!-- Navigation principale -->
        <div class="hidden md:flex items-center space-x-8">
          <router-link
            to="/"
            class="nav-link"
            :class="{ 'active': $route.name === 'Home' }"
          >
            Accueil
          </router-link>
          <router-link
            to="/textes"
            class="nav-link"
            :class="{ 'active': $route.name === 'Texts' }"
          >
            Textes
          </router-link>
          <router-link
            to="/au-hasard"
            class="nav-link"
            :class="{ 'active': $route.name === 'Random' }"
          >
            Au Hasard
          </router-link>

          <!-- Barre de recherche -->
          <div class="relative">
            <input
              v-model="searchQuery"
              @keyup.enter="performSearch"
              type="text"
              placeholder="Rechercher..."
              class="w-64 px-4 py-2 pl-10 pr-4 text-sm border border-gray-300 rounded-full focus:outline-none focus:border-black focus:ring-1 focus:ring-black"
            />
            <div class="absolute inset-y-0 left-0 pl-3 flex items-center">
              <svg class="h-4 w-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
              </svg>
            </div>
          </div>
        </div>

        <!-- Menu mobile -->
        <div class="md:hidden">
          <button
            @click="mobileMenuOpen = !mobileMenuOpen"
            class="text-black focus:outline-none" style="color: black; --hover-color: #6b7280;" onmouseover="this.style.color='#6b7280'" onmouseout="this.style.color='black'"
          >
            <svg class="h-6 w-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
            </svg>
          </button>
        </div>
      </div>

      <!-- Menu mobile déplié -->
      <div v-if="mobileMenuOpen" class="md:hidden border-t border-gray-200 pt-4 pb-4">
        <div class="flex flex-col space-y-4">
          <router-link to="/" class="nav-link-mobile">Accueil</router-link>
          <router-link to="/textes" class="nav-link-mobile">Textes</router-link>
          <router-link to="/au-hasard" class="nav-link-mobile">Au Hasard</router-link>
          <div class="pt-2">
            <input
              v-model="searchQuery"
              @keyup.enter="performSearch"
              type="text"
              placeholder="Rechercher..."
              class="w-full px-4 py-2 text-sm border border-gray-300 rounded-full focus:outline-none focus:border-black"
            />
          </div>
        </div>
      </div>
    </div>
  </nav>
</template>

<script>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

export default {
  name: 'NavigationBar',
  setup() {
    const router = useRouter()
    const searchQuery = ref('')
    const mobileMenuOpen = ref(false)

    const performSearch = () => {
      if (searchQuery.value.trim()) {
        router.push({
          name: 'Texts',
          query: { search: searchQuery.value.trim() }
        })
        mobileMenuOpen.value = false
      }
    }

    return {
      searchQuery,
      mobileMenuOpen,
      performSearch
    }
  }
}
</script>

<style scoped>
.nav-link {
  @apply font-medium transition-colors duration-200 pb-1;
  color: #6b7280;
}

.nav-link:hover {
  color: black;
}

.nav-link.active {
  @apply text-black border-b-2 border-black;
}

.nav-link-mobile {
  @apply font-medium transition-colors duration-200 py-2;
  color: #6b7280;
}

.nav-link-mobile:hover {
  color: black;
}
</style>
