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

class TemaApp {
  static const colorFondo = Color(0xFF05080D);
  static const colorFondoAzul = Color(0xFF0A1520);
  static const colorSuperficie = Color(0xFF0D151C);
  static const colorTarjeta = Color(0xFF121B23);
  static const colorBorde = Color(0xFF263947);
  static const colorAcento = Color(0xFFC02824);
  static const colorAcentoClaro = Color(0xFFF06A1A);
  static const colorNaranja = Color(0xFFF49A13);
  static const colorDorado = Color(0xFFFFCE55);
  static const colorPurpura = Color(0xFF65306E);
  static const colorAzul = Color(0xFF235BCE);
  static const colorVerde = Color(0xFF61B944);
  static const colorTexto = Color(0xFFFFFFFF);
  static const colorTextoSecundario = Color(0xFFC2B9AA);

  static const gradientePrimario = LinearGradient(
    colors: [Color(0xFFFFB11A), Color(0xFFE87A08)],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
  );

  static const gradientePeligro = LinearGradient(
    colors: [Color(0xFFC02824), Color(0xFF741112)],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
  );

  static const gradienteFondo = LinearGradient(
    colors: [Color(0xFF09131E), Color(0xFF030507)],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
  );

  static ThemeData obtenerTema() {
    final base = ThemeData.dark(useMaterial3: true);
    final cuerpo = GoogleFonts.robotoCondensedTextTheme(base.textTheme);

    return ThemeData(
      useMaterial3: true,
      brightness: Brightness.dark,
      scaffoldBackgroundColor: colorFondo,
      colorScheme: const ColorScheme.dark(
        primary: colorNaranja,
        secondary: colorNaranja,
        surface: colorSuperficie,
        error: colorAcento,
        onPrimary: Colors.black,
        onSurface: colorTexto,
      ),
      textTheme: cuerpo.copyWith(
          headlineLarge: TextStyle(
            fontFamily: GoogleFonts.oswald().fontFamily,
            color: colorTexto,
            fontWeight: FontWeight.bold,
            fontSize: 30,
            letterSpacing: 0,
          ),
          headlineMedium: TextStyle(
            fontFamily: GoogleFonts.oswald().fontFamily,
            color: colorTexto,
            fontWeight: FontWeight.bold,
            fontSize: 22,
            letterSpacing: 0,
          ),
          titleLarge: TextStyle(
            fontFamily: GoogleFonts.oswald().fontFamily,
            color: colorDorado,
            fontWeight: FontWeight.w700,
            fontSize: 18,
            letterSpacing: 0,
          ),
          titleMedium: TextStyle(
            fontFamily: GoogleFonts.oswald().fontFamily,
            color: colorTexto,
            fontWeight: FontWeight.w600,
            fontSize: 16,
            letterSpacing: 0,
          ),
          bodyLarge: const TextStyle(color: colorTexto, fontSize: 16),
          bodyMedium: const TextStyle(color: colorTextoSecundario, fontSize: 14),
          bodySmall: const TextStyle(color: colorTextoSecundario, fontSize: 12),
      ),
      cardTheme: CardThemeData(
        color: colorTarjeta.withValues(alpha: 0.82),
        elevation: 0,
        margin: EdgeInsets.zero,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(18),
          side: BorderSide(color: colorDorado.withValues(alpha: 0.34)),
        ),
      ),
      elevatedButtonTheme: ElevatedButtonThemeData(
        style: ElevatedButton.styleFrom(
          backgroundColor: colorNaranja,
          foregroundColor: Colors.black,
          disabledBackgroundColor: colorTarjeta,
          disabledForegroundColor: colorTextoSecundario,
          elevation: 0,
          padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)),
          textStyle: GoogleFonts.oswald(
            fontWeight: FontWeight.w700,
            fontSize: 17,
            letterSpacing: 0.6,
          ),
        ),
      ),
      outlinedButtonTheme: OutlinedButtonThemeData(
        style: OutlinedButton.styleFrom(
          foregroundColor: colorTexto,
          side: const BorderSide(color: colorBorde),
          padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
          shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)),
          textStyle: GoogleFonts.oswald(
            fontWeight: FontWeight.w700,
            fontSize: 16,
            letterSpacing: 0,
          ),
        ),
      ),
      inputDecorationTheme: InputDecorationTheme(
        filled: true,
        fillColor: const Color(0xFF0B1117),
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(16),
          borderSide: const BorderSide(color: colorBorde),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(16),
          borderSide: const BorderSide(color: colorBorde),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(16),
          borderSide: const BorderSide(color: colorNaranja),
        ),
        labelStyle: const TextStyle(color: colorTextoSecundario),
        hintStyle: const TextStyle(color: colorTextoSecundario),
      ),
      appBarTheme: AppBarTheme(
        backgroundColor: Colors.transparent,
        foregroundColor: colorNaranja,
        centerTitle: true,
        elevation: 0,
        titleTextStyle: GoogleFonts.oswald(
          color: colorDorado,
          fontWeight: FontWeight.bold,
          fontSize: 20,
          letterSpacing: 0,
        ),
      ),
      dividerTheme: const DividerThemeData(color: colorBorde, thickness: 1),
      listTileTheme: const ListTileThemeData(
        iconColor: colorNaranja,
        textColor: colorTexto,
        subtitleTextStyle: TextStyle(color: colorTextoSecundario),
      ),
      segmentedButtonTheme: SegmentedButtonThemeData(
        style: ButtonStyle(
          backgroundColor: WidgetStateProperty.resolveWith((states) {
            if (states.contains(WidgetState.selected)) return colorNaranja;
            return colorSuperficie;
          }),
          foregroundColor: WidgetStateProperty.resolveWith((states) {
            if (states.contains(WidgetState.selected)) return Colors.black;
            return colorTexto;
          }),
          side: const WidgetStatePropertyAll(BorderSide(color: colorBorde)),
          shape: WidgetStatePropertyAll(
            RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
          ),
        ),
      ),
      switchTheme: SwitchThemeData(
        thumbColor: WidgetStateProperty.resolveWith((states) {
          if (states.contains(WidgetState.selected)) return colorNaranja;
          return colorTextoSecundario;
        }),
        trackColor: WidgetStateProperty.resolveWith((states) {
          if (states.contains(WidgetState.selected)) {
            return colorNaranja.withValues(alpha: 0.5);
          }
          return colorTarjeta;
        }),
      ),
      snackBarTheme: SnackBarThemeData(
        backgroundColor: colorTarjeta,
        contentTextStyle: cuerpo.bodyMedium?.copyWith(color: colorTexto),
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
      ),
    );
  }

  static BoxDecoration decoracionPanel({
    Color? color,
    Color? borderColor,
  }) {
    return BoxDecoration(
      color: color ?? colorTarjeta.withValues(alpha: 0.84),
      borderRadius: BorderRadius.circular(18),
      border: Border.all(
        color: borderColor ?? colorDorado.withValues(alpha: 0.30),
      ),
      boxShadow: [
        BoxShadow(
          color: Colors.black.withValues(alpha: 0.35),
          blurRadius: 22,
          offset: const Offset(0, 12),
        ),
        BoxShadow(
          color: colorNaranja.withValues(alpha: 0.10),
          blurRadius: 24,
        ),
      ],
    );
  }
}
