<script setup>


import MainNav from "~/components/MainNav.vue";
import dayjs from "dayjs";
import {useProfileStore} from "~/stores/profile.js";
import {useCapacitor} from "../composables/useCapacitor.js";

const dataStore = useDataStore()
const profileStore = useProfileStore()
const colorMode = useColorMode()
const { isHelpSlideoverOpen } = useDashboard()
const supabase = useSupabaseClient()
const router = useRouter()
const route = useRoute()
const auth = useAuthStore()

//profileStore.initializeData((await supabase.auth.getUser()).data.user.id)

const month = dayjs().format("MM")

const actions = [
  {
    id: 'new-customer',
    label: 'Kunde hinzufügen',
    icon: 'i-heroicons-user-group',
    to: "/customers/create" ,
  },
  {
    id: 'new-vendor',
    label: 'Lieferant hinzufügen',
    icon: 'i-heroicons-truck',
    to: "/vendors/create" ,
  },
  {
    id: 'new-contact',
    label: 'Ansprechpartner hinzufügen',
    icon: 'i-heroicons-user-group',
    to: "/contacts/create" ,
  },
  {
    id: 'new-task',
    label: 'Aufgabe hinzufügen',
    icon: 'i-heroicons-rectangle-stack',
    to: "/tasks/create" ,
  },
  {
    id: 'new-plant',
    label: 'Objekt hinzufügen',
    icon: 'i-heroicons-clipboard-document',
    to: "/plants/create" ,
  },
  {
    id: 'new-product',
    label: 'Artikel hinzufügen',
    icon: 'i-heroicons-puzzle-piece',
    to: "/products/create" ,
  },
  {
    id: 'new-project',
    label: 'Projekt hinzufügen',
    icon: 'i-heroicons-clipboard-document-check',
    to: "/projects/create" ,
  }
]


const footerLinks = [/*{
  label: 'Invite people',
  icon: 'i-heroicons-plus',
  to: '/settings/members'
}, */{
  label: 'Hilfe & Info',
  icon: 'i-heroicons-question-mark-circle',
  click: () => isHelpSlideoverOpen.value = true
}]

</script>

<template>
  <div v-if="!auth.loading">
    <div v-if="auth.activeTenantData?.locked === 'maintenance_tenant'">
      <UContainer class="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900">
        <UCard class="max-w-lg text-center p-10">
          <UColorModeImage
              light="/Logo_Hell_Weihnachten.png"
              dark="/Logo_Dunkel_Weihnachten.png"
              class=" mx-auto my-10"
              v-if="month === '12'"
          />
          <UColorModeImage
              light="/Logo.png"
              dark="/Logo_Dark.png"
              class="mx-auto my-10"
              v-else
          />
          <div class="flex justify-center mb-6">
            <UIcon name="i-heroicons-exclamation-triangle-solid" class="w-16 h-16 text-yellow-500" />
          </div>

          <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-4">
            Wartungsarbeiten
          </h1>
          <p class="text-gray-600 dark:text-gray-300 mb-8">
            Dieser FEDEO Mandant wird derzeit gewartet. Bitte versuche es in einigen Minuten erneut oder verwende einen anderen Mandanten.
          </p>
          <div class="mx-auto text-left flex flex-row justify-between my-3" v-for="tenant in auth.tenants">
            {{tenant.name}}
            <UButton
                :disabled="tenant.locked"
                @click="auth.switchTenant(tenant.id)"
            >Wählen</UButton>
          </div>


        </UCard>
      </UContainer>
    </div>
    <div v-else-if="auth.activeTenantData?.locked === 'maintenance'">
      <UContainer class="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900">
        <UCard class="max-w-lg text-center p-10">
          <UColorModeImage
              light="/Logo_Hell_Weihnachten.png"
              dark="/Logo_Dunkel_Weihnachten.png"
              class=" mx-auto my-10"
              v-if="month === '12'"
          />
          <UColorModeImage
              light="/Logo.png"
              dark="/Logo_Dark.png"
              class="mx-auto my-10"
              v-else
          />
          <div class="flex justify-center mb-6">
            <UIcon name="i-heroicons-exclamation-triangle-solid" class="w-16 h-16 text-yellow-500" />
          </div>

          <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-4">
            Wartungsarbeiten
          </h1>
          <p class="text-gray-600 dark:text-gray-300 mb-8">
            FEDEO wird derzeit gewartet. Bitte versuche es in einigen Minuten erneut.
          </p>


        </UCard>
      </UContainer>
    </div>
    <div v-else-if="auth.activeTenantData?.locked === 'no_subscription'">
      <UContainer class="min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900">
        <UCard class="max-w-lg text-center p-10">
          <UColorModeImage
              light="/Logo_Hell_Weihnachten.png"
              dark="/Logo_Dunkel_Weihnachten.png"
              class=" mx-auto my-10"
              v-if="month === '12'"
          />
          <UColorModeImage
              light="/Logo.png"
              dark="/Logo_Dark.png"
              class="mx-auto my-10"
              v-else
          />
          <div class="flex justify-center mb-6">
            <UIcon name="i-heroicons-credit-card" class="w-16 h-16 text-red-600" />
          </div>

          <h1 class="text-2xl font-bold text-gray-900 dark:text-white mb-4">
            Kein Aktives Abonnement für diesen Mandant.
          </h1>
          <p class="text-gray-600 dark:text-gray-300 mb-8">
            Bitte wenden Sie sich an den FEDEO Support um ein Abonnement zu erhalten oder verwenden Sie einen anderen Mandanten.
          </p>
          <div class="mx-auto text-left flex flex-row justify-between my-3" v-for="tenant in auth.tenants">
            {{tenant.name}}
            <UButton
                :disabled="tenant.locked"
                @click="auth.switchTenant(tenant.id)"
            >Wählen</UButton>
          </div>


        </UCard>
      </UContainer>
    </div>
    <UDashboardLayout class="safearea" v-else>

      <UDashboardPage style="height: 90vh">
        <UDashboardPanel grow>
          <slot />
        </UDashboardPanel>
      </UDashboardPage>

      <div class="mobileFooter bg-white dark:bg-gray-950">
        <UButton
            icon="i-heroicons-home"
            to="/mobile/"
            variant="ghost"
            :color="route.fullPath === '/mobile' ? 'primary' : 'gray'"
        />
        <UButton
            icon="i-heroicons-clipboard-document-check"
            to="/standardEntity/tasks"
            variant="ghost"
            :color="route.fullPath === '/standardEntity/tasks' ? 'primary' : 'gray'"
        />
        <UButton
            icon="i-heroicons-rectangle-stack"
            to="/standardEntity/projects"
            variant="ghost"
            :color="route.fullPath === '/standardEntity/projects' ? 'primary' : 'gray'"
        />
        <!--      <UButton
                icon="i-heroicons-clock"
                to="/workingtimes"
                variant="ghost"
                :color="route.fullPath === '/workingtimes' ? 'primary' : 'gray'"
              />-->
        <UButton
            icon="i-heroicons-bars-4"
            to="/mobile/menu"
            variant="ghost"
            :color="route.fullPath === '/mobile/menu' ? 'primary' : 'gray'"
        />
      </div>



      <!-- ~/components/HelpSlideover.vue -->
      <HelpSlideover/>
      <!-- ~/components/NotificationsSlideover.vue -->
      <NotificationsSlideover />


    </UDashboardLayout>
  </div>

  <div
      v-else
      class="flex flex-col"
  >
    <UColorModeImage
        light="/Logo_Hell_Weihnachten.png"
        dark="/Logo_Dunkel_Weihnachten.png"
        class="w-1/3 mx-auto my-10"
        v-if="month === '12'"
    />
    <UColorModeImage
      light="/Logo.png"
      dark="/Logo_Dark.png"
      class="w-1/3 mx-auto my-10"
      v-else
    />
    <div v-if="!auth.activeTenant" class="w-full mx-auto text-center">
      <!-- Tenant Selection      -->
      <h3 class="text-center font-bold text-2xl mb-5">Kein Aktiver Mandant. Bitte wählen Sie ein Mandant.</h3>
      <div class="mx-auto w-5/6 flex flex-row justify-between my-3" v-for="tenant in auth.tenants">
        <span class="text-left">{{tenant.name}}</span>
        <UButton
            @click="auth.switchTenant(tenant.id)"
        >Wählen</UButton>
      </div>
      <UButton
          variant="outline"
          color="rose"
          @click="auth.logout()"
      >Abmelden</UButton>


    </div>
    <div v-else>
      <UProgress animation="carousel" class="w-3/4 mx-auto mt-10" />
    </div>
  </div>

</template>

<style scoped>
.mobileFooter {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 8vh;
  width: 100%;
  border-top: 1px solid grey;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 1em;
}

.mobileFooter > a {

}
</style>