import { Image } from '@components/common/Image.js'; import type { ContentAnchor } from '@components/common/page-builder/drawer/AnchorPicker.js'; import { ctaButtonVariant, type CtaValue } from '@components/common/page-builder/fields/CtaField.js'; import { Editable, EditableImage, isPageBuilderActive } from '@components/common/page-builder/index.js'; import { buttonVariants } from '@components/common/ui/Button.js'; import { scrimButtonClassName } from '@components/common/ui/scrimButton.js'; import { ImagePlus } from 'lucide-react'; import React, { useEffect, useState } from 'react'; interface BannerProps { bannerWidget: { src: string | null; alignment: string | null; width: number | string | null; height: number | string | null; alt: string | null; link: string | null; eyebrow: string | null; heading: string | null; subText: string | null; contentPosition: ContentAnchor | null; overlayTint: 'none' | 'dark' | 'light' | 'gradient' | null; overlayOpacity: number | null; cta: CtaValue | null; cta2: CtaValue | null; mobileImage: string | null; mobileImageWidth: number | string | null; mobileImageHeight: number | string | null; }; } const ALIGNMENT_CLASS: Record = { left: 'justify-start', center: 'justify-center', right: 'justify-end' }; // Anchor → flex classes for the overlay copy block. Mirrors slideshow's // mapping: justify-* drives vertical placement (the overlay container is // flex-col), items-* drives horizontal placement, text-* aligns text. const ANCHOR_CLASS: Record = { tl: { box: 'justify-start items-start', text: 'text-left' }, tc: { box: 'justify-start items-center', text: 'text-center' }, tr: { box: 'justify-start items-end', text: 'text-right' }, ml: { box: 'justify-center items-start', text: 'text-left' }, mc: { box: 'justify-center items-center', text: 'text-center' }, mr: { box: 'justify-center items-end', text: 'text-right' }, bl: { box: 'justify-end items-start', text: 'text-left' }, bc: { box: 'justify-end items-center', text: 'text-center' }, br: { box: 'justify-end items-end', text: 'text-right' } }; // Renders the banner image. When `mobileSrc` is set, swaps in the mobile // asset below the `sm` breakpoint (640px) via CSS-toggled siblings — so the // mobile image is a PHONE asset and tablets (≥640px) get the desktop image. // Two `` elements is the simplest path that preserves each asset's // intrinsic aspect ratio (the alternative — a `` with one `` // plus a fallback `` — only swaps the source bytes, not the box aspect, // so a mobile portrait crop would render in the desktop landscape box). // // Below `sm`, only the mobile `` is visible (`sm:hidden`); the desktop // one is `display: none` and is deferred from download by every modern // browser. Same in reverse at `sm` and up. function BannerImage({ src, width, height, alt, mobileSrc, mobileWidth, mobileHeight }: { src: string; width: number; height: number; alt: string; mobileSrc: string | null; mobileWidth: number | null; mobileHeight: number | null; }) { if (!mobileSrc) { return ( {alt} ); } const mw = mobileWidth && mobileWidth > 0 ? mobileWidth : 800; const mh = mobileHeight && mobileHeight > 0 ? mobileHeight : 1000; return ( <> {alt} {alt} ); } function Placeholder({ alignment }: { alignment: string }) { const cls = ALIGNMENT_CLASS[alignment] ?? 'justify-center'; return (
Banner — open settings to pick an image
); } function OverlayScrim({ tint, opacity }: { tint: 'none' | 'dark' | 'light' | 'gradient'; opacity: number; }) { if (tint === 'none' || opacity <= 0) return null; const style: React.CSSProperties = { pointerEvents: 'none' }; if (tint === 'dark') { style.backgroundColor = `rgba(0, 0, 0, ${opacity})`; } else if (tint === 'light') { style.backgroundColor = `rgba(255, 255, 255, ${opacity})`; } else if (tint === 'gradient') { // Bottom-darkening gradient; opacity scales the bottom stop only so // the top half stays clear. style.backgroundImage = `linear-gradient(to top, rgba(0, 0, 0, ${opacity}) 0%, rgba(0, 0, 0, 0) 60%)`; } return (