package com.develop.setting.init.adapter

import android.widget.ImageView
import android.widget.RelativeLayout
import androidx.appcompat.widget.AppCompatTextView
import androidx.cardview.widget.CardView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.develop.food.base.data.model.LanguageModel
import com.develop.food.base.utils.ResDimension
import com.develop.setting.R

class LanguageAdapter :
    BaseQuickAdapter<LanguageModel, BaseViewHolder>(R.layout.item_language_view) {
    private var selectedPosition = 0
    override fun convert(holder: BaseViewHolder, item: LanguageModel) {
        val ivIcon = holder.getView<ImageView>(R.id.ic_icon)
        val tvTitle = holder.getView<AppCompatTextView>(R.id.tv_title)
        val cardView = holder.getView<CardView>(R.id.cardView)
        if (selectedPosition == holder.adapterPosition) {
            tvTitle.setTextColor(context.resources.getColor(R.color.color_F4A12E))
            cardView.setCardBackgroundColor(context.resources.getColor(R.color.color_33F4A12E))
            cardView.cardElevation = 0.1f
        } else {
            tvTitle.setTextColor(context.resources.getColor(R.color.color_6B6B6B))
            cardView.setCardBackgroundColor(context.resources.getColor(R.color.color_fff))
            cardView.cardElevation = ResDimension(R.dimen.convert_6px)
        }
        Glide.with(context).load(item.icon).into(ivIcon)
        tvTitle.text = item.languageName
    }


    fun updateSelectedPosition(adapterPosition: Int) {
        val tempPosition = selectedPosition
        selectedPosition = adapterPosition
        notifyItemChanged(tempPosition)
        notifyItemChanged(selectedPosition)
    }
}