package it.integry.integrywmsnative.gest.contab_doc_interni.edit_form.ui;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ObservableArrayList;
import androidx.recyclerview.widget.RecyclerView;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.data_store.db.entity.SqlMtbColr;
import it.integry.integrywmsnative.core.data_store.db.entity.SqlMtbColt;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.expansion.view.ExtendedRecyclerView;
import it.integry.integrywmsnative.core.utility.UtilityDate;
import it.integry.integrywmsnative.databinding.ActivityContabDocInternoRowListSingleItemBinding;
import it.integry.integrywmsnative.databinding.DocInterniListModelBinding;

public class DocumentRowsListAdapter extends ExtendedRecyclerView<SqlMtbColr, DocumentRowsListAdapter.SingleItemViewHolder> {

    private Context mContext;

    private RunnableArgs<SqlMtbColr> mOnItemClicked;

    public DocumentRowsListAdapter(Context context, ObservableArrayList<SqlMtbColr> myDataset) {
        super(myDataset);
        this.mContext = context;
    }

    @NonNull
    @Override
    public SingleItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ActivityContabDocInternoRowListSingleItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.activity_contab_doc_interno_row__list_single_item, parent, false);
        return new SingleItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull SingleItemViewHolder holder, int position) {
        final SqlMtbColr row = mDataset.get(position);
        holder.binding.setItem(row);
        holder.binding.executePendingBindings();
        holder.binding.getRoot().setOnClickListener(v -> {
            if (this.mOnItemClicked != null)
                this.mOnItemClicked.run(row);
        });
    }


    public void setOnItemClicked(RunnableArgs<SqlMtbColr> onItemClicked){
        this.mOnItemClicked = onItemClicked;
    }
    static class SingleItemViewHolder extends RecyclerView.ViewHolder {

        ActivityContabDocInternoRowListSingleItemBinding binding;

        SingleItemViewHolder(ActivityContabDocInternoRowListSingleItemBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }


}
