package com.develop.main.init.ui.adapter

import android.widget.ImageView
import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.develop.food.base.data.model.FilterSortModel
import com.develop.main.R

class SortAdapter :
    BaseQuickAdapter<FilterSortModel, BaseViewHolder>(R.layout.item_filter_and_sort_view) {
    private var selectedPosition = 0
    override fun convert(holder: BaseViewHolder, item: FilterSortModel) {
        val ivCheck = holder.getView<ImageView>(R.id.iv_check)
        val tvName = holder.getView<AppCompatTextView>(R.id.tv_name)
        tvName.text = item.name
        if (selectedPosition == holder.adapterPosition) {
            tvName.setTextColor(context.resources.getColor(R.color.color_F4A12E))
            ivCheck.setBackgroundResource(R.drawable.ic_check)
        } else {
            tvName.setTextColor(context.resources.getColor(R.color.color_6B6B6B))
            ivCheck.setBackgroundResource(0)
        }
    }

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