package com.adealink.weparty.wallet.detail.coin

import android.view.LayoutInflater
import android.view.ViewGroup
import com.adealink.weparty.commonui.ext.dp
import com.adealink.weparty.commonui.recycleview.adapter.BindingViewHolder
import com.adealink.weparty.commonui.recycleview.adapter.multitype.ItemViewBinder
import com.adealink.weparty.wallet.R
import com.adealink.weparty.wallet.databinding.ItemCoinDetailBinding
import com.adealink.weparty.wallet.detail.data.CoinDetailItemData

class CoinDetailItemViewBinder() :
    ItemViewBinder<CoinDetailItemData, BindingViewHolder<ItemCoinDetailBinding>>() {

    override fun onBindViewHolder(
        holder: BindingViewHolder<ItemCoinDetailBinding>,
        item: CoinDetailItemData,
    ) {
        if (holder.layoutPosition == 0) {
            //第一个
            holder.binding.root.setPadding(12.dp(), 10.dp(), 12.dp(), 0)
            holder.binding.root.setBackgroundResource(R.drawable.wallet_detail_item_top_bg)
        } else if (holder.layoutPosition == adapter.itemCount - 1) {
            //最后一个
            holder.binding.root.setPadding(12.dp(), 0, 12.dp(), 10.dp())
            holder.binding.root.setBackgroundResource(R.drawable.wallet_detail_item_bottom_bg)
        } else {
            holder.binding.root.setPadding(12.dp(), 0, 12.dp(), 0)
            holder.binding.root.setBackgroundResource(R.drawable.wallet_detail_item_bg)
        }

    }

    override fun onCreateViewHolder(
        inflater: LayoutInflater,
        parent: ViewGroup,
    ): BindingViewHolder<ItemCoinDetailBinding> {
        return BindingViewHolder(
            ItemCoinDetailBinding.inflate(
                inflater,
                parent,
                false
            )
        )
    }
}