import 'package:chat/generated/i18n.dart';
import 'package:chat/utils/date_utils.dart';
import 'package:flutter/material.dart';

class AppColors {
  static const BackgroundColor = Color(0xFFeeeeee);
  static const RefreshBgColor = Color(0xFFF4F4F4);
  static const AppBarColor = 0xff303030;
  static const TabIconNormal = 0xff999999;
  static const TabIconActive = 0xff46c11b;
  static const AppBarPopupMenuColor = 0xffffffff;
  static const TitleColor = Color(0xff353535);
  static const ConversationItemBgColor = 0xffffffff;
  static const DescTextColor = 0xff9e9e9e;
  static const DividerColor = Color(0xffd9d9d9);
  static const NewAppbarBgColor = Colors.white;
  static const NewAppbarTextColor = Colors.black;
  static const ChatItemBgColor = Color(0xffF75F92);
  static const NotifyDotBgColor = 0xffff3e3e;
  static const NotifyDotText = 0xffffffff;
  static const ConversationMuteIconColor = 0xffd8d8d8;
  static const DeviceInfoItemBgColor = 0xfff5f5f5;
  static const DeviceInfoItemTextColor = 0xff606062;
  static const DeviceInfoItemIconColor = 0xff606062;
  static const ContactGroupTitleBgColor = 0xffebebeb;
  static const ContactGroupTitleColor = 0xff888888;
  static const IndexLetterBoxBgColor = Colors.black45;
}

class AppStyles {
  static const TitleStyle = TextStyle(
    fontSize: 14.0,
    color: AppColors.TitleColor,
  );

  static const DescStyle = TextStyle(
    fontSize: 12.0,
    color: Constants.GreyTextColor,
  );
  static const UnreadMsgCountDotStyle = TextStyle(
    fontSize: 11.0,
    color: Color(AppColors.NotifyDotText),
  );

  static const DeviceInfoItemTextStyle = TextStyle(
    fontSize: 13.0,
    color: Color(AppColors.DeviceInfoItemTextColor),
  );
  static const GroupTitleItemTextStyle =
      TextStyle(color: Color(AppColors.ContactGroupTitleColor), fontSize: 14.0);

  static const IndexLetterBoxTextStyle = TextStyle(
    fontSize: 64.0,
    color: Colors.white,
  );
}

class ComId {
  static const int Heart = 0;
  static const int Login = 1;
  static const int Chat = 2;
  static const int TranslateOrder = 3;
  static const int PushMsg = 100;
}

enum ChatState {
  connecting, //连接中
  connected, //连接成功
  connectFailed, //连接失败
  logining, //登录中
  logined, //登录成功
  loginFailed //登录失败
}

//语言类别
class LanguageType {
  static const int English = 0; //英语
  static const int Vietnamese = 1; //越南语
  static const int TraditionalChinese = 2; //繁体中文
  static const int SimplifiedChinese = 3; //简体中文
  static const int Korean = 4; //韩语
  static const int Japanese = 5; //日语
}

//群管理界面类别
class GroupOperatingPageType {
  static const int AddMember = 0; //增加新的成员
  static const int DeleteMember = 1; //删除新的成员
  static const int SelectGroupOwner = 2; //选择群主
  static const int CreateGroup = 3; //创建群组
}

//消息发送界面类别
class SendMessagePageType {
  static const int AddFriends = 0;          //添加朋友
  static const int ChangeGroupName = 1;     //修改群名字
  static const int ChangeGroupNickName = 2; //修改群昵称
  static const int Remark = 3; //修改备注
}

//全局搜索类别
class GlobalSearchPageType {
  static const int SearchMyFriends = 0; //查找我的好友成员
  static const int SearchGroup = 1; //查找群
  static const int SearchNewFriends = 2; //查找新的好友
}

const String googleMapApiKey = 'AIzaSyAb9JNtW0BEZ_qLeDg87ZhvxSmZply-7hU';

class Constants {
  ///ture 应用商店版本  false线下渠道
  static const bool isStoreVersion = false;

  //app全局key,处理content
  static final GlobalKey<NavigatorState> navigatorKey = GlobalKey();

  /// 获取当前的state
  static NavigatorState getCurrentState() => navigatorKey.currentState;

  /// 获取当前的context
  static BuildContext getCurrentContext() =>
      navigatorKey.currentState.overlay.context; //navigatorKey.currentContext;

  ///在pubspec.yaml中修改版本号
  static String versionName = '1.0.0';

  static bool isSandbox = false;

  static String packageName = 'com.cyhd.henhoandroid';

  static const IconFontFamily = "iconFont";
  static const ConversationAvatarSize = 48.0;
  static const DividerWidth = 0.5;
  static const UnReadMsgNotifyDotSize = 22.0;
  static const ConversationMuteIcon = 18.0;
  static const ContactAvatarSize = 36.0;
  static const IndexBarWidth = 24.0;
  static const IndexLetterBoxSize = 114.0;
  static const IndexLetterBoxRadius = 4.0;
  static const FullWidthIconButtonIconSize = 24.0;
  static const ProfileHeaderIconSize = 60.0;

  static const int NameLength = 14;

  static const AppId = 'wx02328a8853f058ad';
  static const Secret = '9d401b6a8bfe7b2fe63b3bf5c040b2f2';

  static const CloseLoaindTime = 250;

  static const VipColor = const Color(0xFFFA9F00);
  //背景色
  static const LightGreyBackgroundColor = const Color(0xfffafafa);
  static const GreyBackgroundColor = const Color(0xFFF0F0F0);
  static const PurpleBackgroundColor = const Color(0xFFEC4163);
  static const LightBlueBackgroundColor = const Color(0xFFEDF6FE);

  //字体颜色
  static const GreyTextColor = const Color(0xFF848486);
  static const BlackTextColor = const Color(0xFF1B201F);
  static const RedTextColor = const Color(0xFFFD959F);
  static const YellowTextColor = const Color(0xFFCDBD75);
  static const BlueTextColor = const Color(0xFF008AFF);
  static const LightBlueTextColor = const Color(0xFF88A3BC);
  static const LightGreyTextColor = const Color(0xFFB0B0B0);
  static const OpacityBlueTextColor = const Color(0xFFB7DEFF);
  static const PinkTextColor = const Color(0xFFEB71BD);

  //图标颜色
  static const BlueIconColor = const Color(0xFF86B3D9);
  static const LightBlueIconColor = const Color(0xFFB6DDFF);

  static const MainTitleStyle = TextStyle(
      fontSize: 20.0,
      color: Constants.BlackTextColor,
      fontWeight: FontWeight.w500);

  //分割线颜色
  static const DividerLineColor = const Color(0xFFE8E8E8);
  static const GreyBorderSide =
      BorderSide(color: const Color(0xFFF3F3F3), width: 1);

  //按钮颜色
  static const ConfrimButtonColor = const Color(0xFF3875E9);
  static const CancleButtonColor = Colors.grey;
  static const LightBlueButtonColor = const Color(0xFF6EBCFF);

  //按钮
  static const ConfirmBUttonBoxDecoration = BoxDecoration(
      color: Constants.ConfrimButtonColor,
      borderRadius: BorderRadius.all(Radius.circular(LittleButtonRadius)));

  static const BottomIconGreyColor = const Color(0xffa0a0a0);

  static const LittleButtonRadius = 5.0;
  static const BigButtonRadius = 8.0;

  //tabbar样式
  static const SelectTabBarTextStyle = TextStyle(fontSize: 14);
  static const UnselectTabBarTextStyle = TextStyle(fontSize: 14);

  static const AppBarActionTextStyle =
      TextStyle(color: BlueTextColor, fontSize: 14.9);

  static const double ShaderButtonHeight = 49.15;
  static const double ShaderButtonFontSize = 18;

  static const TextFieldIconSize = 20.0;

  //图片
  static const DefaultHeadImgUrl = 'assets/images/default_nor_avatar.png';

  //类别颜色
  static const Category1Color = const Color(0xFF3D9BE2);
  static const Category2Color = const Color(0xFF934DDA);
  static const Category3Color = const Color(0xFF5B6AEB);
  static const Category4Color = const Color(0xFFE66C84);
  static const Category5Color = const Color(0xFFD4915E);
  static const Category6Color = const Color(0xFF3AB364);
  static const Category7Color = const Color(0xFF59B1FA);
  static const Category8Color = const Color(0xFF676666);

  //系统消息渐变
  static const RadioGradient = LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: <Color>[
        const Color(0xFF58B7F5),
        const Color(0xFF1874C9),
      ]);

  static const MoneyGradient = LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: <Color>[
        const Color(0xFF6171F1),
        const Color(0xFF3441C1),
      ]);
  static const ApplyGradient = LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: <Color>[
        const Color(0xFFED7990),
        const Color(0xFFC22444),
      ]);
  static const EvaGradient = LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: <Color>[
        const Color(0xFF1BC79F),
        const Color(0xFF078D75),
      ]);
  static const ParkGradient = LinearGradient(
      begin: Alignment.topCenter,
      end: Alignment.bottomCenter,
      colors: <Color>[
        const Color(0xFFFBC535),
        const Color(0xFFE67430),
      ]);

  //本地存储key
  static const KeyboardHeight = 'KeyboardHeight';
  static const AutoLoginKey = 'autoLoginKey';
  static const Language = 'language';
  static const LocalUserId = 'localUserId';

  static const ApplyCount = 'applyCount';
  static const EvaluateCount = 'evaluateCount';
  static const ParkCount = 'parkCount';
  static const CastCount = 'castCount';
  static const WalletCount = 'walletCount';

  static const IOS_IAP_Receipt = 'iosIAPReceipt';
  static const SOUND_PLAY_MODE = 'isSoundReceiver'; //false外放-ture声筒

  static const ContactNum = 'ConstantNum'; //本地存储通讯录数量

  static const NewFriendsList = 'NewFriendsList'; //本地缓存的新朋友列表

  static const Splash_OPENED = 'splashOpened_13'; //是否加载过引导页
  static const LocalUsrInfo = 'LocalUsrInfo'; //本地用户数据

  static const TranslationHelper = 'translationhelper'; //加载翻译管家相关信息

  //定位获取太慢，缓存经纬度
  static const Latitude = 'Latitude';
  static const Longitude = 'Longitude';

  /// currentGoodsId+'@'+receipt+'@'+purchaseToken

  static final vipIcon = Image.asset(
    'assets/images/VIP.png',
    height: 11.5,
  );

  static final svipIcon = Padding(
    padding: EdgeInsets.only(bottom: 5.5),
    child: Image.asset(
      'assets/images/svip.png',
      height: 14,
    ),
  );

  static const ConversationAvatarDefaultIocn = Icon(
    IconData(
      0xe642,
      fontFamily: IconFontFamily,
    ),
    size: ConversationAvatarSize,
  );

  static const ContactAvatarDefaultIocn = Icon(
    IconData(
      0xe642,
      fontFamily: IconFontFamily,
    ),
    size: ContactAvatarSize,
  );

  static const ProfileAvatarDefaultIocn = Icon(
    IconData(
      0xe642,
      fontFamily: IconFontFamily,
    ),
    size: ProfileHeaderIconSize,
  );

  static const Agore_appId = '7564ab9804b6455ba337ff39aad2779b';

  //一些公共函数
  static getShowTime(int msgTime, BuildContext context) {
    var showTime;

    DateTime now = DateTime.now();
    DateTime time = DateTime.fromMillisecondsSinceEpoch(msgTime);

    if (now.year != time.year) {
      showTime = DateUtils().getFormartData(timeSamp: msgTime, format: 'yyyy');
    } else {
      if (now.month != time.month) {
        showTime =
            DateUtils().getFormartData(timeSamp: msgTime, format: 'MM/dd');
      } else {
        int days = now.day - time.day;
        if (days != 0) {
          showTime =
              I18n.of(context).day_ago.replaceFirst('/s1', days.toString());
        } else {
          showTime =
              DateUtils().getFormartData(timeSamp: msgTime, format: 'HH:mm');
        }
      }
    }

    return showTime;
  }
}

const INDEX_BAR_WORDS = [
  "↑",
  "#",
  "A",
  "B",
  "C",
  "D",
  "E",
  "F",
  "G",
  "H",
  "I",
  "J",
  "K",
  "L",
  "M",
  "N",
  "O",
  "P",
  "Q",
  "R",
  "S",
  "T",
  "U",
  "V",
  "W",
  "X",
  "Y",
  "Z",
  "  "
];

const double MARGIN_VERTICAL = 10.0;
const double GROUP_TITLE_HEIGHT = 24.0;
