package com.mints.wisdomclean.ui.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.duben.happyplaylet.R
import com.duben.happyplaylet.mvp.model.VedioBean
import com.duben.library.utils.GlideUtils


class HotStyleAdapter(val context: Context, val dataList: ArrayList<VedioBean>?) :
    RecyclerView.Adapter<HotStyleAdapter.ViewHolder>() {

    lateinit var mOnItemClickListener: OnItemClickListener

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val ivVedioItem: ImageView = view.findViewById(R.id.ivVedioItem)
        val tvVedioItemCount: TextView = view.findViewById(R.id.tvVedioItemCount)
        val tvVedioItemTitle: TextView = view.findViewById(R.id.tvVedioItemTitle)
        val tvVedioItemText: TextView = view.findViewById(R.id.tvVedioItemText)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_hot_style, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val topBean = dataList?.get(position)
        if (topBean != null) {
            holder.tvVedioItemCount.text =
                "${if (topBean.completeStatus == 0) "已完结" else "更新至${topBean.vedioTotal}集"}"
            holder.tvVedioItemTitle.text = "${topBean.title}"
            holder.tvVedioItemText.text = "${topBean.vedioDesc}"
            GlideUtils.loadImageViewGifForCenterCrop(
                context,
                topBean.coverImage,
                holder.ivVedioItem
            )
        }

        holder.itemView.setOnClickListener {
            mOnItemClickListener.onItemClick(position)
        }

        holder.itemView.setTag(position)
    }

    override fun getItemCount(): Int = dataList?.size ?: 0

    interface OnItemClickListener {
        fun onItemClick(position: Int)
    }

    fun setOnItemClickListener(listener: OnItemClickListener) {
        mOnItemClickListener = listener
    }
}