/** * Preferred quote card — highlights the recommended service with prominent styling. */ import { useMemo, useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Card, CardBody, Flex, Button, Icon } from '@wordpress/components'; import { starFilled } from '@wordpress/icons'; import type { Quote, Dropshop } from '../../types'; import { Badge, CourierBadge, PriceDisplay } from '../../shared/components'; import { useWindowSize } from '../../shared/hooks'; import ServiceType from './service-type'; import { formatShortDate } from '../../shared/utils'; import { getQuotesValidCollectionDates } from './utils/quoteHelpers'; import { computeFinalPrice, computeProtectedAmount, buildExtras, } from './utils/quotePrice'; interface PreferredQuoteCardProps { quote: Quote; onSelect: (quote: Quote, extras: string[], amount: number) => void; fullProtection: boolean; totalValue: number; dropshops: Dropshop[]; isPreferred?: boolean; disabled?: boolean; } export default function PreferredQuoteCard({ quote, onSelect, fullProtection, totalValue, dropshops, isPreferred = true, disabled = false, }: PreferredQuoteCardProps) { const { isSmOrUp } = useWindowSize(); const price = useMemo( () => computeFinalPrice(quote, fullProtection), [quote, fullProtection] ); const protectedAmount = useMemo( () => computeProtectedAmount(quote, fullProtection), [quote, fullProtection] ); const estimatedDeliveryDate = useMemo(() => { const validDates = getQuotesValidCollectionDates(quote); const dateMin = validDates[0]?.delivery?.dateMin; return dateMin ? formatShortDate(dateMin) : '—'; }, [quote]); const isFullCoverage = protectedAmount / 100 >= totalValue; const handleSelect = useCallback(() => { const extras = buildExtras(quote, fullProtection); onSelect(quote, extras, price.gross); }, [quote, fullProtection, price.gross, onSelect]); return ( {/* Header Section */} {isPreferred && ( )}
{/* Details Section */} {/* Estimated Delivery */} {__('Estimated Delivery', 'parcel2go-shipping')} {estimatedDeliveryDate} {/* Price */} {__('Price', 'parcel2go-shipping')} 0} /> {/* Protection */} {__('Protection', 'parcel2go-shipping')} {isFullCoverage ? __('Full Coverage', 'parcel2go-shipping') : `£${(protectedAmount / 100).toFixed(0)} ${__('Coverage', 'parcel2go-shipping')}`}
); }