<script setup lang="ts">
import { Link } from "@inertiajs/vue3";
import { usePage } from '@inertiajs/vue3'
import type { SharedProps } from '@/Types/types'
import { ref } from 'vue'

const props = usePage<SharedProps>().props
const menuOpen = ref(false)
</script>

<template>
    <header class="glass">
        <Link href="/" class="brand">FlightsGoneBy</Link>

        <!-- Desktop nav -->
        <nav class="nav-desktop">
            <template v-if="!props.auth.user">
                <Link :href="route('login')" class="nav-link">Log In</Link>
                <Link :href="route('register')" class="nav-link nav-link--highlight">Register</Link>
            </template>
            <span v-else class="nav-link nav-link--greeting"><Link :href="route('dashboard')">Welcome, {{ props.auth.user.name }}</Link></span>
        </nav>

        <!-- Hamburger (mobile only) -->
        <button class="hamburger" :class="{ open: menuOpen }" @click="menuOpen = !menuOpen" aria-label="Toggle menu">
            <span /><span /><span />
        </button>

        <!-- Mobile drawer -->
        <Transition name="slide">
            <nav v-if="menuOpen" class="nav-mobile" @click="menuOpen = false">
                <template v-if="!props.auth.user">
                    <Link :href="route('login')" class="nav-link">Log In</Link>
                    <Link :href="route('register')" class="nav-link nav-link--highlight">Register</Link>
                </template>
                <span v-else class="nav-link nav-link--greeting"><Link :href="route('dashboard')">Welcome, {{ props.auth.user.name }}</Link></span>
            </nav>
        </Transition>
    </header>
</template>

<style scoped>
header {
    display: flex;
    align-items: center;
    flex: 0 0 5dvh;
    min-height: 48px;
    padding: 0 1.25rem;
    position: relative;
    z-index: 10;
}

.brand {
    margin-right: auto;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--accent);
    text-decoration: none;
}

/* Shared nav link base */
.nav-link {
    display: inline-flex;
    align-items: center;
    padding: 0.3em 0.75em;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-decoration: none;
    color: var(--text);
    border-radius: 4px;
    transition: color 0.15s ease, background 0.15s ease;
}

.nav-link:visited {
    color: var(--text);
}

.nav-link:hover {
    color: var(--accent);
    background: rgba(56, 189, 248, 0.07);
}

/* Highlighted CTA-style link */
.nav-link--highlight {
    border: 1px solid rgba(56, 189, 248, 0.35);
    color: var(--accent);
}

.nav-link--highlight:visited {
    color: var(--accent);
}

.nav-link--highlight:hover {
    background: rgba(56, 189, 248, 0.12);
}

.nav-link--greeting {
    opacity: 0.7;
    font-size: 0.85rem;
    cursor: default;
}

/* Desktop nav */
.nav-desktop {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Hamburger */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 1.5px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
    transform-origin: center;
}

.hamburger.open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

/* Mobile nav drawer */
.nav-mobile {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid rgba(56, 189, 248, 0.1);
    z-index: 20;
}

.slide-enter-from,
.slide-leave-to {
    opacity: 0;
    transform: translateY(-6px);
}

.slide-enter-active,
.slide-leave-active {
    transition: opacity 0.15s ease, transform 0.15s ease;
}

@media (max-width: 600px) {
    .nav-desktop { display: none; }
    .hamburger { display: flex; }
}
</style>
