package com.simplecleaner.app.ui.dialog

import android.app.Activity
import android.app.AlertDialog
import android.view.LayoutInflater
import com.simplecleaner.app.databinding.DialogBatteryUseBinding


class BatteryUseDialog(
    activity: Activity
) {

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

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

    fun showDialog(
        dl: Int = 0,
    ) {
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(true)

        val params = dialog.window?.attributes
//        params?.width = activity.resources.getDimensionPixelSize(R.dimen.dp_300)
//        params?.width = FrameLayout.LayoutParams.WRAP_CONTENT
//        params?.height = FrameLayout.LayoutParams.WRAP_CONTENT
//        params?.gravity = Gravity.CENTER
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)


        dialog.show()

        binding.idLottie.setAnimation("scan/battery_info.json")
        binding.idLottie.playAnimation()
        binding.idTv01.text = "${dl}%"

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