<script setup lang="ts">
import ContentManager from './components/managers/ContentManager.vue';
import ToastManager from './components/managers/ToastManager.vue';
import WindowManager from './components/managers/WindowManager.vue';

import { CreateWindow } from '@/services/Windows'
import { GetUser, HasAdmin } from './services/User';
import TooltipManager from './components/managers/TooltipManager.vue';
import ContextMenuManager from './components/managers/ContextMenuManager.vue';
import { useCampaignService } from './services/Campaign';

const { RestoreCampaign } = useCampaignService();

async function start(){
  if(GetUser()){
    const restoredCampaign = await RestoreCampaign();
    if (!restoredCampaign) {
      CreateWindow('main_menu');
    }
    return;
  }

  if(await HasAdmin()){
    CreateWindow('login');
  } else {
    CreateWindow('register', {firstTime: true});
  }
  // DisplayToast('aqua', 'All plugins loaded successfully');
}

useHead({
  title: 'Dragonroll',
  meta: [
    { name: 'description', content: 'Dragonroll is a free and open-source tabletop RPG virtual tabletop. It allows you to play your favorite pen-and-paper RPGs online with your friends, with features like character sheets, dice rolling, maps, tokens, and more.' },
    { name: 'keywords', content: 'virtual tabletop, vtt, online rpg, pen-and-paper rpg, dungeons and dragons, pathfinder, roll20 alternative' },
    { name: 'author', content: 'Aran Roig' },
  ],
})

onMounted(() => {
  setupTheme();
  setTheme('dark');
  start();
})
</script>

<template>
  <div class="viewer">
    <ToastManager></ToastManager>
    <TooltipManager></TooltipManager>
    <ContextMenuManager></ContextMenuManager>
    <WindowManager></WindowManager>
    <ContentManager></ContentManager>
    <!-- Managers -->
  </div>
</template>

<style scoped>
.viewer {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
}
</style>
