import { Image } from '@components/common/Image.js';
import {
Editable,
EditableImage,
EditableMarkdown,
WidgetEmptyState,
isPageBuilderActive
} from '@components/common/page-builder/index.js';
import React, { useEffect, useState } from 'react';
/**
* Brand story — an editorial block with four layout variants. Eyebrow,
* heading, two body paragraphs, an optional read-more link, and (for
* three of the four variants) a large image. Mid-funnel trust copy.
*
* Variants:
* - `image-left` : 50/50, image first
* - `image-right` : 50/50, image second
* - `centered` : single column, optional thumb-sized image above
* - `pull-quote` : image hidden; `pullQuote` styled as large blockquote
*/
export type BrandStoryLayout =
| 'image-left'
| 'image-right'
| 'centered'
| 'pull-quote';
export interface BrandStoryProps {
brandStoryWidget: {
layout: BrandStoryLayout;
image: string | null;
imageAlt: string;
/** Natural intrinsic width of `image`, captured at pick time. */
imageWidth: number | null;
/** Natural intrinsic height. */
imageHeight: number | null;
eyebrow: string | null;
heading: string;
body: string;
bodySecondary: string | null;
link: { label: string; url: string; newTab: boolean } | null;
pullQuote: string | null;
imageSize: 40 | 50 | 60;
};
}
function Copy({
eyebrow,
heading,
body,
bodySecondary,
link,
centered = false
}: {
eyebrow: string | null;
heading: string;
body: string;
bodySecondary: string | null;
link: BrandStoryProps['brandStoryWidget']['link'];
centered?: boolean;
}) {
const align = centered ? 'text-center' : 'text-left';
return (
);
}
export default function BrandStory({ brandStoryWidget }: BrandStoryProps) {
const {
layout,
image,
imageAlt,
imageWidth,
imageHeight,
eyebrow,
heading,
body,
bodySecondary,
link,
pullQuote,
imageSize
} = brandStoryWidget;
const [inPb, setInPb] = useState(false);
useEffect(() => {
setInPb(isPageBuilderActive());
}, []);
if (!heading) {
return (
);
}
// Fall back to a hero-scale 4:5 portrait when dimensions aren't stored.
const intrinsicWidth = imageWidth && imageWidth > 0 ? imageWidth : 1200;
const intrinsicHeight = imageHeight && imageHeight > 0 ? imageHeight : 1500;
// Single image, no mobile variant. Shared by all three image render spots.
const imageMap = {
urlField: 'settings.image',
widthField: 'settings.imageWidth',
heightField: 'settings.imageHeight'
};
if (layout === 'pull-quote') {
return (
{eyebrow && (
{eyebrow}
)}
{heading}
{pullQuote && (
“
{pullQuote}
)}
{body}
{bodySecondary && (
{bodySecondary}
)}
{link && link.label && link.url && (
{link.label} →
)}
);
}
if (layout === 'centered') {
return (
{(image || inPb) && (
{image ? (
) : null}
)}
);
}
// image-left / image-right
const reverse = layout === 'image-right';
const cols = `grid-cols-1 md:grid-cols-12`;
const imageSpan =
imageSize === 40
? 'md:col-span-5'
: imageSize === 60
? 'md:col-span-7'
: 'md:col-span-6';
const copySpan =
imageSize === 40
? 'md:col-span-7'
: imageSize === 60
? 'md:col-span-5'
: 'md:col-span-6';
return (
{!reverse && (
<>
{image ? (
) : null}
>
)}
{reverse && (
<>
{image ? (
) : null}
>
)}
);
}
export const query = `
query Query(
$layout: String
$image: String
$imageAlt: String
$imageWidth: Float
$imageHeight: Float
$eyebrow: String
$heading: String
$body: String
$bodySecondary: String
$link: JSON
$pullQuote: String
$imageSize: Float
) {
brandStoryWidget(
layout: $layout
image: $image
imageAlt: $imageAlt
imageWidth: $imageWidth
imageHeight: $imageHeight
eyebrow: $eyebrow
heading: $heading
body: $body
bodySecondary: $bodySecondary
link: $link
pullQuote: $pullQuote
imageSize: $imageSize
) {
layout
image
imageAlt
imageWidth
imageHeight
eyebrow
heading
body
bodySecondary
link
pullQuote
imageSize
}
}
`;
export const variables = `{
layout: getWidgetSetting("layout", "image-left"),
image: getWidgetSetting("image"),
imageAlt: getWidgetSetting("imageAlt"),
imageWidth: getWidgetSetting("imageWidth"),
imageHeight: getWidgetSetting("imageHeight"),
eyebrow: getWidgetSetting("eyebrow"),
heading: getWidgetSetting("heading"),
body: getWidgetSetting("body", ""),
bodySecondary: getWidgetSetting("bodySecondary"),
link: getWidgetSetting("link"),
pullQuote: getWidgetSetting("pullQuote"),
imageSize: getWidgetSetting("imageSize", 50)
}`;