package com.pan_american.android.data.model.group_common_modle.bill_management.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.pan_american.android.R
import com.pan_american.android.data.model.group_common_modle.bill_management.entity.BillFileListItem

class BillFileItemAdapter(private val billFileList: ArrayList<BillFileListItem>): RecyclerView.Adapter<BillFileItemAdapter.ViewHolder>() {

    lateinit var onRecyclerViewItemClick: OnRecyclerViewItemClick<BillFileListItem>

    inner class ViewHolder(view: View): RecyclerView.ViewHolder(view) {
        val documentName: TextView = view.findViewById(R.id.document_name)
        val downloadButton: TextView = view.findViewById(R.id.download)
        val deleteButton: TextView = view.findViewById(R.id.delete)
    }

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

        return ViewHolder(view)
    }

    override fun getItemCount() = billFileList.size

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

        holder.documentName.text = item.fileName

        holder.downloadButton.setOnClickListener {
            onRecyclerViewItemClick.downLoad(position)
        }

        holder.deleteButton.setOnClickListener {
            onRecyclerViewItemClick.delete(position)
        }
    }

    interface OnRecyclerViewItemClick<T> {

        fun downLoad(position: Int)

        fun delete(position: Int)
    }
}