<script setup lang="ts">
import Form from "@/modules/12_evaluatePersonal/components/Director/Form.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useRoute, useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useQuasar } from "quasar";
// import type { FormDataPost } from "@/modules/11_discipline/interface/request/director";
import type { DataForm } from "@/modules/12_evaluatePersonal/interface/index/director";
const $q = useQuasar();
const mixin = useCounterMixin();
const { messageError, showLoader, hideLoader, dialogConfirm, success } = mixin;
const router = useRouter();

/**
 * บันทึกข้อมูลที่เเก้ไข
 * @param id ระบุ บุคคล
 */
function onSubmit(formData: DataForm) {
  dialogConfirm($q, () => addData(formData));
}

function addData(formData: DataForm) {
  console.log(formData);
  showLoader();
  http
    .post(config.API.evaluateDirectorMain(), {
      // personalId:formData.personalId ?? '',
      prefix: formData.prefix,
      firstName: formData.firstname,
      lastName: formData.lastname,
      position: formData.position,
      email: formData.email,
      phone: formData.phone,
    })
    .then((res) => {
      success($q, "บันทึกข้อมูลสำเร็จ");
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(async () => {
      router.push(`/evaluate/director`);
    });
}
</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.go(-1)"
      />
      เพิ่มรายชื่อกรรมการ
    </div>

    <Form :on-submit="onSubmit" />
  </div>
</template>
