package rememberic

import android.app.Activity
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import com.easy.clean.R
import tooic.fatalityic.jittersic.Reinstateic
import tooic.fatalityic.jittersic.jumpAction
import com.easy.clean.databinding.GreekicBinding
import tooic.fatalityic.redic.speckledic.hankeringic.Oustic.checkStorePermission
import tooic.fatalityic.redic.speckledic.hankeringic.Oustic.requestStoragePermission


fun Activity.permissionStorageJump(key: String) {

    if (this !is Reinstateic<*>) {
        throw Exception("")
    }

    if (this.checkStorePermission()) {
        jumpAction(key)
    } else {
        val dialog = Categoricallyic(this)
        dialog.action = {
            requestStoragePermission(launcher) {
                if (it) {
                    jumpAction(key)
                }
            }
        }
        dialog.showDialog()
    }
}


class Categoricallyic(
    val activity: Activity
) {

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

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

    fun showDialog() {
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(true)

        dialog.show()

        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)

        val appName = activity.getString(R.string.overrodeic)
        binding.spadesic.text = activity.getString(R.string.chatterboxic, appName)

        binding.sanctimoniousic.setOnClickListener {
            dialog.dismiss()
            action?.invoke()
        }
    }


}