All files / src/app/jurisdictions page.tsx

100% Statements 29/29
89.18% Branches 33/37
100% Functions 15/15
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 3051x                                         1x                     1x                         192x                     24x 24x     144x                                   24x 24x 24x                                                                           16x                             24x               72x                                                               32x                 88x                                       10x 10x 10x 10x   10x 5x   5x 5x 1x   4x       1x       10x                                                                                                                           24x                     24x                  
"use client";
 
import { fetchApi } from "@/lib/api";
import type {
  Jurisdiction,
  JurisdictionsResponse,
  Milestone,
} from "@/lib/jurisdictions";
import { useEffect, useState } from "react";
import Link from "next/link";
import { AlertCircle, ExternalLink, Loader2, Scale } from "lucide-react";
import { useT } from "@/lib/i18n/translate";
 
/**
 * How six member states implement the secondary use of Regulation (EU)
 * 2025/327 (#782). The Regulation is the same everywhere; the access body,
 * the national law it acts under, the way a person objects, the fees and the
 * dates differ. The laws and legal roles are real, the organisations on the
 * hub fictional.
 */
 
const LANGUAGE_NAMES: Record<string, string> = {
  de: "German",
  fr: "French",
  nl: "Dutch",
  es: "Spanish",
  en: "English",
  ca: "Catalan",
  eu: "Basque",
  gl: "Galician",
};
 
const LAW_STATUS: Record<string, string> = {
  IN_FORCE: "in force",
  BILL: "bill",
  DRAFT: "draft",
};
 
function Field({
  label,
  children,
}: {
  label: string;
  children: React.ReactNode;
}) {
  return (
    <div className="grid grid-cols-1 sm:grid-cols-[11rem_1fr] gap-1 sm:gap-3 py-2 border-b border-(--border) last:border-0">
      <dt className="text-xs font-semibold uppercase tracking-wide text-(--text-secondary)">
        {label}
      </dt>
      <dd className="text-sm text-(--text-primary)">{children}</dd>
    </div>
  );
}
 
function MilestoneList({ milestones }: { milestones: Milestone[] }) {
  const t = useT("jurisdictions");
  return (
    <ol className="space-y-1">
      {milestones.map((m) => (
        <li key={m.milestoneId} className="flex gap-3">
          <span className="font-mono text-xs w-24 shrink-0 pt-0.5">
            {m.date}
          </span>
          <span>
            {m.label}
            <span className="ml-2 text-[10px] font-bold uppercase tracking-wider text-(--text-secondary)">
              {m.scope === "EU" ? "EU" : t("national")}
              {m.status === "PLANNED" ? t(", planned") : ""}
            </span>
          </span>
        </li>
      ))}
    </ol>
  );
}
 
function Profile({ j }: { j: Jurisdiction }) {
  const lang = j.languages[0];
  const t = useT("jurisdictions");
  return (
    <section
      id={j.code.toLowerCase()}
      data-testid={`jurisdiction-${j.code}`}
      className="rounded-xl border border-(--border) bg-(--surface) p-5 scroll-mt-20"
    >
      <h2 className="text-lg font-bold text-(--text-primary) flex items-baseline gap-2">
        <span className="font-mono text-sm px-2 py-0.5 rounded-sm bg-(--surface-2)">
          {j.code}
        </span>
        {j.name}
        {j.nameNative !== j.name && (
          <span
            lang={lang}
            className="text-sm font-normal text-(--text-secondary)"
          >
            {j.nameNative}
          </span>
        )}
      </h2>
      <p className="text-sm text-(--text-secondary) mt-2">{j.summary}</p>
 
      <dl className="mt-4">
        <Field label={t("Access body (role)")}>
          <span lang={lang}>{j.accessBodyRole}</span>
          {j.accessBodyRoleEn !== j.accessBodyRole && (
            <span className="text-(--text-secondary)">
              {" "}
              ({j.accessBodyRoleEn})
            </span>
          )}
          <p className="text-xs text-(--text-secondary) mt-1">
            {j.designationStatus}
          </p>
        </Field>
        <Field label={t("On the hub")}>
          {j.accessBodies.length > 0 ? (
            j.accessBodies.map((b) => (
              <span key={b.participantId} className="mr-3">
                {b.name}{" "}
                <span className="text-xs text-(--text-secondary)">
                  {t("(fictional access body)")}
                </span>
              </span>
            ))
          ) : (
            <span className="text-(--text-secondary)">
              {t("No access body of this country on the hub yet.")}
            </span>
          )}
          {j.participants.length > 0 && (
            <p className="text-xs text-(--text-secondary) mt-1">
              {t("Also under it: {names}", {
                names: j.participants.map((p) => p.name).join(", "),
              })}
            </p>
          )}
        </Field>
        <Field label={t("National legal basis")}>
          <ul className="space-y-1.5">
            {j.laws.map((l) => (
              <li key={l.lawId}>
                {l.url ? (
                  <a
                    href={l.url}
                    target="_blank"
                    rel="noopener noreferrer"
                    lang={lang}
                    className="text-(--accent) underline"
                  >
                    {l.title}
                  </a>
                ) : (
                  <span lang={lang}>{l.title}</span>
                )}
                {l.citation && (
                  <span className="text-(--text-secondary)">
                    , {l.citation}
                  </span>
                )}
                <span className="block text-xs text-(--text-secondary)">
                  {l.titleEn}
                  {" · "}
                  {LAW_STATUS[l.status] ? t(LAW_STATUS[l.status]) : l.status}
                </span>
              </li>
            ))}
          </ul>
        </Field>
        <Field label={t("Objecting (Art. 71)")}>{j.optOutModel}</Field>
        <Field label={t("Fees (Art. 62)")}>{j.fees}</Field>
        <Field label={t("Languages")}>
          {j.languages
            .map((l) => (LANGUAGE_NAMES[l] ? t(LANGUAGE_NAMES[l]) : l))
            .join(", ")}
        </Field>
        <Field label={t("Timeline")}>
          <MilestoneList milestones={j.milestones} />
        </Field>
        <Field label={t("Sources")}>
          <ul className="space-y-0.5">
            {j.sources.map((s) => (
              <li key={s} className="text-xs break-all">
                <a
                  href={s}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="text-(--accent) underline inline-flex items-center gap-1"
                >
                  {s}
                  <ExternalLink size={10} aria-hidden="true" />
                </a>
              </li>
            ))}
          </ul>
        </Field>
      </dl>
    </section>
  );
}
 
export default function JurisdictionsPage() {
  const [data, setData] = useState<JurisdictionsResponse | null>(null);
  const [error, setError] = useState<string | null>(null);
  const t = useT("jurisdictions");
  const tc = useT("common");
 
  useEffect(() => {
    fetchApi("/api/jurisdictions")
      .then(async (r) => {
        const body = await r.json();
        if (!r.ok || body?.error) {
          throw new Error(body?.error || `HTTP ${r.status}`);
        }
        return body as JurisdictionsResponse;
      })
      .then(setData)
      .catch((e: unknown) =>
        setError(e instanceof Error ? e.message : String(e)),
      );
  }, []);
 
  return (
    <div className="min-h-screen bg-(--bg)">
      <div className="max-w-5xl mx-auto px-6 py-10">
        <div className="mb-6">
          <h1 className="page-header flex items-center gap-2">
            <Scale size={28} />
            {t("National implementation of the EHDS")}
          </h1>
          <p className="text-(--text-secondary) text-lg mt-1">
            {t(
              "One Regulation, (EU) 2025/327, and six ways of putting it to work: who grants access, under which national law, how a person objects, what access costs and when it applies.",
            )}
          </p>
        </div>
 
        <div className="rounded-lg border border-(--border) bg-(--surface-2) p-4 text-sm text-(--text-secondary) mb-6 space-y-1">
          <p>
            {t(
              "The laws and the legal roles are real and linked to their official sources. The organisations on this hub are fictional; the real institution that holds each role is not named. This is an overview for demonstration, not legal advice.",
            )}
          </p>
          {data?.reviewedOn && (
            <p>
              {t(
                "Checked against the sources on {date}. National implementation is moving; a bill can change before it passes.",
                { date: data.reviewedOn },
              )}
            </p>
          )}
          <p>
            {t(
              "The dataset descriptions in the catalogue are available in German and Spanish, and some in French and Dutch.",
            )}{" "}
            <Link href="/catalog" className="text-(--accent) underline">
              {t("Open the catalogue")}
            </Link>
          </p>
        </div>
 
        {error && (
          <div className="rounded-lg border border-(--border) bg-(--surface) p-4 text-sm flex items-start gap-2 mb-6">
            <AlertCircle size={16} className="mt-0.5" />
            <span>
              {t("The national profiles are unavailable: {error}", { error })}
            </span>
          </div>
        )}
 
        {!data && !error && (
          <div className="flex items-center gap-2 text-(--text-secondary)">
            <Loader2 size={16} className="animate-spin" />
            {tc("Loading…")}
          </div>
        )}
 
        {data && (
          <>
            <nav
              aria-label={t("Countries")}
              className="flex flex-wrap gap-2 mb-6"
            >
              {data.jurisdictions.map((j) => (
                <a
                  key={j.code}
                  href={`#${j.code.toLowerCase()}`}
                  className="px-3 py-1 rounded-full text-xs font-bold border border-(--border-ui) bg-(--surface-card) text-(--text-primary) hover:border-(--accent)"
                >
                  {j.code} · {j.name}
                </a>
              ))}
            </nav>
            <div className="grid grid-cols-1 gap-6">
              {data.jurisdictions.map((j) => (
                <Profile key={j.code} j={j} />
              ))}
            </div>
          </>
        )}
      </div>
    </div>
  );
}