package com.tgv.malware.ui.dialog

import android.app.Activity
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import com.tgv.malware.R
import com.tgv.malware.business.ads.AdsMgr
import com.tgv.malware.databinding.DialogFunctionBackBinding
import com.tgv.malware.ui.batteryinfo.BatteryInfoActivity
import com.tgv.malware.ui.clean.JunkCleanActivity
import com.tgv.malware.ui.largefile.LargeFileCleanActivity
import com.tgv.malware.ui.malware.MalwareCleanActivity
import com.tgv.malware.ui.photocompression.PhotoCompressionActivity
import com.tgv.malware.ui.screenshot.ScreenshotCleanActivity
import com.tgv.malware.ui.similar.SimilarPhotosActivity

class FunctionBackDialog(
    val activity: Activity
) {

    val dialog = AlertDialog.Builder(activity).create()
    val binding = DialogFunctionBackBinding.inflate(LayoutInflater.from(activity))


    fun showDialog(back: () -> Unit) {
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(true)

        val params = dialog.window?.attributes
//        params?.width = LinearLayout.LayoutParams.MATCH_PARENT
//        params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
//        params?.gravity = Gravity.BOTTOM
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        when (activity) {
            is JunkCleanActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_junk_clean)
                binding.tvContent.text = activity.getString(R.string.exit_junk_clean_content)
            }

            is BatteryInfoActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_battery_info)
                binding.tvContent.text = activity.getString(R.string.exit_battery_info_content)
            }

            is LargeFileCleanActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_large_file_clean)
                binding.tvContent.text = activity.getString(R.string.exit_large_file_clean_content)
            }

            is PhotoCompressionActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_photo_compression)
                binding.tvContent.text = activity.getString(R.string.exit_photo_compression_content)
            }

            is ScreenshotCleanActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_screenshot_cleaner)
                binding.tvContent.text = activity.getString(R.string.exit_screenshot_cleaner_content)
            }

            is SimilarPhotosActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_similar_photos)
                binding.tvContent.text = activity.getString(R.string.exit_similar_photos_content)
            }

            is MalwareCleanActivity -> {
                binding.tvTitle.text = activity.getString(R.string.exit_malware_clean)
                binding.tvContent.text = activity.getString(R.string.exit_malware_clean_content)
            }

            else -> {
                back.invoke()
                return
            }
        }
        dialog.show()

        AdsMgr.showNative(binding.flAd, R.layout.layout_admob_native_custom)

        binding.ivCancel.setOnClickListener {
            dialog.dismiss()
        }
        binding.tvCancel.setOnClickListener {
            dialog.dismiss()
        }
        binding.tvSure.setOnClickListener {
            dialog.dismiss()
            back.invoke()
        }
    }
}