package com.khmer9.yuki.screen.report.resultStatement

import android.annotation.SuppressLint
import android.graphics.Color
import android.graphics.Typeface
import android.view.View
import android.widget.TextView
import com.gdtlib.lib.adapter.BaseListItem
import com.gdtlib.lib.viewholder.BaseListViewHolder
import com.khmer9.yuki.R
import com.khmer9.yuki.remote.StatementResult

class ReportResultViewHolder(itemView: View, private val printButtonListener: ((String, String, String, String, String, String) -> Unit)? = null) : BaseListViewHolder(itemView) {
    @SuppressLint("SetTextI18n")
    override fun bindView(item: BaseListItem) {
        val tvId = itemView.findViewById<TextView>(R.id.tv_id)
        val tvResult = itemView.findViewById<TextView>(R.id.tv_result)
        val tvOverUnder = itemView.findViewById<TextView>(R.id.tv_over_under)
        val tvRange = itemView.findViewById<TextView>(R.id.tv_range)

        if (item is StatementResult) {
            try {
                val gameNo = item.date.split(" ")[0] + "#" + item.no
                tvId.text = gameNo
            } catch (err: Exception) {
                tvId.text = item.no.toString()
            }

            //Result and Range
            tvResult.text = item.resultYear.name
            tvRange.text = item.resultRange.name
            tvOverUnder.text = item.smallLarge.name

            tvResult.setTypeface(null, Typeface.BOLD)
            tvRange.setTypeface(null, Typeface.BOLD)
            tvOverUnder.setTypeface(null, Typeface.BOLD)

            when (item.resultRange.name) {
                "1-2-3" -> {
                    tvRange.setTextColor(Color.BLUE)
                    tvResult.setTextColor(Color.BLUE)
                    tvOverUnder.setTextColor(Color.BLUE)
                }
                "4-5-6" -> {
                    tvRange.setTextColor(Color.BLUE)
                    tvResult.setTextColor(Color.BLUE)
                    tvOverUnder.setTextColor(Color.BLUE)
                }
                "7-8-9" -> {
                    tvRange.setTextColor(Color.RED)
                    tvResult.setTextColor(Color.RED)
                    tvOverUnder.setTextColor(Color.RED)
                }
                "10-11-12" -> {
                    tvRange.setTextColor(Color.RED)
                    tvResult.setTextColor(Color.RED)
                    tvOverUnder.setTextColor(Color.RED)
                }
            }

        }
    }
}