package com.example.mysmartlab.Adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.mysmartlab.Model.CatalogItem
import com.example.mysmartlab.R
import com.example.mysmartlab.databinding.AnaliseBinding

class AdapterCatalog() : RecyclerView.Adapter<AdapterCatalog.CatalogHolder>() {
    private val catalogList = ArrayList<CatalogItem>()

    class CatalogHolder(item: View) : RecyclerView.ViewHolder(item) {
        private val binding = AnaliseBinding.bind(item)
        fun bind(catalog: CatalogItem) = with(binding)
        {
            analiseHeader.text = catalog.name
            priceAnalise.text = catalog.price.toString()
            countDayAnalise.text = catalog.timeResul

        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CatalogHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.analise, parent, false)
        return AdapterCatalog.CatalogHolder(view)
    }

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

    override fun onBindViewHolder(holder: CatalogHolder, position: Int) {
        holder.bind(catalogList[position])
    }
    fun addCatalog(catalog: CatalogItem) {
        catalogList.add(catalog)
        notifyDataSetChanged()
    }
}
