package com.remax.visualnovel.ui.main.actor


import com.bumptech.glide.Glide
import com.chad.library.adapter.base.module.LoadMoreModule
import com.remax.visualnovel.R
import com.remax.visualnovel.app.BaseBindingQuickAdapter
import com.remax.visualnovel.databinding.FragmentMainActorItemBinding
import com.remax.visualnovel.entity.response.ActorBean
import com.remax.visualnovel.extension.glide.load
import com.remax.visualnovel.ui.chat.ChatActivity
import com.remax.visualnovel.utils.ResUtil
import com.remax.visualnovel.widget.glidetransformation.DiffCornersTransformation

class ActorsAdapter : BaseBindingQuickAdapter<ActorBean, FragmentMainActorItemBinding>(FragmentMainActorItemBinding::inflate), LoadMoreModule {
    init {
        setOnItemClickListener { _, _, position ->
            val item = getItem(position)
            ChatActivity.start(item.id)
        }

        addChildClickViewIds(R.id.top_container_left_top)
        setOnItemChildClickListener { _, _, position ->
            val item = getItem(position)
            ChatActivity.start(item.id)
        }
    }


    override fun convert(holder: BaseBindingHolder, item: ActorBean) {
        holder.getViewBinding<FragmentMainActorItemBinding>().run {
            var imgUrl = item.coverImage
            var validUrl = if (imgUrl.contains(".png")) imgUrl.substring(0, imgUrl.indexOf(".png") + 4) else imgUrl

            var radius: Float = ResUtil.getPixelSize(R.dimen.dp_25).toFloat()
            Glide.with(context)
                .load(validUrl)
                .transform(DiffCornersTransformation(0f, radius, radius, radius))
                .into(ivCharacter);

            ivFrom.setImageResource(R.mipmap.icon_search_on)
            tvScore.text = item.commonCount.toString()
            tvFrom.text = item.sourceId.toString()

            /*tvFrom.text = item.from
            tvScore.text = "%.1f".format(item.rating)
            tvChapterNum.text = "${item.characterName}·${item.age}"
            tvLables.text = item.tags.toString()
            tvDescription.text = item.description
            tvLast.text = "[${item.workTitle}]"*/
        }
    }
}