package com.base.scanqrclear.ui.whatsappqr

import android.annotation.SuppressLint
import android.content.Context
import android.view.ViewGroup
import com.base.scanqrclear.R
import com.base.scanqrclear.bean.AreaCodeBean
import com.base.scanqrclear.databinding.ItemAreCodeBinding
import com.base.scanqrclear.ui.adapter.CommonViewHolder
import com.base.scanqrclear.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class AreCodeAdapter : BaseQuickAdapter<AreaCodeBean, CommonViewHolder>() {

    var itemClick: ((item: AreaCodeBean) -> Unit)? = null

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: CommonViewHolder, position: Int, item: AreaCodeBean?) {
        item ?: return
        val binding = ItemAreCodeBinding.bind(holder.itemView)
        binding.tvCode.text = "${item.code}   ${item.area}"
        binding.root.setOnClickListener {
            itemClick?.invoke(item)
        }
    }

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