<template>
    <header class="header">
        <div>
            <router-link
                to="/home"
                class="logo-link"
            ><h1 class="logo"><Icon icon="logo" /></h1></router-link>

            <nav class="nav">
                <ul class="nolist">
                    <li class="nav-item">
                        <router-link
                            v-slot="{ href, isActive, navigate }"
                            to="/actors"
                        >
                            <a
                                class="nav-link"
                                :href="href"
                                :class="{ active: isActive }"
                                @click="navigate"
                            >Actors</a>
                        </router-link>
                    </li>

                    <li class="nav-item">
                        <router-link
                            v-slot="{ href, isActive, navigate }"
                            to="/networks"
                        >
                            <a
                                class="nav-link"
                                :href="href"
                                :class="{ active: isActive }"
                                @click="navigate"
                            >Networks</a>
                        </router-link>
                    </li>

                    <li class="nav-item">
                        <router-link
                            v-slot="{ href, isActive, navigate }"
                            to="/tags"
                        >
                            <a
                                class="nav-link"
                                :href="href"
                                :class="{ active: isActive }"
                                @click="navigate"
                            >Tags</a>
                        </router-link>
                    </li>
                </ul>
            </nav>
        </div>

        <Search class="search-full" />

        <v-popover
            class="search-compact"
            :open="searching"
            @show="searching = true"
            @hide="searching = false"
        >
            <button
                type="button"
                class="search-button"
            ><Icon
                icon="search"
            /></button>

            <Search
                slot="popover"
                :searching="searching"
                class="compact"
                @search="searching = false"
            />
        </v-popover>
    </header>
</template>

<script>
import Search from './search.vue';

export default {
    components: {
        Search,
    },
    data() {
        return {
            searching: false,
        };
    },
};
</script>

<style lang="scss" scoped>
@import 'theme';

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: $background;
    color: $primary;
    border-bottom: solid 1px $shadow-hint;
    font-size: 0;
}

.logo-link {
    color: inherit;
    display: inline-block;
    text-decoration: none;
}

.logo {
    display: inline-block;
    padding: 0 0 0 1rem;
    margin: 0 .5rem 0 0;

    .icon {
        width: 6rem;
        height: 1.5rem;
    }
}

.nav {
    display: inline-block;
}

.nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 1rem calc(1rem - 5px) 1rem;
    border-bottom: solid 5px transparent;
    color: $shadow;
    text-decoration: none;
    font-size: .9rem;
    font-weight: bold;
    cursor: pointer;

    .icon {
        fill: $shadow;
        margin: 0 .5rem 0 0;
    }

    &.active {
        color: $primary;
        border-bottom: solid 5px $primary;

        .icon {
            fill: $primary;
        }
    }

    &:hover:not(.active) {
        color: $primary;

        .icon {
            fill: $primary;
        }
    }
}

.search-button {
    height: 100%;
    padding: 0 1rem;
    background: none;
    border: none;
    outline: none;
    margin: .2rem 0 0 0;

    .icon {
        fill: $shadow;
    }
}

.search-compact {
    display: none;
}

@media(max-width: $breakpoint2) {
    .search-full {
        display: none;
    }

    .search-compact {
        display: flex;
    }
}

@media(max-width: $breakpoint0) {
    .nav-label {
        display: none;
    }

    .nav .nolist {
        display: flex;
    }

    .nav,
    .nav-item {
        flex-grow: 1;
    }

    .logo {
        display: none;
    }
}
</style>
