/* ======================================== File: frontend/features/model-explanation/components/price-comparison-chart.tsx ======================================== */ "use client"; import { useTheme } from "next-themes"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend, Cell, } from "@/components/ui/chart"; // Using shared ui chart components import type { ComparableProperty, PropertyBaseDetails } from "../types"; // Feature specific types interface PriceComparisonChartProps { property: PropertyBaseDetails & { name: string }; // Add name for the primary property comparisons: ComparableProperty[]; } export function PriceComparisonChart({ property, comparisons }: PriceComparisonChartProps) { const { theme } = useTheme(); const isDark = theme === "dark"; // Combine property and comparisons for chart data // Ensure the property being explained is included and identifiable const data = [ { ...property }, // Keep all details for tooltip if needed ...comparisons.map((c) => ({ ...c, name: c.address })), // Use address as name for comparisons ]; // Format the price for display const formatPrice = (value: number) => { return new Intl.NumberFormat("th-TH", { style: "currency", currency: "THB", notation: "compact", // Use compact notation like 15M minimumFractionDigits: 0, maximumFractionDigits: 1, }).format(value); }; // Custom tooltip content const CustomTooltip = ({ active, payload, label }: any) => { if (active && payload && payload.length) { const data = payload[0].payload; // Get the data point for this bar return (

{label}

Price: {formatPrice(data.price)}

Size: {data.size} sqm

Age: {data.age} years

); } return null; }; return ( formatPrice(value)} stroke={isDark ? "#9ca3af" : "#6b7280"} fontSize={10} width={40} /> } // Use custom tooltip wrapperStyle={{ zIndex: 100 }} // Ensure tooltip is on top /> {/* // Legend might be redundant if XAxis labels are clear */} {data.map((entry, index) => ( ))} ); }