import React from 'react' import { STATE_CODE_TO_NAME } from '../utils/stateMapping' import { licensePlatePublicSrc } from '../utils/wikicommonsLicensePlate' /** Short plate slogans (subset); used only for CSS fallback when no Commons image. */ const STATE_SLOGANS: Partial> = { AL: 'Heart of Dixie', AK: 'North to the Future', AZ: 'Grand Canyon State', AR: 'Natural State', CA: 'The Golden State', CO: 'Colorful Colorado', CT: 'Constitution State', DE: 'The First State', FL: 'Sunshine State', GA: 'Peach State', HI: 'Aloha State', ID: 'Gem State', IL: 'Land of Lincoln', IN: 'Crossroads of America', IA: 'Fields of Opportunities', KS: 'Ad astra per aspera', KY: 'Unbridled Spirit', LA: "Sportsman's Paradise", ME: 'Vacationland', MD: 'America in Miniature', MA: 'The Spirit of America', MI: 'Great Lakes State', MN: 'Land of 10,000 Lakes', MS: "Birthplace of America's Music", MO: 'Show Me State', MT: 'Big Sky Country', NE: 'The Good Life', NV: 'Battle Born', NH: 'Live Free or Die', NJ: 'Garden State', NM: 'Land of Enchantment', NY: 'Empire State', NC: 'First in Flight', ND: 'Peace Garden State', OH: 'Birthplace of Aviation', OK: 'Native America', OR: 'Pacific Wonderland', PA: 'Virtue, Liberty, Independence', RI: 'Ocean State', SC: 'Smiling Faces, Beautiful Places', SD: 'Great Faces, Great Places', TN: 'Volunteer State', TX: 'Lone Star State', UT: 'Life Elevated', VT: 'Freedom and Unity', VA: 'Virginia is for Lovers', WA: 'Evergreen State', WV: 'Wild, Wonderful', WI: "America's Dairyland", WY: 'Forever West', DC: 'Taxation Without Representation', PR: 'Isla del Encanto', } const PLATE_FONT = "'Bebas Neue', sans-serif" const DEFAULT_SLOGAN = 'Open Navigator' export type HeroLicensePlateBadgeProps = { location: { state: string; county?: string; city?: string } | null onChangeLocation: () => void changeLocationLabel?: string } function plateStateLine(loc: HeroLicensePlateBadgeProps['location']): string { if (!loc?.state) return 'United States' const code = loc.state.toUpperCase() return STATE_CODE_TO_NAME[code] ?? loc.state } function plateMainLine(loc: HeroLicensePlateBadgeProps['location']): string { if (!loc?.state) return 'Your community' const county = loc.county?.replace(/\s+County$/i, '').trim() if (county) return truncatePlateText(county, 20) const city = loc.city?.trim() if (city) return truncatePlateText(city, 20) const code = loc.state.toUpperCase() return STATE_CODE_TO_NAME[code] ?? loc.state } function truncatePlateText(s: string, max: number): string { if (s.length <= max) return s return `${s.slice(0, Math.max(0, max - 1))}…` } function plateSlogan(loc: HeroLicensePlateBadgeProps['location']): string { if (!loc?.state) return DEFAULT_SLOGAN return STATE_SLOGANS[loc.state.toUpperCase()] ?? DEFAULT_SLOGAN } function plateYearLabel(): string { return String(new Date().getFullYear()) } function Bolt({ className }: { className: string }) { return (
) } type HeroPlateImageProps = { src: string alt: string } /** Plate photo fills the frame; edges crop via cover. Corner bolts render above (z-index). */ function HeroPlateImage({ src, alt }: HeroPlateImageProps) { return (
{alt}
) } type CssFallbackProps = { location: HeroLicensePlateBadgeProps['location'] onActivate: () => void onKeyDown: (e: React.KeyboardEvent) => void changeLocationLabel: string } function CssLicensePlateFallback({ location, onActivate, onKeyDown, changeLocationLabel, }: CssFallbackProps) { const stateLine = plateStateLine(location) const mainLine = plateMainLine(location) const slogan = plateSlogan(location) const year = plateYearLabel() return (
{stateLine}
★ ★ ★
{mainLine}
{year} {slogan}
🔄 Change location
) } function HeroLicensePlateBadge({ location, onChangeLocation, changeLocationLabel = 'Change location', }: HeroLicensePlateBadgeProps) { const src = licensePlatePublicSrc(location?.state) const alt = !location?.state ? 'Sample U.S. state license plate from Wikimedia Commons.' : `${location.state} license plate (latest in cache, Wikimedia Commons).` const activate = () => { onChangeLocation() } const onKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() activate() } } if (!src) { return ( ) } return (
🔄 Change location
) } export default HeroLicensePlateBadge