// 我的展厅

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

export const useMyShowroomStore = defineStore(
  "myShowroom",
  () => {
    // 我的展厅
    const myShowroomData = ref({
      userId: "",
      dataList: [],
    });

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

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

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

    // 设置我的展厅
    const setMyShowroomData = (dataList) => {
      myShowroomData.value = dataList;
    };

    // 清除我的展厅
    const clearMyShowroomData = () => {
      myShowroomData.value = {};
    };

    return {
      myShowroomData,
      updateFlag,
      isUpDataList,
      setMyShowroomData,
      clearMyShowroomData,
    };
  },
  {
    // 持久化配置
    persist: true,
  }
);
