import { defineStore } from "pinia";
import { ref } from "vue";

import type { DataOption } from "@/modules/04_registryNew/interface/index/Main";
import type {
  DataType,
  DataLevel,
} from "@/modules/04_registryNew/interface/response/Main";

export const useRegistryNewDataStore = defineStore("registryNew", () => {
  const searchTypeOption = ref<DataOption[]>([
    { id: "fullName", name: "ชื่อ-นามสกุล" },
    { id: "citizenId", name: "เลขประจำตัวประชาชน" },
    // { id: "posNo", name: "ตำแหน่งเลขที่" },
    { id: "position", name: "ตำแหน่งสายงาน" },
  ]);
  const employeeClassOps = ref<DataOption[]>([
    { id: "officer", name: "ข้าราชการ กทม.สามัญ" },
    { id: "perm", name: "ลูกจ้างประจำ" },
    { id: "temp", name: "ลูกจ้างชั่วคราว" },
  ]);
  const posTypeOps = ref<DataOption[]>([]);
  const posTypeMain = ref<DataType[]>([]);
  const posLevelOps = ref<DataOption[]>([]);
  const yearOps = ref<DataOption[]>([]);
  const mode = ref<string>("card");

  function fetchType(data: DataType[]) {
    posTypeMain.value = data;
    const list: DataOption[] = data.map((e: DataType) => ({
      id: e.id,
      name: e.posTypeName,
    }));
    posTypeOps.value = list;
  }
  function fetchLevel(data: DataLevel[]) {
    const list: DataOption[] = data.map((e: DataLevel) => ({
      id: e.id,
      name: e.posLevelName,
    }));
    posLevelOps.value = list;
  }
  return {
    fetchType,
    fetchLevel,
    posTypeMain,
    searchTypeOption,
    employeeClassOps,
    posTypeOps,
    posLevelOps,
    yearOps,
    mode,
  };
});
