import 'package:flutter/material.dart';

class ColorConstants {
  // 私有的构造函数，防止实例化
  ColorConstants._();

  //颜色的常量值
  static const Color lightScaffoldBackgroundColor = Color(0xffF9F9F9); //整体背景颜色（Light）
  static const Color darkScaffoldBackgroundColor = Color(0xFF0F0F0F); //整体背景颜色（Dark）
  static const Color secondaryAppColor = Color(0xff00AFFF); //可以用作光标的一些颜色
  static const Color secondaryDarkAppColor = Color(0xFF1D1D1E); //Theme的Appbar颜色

  static const Color gray = Color(0xFFCCCCCC);
  static const Color grayECECEC = Color(0xFFECECEC);
  static const Color gray88 = Color(0xFF888888);
  static const Color black = Color(0xFF000000);
  static const Color white = Color(0xFFFFFFFF);
  static const Color dividerA6 = Color(0x4da6a6a6);
  static const Color dividerBar = Color(0x334DCFF6);
  static const Color dividerItem = Color(0xffEDF0F3);
  static const Color appBlue = Color(0xff0689fb);
  static const Color blue1578fe = Color(0xFF1578FE);
  static const Color black33 = Color(0xff333333);
  static const Color black66 = Color(0xff666666);
  static const Color black404A5B = Color(0xff404A5B);
  static const Color whitefe = Color(0xffFEFEFE);
  static const Color greye0 = Color(0xffE0E0E0);
  static const Color textGrayAECAE5 = Color(0xFFAECAE5);
  static const Color textBlackHint = Color(0xFF757575);
  static const Color textGray9EB0C1 = Color(0xFF9EB0C1);
  static const Color textYellowFFBB1B = Color(0xFFFFBB1B);
  static const Color textGreen05DC82 = Color(0xFF05DC82);
  static const Color textGreen0AC074 = Color(0xFF0AC074);
  static const Color textGreen00FB92 = Color(0xFF00FB92);
  static const Color textRedFF6262 = Color(0xFFFF6262);
  static const Color textBlue06D9FF = Color(0xFF06D9FF);
  static const Color textBlue5CEEFF = Color(0xFF5CEEFF);
  static const Color textBlue56AAFF = Color(0xFF56AAFF);
  static const Color textYellowF8AE00 = Color(0xFFF8AE00);
  static const Color textPurpleFF35EE = Color(0xFFFF35EE);
  static const Color redFF4066 = Color(0xFFFE4066);

  //黑暗模式的一些色值
  static const Color darkBlackBg = Color(0xFF0F0F0F);
  static const Color darkBlackItem = Color(0xFF1D1D1E);
  static const Color darkBlackItemLight = Color(0xFF3B3933);
  static const Color darkBlackItemLightMost = Color(0xFF5C5850);
  static const Color darkBlackItemDivider = Color(0xFF3B3B3F);

  // 颜色值转换
  static Color string2Color(String colorString) {
    int? value = 0x00000000;
    if (colorString.isNotEmpty) {
      if (colorString[0] == '#') {
        colorString = colorString.substring(1);
      }
      value = int.tryParse(colorString, radix: 16);
      if (value != null) {
        if (value < 0xFF000000) {
          value += 0xFF000000;
        }
      }
    }
    return Color(value!);
  }
}

Color hexToColor(String hex, {double opacity = 1.0}) {
  assert(RegExp(r'^#([0-9a-fA-F]{6})|([0-9a-fA-F]{8})$').hasMatch(hex), 'hex color must be #rrggbb or #rrggbbaa');

  return Color(
    int.parse(hex.substring(1), radix: 16) + (hex.length == 7 ? (opacity * 255).toInt() << 24 : 0x00000000),
  );
}
