package com.base.scanqrclear.ui.main

import android.content.Context
import android.view.View
import android.view.ViewGroup
import com.base.scanqrclear.R
import com.base.scanqrclear.bean.FunctionUIBean
import com.base.scanqrclear.databinding.ItemFunctionRvBinding
import com.base.scanqrclear.ui.adapter.CommonViewHolder
import com.base.scanqrclear.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class FunctionRvAdapter : BaseQuickAdapter<List<FunctionUIBean>, CommonViewHolder>() {

    var itemClick: ((key: String) -> Unit)? = null

    var functionAdapter: FunctionAdapter? = null

    var tittle: String? = null

    override fun onBindViewHolder(holder: CommonViewHolder, position: Int, item: List<FunctionUIBean>?) {
        item ?: return
        val binding = ItemFunctionRvBinding.bind(holder.itemView)
        if (tittle == null) {
            binding.tvTitle.visibility = View.GONE
        } else {
            binding.tvTitle.visibility = View.VISIBLE
            binding.tvTitle.text = tittle
        }

        val adapter = FunctionAdapter()
        adapter.itemClick = itemClick
        binding.rv.adapter = adapter
        adapter.submitList(item)
        functionAdapter = adapter
    }

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

    }


}