package it.integry.integrywmsnative.gest.inventario.picking;

import android.view.LayoutInflater;
import android.view.ViewGroup;

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

import it.integry.integrywmsnative.core.data_store.db.entity.InventarioRowRoomDTO;
import it.integry.integrywmsnative.core.expansion.view.ExtendedRecyclerView;
import it.integry.integrywmsnative.core.model.MtbColr;
import it.integry.integrywmsnative.databinding.ActivityPickingInventarioListItemBinding;

public class PickingInventarioListAdapter extends ExtendedRecyclerView<InventarioRowRoomDTO, PickingInventarioListAdapter.ViewHolder> {

    private PickingInventarioListAdapter.OnItemClickListener mOnItemClickListener;

    public PickingInventarioListAdapter(ObservableArrayList<InventarioRowRoomDTO> myDataset) {
        super(myDataset);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        protected ActivityPickingInventarioListItemBinding mViewDataBinding;


        public ViewHolder(ActivityPickingInventarioListItemBinding v) {
            super(v.getRoot());
            mViewDataBinding = v;
        }

        public void bind(InventarioRowRoomDTO inventarioRowRoomDTO) {
            mViewDataBinding.setItem(inventarioRowRoomDTO);
            mViewDataBinding.executePendingBindings();
        }
    }


    @NonNull
    @Override
    public PickingInventarioListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // create a new view
        ActivityPickingInventarioListItemBinding viewDataBinding =
                ActivityPickingInventarioListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

        return new ViewHolder(viewDataBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull PickingInventarioListAdapter.ViewHolder holder, int position) {
        InventarioRowRoomDTO mtbColr = mDataset.get(position);
        holder.bind(mtbColr);
//
//        //Setting qty with unt_mis
//        if(!SettingsManager.iDB().isFlagForceAllToColli() && (mtbColr.getMtbAart() == null || mtbColr.getMtbAart().isFlagQtaCnfFissaBoolean())){
//            String text = UtilityNumber.decimalToString(mtbColr.getQtaCol());
//
//            if(mtbColr.getMtbAart() != null) {
//                text += !UtilityString.isNullOrEmpty(mtbColr.getMtbAart().getUntMis()) ? "\n" + mtbColr.getMtbAart().getUntMis() : "";
//            }
//
//            holder.mViewDataBinding.qtaTextview.setText(text);
//        } else {
//            holder.mViewDataBinding.qtaTextview.setText(UtilityNumber.decimalToString(mtbColr.getNumCnf()) + "\n" + UtilityResources.getString(R.string.unt_mis_col));
//        }
//
//        holder.mViewDataBinding.getRoot().setOnClickListener(x -> {
//            if(mOnItemClickListener != null) {
//                mOnItemClickListener.onItemClick(holder.mViewDataBinding.getMtbColr());
//            }
//        });
//
//        holder.mViewDataBinding.executePendingBindings();
    }


    public PickingInventarioListAdapter setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
        return this;
    }

    public interface OnItemClickListener {
        void onItemClick(MtbColr item);
    }
}
