<script lang="typescript" context="module">
	import type { AppSession, PageData, PreloadContext } from "src/utils/session";
	import { goto } from "@sapper/app";

	export async function preload(this: PreloadContext, { path }: PageData, session: AppSession) {
		if (path.startsWith("/login/")) {
			if (session?.userId) {
				return this.redirect(302, "/");
			} else {
				return {};
			}
		}
		if (path != "/" && !session?.userId) {
			return this.redirect(302, "/");
		}
		return {};
	}
</script>

<script lang="typescript">
	import { stores } from "@sapper/app";
	const { page } = stores();

	let path: string;
	$: path = $page.path.slice(1);
</script>

<style global>
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

* {
	@apply font-sans;
}
</style>

<svelte:head>
	<title>
		{path ? path.charAt(0).toUpperCase() + path.slice(1) : "Index"}
	</title>
</svelte:head>


<div class="flex items-center justify-center bg-gray-900 h-screen w-screen">
	<slot />	
</div>