diff --git a/src/components/sections/BusinessHoursSection.tsx b/src/components/sections/BusinessHoursSection.tsx new file mode 100644 index 0000000..f80931b --- /dev/null +++ b/src/components/sections/BusinessHoursSection.tsx @@ -0,0 +1,76 @@ +'use client' +import { useVulaContent } from '@/hooks/useVulaContent' +import Badge from '@/components/ui/Badge' + +const DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] + +function parseTime(value?: string): number | null { + if (!value) return null + const parts = value.split(':') + const hours = Number(parts[0]) + const minutes = parts[1] ? Number(parts[1]) : 0 + if (Number.isNaN(hours) || Number.isNaN(minutes)) return null + return hours * 60 + minutes +} + +function isOpenNow(d: { day_of_week?: string; open_time?: string; close_time?: string; is_closed?: boolean }) { + if (String(d.is_closed).toLowerCase() === 'true') return false + const now = new Date() + if (String(d.day_of_week ?? '').toLowerCase() !== DAYS[now.getDay()].toLowerCase()) return false + const current = now.getHours() * 60 + now.getMinutes() + const open = parseTime(d.open_time) + const close = parseTime(d.close_time) + if (open === null || close === null) return false + return current >= open && current < close +} + +export default function BusinessHoursSection() { + const { items = [], loading } = useVulaContent('business_hours') + + if (loading) return
Fourways, Johannesburg
+Walk-ins welcome, but booking ahead saves your chair.
+