import { Image } from '@components/common/Image.js'; import { Editable } from '@components/common/page-builder/index.js'; import React from 'react'; /** * Trust strip — a row of value-prop items (free shipping, easy returns, * etc.) shown below the hero or above the footer. Pure presentation; no * data fetch. Items with a `link` become clickable cells; the rest are * static. */ export type TrustAlignment = 'left' | 'center'; export type TrustIconSize = 'sm' | 'md' | 'lg'; export interface TrustItem { id: string; icon: string | null; /** Natural intrinsic width of the icon. Falls back to the rendered * iconSize when missing. */ iconWidth?: number | null; iconHeight?: number | null; title: string; description: string | null; link: { url: string; newTab: boolean } | null; } export interface TrustStripProps { trustStripWidget: { items: TrustItem[]; columns: number | null; showIcons: boolean | null; iconSize: TrustIconSize | null; alignment: TrustAlignment | null; divider: boolean | null; }; } const ICON_PX: Record = { sm: 24, md: 32, lg: 44 }; function effectiveColumns(items: TrustItem[], columns: number | null): number { if (columns && columns >= 2) return Math.min(columns, 6); // Auto: match the item count, capped at 4 to keep cells readable. return Math.min(Math.max(items.length, 1), 4); } export default function TrustStrip({ trustStripWidget }: TrustStripProps) { const { items = [], columns, showIcons, iconSize, alignment, divider } = trustStripWidget; // Preserve original settings index so inline edits land at // `settings.items.${originalIndex}.{title|description}`. const visibleItems = items .map((item, originalIndex) => ({ item, originalIndex })) .filter(({ item }) => Boolean(item)); if (visibleItems.length === 0) return null; const cols = effectiveColumns( visibleItems.map(({ item }) => item), columns ); const align: TrustAlignment = alignment ?? 'center'; const showIconsResolved = showIcons ?? true; const iconSizeResolved: TrustIconSize = iconSize ?? 'md'; const showDivider = divider ?? false; const alignClass = align === 'center' ? 'items-center text-center' : 'items-start text-left'; return ( <> {/* Configured column count only applies from md up; mobile stacks to a single column and small screens show two, so 3–6 value props don't crush into ~60px cells on a phone. The count rides a CSS variable so the media query can honor the arbitrary 2–6 setting. */}