import { defineStore } from "pinia";
import { ref } from "vue";
import { useCounterMixin } from "@/stores/mixin";

import type { QTableProps } from "quasar";

// store ระบบวินัย >> ข้อมูลพื้นฐาน >> กรรมการ
export const useEvaluateMeetingDataStore = defineStore(
  "evaluateMeeting",
  () => {
    const mixin = useCounterMixin();
    const { date2Thai } = mixin;
    //ค้นหา คอลัมน์ คอลัมน์ที่แสดง
    const visibleColumns = ref<string[]>(["no", "round", "title", "date"]);

    // หัวตาราง
    const columns = ref<QTableProps["columns"]>([
      {
        name: "no",
        align: "left",
        label: "ลำดับ",
        sortable: false,
        field: "no",
        headerStyle: "font-size: 14px",
        style: "font-size: 14px",
      },
      {
        name: "round",
        align: "left",
        label: "ครั้งที่",
        sortable: true,
        field: "round",
        headerStyle: "font-size: 14px",
        style: "font-size: 14px",
      },
      {
        name: "title",
        align: "left",
        label: "หัวข้อการประชุม",
        sortable: true,
        field: "title",
        headerStyle: "font-size: 14px",
        style: "font-size: 14px",
      },
      {
        name: "date",
        align: "left",
        label: "วันเวลาในการประชุม",
        sortable: true,
        field: "date",
        headerStyle: "font-size: 14px",
        style: "font-size: 14px",
      },
    ]);

    // ข้อมูลในตาราง
    const rows = ref<any[]>([]);
    function fetchData(data: any[]) {
      const dataList: any[] = data.map((item: any) => ({
        id: item.id,
        createdAt: item.createdAt,
        createdUserId: item.createdUserId,
        lastUpdatedAt: item.lastUpdatedAt,
        lastUpdateUserId: item.lastUpdateUserId,
        createdFullName: item.createdFullName,
        lastUpdateFullName: item.lastUpdateFullName,
        title: item.title,
        round: item.round,
        date: `${date2Thai(item.dateStart as Date, false, true)} - ${date2Thai(
          item.dateEnd as Date,
          false,
          true
        )}`,
        result: item.result,
        duration: item.duration,
      }));
      rows.value = dataList;
    }

    return {
      visibleColumns,
      columns,
      rows,
      fetchData,
    };
  }
);
