import type { LucideIcon } from 'lucide-react'; import { Award, Clock, Gift, Heart, Leaf, MapPin, MessageCircle, Package, RefreshCw, ShieldCheck, Star, Truck, } from 'lucide-react'; import { useStorefront } from '../context'; import { storefrontText } from '../text'; import { formatPrice } from '../theme'; import type { TrustBarSection, TrustIcon, TrustItem } from '../types'; import { Container } from '../ui'; import { cn } from '@/lib/utils'; const icons: Record = { truck: Truck, shield: ShieldCheck, chat: MessageCircle, refresh: RefreshCw, leaf: Leaf, star: Star, gift: Gift, clock: Clock, heart: Heart, award: Award, 'map-pin': MapPin, package: Package, }; type Shown = { icon: LucideIcon; title: string; text: string | null }; /** * Short reassurances, such as free shipping and secure payment. * Shipping, payment and WhatsApp items are written from the store's real settings, so they are always true. */ export function TrustBar({ section }: { section: TrustBarSection }) { const { shop, language } = useStorefront(); const t = storefrontText(language); function show(item: TrustItem): Shown | null { const icon = item.icon ? icons[item.icon] : undefined; switch (item.kind) { case 'shipping': { const free = shop.free_shipping_over; return { icon: icon ?? Truck, title: free === 0 ? t.trustFreeShipping : free !== null ? t.trustFreeShippingOver(formatPrice(free)) : t.trustShippingFrom( formatPrice(shop.shipping_from), ), text: t.trustShippingText, }; } case 'payment': return { icon: icon ?? ShieldCheck, title: t.trustPayment, text: t.trustPaymentText, }; case 'whatsapp': return shop.whatsapp ? { icon: icon ?? MessageCircle, title: t.trustWhatsApp, text: t.trustWhatsAppText, } : null; default: return item.title ? { icon: icon ?? Star, title: item.title, text: item.text ?? null, } : null; } } const items = section.content.items .map(show) .filter((item): item is Shown => item !== null); if (items.length === 0) { return null; } const columns = items.length >= 4 ? 'md:grid-cols-4' : items.length === 3 ? 'md:grid-cols-3' : 'md:grid-cols-2'; if (section.variant === 'boxed') { return (
    {items.map((item) => (
  • ))}
); } return (
    {items.map((item) => (
  • {item.title}

    {item.text && (

    {item.text}

    )}
  • ))}
); }