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

const { date2Thai } = useCounterMixin();

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

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