import 'package:flutter/material.dart';
import '../../app/data/sp/ix_sp.dart';
import 'theme_extensions/theme_extension.dart';

import 'dark_theme_colors.dart';
import 'ix_styles.dart';
import 'light_theme_colors.dart';

class IXTheme {
  static getThemeData({required bool isLight}) {
    return ThemeData(
      // main color (app bar,tabs..etc)
      primaryColor: isLight
          ? LightThemeColors.primaryColor
          : DarkThemeColors.primaryColor,
      shadowColor: isLight
          ? LightThemeColors.shadowColor
          : DarkThemeColors.shadowColor,
      // secondary & background color
      colorScheme:
          ColorScheme.fromSwatch(
            accentColor: isLight
                ? LightThemeColors.accentColor
                : DarkThemeColors.accentColor,
            backgroundColor: isLight
                ? LightThemeColors.backgroundColor
                : DarkThemeColors.backgroundColor,
            brightness: isLight ? Brightness.light : Brightness.dark,
          ).copyWith(
            secondary: isLight
                ? LightThemeColors.accentColor
                : DarkThemeColors.accentColor,
          ),

      // color contrast (if the theme is dark text should be white for example)
      brightness: isLight ? Brightness.light : Brightness.dark,

      // card widget background color
      cardColor: isLight
          ? LightThemeColors.cardColor
          : DarkThemeColors.cardColor,

      // hint text color
      hintColor: isLight
          ? LightThemeColors.hintTextColor
          : DarkThemeColors.hintTextColor,

      canvasColor: isLight
          ? LightThemeColors.bgDisable
          : DarkThemeColors.bgDisable,

      splashColor: isLight ? LightThemeColors.bgScrim : DarkThemeColors.bgScrim,

      // divider color
      dividerColor: isLight
          ? LightThemeColors.dividerColor
          : DarkThemeColors.dividerColor,

      // app background color
      scaffoldBackgroundColor: isLight
          ? LightThemeColors.scaffoldBackgroundColor
          : DarkThemeColors.scaffoldBackgroundColor,

      highlightColor: isLight
          ? LightThemeColors.backgroundColor
          : DarkThemeColors.backgroundColor,

      // progress bar theme
      progressIndicatorTheme: ProgressIndicatorThemeData(
        color: isLight ? LightThemeColors.strokes2 : DarkThemeColors.strokes2,
      ),

      // appBar theme
      appBarTheme: IXStyles.getAppBarTheme(isLightTheme: isLight),

      // elevated button theme
      elevatedButtonTheme: IXStyles.getElevatedButtonTheme(
        isLightTheme: isLight,
      ),

      // text theme
      textTheme: IXStyles.getTextTheme(isLightTheme: isLight),

      // chip theme
      chipTheme: IXStyles.getChipTheme(isLightTheme: isLight),

      // icon theme
      iconTheme: IXStyles.getIconTheme(isLightTheme: isLight),

      // list tile theme
      listTileTheme: IXStyles.getListTileThemeData(isLightTheme: isLight),

      // custom themes
      extensions: [],
    );
  }

  /// update app theme and save theme type to shared pref
  /// (so when the app is killed and up again theme will remain the same)
  static changeTheme() {
    ReactiveTheme.toggleTheme();
  }

  /// check if the theme is light or dark
  bool get getThemeIsLight => IXSP.getThemeIsLight();
}
