import React from 'react'; import type { Store } from '../types'; const formatDateRange = (from: string | null | undefined, to: string | null | undefined): string | null => { if (!from && !to) return null; const options: Intl.DateTimeFormatOptions = { month: 'long', day: 'numeric', year: 'numeric' }; const fromDate = from ? new Date(`${from}T00:00:00`).toLocaleDateString('en-US', options) : null; const toDate = to ? new Date(`${to}T00:00:00`).toLocaleDateString('en-US', options) : null; if (fromDate && toDate) { return fromDate === toDate ? `Valid on ${fromDate}` : `Deals valid from ${fromDate} to ${toDate}`; } return fromDate ? `Deals start ${fromDate}` : (toDate ? `Deals end ${toDate}` : null); }; interface FlyerDisplayProps { imageUrl: string | null; store?: Store; validFrom?: string | null; validTo?: string | null; storeAddress?: string | null; } export const FlyerDisplay: React.FC = ({ imageUrl, store, validFrom, validTo, storeAddress }) => { const dateRange = formatDateRange(validFrom, validTo); return (
{(store || dateRange) && (
{store?.logo_url && ( {`${store.name )}
{store?.name &&

{store.name}

} {dateRange &&

{dateRange}

} {storeAddress &&

{storeAddress}

}
)}
{imageUrl ? ( Grocery Flyer ) : (

Flyer image will be displayed here

)}
); };