// 我的场景

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

export const useMySceneStore = defineStore(
  "myScene",
  () => {
    // 我的场景
    const mySceneData = ref({
      userId: "",
      dataList: [],
    });

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

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

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

    // 设置我的场景
    const setMySceneData = (dataList) => {
      mySceneData.value = dataList;
    };

    // 清除我的场景
    const clearMySceneData = () => {
      mySceneData.value = {};
    };

    return {
      mySceneData,
      updateFlag,
      isUpDataList,
      setMySceneData,
      clearMySceneData,
    };
  },
  {
    // 持久化配置
    persist: true,
  }
);
