import { useStorefront } from '../context'; import type { HeroSection } from '../types'; import { Container, Eyebrow, ImagePlaceholder, SfButton } from '../ui'; /** * The photo for a hero: the one the design names, or else the store's newest product photo. * Null when the store has no photos yet. */ function useHeroPhoto(section: HeroSection): string | null { const { heroImages } = useStorefront(); const ref = section.content.image; return ( (ref ? heroImages.refs[ref] : undefined) ?? heroImages.fallback[0] ?? null ); } export function Hero({ section }: { section: HeroSection }) { const photo = useHeroPhoto(section); if (section.variant === 'image-full') { return ; } if (section.variant === 'split') { return ; } return ; } function Buttons({ section, onPhoto = false, }: { section: HeroSection; onPhoto?: boolean; }) { const { primaryCta, secondaryCta } = section.content; return (
{primaryCta.label} {secondaryCta && ( {secondaryCta.label} )}
); } /** A photo across the whole width, with the words on top of it. */ function FullPhotoHero({ section, photo, }: { section: HeroSection; photo: string | null; }) { const { eyebrow, headline, subheadline } = section.content; return (
{photo ? ( ) : (
)} {/* Darkens the photo where the words sit, so they stay readable on any photo. */}
{eyebrow && (

{eyebrow}

)}

{headline}

{subheadline}

); } /** Words on one side, a tall photo on the other. */ function SplitHero({ section, photo, }: { section: HeroSection; photo: string | null; }) { const { eyebrow, headline, subheadline } = section.content; return (
{eyebrow && {eyebrow}}

{headline}

{subheadline}

{photo ? ( ) : ( )}
); } /** Words only, centred on a soft background. */ function CenteredHero({ section }: { section: HeroSection }) { const { eyebrow, headline, subheadline } = section.content; return (
{eyebrow && {eyebrow}}

{headline}

{subheadline}

); }