import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:location/resource/colors.gen.dart';
import 'package:location/resource/string.gen.dart';
import 'package:location/utils/common_expand.dart';
import 'common_alert_dialog.dart';

void exitAccountDialog({required VoidCallback confirmOnTap}) {
  final tag = 'exitAccountDialog';
  CommonAlertDialog.show(
      titleWidget: Text(
        StringName.dialogExitAccountTitle,
        style: TextStyle(
            fontSize: 18.sp,
            color: ColorName.black90,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        StringName.dialogExitAccountDesc,
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.dialogSure,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      },
      tag: tag);
}

void deleteFriendDialog({required VoidCallback confirmOnTap}) {
  final tag = 'deleteFriendDialog';
  CommonAlertDialog.show(
      tag: tag,
      titleWidget: Text(
        StringName.kindlyReminder,
        style: TextStyle(
            fontSize: 17.sp,
            color: '#333333'.color,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        StringName.friendDeleteContent,
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.dialogSure,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      });
}

void showBlockMeTipDialog({required VoidCallback confirmOnTap}) {
  final tag = 'showBlockMeTipDialog';
  CommonAlertDialog.show(
      tag: tag,
      titleWidget: Text(
        StringName.kindlyReminder,
        style: TextStyle(
            fontSize: 17.sp,
            color: '#333333'.color,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        StringName.friendNotOpenLocationShare,
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.friendGoInstructHim,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      });
}

void showDeleteUrgentContactDialog(String phone,
    {required VoidCallback confirmOnTap}) {
  final tag = 'showDeleteUrgentContactDialog';
  CommonAlertDialog.show(
      tag: tag,
      titleWidget: Text(
        StringName.kindlyReminder,
        style: TextStyle(
            fontSize: 17.sp,
            color: '#333333'.color,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        '您确定要将 $phone 移除紧急联系人吗？',
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.dialogSure,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      });
}

void sendUrgentContactDialog(String phone,
    {required VoidCallback confirmOnTap}) {
  final tag = 'sendUrgentContactDialog';
  CommonAlertDialog.show(
      tag: tag,
      titleWidget: Text(
        StringName.urgentContactEmergencyHelp,
        style: TextStyle(
            fontSize: 17.sp,
            color: '#333333'.color,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        '确认向 $phone 发送短信求助？',
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.dialogSure,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      });
}

void sendAllUrgentContactDialog({required VoidCallback confirmOnTap}) {
  final tag = 'sendAllUrgentContactDialog';
  CommonAlertDialog.show(
      tag: tag,
      titleWidget: Text(
        StringName.urgentContactEmergencyHelp,
        style: TextStyle(
            fontSize: 17.sp,
            color: '#333333'.color,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        StringName.urgentContactSendAllHelp,
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.dialogSure,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      });
}

String _failPhonesConvertString(List<String> phones) {
  if (phones.isNotEmpty) {
    return phones.join('、');
  }
  return "";
}

void sendUrgentContactPartErrorDialog(List<String> phones,
    {required VoidCallback confirmOnTap}) {
  final tag = 'sendUrgentContactPartErrorDialog';
  CommonAlertDialog.show(
      tag: tag,
      titleWidget: Text(
        StringName.urgentContactEmsSendPartFail,
        style: TextStyle(
            fontSize: 17.sp,
            color: '#333333'.color,
            fontWeight: FontWeight.bold),
      ),
      descWidget: Text(
        '联系人 ${phones.map((phone) => '「$phone」').join('、')} 发送失败，请检查号码重试！',
        style: TextStyle(fontSize: 15.sp, color: '#404040'.color),
      ),
      cancelText: StringName.dialogCancel,
      confirmText: StringName.dialogSure,
      cancelOnTap: () {
        CommonAlertDialog.dismiss(tag: tag);
      },
      confirmOnTap: () {
        confirmOnTap();
        CommonAlertDialog.dismiss(tag: tag);
      });
}

void logoutAccountDialog(
    {required VoidCallback logoutCallback,
    required VoidCallback cancelCallback}) {
  CommonAlertDialog.show(
      titleWidget: Text(StringName.logoutAccount,
          style: TextStyle(
              fontSize: 17.sp,
              color: '#333333'.color,
              fontWeight: FontWeight.bold)),
      descWidget: Text(
        StringName.logoutAccountContent,
        style: TextStyle(fontSize: 14.sp, color: '#404040'.color),
      ),
      cancelOnTap: () {
        CommonAlertDialog.dismiss();
        logoutCallback.call();
      },
      confirmText: StringName.dialogCancel,
      cancelText: StringName.logoutAccount,
      confirmOnTap: () {
        CommonAlertDialog.dismiss();
        cancelCallback.call();
      });
}
