<script setup lang="ts">
import Form from "@/modules/12_evaluatePersonal/components/Meeting/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";

const $q = useQuasar();
const mixin = useCounterMixin();
const { messageError, showLoader, hideLoader, dialogConfirm, success } = mixin;
const router = useRouter();

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

function addData(formData: any) {
  showLoader();
  http
    .post(config.API.meeting(), {
      round: formData.rounded ?? "",
      title: formData.title,
      dateEnd: formData.dateMeetingEnd,
      dateStart: formData.dateMeetingStart,
      result: formData.consider,
      duration: formData.period,
    })
    .then((res) => {
      success($q, "บันทึกข้อมูลสำเร็จ");
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(async () => {
      router.push(`/evaluate/meeting`);
    });
}
</script>
<template>
  <div class="col-xs-12 col-sm-12 col-md-12">
    <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(`/evaluate/meeting`)"
      />
      เพิ่มการประชุม
    </div>

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