import { error } from "@sveltejs/kit";

// v0.2 Phase 5 — route-level gate.
//
// design-system-v2 is a developer-only preview surface for the new
// Lumotia primitives. It MUST NOT be reachable from production
// builds: a hidden-but-routable URL is still a URL. This load
// function throws 404 unless the build was started with
// VITE_LUMOTIA_DESIGN_SYSTEM_V2=1, which means:
//
//   - `npm run dev:frontend` exposes the route only when the env
//     var is set in the developer's shell
//   - the static `npm run build` skips the route entirely because
//     `prerender = false` keeps the static adapter from running
//     `load`, and the SPA fallback returns the SvelteKit error
//     page on direct navigation
//
// To open the preview locally:
//   VITE_LUMOTIA_DESIGN_SYSTEM_V2=1 npm run dev:frontend
export const prerender = false;

export function load() {
  if (import.meta.env.VITE_LUMOTIA_DESIGN_SYSTEM_V2 !== "1") {
    throw error(404, "Not Found");
  }
  return {};
}
