package com.sambath.sbc.screen.report

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.sbc.R
import com.sambath.sbc.remote.CfStatement
import java.text.DecimalFormat

class StatementListViewHolder(
    itemView: View
) : BaseListViewHolder(itemView) {
    fun currencyFormat(amount: Int): String? {
        val formatter = DecimalFormat("#,###")
        return formatter.format(amount)
    }
    override fun bindView(item: BaseListItem) {
        when (item) {
            is CfStatement -> {
//                val txtNO: TextView = itemView.findViewById(R.id.txt_no)
                val txtDate: TextView = itemView.findViewById(R.id.txt_date)
                val txtRemark: TextView = itemView.findViewById(R.id.txt_remark)
                val txtTrunOver: TextView = itemView.findViewById(R.id.txt_trun_over)
                val txtAmount: TextView = itemView.findViewById(R.id.txt_amount)
                val txtAmountWin: TextView = itemView.findViewById(R.id.txt_amount_win)

//                txtNO.text = adapterPosition.plus(1).toString() Deposite  Withdraw
                txtDate.text = item.date
                txtRemark.text = item.note.toString()
                when (item.note) {
                    "Deposite" -> {
                        txtRemark.setTextColor(ContextCompat.getColor(itemView.context, R.color.color_blue_800))
                    }
                    "Withdraw" -> {
                        txtRemark.setTextColor(ContextCompat.getColor(itemView.context, R.color.color_red_800))
                    }
                    else -> {
                        txtRemark.setTextColor(Color.WHITE)
                    }
                }
                txtTrunOver.text = item.trunOver?.let { currencyFormat(it) }
                if(item.trunOver!! > 0){
                    txtTrunOver.setTextColor(ContextCompat.getColor(itemView.context, R.color.wala))
                }else{
                    txtTrunOver.setTextColor(Color.WHITE)
                }
                txtAmount.text = item.amount?.let { currencyFormat(it) }
                txtAmount.setTextColor(ContextCompat.getColor(itemView.context, R.color.blue_green))
                txtAmountWin.text = item.amountWin?.let { currencyFormat(it) }
                when {
                    item.amountWin!! >0 -> {
                        txtAmountWin.setTextColor(ContextCompat.getColor(itemView.context, R.color.light_yellow))
                    }
                    item.amountWin < 0 -> {
                        txtAmountWin.setTextColor(ContextCompat.getColor(itemView.context, R.color.meron))
                    }
                    else -> {
                        txtAmountWin.setTextColor(Color.WHITE)
                    }
                }
            }
        }
    }
}