'use client'; import type { EventName } from '@/lib/events'; import type { Flight } from '@/lib/airline-utils'; 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); }; export default function AirlineCard({ flight }: { flight: Flight }) { const durationRef = useHoverTracking({ eventName: 'hover_over_title', productId: flight.id, metadata: { elementText: flight.duration, dateIndex: flight.dateIndex }, }); const priceRef = useHoverTracking({ eventName: 'hover_over_paragraph', productId: flight.id, metadata: { elementText: 'price', dateIndex: flight.dateIndex }, }); const handleCardClick = () => { dispatchInteraction('view_item_page', flight.id, { cabinClass: flight.cabinClass, fareRule: flight.fareRule, price: flight.basePrice, dateIndex: flight.dateIndex, }); window.location.href = `/airline/products/${flight.id}`; }; 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
)}
); }