<script setup lang="ts">
import { ref, onMounted } from "vue";
// importType
import type { QTableProps } from "quasar";
// importStroe
import { useOrderStore } from "@/modules/11_discipline/store/OrderStore";

const OrderStore = useOrderStore();

const props = defineProps({
  filterTable: {
    type: String,
    default: "",
  },
});

const columns = ref<QTableProps["columns"]>([
  {
    name: "subject",
    align: "left",
    label: "เรื่อง",
    sortable: true,
    field: "subject",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "ordernumber",
    align: "left",
    label: "เลขที่คำสั่ง",
    sortable: true,
    field: "ordernumber",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "dateOrder",
    align: "left",
    label: "สั่ง ณ วันที่/วันที่คำสั่งมีผล",
    sortable: true,
    field: "dateOrder",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "orderby",
    align: "left",
    label: "คำสั่งโดย",
    sortable: true,
    field: "orderby",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "signer",
    align: "left",
    label: "ผู้ลงนาม",
    sortable: true,
    field: "signer",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
  {
    name: "statusorder",
    align: "left",
    label: "สถานะของคำสั่ง",
    sortable: true,
    field: "statusorder",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
  },
]);
const visibleColumns = ref<string[]>([
  "subject",
  "ordernumber",
  "dateOrder",
  "orderby",
  "signer",
  "statusorder",
]);

onMounted(() => {
  OrderStore.columns = columns.value;
  OrderStore.visibleColumns = visibleColumns.value;
});

//pagination
const pagination = ref({
  descending: true,
  page: 1,
  rowsPerPage: 10,
});
</script>

<template>
  <d-table
    for="table"
    ref="table"
    :columns="columns"
    :rows="OrderStore.rows"
    :filter="props.filterTable"
    row-key="subject"
    flat
    bordered
    dense
    class="custom-header-table"
    :visible-columns="OrderStore.visibleColumns"
    v-model:pagination="pagination"
  >
    <template v-slot:header="props">
      <q-tr :props="props">
        <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">
      <q-tr :props="props" class="cursor-pointer" style="height: 40px">
        <q-td v-for="col in props.cols" :key="col.name" :props="props">
          <div>
            {{ col.value }}
          </div>
        </q-td>
      </q-tr>
    </template>
  </d-table>
</template>

<style scoped></style>
