<template>
  <div class="form-part">
    <div class="form-part-title">
      <h4>Çekiliş Tutanağı</h4>
      <div class="form-part-title-buttons">
        <icon-button
          v-if="!usersStore.isPanelUser"
          icon="plus"
          class="ico-section ico-section-header-btn"
          @click="AddNewDocument" />
      </div>
    </div>
    <div class="form-part-content" v-if="cekilisTutanagiStore.loaded">
      <template v-if="cekilisTutanagiStore.cekilisTutanagiList.length > 0">
        <template v-for="(file, i) in cekilisTutanagiStore.cekilisTutanagiList">
          <file-list-item
            :data="file"
            title="dokumanAdi"
            :filePath="file.url"
            :editable="false" />
        </template>
      </template>
      <template v-else>
        <div class="form-inner-comment">
          <span>
            Eklenmiş dosya bulunamadı. Üstteki butonu kullanarak dosya ekleyebilirsiniz.
          </span>
        </div>
      </template>
    </div>
  </div>
  <panel-wrapper
    v-if="cekilisTutanagiStore.documentPanel"
    v-model="cekilisTutanagiStore.documentPanel"
    panel-title="Doküman Ekle">
    <template #panelContent>
      <panel-piyango-cekilis-tutanagi />
    </template>
    <template #footerButton>
      <div class="button-c button-save" @click="cekilisTutanagiService.SaveDocument">
        Ekle
      </div>
    </template>
  </panel-wrapper>
</template>
<script setup lang="ts">
  import { ref, onBeforeMount } from 'vue'

  import PanelPiyangoCekilisTutanagi from '../panel/PanelPiyangoCekilisTutanagi.vue'
  import PanelWrapper from '@/components/PanelWrapper.vue'

  import { useUsersStore } from '@/stores/usersStore'
  const usersStore = useUsersStore()
  import { usePiyangoStore } from '../../stores/piyangoStore'
  const piyangoStore = usePiyangoStore()
  import { usePiyangoCekilisTutanagiStore } from '../../stores/piyangoCekilisTutanagiStore'
  const cekilisTutanagiStore = usePiyangoCekilisTutanagiStore()
  import { usePiyangoCekilisTutanagiService } from '../../service/piyangoCekilisTutanagiService'
  const cekilisTutanagiService = usePiyangoCekilisTutanagiService()

  const AddNewDocument = () => {
    cekilisTutanagiStore.ResetForm()
    cekilisTutanagiStore.isUpdate = false
    cekilisTutanagiStore.documentPanel = true
  }

  onBeforeMount(async () => {
    await cekilisTutanagiService.GetDocumentList()
  })
</script>

