package com.adealink.weparty.setting.helpcenter.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.util.onClick
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.setting.databinding.ItemSettingHelpPictureBinding
import com.adealink.weparty.setting.helpcenter.data.PictureItemData


class PictureItemViewBinder(
    val lifecycleOwner: LifecycleOwner,
    val onItemClick: (item: PictureItemData) -> Unit,
    val onDeleteClick: (item: PictureItemData) -> Unit
) :
    ItemViewBinder<PictureItemData, BindingViewHolder<ItemSettingHelpPictureBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemSettingHelpPictureBinding>,
        item: PictureItemData,
    ) {
        holder.binding.root.onClick {
            onItemClick.invoke(item)
        }
        holder.binding.ivDelete.onClick {
            onDeleteClick.invoke(item)
        }
        holder.binding.ivPicture.setImageURI(item.data.uri)
        holder.binding.vUploadProgress.observeProgress(lifecycleOwner, item.data.mediaUpload)
    }

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