<template>
	<div class="container">
		<header class="header">
			<a href="/">
				<h1 class="title">
					<div
						class="logo"
						v-html="logo"
					/>shack
				</h1>
			</a>

			<div class="search">
				<input
					type="search"
					class="input"
					placeholder="Search the shack"
				>
			</div>

			<span
				v-if="me"
				class="userpanel"
				@click="logout"
			>{{ me.username }}</span>
		</header>

		<div class="content-container">
			<slot />
			<footer class="footer">shack {{ version }}</footer>
		</div>
	</div>
</template>

<script setup>
import logo from '../assets/img/logo.svg?raw'; // eslint-disable-line import/no-unresolved
import { del } from '../assets/js/api';
import { navigate } from '../assets/js/navigate';
import { usePageContext } from './usePageContext';

const { me } = usePageContext();
const version = CLIENT_VERSION;

async function logout() {
	await del('/session');
	navigate('/account/login');
}
</script>

<style>
.logo svg {
    height: 100%;
    width: auto;
}
</style>

<style scoped>
.container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--background-dark-10);
}

.content-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
	overflow-y: auto;
}

.header {
    display: flex;
	flex-shrink: 0;
    background: var(--background);
    box-shadow: 0 0 3px var(--shadow-weak-10);
	overflow: hidden;
}

.logo {
	width: auto;
    height: 1.75rem;
    fill: var(--primary);
    margin: .75rem .5rem 1rem 1rem;
}

.title {
    font-size: 0;
}

.search {
    display: flex;
    flex-grow: 1;
    align-items: center;
    margin: 0 1rem;

    .input {
	flex-grow: 1;
    }
}

.userpanel {
	display: flex;
	align-items: center;
	padding: 1rem;
	font-weight: bold;
}

.footer {
	padding: .5rem 1rem;
	color: var(--shadow);
	text-align: center;
}
</style>
