import 'package:cargocalculaterapp/core/theme/theme_text_style.dart';
import 'package:flutter/material.dart';
import 'colors/app_colors.dart';

final appTheme = ThemeData(
  fontFamily: "Inter",
  extensions: <ThemeExtension<dynamic>>[
    AppThemeColors.light,
    AppThemeColors.dark,
    ThemeTextStyles.light,
    ThemeTextStyles.dark,
  ],
  useMaterial3: true,
  applyElevationOverlayColor: true,
  // disabledColor: ThemeColors.disabledColor,
  // splashColor: ThemeColors.primary1Transparent,
  // focusColor: ThemeColors.primaryColor,
  // colorSchemeSeed: ThemeColors.primaryColor,
  visualDensity: VisualDensity.standard,
  materialTapTargetSize: MaterialTapTargetSize.padded,
  pageTransitionsTheme: const PageTransitionsTheme(
    builders: {
      TargetPlatform.android: CupertinoPageTransitionsBuilder(),
      TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
    },
  ),
  // textButtonTheme: TextButtonThemeData(
  //   style: ButtonStyle(
  //     padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
  //       EdgeInsets.zero,
  //     ),
  //   ),
  // ),
  dividerTheme: const DividerThemeData(thickness: 1),
);

final lightTheme = appTheme.copyWith(
  extensions: <ThemeExtension<dynamic>>[
    AppThemeColors.light,
    ThemeTextStyles.light,
  ],
  scaffoldBackgroundColor: LightThemeColors.scaffoldBackgroundColor,
  brightness: Brightness.light,
  dividerTheme: appTheme.dividerTheme.copyWith(
    color: LightThemeColors.dividerColor,
  ),
  colorScheme: const ColorScheme.light(
    secondary: LightThemeColors.white,
    primary: LightThemeColors.accentColor,
  ),
  // listTileTheme: const ListTileThemeData(
  //   minVerticalPadding: 14,
  //   minLeadingWidth: 16,
  //   horizontalTitleGap: 12,
  //   tileColor: LightThemeColors.textFieldBackGround,
  //   selectedColor: LightThemeColors.backgroundColor,
  //   selectedTileColor: LightThemeColors.backgroundColor,
  //   shape: RoundedRectangleBorder(
  //     borderRadius: AppUtils.kBorderRadius4,
  //   ),
  // ),
  tabBarTheme: TabBarThemeData(
    labelColor: LightThemeColors.accentColor,
    unselectedLabelColor: LightThemeColors.grey,
    labelPadding: EdgeInsets.zero,
    labelStyle: const TextStyle(fontSize: 11, fontWeight: FontWeight.w400),
    unselectedLabelStyle: const TextStyle(
      fontSize: 11,
      fontWeight: FontWeight.w400,
    ),
    indicator: const UnderlineTabIndicator(
      borderSide: BorderSide(color: LightThemeColors.accentColor, width: 2.0),
    ),
    overlayColor: WidgetStateProperty.resolveWith<Color>((states) {
      return LightThemeColors.lightGrey;
    }),
  ),
  appBarTheme: const AppBarTheme(
    elevation: 0,
    centerTitle: true,
    scrolledUnderElevation: 0,
    foregroundColor: LightThemeColors.scaffoldBackgroundColor,
    backgroundColor: LightThemeColors.white,
    surfaceTintColor: LightThemeColors.scaffoldBackgroundColor,
    shadowColor: Colors.black,
    titleTextStyle: TextStyle(
      fontSize: 20,
      fontWeight: FontWeight.w700,
      color: LightThemeColors.textColor,
    ),
    toolbarHeight: 56,
    iconTheme: IconThemeData(color: LightThemeColors.primaryColor),
  ),
  inputDecorationTheme: const InputDecorationTheme(
    contentPadding: EdgeInsets.all(16),
    alignLabelWithHint: true,
    labelStyle: TextStyle(
      color: LightThemeColors.white,
      fontSize: 16,
      fontWeight: FontWeight.w400,
    ),
    hintStyle: TextStyle(
      color: LightThemeColors.secondaryText,
      fontSize: 16,
      fontWeight: FontWeight.w500,
    ),
    errorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: LightThemeColors.errorColor),
    ),
    border: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: LightThemeColors.borderColor),
    ),
    enabledBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: LightThemeColors.borderColor),
    ),
    focusedBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: LightThemeColors.primaryColor),
    ),
    disabledBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: LightThemeColors.white10Transparent),
    ),
    focusedErrorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: LightThemeColors.errorColor),
    ),
    filled: true,
    isDense: true,
    fillColor: LightThemeColors.edittextBackground,
    floatingLabelAlignment: FloatingLabelAlignment.start,
    floatingLabelBehavior: FloatingLabelBehavior.always,
  ),
  elevatedButtonTheme: ElevatedButtonThemeData(
    style: ButtonStyle(
      overlayColor: WidgetStateProperty.resolveWith<Color?>((
        Set<WidgetState> states,
      ) {
        if (states.contains(WidgetState.hovered)) {
          return LightThemeColors.errorColor;
        }
        return null;
      }),
      elevation: WidgetStateProperty.all<double>(0),
      textStyle: WidgetStateProperty.all<TextStyle>(
        const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.w700,
          color: LightThemeColors.textColor,
        ),
      ),
      foregroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        if (states.contains(WidgetState.disabled)) {
          return LightThemeColors.white;
        } else {
          return LightThemeColors.white;
        }
      }),
      backgroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        if (states.contains(WidgetState.disabled)) {
          return LightThemeColors.disabledColor;
        } else {
          return LightThemeColors.primaryColor;
        }
      }),
      maximumSize: WidgetStateProperty.all<Size>(
        const Size(double.infinity, 56),
      ),
      minimumSize: WidgetStateProperty.all<Size>(
        const Size(double.infinity, 56),
      ),
      shape: WidgetStateProperty.all<RoundedRectangleBorder>(
        const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(24)),
        ),
      ),
    ),
  ),
  bottomNavigationBarTheme: const BottomNavigationBarThemeData(
    backgroundColor: LightThemeColors.scaffoldBackgroundColor,
    type: BottomNavigationBarType.fixed,
    showSelectedLabels: true,
    selectedLabelStyle: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
    unselectedLabelStyle: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
    unselectedItemColor: LightThemeColors.lightSecondary,
    selectedItemColor: LightThemeColors.primaryColor,
    selectedIconTheme: IconThemeData(size: 25),
    unselectedIconTheme: IconThemeData(size: 25),
    elevation: 2,
  ),
  textButtonTheme: TextButtonThemeData(
    style: ButtonStyle(
      padding: WidgetStateProperty.all(
        const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
      ),
      tapTargetSize: MaterialTapTargetSize.shrinkWrap,
      elevation: WidgetStateProperty.all<double>(2),
      foregroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        return LightThemeColors.scaffoldBackgroundColor;
      }),
      backgroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        if (states.contains(WidgetState.disabled)) {
          return Colors.transparent;
        } else {
          return Colors.transparent;
        }
      }),
      maximumSize: WidgetStateProperty.all<Size>(
        const Size(double.infinity, double.infinity),
      ),
      minimumSize: WidgetStateProperty.all<Size>(
        const Size(double.minPositive, double.minPositive),
      ),
      shape: WidgetStateProperty.all<RoundedRectangleBorder>(
        const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
        ),
      ),
      textStyle: WidgetStateProperty.all<TextStyle>(
        const TextStyle(
          fontSize: 12,
          fontWeight: FontWeight.w600,
          color: LightThemeColors.accentColor,
        ),
      ),
      // overlayColor: WidgetStateProperty.resolveWith<Color>((states) {
      //   return LightThemeColors.lightGrey;
      // }),
    ),
  ),
  bottomSheetTheme: const BottomSheetThemeData(
    backgroundColor: Colors.transparent,
    // surfaceTintColor: Colors.transparent,
    modalBackgroundColor: Colors.transparent,
    modalElevation: 0,
    elevation: 0,
  ),
);

final darkTheme = appTheme.copyWith(
  extensions: <ThemeExtension<dynamic>>[
    AppThemeColors.dark,
    ThemeTextStyles.dark,
  ],
  scaffoldBackgroundColor: DarkThemeColors.scaffoldBackgroundColor,
  brightness: Brightness.dark,
  dividerTheme: appTheme.dividerTheme.copyWith(
    color: DarkThemeColors.dividerColor,
  ),
  colorScheme: const ColorScheme.dark(secondary: Colors.white),
  tabBarTheme: TabBarThemeData(
    labelColor: DarkThemeColors.accentColor,
    unselectedLabelColor: DarkThemeColors.grey,
    labelPadding: EdgeInsets.zero,
    labelStyle: const TextStyle(fontSize: 11, fontWeight: FontWeight.w400),
    unselectedLabelStyle: const TextStyle(
      fontSize: 11,
      fontWeight: FontWeight.w400,
    ),
    indicator: const UnderlineTabIndicator(
      borderSide: BorderSide(color: DarkThemeColors.accentColor, width: 2.0),
    ),
    overlayColor: WidgetStateProperty.resolveWith<Color>((states) {
      return DarkThemeColors.lightGrey;
    }),
  ),
  appBarTheme: const AppBarTheme(
    elevation: 0,
    centerTitle: true,
    scrolledUnderElevation: 0,
    foregroundColor: DarkThemeColors.scaffoldBackgroundColor,
    backgroundColor: DarkThemeColors.scaffoldBackgroundColor,
    surfaceTintColor: DarkThemeColors.scaffoldBackgroundColor,
    shadowColor: Colors.black,
    titleTextStyle: TextStyle(
      fontSize: 20,
      fontWeight: FontWeight.w700,
      color: DarkThemeColors.textColor,
    ),
    toolbarHeight: 56,
    iconTheme: IconThemeData(color: DarkThemeColors.primaryColor),
  ),
  inputDecorationTheme: const InputDecorationTheme(
    alignLabelWithHint: true,
    contentPadding: EdgeInsets.all(16),
    labelStyle: TextStyle(
      color: DarkThemeColors.textColor,
      fontSize: 16,
      fontWeight: FontWeight.w400,
    ),
    hintStyle: TextStyle(
      color: DarkThemeColors.secondaryText,
      fontSize: 16,
      fontWeight: FontWeight.w400,
    ),

    errorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: DarkThemeColors.errorColor),
    ),
    border: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: DarkThemeColors.borderColor),
    ),
    enabledBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: DarkThemeColors.borderColor),
    ),
    focusedBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: DarkThemeColors.primaryColor),
    ),
    disabledBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: DarkThemeColors.white10Transparent),
    ),
    focusedErrorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(16)),
      borderSide: BorderSide(color: DarkThemeColors.errorColor),
    ),
    filled: true,
    isDense: true,
    fillColor: DarkThemeColors.edittextBackground,
    floatingLabelAlignment: FloatingLabelAlignment.start,
    floatingLabelBehavior: FloatingLabelBehavior.always,
  ),
  elevatedButtonTheme: ElevatedButtonThemeData(
    style: ButtonStyle(
      overlayColor: WidgetStateProperty.resolveWith<Color?>((
        Set<WidgetState> states,
      ) {
        if (states.contains(WidgetState.hovered)) {
          return DarkThemeColors.errorColor;
        }
        return null;
      }),
      elevation: WidgetStateProperty.all<double>(0),
      textStyle: WidgetStateProperty.all<TextStyle>(
        const TextStyle(
          fontSize: 16,
          fontWeight: FontWeight.w700,
          color: DarkThemeColors.buttonColorText,
        ),
      ),
      foregroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        if (states.contains(WidgetState.disabled)) {
          return DarkThemeColors.white60Transparent;
        } else {
          return DarkThemeColors.buttonColorText;
        }
      }),
      backgroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        if (states.contains(WidgetState.disabled)) {
          return DarkThemeColors.disabledColor;
        } else {
          return DarkThemeColors.primaryColor;
        }
      }),
      maximumSize: WidgetStateProperty.all<Size>(
        const Size(double.infinity, 56),
      ),
      minimumSize: WidgetStateProperty.all<Size>(
        const Size(double.infinity, 56),
      ),
      shape: WidgetStateProperty.all<RoundedRectangleBorder>(
        const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(24)),
        ),
      ),
    ),
  ),
  bottomNavigationBarTheme: const BottomNavigationBarThemeData(
    backgroundColor: DarkThemeColors.scaffoldBackgroundColor,
    type: BottomNavigationBarType.fixed,
    showSelectedLabels: true,
    selectedLabelStyle: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
    unselectedLabelStyle: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
    unselectedItemColor: DarkThemeColors.lightSecondary,
    selectedItemColor: DarkThemeColors.primaryColor,
    selectedIconTheme: IconThemeData(size: 25),
    unselectedIconTheme: IconThemeData(size: 25),
    elevation: 2,
  ),
  textButtonTheme: TextButtonThemeData(
    style: ButtonStyle(
      padding: WidgetStateProperty.all(
        const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
      ),
      tapTargetSize: MaterialTapTargetSize.shrinkWrap,
      elevation: WidgetStateProperty.all<double>(2),
      foregroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        return DarkThemeColors.scaffoldBackgroundColor;
      }),
      backgroundColor: WidgetStateProperty.resolveWith<Color>((states) {
        if (states.contains(WidgetState.disabled)) {
          return Colors.transparent;
        } else {
          return Colors.transparent;
        }
      }),
      maximumSize: WidgetStateProperty.all<Size>(
        const Size(double.infinity, double.infinity),
      ),
      minimumSize: WidgetStateProperty.all<Size>(
        const Size(double.minPositive, double.minPositive),
      ),
      shape: WidgetStateProperty.all<RoundedRectangleBorder>(
        const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(4)),
        ),
      ),
      textStyle: WidgetStateProperty.all<TextStyle>(
        const TextStyle(
          fontSize: 12,
          fontWeight: FontWeight.w600,
          color: DarkThemeColors.accentColor,
        ),
      ),
      // overlayColor: WidgetStateProperty.resolveWith<Color>((states) {
      //   return DarkThemeColors.lightGrey;
      // }),
    ),
  ),
  bottomSheetTheme: const BottomSheetThemeData(
    backgroundColor: Colors.transparent,
    // surfaceTintColor: Colors.transparent,
    modalBackgroundColor: Colors.transparent,
    modalElevation: 0,
    elevation: 0,
  ),
);
