<script setup lang="ts">
import { useRoute, useRouter } from "vue-router";
import Form from "@/modules/11_discipline/components/1_Complaint/Form.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";

import config from "@/app.config";
import http from "@/plugins/http";

const $q = useQuasar();
const mixin = useCounterMixin();

const { showLoader, hideLoader, success, messageError } = mixin;
const router = useRouter();

/** บันทึกข้อมูล */
async function onSubmit(data: any) {
  /** post */
  console.log(data)
  showLoader();
  http
    .post(config.API.complaintAdd(), data)
    .then((res) => {
      console.log(res)
      success($q, "บันทึกข้อมูลสำเร็จ");
      router.push(`/discipline/complaints/${res.data.result}`);
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(async () => {
      hideLoader();
    });
}
</script>
<template>
  <div class="col-xs-12 col-sm-12 col-md-11">
    <div class="toptitle text-dark col-12 row items-center">
      <q-btn
        for="#backMaininvestigate"
        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>
