package com.gh.gamecenter.common.utils

import android.app.Dialog
import android.content.Context
import androidx.core.content.ContextCompat
import android.view.Window
import android.widget.LinearLayout
import android.widget.TextView
import com.gh.gamecenter.common.R
import com.gh.gamecenter.core.utils.DisplayUtils

object OptionDialogHelper {

    fun showOptionDialog(context: Context, typeList: List<String>, callback: (String) -> Unit) {
        val dialog = Dialog(context)
        val container = LinearLayout(context)
        container.orientation = LinearLayout.VERTICAL
        container.setBackgroundColor(R.color.background_white.toColor(context))
        container.setPadding(0, DisplayUtils.dip2px(context, 12f), 0, DisplayUtils.dip2px(context, 12f))

        for (type in typeList) {
            val reportTv = TextView(context)
            reportTv.text = type
            reportTv.textSize = 17f
            reportTv.setTextColor(ContextCompat.getColor(context, R.color.title))
            reportTv.setBackgroundResource(R.drawable.textview_white_style)
            val widthPixels = context.resources.displayMetrics.widthPixels
            reportTv.layoutParams = LinearLayout.LayoutParams(
                widthPixels * 9 / 10,
                LinearLayout.LayoutParams.WRAP_CONTENT
            )
            reportTv.setPadding(
                DisplayUtils.dip2px(context, 20f), DisplayUtils.dip2px(context, 12f),
                0, DisplayUtils.dip2px(context, 12f)
            )
            container.addView(reportTv)

            reportTv.setOnClickListener {
                callback.invoke(reportTv.text.toString())
                dialog.cancel()
            }
        }

        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
        dialog.setContentView(container)
        dialog.show()
    }
}