"use client" import { useIntersection } from "@/hooks/use-intersection" import { domesticPricing, internationalPricing } from "@/lib/pricing-data" // Convert data points to SVG path coordinates // Chart: X = 0 (60 days) to 400 (0 days), Y = 0 (top, 10x) to 300 (bottom, 0x) function toPath( data: { days: number; multiplier: number }[] ): string { const points = data.map((d) => ({ x: ((60 - d.days) / 60) * 380 + 40, y: 280 - (d.multiplier / 10) * 260, })) // Smooth bezier curve through points let path = `M ${points[0].x} ${points[0].y}` for (let i = 1; i < points.length; i++) { const prev = points[i - 1] const curr = points[i] const cpx = (prev.x + curr.x) / 2 path += ` C ${cpx} ${prev.y}, ${cpx} ${curr.y}, ${curr.x} ${curr.y}` } return path } export function PricingChart() { const { ref, isVisible } = useIntersection(0.3) const domesticPath = toPath(domesticPricing) const internationalPath = toPath(internationalPricing) // Y position for 2x multiplier (danger threshold) const dangerY = 280 - (2 / 10) * 260 return (
} className="w-full max-w-3xl mx-auto"> {/* Danger zone (above 2x) */} {/* Grid lines */} {[0, 2, 4, 6, 8, 10].map((mult) => { const y = 280 - (mult / 10) * 260 return ( {mult}x ) })} {/* X-axis labels */} {[60, 45, 30, 21, 14, 7, 3, 0].map((days) => { const x = ((60 - days) / 60) * 380 + 40 return ( {days}d ) })} {/* 2x danger label */} 2x {/* International line */} {/* Domestic line */} {/* End point dots */} {isVisible && ( <> )} {/* Axis labels */} Days before departure Price multiplier {/* Legend */}
Domestic
International
) }