package com.unibuy.smartdevice.ui.recycler;

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

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

import com.unibuy.smartdevice.databinding.ActivityProductSearchBinding;
import com.unibuy.smartdevice.databinding.RecyclerSearchTextBinding;
import com.unibuy.smartdevice.databinding.RecyclerSettingListBinding;

import java.util.List;

public class RecyclerSettingListAdpter extends RecyclerView.Adapter<RecyclerSettingListAdpter.ViewHolder> {
    private final List<String> textList;

    public RecyclerSettingListAdpter(List<String> textList) {
        this.textList = textList;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        RecyclerSettingListBinding binding;

        public ViewHolder(@NonNull RecyclerSettingListBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 使用 ViewBinding 來綁定佈局
        RecyclerSettingListBinding binding = RecyclerSettingListBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String oneText = textList.get(position);
        holder.binding.textStatus.setText(oneText);
    }

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

    public void addProductData(String text) {
        textList.add(text);
        notifyItemInserted(textList.size() -1);
    }
}
