import React from "react"; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, Legend, } from "recharts"; import { normalizeCurrencyPosition } from "../../lib/currency-display"; export interface BookingsOverviewPoint { label: string; count: number; amount: number; } interface BookingsOverviewChartProps { data: BookingsOverviewPoint[]; currency: string; currencyPosition?: string; currencyDecimals?: number; } const BookingsOverviewChart: React.FC = ({ data, currency, currencyPosition = "left", currencyDecimals = 2, }) => { const currencySymbolMap: Record = { USD: "$", EUR: "€", GBP: "£", INR: "₹", GHS: "₵", AUD: "A$", CAD: "C$", }; const symbol = currencySymbolMap[currency] || currency || ""; const formatAmount = (value: number, { compact }: { compact: boolean }) => { const v = Number(value) || 0; const decimals = Math.max(0, Math.min(4, currencyDecimals)); const formatCore = (num: number, useK: boolean) => { if (compact && useK && Math.abs(num) >= 1000) { const base = (num / 1000).toFixed(1); return `${base}k`; } return num.toFixed(decimals); }; const useK = compact; const core = formatCore(v, useK); const mode = normalizeCurrencyPosition(currencyPosition); switch (mode) { case "right": return `${core}${symbol}`; case "left_space": return `${symbol} ${core}`; case "right_space": return `${core} ${symbol}`; case "left": default: return `${symbol}${core}`; } }; const safeData = Array.isArray(data) ? data.map((d) => ({ month: d.label, bookings: d.count ?? 0, amount: d.amount ?? 0, })) : []; if (!safeData.length) { return (
No data available
); } return (
formatAmount(value, { compact: true }) } tick={{ fontFamily: "inherit", fontSize: 11, fill: "#6b7280" }} /> { if (name === "Bookings") { return [value, "Bookings"]; } if (name === "Amount") { const formatted = formatAmount(Number(value) || 0, { compact: false, }); return [formatted, "Amount"]; } return [value, name]; }} />
); }; export default BookingsOverviewChart;