// Top bar, nav, marquee and footer (TypeScript).
// Loaded as a global script — no import/export. Published on window at the end.

const TopBar: FC = () => {
  const { brand } = window.RIO3_DATA;
  return (
    <div className="topbar">
      <div className="shell">
        <div className="topbar-note">
          <span className="topbar-dot" aria-hidden="true" />
          Welcoming new patients · {brand.address}, {brand.city}
        </div>
        <div className="topbar-links">
          <a href={`tel:${brand.phone}`}>{brand.phone}</a>
          <span className="pipe" aria-hidden="true">·</span>
          <a href={`mailto:${brand.email}`}>{brand.email}</a>
        </div>
      </div>
    </div>
  );
};

const Nav: React.FC<NavProps> = ({ page, setPage, onBook }) => {
  const [open, setOpen] = React.useState(false);
  const links: { id: PageId; label: string }[] = [
    { id: "home", label: "Home" },
    { id: "treatments", label: "Treatments" },
    { id: "programs", label: "Programs" },
    { id: "contact", label: "Visit" },
  ];
  const close = () => setOpen(false);
  return (
    <nav className="nav" aria-label="Main">
      <div className="shell">
        <a
          onClick={() => { setPage("home"); close(); }}
          style={{ cursor: "pointer" }}
          aria-label="Rio3 — home"
        >
          <LogoSlot w={150} h={54} />
        </a>
        <div className={`nav-links${open ? " open" : ""}`}>
          {links.map((l) => (
            <a
              key={l.id}
              className={`nav-link ${page === l.id ? "active" : ""}`}
              aria-current={page === l.id ? "page" : undefined}
              onClick={() => { setPage(l.id); close(); }}
              style={{ cursor: "pointer" }}
            >
              {l.label}
            </a>
          ))}
        </div>
        <div className={`nav-cta${open ? " open" : ""}`}>
          <button
            className="btn btn-primary"
            onClick={() => { close(); if (onBook) onBook("consultation"); }}
          >
            Book <Arrow />
          </button>
        </div>
        <button
          className="nav-hamburger"
          onClick={() => setOpen(!open)}
          aria-label={open ? "Close menu" : "Open menu"}
          aria-expanded={open}
        >
          {open ? "✕" : "☰"}
        </button>
      </div>
    </nav>
  );
};

const Marquee: FC = () => {
  // Verifiable statements only.
  const items: string[] = [
    "Established 2019",
    "Root-cause integrative medicine",
    "Ozone · IV · Regenerative",
    "Deerfield Beach, Florida",
    "Multilingual care · EN · PT · ES",
    "Welcoming new patients",
  ];
  const row = (
    <span aria-hidden="true">
      {items.map((t, i) => (
        <React.Fragment key={i}>
          <span>{t}</span>
          <span className="sep" />
        </React.Fragment>
      ))}
    </span>
  );
  return (
    <div className="marquee" role="presentation">
      <div className="marquee-track">
        {row}
        {row}
      </div>
    </div>
  );
};

const Footer: React.FC<FooterProps> = ({ setPage }) => {
  const { brand, hours } = window.RIO3_DATA;
  return (
    <footer className="footer">
      <div className="shell">
        <div className="footer-grid">
          <div>
            <Brand size={52} dark />
            <p className="tagline" style={{ marginTop: 20 }}>
              Clinician-led integrative health — ozone therapy, IV nutrition and
              regenerative medicine in Deerfield Beach, Florida.
            </p>
          </div>
          <div>
            <h2 className="footer-col-title">Explore</h2>
            <ul>
              <li><a onClick={() => setPage("treatments")} style={{ cursor: "pointer" }}>Treatments &amp; pricing</a></li>
              <li><a onClick={() => setPage("programs")} style={{ cursor: "pointer" }}>Programs</a></li>
              <li><a onClick={() => setPage("contact")} style={{ cursor: "pointer" }}>Visit the clinic</a></li>
              {/* Static service pages — real hrefs so crawlers can reach them. */}
              <li><a href="/ozone-therapy">Ozone Therapy</a></li>
              <li><a href="/iv-therapy">IV Therapy</a></li>
              <li><a href="/prolozone-prp">Prolozone &amp; PRP</a></li>
              <li><a href="/colon-hydrotherapy">Colon Hydrotherapy</a></li>
              <li><a href="/glp-1-weight-loss">GLP-1 Weight Loss</a></li>
              <li><a href="/prp-facial">PRP Facial</a></li>
              <li><a href="/lab-testing">Labs &amp; Testing</a></li>
              <li><a href="/consultations">Consultations</a></li>
              <li><a href="/services">All services</a></li>
            </ul>
          </div>
          <div>
            <h2 className="footer-col-title">Hours</h2>
            <ul className="footer-hours">
              {hours.map((h) => (
                <li key={h.day} className={h.closed ? "closed" : ""}>
                  <span>{h.day.slice(0, 3)}</span>
                  <span>{h.open}</span>
                </li>
              ))}
            </ul>
          </div>
          <div>
            <h2 className="footer-col-title">Contact</h2>
            <ul>
              <li><a href={`tel:${brand.phone}`}>{brand.phone}</a></li>
              <li><a href={`mailto:${brand.email}`}>{brand.email}</a></li>
              <li style={{ paddingTop: 12 }}>{brand.address}</li>
              <li>{brand.city}</li>
            </ul>
          </div>
        </div>
        <div className="footer-base">
          <span>© {new Date().getFullYear()} Rio3 | Ozone Therapy. All rights reserved.</span>
          <span className="legal">
            <a href="/privacy-policy">Privacy Policy</a>
            <a href="/terms">Terms of Service</a>
            <a href="/medical-disclaimer">Medical Disclaimer</a>
            <a href="/accessibility">Accessibility</a>
          </span>
        </div>
      </div>
    </footer>
  );
};

Object.assign(window, { TopBar, Nav, Marquee, Footer });
