package Test;

import API.Etudiant;
import API.Groupe;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

public class StudentView extends JPanel {
    private final ArrayList<Etudiant> e;
    private final ArrayList<Groupe> g;
    private final Controller listener;
    private JComboBox<String> groupeOption;

    public StudentView(ArrayList<Etudiant> e, ArrayList<Groupe> g, Controller listener) {
        super();

        this.setLayout(new GridBagLayout());

        this.listener = listener;
        this.e = e;
        this.g = g;

        this.Display();
    }

    public String getComboSelection() {
        return (String) this.groupeOption.getSelectedItem();
    }

    public int getComboSelectionIndex() {
        return this.groupeOption.getSelectedIndex();
    }

    public void Display() {
        BLayout settings = new BLayout();
        settings.setPositionX(0);
        settings.setPositionY(1);

        settings.setPositionY(0);
        JButton studList = new JButton("Voir la liste des groupes");
        studList.setActionCommand("sv::GetGrup");
        studList.addActionListener(this.listener);
        this.add(studList, settings);

        settings.setPositionY(1);
        this.add(new JLabel(" "), settings);

        settings.setPositionY(2);
        JLabel gs = new JLabel("Afficher les etudiants se trouvant dans le groupe :");
        this.add(gs, settings);

        settings.setPositionY(3);
        settings.setPadding(new Insets(0, 0, 0, 50));
        String[] groupeList = new String[this.g.size()];

        for(int i = 0; i <= this.g.size()-1; i++) {
            groupeList[i] = this.g.get(i).getName();
        }

        this.groupeOption = new JComboBox<>(groupeList);
        this.groupeOption.setPreferredSize(new Dimension(110, 30));
        this.add(groupeOption, settings);

        settings.setPositionY(3);
        settings.setPadding(new Insets(0, 0, 0, 0));
        settings.setAnchor(GridBagConstraints.EAST);
        JButton confirm = new JButton("Rechercher");
        confirm.setActionCommand("sv::GetListFiltered");
        confirm.addActionListener(this.listener);
        this.add(confirm, settings);

        settings.setPositionY(4);
        settings.setAnchor(GridBagConstraints.CENTER);
        this.add(new JLabel(" "), settings);

        settings.setPositionY(5);
        JButton makeRequest = new JButton("Faire une requete");
        makeRequest.setActionCommand("sv::MakeRequest");
        makeRequest.addActionListener(this.listener);
        this.add(makeRequest, settings);

        settings.setPositionY(6);
        this.add(new JLabel(" "), settings);

        settings.setPositionY(7);
        JButton showRequest = new JButton("Voir mes requetes");
        showRequest.setActionCommand("sv::ShowRequest");
        showRequest.addActionListener(this.listener);
        this.add(showRequest, settings);

        this.repaint();
    }
}
