package com.base.appzxhy.ui.adapter

import android.content.Context
import android.view.ViewGroup
import com.base.appzxhy.R
import com.base.appzxhy.databinding.ItemShortplayStyle4Binding
import com.base.appzxhy.utils.XmlEx.inflate
import com.bumptech.glide.Glide
import com.bytedance.sdk.shortplay.api.ShortPlay
import com.chad.library.adapter4.BaseQuickAdapter

class ShortPlayAdapter(
    val layout: Int
) : BaseQuickAdapter<ShortPlay, CommonViewHolder>() {

    var itemClick: ((shortList: ShortPlay) -> Unit)? = null

    override fun onBindViewHolder(holder: CommonViewHolder, position: Int, item: ShortPlay?) {
        item ?: return
        val context = holder.itemView.context
        when (layout) {
            R.layout.item_shortplay_style_4 -> {
                val binding = ItemShortplayStyle4Binding.bind(holder.itemView)
                Glide.with(context).load(item.coverImage).into(binding.iv)
                binding.tvName.text = item.title
                binding.root.setOnClickListener {
                    itemClick?.invoke(item)
                }
            }
        }
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): CommonViewHolder {
        return CommonViewHolder(layout.inflate(parent))
    }
}