package com.base.browserwhite.ui.activity.bookmark

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.R
import com.base.browserwhite.databinding.ItemBookmarkFolderBinding
import com.base.browserwhite.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class BookmarkFolderAdapter(
    val selectFolder: String,
    val clickAction: (folder: String) -> Unit
) : BaseQuickAdapter<String, BookmarkFolderAdapter.BookmarkFolderViewHolder>() {

    inner class BookmarkFolderViewHolder(view: View) : ViewHolder(view)

    override fun onBindViewHolder(holder: BookmarkFolderViewHolder, position: Int, item: String?) {
        if (item == null) return

        val binding = ItemBookmarkFolderBinding.bind(holder.itemView)
        binding.tvName.text = item
        binding.ivSelector.isSelected = item == selectFolder
        binding.root.setOnClickListener {
            clickAction.invoke(item)
        }
    }

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