import { chatApi } from '../services/chatApi'

export function useCSVDownload() {
  function downloadCSV(messageId: string) {
    const url = chatApi.getResultCsvUrl(messageId)
    const a = document.createElement('a')
    a.href = url
    a.download = `results_${messageId}.csv`
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
  }

  return { downloadCSV }
}
