import { DashboardStats } from "@/types" import { leads } from "./leads" function getLeadsPerMonth() { const months: { month: string; leads: number; closed: number }[] = [] const now = new Date() for (let i = 5; i >= 0; i--) { const d = new Date(now.getFullYear(), now.getMonth() - i, 1) const monthStr = d.toLocaleDateString("en-US", { month: "short", year: "2-digit" }) const yearMonth = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}` const leadsCount = leads.filter((l) => l.createdAt.startsWith(yearMonth)).length const closedCount = leads.filter( (l) => l.status === "closed" && l.updatedAt.startsWith(yearMonth) ).length months.push({ month: monthStr, leads: leadsCount, closed: closedCount }) } return months } function getStatusDistribution() { const statusCounts: Record = { open: 0, contacted: 0, pending: 0, closed: 0, ignored: 0 } leads.forEach((l) => { statusCounts[l.status]++ }) return [ { name: "Open", value: statusCounts.open, color: "#0d9488" }, { name: "Contacted", value: statusCounts.contacted, color: "#5eead4" }, { name: "Pending", value: statusCounts.pending, color: "#c9a96e" }, { name: "Closed", value: statusCounts.closed, color: "#f43f5e" }, { name: "Ignored", value: statusCounts.ignored, color: "#94a3b8" }, ] } export const dashboardStats: DashboardStats = { totalLeads: leads.length, openLeads: leads.filter((l) => l.status === "open").length, contactedLeads: leads.filter((l) => l.status === "contacted").length, pendingLeads: leads.filter((l) => l.status === "pending").length, closedLeads: leads.filter((l) => l.status === "closed").length, ignoredLeads: leads.filter((l) => l.status === "ignored").length, conversionRate: Math.round( (leads.filter((l) => l.status === "closed").length / leads.length) * 100 ), leadsPerMonth: getLeadsPerMonth(), recentLeads: leads.slice(0, 10), statusDistribution: getStatusDistribution(), }