/* eslint-disable no-restricted-exports */
'use client'
import { type WidgetServerProps } from 'payload'
import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'
import type { RevenueWidget } from '../payload-types.js'
interface RevenueData {
amount: number
date: string
period: string
}
const formatCurrency = (value: number) => {
return new Intl.NumberFormat('en-US', {
currency: 'USD',
minimumFractionDigits: 0,
style: 'currency',
}).format(value)
}
function CustomTooltip(props: {
active?: boolean
label?: number | string
payload?: { value: number }[]
}) {
const { active, label, payload } = props
if (active && payload && payload.length) {
return (
{label}
{formatCurrency(payload[0]?.value ?? 0)}
)
}
return null
}
export default function Revenue({ widgetData }: WidgetServerProps) {
const timeframe = typeof widgetData?.timeframe === 'string' ? widgetData.timeframe : 'monthly'
const title = typeof widgetData?.title === 'string' ? widgetData.title : 'Revenue Statistics'
// Mock data for now - in real implementation, this would come from props or server-side fetch
const mockData: RevenueData[] = [
{ amount: 20000, date: '2024-01', period: 'Jan' },
{ amount: 25000, date: '2024-02', period: 'Feb' },
{ amount: 18000, date: '2024-03', period: 'Mar' },
{ amount: 30000, date: '2024-04', period: 'Apr' },
{ amount: 35000, date: '2024-05', period: 'May' },
{ amount: 28000, date: '2024-06', period: 'Jun' },
{ amount: 40000, date: '2024-07', period: 'Jul' },
{ amount: 38000, date: '2024-08', period: 'Aug' },
{ amount: 45000, date: '2024-09', period: 'Sep' },
{ amount: 42000, date: '2024-10', period: 'Oct' },
{ amount: 48000, date: '2024-11', period: 'Nov' },
{ amount: 52000, date: '2024-12', period: 'Dec' },
]
return (
{title}
`$${value / 1000}k`}
tickLine={false}
/>
} />
)
}