import { defineStore } from "pinia";
import { ref } from "vue";
import type {
  DataResponse,
  DataRow,
} from "../interface/response/insignia/Insignia";
import { useCounterMixin } from "@/stores/mixin";

const { date2Thai } = useCounterMixin();

export const useInsigniaDataStore = defineStore("insigniaData", () => {
  const row = ref<DataRow[]>([]);

  async function fetchData(data: DataResponse[], insigniaType?: string) {
    const list = data.map((e) => ({
      ...e,
      insigniaType: insigniaType,
      createdAt: e.createdAt ? date2Thai(e.createdAt) : "",
      lastUpdatedAt: e.lastUpdatedAt ? date2Thai(e.lastUpdatedAt) : "",
    }));
    list;
    row.value = list;
  }

  return {
    fetchData,
    row,
  };
});
