<script lang="ts">
	import Header from "$lib/components/Header.svelte";
	import Router from "$lib/router/Router.svelte";
	import { Close } from "$wails/main/App";
	import { Toaster } from "svelte-sonner";
	import * as srouter from "svelte-spa-router";
	import { location } from "svelte-spa-router";

	const energyLocRegex = /^\/(?:Energy)?(?!Weight)/;
	const weightLocRegex = /^\/(?:Weight)(?!Energy)/;
	function keyDown(event: KeyboardEvent) {
		if (event.ctrlKey && event.key == "r") {
			window.location.reload();
		}
		if (event.ctrlKey && event.key == "w") {
			Close();
		}
		if (event.ctrlKey && event.key == "Tab") {
			if (energyLocRegex.test($location)) {
				srouter.replace($location.replace(energyLocRegex, "/Weight"));
			} else if (weightLocRegex.test($location)) {
				srouter.replace($location.replace(weightLocRegex, "/Energy"));
			}
		}
	}
</script>

<svelte:window on:keydown={keyDown} />

<Toaster />
<template>
	<Header />
	<main class="flex-1">
		<Router />
	</main>
</template>
