import { store } from "@/store";
import { defineStore } from "pinia";
// import { getUserList } from "@/api/auth";

export const useDictionaryStore = defineStore("dictionaryStore", () => {
  const types = [
    "defect_mana",
    "stage",
    "process_state",
    "outsource_state",
    "work_order_seq_state",
    "accessories_type",
    "danwei_type",
    "system_message_type",
    "plan_work_order_state",
    "disposal_measures_type",
    "escalation_fault_state",
    "excel_type",
    "plan_order_state",
  ];
  const dicts = ref<{ [key: string]: any[] }>({});

  // 所有的用户列表
  const allUsers = ref<any[]>([]);

  function checkAllData() {
    // if (allUsers.value.length === 0) {
    //   getUserList().then((res) => {
    //     allUsers.value = res.data || [];
    //   });
    // }
  }

  function getLableByValue(type: string, value: string) {
    const dict = dicts.value[type];
    if (dict) {
      const lable = dict.find((item: any) => item.dictValue === value);
      return lable?.dictLabel;
    }
    return "";
  }

  return {
    types,
    dicts,
    allUsers,
    checkAllData,
    getLableByValue,
  };
});

export function useDictionaryStoreHook() {
  // console.log('dicts:',useDictionaryStore(store))
  return useDictionaryStore(store);
}
