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: "文档" },
      { id: "artifact-content-calendar", name: "发布日历.xlsx", kind: "表格" }
    ]
  },
  {
    id: "mock-task-zhihu",
    date: getDefaultTaskPanelDate(),
    expertName: "知乎专家",
    taskTitle: "生成知乎回答结构",
    status: "completed",
    statusDetail: "已完成回答大纲与首版正文",
    artifacts: [
      { id: "artifact-zhihu-answer", name: "知乎回答初稿.md", kind: "文档" }
    ]
  },
  {
    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: []
  }
]

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