const assert = require("assert");
const fs = require("fs");
const path = require("path");

const pagePath = path.resolve(__dirname, "../../src/views/ccdiProject/index.vue");
const dialogPath = path.resolve(
  __dirname,
  "../../src/views/ccdiProject/components/ArchiveConfirmDialog.vue"
);
const pageSource = fs.readFileSync(pagePath, "utf8");
const dialogSource = fs.readFileSync(dialogPath, "utf8");

assert(
  pageSource.includes("delProject") && pageSource.includes("restoreProject"),
  "项目列表页应引入删除和恢复接口"
);

assert(
  pageSource.includes("includeDeleted: false"),
  "默认查询参数应不包含已删除项目"
);

assert(
  pageSource.includes(':show-deleted-tab="isProjectAdmin"'),
  "已删除入口应仅对项目管理员角色展示"
);

assert(
  pageSource.includes("'5': counts.status5 || 0"),
  "状态统计应接入已删除数量"
);

assert(
  pageSource.includes('await delProject(row.projectId)'),
  "删除确认后应调用项目删除接口"
);

assert(
  pageSource.includes('await restoreProject(row.projectId)'),
  "恢复确认后应调用项目恢复接口"
);

assert(
  pageSource.includes("项目内数据不会删除"),
  "删除确认文案应明确项目内数据不会删除"
);

assert(
  pageSource.includes("项目将恢复为已完成状态"),
  "恢复确认文案应明确恢复到已完成状态"
);

assert(
  pageSource.includes("await archiveProject(data.projectId)"),
  "确认归档后应调用真实归档接口"
);

assert(
  pageSource.includes('this.$modal.msgSuccess("项目归档成功")') ||
    pageSource.includes("this.$modal.msgSuccess('项目归档成功')"),
  "归档成功后应提示项目归档成功"
);

assert(
  pageSource.includes("项目归档失败，请稍后重试"),
  "归档失败时应有统一兜底提示"
);

[
  "自动生成项目报告PDF",
  "移入归档库，可随时查看",
  "同时删除项目相关数据",
  "归档后可从\"归档库\"中查看和恢复",
].forEach((token) => {
  assert(!dialogSource.includes(token), `归档弹窗不应保留超范围文案: ${token}`);
});

assert(
  !dialogSource.includes("deleteData"),
  "归档弹窗不应再保留删除数据状态"
);

console.log("project-list-archive-flow test passed");
