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.R
import com.base.appzxhy.databinding.DialogNotificationBinding
import com.google.android.material.bottomsheet.BottomSheetDialog


class NotificationTurnOnDialog(
    val activity: Activity
) {

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

    //    val dialog = BottomSheetDialog(activity, R.style.BottomSheetDialog)
    val binding = DialogNotificationBinding.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.tvTurnOn.setOnClickListener {
            dialog.dismiss()
            action?.invoke()
        }
    }
}