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

/// "The Kinetic Vault" & "The Ethereal Terminal" 主题配置
class AppTheme {
  AppTheme._();

  // ============================================
  // 深色主题 - "The Kinetic Vault"
  // ============================================

  static ThemeData get darkTheme {
    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.dark,
      scaffoldBackgroundColor: AppColorScheme.darkBackground,
      primaryColor: AppColorScheme.darkPrimary,
      colorScheme: AppColorScheme.darkMaterial,

      // AppBar - 无边框规则
      appBarTheme: AppBarTheme(
        backgroundColor: AppColorScheme.darkBackground,
        foregroundColor: AppColorScheme.darkOnSurface,
        elevation: 0,
        scrolledUnderElevation: 0,
        centerTitle: true,
        titleTextStyle: GoogleFonts.spaceGrotesk(
          fontSize: 18,
          fontWeight: FontWeight.w600,
          color: AppColorScheme.darkOnSurface,
        ),
      ),

      // 卡片 - 无边框，使用 surface 层次
      cardTheme: CardThemeData(
        color: AppColorScheme.darkSurface,
        elevation: 0,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(AppRadius.xl),
        ),
      ),

      // 输入框 - Ghost Border 风格
      inputDecorationTheme: InputDecorationTheme(
        filled: true,
        fillColor: AppColorScheme.darkSurfaceLow,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(AppRadius.md),
          borderSide: BorderSide(
            color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15),
          ),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(AppRadius.md),
          borderSide: BorderSide(
            color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15),
          ),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(AppRadius.md),
          borderSide: const BorderSide(color: AppColorScheme.darkPrimary, width: 2),
        ),
        hintStyle: TextStyle(color: AppColorScheme.darkOnSurfaceMuted),
        contentPadding: const EdgeInsets.symmetric(
          horizontal: AppSpacing.md,
          vertical: 14,
        ),
      ),

      // 按钮 - 渐变 CTA，大圆角
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: AppColorScheme.darkPrimary,
          foregroundColor: AppColorScheme.darkBackground,
          minimumSize: const Size(double.infinity, 48),
          padding: const EdgeInsets.symmetric(vertical: 14),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(AppRadius.xxl),
          ),
          elevation: 0,
          textStyle: GoogleFonts.manrope(
            fontSize: 16,
            fontWeight: FontWeight.w600,
          ),
        ),
      ),

      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
          foregroundColor: AppColorScheme.darkPrimary,
        ),
      ),

      // 分割线 - 使用层次而非边框
      dividerTheme: DividerThemeData(
        color: AppColorScheme.darkOutlineVariant.withValues(alpha: 0.1),
        thickness: 1,
      ),

      // 底部导航
      bottomNavigationBarTheme: BottomNavigationBarThemeData(
        backgroundColor: AppColorScheme.darkSurface,
        selectedItemColor: AppColorScheme.darkPrimary,
        unselectedItemColor: AppColorScheme.darkOnSurfaceVariant,
        type: BottomNavigationBarType.fixed,
        elevation: 0,
      ),
    );
  }

  // ============================================
  // 浅色主题 - "The Ethereal Terminal"
  // ============================================

  static ThemeData get lightTheme {
    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.light,
      scaffoldBackgroundColor: AppColorScheme.lightBackground,
      primaryColor: AppColorScheme.lightPrimary,
      colorScheme: AppColorScheme.lightMaterial,

      // AppBar - 珍珠白
      appBarTheme: AppBarTheme(
        backgroundColor: AppColorScheme.lightBackground,
        foregroundColor: AppColorScheme.lightOnSurface,
        elevation: 0,
        scrolledUnderElevation: 0,
        centerTitle: true,
        titleTextStyle: GoogleFonts.spaceGrotesk(
          fontSize: 18,
          fontWeight: FontWeight.w600,
          color: AppColorScheme.lightOnSurface,
        ),
      ),

      // 卡片 - Elevated (pop) on pearl background
      cardTheme: CardThemeData(
        color: AppColorScheme.lightSurfaceLowest,
        elevation: 0,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(AppRadius.xl),
        ),
      ),

      // 输入框 - 底部线条风格
      inputDecorationTheme: InputDecorationTheme(
        filled: true,
        fillColor: AppColorScheme.lightSurfaceLow,
        border: UnderlineInputBorder(
          borderRadius: BorderRadius.circular(AppRadius.md),
          borderSide: BorderSide(
            color: AppColorScheme.lightOutlineVariant.withValues(alpha: 0.5),
            width: 2,
          ),
        ),
        enabledBorder: UnderlineInputBorder(
          borderRadius: BorderRadius.circular(AppRadius.md),
          borderSide: BorderSide(
            color: AppColorScheme.lightOutlineVariant.withValues(alpha: 0.5),
            width: 2,
          ),
        ),
        focusedBorder: UnderlineInputBorder(
          borderRadius: BorderRadius.circular(AppRadius.md),
          borderSide: const BorderSide(color: AppColorScheme.lightPrimary, width: 2),
        ),
        hintStyle: TextStyle(color: AppColorScheme.lightOnSurfaceMuted),
        contentPadding: const EdgeInsets.symmetric(
          horizontal: AppSpacing.md,
          vertical: 14,
        ),
      ),

      // 按钮 - Plasma 渐变，full 圆角
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: AppColorScheme.lightPrimary,
          foregroundColor: const Color(0xFFFFFFFF),
          minimumSize: const Size(double.infinity, 48),
          padding: const EdgeInsets.symmetric(vertical: 14),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(AppRadius.xxl),
          ),
          elevation: 0,
          textStyle: GoogleFonts.manrope(
            fontSize: 16,
            fontWeight: FontWeight.w600,
          ),
        ),
      ),

      textButtonTheme: TextButtonThemeData(
        style: TextButton.styleFrom(
          foregroundColor: AppColorScheme.lightPrimary,
        ),
      ),

      // 分割线 - 不使用，用留白代替
      dividerTheme: DividerThemeData(
        color: AppColorScheme.lightOutlineVariant.withValues(alpha: 0.2),
        thickness: 1,
      ),

      // 底部导航
      bottomNavigationBarTheme: BottomNavigationBarThemeData(
        backgroundColor: AppColorScheme.lightSurfaceHighest,
        selectedItemColor: AppColorScheme.lightPrimary,
        unselectedItemColor: AppColorScheme.lightOnSurfaceVariant,
        type: BottomNavigationBarType.fixed,
        elevation: 0,
      ),
    );
  }
}

/// "The Kinetic Vault" & "The Ethereal Terminal" 文字样式系统
///
/// Display/Headlines: Space Grotesk (编辑风格)
/// Body/Labels: Manrope (实用风格)
class AppTextStyles {
  AppTextStyles._();

  // ============================================
  // Display - 编辑风格 (Space Grotesk)
  // ============================================

  /// D1 - 大标题 (48px) - Hero moments
  static TextStyle displayLarge(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 48,
    fontWeight: FontWeight.w700,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.1,
    letterSpacing: -0.02,
  );

  /// D2 - 中标题 (36px)
  static TextStyle displayMedium(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 36,
    fontWeight: FontWeight.w600,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.2,
    letterSpacing: -0.01,
  );

  /// D3 - 小标题 (28px)
  static TextStyle displaySmall(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 28,
    fontWeight: FontWeight.w600,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.25,
  );

  // ============================================
  // Headline - 编辑风格 (Space Grotesk)
  // ============================================

  static TextStyle headlineLarge(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 24,
    fontWeight: FontWeight.w600,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.3,
  );

  static TextStyle headlineMedium(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 20,
    fontWeight: FontWeight.w600,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.35,
  );

  static TextStyle headlineSmall(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 18,
    fontWeight: FontWeight.w500,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.4,
  );

  // ============================================
  // Body - 实用风格 (Manrope)
  // ============================================

  static TextStyle bodyLarge(BuildContext context) => GoogleFonts.manrope(
    fontSize: 16,
    fontWeight: FontWeight.w400,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.5,
  );

  static TextStyle bodyMedium(BuildContext context) => GoogleFonts.manrope(
    fontSize: 14,
    fontWeight: FontWeight.w400,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.5,
  );

  static TextStyle bodySmall(BuildContext context) => GoogleFonts.manrope(
    fontSize: 12,
    fontWeight: FontWeight.w400,
    color: Theme.of(context).colorScheme.onSurfaceVariant,
    height: 1.45,
  );

  // ============================================
  // Label - 实用风格 (Manrope)
  // ============================================

  static TextStyle labelLarge(BuildContext context) => GoogleFonts.manrope(
    fontSize: 14,
    fontWeight: FontWeight.w500,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.4,
  );

  static TextStyle labelMedium(BuildContext context) => GoogleFonts.manrope(
    fontSize: 12,
    fontWeight: FontWeight.w500,
    color: Theme.of(context).colorScheme.onSurfaceVariant,
    height: 1.4,
  );

  static TextStyle labelSmall(BuildContext context) => GoogleFonts.manrope(
    fontSize: 11,
    fontWeight: FontWeight.w500,
    color: Theme.of(context).colorScheme.onSurfaceVariant,
    height: 1.4,
  );

  // ============================================
  // 数字/金额 - Space Grotesk (等宽特性)
  // ============================================

  static TextStyle numberLarge(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 24,
    fontWeight: FontWeight.w600,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.2,
    fontFeatures: const [FontFeature.tabularFigures()],
  );

  static TextStyle numberMedium(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 18,
    fontWeight: FontWeight.w500,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.25,
    fontFeatures: const [FontFeature.tabularFigures()],
  );

  static TextStyle numberSmall(BuildContext context) => GoogleFonts.spaceGrotesk(
    fontSize: 14,
    fontWeight: FontWeight.w500,
    color: Theme.of(context).colorScheme.onSurface,
    height: 1.3,
    fontFeatures: const [FontFeature.tabularFigures()],
  );

  // ============================================
  // 兼容旧代码的静态样式 (已废弃)
  // ============================================

  @Deprecated('Use displaySmall instead')
  static const TextStyle heading1 = TextStyle(
    fontSize: 28,
    fontWeight: FontWeight.bold,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use headlineLarge instead')
  static const TextStyle heading2 = TextStyle(
    fontSize: 24,
    fontWeight: FontWeight.bold,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use headlineMedium instead')
  static const TextStyle heading3 = TextStyle(
    fontSize: 18,
    fontWeight: FontWeight.w600,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use headlineSmall instead')
  static const TextStyle heading4 = TextStyle(
    fontSize: 16,
    fontWeight: FontWeight.w600,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use bodyLarge instead')
  static const TextStyle body1 = TextStyle(
    fontSize: 16,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use bodyMedium instead')
  static const TextStyle body2 = TextStyle(
    fontSize: 14,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use labelSmall instead')
  static const TextStyle caption = TextStyle(
    fontSize: 12,
    color: Color(0xFFA1A1AA),
  );

  @Deprecated('Use labelSmall instead')
  static const TextStyle hint = TextStyle(
    fontSize: 14,
    color: Color(0xFF71717A),
  );

  @Deprecated('Use numberMedium instead')
  static const TextStyle price = TextStyle(
    fontSize: 20,
    fontWeight: FontWeight.bold,
    color: Color(0xFFFFFFFF),
  );

  @Deprecated('Use numberSmall with color instead')
  static const TextStyle change = TextStyle(
    fontSize: 14,
    fontWeight: FontWeight.w600,
  );

  @Deprecated('Use numberSmall instead')
  static const TextStyle number = TextStyle(
    fontSize: 16,
    fontWeight: FontWeight.w500,
    color: Color(0xFFFFFFFF),
  );
}

/// 动画时长
class AnimationDurations {
  AnimationDurations._();

  static const Duration fast = Duration(milliseconds: 150);
  static const Duration normal = Duration(milliseconds: 250);
  static const Duration slow = Duration(milliseconds: 400);
  static const Duration verySlow = Duration(milliseconds: 600);
}
