package com.b2lmobitech.fieldcloudhrms

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class LeaveBalanceAdapter(
    private val list: List<LeaveBalanceModel>
) : RecyclerView.Adapter<LeaveBalanceAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val txtLeaveType: TextView = view.findViewById(R.id.txtLeaveType)
        val txtCredited: TextView = view.findViewById(R.id.txtCredited)
        val txtUsed: TextView = view.findViewById(R.id.txtUsed)
        val txtBalance: TextView = view.findViewById(R.id.txtBalance)
    }

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

    override fun getItemCount() = list.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = list[position]

        holder.txtLeaveType.text = item.leave_type
        holder.txtCredited.text = "Credited: ${item.credited} days"
        holder.txtUsed.text = "Used: ${item.used} days"
        holder.txtBalance.text = "Balance: ${item.balance} days"
    }
}

