<script setup lang="ts">
import { reactive, ref, computed, onMounted, watch } from "vue";
import { useQuasar } from "quasar";

import http from "@/plugins/http";
import config from "@/app.config";
import { useLeaveStore } from "@/modules/05_leave/store";
import { useCounterMixin } from "@/stores/mixin";

import type { studyDaySubjectForm } from "@/modules/05_leave/interface/request/AddAbsence";

/** Use */
const $q = useQuasar();
const dataStore = useLeaveStore();
const mixin = useCounterMixin();
const {
  date2Thai,
  calculateDurationYmd,
  dateToISO,
  messageError,
  arabicNumberToText,
  convertDateToAPI,
  showLoader,
  hideLoader,
} = mixin;

const leaveText = ref<string>("");
const edit = ref<boolean>(true);
const leaveId = ref<string>("");
const leaveStartDateRef = ref<object | null>(null);
const leaveEndDateRef = ref<object | null>(null);
const leavebirthDateRef = ref<object | null>(null);
const leavegovernmentDateRef = ref<object | null>(null);
const leaveSalaryRef = ref<object | null>(null);
const leaveNumberRef = ref<object | null>(null);
const leaveAddressRef = ref<object | null>(null);
const studyDayScholarshipRef = ref<object | null>(null);
const studyDayCountryRef = ref<object | null>(null);
const studyDayUniversityNameRef = ref<object | null>(null);
const studyDayDegreeLevelRef = ref<object | null>(null);
const studyDaySubjectRef = ref<object | null>(null);
const leaveWroteRef = ref<object | null>(null);

/** รับ props มาจากหน้าหลัก */
const props = defineProps({
  data: {
    type: Object,
    default: null,
  },
  onSubmit: {
    type: Function,
    default: () => "",
  },
  onConfirm: {
    type: Function,
    default: () => "",
  },
  clickDelete: {
    type: Function,
    default: () => "",
  },
});

/** ข้อมูล v-model ของฟอร์ม */
const formDataStudy = reactive<any>({
  type: dataStore.typeId, //
  leaveWrote: "", //
  leaveStartDate: null,
  leaveEndDate: null,
  leavebirthDate: new Date(),
  leavegovernmentDate: new Date(),
  leaveSalary: 10000,
  leaveSalaryText: arabicNumberToText(10000),
  studyDayScholarship: "",
  studyDayCountry: "",
  studyDayUniversityName: "", //
  studyDayDegreeLevel: "", //
  studyDaySubject: "", //
  leaveDocument: [], //
  leaveDetail: "",
  leaveTotal: "",
  leaveRange: "ALL",
  leaveRangeEnd: "ALL",
  leaveTotalDay: "", //จำนวนวันลา
});

/** maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ */
const formRef: studyDaySubjectForm = {
  leaveStartDate: leaveStartDateRef,
  leaveEndDate: leaveEndDateRef,
  leavebirthDate: leavebirthDateRef,
  leavegovernmentDate: leavegovernmentDateRef,
  leaveSalary: leaveSalaryRef,
  leaveNumber: leaveNumberRef,
  leaveAddress: leaveAddressRef,
  studyDayScholarship: studyDayScholarshipRef,
  studyDayCountry: studyDayCountryRef,
  studyDayUniversityName: studyDayUniversityNameRef,
  studyDayDegreeLevel: studyDayDegreeLevelRef,
  studyDaySubject: studyDaySubjectRef,
  leaveWrote: leaveWroteRef,
};

const fileDocDataUpload = ref<File[]>([]);
const leaveDocumentList = ref<any>();
const statusCheck = ref<string>("");
const isLeave = ref<boolean>(true);
const dateEndInputStyle = computed(() => {
  return !isLeave.value ? "input-alert" : "";
});

async function fileUploadDoc(files: any) {
  files.forEach((file: any) => {
    fileDocDataUpload.value.push(file);
  });
}

/** ฟังก์ชั่นตรวจสอบความถูกต้องก่อน บันทึก */
function onValidate() {
  const hasError = [];
  for (const key in formRef) {
    if (Object.prototype.hasOwnProperty.call(formRef, key)) {
      const property = formRef[key];
      if (property.value && typeof property.value.validate === "function") {
        const isValid = property.value.validate();
        hasError.push(isValid);
      }
    }
  }
  if (hasError.every((result) => result === true)) {
    const formData = new FormData();
    if (formDataStudy.leaveDocument) {
      formDataStudy.leaveDocument.forEach((file: File) => {
        formData.append("leaveDocument", file);
      });
    }
    // formData.append("leaveDocument", formDataStudy.leaveDocument);
    formData.append("type", formDataStudy.type); //
    formData.append(
      "leaveStartDate",
      convertDateToAPI(formDataStudy.leaveStartDate) ?? ""
    );
    formData.append(
      "leaveEndDate",
      convertDateToAPI(formDataStudy.leaveEndDate) ?? ""
    );
    formData.append("studyDaySubject", formDataStudy.studyDaySubject);
    formData.append("studyDayDegreeLevel", formDataStudy.studyDayDegreeLevel);
    // formData.append(
    //   "leavegovernmentDate",
    //   convertDateToAPI(formDataStudy.leavegovernmentDate)??''
    // );
    formData.append(
      "studyDayUniversityName",
      formDataStudy.studyDayUniversityName
    );
    formData.append("studyDayCountry", formDataStudy.studyDayCountry);
    formData.append("leaveWrote", formDataStudy.leaveWrote); //
    formData.append("leaveDetail", formDataStudy.leaveDetail); //
    formData.append("studyDayScholarship", formDataStudy.studyDayScholarship);
    formData.append("leaveAddress", dataStore.currentAddress); //
    formData.append("leaveNumber", dataStore.telephoneNumber); //
    formData.append("leaveTotal", formDataStudy.leaveTotal); //

    formData.append("leaveRange", formDataStudy.leaveRange);
    formData.append("leaveRangeEnd", formDataStudy.leaveRangeEnd);

    props.onSubmit(formData, isLeave.value);
  }
}

const reasonLeave = ref<string>("");

const checkDate = computed(() => {
  if (
    convertDateToAPI(formDataStudy.leaveEndDate) ==
    convertDateToAPI(formDataStudy.leaveStartDate)
  ) {
    return true;
  } else {
    return false;
  }
});

// const totalCheck = ref<number | null>(null);
async function fetchCheck() {
  if (formDataStudy.leaveStartDate && formDataStudy.leaveEndDate) {
    showLoader();
    await http
      .post(config.API.leaveCheck(), {
        type: dataStore.typeId ?? null,
        StartLeaveDate: convertDateToAPI(formDataStudy.leaveStartDate) ?? null,
        EndLeaveDate: convertDateToAPI(formDataStudy.leaveEndDate) ?? null,
        leaveRange: formDataStudy.leaveRange,
        leaveRangeEnd: checkDate.value
          ? formDataStudy.leaveRange
          : formDataStudy.leaveRangeEnd,
      })
      .then((res: any) => {
        const data = res.data.result;
        isLeave.value = data.isLeave;
        formDataStudy.leaveTotal = data.totalDate;
        // totalCheck.value = data.totalDate;
        leaveText.value = calculateDurationYmd(
          convertDateToAPI(formDataStudy.leaveStartDate),
          convertDateToAPI(formDataStudy.leaveEndDate)
        );
        reasonLeave.value = data.message
          ? data.message
          : "จำนวนวันลาเกินที่กำหนด";
        hideLoader();
      })
      .catch((e: any) => {
        messageError($q, e);
        // totalCheck.value = null;
        hideLoader();
      });
  }
}

// /**
//  * function อัพเดทค่า LeaveTotal
//  */
// function updateLeaveTotal() {
//   const newLeaveTotal = calculateDurationYmd(
//     formDataStudy.leaveStartDate,
//     formDataStudy.leaveEndDate
//   );
//   formDataStudy.leaveTotal = newLeaveTotal;
// }

/** ตรวจสอบว่ามีการส่งข้อมูลเข้ามาที่ฟอร์มไหม เมื่อมีการส่งจะ map ข้อมูลเข้า v-model ของฟอร์ม */
watch(
  () => props.data,
  async () => {
    if (props.data) {
      // totalCheck.value = null;
      formDataStudy.leaveWrote = props.data.leaveWrote;
      formDataStudy.leaveStartDate = props.data.leaveStartDate;
      formDataStudy.leaveEndDate = props.data.leaveEndDate;
      formDataStudy.leaveTotal = props.data.leaveTotal;
      formDataStudy.leavebirthDate = props.data.leavebirthDate;
      formDataStudy.leavegovernmentDate = props.data.leavegovernmentDate;
      formDataStudy.leaveSalary = props.data.leaveSalary;
      formDataStudy.leaveSalaryText = props.data.leaveSalaryText;

      formDataStudy.studyDayScholarship = props.data.studyDayScholarship;
      formDataStudy.studyDayCountry = props.data.studyDayCountry;
      formDataStudy.studyDayUniversityName = props.data.studyDayUniversityName;
      formDataStudy.studyDayDegreeLevel = props.data.studyDayDegreeLevel;
      formDataStudy.studyDaySubject = props.data.studyDaySubject;
      formDataStudy.leaveDetail = props.data.leaveDetail;
      formDataStudy.leaveRange = props.data.leaveRange;
      formDataStudy.leaveRangeEnd = props.data.leaveRangeEnd;
      formDataStudy.leaveDocument = [];
      leaveDocumentList.value = props.data.leaveDocument;
      const leaveTotal = await calculateDurationYmd(
        props.data.leaveStartDate,
        props.data.leaveEndDate
      );
      leaveText.value = leaveTotal;
      statusCheck.value = props.data.status;
    }
  }
);

/**Hook */
onMounted(async () => {
  if (props.data) {
    // totalCheck.value = null;
    formDataStudy.leaveWrote = props.data.leaveWrote;
    formDataStudy.leaveStartDate = props.data.leaveStartDate;
    formDataStudy.leaveEndDate = props.data.leaveEndDate;
    formDataStudy.leavebirthDate = props.data.leavebirthDate;
    formDataStudy.leavegovernmentDate = props.data.leavegovernmentDate;
    formDataStudy.leaveSalary = props.data.leaveSalary;
    formDataStudy.leaveSalaryText = props.data.leaveSalaryText;

    formDataStudy.studyDayScholarship = props.data.studyDayScholarship;
    formDataStudy.studyDayCountry = props.data.studyDayCountry;
    formDataStudy.studyDayUniversityName = props.data.studyDayUniversityName;
    formDataStudy.studyDayDegreeLevel = props.data.studyDayDegreeLevel;
    formDataStudy.studyDaySubject = props.data.studyDaySubject;
    formDataStudy.leaveDetail = props.data.leaveDetail;

    formDataStudy.leaveRange = props.data.leaveRange;
    formDataStudy.leaveRangeEnd = props.data.leaveRangeEnd;

    leaveDocumentList.value = props.data.leaveDocument;
    formDataStudy.leaveTotal = props.data.leaveTotal;

    const leaveTotal = await calculateDurationYmd(
      props.data.leaveStartDate,
      props.data.leaveEndDate
    );
    leaveText.value = leaveTotal;
    statusCheck.value = props.data.status;
    leaveId.value = props.data.id;
  }
});
</script>

<template>
  <div style="display: flex; align-items: center">
    <q-icon name="mdi-numeric-3-circle" size="20px" color="primary" />
    <div class="q-pl-sm text-weight-bold text-dark">กรอกข้อมูล</div>
  </div>
  <form @submit.prevent="onValidate">
    <q-card bordered class="q-pa-md bg-grey-1">
      <div class="row q-pa-sm q-col-gutter-sm">
        <div class="col-12 inputgreen">
          <q-input
            v-model="formDataStudy.leaveWrote"
            ref="leaveWroteRef"
            bg-color="white"
            dense
            outlined
            label="เขียนที่"
            hide-bottom-space
            :readonly="!edit || statusCheck === 'NEW'"
            :rules="[(val:string) => !!val || `${'เขียนที่'}`]"
          />
        </div>

        <div class="col-12">
          <div class="row q-col-gutter-sm">
            <div class="col-12 col-md-3 col-sm-6 inputgreen">
              <datepicker
                v-model="formDataStudy.leaveStartDate"
                :locale="'th'"
                autoApply
                hide-bottom-space
                borderless
                :enableTimePicker="false"
                week-start="0"
                :readonly="!edit || statusCheck === 'NEW'"
                @update:model-value="
                  (formDataStudy.leaveEndDate = null), fetchCheck()
                "
              >
                <template #year="{ year }">
                  {{ year + 543 }}
                </template>
                <template #year-overlay-value="{ value }">
                  {{ parseInt(value + 543) }}
                </template>
                <template #trigger>
                  <q-input
                    outlined
                    dense
                    ref="leaveStartDateRef"
                    for="leaveStartDateRef"
                    hide-bottom-space
                    bg-color="white"
                    :readonly="!edit || statusCheck === 'NEW'"
                    class="full-width datepicker"
                    :model-value="
                      formDataStudy.leaveStartDate != null
                        ? date2Thai(formDataStudy.leaveStartDate)
                        : null
                    "
                    :label="`${'วันที่เริ่มต้น'}`"
                    :rules="[(val:string) => !!val || `${'กรุณาเลือกวันที่เริ่มต้น'}`]"
                  >
                    <template v-slot:prepend>
                      <q-icon
                        name="event"
                        class="cursor-pointer"
                        style="color: var(--q-primary)"
                      >
                      </q-icon>
                    </template>
                  </q-input>
                </template>
              </datepicker>
            </div>

            <!-- <div class="col-12 col-sm-3 inputgreen">
              <q-select
                outlined
                dense
                bg-color="white"
                v-model="formDataStudy.leaveRange"
                :options="dataStore.rangeOptions"
                emit-value
                map-options
                option-value="id"
                option-label="name"
                @update:model-value="fetchCheck()"
              >
                <template v-slot:prepend>
                  <q-icon
                    name="mdi-clock-outline"
                    style="color: var(--q-primary)"
                  />
                </template>
              </q-select>
            </div> -->
            <!-- </div>
        </div>

        <div class="col-12">
          <div class="row q-col-gutter-sm"> -->
            <div class="col-12 col-md-3 col-sm-6 inputgreen">
              <datepicker
                v-model="formDataStudy.leaveEndDate"
                :locale="'th'"
                autoApply
                hide-bottom-space
                @update:model-value="fetchCheck()"
                borderless
                :enableTimePicker="false"
                week-start="0"
                :min-date="formDataStudy.leaveStartDate"
              >
                <template #year="{ year }">
                  {{ year + 543 }}
                </template>
                <template #year-overlay-value="{ value }">
                  {{ parseInt(value + 543) }}
                </template>
                <template #trigger>
                  <q-input
                    outlined
                    dense
                    ref="leaveEndDateRef"
                    for="leaveEndDateRef"
                    hide-bottom-space
                    bg-color="white"
                    class="full-width datepicker"
                    :model-value="
                      formDataStudy.leaveEndDate != null
                        ? date2Thai(formDataStudy.leaveEndDate)
                        : null
                    "
                    :label="`${'วันที่สิ้นสุด'}`"
                    :rules="[(val:string) => !!val || `${'กรุณาเลือกวันที่สิ้นสุด'}`]"
                  >
                    <template v-slot:prepend>
                      <q-icon
                        name="event"
                        class="cursor-pointer"
                        style="color: var(--q-primary)"
                      >
                      </q-icon>
                    </template>
                  </q-input>
                </template>
              </datepicker>
            </div>

            <!-- <div class="col-12 col-sm-3  inputgreen">
              <q-select
                v-if="!checkDate"
                outlined
                dense
                bg-color="white"
                v-model="formDataStudy.leaveRangeEnd"
                :options="dataStore.rangeOptions.filter((items:any)=> items.id !== 'AFTERNOON')"
                emit-value
                map-options
                option-value="id"
                option-label="name"
                @update:model-value="fetchCheck()"
              >
                <template v-slot:prepend>
                  <q-icon
                    name="mdi-clock-outline"
                    style="color: var(--q-primary)"
                  />
                </template>
              </q-select>
            </div> -->
            <!-- </div>
        </div>

        <div class="full-width">
          <div class="q-col-gutter-sm row"> -->
            <div class="col-12 col-md-3 col-sm-6">
              <q-input
                :bottom-slots="!isLeave ? true : false"
                :color="!isLeave ? 'red' : 'black'"
                :bg-color="!isLeave ? 'red-2' : 'white'"
                :border-color="!isLeave ? 'red' : 'gray'"
                :input-class="!isLeave ? dateEndInputStyle : ''"
                dense
                outlined
                ref="leaveTotalRef"
                for="leaveTotalRef"
                v-model="leaveText"
                label="มีกำหนด"
                readonly
              >
                <template v-slot:hint>
                  <span style="color: red">
                    {{ !isLeave ? reasonLeave : "" }}
                  </span>
                </template>
              </q-input>
            </div>
          </div>
        </div>

        <div class="full-width">
          <div class="q-col-gutter-sm row">
            <div class="col-12 col-md-3 col-sm-6">
              <datepicker
                autoApply
                borderless
                week-start="0"
                readonly
                :enableTimePicker="false"
                :locale="'th'"
              >
                <template #year="{ year }">
                  {{ year + 543 }}
                </template>
                <template #year-overlay-value="{ value }">
                  {{ parseInt(value + 543) }}
                </template>
                <template #trigger>
                  <q-input
                    ref="leavegovernmentDateRef"
                    class="full-width"
                    bg-color="white"
                    outlined
                    readonly
                    dense
                    hide-bottom-space
                    :label="`${'วันที่เข้ารับราชการ'}`"
                    :model-value="
                      dataStore.dateAppoint != null
                        ? date2Thai(dataStore.dateAppoint)
                        : null
                    "
                    :rules="[
                    (val:string) => !!val || `${'กรุณาเลือกวันที่เข้ารับราชการ'}`,
                  ]"
                  >
                    <template v-slot:prepend>
                      <q-icon
                        name="event"
                        class="cursor-pointer"
                        style="color: var(--black)"
                      >
                      </q-icon>
                    </template>
                  </q-input>
                </template>
              </datepicker>
            </div>

            <div class="col-12 col-md-3 col-sm-6">
              <datepicker
                autoApply
                borderless
                readonly
                week-start="0"
                :enableTimePicker="false"
                :locale="'th'"
              >
                <template #year="{ year }">
                  {{ year + 543 }}
                </template>
                <template #year-overlay-value="{ value }">
                  {{ parseInt(value + 543) }}
                </template>
                <template #trigger>
                  <q-input
                    ref="leavebirthDateRef"
                    class="full-width"
                    bg-color="white"
                    outlined
                    dense
                    readonly
                    hide-bottom-space
                    :label="`${'วันเดือนปีเกิด'}`"
                    :model-value="
                      dataStore.birthDate != null
                        ? date2Thai(dataStore.birthDate)
                        : null
                    "
                  >
                    <template v-slot:prepend>
                      <q-icon
                        name="event"
                        class="cursor-pointer"
                        style="color: var(--black)"
                      >
                      </q-icon>
                    </template>
                  </q-input>
                </template>
              </datepicker>
            </div>

            <div class="col-12 col-md-3 col-sm-6">
              <q-input
                :model-value="dataStore.salary"
                ref="leaveSalaryRef"
                bg-color="white"
                dense
                outlined
                readonly
                label="เงินเดือนปัจจุบัน"
              />
            </div>

            <div class="col-12 col-md-3 col-sm-6">
              <q-input
                :model-value="dataStore.salaryText"
                ref="leaveSalaryRef"
                bg-color="white"
                dense
                readonly
                outlined
                label="เงินเดือนปัจจุบัน (ตัวอักษร)"
                hide-bottom-space
                :rules="[(val:string) => !!val || `${'กรุณากรอกเงินเดือนปัจจุบัน'}`]"
              />
            </div>
          </div>
        </div>

        <div class="full-width">
          <div class="q-col-gutter-sm row">
            <div class="col-12 col-md-4 col-sm-12 inputgreen">
              <q-input
                v-model="formDataStudy.studyDayUniversityName"
                ref="studyDayUniversityNameRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                label="ชื่อสถานศึกษา"
                hide-bottom-space
                :rules="[(val:string) => !!val || `${'กรุณากรอกชื่อสถานศึกษา'}`]"
              />
            </div>

            <div class="col-12 col-md-4 col-sm-6 inputgreen">
              <q-input
                v-model="formDataStudy.studyDayDegreeLevel"
                ref="studyDayDegreeLevelRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                label="ชั้นปริญญา"
                hide-bottom-space
                :rules="[(val:string) => !!val || `${'กรุณากรอกชั้นปริญญา'}`]"
              />
            </div>

            <div class="col-12 col-md-4 col-sm-6 inputgreen">
              <q-input
                v-model="formDataStudy.studyDaySubject"
                ref="studyDaySubjectRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                label="ศึกษาวิชา"
                hide-bottom-space
                :rules="[(val:string) => !!val || `${'กรุณากรอกศึกษาวิชา'}`]"
              />
            </div>

            <div class="col-12 col-md-4 col-sm-6 inputgreen">
              <q-input
                v-model="formDataStudy.studyDayCountry"
                ref="studyDayCountryRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                label="ประเทศ"
                hide-bottom-space
                :rules="[(val:string) => !!val || `${'กรุณากรอกประเทศ'}`]"
              />
            </div>

            <div class="col-12 col-md-4 col-sm-6 inputgreen">
              <q-input
                v-model="formDataStudy.studyDayScholarship"
                ref="studyDayScholarshipRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                label="ด้วยทุน"
                hide-bottom-space
                :rules="[(val:string) => !!val || `${'กรุณากรอกด้วยทุน'}`]"
              />
            </div>
          </div>
        </div>

        <div class="full-width">
          <div class="q-col-gutter-sm row">
            <div class="col-12 col-md-4 col-sm-12 inputgreen">
              <q-input
                v-model="dataStore.telephoneNumber"
                ref="leaveNumberRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                unmasked-value
                hide-bottom-space
                mask="(###)-###-####"
                label="หมายเลขโทรศัพท์ที่ติดต่อได้"
                :rules="[
                (val:string) => !!val || `${'กรุณากรอกหมายเลขโทรศัพท์ที่ติดต่อได้'}`,
              ]"
              />
            </div>

            <div class="col-12 col-md-8 col-sm-12 inputgreen">
              <q-input
                v-model="dataStore.currentAddress"
                ref="leaveAddressRef"
                bg-color="white"
                dense
                outlined
                :readonly="!edit || statusCheck === 'NEW'"
                label="ที่อยู่ที่ติดต่อได้ระหว่างลา"
                hide-bottom-space
                :rules="[
                (val:string) => !!val || `${'กรุณากรอก ที่อยู่ที่ติดต่อได้ระหว่างลา'}`,
              ]"
              />
            </div>
          </div>
        </div>

        <div class="col-12 inputgreen">
          <q-input
            v-model="formDataStudy.leaveDetail"
            :readonly="!edit || statusCheck === 'NEW'"
            bg-color="white"
            dense
            outlined
            type="textarea"
            label="สาเหตุการลา"
          />
        </div>

        <div class="col-12" v-if="statusCheck != 'NEW'">
          <q-file
            v-model="formDataStudy.leaveDocument"
            bg-color="white"
            multiple
            dense
            outlined
            use-chips
            @added="fileUploadDoc"
            label="เอกสารประกอบ"
          >
            <template v-slot:prepend>
              <q-icon name="attach_file" color="primary" />
            </template>
          </q-file>
          <div class="col-12 q-mt-sm" v-if="data">
            <div class="col-12 col-md-12 col-sm-12">
              <q-card>
                <q-list
                  separator
                  v-if="leaveDocumentList && leaveDocumentList.length > 0"
                >
                  <q-item
                    v-for="(document, index) in leaveDocumentList"
                    :key="index"
                    class="q-my-xs"
                  >
                    <q-item-section>
                      <q-item-label class="row items-baseline">
                        <div class="col">
                          {{ "เอกสารแนบที่ " + (index + 1) }}
                        </div>
                        <div>
                          <q-btn
                            :href="document.path"
                            target="_blank"
                            outline
                            flat
                            dense
                            color="blue"
                            icon="mdi-download"
                            size="12px"
                            class="q-mr-md"
                          >
                            <q-tooltip>ดาวน์โหลดไฟล์</q-tooltip>
                          </q-btn>
                        </div>
                        <div>
                          <q-btn
                            @click="clickDelete(leaveId, document.docId)"
                            target="_blank"
                            outline
                            color="red"
                            flat
                            dense
                            icon="delete"
                            size="12px"
                          >
                            <q-tooltip>ลบไฟล์</q-tooltip>
                          </q-btn>
                        </div>
                      </q-item-label>
                    </q-item-section>
                  </q-item>
                </q-list>
              </q-card>
            </div>
          </div>
        </div>
      </div>
    </q-card>

    <q-separator class="q-mt-sm" />

    <div class="row col-12 q-pt-md">
      <q-space />
      <!-- <div v-if="totalCheck == 0" class="text-red q-mr-sm">**จำนวนวันลาของท่านไม่ถูกต้อง หรือวันที่ยื่นลาของท่านตรงกับวันหยุด</div> -->
      <q-btn
        v-if="!props.data || props.data.status == 'DRAFT'"
        id="onSubmit"
        type="submit"
        unelevated
        dense
        class="q-px-md items-center btnBlue"
        label="บันทึก"
        :disable="!isLeave"
        ><q-tooltip>บันทึกแบบร่าง</q-tooltip></q-btn
      >
      <q-btn
        v-if="data && statusCheck != 'NEW'"
        id="onSubmit"
        type="button"
        unelevated
        dense
        class="q-px-md items-center q-ml-sm"
        color="primary"
        label="ยื่นใบลา"
        @click="onConfirm()"
        ><q-tooltip>ยื่นใบลา</q-tooltip></q-btn
      >
    </div>
  </form>
</template>
