package industries.doublehelix.furrynotemanager.gui;

import java.awt.Font;
import java.sql.SQLException;
import java.util.TreeSet;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;

import industries.doublehelix.furrynotemanager.Folder;
import industries.doublehelix.furrynotemanager.User;

public class UserPanel extends JPanel {
	private static final long serialVersionUID = -2742542137781172306L;
	JList<Folder> list;
	User user;
	
	
	public UserPanel(User user) throws SQLException {
		this.user = user;
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		JLabel lblUser = new JLabel(user.getName());
		lblUser.setFont(lblUser.getFont().deriveFont(Font.BOLD, 20f));
		lblUser.setAlignmentX(LEFT_ALIGNMENT);
		
		JLabel lblSite = new JLabel(user.getSite().getName());
		lblSite.setFont(lblSite.getFont().deriveFont(Font.ITALIC, 13f));
		lblSite.setAlignmentX(LEFT_ALIGNMENT);
		
		TreeSet<Folder> allFolders = user.getFolders();
		allFolders.add(new Folder("All Folders", false));
		list = new JList<Folder>(allFolders.toArray(new Folder[allFolders.size()]));
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setLayoutOrientation(JList.VERTICAL);
		list.setAlignmentX(LEFT_ALIGNMENT);
		
		this.add(lblUser);
		this.add(Box.createVerticalStrut(3));
		this.add(lblSite);
		this.add(Box.createVerticalStrut(10));
		this.add(list);
		this.setAlignmentX(LEFT_ALIGNMENT);
	}
	
	public JList<Folder> getList() {
		return list;
	}
	
	public User getUser() {
		return user;
	}
}
