package com.base.appzxhy.ui.dialog

import android.app.Activity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import com.base.appzxhy.R
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.databinding.DialogFunctionBackBinding
import com.base.appzxhy.ui.batteryinfo.BatteryInfoActivity
import com.base.appzxhy.ui.clean.JunkCleanActivity
import com.base.appzxhy.ui.largefile.LargeFileCleanActivity
import com.base.appzxhy.ui.photocompression.PhotoCompressionActivity
import com.base.appzxhy.ui.screenshot.ScreenshotCleanActivity
import com.base.appzxhy.ui.similar.SimilarPhotosActivity
import com.base.appzxhy.ui.videoclean.VideoCleanActivity

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_screenshot_cleaner)
                binding.tvContent.text = activity.getString(R.string.exit_screenshot_cleaner_content)
            }
            is VideoCleanActivity->{
                binding.tvTitle.text = activity.getString(R.string.Exit_Video_Clean)
                binding.tvContent.text = activity.getString(R.string.Exit_Video_Clean_Content)
            }

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

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

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