// 我的模板

import { defineStore } from "pinia";
import { ref, computed } from "vue";
import serviceAxios from "@/http/index";

export const useMyTemplateStore = defineStore(
  "myTemplate",
  () => {
    // 我的模板
    const myTemplateData = ref({
      userId: "",
      dataList: [],
    });

    // 更新标识
    const updateFlag = ref(false);

    const doubleCount = computed(() => {});

    // 判断数据是否可更新
    const isUpDataList = (newUserId) => {
      if (
        myTemplateData.value.dataList.length == 0 ||
        myTemplateData.value.userId != newUserId ||
        updateFlag.value == true
      ) {
        updateFlag.value = false;
        return true;
      }
      return false;
    };

    // 设置我的模板
    const setMyTemplateData = (dataList) => {
      myTemplateData.value = dataList;
    };

    // 清除我的模板
    const clearMyTemplateData = () => {
      myTemplateData.value = {};
    };

    return {
      myTemplateData,
      updateFlag,
      isUpDataList,
      setMyTemplateData,
      clearMyTemplateData,
    };
  },
  {
    // 持久化配置
    persist: true,
  }
);
