package com.example.calendaryapp;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.Calendar;


public class Main2Activity extends AppCompatActivity {
    private RecyclerView mRecyclerView;//recyclerview o items de los dias de la semana
    private WeekAdapter mAdapter; //Adaptador del recyclerview
    private RecyclerView.LayoutManager mLayoutManager;
    private ArrayList<WeekItem> mWeekList; //items que van en el recylcerview
    private Calendar calendar = Calendar.getInstance();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        createWeekDaysList(); //se crea la lista con los dias de la semana
        buildRecyclerView();  //se construye el reclyreview
    }
    public String getMonth(int number){
        String mes = "";
        switch(number){
            case 0: mes =  "Enero";
                    break;
            case 1: mes = "Febrero";
                    break;
            case 2: mes =  "Marzo";
                break;
            case 3: mes = "Abril";
                break;
            case 4: mes =  "Mayo";
                break;
            case 5: mes = "Junio";
                break;
            case 6: mes =  "Julio";
                break;
            case 7: mes = "Agosto";
                break;
            case 8: mes =  "Septiembre";
                break;
            case 9: mes = "Octubre";
                break;
            case 10: mes =  "Noviembre";
                break;
            case 11: mes = "Diciembre";
        }
        return mes;

    }

    public void createWeekDaysList() {


        mWeekList = new ArrayList<>();
        calendar.set(Calendar.DAY_OF_WEEK, calendar.MONDAY);
        mWeekList.add(new WeekItem("Lun", ""+calendar.get(Calendar.DATE)+" "+getMonth(calendar.get(Calendar.MONTH))));
        calendar.set(Calendar.DAY_OF_WEEK, calendar.TUESDAY);
        mWeekList.add(new WeekItem("Mar", ""+calendar.get(Calendar.DATE)+" "+getMonth(calendar.get(Calendar.MONTH))));
        calendar.set(Calendar.DAY_OF_WEEK, calendar.WEDNESDAY);
        mWeekList.add(new WeekItem("Mie", ""+calendar.get(Calendar.DATE)+" "+getMonth(calendar.get(Calendar.MONTH))));
        calendar.set(Calendar.DAY_OF_WEEK, calendar.THURSDAY);
        mWeekList.add(new WeekItem("Jue", ""+calendar.get(Calendar.DATE)+" "+getMonth(calendar.get(Calendar.MONTH))));
        calendar.set(Calendar.DAY_OF_WEEK, calendar.FRIDAY);
        mWeekList.add(new WeekItem("Vie", ""+calendar.get(Calendar.DATE)+" "+getMonth(calendar.get(Calendar.MONTH))));
    }

    public void buildRecyclerView() {
        mRecyclerView = findViewById(R.id.recyclerView); //se referencia la objeto recyclerview del layout
        mRecyclerView.setHasFixedSize(true);
        //se crea el layout manager que provee de vistas para el recyclerview
        //este manager se encarga de posicionar y medir los items que van en el listado
        //se le pasa el contexto para acceder a los recursos
        mLayoutManager = new LinearLayoutManager(this);
        //las vistas de la lista son objetos viewHolder los cuales son instancias de alguna clase que derive de RecyclerView.ViewHolder.
        //estos objetos son manejados por el adaptador
        mAdapter = new WeekAdapter(mWeekList);

        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new WeekAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                //changeItem(position, ""+position);
                Intent startIntent;
                startIntent = new Intent(getApplicationContext(),LunesAgenda.class);
                switch(position) {
                    case 0:
                        startIntent = new Intent(getApplicationContext(),LunesAgenda.class);
                        break;
                    case 1:
                        startIntent = new Intent(getApplicationContext(),MartesAgenda.class);
                        break;
                    case 2:
                        startIntent = new Intent(getApplicationContext(),MiercolesAgenda.class);
                        break;
                    case 3:
                        startIntent = new Intent(getApplicationContext(),JuevesAgenda.class);
                        break;
                    case 4:
                        startIntent = new Intent(getApplicationContext(),ViernesAgenda.class);



                }
                startActivity(startIntent);
            }
        });
    }
}


