import { defineStore } from "pinia";
import { ref } from "vue";
import type { QTableProps } from "quasar";
import type { RowList, Row } from '@/modules/13_salary/interface/response/Main'
import { useCounterMixin } from "@/stores/mixin";
// store 
export const useSalaryDataStore = defineStore("salaryDataStore", () => {
  const rows = ref<RowList[]>([]);
  const visibleColumns = ref<string[]>([]);
  const columns = ref<QTableProps["columns"]>([]);

  const mixin = useCounterMixin()
  const{ date2Thai }= mixin


  function fetchDataMap(data: RowList[]) {
    rows.value = data.map((i: RowList) => ({
      id: i.id,
      period: i.period !== null ? i.period : null,
      year: i.year !== null ? i.year : null,
      isActive: i.isActive !== null ? i.isActive : null,
      isClose: i.isClose !== null ? i.isClose : null,
      effectiveDate: i.effectiveDate !== null ? i.effectiveDate : null,
      status: i.status !== null ? i.status : null,
      revisionId: i.revisionId,
    }));
  }

          /**
         * แปลง status เป็น Text
         * @param val status
         * @returns text
         */
          function statusTothai(val: string) {
            switch (val) {
                case "SPECIAL":
                    return "รอบพิเศษ";
                case "APR":
                    return "รอบเมษายน";
                case "OCT":
                    return "รอบตุลาคม";
                default:
                    return "-";
            }
        };
  return {
    rows,
    visibleColumns,
    columns,
    fetchDataMap,
    statusTothai
  };
});
