<script setup>
import { RouterView } from "vue-router";
import Navbar from "./components/navbar/Navbar.vue";
import useUserInfoStore from "@/stores/useUserInfoStore";
import { ref, provide, onUnmounted, onMounted } from "vue";

const store = useUserInfoStore();
let isToastOpen = ref({
  open: false,
  content: "",
  status: "info",
  to: "body",
});
const cancelToastOpen = () => {
  isToastOpen.value = {
    open: false,
    content: "",
  };
};

const openToast = (status, content, to = "body", confirm = null) => {
  isToastOpen.value = {
    open: true,
    content,
    status,
    to,
    confirm,
  };
};
provide("app_toast", { openToast, cancelToastOpen });
</script>

<template>
  <Toast
    :content="isToastOpen.content"
    :open="isToastOpen.open"
    :status="isToastOpen.status"
    :cancel="cancelToastOpen"
    :confirm="isToastOpen.confirm"
    :to="isToastOpen.to"
  />
  <div v-if="store.user.token" class="min-h-screen">
    <Navbar />
    <div class="px-3 lg:px-8 w-full relative app-container " style="min-height: calc(100vh - 6rem);">
      <RouterView />
    </div>
  </div>
  <div v-else class="min-h-screen"><RouterView /></div>
</template>

<style scoped>
header {
  line-height: 1.5;
}

.logo {
  display: block;
  margin: 0 auto 1rem;
}
</style>
