package com.ym.game.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.xynt.R
import com.ym.library.listener.OnRecycleItemClickListener
import com.ym.library.module.PuzzleEntity
import com.ym.modulecommon.AppliContext
import com.ym.modulecommon.base.BaseRecyclerAdapter


class PuzzleBottomAdapter : BaseRecyclerAdapter<PuzzleEntity.PuzzleData, RecyclerView.ViewHolder> {
    var listner: OnRecycleItemClickListener<PuzzleEntity.PuzzleData>?


    constructor(listner: OnRecycleItemClickListener<PuzzleEntity.PuzzleData>?) {
        this.listner = listner

    }

    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) {
                holder.tvnum?.text = entity?.number.toString()
                when (entity.index) {
                    1 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_one_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_one_gray)
                        }
                    }
                    2 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_two_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_two_gray)
                        }
                    }
                    3 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_three_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_three_gray)
                        }
                    }
                    4 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_four_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_four_gray)
                        }
                    }
                    5 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_five_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_five_gray)
                        }
                    }
                    6 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_six_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_six_gray)
                        }
                    }
                    7 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_seven_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_seven_gray)
                        }
                    }
                    8 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_eight_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_eight_gray)
                        }
                    }
                    9 -> {
                        if (entity.number > 0) {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_nine_light)
                        } else {
                            holder.tvbg.setBackgroundResource(R.drawable.icon_bottom_nine_gray)
                        }
                    }
                }

                //  holder.tvallnum.text = entity?.number.toString()

            }

        }
    }

    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_bottom_pizzle, parent, false)
        )

    }

    inner class ViewHolder : RecyclerView.ViewHolder {

        val tvbg: TextView
        val tvnum: TextView


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

            tvbg = itemView.findViewById(R.id.id_tv_bottom_bg)
            tvnum = itemView.findViewById(R.id.id_tv_number)
            tvbg.setOnClickListener {
                val pos = adapterPosition
                if (pos >= 0 && pos < mList.size) {
                    listner?.onItemClick(it, pos, mList[pos])
//                    val entity = mList[pos]
//                    if (entity.number > 0) {
//
//                    } else {
//                        Utils.showToast(AppliContext.get(), "看视频")
//                    }

                }
            }
        }
    }


}

