package com.base.datarecovery.view

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import com.base.datarecovery.R
import com.base.datarecovery.databinding.DialogPermissonOpenBinding

object DialogViews {

    @SuppressLint("SetTextI18n")
    fun Context.showGerPermission(
        tittle: String? = null,
        deny: ((view: Dialog) -> Unit)? = null,
        allow: ((view: Dialog) -> Unit)? = null
    ): Dialog {
        val dialog = Dialog(this)
        val binding = DialogPermissonOpenBinding.inflate(LayoutInflater.from(this))
        dialog.requestWindowFeature(1)
        dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog.window!!.setLayout(-1, -1)
        dialog.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        dialog.setContentView(binding.root)
        val str = resources.getString(R.string.app_name)

        tittle?.let { binding.idTvTt.text = it }
        binding.idFullLottie.imageAssetsFolder = "recovery_permission_finger/images/"
        binding.idFullLottie.setAnimation("recovery_permission_finger/data.json")
        binding.idFullLottie.playAnimation()
        binding.idDeny.setOnClickListener {
            dialog.dismiss()
            deny?.invoke(dialog)
        }
        binding.idTvAllow.setOnClickListener {
            dialog.dismiss()
            allow?.invoke(dialog)
        }
        dialog.show()
        return dialog
    }
}
