package harrowingic.entitledic
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import tooic.fatalityic.corroborateic.breakfastic.moleculeic.Gayic
import tooic.fatalityic.corroborateic.breakfastic.moleculeic.Gayic.Companion.POPUP_WHERE_LOCK
import tooic.fatalityic.corroborateic.indexic.Friendlinessic.Companion.popupConfigBean
import upkeepic.Explanationic
import java.util.Objects

class Dissociateic : BroadcastReceiver() {


    override fun onReceive(context: Context, intent: Intent) {
        val action = intent.action
        when (Objects.requireNonNull<String?>(action)) {
            Intent.ACTION_SCREEN_ON -> isDeviceInteractive = true
            Intent.ACTION_SCREEN_OFF -> {
                isDeviceInteractive = false
                isSecureLockActive = true
            }

            Intent.ACTION_USER_PRESENT -> {
                isSecureLockActive = false
                if (isDeviceInteractive && !isSecureLockActive) {
                    if (popupConfigBean.screenS) {
                        Explanationic.submitSendBean(Gayic(context, POPUP_WHERE_LOCK))
                    }
                }
            }
        }
    }


    companion object {
        private val TAG = "ScreenStatusReceiver"

        var isDeviceInteractive: Boolean = true
        var isSecureLockActive: Boolean = false

        fun registerScreenStatusReceiver(context: Context) {
            val intentFilter = IntentFilter()
            intentFilter.addAction(Intent.ACTION_SCREEN_OFF)
            intentFilter.addAction(Intent.ACTION_SCREEN_ON)
            intentFilter.addAction(Intent.ACTION_USER_PRESENT)

            val applicationContext = context.applicationContext
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                applicationContext.registerReceiver(Dissociateic(), intentFilter, Context.RECEIVER_EXPORTED)
            } else {
                applicationContext.registerReceiver(Dissociateic(), intentFilter)
            }
        }

    }
}