package com.bc_chat.circle.adapetr

import android.content.Context
import com.bc_chat.bc_base.entity.contact.Comment
import com.bc_chat.bc_base.utils.AppConfig
import com.bc_chat.bc_base.utils.Const
import com.bc_chat.bc_base.utils.gone
import com.bc_chat.bc_base.utils.visible
import com.bc_chat.contacts.R
import com.bc_chat.contacts.databinding.ItemChildCommentBinding
import com.bc_chat.contacts.view.CommentView
import com.zhaohaoting.framework.abs.adapter.ListToAdapter


/**
 * author：Created by zhaohaoting on 2019/8/28
 * email：526309416@qq.com
 * desc：
 */
class ChildeCommentAdapter(context: Context) : ListToAdapter<Comment, List<Comment>>(context) {

    override fun getItemLayoutId(type: Int): Int = R.layout.item_child_comment

    override fun onBindViewHolderHF(baseViewHolder: BaseViewHolder<*>?, realPosition: Int, data: Comment?) {
        val binding = baseViewHolder?.dataBinding as ItemChildCommentBinding
        if (data?.type == 2) {
            binding.name.text = "%s 回复 %s：".format(data?.nickname, data?.parent_nickname)
        } else {
            binding.name.text = "%s：".format(data?.nickname)
        }
        binding.content.text = data?.content
//        if (data?.uid.equals(AppConfig.instance.getUser().userId) || AppConfig.instance.getUser().userId.equals(Const.ADMIN_ID)) {
//            binding.tvDelete.visible()
//        } else {
//            binding.tvDelete.gone()
//        }
        binding.content.setOnLongClickListener {
            if (data?.uid.equals(AppConfig.instance.getUser().userId) || AppConfig.instance.getUser().userId.equals(Const.ADMIN_ID)) {
                childRefreshListener?.deleteChildItemClik(realPosition)
            }
            return@setOnLongClickListener false
        }
        binding.content.setOnClickListener {
            onItemClickListener?.onItemClick(baseViewHolder,realPosition)
        }
//        binding.tvDelete.setOnClickListener {
//            childRefreshListener?.deleteChildItemClik(realPosition)
//        }
    }

    fun setChildRefreshListener(childRefreshListener: CommentView.ChildRefreshListener) {
        this.childRefreshListener = childRefreshListener
    }

    private var childRefreshListener: CommentView.ChildRefreshListener? = null
}