<template>
    <div class="form-part-content" v-if="piyangoTeminatStore.loaded">
      <form-input
        modelKey="amount"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.amount"
        required
        half
        label="Tutarı"
        minlength="2"
        @keyup="OnKeyup"
        @keydown="validationStore.allowPrice"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.amount" />

      <form-select
        modelKey="teminatParentType"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.teminatParentType"
        required
        half
        label="Para Birimi"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.teminatParentType"
        :listData="piyangoDataStore.piyangoTeminatParaBirimleri"
        listVal="id"
        listText="value"
        @change="OnKeyup" />

      <form-select
        label="Teminat Türü"
        :listData="piyangoDataStore.piyangoTeminatTurleri"
        listText="value"
        listVal="id"
        half
        v-model="piyangoTeminatStore.piyangoTeminatFormData.teminantChildType"
        required
        :invalidText="piyangoTeminatValidationStore.invalidTexts.teminantChildType"
        @change="OnKeyup" />

      <form-date
        type="date"
        half
        required
        modelKey="teminantDate"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.teminantDate"
        label="Tarih"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.teminantDate"
        @change="OnKeyup" />

      <form-input
        modelKey="teminantNo"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.teminantNo"
        required
        half
        label="No"
        minlength="2"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.teminantNo"
        @keyup="OnKeyup" />
      <div class="form-item form-item-half"></div>

      <form-input
        modelKey="bankName"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.bankName"
        required
        half
        label="Banka Adı"
        minlength="2"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.bankName"
        @keyup="OnKeyup" />

      <form-input
        modelKey="bankBranch"
        v-model="piyangoTeminatStore.piyangoTeminatFormData.bankBranch"
        required
        half
        label="Banka Şubesi"
        minlength="2"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.bankBranch"
        @keyup="OnKeyup" />

      <form-file
        v-model="piyangoTeminatStore.piyangoTeminatFormData.file"
        elclass="panel-documents-item"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.file"
        @change="OnKeyup" />

      <form-textarea
        v-model="piyangoTeminatStore.piyangoTeminatFormData.description"
        :invalidText="piyangoTeminatValidationStore.invalidTexts.description"
        label="Açıklama"
        @keyup="OnKeyup" />
    </div>
</template>
<script setup lang="ts">
  import { onBeforeMount } from 'vue'

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

  const OnKeyup = () => {
    piyangoTeminatValidationStore.formChanged = true
  }

  onBeforeMount(async () => {   
    
    await piyangoServices.GetPiyangoTeminatTurleriList()
    await piyangoServices.GetPiyangoTeminatParaBirimleriList()
    await piyangoServices.GetPiyangoTeminatDurumList()
    
    piyangoTeminatStore.RestoreFormData()
    piyangoTeminatStore.loaded = true

    if (!piyangoTeminatStore.isNew) await piyangoTeminatService.GetTeminatDurum()
  })
</script>
