package com.example.tolucagraphics.adapters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.tolucagraphics.R
import com.example.tolucagraphics.events.UserElement
import com.example.tolucagraphics.events.UserElementJoin

class JugadoresAdapter (val listaJugadores : ArrayList<UserElementJoin>) : RecyclerView.Adapter<JugadoresAdapter.MesaHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MesaHolder {
        var layoutInflate = LayoutInflater.from(parent.context)
            .inflate(R.layout.modelo_jugadores, parent, false)
        return MesaHolder(layoutInflate)
    }

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

    override fun onBindViewHolder(holder: MesaHolder, position: Int) {
        holder.binder(listaJugadores[position])
    }

    class MesaHolder(view: View) : RecyclerView.ViewHolder(view) {
        private val name: TextView = view.findViewById(R.id.campoNomgreJugadores)
        private val rank: TextView = view.findViewById(R.id.campoRanking)


        fun binder(element : UserElementJoin) {
            name.text = element.user?.id.toString()
            rank.text = element.user?.username.toString()

        }

    }
}

