package com.sambath.klaklouk_main.screen.main.cflive.currentbets

import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.gdtlib.lib.adapter.BaseListItem
import com.gdtlib.lib.viewholder.BaseListViewHolder
import com.sambath.klaklouk_main.R
import com.sambath.klaklouk_main.extension.btnClick
import com.sambath.klaklouk_main.extension.setSafeOnClickListener
import com.sambath.klaklouk_main.remote.CurrentBetItem
import com.sambath.klaklouk_main.remote.K

class CurrentBetsListViewHolder(
    itemView: View,
    private val printButtonListener: ((String, String, String, String, String, String, String) -> Unit)? = null
) : BaseListViewHolder(itemView) {
    override fun bindView(item: BaseListItem) {
        when (item) {
            is CurrentBetItem -> {
                val txtFightBet: TextView = itemView.findViewById(R.id.txt_fight_no)
                val txtType: TextView = itemView.findViewById(R.id.txt_type)
                val txtAmount: TextView = itemView.findViewById(R.id.txt_amount)
                val txtTime: TextView = itemView.findViewById(R.id.txt_time)
                val txtPrint: TextView = itemView.findViewById(R.id.txt_print)
                val fightNo = "#" + item.fightNo.toString()
                txtFightBet.text = fightNo
                var type = item.betting
                when (type) {
                    /*K.Meron -> {
                        txtType.setTextColor(ContextCompat.getColor(itemView.context, R.color.meron))
                    }
                    K.Wala -> {
                        txtType.setTextColor(ContextCompat.getColor(itemView.context, R.color.wala))
                    }*/
                    K.Tie -> {
                        txtType.setTextColor(ContextCompat.getColor(itemView.context, R.color.draw))
                    }
                    K.Cancel -> {
                        txtType.setTextColor(ContextCompat.getColor(itemView.context, R.color.cancel))
                    }
                }
                txtType.text = type
                txtAmount.text = item.amount
                txtTime.text = item.time
                txtPrint.setSafeOnClickListener {
//                    Log.d("currentBet", item.toString())
                    it.btnClick().subscribe {
                        printButtonListener?.invoke(
                            item.fightNo.toString(),
                            item.time,
                            type,
                            item.amount.toString(),
                            item.amount.toString(),
                            item.amount,
                            item._id
                        )
                    }
                }
            }
        }
    }
}