diff --git a/components/AIAssist.tsx b/components/AIAssist.tsx index 1b500a6..26aade1 100644 --- a/components/AIAssist.tsx +++ b/components/AIAssist.tsx @@ -937,6 +937,50 @@ export default function AIAssist({ vibeMode = false }: { vibeMode?: boolean } = downloadSeoReport(seoAuditData, format); }; + const exportLeadsReport = (format: "html" | "csv") => { + const htmlContent = previewData?.data; + if (!htmlContent) return; + if (format === "html") { + const blob = new Blob([htmlContent], { type: "text/html" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = "leads-report.html"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } else { + // Extract table rows from HTML and convert to CSV + const parser = new DOMParser(); + const doc = parser.parseFromString(htmlContent, "text/html"); + const rows = doc.querySelectorAll("tbody tr"); + if (rows.length === 0) return; + let csv = "Name,Platform,Followers,Region,Bio,Link\n"; + rows.forEach((row) => { + const cells = row.querySelectorAll("td"); + if (cells.length >= 7) { + const name = cells[1]?.textContent?.trim().replace(/,/g, ";") || ""; + const platform = cells[2]?.textContent?.trim() || ""; + const followers = cells[3]?.textContent?.trim() || ""; + const region = cells[4]?.textContent?.trim().replace(/,/g, ";") || ""; + const bio = cells[5]?.textContent?.trim().replace(/,/g, ";") || ""; + const link = cells[6]?.querySelector("a")?.href || ""; + csv += `"${name}","${platform}","${followers}","${region}","${bio}","${link}"\n`; + } + }); + const blob = new Blob([csv], { type: "text/csv" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = "leads-report.csv"; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } + }; + const clearHistory = () => { updateActiveTab({ @@ -1440,6 +1484,24 @@ export default function AIAssist({ vibeMode = false }: { vibeMode?: boolean } = )} + {currentAgent === "leads" && previewData?.data && ( +