import listPrdMarkdown from '../.spec/requirements-prd-list.md?raw';
import detailPrdMarkdown from '../.spec/requirements-prd-detail.md?raw';

function downloadTextFile(filename: string, content: string) {
  const blob = new Blob(['\uFEFF', content], { type: 'text/markdown;charset=utf-8' });
  const url = URL.createObjectURL(blob);
  const link = document.createElement('a');
  link.href = url;
  link.download = filename;
  link.click();
  URL.revokeObjectURL(url);
}

/** 依次下载列表页、详情页 PRD Markdown 文件 */
export function downloadVehiclePrdMarkdownFiles(onComplete?: (message: string) => void) {
  downloadTextFile('车辆管理-列表页PRD.md', listPrdMarkdown);
  window.setTimeout(() => {
    downloadTextFile('车辆管理-详情页PRD.md', detailPrdMarkdown);
    onComplete?.('已下载列表页、详情页 PRD 文档（.md）');
  }, 250);
}
