import { ref } from "vue";
import { defineStore } from "pinia";
import type { Options } from "@/modules/22_issues/interface/Main";

export const useIssueStore = defineStore("issue", () => {
  const systemOptions = ref<Options[]>([
    { label: "ทั้งหมด", value: "" },
    { label: "ระบบบริหารจัดการ", value: "MGT" },
    { label: "ระบบผู้ใช้งาน", value: "USER" },
    { label: "ระบบลงเวลา", value: "CHECKIN" },
  ]);

  const statusOptions = ref<Options[]>([
    { label: "ทั้งหมด", value: "" },
    { label: "ใหม่", value: "NEW" },
    { label: "กำลังดำเนินการ", value: "IN_PROGRESS" },
    { label: "แก้ไขแล้ว", value: "RESOLVED" },
    { label: "ปิดแล้ว", value: "CLOSED" },
  ]);

  function convertStatus(status: string) {
    let val = status.toUpperCase();
    switch (val) {
      case "NEW":
        return "ใหม่";
      case "IN_PROGRESS":
        return "กำลังดำเนินการ";
      case "RESOLVED":
        return "แก้ไขแล้ว";
      case "CLOSED":
        return "ปิดแล้ว";
      default:
        return "-";
    }
  }

  function convertSystem(system: string) {
    let val = system.toUpperCase();
    switch (val) {
      case "MGT":
        return "ระบบบริหารจัดการ";
      case "USER":
        return "ระบบผู้ใช้งาน";
      case "CHECKIN":
        return "ระบบลงเวลา";
      default:
        return "-";
    }
  }

  return { systemOptions, statusOptions, convertStatus, convertSystem };
});
