import 'package:ambito/src/packages/ambito_notifier/notifier/theme_manager.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:screen_breakpoints/screen_breakpoints.dart';

import '../../config/config.dart';
import '../../consts/consts.dart';

final orangeColors = {
  'primary': const Color(0xffeebb4b),
  'secondary': const Color(0xfff8e0aa),
  'tertiary': const Color(0xfff3b25c),
  'quarternary': const Color(0xffec863a),
};

final redColors = {
  'primary': const Color(0xff96172f),
  'secondary': const Color(0xffca414c),
  'tertiary': const Color(0xffa83745),
  'quarternary': const Color(0xff883443),
};

final greenColors = {
  'primary': const Color(0xff88a44e),
  'secondary': const Color(0xffd5d808),
  'tertiary': const Color(0xffacc11e),
  'quarternary': const Color(0xff3d693f),
};

final actionGroupColors = {
  'Bauelemente': const Color(0xffFFD269),
  'Begrünung': const Color(0xff40DD74),
  'Bewirtschaftung': const Color(0xffBF72ED),
  'Nisthilfe': const Color(0xffDAE3FD),
  'Pflanzung': const Color(0xff40D6E9),
  'Sondermaßnahmen': const Color(0xff689EF1),
};

final actionAreaColors = {
  'Landschaft': const Color(0xffeebb4b)..withValues(alpha: .1),
  'Weinberg': const Color(0xff88a44e)..withValues(alpha: .1),
  'Betriebsfläche': const Color(0xff96172f)..withValues(alpha: .1),
  'Betriebsstätte': const Color(0xffCCCDCC)..withValues(alpha: .1),
};

final actionAreaFGColors = {
  'Landschaft': const Color(0xffeebb4b),
  'Weinberg': const Color(0xff88a44e),
  'Betriebsfläche': const Color(0xff96172f),
  'Betriebsstätte': const Color(0xff666666),
};

AmbitoTheme getTheme(BuildContext context) {
  var breakpoint = context.breakpoint;
  if (breakpoint >= myBreakpoints.lg) {
    ThemeManager().setTheme(largeTheme);
    return largeTheme;
  }
  if (breakpoint > myBreakpoints.sm) {
    ThemeManager().setTheme(mediumTheme);
    return mediumTheme;
  }
  ThemeManager().setTheme(smallTheme);
  return smallTheme;
}

abstract class AmbitoTheme {
  static ThemeMode appThemeMode = ThemeMode.light;

  ColorScheme get lightColorScheme => const ColorScheme(
        brightness: Brightness.light,
        primary: Color(0xFF60845E),
        onPrimary: Color(0xFFFFFFFF),
        primaryContainer: Color(0xFFDCE3C9),
        onPrimaryContainer: Color(0xFF001E2D),
        secondary: Color(0xff87A34E),
        onSecondary: Color(0xFFFFFFFF),
        secondaryContainer: Color(0xFFD2E5F4),
        onSecondaryContainer: Color(0xFF0A1D28),
        tertiary: Color(0xFFf5f5f5),
        onTertiary: Color(0xFFFFFFFF),
        tertiaryContainer: Color(0xFFB8F483),
        onTertiaryContainer: Color(0xFF0D2000),
        error: Color(0xFFBA1A1A),
        errorContainer: Color(0xFFFFDAD6),
        onError: Color(0xFFFFFFFF),
        onErrorContainer: Color(0xFF410002),
        surface: Color(0xFFffffff),
        onSurface: Color(0xFF666666),
        surfaceContainerHighest: Color(0xFFDDE3EA),
        onSurfaceVariant: Color(0xFF41484D),
        outline: Color(0xFF71787E),
        onInverseSurface: Color(0xFFF0F1F3),
        inverseSurface: Color(0xFF2E3133),
        inversePrimary: Color(0xFF82CFFF),
        shadow: Color(0xFF000000),
        surfaceTint: Color(0xFF00658D),
        outlineVariant: Color(0xFFC1C7CE),
        scrim: Color(0xFF000000),
      );

  ColorScheme get darkColorScheme => const ColorScheme(
        brightness: Brightness.dark,
        primary: Color(0xFF82CFFF),
        onPrimary: Color(0xFF00344B),
        primaryContainer: Color(0xFF004C6B),
        onPrimaryContainer: Color(0xFFC6E7FF),
        secondary: Color(0xFFB6C9D8),
        onSecondary: Color(0xFF21323E),
        secondaryContainer: Color(0xFF374955),
        onSecondaryContainer: Color(0xFFD2E5F4),
        tertiary: Color(0xFF9DD76A),
        onTertiary: Color(0xFF1A3700),
        tertiaryContainer: Color(0xFF285000),
        onTertiaryContainer: Color(0xFFB8F483),
        error: Color(0xFFFFB4AB),
        errorContainer: Color(0xFF93000A),
        onError: Color(0xFF690005),
        onErrorContainer: Color(0xFFFFDAD6),
        surface: Color(0xFF191C1E),
        onSurface: Color(0xFFE2E2E5),
        surfaceContainerHighest: Color(0xFF41484D),
        onSurfaceVariant: Color(0xFFC1C7CE),
        outline: Color(0xFF8B9198),
        onInverseSurface: Color(0xFF191C1E),
        inverseSurface: Color(0xFFE2E2E5),
        inversePrimary: Color(0xFF00658D),
        shadow: Color(0xFF000000),
        surfaceTint: Color(0xFF82CFFF),
        outlineVariant: Color(0xFF41484D),
        scrim: Color(0xFF000000),
      );

  TextStyle get defaultFont => GoogleFonts.roboto();
  TextStyle get displayLarge => textTheme.displayLarge!;
  TextStyle get displayMedium => textTheme.displayMedium!;
  TextStyle get displaySmall => textTheme.displaySmall!;
  TextStyle get headlineLarge => textTheme.headlineLarge!;
  TextStyle get headlineMedium => textTheme.headlineMedium!;
  TextStyle get headlineSmall => textTheme.headlineSmall!;
  TextStyle get titleLarge => textTheme.titleLarge!;
  TextStyle get titleMedium => textTheme.titleMedium!;
  TextStyle get titleSmall => textTheme.titleSmall!;
  TextStyle get labelLarge => textTheme.labelLarge!;
  TextStyle get labelMedium => textTheme.labelMedium!;
  TextStyle get labelSmall => textTheme.labelSmall!;
  TextStyle get bodyLarge => textTheme.bodyLarge!;
  TextStyle get bodyMedium => textTheme.bodyMedium!;
  TextStyle get bodySmall => textTheme.bodySmall!;

  TextTheme get textTheme => TextTheme(
        displayLarge: GoogleFonts.openSans(
            fontSize: 57,
            height: 1.12,
            fontWeight: FontWeight.w400,
            letterSpacing: -.25),
        displayMedium: GoogleFonts.openSans(
          fontSize: 45,
          height: 1.15,
          fontWeight: FontWeight.w400,
          letterSpacing: 0,
        ),
        displaySmall: GoogleFonts.openSans(
          fontSize: 36,
          height: 1.22,
          fontWeight: FontWeight.w400,
          letterSpacing: 0,
        ),
        headlineLarge: GoogleFonts.openSans(
          fontSize: 44,
          height: 1.25,
          fontWeight: FontWeight.w400,
          letterSpacing: 0,
        ),
        headlineMedium: GoogleFonts.openSans(
          fontSize: 28,
          height: 1.29,
          fontWeight: FontWeight.w400,
          letterSpacing: 0,
        ),
        headlineSmall: GoogleFonts.openSans(
          fontSize: 24,
          height: 1.33,
          fontWeight: FontWeight.w400,
          letterSpacing: 0,
        ),
        titleLarge: GoogleFonts.openSans(
          fontSize: 22,
          height: 1.27,
          fontWeight: FontWeight.w400,
          letterSpacing: 0,
        ),
        titleMedium: GoogleFonts.openSans(
          fontSize: 16,
          height: 1.5,
          fontWeight: FontWeight.w500,
          letterSpacing: 0.15,
        ),
        titleSmall: GoogleFonts.openSans(
          fontSize: 14,
          height: 1.42,
          fontWeight: FontWeight.w500,
          letterSpacing: 0.1,
        ),
        labelLarge: GoogleFonts.openSans(
          fontSize: 14,
          height: 1.42,
          fontWeight: FontWeight.w500,
          letterSpacing: 0.1,
        ),
        labelMedium: GoogleFonts.openSans(
          fontSize: 12,
          height: 1.33,
          fontWeight: FontWeight.w500,
          letterSpacing: 0.15,
        ),
        labelSmall: GoogleFonts.openSans(
          fontSize: 11,
          height: 1.45,
          fontWeight: FontWeight.w500,
          letterSpacing: 0.1,
        ),
        bodyLarge: GoogleFonts.openSans(
          fontSize: 16,
          height: 1.5,
          fontWeight: FontWeight.w400,
          letterSpacing: 0.5,
        ),
        bodyMedium: GoogleFonts.openSans(
          fontSize: 14,
          height: 1.42,
          fontWeight: FontWeight.w400,
          letterSpacing: 0.25,
        ),
        bodySmall: GoogleFonts.openSans(
          fontSize: 12,
          height: 1.33,
          fontWeight: FontWeight.w400,
          letterSpacing: 0.4,
        ),
      );

  EdgeInsets get padding => const EdgeInsets.all(20);
  EdgeInsets get paddingSmall => const EdgeInsets.all(10);
  Widget get horizontalSpacer => const SizedBox(
        width: 20,
      );
  Widget get horizontalSpacerMax => const SizedBox(
        width: 40,
      );
  Widget get horizontalSpacerSmall => const SizedBox(
        width: 10,
      );
  Widget get verticalSpacer => const SizedBox(
        height: 20,
      );
  Widget get verticalSpacerSmall => const SizedBox(
        height: 10,
      );
  Widget get verticalSpacerMax => const SizedBox(
        height: 40,
      );

  ThemeData get darkThemeData => ThemeData(
      useMaterial3: true, colorScheme: darkColorScheme, textTheme: textTheme);

  ThemeData get lightThemeData => ThemeData(
      useMaterial3: true, colorScheme: lightColorScheme, textTheme: textTheme);
  ThemeData get currentThemeData =>
      (AmbitoTheme.appThemeMode == ThemeMode.light)
          ? lightThemeData
          : darkThemeData;

  ThemeMode get mode => AmbitoTheme.appThemeMode;

  ColorScheme get currentColorScheme =>
      (AmbitoTheme.appThemeMode == ThemeMode.light)
          ? lightColorScheme
          : darkColorScheme;
}
