// /pribehy/ index — React-rendered for filter/sort interactivity.
// Detail pages (/pribehy/<slug>/) are built as fully-static HTML by build-site.py;
// they never load React. This file only runs on the index page.
//
// Legacy hash URL fallback: if someone lands on /pribehy/#<slug> (old short URL),
// redirect to the new /pribehy/<slug>/ path.

(function legacyHashRedirect() {
  const m = window.location.hash.match(/^#\/?(?:pribehy\/)?([a-z0-9-]+)\/?$/);
  if (!m) return;
  const slug = m[1];
  // Verify slug exists in STORIES (loaded synchronously by data.jsx already)
  if (typeof STORIES !== "undefined" && STORIES.some((s) => s.slug === slug)) {
    const base = window.location.pathname.replace(/\/$/, "");
    window.location.replace(`${base}/${slug}/`);
  }
})();

function App() {
  // Determine current language from URL prefix.
  const path = window.location.pathname;
  const lang = path.startsWith("/vi/") ? "vi"
             : path.startsWith("/en/") ? "en"
             : "cs";

  return <StoriesScreen lang={lang} />;
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
