// stores/counter.js
import { defineStore } from "pinia";
import * as shopApi from "@/http/api/shop.js";

//判断是否是主店
export const isMainShop = (shopId) => {
  const shopInfo=uni.getStorageSync("shopInfo");
  if(shopInfo.isHeadShop){
    return true
  }
  if(shopInfo.shopType=='only'){
    return  true
  }
  return false
}

// 分销
export const useAccountInfoStore = defineStore("accountInfo", {
  state: () => {
    return {
      shopInfo: {},
    };
  },
  actions: {
    getShopInfo() {
      return shopApi.getShopInfo().then((res) => {
        this.shopInfo = res;
        return this.shopInfo;
      });
    },
    editShopInfo(data,autoRefresh = true) {
      return shopApi.editShopInfo(data).then((res) => {
        if(autoRefresh) {
          this.getShopInfo()
        }
        return res
      });
    },
  },
  unistorage: true, // 开启后对 state 的数据读写都将持久化
});
