export function saveBlob(blob, filename) {
  const url = window.URL.createObjectURL(blob)
  const link = document.createElement('a')
  link.href = url
  link.download = filename
  document.body.appendChild(link)
  link.click()
  document.body.removeChild(link)
  window.URL.revokeObjectURL(url)
}

export function sourceZipName(project) {
  const fallback = project?.projectId ? `project-${project.projectId}` : 'easycode-project'
  const rawName = project?.projectFileName || project?.projectName || fallback
  const safeName = String(rawName).trim().replace(/[\\/:*?"<>|]/g, '_') || fallback
  return `${safeName}-source.zip`
}
