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

/**
 * 全局"查看我的资产"弹窗状态（AdminLayout 承载 AssetsDialog）
 * - 三个场景(抽奖/签到/提交工单)的 RewardResultDialog 中点击"查看我的资产"时调用 open
 */
export const useAssetDialogStore = defineStore("assetDialog", () => {
  const visible = ref(false);

  // 透传给 AssetsDialog 的 props
  const totalPoints = ref(0);
  const exchangeGoal = ref(500);
  const rewardName = ref("康小虎 AI 吉祥物");
  const todayOrder = ref(0);
  const todaySignIn = ref(0);
  const todayDraw = ref(0);

  const open = (opts = {}) => {
    totalPoints.value = Number(opts.totalPoints) || 0;
    exchangeGoal.value = Number(opts.exchangeGoal) || 500;
    rewardName.value = opts.rewardName || "康小虎 AI 吉祥物";
    todayOrder.value = Number(opts.todayOrder) || 0;
    todaySignIn.value = Number(opts.todaySignIn) || 0;
    todayDraw.value = Number(opts.todayDraw) || 0;
    visible.value = true;
  };

  const close = () => {
    visible.value = false;
  };

  return {
    visible,
    totalPoints,
    exchangeGoal,
    rewardName,
    todayOrder,
    todaySignIn,
    todayDraw,
    open,
    close,
  };
});
