"use client"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "./ui/card"; import { useCopilotAction, useCopilotReadable } from "@copilotkit/react-core"; import { AreaChart } from "./ui/area-chart"; import { BarChart } from "./ui/bar-chart"; import { DonutChart } from "./ui/pie-chart"; import { SearchResults } from "./generative-ui/SearchResults"; import { salesData, productData, categoryData, regionalData, demographicsData, calculateTotalRevenue, calculateTotalProfit, calculateTotalCustomers, calculateConversionRate, calculateAverageOrderValue, calculateProfitMargin, } from "../data/dashboard-data"; export function Dashboard() { // Calculate metrics const totalRevenue = calculateTotalRevenue(); const totalProfit = calculateTotalProfit(); const totalCustomers = calculateTotalCustomers(); const conversionRate = calculateConversionRate(); const averageOrderValue = calculateAverageOrderValue(); const profitMargin = calculateProfitMargin(); // Make data available to the Copilot useCopilotReadable({ description: "Dashboard data including sales trends, product performance, and category distribution", value: { salesData, productData, categoryData, regionalData, demographicsData, metrics: { totalRevenue, totalProfit, totalCustomers, conversionRate, averageOrderValue, profitMargin, }, }, }); // Define render only search action useCopilotAction({ name: "searchInternet", available: "disabled", description: "Searches the internet for information.", parameters: [ { name: "query", type: "string", description: "The query to search the internet for.", required: true, }, ], render: ({ args, status }) => { return ( ); }, }); // Color palettes for different charts const colors = { salesOverview: ["#3b82f6", "#10b981", "#ef4444"], // Blue, Green, Red productPerformance: ["#8b5cf6", "#6366f1", "#4f46e5"], // Purple spectrum categories: ["#3b82f6", "#64748b", "#10b981", "#f59e0b", "#94a3b8"], // Mixed regional: ["#059669", "#10b981", "#34d399", "#6ee7b7", "#a7f3d0"], // Green spectrum demographics: ["#f97316", "#f59e0b", "#eab308", "#facc15", "#fde047"], // Orange to Yellow }; return (
{/* Key Metrics */}

Total Revenue

${totalRevenue.toLocaleString()}

Total Profit

${totalProfit.toLocaleString()}

Customers

{totalCustomers.toLocaleString()}

Conversion Rate

{conversionRate}

Avg Order Value

${averageOrderValue}

Profit Margin

{profitMargin}

{/* Charts */} Sales Overview Monthly sales and profit data
`$${value.toLocaleString()}`} showLegend={true} showGrid={true} showXAxis={true} showYAxis={true} />
Product Performance Top selling products
`$${value.toLocaleString()}`} showLegend={false} showGrid={true} layout="horizontal" />
Sales by Category Distribution across categories
`${value}%`} colors={colors.categories} centerText="Categories" paddingAngle={0} showLabel={false} showLegend={true} innerRadius={45} outerRadius="90%" />
Regional Sales Sales by geographic region
`$${value.toLocaleString()}`} showLegend={false} showGrid={true} layout="horizontal" />
Customer Demographics Spending by age group
`$${value}`} showLegend={false} showGrid={true} layout="horizontal" />
); }