package com.sambath.sbc.util;

import android.content.Context
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.AppCompatTextView
import com.sambath.sbc.R

class ConfirmDialog {

    companion object {
        fun create(
            context: Context,
            title: String? = null,
            message: String? = null,
            onConfirm: (() -> Unit)? = null
        ): AlertDialog {
            val builder = AlertDialog.Builder(context)
            val view =
                LayoutInflater.from(context)
                    .inflate(R.layout.dialog_yearly_tax_confirm, null, false)

            val btnConfirm = view.findViewById<AppCompatButton>(R.id.btn_confirm)
            val btnCancel = view.findViewById<AppCompatButton>(R.id.btn_cancel)

            title?.let {
                val tvTitle = view.findViewById<AppCompatTextView>(R.id.tv_title)
                tvTitle.text = it
            }
            message?.let {
                val tvMessage = view.findViewById<AppCompatTextView>(R.id.tv_message)
                tvMessage.text = it
            }

            builder.setView(view)
            val dialog = builder.create()

            btnCancel.setOnClickListener {
                dialog.dismiss()
            }
            btnConfirm.setOnClickListener {
                onConfirm?.invoke()
                dialog.dismiss()
            }

            dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
            return dialog
        }
    }

}