package net.pokeranalytics.android.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.row_bottom_sheet_grid_title.view.*
import net.pokeranalytics.android.R

class TableSizeGridAdapter(private var tableSizes: ArrayList<String>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

	companion object {
		const val ROW_TABLE_SIZE: Int = 100
	}

	var onClickOnItem: ((position: Int) -> Unit)? = null

	inner class CellSessionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

		fun bind(tableSize: String) {
			itemView.title.text = tableSize
			itemView.container.setOnClickListener {
				onClickOnItem?.invoke(adapterPosition)
			}
		}
	}

	override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
		when (viewType) {
			ROW_TABLE_SIZE -> return CellSessionViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_bottom_sheet_grid_title, parent, false))
			else -> throw IllegalStateException("Need to implement type $viewType in HistoryAdapter")
		}
	}

	override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
		when (getItemViewType(position)) {
			ROW_TABLE_SIZE -> (holder as TableSizeGridAdapter.CellSessionViewHolder).bind(tableSizes[position])
		}
	}

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

	override fun getItemViewType(position: Int): Int {
		return ROW_TABLE_SIZE
	}


}