<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar, type QTableColumn } from "quasar";

import { useRoute } from "vue-router";
import { checkPermission } from "@/utils/permissions";
import { useCounterMixin } from "@/stores/mixin";
import http from "@/plugins/http";
import config from "@/app.config";

import type {
  DetailData,
  DataOptionLeave,
  DataOption,
} from "@/modules/04_registryPerson/interface/index/leave";
import type {
  DataLeave,
  DataLeaveType,
} from "@/modules/04_registryPerson/interface/response/Main";

import DialogHeader from "@/components/DialogHeader.vue";
import DialogHistory from "@/modules/04_registryPerson/components/detail/DialogHistory.vue";

/**props*/
const isLeave = defineModel<boolean>("isLeave", {
  required: true,
});
const route = useRoute();

const $q = useQuasar();
const mixin = useCounterMixin();
const {
  dialogConfirm,
  messageError,
  showLoader,
  hideLoader,
  success,
  date2Thai,
  dateToISO,
  pathRegistryEmp,
  onSearchDataTable,
  dialogRemove,
} = mixin;

const profileId = ref<string>(
  route.params.id ? route.params.id.toString() : ""
);
const empType = ref<string>(pathRegistryEmp(route.name?.toString() ?? ""));
const id = ref<string>("");

const mode = ref<string>("table");
const filterKeyword = ref<string>("");

const modal = ref<boolean>(false);
const edit = ref<boolean>(false);
const modalHistory = ref<boolean>(false);

const typeLeave = ref<DataOptionLeave | undefined | null>(); //ประเภทการลา
const dateRange = ref<[Date, Date]>([new Date(), new Date()]); //วัน เดือน ปีที่ล
const numLeave = ref<number>(1); //จำนวนวันที่ลา
const statLeave = ref<string>(""); //สถานะการลา
const reason = ref<string>(""); //เหตุผล
const numUsedLeave = ref<number | undefined>(0);
const typeLeaveOption = ref<DataOptionLeave[]>([]);
const typeLeaveOptionFilter = ref<DataOptionLeave[]>([]);
const statLeaveOption = ref<DataOption[]>([
  { id: "approve", name: "ผ่านการอนุมัติ" },
  { id: "reject", name: "ไม่ผ่านการอนุมัติ" },
  { id: "cancel", name: "ยกเลิก" },
  { id: "waitting", name: "รออนุมัติ" },
]);
const statLeaveOptionFilter = ref<DataOption[]>([
  { id: "approve", name: "ผ่านการอนุมัติ" },
  { id: "reject", name: "ไม่ผ่านการอนุมัติ" },
  { id: "cancel", name: "ยกเลิก" },
  { id: "waitting", name: "รออนุมัติ" },
]);

const baseColumns = ref<QTableColumn[]>([
  {
    name: "no",
    align: "left",
    label: "ลำดับ",
    sortable: false,
    field: "no",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "typeLeave",
    align: "left",
    label: "ประเภทการลา",
    sortable: true,
    field: "typeLeave",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "dateLeave",
    align: "left",
    label: "วัน เดือน ปี ที่ลา",
    sortable: true,
    field: "dateLeave",
    headerStyle: "font-size: 14px",
    format(val, row) {
      return dateThaiRange([row.dateStartLeave, row.dateEndLeave]) || "";
    },
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "numLeave",
    align: "left",
    label: "จำนวนวันลา",
    sortable: true,
    field: "numLeave",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a
        .toString()
        .localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "status",
    align: "left",
    label: "สถานะ",
    sortable: true,
    field: "status",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    format(val, row) {
      return statusLeave(val);
    },
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "reason",
    align: "left",
    label: "เหตุผล",
    sortable: true,
    field: "reason",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "lastUpdateFullName",
    align: "left",
    label: "ผู้ดำเนินการ",
    sortable: true,
    field: "lastUpdateFullName",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "lastUpdatedAt",
    align: "left",
    label: "วันที่แก้ไข",
    sortable: true,
    field: "lastUpdatedAt",
    format: (v) => date2Thai(v, false, true),
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
]);
const baseVisibleColumns = ref<string[]>([
  "no",
  "typeLeave",
  "dateLeave",
  "numLeave",
  "status",
  "reason",
  "lastUpdateFullName",
  "lastUpdatedAt",
]);

//Table
const rows = ref<DetailData[]>([]);
const rowsMain = ref<DetailData[]>([]);
const columns = ref<QTableColumn[]>(
  baseColumns.value.filter((e: QTableColumn) => e.name !== "lastUpdateFullName")
);
const visibleColumns = ref<String[]>(
  baseVisibleColumns.value.filter((e: string) => e !== "lastUpdateFullName")
);
const pagination = ref({
  sortBy: "lastUpdatedAt",
});

const columnsHistory = ref<QTableColumn[]>(baseColumns.value);
const visibleColumnsHistory = ref<string[]>(baseVisibleColumns.value);

/** รายการประเภทการลาของ ลาไปศึกษา ฝึกอบรม ปฎิบัติการวิจัย หรือดูงาน*/
const leaveSubTypeName = ref<string>("");
const optionSubTypeName = ref<string[]>([
  "ศึกษาต่อ",
  "ฝึกอบรม",
  "ปฎิบัติการวิจัย",
  "ดูงาน",
]);

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

/** function fetch ข้อมูลรายการลา*/
async function getData() {
  showLoader();
  await http
    .get(config.API.profileNewLeaveById(profileId.value, empType.value))
    .then(async (res) => {
      const data = await res.data.result;
      const baseData = data.map((item: DataLeave) => ({
        ...item,
        id: item.id,
        typeLeave: item.leaveType.name,
        codeLeave: item.leaveType.code,
        code: item.leaveType.refCommandDate,
        dateStartLeave: item.dateLeaveStart,
        dateEndLeave: item.dateLeaveEnd,
        numLeave: item.leaveDays,
        typeLeaveId: item.leaveTypeId,
      }));
      rowsMain.value = baseData;

      serchDataTable();
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(() => {
      hideLoader();
    });
}

/** function เปิด dialog ข้อมูลการลา*/
function openDialogAdd() {
  modal.value = true;
  edit.value = false;
  showLoader();
  http
    .get(config.API.profileNewLeaveType())
    .then((res) => {
      const dataOp = res.data.result.map((item: DataLeaveType) => ({
        id: item.id,
        name: item.name,
        code: item.code,
      }));

      typeLeaveOption.value = dataOp;
      typeLeaveOptionFilter.value = dataOp;
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(() => {
      hideLoader();
    });
}

/**
 * ฟังชั้นดูข้อมูลประวัติแก้ไขข้อมูลที่เลือก
 * @param row ข้อมูล row ที่ดูประวัติการแก้ไข
 */
function fetchTypeLeave() {
  showLoader();
  http
    .get(config.API.profileNewLeaveType())
    .then((res) => {
      const dataOp = res.data.result.map((item: DataOption) => ({
        id: item.id,
        name: item.name,
      }));

      typeLeaveOption.value = dataOp;
      typeLeaveOptionFilter.value = dataOp;
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(() => {
      hideLoader();
    });
}

/**
 * function เปิด dialog แก้ไขข้อมูลการลา
 * @param props ข้อมูลที่ต้องการแก้ไข
 */
function openDialogEdit(props: DetailData) {
  edit.value = true;
  modal.value = true;
  id.value = props.id;
  typeLeave.value = {
    id: props.typeLeaveId,
    name: props.typeLeave,
    code: props.codeLeave,
  };
  leaveSubTypeName.value = props.leaveSubTypeName;
  coupleDayLevelCountry.value = props.coupleDayLevelCountry;
  statLeave.value = props.status;
  reason.value = props.reason;
  dateRange.value = [
    new Date(props.dateStartLeave as Date),
    new Date(props.dateEndLeave as Date),
  ];
  numLeave.value = props.numLeave;
  fetchTypeLeave();
}

/** function ยืนยันการบันทึกข้อมูล*/
function onSubmit() {
  dialogConfirm($q, async () => {
    showLoader();
    const url = edit.value
      ? config.API.profileNewLeaveById(id.value, empType.value)
      : config.API.profileNewLeave(empType.value);

    const methods = edit.value ? http.patch : http.post;

    const body = {
      leaveTypeId: typeLeave.value?.id,
      leaveSubTypeName:
        typeLeave.value?.code === "LV-008" ? leaveSubTypeName.value : undefined,
      coupleDayLevelCountry:
        typeLeave.value?.code === "LV-010" ? coupleDayLevelCountry.value : undefined,
      dateLeaveStart: dateToISO(dateRange.value[0]),
      dateLeaveEnd: dateToISO(dateRange.value[1]),
      leaveDays: numLeave.value,
      leaveCount: 0,
      totalLeave: 0,
      status: statLeave.value,
      reason: reason.value,
      profileId: edit.value
        ? undefined
        : empType.value === ""
        ? profileId.value
        : undefined,
      profileEmployeeId: edit.value
        ? undefined
        : empType.value !== ""
        ? profileId.value
        : undefined,
    };

    await methods(url, body)
      .then(async () => {
        await getData();
        success($q, "บันทึกข้อมูลสำเร็จ");
        closeDialog();
      })
      .catch((err) => {
        messageError($q, err);
      })
      .finally(() => {
        hideLoader();
      });
  });
}

/**
 * function ค้นหา คำใน option
 * @param val คำค้นหา
 * @param update function
 * @param filtername type select
 */
function filterSelector(val: string, update: Function, filtername: string) {
  switch (filtername) {
    case "typeLeaveOption":
      update(() => {
        typeLeaveOption.value = typeLeaveOptionFilter.value.filter(
          (v: DataOptionLeave) =>
            v.name.toLowerCase().indexOf(val.toLowerCase()) > -1
        );
      });
      break;
    case "statLeaveOption":
      update(() => {
        statLeaveOption.value = statLeaveOptionFilter.value.filter(
          (v: DataOption) =>
            v.name.toLowerCase().indexOf(val.toLowerCase()) > -1
        );
      });
      break;
    default:
      break;
  }
}

/**
 * แปลงช่วงวันที่ถ้า2ค่าเป็นวันเดียวกันจะโชววันเดียวแต่ถ้าไม่เท่ากันจะแสดงเป็นช่วง
 * @param val ช่วงวันที่
 */
function dateThaiRange(val: [Date, Date]) {
  if (val === null) {
  } else if (date2Thai(val[0]) === date2Thai(val[1])) {
    return `${date2Thai(val[0])}`;
  } else {
    return `${date2Thai(val[0])} - ${date2Thai(val[1])} `;
  }
}

/**
 * ฟังชั้นดูข้อมูลประวัติแก้ไขข้อมูลที่เลือก
 * @param id id รายการ
 */
function openDialogHistory(idOrder: string) {
  modalHistory.value = true;
  id.value = idOrder;
}

async function fetchDataHistory() {
  showLoader();
  try {
    const res = await http.get(
      config.API.profileNewLeaveHistory(id.value, empType.value)
    );

    const data = res.data.result.map((e: DataLeave) => ({
      ...e,
      id: e.id,
      typeLeave: e.leaveType.name,
      code: e.leaveType.refCommandDate,
      dateStartLeave: e.dateLeaveStart,
      dateEndLeave: e.dateLeaveEnd,
      numLeave: e.leaveDays,
      status: e.status,
      reason: e.reason,
      typeLeaveId:
        e.typeLeaveId !== "00000000-0000-0000-0000-000000000000"
          ? e.typeLeaveId
          : "",
    }));
    return data;
  } catch (err) {
    messageError($q, err);
  } finally {
    hideLoader();
  }
}

/** ฟังก์ค้นหาข้อมูลรายการวินัย */
function serchDataTable() {
  rows.value = onSearchDataTable(
    filterKeyword.value,
    rowsMain.value,
    columns.value ? columns.value : []
  );
}

/** ปิด dialog ข้อมูลการลา*/
function closeDialog() {
  modal.value = false;
  edit.value = false;
  id.value = "";
  typeLeave.value = null;
  statLeave.value = "";
  reason.value = "";
  dateRange.value = [new Date(), new Date()];
  numLeave.value = 1;
  numUsedLeave.value = 0;
  leaveSubTypeName.value = "";
  coupleDayLevelCountry.value = "";
}

function statusLeave(val: string) {
  switch (val) {
    case "waitting":
      return "รออนุมัติ";
    case "reject":
      return "ไม่ผ่านการอนุมัติ";
    case "approve":
      return "ผ่านการอนุมัติ";
    case "cancel":
      return "ยกเลิก";
    default:
      return "-";
  }
}

function clickEditRowType() {
  const filter = typeLeaveOptionFilter.value.filter(
    (v: DataOptionLeave) => v.id == typeLeave.value?.id
  );
  if (filter.length > 0) {
    numUsedLeave.value = filter[0].totalLeave;
  }
}

function handleDelete(id: string) {
  dialogRemove($q, async () => {
    showLoader();
    try {
      await http.patch(
        config.API.profileNewLeaveUpdateDelete(empType.value) + `${id}`
      );
      await getData();
      success($q, "ลบข้อมูลสำเร็จ");
    } catch (err) {
      messageError($q, err);
    } finally {
      hideLoader();
    }
  });
}

/** ทำงานเมื่อ Components ถูกเรียกใช้งาน*/
onMounted(() => {
  getData();
});
</script>

<template>
  <div class="row items-center q-gutter-x-sm q-pb-sm">
    <q-btn
      v-if="isLeave == false && checkPermission($route)?.attrIsUpdate"
      dense
      color="primary"
      icon="add"
      flat
      round
      @click="openDialogAdd()"
      ><q-tooltip>เพิ่มข้อมูล</q-tooltip></q-btn
    >

    <q-space />
    <q-input
      standout
      dense
      v-model="filterKeyword"
      ref="filterRef"
      outlined
      placeholder="ค้นหา"
      @keydown.enter.prevent="serchDataTable"
    >
      <template v-slot:append>
        <q-icon name="search" />
      </template>
    </q-input>
    <q-select
      v-model="visibleColumns"
      multiple
      outlined
      dense
      options-dense
      :display-value="$q.lang.table.columns"
      emit-value
      map-options
      :options="columns"
      option-value="name"
      style="min-width: 140px"
    />
    <q-btn-toggle
      v-model="mode"
      dense
      class="no-shadow toggle-borderd"
      toggle-color="grey-4"
      :options="[
        { value: 'table', slot: 'table' },
        { value: 'card', slot: 'card' },
      ]"
    >
      <template v-slot:table>
        <q-icon
          name="format_list_bulleted"
          size="24px"
          :style="{
            color: mode === 'table' ? '#787B7C' : '#C9D3DB',
          }"
        />
      </template>

      <template v-slot:card>
        <q-icon
          name="mdi-view-grid-outline"
          size="24px"
          :style="{
            color: mode === 'card' ? '#787B7C' : '#C9D3DB',
          }"
        />
      </template>
    </q-btn-toggle>
  </div>

  <d-table
    ref="table"
    flat
    bordered
    dense
    :columns="columns"
    :rows="rows"
    :grid="mode === 'card'"
    v-model:pagination="pagination"
    :visible-columns="visibleColumns"
  >
    >
    <template v-slot:header="props">
      <q-tr :props="props">
        <q-th auto-width></q-th>
        <q-th v-for="col in props.cols" :key="col.name" :props="props">
          <span class="text-weight-medium">{{ col.label }}</span>
        </q-th>
      </q-tr>
    </template>
    <template v-slot:body="props" v-if="mode === 'table'">
      <q-tr :props="props">
        <q-td auto-width>
          <q-btn
            flat
            dense
            round
            color="deep-purple"
            icon="mdi-history"
            @click="openDialogHistory(props.row.id)"
          >
            <q-tooltip>ประวัติแก้ไขการลา</q-tooltip>
          </q-btn>
          <q-btn
            v-if="isLeave == false && checkPermission($route)?.attrIsUpdate"
            flat
            dense
            round
            color="edit"
            icon="edit"
            clickable
            @click="openDialogEdit(props.row)"
          >
            <q-tooltip>แก้ไขข้อมูล</q-tooltip>
          </q-btn>
          <q-btn
            v-if="!isLeave && checkPermission($route)?.attrIsDelete"
            color="red"
            flat
            dense
            round
            icon="delete"
            @click="handleDelete(props.row.id)"
          >
            <q-tooltip>ลบข้อมูล</q-tooltip>
          </q-btn>
        </q-td>
        <q-td
          v-for="col in props.cols"
          :key="col.id"
          :class="props.row.isEntry ? 'text-grey' : ''"
        >
          <div v-if="col.name === 'no'">
            {{ props.rowIndex + 1 }}
          </div>

          <div v-else>
            {{ col.value ? col.value : "-" }}
          </div>
        </q-td>
      </q-tr>
    </template>
    <template v-slot:item="props" v-else>
      <div class="q-pa-xs col-xs-12 col-sm-4 col-md-3">
        <q-card flat bordered>
          <q-card-actions align="right" class="bg-grey-3">
            <q-btn
              color="deep-purple"
              icon="mdi-history"
              flat
              round
              @click="openDialogHistory(props.row.id)"
            >
              <q-tooltip>ประวิติแก้ไขการลา</q-tooltip>
            </q-btn>
            <q-btn
              v-if="isLeave == false && checkPermission($route)?.attrIsUpdate"
              color="edit"
              icon="edit"
              flat
              round
              @click="openDialogEdit(props.row)"
            >
              <q-tooltip>แก้ไขข้อมูล</q-tooltip>
            </q-btn>
            <q-btn
              v-if="!isLeave && checkPermission($route)?.attrIsDelete"
              color="red"
              flat
              dense
              round
              icon="delete"
              @click="handleDelete(props.row.id)"
            >
              <q-tooltip>ลบข้อมูล</q-tooltip>
            </q-btn>
          </q-card-actions>
          <q-separator />
          <q-list>
            <div
              :class="`row q-pa-sm`"
              :style="`background-color: ${index % 2 !== 0 ? '#FAFAFA' : ''}`"
              v-for="(col, index) in props.cols"
              :key="col.name"
            >
              <div class="col text-grey-6">
                <div>{{ col.label }}</div>
              </div>

              <div class="col">
                <div v-if="col.name === 'no'">
                  {{ props.rowIndex + 1 }}
                </div>
                <div v-else>{{ col.value ? col.value : "-" }}</div>
              </div>
            </div>
          </q-list>
        </q-card>
      </div>
    </template>
  </d-table>

  <!-- dialog add edit -->
  <q-dialog v-model="modal" persistent>
    <q-card>
      <q-form @submit.prevent greedy @validation-success="onSubmit()">
        <DialogHeader
          :tittle="edit ? 'แก้ไขข้อมูลการลา' : 'เพิ่มข้อมูลการลา'"
          :close="closeDialog"
        />
        <q-separator color="grey-4" />

        <q-card-section>
          <div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
            <div class="col-xs-6 col-sm-6 col-md-6">
              <q-select
                ref="typeLeaveRef"
                class="full-width inputgreen cursor-pointer"
                outlined
                dense
                lazy-rules
                v-model="typeLeave"
                :rules="[(val:string) => !!val || `${'กรุณาเลือกประเภทการลา'}`]"
                hide-bottom-space
                :label="`${'ประเภทการลา'}`"
                @update:modelValue="clickEditRowType"
                map-options
                option-label="name"
                :options="typeLeaveOption"
                option-value="id"
                use-input
                hide-selected
                fill-input
                input-debounce="0"
                @filter="(inputValue:string,
                      doneFn:Function) => filterSelector(inputValue, doneFn,'typeLeaveOption'
                      ) "
              />
            </div>

            <div
              class="col-xs-6 col-sm-6 col-md-6"
              v-if="
                typeLeave?.code === 'LV-008' || typeLeave?.code === 'LV-010'
              "
            >
              <q-select
                v-if="typeLeave?.code === 'LV-008'"
                ref="typeLeaveRef"
                class="full-width inputgreen cursor-pointer"
                outlined
                dense
                lazy-rules
                :label="`${'ประเภท'}`"
                :rules="[(val:string) => !!val || `${'กรุณาเลือกประเภท'}`]"
                v-model="leaveSubTypeName"
                :options="optionSubTypeName"
                option-value="id"
                option-label="name"
                emit-value
                map-options
                hide-bottom-space
              />
              <q-input
                v-if="typeLeave?.code === 'LV-010'"
                ref="numLeaveRef"
                class="full-width inputgreen cursor-pointer"
                outlined
                dense
                lazy-rules
                v-model="coupleDayLevelCountry"
                :rules="[(val:string) => !!val || `${'กรุณากรอกประเทศที่ลาติดตามคู่สมรส'}`]"
                hide-bottom-space
                :label="`${'ประเทศที่ลาติดตามคู่สมรส'}`"
              />
            </div>
            <div class="col-xs-6 col-sm-6 col-md-6">
              <datepicker
                :readonly="!typeLeave"
                menu-class-name="modalfix"
                v-model="dateRange"
                :locale="'th'"
                autoApply
                :enableTimePicker="false"
                week-start="0"
                range
              >
                <template #year="{ year }">{{ year + 543 }}</template>
                <template #year-overlay-value="{ value }">{{
                  parseInt(value + 543)
                }}</template>
                <template #trigger>
                  <q-input
                    :readonly="!typeLeave"
                    class="full-width inputgreen cursor-pointer"
                    outlined
                    dense
                    ref="dateRangeRef"
                    :model-value="dateThaiRange(dateRange)"
                    :rules="[(val:string) => !!val || `${'กรุณาเลือกวัน เดือน ปีที่ลา'}`]"
                    hide-bottom-space
                    :label="`${'วัน เดือน ปีที่ลา'}`"
                  >
                    <template v-slot:prepend>
                      <q-icon
                        name="event"
                        class="cursor-pointer"
                        color="primary"
                      >
                      </q-icon>
                    </template>
                  </q-input>
                </template>
              </datepicker>
            </div>
            <div class="col-xs-6 col-sm-6 col-md-6">
              <q-input
                ref="numLeaveRef"
                class="full-width inputgreen cursor-pointer"
                outlined
                dense
                lazy-rules
                v-model="numLeave"
                type="number"
                :rules="[(val:string) => !!val || `${'กรุณากรอกจำนวนวันที่ลา'}`]"
                hide-bottom-space
                :label="`${'จำนวนวันที่ลา'}`"
              />
            </div>
            <div class="col-xs-6 col-sm-6 col-md-6">
              <q-select
                ref="statLeaveRef"
                class="full-width inputgreen cursor-pointer"
                outlined
                dense
                lazy-rules
                v-model="statLeave"
                :rules="[(val:string) => !!val || `${'กรุณาเลือกสถานะการลา'}`]"
                hide-bottom-space
                :label="`${'สถานะการลา'}`"
                emit-value
                map-options
                option-label="name"
                :options="statLeaveOption"
                option-value="id"
                use-input
                input-debounce="0"
                @filter="(inputValue:string,
                      doneFn:Function) => filterSelector(inputValue, doneFn,'statLeaveOption'
                      ) "
              />
            </div>
            <div class="col-xs-12 col-sm-12 col-md-12">
              <q-input
                ref="reasonRef"
                class="full-width inputgreen cursor-pointer"
                outlined
                dense
                lazy-rules
                v-model="reason"
                type="textarea"
                :rules="[(val:string) => !!val || `${'กรุณากรอกเหตุผล'}`]"
                hide-bottom-space
                :label="`${'เหตุผล'}`"
              />
            </div>
          </div>
        </q-card-section>
        <q-separator />
        <q-card-actions align="right">
          <q-btn label="บันทึก" id="onSubmit" type="submit" color="public">
            <q-tooltip>บันทึกข้อมูล</q-tooltip>
          </q-btn>
        </q-card-actions>
      </q-form>
    </q-card>
  </q-dialog>

  <DialogHistory
    v-model:modal="modalHistory"
    :title="`ประวัติแก้ไขการลา`"
    :columns="columnsHistory"
    :visible-columns="visibleColumnsHistory"
    :fetch-data="fetchDataHistory"
  />
</template>

<style scoped></style>
