package com.secspace.lib.common.function

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.view.View
import com.secspace.lib.common.R
import com.secspace.lib.common.dialog.SimpleDialog
import com.secspace.lib.common.dialog.SwitcherDialog
import com.secspace.lib.common.dialog.other.DialogUIListener
import com.secspace.lib.common.dialog.other.DialogUIUtils
import com.secspace.lib.common.event.ExitEvent
import com.secspace.lib.common.function.DpmOwnerHelper.disableAccountsAndRemoveProfileUsers
import com.secspace.lib.common.function.DpmOwnerHelper.isSettingDeviceOwner
import com.secspace.lib.common.function.DpmOwnerHelper.removeOtherUsers
import com.secspace.lib.common.function.WorkManager.installMiddleWare
import org.greenrobot.eventbus.EventBus

/**
 * Created by cyw_m on 2018/4/6.
 */
@SuppressLint("StaticFieldLeak")
object DialogManager{
    private var mSimpleDialog: SimpleDialog? = null
    /**
     * 安装中间件弹窗
     */
    fun showInstallMiddleWare(activity: Activity) {
        val context: Context = activity.application
        mSimpleDialog = SimpleDialog(activity).show(context.resources.getString(R.string.common_remind)
                , context.resources.getString(R.string.common_need_install_middleware)
                , false
                , DialogInterface.OnClickListener { dialog, which ->
            installMiddleWare(context)
            dialog.dismiss()
        }
                , null
        )
    }

    /**
     * 关闭普通dialog
     */
    fun dismissSimpleDialog() {
        if (mSimpleDialog != null) {
            mSimpleDialog!!.dismiss()
        }
    }

    fun showPrivacyPolicyDialog(activity: Activity?) {
        PrivacyPolicyDialog(activity).show()
    }

    fun showBuyCodeDialog(context: Context) {
        BuyCodeDialog.getInstance(context).show()
    }

    fun showMessageDialog(activity: Activity?, title: String?, content: String?, listener: MessageListener) {
        DialogUIUtils.showAlert(activity, title, content, "", "", "确定", "取消", false, false, false, object : DialogUIListener() {
            override fun onPositive() {
                listener.onPositive()
            }

            override fun onNegative() {
                listener.onNegative()
            }
        }).show()
    }

    fun showActivateLoseDialog(activity: Activity?, title: String?, content: String?, listener: MessageListener) {
        DialogUIUtils.showAlert(activity, title, content, "", "", "确定", "输入激活码", false, false, false, object : DialogUIListener() {
            override fun onPositive() {
                listener.onPositive()
            }

            override fun onNegative() {
                listener.onNegative()
            }
        }).show()
    }

    fun showPwdDialog(activity: Activity?, title: String?, listener: PwdListener) {
        val buildBean = DialogUIUtils.showAlertPassword(activity, title, "", "", "", "确定", "取消", false, false, false, object : DialogUIListener() {
            override fun onPositive(view: View) {
                listener.onPositive(view)
            }

            override fun onPositive() {}
            override fun onNegative() {
                listener.onNegative()
            }
        })
        buildBean.show()
    }

    interface MessageListener {
        fun onPositive()
        fun onNegative()
    }

    interface PwdListener {
        fun onPositive(view: View?)
        fun onNegative()
    }
}