package it.integry.integrywmsnative.gest.prod_rientro_merce.order_detail;

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

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

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.expansion.view.ExtendedRecyclerView;
import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.databinding.FragmentProdRientroMerceOrderDetailMtbColtItemModelBinding;

public class ProdRientroMerceOrderDetailMtbColtListAdapter extends ExtendedRecyclerView<MtbColt, ProdRientroMerceOrderDetailMtbColtListAdapter.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    public ProdRientroMerceOrderDetailMtbColtListAdapter(ObservableArrayList<MtbColt> myDataset) {
        super(myDataset);
    }

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


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

        public void bind(MtbColt mtbColt) {
            mViewDataBinding.setMtbColt(mtbColt);
            mViewDataBinding.executePendingBindings();
        }
    }


    @Override
    public ProdRientroMerceOrderDetailMtbColtListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // create a new view
        FragmentProdRientroMerceOrderDetailMtbColtItemModelBinding viewDataBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.fragment_prod_rientro_merce_order_detail__mtb_colt_item_model, parent, false);

        return new ProdRientroMerceOrderDetailMtbColtListAdapter.ViewHolder(viewDataBinding);
    }



    @Override
    public void onBindViewHolder(ProdRientroMerceOrderDetailMtbColtListAdapter.ViewHolder holder, int position) {
        MtbColt mtbColt = mDataset.get(position);
        holder.bind(mtbColt);

        //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.getMtbColt());
            }
        });

        holder.mViewDataBinding.executePendingBindings();
    }





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

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

}
