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


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.ui.chat.ChatActivity

class ActorsAdapter : BaseBindingQuickAdapter<ActorItem, 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: ActorItem) {
        holder.getViewBinding<FragmentMainActorItemBinding>().run {
            ivCharacter.setImageResource(item.imageRes)
            ivFrom.setImageResource(item.avatarRes)

            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}]"
        }
    }
}