package com.base.scanqrclear.ui.widget

import android.app.Activity
import android.app.AlertDialog
import android.view.Gravity
import android.view.LayoutInflater
import com.base.scanqrclear.BuildConfig
import com.base.scanqrclear.R
import com.base.scanqrclear.ads.AdsMgr
import com.base.scanqrclear.databinding.DialogAppExitBinding
import kotlin.system.exitProcess

object AppExitDialog {

    fun Activity.showAppExitDialog() {

        val dialog = AlertDialog.Builder(this).create()
        val binding = DialogAppExitBinding.inflate(LayoutInflater.from(this))
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(false)

        dialog.show()

        val params = dialog.window?.attributes
//        params?.width = resources.getDimensionPixelOffset(R.dimen.dp_320)
//        params?.height = resources.getDimensionPixelOffset(R.dimen.dp_400)
        params?.gravity = Gravity.CENTER
//        params?.y = 50

        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_app_exit)
        binding.tvYes.setOnClickListener {
            dialog.dismiss()
            if (BuildConfig.DEBUG) exitProcess(0) else finish()
        }
        binding.tvNo.setOnClickListener {
            dialog.dismiss()
        }

    }
}