import type { SkillFileContent } from './types';

/** Build a download from the active text buffer so unsaved edits are included. */
export function buildSkillTextDownload(
  file: SkillFileContent,
  content: string,
): Blob | undefined {
  if (file.isText === false) return undefined;
  const textFile =
    file.isText === true ||
    ['REFERENCE', 'SCRIPT', 'SKILL'].includes(file.type);
  if (!textFile) return undefined;
  return new Blob([content], {
    type: file.mediaType || 'text/plain;charset=utf-8',
  });
}
