package com.ym.piggybank.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ym.ddhy.R
import com.ym.library.module.PuzzleEntity
import com.ym.modulecommon.AppliContext
import com.ym.modulecommon.base.BaseRecyclerAdapter


class PuzzleTopAdapter:
    BaseRecyclerAdapter<PuzzleEntity.PuzzleData, RecyclerView.ViewHolder>() {




    override fun getItemId(position: Int): Long {
        return position?.toLong()
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, p1: Int) {
        if (holder is ViewHolder) {

            val entity = mList[p1]

            if (entity != null) {
                when(entity.index){
                    1->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_one_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_one_gray)
                        }
                    }
                    2->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_two_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_two_gray)
                        }
                    }
                    3->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_three_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_three_gray)
                        }
                    }
                    4->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_four_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_four_gray)
                        }
                    }
                    5->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_five_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_five_gray)
                        }
                    }
                    6->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_six_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_six_gray)
                        }
                    }
                    7->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_seven_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_seven_gray)
                        }
                    }
                    8->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_eight_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_eight_gray)
                        }
                    }
                    9->{
                        if(entity.number>0){
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_nine_light)
                        }else{
                            holder.tvnum.setBackgroundResource(R.drawable.icon_img_nine_gray)
                        }
                    }
                }

            }

        }
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return ViewHolder(
            LayoutInflater.from(AppliContext.get())
                .inflate(R.layout.layout_item_top_pizzle, parent, false)
        )

    }

    inner class ViewHolder : RecyclerView.ViewHolder {

      val tvnum: TextView

        constructor(itemView: View) : super(itemView) {

            tvnum = itemView.findViewById(R.id.id_tv_item)

        }
    }

}
