
import { store } from "@/store";
import quickApi, { type QuickMenu } from "@/api/account/quick";
import { usePermissionStoreHook } from "@/store/modules/permission";


export const useQuickStore = defineStore("quick", () => {
  const quickMenus = ref<QuickMenu[]>([]);

  async function getQuickMenus() {
    const res = await quickApi.getList({ isEdit: 0 });
    const obj: any = {}
    let arr = []
    for (let menu of res) {
      if (obj.hasOwnProperty(menu.menuId) || menu.status != 1 || !usePermissionStoreHook().returnMenuName(menu.menuId)) {
        continue;
      } else {
        obj[menu.menuId] = true;
        arr.push(menu)
      }
    }
    quickMenus.value = arr;
  }
  getQuickMenus()
  return {
    quickMenus, getQuickMenus
  };
});

/**
 * 用于在组件外部（如在Pinia Store 中）使用 Pinia 提供的 store 实例。
 * 官方文档解释了如何在组件外部使用 Pinia Store：
 * https://pinia.vuejs.org/core-concepts/outside-component-usage.html#using-a-store-outside-of-a-component
 */
export function useQuickStoreHook() {
  return useQuickStore(store);
}
