package com.zxhl.main.page.adapter

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.zxhl.cms.AppContext
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.chat.FollowEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.main.R

class BlockAdapter : BaseRecyclerAdapter<FollowEntity, BlockAdapter.ViewHolder> {
    private var mContext: Context? = null
    private val listener: OnRecycleItemClickListener<FollowEntity>

    constructor(
        content: Context?,
        listener: OnRecycleItemClickListener<FollowEntity>
    ) : super() {
        this.listener = listener
        mContext = content
    }

    override fun onCreateViewHolder(holder: ViewGroup, p1: Int): ViewHolder {
        return ViewHolder(
            LayoutInflater.from(holder.context).inflate(R.layout.layout_item_block_list, holder, false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mList[position]
        holder.id_tv_name.text = data.nickname
        if (!TextUtils.isEmpty(data.headImage)) {
            Glide.with(AppContext.get()).load(data.headImage)
                .apply(RequestOptions.bitmapTransform(CircleCrop()))
                .into(holder.id_img_head)
        } else {
            holder.id_img_head.setImageResource(R.drawable.icon_user_photo_default)
        }



    }

    inner class ViewHolder : RecyclerView.ViewHolder {


        var id_tv_name: TextView
        var id_tv_remove_black: TextView
        var id_img_head: ImageView

        constructor(itemView: View) : super(itemView) {
            id_img_head = itemView.findViewById(R.id.id_img_block_head)
            id_tv_name = itemView.findViewById(R.id.id_tv_block_name)
            id_tv_remove_black = itemView.findViewById(R.id.id_tv_remove_black)
            id_tv_remove_black.setOnClickListener {
                val pos = adapterPosition
                if (pos >= 0 && pos < mList.size) {
                    listener.onItemClick(it,pos,mList[pos])
                }
            }
//            id_rl_item.setOnClickListener {
//                val pos = adapterPosition
//                if (pos >= 0 && pos < mList.size) {
//                    listener.onItemClick(it,pos,mList[pos])
//                }
//            }

        }
    }
}