/* global React */
/* Shared chrome: TopStrip, Nav, Footer, EmergencyPill, LocationSwitcher */
const { useState, useEffect, useRef } = React;
const D = window.BVH_DATA;
function TopStrip() {
return (
);
}
function Nav({ route, setRoute, location, setLocation }) {
const links = [
{ id: "home", label: "Home" },
{ id: "services", label: "Services" },
{ id: "team", label: "Team" },
{ id: "locations", label: "Locations" },
{ id: "emergency", label: "Emergency" },
{ id: "about", label: "About" },
];
return (
setRoute("home")}>
BV
British Veterinary Hospital
EST. JUMEIRAH · DUBAI
{links.map(l => (
setRoute(l.id)}
>
{l.label}
))}
setRoute("book")}>
Book appointment
);
}
function LocationSwitcher({ location, setLocation, big }) {
const [open, setOpen] = useState(false);
const ref = useRef(null);
useEffect(() => {
function onDoc(e) { if (ref.current && !ref.current.contains(e.target)) setOpen(false); }
document.addEventListener("mousedown", onDoc);
return () => document.removeEventListener("mousedown", onDoc);
}, []);
const current = D.locations.find(l => l.id === location);
return (
setOpen(o => !o)}>
{big ? `Showing ${current.short}` : current.short}
▾
{open && (
{D.locations.map(l => (
{ setLocation(l.id); setOpen(false); }}
style={{
display:'block',
width:'100%',
textAlign:'left',
padding:'12px 14px',
borderRadius:5,
background: l.id === location ? 'var(--paper-2)' : 'transparent',
}}
>
{l.name}
{l.addressLine1}
{l.hoursLine}
))}
)}
);
}
function EmergencyPill() {
return (
);
}
function Footer({ setRoute }) {
return (
);
}
/* small util — render a title array with ... markers */
function RenderTitle({ chunks }) {
return (
{chunks.map((c, i) => (
{c.includes('')
? {c.replace(/<\/?em>/g,'')}
: c}
{i < chunks.length-1 && ' '}
))}
);
}
Object.assign(window, { TopStrip, Nav, LocationSwitcher, EmergencyPill, Footer, RenderTitle, BVH_D: D });