package com.example.tyre.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

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

import com.example.tyre.BR;
import com.example.tyre.R;
import com.example.tyre.databinding.ItemCarRecordBinding;
import com.example.tyre.entity.CarMaintenanceLifecycleDTO;
import com.example.tyre.maintenance.been.CheckInstanceFiles;

import java.util.List;

/**
 * @author wanghao
 * @date 2024/3/11
 */
public class CarRecordAdapter extends RecyclerView.Adapter<CarRecordAdapter.MyViewHolder> {
    private List<CarMaintenanceLifecycleDTO> list;
    private static Context context;
    private LayoutInflater inflater;
    private ItemClickCall clickCall;




    public CarRecordAdapter(Context context, ItemClickCall clickCall) {
        this.context = context;
        this.clickCall = clickCall;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<CarMaintenanceLifecycleDTO> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemCarRecordBinding binding = DataBindingUtil.inflate(inflater, R.layout.item_car_record, parent, false);
        return new MyViewHolder(binding);
    }

    // @SuppressLint("CheckResult")
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        var item = list.get(position);
        var binding = holder.binding;
        binding.setVariable(BR.item, item);



    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ItemCarRecordBinding binding;

        public MyViewHolder(ItemCarRecordBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }


    }
    public interface ItemClickCall {
        void onClick(int position);
    }
}
