package com.example.mynotepad.Dialogs.FoldersCustomDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.mynotepad.R;
import java.util.ArrayList;

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

    private ArrayList<String> foldersName;
    private Context context;
    private OnFolderClickListener onFolderClickListener;

    public FolderRecyclerViewAdapter(ArrayList<String> foldersName , Context context) {
        this.foldersName = foldersName;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.custom_folder_item , parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.folderName.setText(foldersName.get(position));
    }

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

    public void setOnFolderClickListener(OnFolderClickListener onFolderClickListener) {
        this.onFolderClickListener = onFolderClickListener;
    }

    class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        TextView folderName;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            folderName = itemView.findViewById(R.id.folderName);
        }

        @Override
        public void onClick(View v) {
            if(onFolderClickListener!= null)
            onFolderClickListener.itemClicked(folderName.getText().toString());//todo remove this and add this name to data base
        }
    }
}
