// src/stores/counter.ts
import { defineStore, storeToRefs } from 'pinia';
import { useCommonStore } from './modules/common';

// 类型安全的实现方式
const modulesFiles = import.meta.glob('./modules/**/*.ts', { eager: true });
const modules = Object.entries(modulesFiles).reduce(
  (acc: { [key: string]: any }, [path, module]) => {
    const moduleName = path.replace(/^\.\/modules\/(.*)\.\w+$/, '$1');
    acc[moduleName] = (module as any).default;
    return acc;
  },
  {}
);
export const useCounterStore = defineStore('counter', () => {
  // 引入 common 模块
  const commonStore = useCommonStore();
  const ques = storeToRefs(commonStore);

  // 暴露 fetchQuestionInfo 方法
  const { fetchQuestionInfo, setQuestionInfo } = commonStore;
  // 返回需要暴露的内容
  return { commonStore, modules, fetchQuestionInfo, ...ques, setQuestionInfo };
});
