'use client'; import type { EventName } from '@/lib/events'; import { useHoverTracking } from '@/hooks/useHoverTracking'; import PriceDisplay from '@/components/ui/PriceDisplay'; const dispatchInteraction = (eventName: EventName, productId?: string, metadata?: Record) => { const e = new CustomEvent('definedInteraction', { detail: { eventName, productId, metadata }, }); document.dispatchEvent(e); }; type CabinClass = 'economy' | 'premium' | 'business' | 'first'; type FareRule = 'flexible' | 'standard' | 'basic'; interface Flight { id: string; departure: { time: string; airport: string }; arrival: { time: string; airport: string }; duration: string; stops: number; cabinClass: CabinClass; fareRule: FareRule; refundable: boolean; basePrice: number; } export default function AirlineCard({ flight }: { flight: Flight }) { const durationRef = useHoverTracking({ eventName: 'hover_over_title', productId: flight.id, metadata: { elementText: flight.duration }, }); const priceRef = useHoverTracking({ eventName: 'hover_over_paragraph', productId: flight.id, metadata: { elementText: 'price' }, }); const handleCardClick = () => { dispatchInteraction('view_item_page', flight.id, { cabinClass: flight.cabinClass, fareRule: flight.fareRule, price: flight.basePrice, }); }; return (
{flight.departure.time}
{flight.departure.airport}
{flight.duration}
{flight.stops === 0 ? 'Direct' : `${flight.stops} stop${flight.stops > 1 ? 's' : ''}`}
{flight.arrival.time}
{flight.arrival.airport}
{flight.cabinClass}
{flight.fareRule}
{flight.refundable && (
Refundable
)}
); }