"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../_vendor/@legendapp/state/index.cjs");
const planStore$ = index.observable({
  currentPlan: null,
  currentStepIndex: -1,
  // -1 表示还未开始
  totalSteps: 0,
  isExecuting: false,
  currentMessageId: null,
  startTime: null,
  endTime: null
});
const planActions = {
  // 初始化新计划
  initializePlan: (plan, messageId) => {
    index.batch(() => {
      planStore$.currentPlan.set(plan);
      planStore$.currentStepIndex.set(-1);
      planStore$.totalSteps.set(plan.length);
      planStore$.isExecuting.set(true);
      planStore$.currentMessageId.set(messageId);
      planStore$.startTime.set(Date.now());
      planStore$.endTime.set(null);
    });
  },
  // 更新计划（用于重新规划）
  updatePlan: (plan) => {
    index.batch(() => {
      planStore$.currentPlan.set(plan);
      planStore$.totalSteps.set(plan.length);
    });
  },
  // 开始执行步骤
  startStep: (stepIndex) => {
    const plan = planStore$.currentPlan.peek();
    if (plan && plan[stepIndex]) {
      const updatedPlan = [...plan];
      updatedPlan[stepIndex] = {
        ...updatedPlan[stepIndex],
        startedAt: Date.now()
      };
      planStore$.currentPlan.set(updatedPlan);
    }
    planStore$.currentStepIndex.set(stepIndex);
  },
  // 完成当前步骤
  completeStep: (stepIndex) => {
    const plan = planStore$.currentPlan.peek();
    if (plan && plan[stepIndex]) {
      const updatedPlan = [...plan];
      updatedPlan[stepIndex] = {
        ...updatedPlan[stepIndex],
        completed: true,
        completedAt: Date.now()
      };
      planStore$.currentPlan.set(updatedPlan);
    }
  },
  // 标记步骤失败
  failStep: (stepIndex, error) => {
    const plan = planStore$.currentPlan.peek();
    if (plan && plan[stepIndex]) {
      const updatedPlan = [...plan];
      updatedPlan[stepIndex] = {
        ...updatedPlan[stepIndex],
        completed: true,
        // 失败也算完成
        failed: true,
        error,
        completedAt: Date.now()
      };
      planStore$.currentPlan.set(updatedPlan);
    }
  },
  // 完成整个计划
  completePlan: () => {
    index.batch(() => {
      planStore$.isExecuting.set(false);
      planStore$.endTime.set(Date.now());
    });
  },
  // 清空计划
  clearPlan: () => {
    index.batch(() => {
      planStore$.currentPlan.set(null);
      planStore$.currentStepIndex.set(-1);
      planStore$.totalSteps.set(0);
      planStore$.isExecuting.set(false);
      planStore$.currentMessageId.set(null);
      planStore$.startTime.set(null);
      planStore$.endTime.set(null);
    });
  },
  // 获取当前步骤
  getCurrentStep: () => {
    const plan = planStore$.currentPlan.peek();
    const index2 = planStore$.currentStepIndex.peek();
    return plan && index2 >= 0 && index2 < plan.length ? plan[index2] : null;
  },
  // 获取进度百分比
  getProgress: () => {
    const plan = planStore$.currentPlan.peek();
    if (!plan || plan.length === 0) return 0;
    const completedSteps = plan.filter((step) => step.completed).length;
    return Math.round(completedSteps / plan.length * 100);
  },
  // 获取执行时长（毫秒）
  getDuration: () => {
    const startTime = planStore$.startTime.peek();
    const endTime = planStore$.endTime.peek();
    if (!startTime) return 0;
    return endTime ? endTime - startTime : Date.now() - startTime;
  }
};
exports.planActions = planActions;
exports.planStore$ = planStore$;
//# sourceMappingURL=plan-store.cjs.map
