package com.casic.br.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.casic.br.R
import com.casic.br.model.SolutionModel2

class FaultDescAdapter2(
    val context: Context, private val dataRows: MutableList<SolutionModel2>
) : RecyclerView.Adapter<FaultDescAdapter2.ItemViewHolder>() {

    private var layoutInflater: LayoutInflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        return ItemViewHolder(
            layoutInflater.inflate(R.layout.item_fault_desc_rv_l_2, parent, false)
        )
    }

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        val rowsModel = dataRows[position]
        holder.phenomenonView.text = rowsModel.phenomenon
        holder.reasonRecyclerView.adapter = SolutionAdapter(context, rowsModel.reason)
        holder.solutionRecyclerView.adapter = SolutionAdapter(context, rowsModel.solution)
    }

    override fun getItemCount(): Int = dataRows.size

    class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val phenomenonView: TextView = itemView.findViewById(R.id.phenomenonView)
        val reasonRecyclerView: RecyclerView = itemView.findViewById(R.id.reasonRecyclerView)
        val solutionRecyclerView: RecyclerView = itemView.findViewById(R.id.solutionRecyclerView)
    }
}