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

/// Brand Match Live TV — dark theme, rosso #FF2D2D, Barlow Condensed.
class AppTheme {
  AppTheme._();

  static const Color primaryRed = Color(0xFFFF2D2D);
  static const Color background = Color(0xFF0A0A0A);
  static const Color surface = Color(0xFF1E1E1E);
  static const Color surfaceElevated = Color(0xFF2A2A2A);
  static const Color accentYellow = Color(0xFFF5C518);
  static const Color successGreen = Color(0xFF22C55E);
  static const Color textSecondary = Color(0xFF9CA3AF);

  static TextTheme get _textTheme {
    final base = GoogleFonts.barlowCondensedTextTheme(
      ThemeData.dark().textTheme,
    );
    return base.copyWith(
      displayLarge: base.displayLarge?.copyWith(
        fontWeight: FontWeight.w900,
        letterSpacing: -0.5,
      ),
      displayMedium: base.displayMedium?.copyWith(fontWeight: FontWeight.w900),
      displaySmall: base.displaySmall?.copyWith(fontWeight: FontWeight.w900),
      headlineLarge: base.headlineLarge?.copyWith(fontWeight: FontWeight.w900),
      headlineMedium: base.headlineMedium?.copyWith(fontWeight: FontWeight.w800),
      headlineSmall: base.headlineSmall?.copyWith(fontWeight: FontWeight.w800),
      titleLarge: base.titleLarge?.copyWith(fontWeight: FontWeight.w700),
      titleMedium: base.titleMedium?.copyWith(fontWeight: FontWeight.w700),
      labelLarge: base.labelLarge?.copyWith(
        fontWeight: FontWeight.w800,
        letterSpacing: 1.2,
      ),
      bodyLarge: base.bodyLarge?.copyWith(fontWeight: FontWeight.w500),
      bodyMedium: base.bodyMedium?.copyWith(
        fontWeight: FontWeight.w500,
        color: textSecondary,
      ),
    );
  }

  static ThemeData get dark {
    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.dark,
      scaffoldBackgroundColor: background,
      colorScheme: const ColorScheme.dark(
        primary: primaryRed,
        secondary: accentYellow,
        surface: surface,
        error: primaryRed,
        onPrimary: Colors.white,
        onSecondary: Colors.black,
        onSurface: Colors.white,
      ),
      textTheme: _textTheme,
      appBarTheme: AppBarTheme(
        backgroundColor: background,
        elevation: 0,
        centerTitle: true,
        titleTextStyle: _textTheme.titleLarge?.copyWith(color: Colors.white),
        iconTheme: const IconThemeData(color: Colors.white),
      ),
      cardTheme: CardThemeData(
        color: surface,
        elevation: 0,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      ),
      inputDecorationTheme: InputDecorationTheme(
        filled: true,
        fillColor: surfaceElevated,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10),
          borderSide: BorderSide.none,
        ),
        labelStyle: _textTheme.bodyMedium,
        hintStyle: _textTheme.bodyMedium,
      ),
      segmentedButtonTheme: SegmentedButtonThemeData(
        style: ButtonStyle(
          backgroundColor: WidgetStateProperty.resolveWith((states) {
            if (states.contains(WidgetState.selected)) return primaryRed;
            return surfaceElevated;
          }),
          foregroundColor: WidgetStateProperty.all(Colors.white),
        ),
      ),
      dividerColor: surfaceElevated,
    );
  }
}
