package com.sjkj.appthreefloor_tsgz.utils;

import android.content.DialogInterface;
import android.content.Intent;

import androidx.appcompat.app.AlertDialog;

import com.sjkj.appthreefloor_tsgz.bean.MenuMainItemBean;
import com.sjkj.appthreefloor_tsgz.login.LoginActivity;
import com.sjkj.base_lib.app.AppManager;
import com.sjkj.base_lib.utils.AppTools;
import com.tencent.mmkv.MMKV;

import java.util.ArrayList;

public class AppSystemUtils {
    private static MMKV mmkv = MMKV.defaultMMKV();
    public static ArrayList<MenuMainItemBean> menuList = new ArrayList<>();
    public static boolean isLeader = false;

    public static void exitApp() {
        try {
            AppSystemUtils.menuList.clear();
            AppTools.LOCUS_OPEN = false;
            AppTools.setLogin(false);
            AppTools.setToken("");
            AppTools.setUserId("");
            AppTools.setDeptId("");
            AppTools.setDeptName("");
            AppTools.setNickName("");
            AppTools.setIsWangGe("");
            //AppTools.setUserName("");
//            AppTools.setPassword("");
            //停止、清除登录人推送信息
            //PushUtils.pushStop();
            //页面跳转登录页
            Intent intent = new Intent(AppManager.getAppManager().currentActivity(), LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            AppManager.getAppManager().currentActivity().startActivity(intent);
            //关闭当前页面
            AppManager.getAppManager().currentActivity().finish();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void showDialogLoginAuth() {
        AlertDialog alertDialog = new AlertDialog.Builder(AppManager.getAppManager().currentActivity())
                .setTitle("提示")
                .setMessage("登录状态失效，或已在其他设备登录!")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        AppSystemUtils.exitApp();
                        dialogInterface.dismiss();
                    }
                })
//                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                     }
//                })
                .setCancelable(false)
                .create();

        alertDialog.show();

    }

    public static void setGhb(boolean isghb) {
            mmkv.encode("isGhb", isghb);
    }

    public static boolean isGhb() {
        return mmkv.decodeBool("isGhb", false);
    }

    public static void isGhb(GhbListener ghbListener) {
        if (isGhb()) {
            if (ghbListener != null)
                ghbListener.resultYes();
        } else {
            if (ghbListener != null)
                ghbListener.resultNo();
        }
    }

    public interface GhbListener {
        void resultYes();

        void resultNo();
    }
}
