/* global React */

const { useState, useEffect, useRef } = React;

// Live session timer — purely decorative, resets on page load.
function Uptime() {
  const start = useRef(Date.now());
  const [now, setNow] = useState(0);

  useEffect(() => {
    const id = setInterval(() => setNow(Date.now() - start.current), 1000);
    return () => clearInterval(id);
  }, []);

  const s  = Math.floor(now / 1000);
  const hh = String(Math.floor(s / 3600)).padStart(2, "0");
  const mm = String(Math.floor((s % 3600) / 60)).padStart(2, "0");
  const ss = String(s % 60).padStart(2, "0");

  return (
    <span className="live">
      <span className="dot" />
      <span>UPTIME {hh}:{mm}:{ss}</span>
    </span>
  );
}

Object.assign(window, { Uptime });
