{{define "base"}}<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>{{block "title" .}}restic-manager{{end}}</title>
  <link rel="stylesheet" href="/static/css/styles.css">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
  <script src="https://unpkg.com/htmx.org@1.9.12" defer></script>
</head>
<body class="min-h-screen">

  {{template "nav" .}}

  <main>
    {{block "content" .}}{{end}}
  </main>

  {{template "toast" .}}

  <script>
  // Tick <time data-rel-ts> labels so long-open tabs don't freeze
  // (e.g. a job page rendered an hour ago kept showing "2h ago" when
  // the truth was "3h ago"). Buckets must match relTimeLabel in
  // internal/server/ui/funcs.go.
  (function () {
    function label(ms) {
      var suffix = 'ago';
      if (ms < 0) { ms = -ms; suffix = 'from now'; }
      var s = Math.floor(ms / 1000);
      if (s < 60) return s + 's ' + suffix;
      var m = Math.floor(s / 60);
      if (m < 60) return m + 'm ' + suffix;
      var h = Math.floor(m / 60);
      if (h < 24) return h + 'h ' + suffix;
      var d = Math.floor(h / 24);
      if (d < 7) return d + 'd ' + suffix;
      return Math.floor(d / 7) + 'w ' + suffix;
    }
    function tick() {
      var now = Date.now();
      document.querySelectorAll('time[data-rel-ts]').forEach(function (el) {
        var t = Date.parse(el.getAttribute('data-rel-ts'));
        if (!isNaN(t)) el.textContent = label(now - t);
      });
    }
    tick();
    setInterval(tick, 30000);
  })();
  </script>

</body>
</html>
{{end}}
