package com.doverfuelingsolutions.issp.view.adapter

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doverfuelingsolutions.issp.R
import kotlinx.android.synthetic.main.adapter_choose_item.view.*

class ChooseListAdapter(private val chooseList: List<String>, private val handler: (item: String) -> Unit) :
    RecyclerView.Adapter<ChooseListAdapter.ChooseViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChooseViewHolder {
        val view = View.inflate(parent.context, R.layout.adapter_choose_item, null)
        return ChooseViewHolder(view)
    }

    override fun onBindViewHolder(holder: ChooseViewHolder, position: Int) {
        holder.itemView.chooseItemView.text = chooseList[position]
        holder.itemView.chooseItemView.setOnClickListener {
            handler.invoke(chooseList[position])
        }
    }

    override fun getItemCount(): Int = chooseList.size

    class ChooseViewHolder(view: View) : RecyclerView.ViewHolder(view)
}