/* === Shared: constants, Header, Footer, building blocks === */
const SITE = {
domain: "vinodepasto.com",
buyUrl: "https://bodegasbaron.es/collections/tienda-online?filter.p.tag=Paranormal&utm_source=vinodepasto.com&utm_medium=referral&utm_campaign=paranormal_pasto10",
buyUrlBlanco: "https://bodegasbaron.es/products/vino-blanco-paranormal?utm_source=vinodepasto.com&utm_medium=referral&utm_campaign=paranormal_blanco_pasto10",
buyUrlOxidativo: "https://bodegasbaron.es/products/vino-blanco-oxidativo-paranormal-2023?utm_source=vinodepasto.com&utm_medium=referral&utm_campaign=paranormal_oxidativo_pasto10",
coupon: "PASTO10",
};
const NAV = [
{ id: "home", label: "Inicio", path: "/" },
{ id: "que-es", label: "Vino de Pasto", path: "/que-es-vino-de-pasto" },
{ id: "paranormal", label: "Paranormal", path: "/paranormal" },
{ id: "bodega", label: "Bodegas Barón", path: "/bodegas-baron" },
{ id: "blog", label: "Cuaderno", path: "/blog" },
];
const NAV_EN = [
{ id: "home", label: "Home", path: "/en" },
{ id: "que-es", label: "Vino de Pasto", path: "/en/wine-de-pasto" },
{ id: "paranormal", label: "Paranormal", path: "/en/paranormal" },
{ id: "bodega", label: "Bodegas Barón", path: "/en/bodegas-baron" },
{ id: "blog", label: "Notebook", path: "/en/notebook" },
];
function currentLang() { return window.location.pathname.startsWith("/en") ? "en" : "es"; }
function langPath(path) { return currentLang() === "en" ? "/en" + (path === "/" ? "" : path) : path; }
function isExternalUrl(to) { return typeof to === "string" && /^(https?:)?\/\//.test(to); }
function switchLangPath() {
const p = window.location.pathname.replace(/\/$/, "") || "/";
if (p === "/en") return "/";
if (p.startsWith("/en/")) {
const rest = p.slice(3);
const map = { "/wine-de-pasto": "/que-es-vino-de-pasto", "/paranormal": "/paranormal", "/bodegas-baron": "/bodegas-baron", "/notebook": "/blog" };
return map[rest] || "/";
}
const map = { "/": "/en", "/que-es-vino-de-pasto": "/en/wine-de-pasto", "/paranormal": "/en/paranormal", "/bodegas-baron": "/en/bodegas-baron", "/blog": "/en/notebook" };
return map[p] || "/en";
}
/* --- clean URL router with hash fallback for old links --- */
function normalisePath() {
const hash = window.location.hash.replace(/^#/, "");
if (hash && hash.startsWith("/")) return hash;
return window.location.pathname.replace(/\/$/, "") || "/";
}
function useRoute() {
const [route, setRoute] = React.useState(() => normalisePath());
React.useEffect(() => {
const refresh = () => {
setRoute(normalisePath());
window.scrollTo({ top: 0, behavior: "instant" });
};
window.addEventListener("popstate", refresh);
window.addEventListener("hashchange", refresh);
return () => {
window.removeEventListener("popstate", refresh);
window.removeEventListener("hashchange", refresh);
};
}, []);
return route;
}
function go(path) {
window.history.pushState({}, "", path);
window.dispatchEvent(new PopStateEvent("popstate"));
}
function Link({ to, children, className, style, onClick }) {
return (
{
if (onClick) onClick(e);
if (!e.defaultPrevented && to && to.startsWith("/")) {
e.preventDefault();
go(to);
}
}}
>
{children}
);
}
/* === Header === */
function Header({ route }) {
const lang = currentLang();
const nav = lang === "en" ? NAV_EN : NAV;
const en = lang === "en";
const active = (path) => {
if (path === "/" || path === "/en") return route === path || (path === "/" && route === "");
return route === path || route.startsWith(path + "/");
};
const buyPath = en ? "/en/paranormal" : "/paranormal";
const langTarget = switchLangPath();
return (
{en ? "Sections" : "Secciones"}{en ? "Open" : "Abrir"}