import Image from "next/image"; import Link from "next/link"; import { Check } from "lucide-react"; import type { CmsProductContent } from "@/types/cms-landing"; const DEFAULT_TITLE = "The product we offer is designed to meet your business needs."; const DEFAULT_BODY = "Social media marketing services are provided by companies or individuals who specialize in marketing strategies through social media platforms."; function cardImageUrl(p: CmsProductContent) { return p.images?.[0]?.image_url?.trim() || "/image/p1.png"; } /** Normalize CMS link: relative paths and full URLs; bare domains get https:// */ function resolveProductLink(raw: string | undefined | null): string | null { const t = raw?.trim(); if (!t) return null; if (/^(https?:|\/|#|mailto:)/i.test(t)) return t; return `https://${t}`; } function LearnMoreCta({ href }: { href?: string | null }) { const resolved = resolveProductLink(href); const className = "inline-flex text-sm font-semibold text-[#966314] hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#966314]"; if (!resolved) return null; if (resolved.startsWith("/")) { return ( Learn More → ); } return ( Learn More → ); } /** Renders "Label: rest" with a bold label when a colon is present (one colon split). */ function BulletLine({ text }: { text: string }) { const idx = text.indexOf(":"); if (idx > 0 && idx < text.length - 1) { const label = text.slice(0, idx).trim(); const rest = text.slice(idx + 1).trim(); return ( <> {label}: {rest} ); } return <>{text}; } function ProductImageBlock({ imgSrc, alt, }: { imgSrc: string; alt: string; }) { const external = /^https?:\/\//i.test(imgSrc); return (
{external ? ( // eslint-disable-next-line @next/next/no-img-element {alt} ) : ( {alt} )}
); } function ProductOrderBadge({ order }: { order: number }) { return (
{order}
); } function ProductTextBlock({ p, order }: { p: CmsProductContent; order: number }) { const rawDesc = p.description?.trim(); const lines = rawDesc ? rawDesc.split(/\r?\n/).map((l) => l.trim()).filter(Boolean) : []; const useBullets = lines.length > 1; const bodyText = lines.length === 0 ? DEFAULT_BODY : rawDesc ?? ""; return (

{p.primary_title?.trim() || "Product"}

{p.secondary_title?.trim() ? (

{p.secondary_title.trim()}

) : null} {useBullets ? ( ) : (

{bodyText}

)}
); } export default function ProductSection({ products, }: { products?: CmsProductContent[] | null; }) { const list = products?.filter((p) => p.id) ?? []; if (list.length === 0) { return (

Our Product

{DEFAULT_TITLE}

MediaHUB Content Aggregator

{DEFAULT_BODY}

); } return (

Our Product

The product we offer is designed to meet your business needs.

{list.map((p, index) => { const imgSrc = cardImageUrl(p); const alt = p.primary_title?.trim() || "Product"; const reverse = index % 2 === 1; return (
); })}
); }