package com.example.leudaemialikeme.Adapter;

import android.content.Intent;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

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

import com.example.leudaemialikeme.Activity.AddEventActivity;
import com.example.leudaemialikeme.Model.Event;
import com.example.leudaemialikeme.R;

import java.util.List;
import java.util.Map;

public class EventAdapter extends RecyclerView.Adapter<EventAdapter.ViewHolder>{
//    private List<Event> meventList;
    private List<Map<String,String>> mcontentList;

    //重写构造方法
    public EventAdapter(List<Map<String,String>> contentList){
        this.mcontentList = contentList;
    }
    public int getItemCount(){
        return mcontentList.size();
    }
    //内部类
    static class ViewHolder extends RecyclerView.ViewHolder {
        View eventView;
        TextView event_day,event_month,event_info,event_time;
        TextView event_place,event_doctor_name,event_create_time;
        LinearLayout event_item_layout;

        public ViewHolder(@NonNull View itemView){
            super(itemView);
            eventView = itemView;
            this.event_day = (TextView)itemView.findViewById(R.id.event_day);
            this.event_month = (TextView)itemView.findViewById(R.id.event_month);
            this.event_info = (TextView)itemView.findViewById(R.id.event_info);
            this.event_time = (TextView)itemView.findViewById(R.id.event_time);
            this.event_place = itemView.findViewById(R.id.event_place);
            this.event_doctor_name = itemView.findViewById(R.id.event_doctor_name);
            this.event_create_time = itemView.findViewById(R.id.event_create_time);
            this.event_item_layout = itemView.findViewById(R.id.event_item_layout);
        }
    }
    //重写 onCreateViewHolder()方法
    @Override
    public EventAdapter.ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.event_item,parent,false);
//        EventAdapter.ViewHolder holder=new EventAdapter.ViewHolder(view);
        final ViewHolder holder = new ViewHolder(view);
        holder.eventView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int position = holder.getAdapterPosition();
                String event_day = mcontentList.get(position).get("event_day");
                String event_month = mcontentList.get(position).get("event_month");
                String event_info = mcontentList.get(position).get("event_info");
                String event_place = mcontentList.get(position).get("event_place");
                String event_doctor_name = mcontentList.get(position).get("event_doctor_name");
                String event_time = mcontentList.get(position).get("event_time");
                String event_create_time = mcontentList.get(position).get("event_create_time");
                Intent intent = new Intent(parent.getContext(), AddEventActivity.class);
                intent.putExtra(AddEventActivity.EVENT_DAY,event_day);
                intent.putExtra(AddEventActivity.EVENT_MONTH,event_month);
                intent.putExtra(AddEventActivity.EVENT_INFO,event_info);
                intent.putExtra(AddEventActivity.EVENT_PLACE,event_place);
                intent.putExtra(AddEventActivity.EVENT_DOCTOR_NAME,event_doctor_name);
                intent.putExtra(AddEventActivity.EVENT_TIME,event_time);
                intent.putExtra(AddEventActivity.EVENT_CREATE_TIME,event_create_time);
                parent.getContext().startActivity(intent);
            }
        });
        return holder;
    }
    //重写onBindViewHolder()方法
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        holder.event_day.setText(mcontentList.get(position).get("event_day"));
        holder.event_month.setText(mcontentList.get(position).get("event_month"));
        holder.event_info.setText(mcontentList.get(position).get("event_info"));
        holder.event_time.setText(mcontentList.get(position).get("event_time"));
        holder.event_place.setText(mcontentList.get(position).get("event_place"));
        holder.event_doctor_name.setText(mcontentList.get(position).get("event_doctor_name"));
        holder.event_create_time.setText(mcontentList.get(position).get("event_create_time"));

    }
}
