<template>
  <div class="form-part">
    <div class="form-part-title">
      <h4>Piyango Resimleri</h4>
    </div>
    <div class="form-part-content">
      <template v-for="(file, i) in fileList">
        <file-list-item
          :data="file"
          onlyPreview
          :editable="false"
          :filePath="file.resimYolu" />
      </template>
      <div v-if="usersStore.isPanelUser && fileList.length === 0" class="form-inner-comment">
        Eklenmiş resim bulunamadı.
      </div>
    </div>
  </div>
</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 { usePiyangoStore } from '../../stores/piyangoStore'
  const piyangoStore = usePiyangoStore()

  const fileList = ref<Record<string,any>[]>([])

  const GetData = async () => {
    let dt = await dataStore.dataGet('CekilisResim/Cekilis/' + piyangoStore.selectedLottery)
    if (dt !== 'errorfalse') fileList.value.splice(0, fileList.value.length, ...dt.data)
  }
  onBeforeMount(async () => {
    await GetData()
  })
</script>
