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.Adapter
import android.widget.ImageView
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.cms.widget.BlurTransformation
import com.zxhl.cms.widget.CircleImageView
import com.zxhl.cms.widget.RecycleImageView
import com.zxhl.main.R

class LikesAdpater : BaseRecyclerAdapter<FollowEntity, LikesAdpater.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.item_layout_likes, holder, false)
        )
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mList[position]
        holder.id_tv_name.text = data.nickname
        holder.id_tv_price.text="${data.videoPrice}/min"
        holder.id_img_guoqi.setLoadImageUrl("${data.nationalFlag}",false)
        if (!TextUtils.isEmpty(data.headImage)) {
            Glide.with(AppContext.get()).load(data.headImage)
                .into(holder.id_img_likes_head)
        } else {
            holder.id_img_likes_head.setImageResource(R.drawable.icon_user_photo_default)
        }
    }

    inner class ViewHolder : RecyclerView.ViewHolder {


        var id_tv_name: TextView
        var id_tv_price: TextView
        var id_img_guoqi: RecycleImageView
        var id_img_xiaoxi: ImageView
        var id_img_shipin: ImageView
        var id_img_likes_head: CircleImageView

        constructor(itemView: View) : super(itemView) {
            id_img_likes_head = itemView.findViewById(R.id.id_img_likes_head)
            id_img_guoqi = itemView.findViewById(R.id.id_img_guoqi)
            id_img_xiaoxi = itemView.findViewById(R.id.id_img_xiaoxi)
            id_img_shipin = itemView.findViewById(R.id.id_img_shipin)
            id_tv_name = itemView.findViewById(R.id.id_tv_name)
            id_tv_price = itemView.findViewById(R.id.id_tv_price)
            id_img_xiaoxi?.setOnClickListener {
                val pos = adapterPosition
                if (pos >= 0 && pos < mList.size) {
                    listener.onItemClick(it,pos,mList[pos])
                }

            }
            id_img_shipin?.setOnClickListener {
                val pos = adapterPosition
                if (pos >= 0 && pos < mList.size) {
                    listener.onItemClick(it,pos,mList[pos])
                }

            }
        }
    }
}