// 模板案例

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

export const useTemplateCaseStore = defineStore(
  "templateCase",
  () => {
    const templateCaseList = ref([]);

    /*
     * 获取模板案例信息
     */
    const getTemplatesCaseList = async (
      { type, title } = {},
      { isRefetch = false } = {}
    ) => {
      var row = templateCaseList.value.find(
        (item) => item.type == type && item.title == title
      );
      if (isRefetch === true) {
        await setTemplateCaseList({ type, title, row });
      } else {
        if (row) {
          if (!row.data || row.data.length == 0) {
            await setTemplateCaseList({ type, title, row });
          }
        } else {
          await setTemplateCaseList({ type, title });
        }
      }
      return row
        ? row.data || []
        : (
            templateCaseList.value.find(
              (item) => item.type == type && item.title == title
            ) || {}
          ).data || [];
    };

    /*
     * 设置模板案例信息
     */
    const setTemplateCaseList = async ({ type, title, row } = {}) => {};

    return {
      templateCaseList,
      getTemplatesCaseList,
      setTemplateCaseList,
    };
  },
  {
    // 持久化配置
    persist: true,
  }
);
