package com.base.appzxhy.ui.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.base.appzxhy.R
import com.base.appzxhy.bean.ShortPlayEPBean
import com.base.appzxhy.databinding.ItemEpBinding
import com.base.appzxhy.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class EPAdapter : BaseQuickAdapter<ShortPlayEPBean, CommonViewHolder>() {

    var selectEp: ((ep: Int, lock: Boolean) -> Unit)? = null

    override fun onBindViewHolder(holder: CommonViewHolder, position: Int, item: ShortPlayEPBean?) {
        item ?: return
        val context = holder.itemView.context
        val binding = ItemEpBinding.bind(holder.itemView)
        if (item.isPlaying) {
            binding.ivLock.visibility = View.GONE
            binding.tvEP.visibility = View.GONE
            binding.ivPlay.visibility = View.VISIBLE
        } else {
            binding.ivPlay.visibility = View.GONE
            binding.ivLock.isVisible = item.lock
            binding.tvEP.visibility = View.VISIBLE
            binding.tvEP.text = item.ep.toString()
        }
        binding.root.setOnClickListener {
            selectEp?.invoke(item.ep, item.lock)
        }
    }

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