/**
 * Resolve a board's generated GLBs to ABSOLUTE URLs.
 *
 * Two constraints force this shape:
 *
 * 1. tscircuit's GLB loader FETCHES `glbUrl` — it does not read it off disk —
 *    so a relative path like "models/x.glb" 404s at build time and the part
 *    silently falls back to a plain box.
 * 2. The base cannot be built from `process.cwd()`, because each board is
 *    served from its own directory (`adom-tsci start boards/<slug>`) as well as
 *    built from the repo root. cwd differs between those two, so a cwd-relative
 *    URL works in one and 404s in the other.
 *
 * The board passes its own `import.meta.url`-derived base, which is correct
 * from anywhere. ADOM_NAMEPLATE_MODEL_BASE overrides it for hosted copies.
 */
export const modelResolver = (base: string) => (file: string) => {
  const override =
    typeof process !== "undefined" ? process.env?.ADOM_NAMEPLATE_MODEL_BASE : undefined
  const root = (override ?? base).replace(/\/$/, "")
  return `${root}/${file}`
}
