import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

import 'theme_extension.dart';
import 'tokens.dart';

ThemeData buildDarkTheme() {
  final fs = FabledSwordTheme.dark();
  final colorScheme = ColorScheme.dark(
    surface: fs.iron,
    onSurface: fs.parchment,
    primary: fs.accent,
    onPrimary: fs.parchment,
    secondary: fs.moss,
    error: fs.error,
  );
  return ThemeData(
    useMaterial3: true,
    brightness: Brightness.dark,
    colorScheme: colorScheme,
    scaffoldBackgroundColor: fs.obsidian,
    textTheme: GoogleFonts.interTextTheme().apply(
      bodyColor: fs.parchment,
      displayColor: fs.parchment,
    ),
    fontFamily: FabledSwordFlatTokens.fontBody,
    extensions: <ThemeExtension<dynamic>>[fs],
  );
}

ThemeData buildLightTheme() {
  final fs = FabledSwordTheme.light();
  final colorScheme = ColorScheme.light(
    surface: fs.iron,
    onSurface: fs.parchment, // semantic — light's "parchment" is dark text
    primary: fs.accent,
    onPrimary: FabledSwordFlatTokens.onAction,
    secondary: fs.moss,
    error: fs.error,
  );
  return ThemeData(
    useMaterial3: true,
    brightness: Brightness.light,
    colorScheme: colorScheme,
    scaffoldBackgroundColor: fs.obsidian, // semantic — light's obsidian is the bg
    textTheme: GoogleFonts.interTextTheme().apply(
      bodyColor: fs.parchment,
      displayColor: fs.parchment,
    ),
    fontFamily: FabledSwordFlatTokens.fontBody,
    extensions: <ThemeExtension<dynamic>>[fs],
  );
}

/// Back-compat alias. Existing tests + code call buildThemeData(); it
/// returns the dark theme to preserve current behaviour. New code
/// should prefer buildDarkTheme()/buildLightTheme() explicitly.
ThemeData buildThemeData() => buildDarkTheme();
