/* App.jsx — routes between Home and the three tabs (Software, Photography, Videography). */
const { useState: useAppState, useEffect: useAppEffect } = React;

const TAB_TITLES = { software: "Software", photography: "Photography", videography: "Videography" };
const RESUME_URL = ASSET_BASE + "Neel-Satyavolu-Resume.pdf";

function App() {
  const route = useRoute();
  const [video, setVideo] = useAppState(null);
  const tab = TAB_TITLES[route[0]] ? route[0] : null;
  const unknown = route.length > 0 && !tab;

  useAppEffect(() => {
    // Photography sets its own title for collections and photos.
    if (tab === "photography" && route[1]) return;
    document.title = tab ? `${TAB_TITLES[tab]} — Neel Satyavolu` : "Neel Satyavolu — Broadcast Journalist";
  }, [route.join("/")]);

  const resume = () => { window.open(RESUME_URL, "_blank"); };
  const toAbout = () => {
    const el = document.getElementById("about");
    if (el) window.scrollTo({ top: el.offsetTop - 72, behavior: "smooth" });
  };

  // A new key per page (not per open photo) replays the page entrance and the red cut bar.
  const pageKey = route.slice(0, 2).join("/") || "home";

  return (
    <React.Fragment>
      <Nav active={tab} onResume={resume} />
      {pageKey !== "home" && <div className="cut-bar" key={"cut-" + pageKey} aria-hidden="true" />}
      <main key={pageKey} className={pageKey === "home" ? undefined : "route-in"}>
        {!tab && !unknown && (
          <React.Fragment>
            <Hero onResume={resume} onNav={toAbout} />
            <HomeIndex />
          </React.Fragment>
        )}
        {unknown && (
          <Section style={{ paddingBottom: "var(--section)" }}>
            <PageHead kicker="Not found" title="This page doesn't exist" lede="The link may be old. Everything lives under Software, Photography and Videography." />
            <Link className="btn btn-ghost" to="/">Go home</Link>
          </Section>
        )}
        {tab === "software" && <Software />}
        {tab === "photography" && <Photography route={route.slice(1)} />}
        {tab === "videography" && <Work onPlay={setVideo} />}
      </main>
      <Footer onResume={resume} compact={!!tab || unknown} />
      {video && <VideoPlayer video={video} onClose={() => setVideo(null)} />}
    </React.Fragment>
  );
}

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