import { message } from 'ant-design-vue'

/**
 * 复制文档引用信息到剪贴板
 * Copy document citation to clipboard
 *
 * 格式：标题（文号），发文机关，发布日期
 * Format: title (doc_number), issuing_org, publish_date
 */
export async function copyCitation(doc: {
  title?: string
  doc_number?: string
  issuing_org?: string
  publish_date?: string
}): Promise<void> {
  const title = doc.title || ''
  const citation = `${title}${doc.doc_number ? `（${doc.doc_number}）` : ''}${doc.issuing_org ? `，${doc.issuing_org}` : ''}${doc.publish_date ? `，${doc.publish_date}` : ''}`
  try {
    await navigator.clipboard.writeText(citation)
    message.success('引用已复制')
  } catch {
    message.warning('复制失败，请手动复制')
  }
}
