package com.symbol.elearningapp.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.symbol.elearningapp.HomeActivity;
import com.symbol.elearningapp.LoginActivity;
import com.symbol.elearningapp.R;
import com.symbol.elearningapp.service.ClassDetail;

import java.util.List;

public class ClassAdapter extends RecyclerView.Adapter<ClassAdapter.ViewHolder>{
    private List<ClassDetail> classDetails;
    Context context;
    ClickListener clickListener;

        public ClassAdapter(List<ClassDetail> listdata,Context context,ClickListener clickListener) {
            this.classDetails = listdata;
            this.context = context;
            this.clickListener =clickListener;
        }
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
            View listItem= layoutInflater.inflate(R.layout.list_item, parent, false);
            ViewHolder viewHolder = new ViewHolder(listItem);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            final ClassDetail myListData = classDetails.get(position);
            holder.tvSubjectname.setText(myListData.getSubject());
            holder.tvDate.setText(myListData.getDate());
            holder.tvClassTime.setText(myListData.getClassTime());
            holder.linearLayout.setOnClickListener(v ->{
                clickListener.onItemClicked(position);
//                Toast.makeText(context,myListData.getSubject() +" " +myListData.getId(),Toast.LENGTH_LONG).show();
            });

        }


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

        public static class ViewHolder extends RecyclerView.ViewHolder {
            private ClickListener listener;
            public TextView tvSubjectname,tvDate,tvClassTime;
            public LinearLayout linearLayout;
            public ViewHolder(View itemView) {
                super(itemView);
                tvSubjectname = (TextView) itemView.findViewById(R.id.tvSubject);
                tvDate = (TextView) itemView.findViewById(R.id.tvdate);
                tvClassTime = (TextView) itemView.findViewById(R.id.tvclasstime);
                linearLayout = (LinearLayout)itemView.findViewById(R.id.lvitems);
            }
        }
    public interface ClickListener {
        public void onItemClicked(int position);
    }
    }