import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ym.library.module.GameDuiHuanShopEntity
import com.ym.modulecommon.base.BaseRecyclerAdapter
import com.ym.xynt.R
import kotlinx.android.synthetic.main.item_order.view.*

class OrderAdapter :
    BaseRecyclerAdapter<GameDuiHuanShopEntity.NeedPlantListBean, RecyclerView.ViewHolder> {

    constructor() : super()

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

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val dishOrder: GameDuiHuanShopEntity.NeedPlantListBean = mList[position]

        setImage(holder?.itemView.id_fruit_image, dishOrder.plantId)
        holder.itemView.progress_with_draw_item.max = dishOrder.targetNum;
        holder.itemView.progress_with_draw_item.progress = dishOrder.currentNum;
        holder.itemView.id_tv_text.text = "${dishOrder.currentNum}/${dishOrder.targetNum}"
//        if (null != dishOrder?.imageUrl) {
//            Glide.with(AppliContext.get()).load(dishOrder?.imageUrl).into(holder?.itemView?.id_iv_image)
//        }
//        holder?.itemView?.id_tv_text?.text = "${dishOrder?.count}/${dishOrder?.countLimit}"
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChangeViewHolder {
        return ChangeViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_order, parent, false)
        )
    }

    inner class ChangeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val id_iv_image: ImageView
        val progress: ProgressBar
        val id_tv_text: TextView

        init {
            id_iv_image = itemView?.findViewById(R.id.id_fruit_image)
            progress = itemView?.findViewById(R.id.progress_with_draw_item)
            id_tv_text = itemView?.findViewById(R.id.id_tv_text)
        }
    }

    fun setImage(img: ImageView?, id: Int) {
        when (id) {
            0 -> {
                img?.setImageResource(R.mipmap.ic_zuanshi)
            }
            1 -> {
                img?.setImageResource(R.mipmap.icon_flower_one)
            }
            2 -> {
                img?.setImageResource(R.mipmap.icon_flower_two)
            }
            3 -> {
                img?.setImageResource(R.mipmap.icon_flower_three)
            }
            4 -> {
                img?.setImageResource(R.mipmap.icon_flower_four)
            }
            5 -> {
                img?.setImageResource(R.mipmap.icon_flower_five)
            }
            6 -> {
                img?.setImageResource(R.mipmap.icon_flower_six)
            }
            7 -> {
                img?.setImageResource(R.mipmap.icon_flower_seven)
            }
            8 -> {
                img?.setImageResource(R.mipmap.icon_flower_eight)
            }
            9 -> {
                img?.setImageResource(R.mipmap.icon_flower_eight)
            }
        }
    }

}
