import { useEffect, useMemo } from 'react'; import CdnGallery from './CdnGallery'; import { getBusinessDomain, getBusinessImage, getBusinessName, getBusinessTagline, } from '../utils/businessProfile'; function normalizeText(value) { return typeof value === 'string' ? value.trim() : ''; } function normalizeUniqueStrings(value) { if (!Array.isArray(value)) return []; const seen = new Set(); return value .map((entry) => normalizeText(entry)) .filter((entry) => { if (!entry || seen.has(entry)) return false; seen.add(entry); return true; }); } function normalizeColorEntries(value) { if (!Array.isArray(value)) return []; const seen = new Set(); return value .map((entry, index) => { if (typeof entry === 'string') { const hex = normalizeText(entry); return hex ? { name: '', hex, key: `${hex}:${index}` } : null; } if (!entry || typeof entry !== 'object') return null; const hex = normalizeText(entry.hex || entry.value || entry.color); if (!hex) return null; const name = normalizeText(entry.name || entry.label || entry.role); return { name, hex, key: `${name}:${hex}` }; }) .filter((entry) => { if (!entry || seen.has(entry.key)) return false; seen.add(entry.key); return true; }); } function extractCdnUrls(business) { const artifactUrls = business?.scrapeArtifacts?.cdnUrls; if (Array.isArray(artifactUrls) && artifactUrls.length > 0) { return normalizeUniqueStrings(artifactUrls); } return normalizeUniqueStrings(business?.relevantImagePaths); } function normalizeScrapeLinks(value) { if (!Array.isArray(value)) return []; const seen = new Set(); return value .map((entry) => { if (typeof entry === 'string') { const href = normalizeText(entry); return href ? { href, label: href } : null; } if (!entry || typeof entry !== 'object') return null; const href = normalizeText(entry.href || entry.url || entry.link); if (!href) return null; const label = normalizeText(entry.text || entry.title || entry.label || href); return { href, label }; }) .filter((entry) => { if (!entry || seen.has(entry.href)) return false; seen.add(entry.href); return true; }); } function formatPrettyJson(value) { if (value == null) return ''; if (typeof value === 'string') { try { return JSON.stringify(JSON.parse(value), null, 2); } catch { return value; } } try { return JSON.stringify(value, null, 2); } catch { return String(value); } } function extractColors(business) { const labeledColors = normalizeColorEntries(business?.scrapeArtifacts?.json?.branding?.labeledColors); if (labeledColors.length > 0) return labeledColors; const directColors = normalizeColorEntries(business?.colors); if (directColors.length > 0) return directColors; const brandingColors = business?.scrapeArtifacts?.json?.branding?.colors; return normalizeColorEntries(brandingColors); } function extractAboutText(business) { const directSummary = normalizeText(business?.aboutSummary); if (directSummary) return directSummary; const scrapeJson = business?.scrapeArtifacts?.json; const aboutExcerpt = normalizeText(scrapeJson?.aboutPage?.excerpt); if (aboutExcerpt) return aboutExcerpt; const representativeAbout = Array.isArray(scrapeJson?.representativeTextBlocks) ? scrapeJson.representativeTextBlocks.find((block) => normalizeText(block?.pageType) === 'about') : null; const representativeAboutText = normalizeText(representativeAbout?.text); if (representativeAboutText) return representativeAboutText; const homepageExcerpt = normalizeText(scrapeJson?.homepage?.excerpt); if (homepageExcerpt) return homepageExcerpt; return normalizeText(scrapeJson?.summaryText); } export default function BusinessReviewModal({ business, onClose }) { const name = getBusinessName(business); const domain = getBusinessDomain(business); const tagline = getBusinessTagline(business); const image = getBusinessImage(business); const tone = normalizeText(business?.tone); const taglines = normalizeUniqueStrings(business?.taglines); const colors = extractColors(business); const aboutText = extractAboutText(business); const cdnUrls = extractCdnUrls(business); const links = normalizeScrapeLinks(business?.scrapeArtifacts?.links); const prettyJson = useMemo(() => formatPrettyJson(business?.scrapeArtifacts?.json), [business]); useEffect(() => { const previousBodyOverflow = document.body.style.overflow; const previousBodyOverscroll = document.body.style.overscrollBehavior; const previousHtmlOverflow = document.documentElement.style.overflow; const previousHtmlOverscroll = document.documentElement.style.overscrollBehavior; document.body.style.overflow = 'hidden'; document.body.style.overscrollBehavior = 'none'; document.documentElement.style.overflow = 'hidden'; document.documentElement.style.overscrollBehavior = 'none'; return () => { document.body.style.overflow = previousBodyOverflow; document.body.style.overscrollBehavior = previousBodyOverscroll; document.documentElement.style.overflow = previousHtmlOverflow; document.documentElement.style.overscrollBehavior = previousHtmlOverscroll; }; }, []); return (

Business review

{name}

{domain ? `Review the captured storefront context for ${domain}.` : 'Review the captured storefront context before moving on.'}

{image ? ( {name} ) : ( {name?.[0]?.toUpperCase() || 'B'} )}

{name}

{domain &&

{domain}

} {tagline &&

{tagline}

}
{tone && ( Tone: {tone} )} {cdnUrls.length} image{cdnUrls.length === 1 ? '' : 's'} {links.length} link{links.length === 1 ? '' : 's'} {colors.length} color{colors.length === 1 ? '' : 's'}
{aboutText && (

About Company

A concise summary of what the brand is about, what it sells, and its overall vibe.

{aboutText}

)} {(taglines.length > 0 || colors.length > 0) && (
{taglines.length > 0 && (

Taglines

Short brand lines captured during onboarding.

{taglines.map((entry, index) => (

"{entry}"

))}
)} {colors.length > 0 && (

Color Codes

Detected brand colors used across the storefront.

{colors.map((color) => (
{color.name && ( {color.name} )} {color.hex}
))}
)}
)} {cdnUrls.length > 0 && (

Images

Captured storefront images are available below.

)} {prettyJson && (

Captured Data

Raw storefront data captured during onboarding.

                    {prettyJson}
                  
)} {links.length > 0 && (

Links

Every discovered storefront link is available below.

{links.map((link, index) => (

{link.label}

{link.href}

))}
)}
); }