package com.base.appzxhy.ui.dialog

import android.app.Activity
import android.app.AlertDialog
import android.view.Gravity
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.base.appzxhy.databinding.DialogNotification2Binding


class NotificationTurnOnDialog(
    val activity: Activity
) {

    val dialog = AlertDialog.Builder(activity).create()

    //    val dialog = BottomSheetDialog(activity, R.style.BottomSheetDialog)
    val binding = DialogNotification2Binding.inflate(LayoutInflater.from(activity))

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

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

        dialog.show()


        val params = dialog.window?.attributes
        params?.width = ConstraintLayout.LayoutParams.MATCH_PARENT
//        params?.width = activity.resources.getDimensionPixelSize(R.dimen.dp_295)
        params?.height = ConstraintLayout.LayoutParams.WRAP_CONTENT
        params?.gravity = Gravity.BOTTOM
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        binding.ivClose.setOnClickListener {
            dialog.dismiss()
        }

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