<template>
  <div :class="showShell ? 'app-shell' : 'layout layout-login'">
    <AppSidebar v-if="showShell" />
    <main :class="showShell ? 'app-main' : ''">
      <RouterView />
    </main>
    <HostActionLogStack v-if="showShell" />
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted } from "vue";
import { useRoute } from "vue-router";
import { getToken } from "./api";
import AppSidebar from "./components/AppSidebar.vue";
import HostActionLogStack from "./components/HostActionLogStack.vue";
import { refreshSessionRole } from "./router";

const route = useRoute();
const publicLayout = computed(() => route.path === "/login" || route.meta.standalone === true);
const showShell = computed(() => !publicLayout.value && !!getToken());

onMounted(() => {
  if (getToken()) {
    void refreshSessionRole();
  }
});
</script>
