package com.example.mynotepad.MenuFeatures.Calender.MyCalenderRecyclerView;

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.MenuFeatures.Calender.MyCalenderRecyclerView.TimePicker.MyDate;
import com.example.mynotepad.R;

import java.util.List;

public class MyCalenderAdaptor extends RecyclerView.Adapter<MyCalenderAdaptor.CalenderViewHolder> {

    private List<MyDate> dates;
    private OnCalenderItemClickListener onCalenderItemClickListener;

    public MyCalenderAdaptor(List<MyDate> dates){
        this.dates = dates;
    }
    @NonNull
    @Override
    public CalenderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_allnotes_item, parent, false);
        return new CalenderViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CalenderViewHolder holder, int position) {
        holder.dateTV.setText(dates.get(position).getDate());
        holder.descriptionTV.setText(dates.get(position).getDescription());
        holder.isarchived = dates.get(position).isArchived();
    }

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

    public void setOnCalenderItemClickListener(OnCalenderItemClickListener onCalenderItemClickListener) {
        this.onCalenderItemClickListener = onCalenderItemClickListener;
    }

    class CalenderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        protected TextView dateTV, descriptionTV;
        protected boolean isarchived;

        public CalenderViewHolder(@NonNull View itemView) {
            super(itemView);
            dateTV = itemView.findViewById(R.id.titleTv);
            descriptionTV = itemView.findViewById(R.id.descriptionTv);
            isarchived = false;
            itemView.setOnClickListener(this);
            itemView.setOnLongClickListener(this);
        }

        @Override
        public void onClick(View view) {
            if (onCalenderItemClickListener != null) {
                onCalenderItemClickListener.onItemClicked(dates.get(getAdapterPosition()));
            }
        }

        @Override
        public boolean onLongClick(View view) {
            if (onCalenderItemClickListener != null)
                onCalenderItemClickListener.onItemLongClicked(dates.get(getAdapterPosition()));
            return true;
        }
    }

}

