package kr.co.vividnext.sodalive.explorer.profile.creator_community.all

import android.annotation.SuppressLint
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.DialogPurchaseCommunityPostBinding
import kr.co.vividnext.sodalive.extensions.dpToPx
import kr.co.vividnext.sodalive.extensions.moneyFormat

@SuppressLint("SetTextI18n")
class PurchaseCommunityPostDialog(
    activity: Activity,
    layoutInflater: LayoutInflater,
    can: Int,
    confirmButtonClick: () -> Unit,
) {

    private val alertDialog: AlertDialog
    val dialogView = DialogPurchaseCommunityPostBinding.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.tvCan.text = "${can.moneyFormat()}캔으로 보기"
        dialogView.tvCan.setOnClickListener {
            alertDialog.dismiss()
            confirmButtonClick()
        }
        dialogView.tvCancel.setOnClickListener { alertDialog.dismiss() }
    }

    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
    }
}
