package com.adealink.weparty.imageselect.view

import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.databinding.ItemImageFolderBinding
import com.adealink.weparty.imageselect.listener.OnOperateListener
import com.adealink.weparty.imageselect.model.LocalMediaFolder

class ImageFolderItemViewBinder(val l: OnOperateListener) :
    ItemViewBinder<LocalMediaFolder, BindingViewHolder<ItemImageFolderBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemImageFolderBinding>,
        item: LocalMediaFolder
    ) {
        val viewBinding = holder.binding
        item.firstImageUri?.let {
            viewBinding.folderIv.setImageUrl(it)
        }
        viewBinding.folderNameTv.text = item.name
        viewBinding.folderImageCountTv.text = "${item.imageNum}"
        viewBinding.root.setOnClickListener {
            l.onSelectFolder(item)
        }
    }

    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup
    ): BindingViewHolder<ItemImageFolderBinding> {
        return BindingViewHolder(ItemImageFolderBinding.inflate(inflater, parent, false))
    }
}