package com.abbidot.tracker.adapter

import android.content.Context
import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import com.abbidot.baselibrary.list.BaseRecyclerAdapter
import com.abbidot.baselibrary.list.RecyclerViewHolder
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.tracker.R
import com.abbidot.tracker.bean.DataBean

/**
 */
class SelectMapTypeCardShadeAdapter(
    ctx: Context, list: MutableList<DataBean>?
) : BaseRecyclerAdapter<DataBean>(ctx, list) {

    override fun getEmptyLayoutId(viewType: Int) = 0

    override fun getItemLayoutId(viewType: Int) = R.layout.item_map_type_layout

    override fun bindData(holder: RecyclerViewHolder?, position: Int, item: DataBean) {
        val imageView = holder!!.getImageView(R.id.iv_select_type_image)
        imageView.setImageResource(item.imageId)
        holder.setText(R.id.tv_map_type_name, item.name)
        val cardView = holder.getView(R.id.il_map_type_shade_image) as CardView
        cardView.apply {
            isSelected = item.selected
            cardElevation = if (item.selected) {
                setCardBackgroundColor(ContextCompat.getColor(context, R.color.white))
                val padding = AppUtils.dpToPx(3)
                setContentPadding(padding, padding, padding, padding)
                AppUtils.dpToPx(4).toFloat()
            } else {
                setCardBackgroundColor(ContextCompat.getColor(context, R.color.transparent))
                setContentPadding(0, 0, 0, 0)
                0f
            }
        }
    }
}