export function buildPublicDocuments(home, data = {}) {
  const ordinary = (home.notices || []).filter(item => !String(item.id).startsWith('system-')).map(item => ({
    ...item,
    documentId: String(item.id),
    documentType: 'notice',
    subtype: item.category || '通知公告',
    publishedAt: item.publishAt
  }));
  const plans = (data.plans || []).map(item => ({
    ...item, documentId: `plan-${item.id}`, documentType: 'plan', category: '招生公示', subtype: '招生计划',
    title: `${item.examName} · ${item.schoolName}招生计划公示`,
    summary: `共 ${item.rows?.reduce((sum, row) => sum + Number(row.quota || 0), 0) || 0} 个招生名额。`
  }));
  const qualifications = (data.qualifications || []).map(item => ({
    ...item, documentId: `qualification-${item.id}`, documentType: 'qualification', category: '录取公示', subtype: '指标资格',
    title: `${item.examName} · ${item.schoolName}指标分配资格公示`, summary: `公开 ${item.rows?.length || 0} 名考生的指标分配资格。`
  }));
  const admissions = (data.admissions || []).map(item => ({
    ...item, documentId: `admission-${item.id}`, documentType: 'admission', category: '录取公示', subtype: item.round ? `第 ${item.round} 轮录取名单` : '最终录取名单',
    title: item.title || `${item.examName}最终录取名单`, summary: `共 ${item.rows?.length || 0} 名考生正式录取。`
  }));
  const cutoffs = (data.cutoffs || []).map(item => ({
    ...item, documentId: `cutoff-${item.id}`, documentType: 'cutoff', category: '录取公示', subtype: '录取分数线',
    title: `${item.examName}录取分数线`, summary: `公布 ${item.rows?.length || 0} 条学校及类别录取分数线。`
  }));
  const reports = (data.reports || []).map(item => ({
    ...item, documentId: `reporting-${item.id}`, documentType: 'reporting', category: '录取公示',
    subtype: item.supplementDecision === 'supplement' ? '报到与补录' : '报到情况'
  }));
  return [...ordinary, ...plans, ...qualifications, ...admissions, ...cutoffs, ...reports]
    .sort((left, right) => new Date(right.publishedAt) - new Date(left.publishedAt));
}
