package com.base.appzxhy.ui.dialog

import android.app.Activity
import android.app.Dialog
import android.view.Gravity
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatDialog
import com.applovin.impl.cl
import com.base.appzxhy.R
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.databinding.DialogExitBinding

class ExitDialog(val activity: Activity) {

    val dialog = AppCompatDialog(activity)
    val bind = DialogExitBinding.inflate(activity.layoutInflater)
    var exit: (() -> Unit)? = null
    var clean: (() -> Unit)? = null
    var ad: (() -> Unit)? = null

    fun init() {
        dialog.setContentView(bind.root)
        dialog.setCanceledOnTouchOutside(true)
        val params = dialog.window?.attributes
        dialog.window?.attributes = params
        params?.width = LinearLayout.LayoutParams.MATCH_PARENT
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
        initView()
    }

    private fun initView() {
        bind.ivClose.setOnClickListener {
            dialog.dismiss()
        }
        bind.tvExit.setOnClickListener {
            dialog.dismiss()
            activity.finish()
        }
        bind.tvClean.setOnClickListener {
            dialog.dismiss()
            clean?.invoke()
        }

    }

    fun show() {
        dialog.show()
        AdsMgr.showNative(bind.flAd, R.layout.layout_admob_native_custom_r16)
    }

    fun hide() {
        dialog.hide()
    }
}