package kr.co.vividnext.sodalive.report

import android.app.Activity
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import kr.co.vividnext.sodalive.databinding.DialogProfileReportBinding
import kr.co.vividnext.sodalive.extensions.dpToPx

class ProfileReportDialog(
    activity: Activity,
    layoutInflater: LayoutInflater,
    confirmButtonClick: () -> Unit
) {

    private val alertDialog: AlertDialog

    val dialogView = DialogProfileReportBinding.inflate(layoutInflater)

    init {
        val dialogBuilder = AlertDialog.Builder(activity)
        dialogBuilder.setView(dialogView.root)

        alertDialog = dialogBuilder.create()
        alertDialog.setCancelable(false)
        alertDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

        dialogView.tvCancel.setOnClickListener {
            alertDialog.dismiss()
        }

        dialogView.tvReport.setOnClickListener {
            alertDialog.dismiss()
            confirmButtonClick()
        }
    }

    fun show(width: Int) {
        alertDialog.show()

        val lp = WindowManager.LayoutParams()
        lp.copyFrom(alertDialog.window?.attributes)
        lp.width = width - (26.7f.dpToPx()).toInt()
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT

        alertDialog.window?.attributes = lp
    }
}
