<template>
  <div class="form-part form-title">
    <div class="form-title-buttons">
      <div class="button-c button-save" @click="piyangoOnayService.SaveOnayDurum">
        Kaydet
      </div>
    </div>
  </div>
  <div :class="['form-part', piyangoOnayValidationStore.formChanged ? 'changed' : '']">
    <div class="form-part-title">
      <h4>Onay Durumu</h4>
    </div>
    <div class="form-part-content" v-if="piyangoOnayStore.loaded">
      <form-select
        label="İşlem"
        :listData="piyangoDataStore.piyangoOnayDurumlari"
        listText="tipAdi"
        listVal="islemId"
        v-model="piyangoOnayStore.piyangoOnayForm.onayDurumuIslemTipiId"
        required
        :invalidText="piyangoOnayValidationStore.invalidTexts.onayDurumuIslemTipiId" />
      <template v-if="piyangoOnayStore.piyangoOnayForm.onayDurumuIslemTipiId === 4">
        <form-input
          modelKey="izinSayisi"
          v-model="piyangoOnayStore.piyangoOnayForm.izinSayisi"
          required
          label="İzin Sayı No"
          placeholder="İzin Sayı No"
          :invalidText="piyangoOnayValidationStore.invalidTexts.izinSayisi"
          @keyup="OnKeyup" />
        <form-date
          type="date"
          required
          modelKey="izinTarihi"
          v-model="piyangoOnayStore.piyangoOnayForm.izinTarihi"
          label="İzin Tarihi"
          :invalidText="piyangoOnayValidationStore.invalidTexts.izinTarihi"
          @change="OnKeyup" />
        <form-textarea
          v-model="piyangoOnayStore.piyangoOnayForm.izinAciklamasi"
          :invalidText="piyangoOnayValidationStore.invalidTexts.izinAciklamasi"
          label="İzin Açıklaması"
          @keyup="OnKeyup" />
      </template>
      <form-file
        v-model="piyangoOnayStore.piyangoOnayForm.file"
        elclass="panel-documents-item"
        :invalidText="piyangoOnayValidationStore.invalidTexts.file" />
      <form-textarea
        v-model="piyangoOnayStore.piyangoOnayForm.aciklama"
        :invalidText="piyangoOnayValidationStore.invalidTexts.aciklama"
        label="Açıklama"
        @keyup="OnKeyup" />
    </div>
  </div>
</template>
<script setup lang="ts">
  import { ref, reactive, onBeforeMount } from 'vue'

  import { useDataStore } from '@/stores/dataStore'
  const dataStore = useDataStore()
  import { useUsersStore } from '@/stores/usersStore'
  const usersStore = useUsersStore()
  import { useValidationStore } from '@/stores/validationStore'
  const validationStore = useValidationStore()
  import { usePiyangoStore } from '../../stores/piyangoStore'
  const piyangoStore = usePiyangoStore()
  import { usePiyangoOnayStore } from '../../stores/piyangoOnayStore'
  const piyangoOnayStore = usePiyangoOnayStore()
  import { usePiyangoOnayValidationStore } from '../../validation/piyangoOnayValidationStore'
  const piyangoOnayValidationStore = usePiyangoOnayValidationStore()
  import { usePiyangoOnayService } from '../../service/piyangoOnayService'
  const piyangoOnayService = usePiyangoOnayService()
  import { usePiyangoDataStore } from '../../stores/piyangoDataStore'
  const piyangoDataStore = usePiyangoDataStore()
  import { usePiyangoServices } from '../../service/piyangoServices'
  const piyangoServices = usePiyangoServices()

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

  onBeforeMount(async () => {
    piyangoOnayStore.ResetForm()
    await piyangoServices.GetPiyangoOnayDurumList()
    piyangoDataStore.RemoveOnayDurumIncelemeBekleniyor()
    piyangoOnayStore.loaded = true
  })
</script>
