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

/**
 * 全局工单表单弹窗状态（用于 AdminLayout header 按钮、列表页、详情页、积分页等任意位置触发）
 * - open()       新建模式
 * - openEdit(id) 编辑模式
 * - close()      关闭
 */
export const useOrderDialogStore = defineStore("orderDialog", () => {
  const visible = ref(false);
  const orderId = ref(null);

  const open = () => {
    orderId.value = null;
    visible.value = true;
  };
  const openEdit = (id) => {
    orderId.value = id;
    visible.value = true;
  };
  const close = () => {
    visible.value = false;
  };

  return { visible, orderId, open, openEdit, close };
});
