/**
 * Design tokens — programmatic access to the canonical token JSON.
 * For generated platform files, see the `generated/` directory.
 * For the canonical JSON source, see `tokens/bytelyst.tokens.json`.
 */

import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

export interface DesignTokens {
  meta: { name: string; version: string; updatedAt: string; scale: string };
  color: {
    palette: Record<string, Record<string, string>>;
    semantic: {
      dark: Record<string, string>;
      light: Record<string, string>;
    };
    brain: Record<string, { from: string; to: string }>;
  };
  typography: {
    fontFamily: Record<string, string>;
    fontWeight: Record<string, number>;
    fontSize: Record<string, number>;
    lineHeight: Record<string, number>;
    letterSpacing: Record<string, number>;
  };
  spacing: Record<string, number>;
  radius: Record<string, number>;
  elevation: Record<string, string>;
  motion: {
    duration: Record<string, number>;
    easing: Record<string, string>;
  };
  breakpoints: Record<string, number>;
  layout: Record<string, number>;
}

let _cached: DesignTokens | null = null;

export function loadTokens(): DesignTokens {
  if (_cached) return _cached;
  const tokenPath = resolve(__dirname, '../tokens/bytelyst.tokens.json');
  const raw = readFileSync(tokenPath, 'utf-8');
  _cached = JSON.parse(raw) as DesignTokens;
  return _cached;
}
