import 'package:flutter/material.dart';

//定义扩展方便获取到颜色值
extension ThemeDataExtension on ThemeData {
  AppColorsTheme get appColors => extension<AppColorsTheme>()!;
}

extension AppColorsThemeExtensions on BuildContext {
  AppColorsTheme get appColors => Theme.of(this).extension<AppColorsTheme>()!;
}

class AppColorsTheme extends ThemeExtension<AppColorsTheme> {
  //亮色主题的自定义颜色值
  static const color666666 = Color(0xFF666666);
  static const colorPrimary = Color(0xFF01B5EB);
  static const _colorPrimary = Color(0xFF01B5EB);
  static const _colorFF5E75 = Color(0xFFFF5E75);
  static const _color06FBFD = Color(0xFFF6FBFD);
  static const _colorD7DBE7 = Color(0xffD7DBE7);
  static const _colorBDBDBD = Color(0xFFBDBDBD);
  static const _colorF2F2F2 = Color(0xFFF2F2F2);
  static const _colorFE6C00 = Color(0xFFFEA700);
  static const _colorD3D3D3 = Color(0xFFD3D3D3);
  static const _color333333 = Color(0xFF333333);
  static const _colorF3F3F3 = Color(0xFFF3F3F3);
  static const _color999999 = Color(0xFF999999);
  static const _colorF2F3F6 = Color(0xFFF2F3F6);
  static const _colorDCDCDC = Color(0xFFDCDCDC);
  static const _colorE5F8FF = Color(0xFFE5F8FF);
  static const _colorEFFAFF = Color(0xFFEFFAFF);
  static const _color1B61CA = Color(0X4D1B61CA);
  static const _color8B96BA = Color(0xFF8B96BA);
  static const _colorB4C5FF = Color(0xFFB4C5FF);
  static const _colorFE4066 = Color(0xFFFE4066);
  static const _colorE9E9E9 = Color(0xFFE9E9E9);
  static const _color99A8CA = Color(0xFF99A8CA);
  static const _color0DBE1E= Color(0xFF0DBE1E);
  static const _color05CC67= Color(0xFF05CC67);
  static const _colorB8BFD9= Color(0x4DB8BFD9);
  static const _color063148= Color(0XFF063148);
  static const _color939393= Color(0XFF939393);

  //暗色主题的一些自定义颜色值
  static const _darkBlackBg = Color(0xFF0F0F0F);
  static const _darkBlackItem = Color(0xFF1D1D1E);
  static const _darkBlackItemLight = Color(0xFF3B3933);
  static const _darkBlackItemLightShadow = Color(0x4D3B3933);
  static const _darkBlackItemLightMost = Color(0xFF5C5850);
  static const _darkBlackItemDivider = Color(0xFF3B3B3F);

  // 页面中真正使用到的颜色名称
  final Color backgroundDefault; //页面背景颜色（偏白）
  final Color backgroundDark; //页面背景颜色(蓝灰蓝)
  final Color backgroundWhite; //页面背景颜色(白色)
  final Color btnBgDefault; //按钮背景颜色
  final Color btnBgDefaultDark; //按钮背景颜色
  final Color searchFiledBorder; //搜索框的边框颜色
  final Color authFiledHint; //输入框默认的提示文本颜色
  final Color authFiledText; //输入框默认的文本颜色
  final Color authFiledBG; //输入框默认的背景颜色
  final Color textPrimary; //主题色文本
  final Color textBlack; //黑色文本
  final Color textWhite; // 白色文本
  final Color textDarkGray; //深灰色 666 文本
  final Color textDisEnableGray; //深灰色 939393 文本
  final Color orangeBG; //按钮的橙色背景
  final Color tabBgSelectedPrimary; //Tab的选中主题色背景
  final Color tabBgUnSelectedPrimary; //Tab的未选中主题色背景
  final Color tabTextSelectedPrimary; //Tab的未选中主题色文本
  final Color tabTextUnSelectedPrimary; //Tab的未选中主题色文本
  final Color imgGrayBg; //灰色的图片底色背景
  final Color textDarkGray999; //文本深灰色
  final Color whiteBG; //按钮的白色色背景
  final Color whiteSecondBG; //按钮的白色色背景
  final Color redDefault; //App标准红色
  final Color dividerDefault; //分割线默认颜色
  final Color lightBlueDarkBg; //淡紫色背景
  final Color lightBlueBg; //淡蓝色背景
  final Color tabTextSelectedDefault; //Tab文本，选中主题蓝，黑暗模式为白色
  final Color tabTextUnSelectedDefault; //Tab文本，未选中 亮色为黑色，黑暗模式为灰色
  final Color tabLightBlueShadow; //Tab的淡蓝色阴影
  final Color textLightPurple; //文本淡紫色
  final Color avatarBg; //头像框的淡蓝色
  final Color deleteRed; //删除的红色
  final Color grayBgE9; //e9灰色背景
  final Color disEnableGray; //禁用的灰色
  final Color authFiledHintDark; //文本Hint的深蓝色
  final Color greenBG; //按钮的绿色背景
  final Color textGreen; //按钮的绿色背景
  final Color imageDarkModelWhite; //黑暗模式是白色，亮色模式为null，用于图片 Image 的着色
  final Color itemBGShadow; //列表Item布局的阴影颜色

  // 私有的构造函数
  const AppColorsTheme._internal({
    required this.backgroundDefault,
    required this.backgroundDark,
    required this.backgroundWhite,
    required this.btnBgDefault,
    required this.btnBgDefaultDark,
    required this.searchFiledBorder,
    required this.authFiledHint,
    required this.authFiledText,
    required this.authFiledBG,
    required this.textPrimary,
    required this.textBlack,
    required this.textWhite,
    required this.textDarkGray,
    required this.textDisEnableGray,
    required this.orangeBG,
    required this.tabBgSelectedPrimary,
    required this.tabBgUnSelectedPrimary,
    required this.tabTextSelectedPrimary,
    required this.tabTextUnSelectedPrimary,
    required this.imgGrayBg,
    required this.textDarkGray999,
    required this.whiteBG,
    required this.whiteSecondBG,
    required this.redDefault,
    required this.dividerDefault,
    required this.lightBlueDarkBg,
    required this.lightBlueBg,
    required this.tabLightBlueShadow,
    required this.tabTextSelectedDefault,
    required this.tabTextUnSelectedDefault,
    required this.textLightPurple,
    required this.avatarBg,
    required this.deleteRed,
    required this.grayBgE9,
    required this.disEnableGray,
    required this.authFiledHintDark,
    required this.greenBG,
    required this.textGreen,
    required this.imageDarkModelWhite,
    required this.itemBGShadow,
  });

  // 浅色主题工厂方法
  factory AppColorsTheme.light() {
    return const AppColorsTheme._internal(
      backgroundDefault: _color06FBFD,
      backgroundDark: _colorF2F3F6,
      backgroundWhite: Colors.white,
      btnBgDefault: _colorPrimary,
      btnBgDefaultDark: _colorPrimary,
      searchFiledBorder: _colorD7DBE7,
      authFiledHint: _colorBDBDBD,
      authFiledText: Colors.black,
      authFiledBG: _colorF2F2F2,
      textPrimary: _colorPrimary,
      textBlack: _color063148,
      textWhite: Colors.white,
      textDarkGray: color666666,
      orangeBG: _colorFE6C00,
      tabBgSelectedPrimary: _colorPrimary,
      tabBgUnSelectedPrimary: _colorD3D3D3,
      tabTextSelectedPrimary: Colors.white,
      tabTextUnSelectedPrimary: _color333333,
      imgGrayBg: _colorF3F3F3,
      textDarkGray999: _color999999,
      whiteBG: Colors.white,
      whiteSecondBG: Colors.white,
      redDefault: _colorFF5E75,
      dividerDefault: _colorDCDCDC,
      lightBlueDarkBg: _colorE5F8FF,
      lightBlueBg: _colorEFFAFF,
      tabLightBlueShadow: _color1B61CA,
      tabTextSelectedDefault: _colorPrimary,
      tabTextUnSelectedDefault: Colors.black,
      textLightPurple: _color8B96BA,
      avatarBg: _colorB4C5FF,
      deleteRed: _colorFE4066,
      grayBgE9: _colorE9E9E9,
      disEnableGray: _colorBDBDBD,
      authFiledHintDark: _color99A8CA,
      greenBG: _color0DBE1E,
      textGreen: _color05CC67,
      imageDarkModelWhite: Colors.transparent,
      itemBGShadow: _colorB8BFD9,
      textDisEnableGray: _color939393,
    );
  }

  // 暗色主题工厂方法
  factory AppColorsTheme.dark() {
    return const AppColorsTheme._internal(
      backgroundDefault: _darkBlackBg,
      backgroundDark: _darkBlackBg,
      backgroundWhite: _darkBlackBg,
      btnBgDefault: _darkBlackItem,
      btnBgDefaultDark: _darkBlackItemLight,
      searchFiledBorder: _darkBlackItem,
      authFiledHint: _colorD7DBE7,
      authFiledText: Colors.white,
      authFiledBG: _darkBlackItem,
      textPrimary: Colors.white,
      textBlack: Colors.white,
      textWhite: Colors.black,
      textDarkGray: Colors.white,
      orangeBG: _darkBlackItemLightMost,
      tabBgSelectedPrimary: Colors.white,
      tabBgUnSelectedPrimary: _darkBlackItem,
      tabTextSelectedPrimary: Colors.black,
      tabTextUnSelectedPrimary: Colors.white,
      imgGrayBg: _darkBlackItem,
      textDarkGray999: Colors.white,
      whiteBG: _darkBlackItem,
      whiteSecondBG: _darkBlackItemLight,
      redDefault: _darkBlackItem,
      dividerDefault: _darkBlackItemDivider,
      lightBlueDarkBg: _darkBlackItemLight,
      lightBlueBg: _darkBlackItem,
      tabLightBlueShadow: _color1B61CA,
      tabTextSelectedDefault: _colorPrimary,
      tabTextUnSelectedDefault: Colors.white,
      textLightPurple: Colors.white,
      avatarBg: _darkBlackItemLight,
      deleteRed: Colors.white,
      grayBgE9: _darkBlackItemLightMost,
      disEnableGray: _darkBlackItemLight,
      authFiledHintDark: _color99A8CA,
      greenBG: _darkBlackItemLight,
      textGreen: Colors.white,
      imageDarkModelWhite: Colors.white,
      itemBGShadow: _darkBlackItemLight,
      textDisEnableGray: Colors.white,
    );
  }

  @override
  ThemeExtension<AppColorsTheme> copyWith({bool? lightMode}) {
    if (lightMode == null || lightMode == true) {
      return AppColorsTheme.light();
    }
    return AppColorsTheme.dark();
  }

  @override
  AppColorsTheme lerp(covariant ThemeExtension<AppColorsTheme>? other, double t) {
    if (other is! AppColorsTheme) return this;
    return AppColorsTheme._internal(
      backgroundDefault: Color.lerp(backgroundDefault, other.backgroundDefault, t)!,
      backgroundDark: Color.lerp(backgroundDark, other.backgroundDark, t)!,
      backgroundWhite: Color.lerp(backgroundWhite, other.backgroundWhite, t)!,
      btnBgDefault: Color.lerp(btnBgDefault, other.btnBgDefault, t)!,
      btnBgDefaultDark: Color.lerp(btnBgDefaultDark, other.btnBgDefaultDark, t)!,
      searchFiledBorder: Color.lerp(searchFiledBorder, other.searchFiledBorder, t)!,
      authFiledHint: Color.lerp(authFiledHint, other.authFiledHint, t)!,
      authFiledText: Color.lerp(authFiledText, other.authFiledText, t)!,
      authFiledBG: Color.lerp(authFiledBG, other.authFiledBG, t)!,
      textPrimary: Color.lerp(textPrimary, other.textPrimary, t)!,
      textBlack: Color.lerp(textBlack, other.textBlack, t)!,
      textWhite: Color.lerp(textWhite, other.textWhite, t)!,
      textDarkGray: Color.lerp(textDarkGray, other.textDarkGray, t)!,
      orangeBG: Color.lerp(orangeBG, other.orangeBG, t)!,
      tabBgSelectedPrimary: Color.lerp(tabBgSelectedPrimary, other.tabBgSelectedPrimary, t)!,
      tabBgUnSelectedPrimary: Color.lerp(tabBgUnSelectedPrimary, other.tabBgUnSelectedPrimary, t)!,
      tabTextSelectedPrimary: Color.lerp(tabTextSelectedPrimary, other.tabTextSelectedPrimary, t)!,
      tabTextUnSelectedPrimary: Color.lerp(tabTextUnSelectedPrimary, other.tabTextUnSelectedPrimary, t)!,
      imgGrayBg: Color.lerp(imgGrayBg, other.imgGrayBg, t)!,
      textDarkGray999: Color.lerp(textDarkGray999, other.textDarkGray999, t)!,
      whiteBG: Color.lerp(whiteBG, other.whiteBG, t)!,
      whiteSecondBG: Color.lerp(whiteSecondBG, other.whiteSecondBG, t)!,
      redDefault: Color.lerp(redDefault, other.redDefault, t)!,
      dividerDefault: Color.lerp(dividerDefault, other.dividerDefault, t)!,
      lightBlueDarkBg: Color.lerp(lightBlueDarkBg, other.lightBlueDarkBg, t)!,
      lightBlueBg: Color.lerp(lightBlueBg, other.lightBlueBg, t)!,
      tabTextSelectedDefault: Color.lerp(tabTextSelectedDefault, other.tabTextSelectedDefault, t)!,
      tabLightBlueShadow: Color.lerp(tabLightBlueShadow, other.tabLightBlueShadow, t)!,
      tabTextUnSelectedDefault: Color.lerp(tabTextUnSelectedDefault, other.tabTextUnSelectedDefault, t)!,
      textLightPurple: Color.lerp(textLightPurple, other.textLightPurple, t)!,
      avatarBg: Color.lerp(avatarBg, other.avatarBg, t)!,
      deleteRed: Color.lerp(deleteRed, other.deleteRed, t)!,
      grayBgE9: Color.lerp(grayBgE9, other.grayBgE9, t)!,
      disEnableGray: Color.lerp(disEnableGray, other.disEnableGray, t)!,
      authFiledHintDark: Color.lerp(authFiledHintDark, other.authFiledHintDark, t)!,
      greenBG: Color.lerp(greenBG, other.greenBG, t)!,
      textGreen: Color.lerp(textGreen, other.textGreen, t)!,
      imageDarkModelWhite: Color.lerp(imageDarkModelWhite, other.imageDarkModelWhite, t)!,
      itemBGShadow: Color.lerp(itemBGShadow, other.itemBGShadow, t)!,
      textDisEnableGray: Color.lerp(textDisEnableGray, other.textDisEnableGray, t)!,
    );
  }
}
