package Fenetres;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Image;

import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;

import ClassesJava.Lieu;
import ClassesJava.Profil;
import DAO.LieuxDAO;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Fenetre_Resultats_Profil extends JFrame {

	private JPanel contentPane;
	protected JList <String> list;
	protected DefaultListModel <Profil> listeProfil = new DefaultListModel<Profil>();
	protected  DefaultListModel<String> listeProfils = new DefaultListModel<String>();
	private Fenetre_Creer_Profil fenetre1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Fenetre_Resultats_Profil frame = new Fenetre_Resultats_Profil();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Fenetre_Resultats_Profil() {
		
		LieuxDAO lieuDAO = new LieuxDAO();
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(500, 100, 543, 553);
		contentPane = new JPanel_Background();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		Image icon2 = new ImageIcon(this.getClass().getResource("/left-arrow.png")).getImage();
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(52, 42, 425, 403);
		contentPane.add(scrollPane);
		

		list = new JList<String>(listeProfils);
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		scrollPane.setViewportView(list);
		
		JButton btnRetour = new JButton("  Modifier Profil");
		btnRetour.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				if(fenetre1 == null) {
					fenetre1 = new Fenetre_Creer_Profil(); 
					
					fenetre1.titreprofil.setText(listeProfil.getElementAt(0).getTitre_profil());
					fenetre1.Heure.setSelectedIndex(listeProfil.getElementAt(0).getHouverture().getHours());
					fenetre1.Min.setSelectedIndex(listeProfil.getElementAt(0).getHouverture().getMinutes());
					fenetre1.Sec.setSelectedIndex(listeProfil.getElementAt(0).getHouverture().getSeconds());
					fenetre1.Heure1.setSelectedIndex(listeProfil.getElementAt(0).getHfermerture().getHours());
					fenetre1.Min1.setSelectedIndex(listeProfil.getElementAt(0).getHfermerture().getMinutes());
					fenetre1.Sec1.setSelectedIndex(listeProfil.getElementAt(0).getHfermerture().getSeconds());
					fenetre1.btnCreer.setEnabled(false);
					fenetre1.btnModifier.setEnabled(true);
					
					fenetre1.setVisible(true);
				}
				else {
					fenetre1.setVisible(true);
				}		
			}
		});
		btnRetour.setIcon(new ImageIcon(icon2));
		btnRetour.setFont(new Font("Century Gothic", Font.PLAIN, 16));
		btnRetour.setBounds(166, 467, 191, 36);
		contentPane.add(btnRetour);
	}
}
