/**
 * SET 27 — "Download prompt": exports the run's SUBMITTED prompt verbatim as
 * a `.md` file, client-side blob download (same pattern as exportRunLog).
 * No reformatting, no metadata injected — the file bytes are exactly the
 * stored prompt string.
 */

export function buildPromptMdFilename(runId: string | null | undefined): string {
  return `prompt-${runId || 'unknown'}.md`;
}

/** Verbatim bytes — no trimming, no wrapping, no header. */
export function buildPromptBlob(prompt: string): Blob {
  return new Blob([prompt], { type: 'text/markdown' });
}

/** Build and trigger download of `prompt-<runId>.md`. */
export function downloadPromptMd(runId: string | null | undefined, prompt: string): void {
  const blob = buildPromptBlob(prompt);
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = buildPromptMdFilename(runId);
  document.body.appendChild(a);
  a.click();
  a.remove();
  URL.revokeObjectURL(url);
}
