<template>
  <div class="dashboard-page bg-page">
    <template v-if="loading">
      <div class="row items-center justify-center full-width bg-surface" style="height: 80vh">
        <q-spinner-dots color="primary" />
      </div>
    </template>
    <template v-else>
      <DashboardHeaderBar :data="headerBar" />
      <DashboardSummaryInfos :data="summaryInfos" />
      <DashboardScrollAreaSchedules />
      <DashboardNextSchedules :data="nextSchedules" />
      <DashboardLastDoneSchedules :data="lastDoneSchedules" />
      <DashboardFavoriteProviders :data="favoriteProviders" />
      <DashboardProvidersClose :data="providersClose" />
    </template>
  </div>
</template>

<script setup>
import DashboardHeaderBar from 'src/components/dashboard/DashboardHeaderBar.vue';
import DashboardSummaryInfos from 'src/components/dashboard/DashboardSummaryInfos.vue';
import DashboardScrollAreaSchedules from 'src/components/dashboard/DashboardScrollAreaSchedules.vue';
import DashboardNextSchedules from 'src/components/dashboard/DashboardNextSchedules.vue';
import DashboardLastDoneSchedules from 'src/components/dashboard/DashboardLastDoneSchedules.vue';
import DashboardFavoriteProviders from 'src/components/dashboard/DashboardFavoriteProviders.vue';
import DashboardProvidersClose from 'src/components/dashboard/DashboardProvidersClose.vue';
import { onMounted, ref } from 'vue';
import { dadosDashboard } from 'src/api/dashboard';

const headerBar = ref(null);
const summaryInfos = ref(null);
const nextSchedules = ref(null);
const lastDoneSchedules = ref(null);
const favoriteProviders = ref(null);
const providersClose = ref(null);
const loading = ref(true);
onMounted( async () => {
  const response = await dadosDashboard();
  if(response) {
    headerBar.value = response.headerBar;
    summaryInfos.value = response.summaryInfos;
    nextSchedules.value = response.nextSchedules;
    lastDoneSchedules.value = response.lastDoneSchedules;
    favoriteProviders.value = response.favoriteProviders;
    providersClose.value = response.providersClose;
  }
  loading.value = false;
});
</script>

<style scoped>
.dashboard-page {
  width: 100%;
  min-height: 100%;
  box-sizing: border-box;
}
</style>
