diff --git a/src/components/sections/StreetSpecialsSection.tsx b/src/components/sections/StreetSpecialsSection.tsx new file mode 100644 index 0000000..33063f1 --- /dev/null +++ b/src/components/sections/StreetSpecialsSection.tsx @@ -0,0 +1,86 @@ +'use client' + +import { useState, useEffect } from 'react' +import { useEmDashContent } from '@/hooks/useEmDashContent' +import Image from 'next/image' +import Button from '@/components/ui/Button' + +const CURRENCY_SYMBOLS: Record = { zar: 'R', usd: '$', eur: '€', gbp: '£', kes: 'KSh', ngn: '₦', ghs: '₵' } +const formatPrice = (amount: number, code?: string) => { + const sym = CURRENCY_SYMBOLS[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '') + return `${sym}${(amount / 100).toFixed(2)}` +} + +function Countdown({ availableUntil }: { availableUntil?: string }) { + const [timeLeft, setTimeLeft] = useState('') + + useEffect(() => { + if (!availableUntil) return + const target = new Date(availableUntil).getTime() + const update = () => { + const now = Date.now() + const diff = target - now + if (diff <= 0) { setTimeLeft('Expired'); return } + const days = Math.floor(diff / (1000 * 60 * 60 * 24)) + const hours = Math.floor((diff / (1000 * 60 * 60)) % 24) + const mins = Math.floor((diff / (1000 * 60)) % 60) + setTimeLeft(`${days}d ${hours}h ${mins}m`) + } + update() + const id = setInterval(update, 60000) + return () => clearInterval(id) + }, [availableUntil]) + + return {timeLeft} +} + +export default function StreetSpecialsSection() { + const { items, loading } = useEmDashContent('specials') + + if (loading) { + return
+ } + + if (items.length === 0) return null + + return ( +
+
+

Street Specials

+
+ {items.map((item) => { + const d = item.data as { title?: string; description?: string; price?: number; available_until?: string; image?: string } + return ( +
+ {d.image && ( +
+ {d.title +
+ )} +
+

{d.title}

+

{d.description}

+
+ + {formatPrice(d.price ?? 0, 'zar')} + + +
+ +
+
+ ) + })} +
+
+
+ ) +}