<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import Form from "@/modules/11_discipline/components/3_InvestigateDisciplinary/Form.vue";
import type { FormData } from "@/modules/11_discipline/interface/request/disciplinary";
import { useRouter, useRoute } from "vue-router";

const router = useRouter();
const route = useRoute();
const id = ref<string>(route.params.id as string);


/** ข้อมูล v-model ของฟอร์ม */
const data = reactive<FormData>({
  complaint: "",
  dateInvestigate: null,
  dateAllegation: null,
  dateEvident: null,
  casefault: "",
  typefault: "",
  faultLevel: "",
  refLaw: "",
  detailComplaint: "",
  whereInvestigate: "",
  trueDetail: "",
  evidence: "",
  recordAccuser: "",
  witnesses: "",
  InvestResults: "",
  filesEvidence: null,
  filesRecordAccuser: null,
  filesWitnesses: null,
  filesEtc: null,
});

/** จำลองข้อมูลจาก api */
const fetchData = async () => {
  data.complaint = "test1"
  data.dateInvestigate = new Date("2023-11-08T14:58:00")
  data.dateAllegation = new Date("2023-11-08T14:58:00")
  data.dateEvident = new Date("2023-11-08T14:58:00")
  data.casefault = "test1"
  data.typefault = "2"
  data.faultLevel = "2"
  data.refLaw = "test"
  data.detailComplaint = "รายละเอียด"
  data.whereInvestigate = "ที่ไหน"
  data.trueDetail = "รายละเอียด"
  data.evidence = "รายละเอียด"
  data.recordAccuser = "รายละเอียด"
  data.witnesses = "รายละเอียด"
  data.InvestResults = "รายละเอียด"
  data.filesEvidence = null
  data.filesRecordAccuser = null
  data.filesWitnesses = null
  data.filesEtc = null
};

/**
 * บันทึกข้อมูลที่เเก้ไข
 * @param id ระบุ บุคคล
 */
const onSubmit = async (id:string) => {
  console.log("edit");
  router.push(`/discipline/disciplinary`);
};

/** โหลดข้อมูลเมื่อเข้าหน้านี้ */
onMounted(() => {
  fetchData();
});
</script>
<template>
  <div class="col-xs-12 col-sm-12 col-md-11">
    <div class="toptitle col-12 row items-center">
      <q-btn
        icon="mdi-arrow-left"
        unelevated
        round
        dense
        flat
        color="primary"
        class="q-mr-sm"
        @click="$router.push(`/discipline/disciplinary`)"
      />
      แก้ไขการสอบสวนความผิดทางวินัย {{ id }}#id
    </div>
    <Form :on-submit="onSubmit" :data="data" />
  </div>
</template>
