<template>
  <div class="form-part-content" v-if="piyangoTeminatStore.loaded">
    <form-select
      v-if="usersStore.isPanelUser"
      label="İşlem"
      :listData="piyangoDataStore.piyangoTeminatDurumlari"
      listText="value"
      listVal="id"
      v-model="piyangoTeminatStore.piyangoTeminatFormData.state"
      required
      :invalidText="piyangoTeminatValidationStore.invalidTexts.state"
      @change="OnKeyup"
      :disabled="!usersStore.isPanelUser" />

    <template
      v-if="
        piyangoTeminatStore.piyangoTeminatFormData.state === 2 ||
        piyangoTeminatStore.piyangoTeminatFormData.state === 3
      ">
      <form-date
        type="date"
        half
        modelKey="refundDate"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.refundDate"
        label="İade Tarihi"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.refundDate"
        @change="OnKeyup" />
      <form-input
        modelKey="refundCount"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.refundCount"
        half
        label="Sayısı"
        @keyup="OnKeyup"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.refundCount" />
      <form-file
        v-model="piyangoTeminatStore.piyangoTeminatFormData.refundDocumentUrl"
        label='İade Yazısı'
        elclass="panel-documents-item"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.refundDocumentUrl"
        @change="OnKeyup" />
      <form-input
        modelKey="refundDescription"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.refundDescription"
        label="Klasör Arşiv No"
        @keyup="OnKeyup"  />
    </template>

    <form-display
      v-model="piyangoTeminatStore.piyangoTeminatFormData.amount"
      half
      price
      label="Tutarı" />

    <form-display
      v-model="piyangoTeminatStore.piyangoTeminatFormData.teminatParentTypeText"
      half
      label="Para Birimi" />

    <form-display
      label="Teminat Türü"
      half
      v-model="piyangoTeminatStore.piyangoTeminatFormData.teminantChildTypeText" />

    <form-display
      type="date"
      half
      v-model="piyangoTeminatStore.piyangoTeminatFormData.teminantDate"
      label="Tarih" />

    <form-display
      v-model="piyangoTeminatStore.piyangoTeminatFormData.teminantNo"
      half
      label="No" />
    <div class="form-item form-item-half"></div>

    <form-display
      v-model="piyangoTeminatStore.piyangoTeminatFormData.bankName"
      half
      label="Banka Adı" />

    <form-display
      v-model="piyangoTeminatStore.piyangoTeminatFormData.bankBranch"
      half
      label="Banka Şubesi" />

    <file-list-item
      v-if="
        piyangoTeminatStore.piyangoTeminatFormData.teminantDocumentUrl !== null &&
        piyangoTeminatStore.piyangoTeminatFormData.teminantDocumentUrl !== undefined
      "
      title="Dosya"
      :data="piyangoTeminatStore.piyangoTeminatFormData"
      :editable="false"
      :filePath="piyangoTeminatStore.piyangoTeminatFormData.teminantDocumentUrl"
      :usePath="true"
      :onlyPreview="true" />

    <form-display
      v-model="piyangoTeminatStore.piyangoTeminatFormData.description"
      label="Açıklama" />
  </div>
</template>
<script setup lang="ts">
  import { onBeforeMount } from 'vue'

  import { usePiyangoTeminatStore } from '../../stores/piyangoTeminatStore'
  const piyangoTeminatStore = usePiyangoTeminatStore()
  import { useUsersStore } from '@/stores/usersStore'
  const usersStore = useUsersStore()
  import { usePiyangoDataStore } from '../../stores/piyangoDataStore'
  const piyangoDataStore = usePiyangoDataStore()
  import { usePiyangoTeminatValidationStore } from '../../validation/piyangoTeminatValidationStore'
  const piyangoTeminatValidationStore = usePiyangoTeminatValidationStore()
  import { usePiyangoTeminatService } from '../../service/piyangoTeminatService'
  const piyangoTeminatService = usePiyangoTeminatService()
  import { usePiyangoServices } from '../../service/piyangoServices'
  const piyangoServices = usePiyangoServices()
  const OnKeyup = () => {
    piyangoTeminatValidationStore.formChanged = true
  }

  onBeforeMount(async () => {
    await piyangoServices.GetPiyangoTeminatDurumList()
    await piyangoTeminatService.GetTeminatDurum()
  })
</script>
