package visual.panel;

import javax.swing.*;

import visual.frame.FramePrincipal;

import java.awt.event.*;
import java.util.Calendar;
import java.awt.*;

/**
 * Panel que contiene los componentes en el cual principalmente, estan los
 * botones para intercambiar entre el panelCartola y el panelResumen
 */
public class PanelSuperior extends JPanel {

	private JButton bCartola;
	private JButton bResumen;

	private JTextField fFecha;
	private JTextField fUsuario;

	private JLabel lFecha;
	private JLabel lUsuario;
	private JLabel logo;

	private String usuario;

	/**
	 * Inicia el panelSuperior asignandole el String usuario para ser utilizado
	 * por un componente mas tarde.
	 * 
	 * @param usuario
	 *            Usuario el cual se asignara mas tarde a un objeto.
	 */

	public PanelSuperior(String usuario) {

		this.usuario = usuario;
		initComponents();
	}

	/**
	 * Inicia los componentes del panel
	 */

	private void initComponents() {

		logo = new JLabel();
		lUsuario = new JLabel();
		fUsuario = new JTextField();
		lFecha = new JLabel();
		fFecha = new JTextField();
		bResumen = new JButton();
		bCartola = new JButton();

		setBackground(new Color(0, 128, 128));

		logo.setIcon(new ImageIcon(getClass().getResource("P.A.M.v2/logo.png"))); // NOI18N

		lUsuario.setFont(new Font("Candara", 1, 14)); // NOI18N
		lUsuario.setForeground(new Color(255, 255, 255));
		lUsuario.setText("Usuario:");

		fUsuario.setBackground(new Color(178, 223, 219));
		fUsuario.setEnabled(false);
		fUsuario.setText(usuario);

		lFecha.setFont(new Font("Candara", 1, 14)); // NOI18N
		lFecha.setForeground(new Color(255, 255, 255));
		lFecha.setText("Fecha:");

		Calendar hoy = Calendar.getInstance();
		fFecha.setBackground(new Color(178, 223, 219));
		fFecha.setEnabled(false);
		fFecha.setText((String.valueOf(hoy.get(Calendar.DATE)) + "/" + String.valueOf(hoy.get(Calendar.MONTH) + 1) + "/"
				+ String.valueOf(hoy.get(Calendar.YEAR))));

		bResumen.setBackground(new Color(0, 188, 212));
		bResumen.setText("Resumen");
		bResumen.setBorder(BorderFactory.createTitledBorder(""));
		bResumen.setContentAreaFilled(false);
		bResumen.setOpaque(true);
		bResumen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				bResumenActionPerformed(evt);
			}
		});

		bCartola.setBackground(new Color(0, 188, 212));
		bCartola.setText("Cartola");
		bCartola.setBorder(BorderFactory.createTitledBorder(""));
		bCartola.setContentAreaFilled(false);
		bCartola.setOpaque(true);
		bCartola.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				bCartolaActionPerformed(evt);
			}
		});

		GroupLayout layout = new GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
				.createSequentialGroup().addContainerGap().addComponent(logo)
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
						.createSequentialGroup()
						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE)
						.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
								GroupLayout.Alignment.TRAILING,
								layout.createSequentialGroup().addComponent(lUsuario)
										.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(fUsuario,
												GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
								.addGroup(GroupLayout.Alignment.TRAILING,
										layout.createSequentialGroup().addComponent(lFecha)
												.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(
														fFecha, GroupLayout.PREFERRED_SIZE, 100,
														GroupLayout.PREFERRED_SIZE)))
						.addContainerGap())
						.addGroup(layout.createSequentialGroup().addGap(333, 333, 333)
								.addComponent(bCartola, GroupLayout.PREFERRED_SIZE, 117, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(bResumen, GroupLayout.PREFERRED_SIZE, 117, GroupLayout.PREFERRED_SIZE)
								.addContainerGap(473, Short.MAX_VALUE)))));
		layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
				.createSequentialGroup().addContainerGap()
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(fUsuario, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
								GroupLayout.PREFERRED_SIZE)
						.addComponent(lUsuario))
				.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(lFecha).addComponent(
						fFecha, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
				.addGap(9, 9, 9)
				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
						.addComponent(bResumen, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
						.addComponent(bCartola, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
				.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				.addComponent(logo, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE));

	}

	/**
	 * Accion que se realiza al presionar el boton Resumen.
	 * <p>
	 * Muestra el panel Resumen
	 * </p>
	 */

	private void bResumenActionPerformed(ActionEvent evt) {

		FramePrincipal parent = (FramePrincipal) SwingUtilities.getWindowAncestor(this);
		parent.toResumen();

	}

	/**
	 * Accion que se realiza al presionar el boton Cartola.
	 * <p>
	 * Muestra el panel Cartola
	 * </p>
	 */

	private void bCartolaActionPerformed(ActionEvent evt) {

		FramePrincipal parent = (FramePrincipal) SwingUtilities.getWindowAncestor(this);
		parent.toCartola();

	}
}
