import { Platform } from 'react-native';

/**
 * Trigger a client-side file download on web (no server, nothing uploaded).
 * Returns false on native, where the caller should fall back to share/save.
 */
export function downloadText(filename: string, mime: string, content: string): boolean {
  if (Platform.OS !== 'web') return false;
  const blob = new Blob([content], { type: mime });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = filename;
  document.body.appendChild(a);
  a.click();
  a.remove();
  setTimeout(() => URL.revokeObjectURL(url), 1000);
  return true;
}
