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

import android.graphics.Color
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.remote.*

class TodayReportListViewHolder(
    itemView: View
) : BaseListViewHolder(itemView) {
    override fun bindView(item: BaseListItem) {
        when (item) {
            is TodayData -> {
                val txtFightNo: TextView = itemView.findViewById(R.id.txt_fight_bet)
                val txtType: TextView = itemView.findViewById(R.id.txt_type)
                val txtResult: TextView = itemView.findViewById(R.id.txt_result)
                val txtTime: TextView = itemView.findViewById(R.id.txt_time)
                val fightNo = "#" + item.fightNo.toString()
                txtFightNo.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
                            )
                        )
                    }
                }
                when (item.isWin) {
                    true -> {
                        val result = "" + item.amount
                        txtResult.text = result
                        when (type) {
                           /* K.Meron -> {
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.meron
                                    )
                                )
                            }
                            K.Wala -> {
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.wala
                                    )
                                )
                            }*/
                            K.Tie -> {
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.draw
                                    )
                                )
                            }
                            K.Cancel -> {
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.cancel
                                    )
                                )
                            }
                        }
                        txtFightNo.setTextColor(Color.WHITE)
                        txtTime.setTextColor(Color.WHITE)
                    }
                    false -> {
                        val result = "lose: (" + item.amount + ")"
                        txtResult.text = result
                        txtResult.setTextColor(Color.RED)
                        txtFightNo.setTextColor(Color.RED)
                        txtTime.setTextColor(Color.RED)
                    }
                    else -> {
                        txtFightNo.setTextColor(Color.WHITE)
                        txtTime.setTextColor(Color.WHITE)
//                        if (item.typeBetting == "red") {
//                            txtResult.setTextColor(ContextCompat.getColor(itemView.context, R.color.meron))
//                        } else {
//                            txtResult.setTextColor(ContextCompat.getColor(itemView.context, R.color.wala))
//                        }
                        var resultTxt = ""
                        when (item.resultName) {
                            K.Cancel -> {
                                resultTxt = "cancel ( " + item.amount + " )"
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.cancel
                                    )
                                )
                            }
                            K.Tie -> {
                                resultTxt = "Tie ( " + item.amount + " )"
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.draw
                                    )
                                )
                            }
                            else -> {
                                resultTxt = "" + item.amount
                                txtResult.setTextColor(
                                    ContextCompat.getColor(
                                        itemView.context,
                                        R.color.color_white
                                    )
                                )
                            }
                        }
                        txtResult.text = resultTxt
                    }
                }
            }
        }
    }
}