import type { TaskPanelItem } from "@qjclaw/shared-types"

function toDateInputValue(date: Date) {
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, "0")
  const day = String(date.getDate()).padStart(2, "0")
  return `${year}-${month}-${day}`
}

function addDays(date: Date, days: number) {
  const next = new Date(date)
  next.setDate(next.getDate() + days)
  return next
}

export function getDefaultTaskPanelDate() {
  return toDateInputValue(new Date())
}

export const mockTaskPanelItems: TaskPanelItem[] = [
  {
    id: "mock-task-content-plan",
    date: getDefaultTaskPanelDate(),
    expertName: "内容账号规划专家",
    taskTitle: "整理本周选题方向与发布节奏",
    status: "running",
    statusDetail: "正在汇总账号定位、目标人群和栏目节奏",
    artifacts: [
      { id: "artifact-content-outline", name: "选题规划草稿.md", kind: "文档", url: "/Users/edy/Documents/qianjiangclaw/tasks/content/选题规划草稿.md" },
      { id: "artifact-content-calendar", name: "发布日历.xlsx", kind: "表格", url: "/Users/edy/Documents/qianjiangclaw/tasks/content/发布日历.xlsx" },
      { id: "artifact-content-persona", name: "目标人群画像.md", kind: "文档", url: "/Users/edy/Documents/qianjiangclaw/tasks/content/目标人群画像.md" },
      { id: "artifact-content-topics", name: "栏目选题池.csv", kind: "表格", url: "/Users/edy/Documents/qianjiangclaw/tasks/content/栏目选题池.csv" },
      { id: "artifact-content-brief", name: "账号定位简报.pdf", kind: "文档", url: "/Users/edy/Documents/qianjiangclaw/tasks/content/账号定位简报.pdf" }
    ]
  },
  {
    id: "mock-task-content-review",
    date: getDefaultTaskPanelDate(),
    expertName: "内容账号规划专家",
    taskTitle: "复盘昨日内容表现",
    status: "completed",
    statusDetail: "已完成互动数据摘要与优化建议",
    artifacts: [
      { id: "artifact-content-review", name: "昨日内容复盘与下轮优化建议.md", kind: "文档", url: "/Users/edy/Documents/qianjiangclaw/tasks/content/昨日内容复盘与下轮优化建议.md" }
    ]
  },
  {
    id: "mock-task-zhihu",
    date: getDefaultTaskPanelDate(),
    expertName: "知乎专家",
    taskTitle: "生成知乎回答结构",
    status: "completed",
    statusDetail: "已完成回答大纲与首版正文",
    artifacts: [
      { id: "artifact-zhihu-answer", name: "知乎回答初稿.md", kind: "文档", url: "/Users/edy/Documents/qianjiangclaw/tasks/zhihu/知乎回答初稿.md" }
    ]
  },
  {
    id: "mock-task-zhihu-research",
    date: getDefaultTaskPanelDate(),
    expertName: "知乎专家",
    taskTitle: "整理竞品问答素材",
    status: "running",
    statusDetail: "正在提取高赞回答结构和关键词",
    artifacts: [
      { id: "artifact-zhihu-research", name: "竞品问答素材汇总-长文件名用于验证省略显示效果.xlsx", kind: "表格", url: "/Users/edy/Documents/qianjiangclaw/tasks/zhihu/竞品问答素材汇总-长文件名用于验证省略显示效果.xlsx" }
    ]
  },
  {
    id: "mock-task-leads",
    date: getDefaultTaskPanelDate(),
    expertName: "平台精准线索专家",
    taskTitle: "筛选高意向线索名单",
    status: "pending",
    statusDetail: "等待线索表上传后开始处理",
    artifacts: []
  },
  {
    id: "mock-task-poster",
    date: toDateInputValue(addDays(new Date(), -1)),
    expertName: "海报专家",
    taskTitle: "生成活动海报文案",
    status: "failed",
    statusDetail: "素材包缺少主视觉图片",
    artifacts: [
      { id: "artifact-poster-brief", name: "活动海报文案草稿.txt", kind: "文档", url: "/Users/edy/Documents/qianjiangclaw/tasks/poster/活动海报文案草稿.txt" }
    ]
  }
]

export async function loadTaskPanelItems(date: string): Promise<TaskPanelItem[]> {
  return mockTaskPanelItems.filter((item) => item.date === date)
}
