<script lang="ts">
	import Textarea from '../components/textarea.svelte';
	import Dashboard from '../components/dashboard.svelte';
	import { db, deleteShortformList, type Shortform } from '../db/main';
	import { importShortforms } from '../db/import';

	import { Button } from '$lib/components/ui/button';

	import { hotkeys } from '../modules/keyboard';
	let cache: Array<Shortform>;
	let showDashboard: boolean = true;
	db.shortforms
		.toArray()
		.then((shortforms) => {
			cache = shortforms;
		})
		.catch((err) => {
			console.error(err);
		});
	importShortforms([]);
	const deleteDefaultShortforms = () => {
		deleteShortformList(890324);
		cache = [];
	};
	const handleHotkeys = (e: KeyboardEvent) => {
		hotkeys.get(e.key)?.action(e);
	};
</script>
<svelte:head>
<title>SKRIVERT</title>
</svelte:head>
<svelte:window on:keydown={handleHotkeys} />

<div class="h-dvh w-full overflow-hidden" role="application">
	<div class="h-full">
		<Textarea />
		<Dashboard open={showDashboard} />
	<!--	<Button variant="destructive" on:click={deleteDefaultShortforms}>Ta bort standardlista</Button>-->
	</div>
</div>
