<template>
  <AdminLayout>
    <dash-piyango-liste
      v-if="loaded"
      title="Onay Bekleyen Piyangolar"
      listText="Piyango"
      icon="draws"
      dateKey="tarih"
      :total="onayBekleyenTotal"
      iconBack="waiting"
      :tableData="onayBekleyenPiyango"
      lineRoute="piyangolar/detay/"
      lineRouteKey="id"
      :filterParams="{ durumId: 0 }" />
    <dash-piyango-liste
      v-if="loaded"
      title="İtiraz/Şikayet Edilen Piyangolar"
      listText="Piyango"
      icon="draws"
      dateKey="tarih"
      :total="itirazEdilenTotal"
      iconBack="alert"
      :tableData="itirazEdilenPiyango"
      lineRoute="piyangolar/detay/"
      lineRouteKey="id"
      :filterParams="{ durumId: 1 }" />

    <dash-piyango-liste
      v-if="loaded"
      title="Yaklaşan Piyangolar"
      listText="Piyango"
      icon="draws"
      dateKey="tarih"
      :total="yaklasanTotal"
      iconBack="next"
      :tableData="yaklasanPiyango"
      lineRoute="piyangolar/detay/"
      lineRouteKey="id"
       :filterParams="{ baslangicTarihi: '>' + new Date().toISOString().split('T')[0] }"/>

    <dash-piyango-liste
      v-if="loaded"
      title="Biten Piyangolar"
      listText="Piyango"
      icon="draws"
      dateKey="tarih"
      :total="bitenTotal"
      iconBack="ok"
      :tableData="bitenPiyango"
      lineRoute="piyangolar/detay/"
      lineRouteKey="id"
       :filterParams="{ bitisTarihi: '<' + new Date().toISOString().split('T')[0] }"  />
  </AdminLayout>
</template>
<script setup lang="ts">
  import { ref, onBeforeMount } from 'vue'

  import { useDataStore } from '@/stores/dataStore'
  const dataStore = useDataStore()
  import { useUsersStore } from '@/stores/usersStore'
  const usersStore = useUsersStore()
  import { usePageStore } from '@/stores/pageStore'
  const pageStore = usePageStore()

  import AdminLayout from '@/layouts/AdminLayout.vue'
  import DashPiyangoListe from '@/components/DashPiyangoListe.vue'

  const loaded = ref<boolean>(false)
  const onayBekleyenPiyango = ref<Record<string, any>[]>([])
  const onayBekleyenTotal = ref<number>(0)
  const itirazEdilenPiyango = ref<Record<string, any>[]>([])
  const itirazEdilenTotal = ref<number>(0)
  const yaklasanPiyango = ref<Record<string, any>[]>([])
  const yaklasanTotal = ref<number>(0)
  const bitenPiyango = ref<Record<string, any>[]>([])
  const bitenTotal = ref<number>(0)

  const api = ref<string>('')

  api.value = usersStore.isPanelUser
    ? usersStore.isSuperAdmin || usersStore.isAccounting
      ? 'Cekilis/Dashboard'
      : 'Cekilis/DashboardAtanan/' + usersStore.userId
    : 'Cekilis/Dashboard/' + usersStore.userId

  onBeforeMount(async () => {
    let onayBekleyenData = await dataStore.dataGet(api.value, {
      params: { durum: 0 }
    })
    let itirazEdilenData = await dataStore.dataGet(api.value, {
      params: { durum: 1 }
    })
    let yaklasanData = await dataStore.dataGet(api.value, {
      params: { durum: 2 }
    })
    let bitenData = await dataStore.dataGet(api.value, {
      params: { durum: 3 }
    })
    onayBekleyenPiyango.value = onayBekleyenData.cekilisler
    onayBekleyenTotal.value = onayBekleyenData.totalCount
    itirazEdilenPiyango.value = itirazEdilenData.cekilisler
    itirazEdilenTotal.value = itirazEdilenData.totalCount
    yaklasanPiyango.value = yaklasanData.cekilisler
    yaklasanTotal.value = yaklasanData.totalCount
    bitenPiyango.value = bitenData.cekilisler
    bitenTotal.value = bitenData.totalCount

    loaded.value = true
  })
</script>
