package com.base.datarecovery.view

import android.app.Activity
import android.view.Gravity
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.core.view.updatePadding
import com.base.datarecovery.databinding.PopwindowLayoutViewBinding
import com.base.datarecovery.utils.BarUtils


class NotifPermisonPop(private val activity: Activity, val onDismiss: () -> Unit) : PopupWindow() {

    init {
        width = ViewGroup.LayoutParams.MATCH_PARENT
        height = ViewGroup.LayoutParams.MATCH_PARENT

        isOutsideTouchable = false
        isFocusable = true
        isClippingEnabled = false
    }

    private val binding by lazy {
        PopwindowLayoutViewBinding.inflate(activity.layoutInflater)
    }
    fun show() {
        contentView = binding.root
        activity.window.decorView.post {
            binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
            BarUtils.setStatusBarLightMode(activity, false)
            showAtLocation(activity.window.decorView, Gravity.CENTER, 0, 0)
        }
        binding.idImgClose.setOnClickListener {
            dismiss()
        }
        binding.idTvTurn.setOnClickListener {
            onDismiss.invoke()
            dismiss()

        }

    }


    override fun dismiss() {
        super.dismiss()
        BarUtils.setStatusBarLightMode(activity, true)
    }
}