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

import 'pluriwave_motion.dart';
import 'pluriwave_tokens.dart';

abstract final class PluriWaveTheme {
  static ThemeData dark() {
    const tokens = PluriWaveTokens.dark;
    final colorScheme = const ColorScheme.dark().copyWith(
      primary: tokens.electricMagenta,
      secondary: const Color(0xFF7EE4C2),
      tertiary: tokens.warmCoral,
      surface: const Color(0xFF0D1B24),
      surfaceContainerLow: const Color(0xFF102532),
      surfaceContainerHighest: const Color(0xFF1B3942),
      onSurface: const Color(0xFFF2F7FA),
      onPrimary: Colors.white,
    );

    return ThemeData(
      useMaterial3: true,
      colorScheme: colorScheme,
      scaffoldBackgroundColor: tokens.deepViolet,
      textTheme: GoogleFonts.plusJakartaSansTextTheme(ThemeData.dark().textTheme),
      extensions: const <ThemeExtension<dynamic>>[
        tokens,
        PluriWaveMotion.dark,
      ],
      appBarTheme: const AppBarTheme(
        centerTitle: false,
        backgroundColor: Colors.transparent,
        foregroundColor: Color(0xFFF2F7FA),
        elevation: 0,
        scrolledUnderElevation: 0,
      ),
      navigationBarTheme: NavigationBarThemeData(
        backgroundColor: Colors.transparent,
        indicatorColor: tokens.electricMagenta.withValues(alpha: 0.18),
        labelTextStyle: WidgetStateProperty.resolveWith(
          (states) => TextStyle(
            fontWeight: states.contains(WidgetState.selected) ? FontWeight.w800 : FontWeight.w600,
            fontSize: 12,
          ),
        ),
      ),
      chipTheme: ChipThemeData(
        backgroundColor: const Color(0x1FFFFFFF),
        selectedColor: tokens.electricMagenta.withValues(alpha: 0.24),
        side: BorderSide(color: tokens.glassBorder),
        labelStyle: const TextStyle(fontWeight: FontWeight.w700),
      ),
      cardTheme: CardThemeData(
        elevation: 0,
        color: colorScheme.surfaceContainerLow,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(tokens.radiusMd),
        ),
      ),
    );
  }
}

extension PluriWaveThemeContextX on BuildContext {
  PluriWaveTokens get pluriTokens => Theme.of(this).extension<PluriWaveTokens>() ?? PluriWaveTokens.dark;

  PluriWaveMotion get pluriMotion => Theme.of(this).extension<PluriWaveMotion>() ?? PluriWaveMotion.dark;
}
