package com.test.basd.onecleanmaster.view

import android.view.Gravity
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updatePadding
import com.blankj.utilcode.util.BarUtils
import com.test.basd.onecleanmaster.databinding.DialogBottomLayoutFileBinding

class PermissionPopWindow(private val activity: AppCompatActivity, val onClick: () -> Unit) :
    PopupWindow() {

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

        isOutsideTouchable = false
        isFocusable = true
        isClippingEnabled = false
    }

    private val binding by lazy {
        DialogBottomLayoutFileBinding.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.BOTTOM, 0, 100)
        }
        binding.idLottieFullFile.imageAssetsFolder = "onecle_quanxian_guide/images/"
        binding.idLottieFullFile.setAnimation("onecle_quanxian_guide/data.json")
        binding.idLottieFullFile.playAnimation()
        binding.idFrameLayout.setOnClickListener {
            dismiss()
            onClick.invoke()
        }
        binding.idLlContent.setOnClickListener {
            dismiss()
            onClick.invoke()
        }

    }


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