import 'package:electronic_assistant/base/base_controller.dart';
import 'package:electronic_assistant/resource/colors.gen.dart';
import 'package:electronic_assistant/utils/error_handler.dart';
import 'package:electronic_assistant/utils/toast_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../data/repositories/account_repository.dart';
import '../../../dialog/alert_dialog.dart';
import '../../../resource/string.gen.dart';
import '../../../utils/app_info_util.dart';
import '../controller.dart';

class MainDrawerController extends BaseController {
  String get versionName => "v${appInfoUtil.appVersionName}";

  String get loginTxt =>
      accountRepository.getUserSubName(accountRepository.phone);

  String get electricityTxt => '${StringName.mainLoginChargeTips.tr}';

  void accountLogout() {
    EAAlertDialog.show(
        contentWidget: Text(
          StringName.accountLogoutTips.tr,
          style: TextStyle(
              fontSize: 15.sp,
              color: ColorName.primaryTextColor,
              fontWeight: FontWeight.bold),
        ),
        cancelText: StringName.cancel.tr,
        confirmText: StringName.sure.tr,
        confirmOnTap: () {
          accountRepository.userDeprecate().then((data) {
            Get.find<MainController>().closeDrawer();
            accountRepository.logout();
            ToastUtil.showToast(StringName.accountLogoutSuccess.tr);
          }).catchError((error) {
            ErrorHandler.toastError(error);
          });
        });
  }
}
