package com.hw.nativeapp.ui.activity.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.hw.nativeapp.R;
import com.hw.nativeapp.httpnet.entity.WarehousingDetailsBean;
import com.hw.nativeapp.httpnet.entity.handleBean;
import com.hw.nativeapp.ui.activity.holders.AftermarketOneHolder;

import java.util.ArrayList;
import java.util.List;

public class AftermarketOneAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{


    private Context mContext;
    private List<handleBean> mDatas ;
    private OnBtnClickListerer mOnReplenishBtnClickListerer;
    private OnBtnClickListerer mOnOutBtnClickListerer;


    public AftermarketOneAdapter(Context context) {
        mContext = context;
        mDatas = new ArrayList<>();
    }

    public void addDatas(List<handleBean> datas){
        if (mDatas == null){
            mDatas = new ArrayList<>();
        }
        mDatas.addAll(datas);
        notifyDataSetChanged();
    }

    public void clearDatas(){
        if (mDatas != null){
            mDatas.clear();
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_aftermarket_1, parent, false);
        return new AftermarketOneHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        AftermarketOneHolder normalHolder = (AftermarketOneHolder) holder;
        handleBean detailBean = mDatas.get(position);
        if (detailBean == null){
            return;
        }


        normalHolder.btn_handle.setOnClickListener(v -> {
            mOnOutBtnClickListerer.onClick(detailBean, position);
        });
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public void setOnOutBtnClickListerer(OnBtnClickListerer onBtnClickListerer) {
        this.mOnOutBtnClickListerer = onBtnClickListerer;
    }

    public interface OnBtnClickListerer{
        void onClick(handleBean bean, int position);
    }
}
