package com.tgv.malware.ui.malware

import android.app.Activity
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import androidx.constraintlayout.widget.ConstraintLayout
import com.tgv.malware.R
import com.tgv.malware.business.ads.AdsMgr
import com.tgv.malware.databinding.DialogErrBinding

class ErrorScanDialog(
    val activity: Activity
) {
    val dialog = AlertDialog.Builder(activity).create()
    val binding = DialogErrBinding.inflate(LayoutInflater.from(activity))

    var action: (() -> Unit)? = null

    fun showDialog() {
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(false)
        dialog.show()

        val params = dialog.window?.attributes
//        params?.width = ConstraintLayout.LayoutParams.MATCH_PARENT
        params?.width = activity.resources.getDimensionPixelSize(R.dimen.dp_295)
        params?.height = ConstraintLayout.LayoutParams.WRAP_CONTENT
//        params?.gravity = Gravity.BOTTOM
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_native_custom)
        binding.tvSure.setOnClickListener {
            dialog.dismiss()
            action?.invoke()
        }
    }
}