package com.bassbooster.soundeffects.equalizer.view.activity.edgelighting.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.bassbooster.equalizer.R
import com.bassbooster.equalizer.databinding.AdapterImageBoderBinding


class ImageBoderAdapter(val context: Context, val list: ArrayList<Int>, val mListener: OnItemClickListener) : RecyclerView.Adapter<ImageBoderAdapter.ViewHolder>() {
    var isSelect = 0
    interface OnItemClickListener {
        fun onItemClick(position: Int)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = AdapterImageBoderBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        if (isSelect == position){
            holder.binding.mllImage.background = ContextCompat.getDrawable(context, R.drawable.custom_boder_select_grad)
        }else{
            holder.binding.mllImage.background = ContextCompat.getDrawable(context,R.drawable.boder_radius_style)
        }
        holder.binding.mImgStyle.background = ContextCompat.getDrawable(context,list[position])
        holder.binding.mllImage.setOnClickListener {
            isSelect = position
            mListener.onItemClick(position)
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class ViewHolder(val binding: AdapterImageBoderBinding) : RecyclerView.ViewHolder(binding.root)

}