package tutorialJava.examenes.examen20250509.vista;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JScrollPane;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import java.awt.Insets;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTable;

import tutorialJava.examenes.examen20250509.controlador.ControladorConcierto;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class PanelEstadisticas extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTable jTableDatos;
	private JLabel lblPrecioMedio;
	JLabel lblGrupoConMasConciertos;

	/**
	 * Create the panel.
	 */
	public PanelEstadisticas() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JLabel lblNewLabel = new JLabel("Estadísticas");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 15));
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.gridwidth = 2;
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 0;
		gbc_lblNewLabel.gridy = 0;
		add(lblNewLabel, gbc_lblNewLabel);
		
		JScrollPane scrollPane = new JScrollPane();
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.gridwidth = 2;
		gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 1;
		add(scrollPane, gbc_scrollPane);
		
		jTableDatos = new JTable(getMatrizDeDatos(), getTitulosMatriz());
		scrollPane.setViewportView(jTableDatos);
		
		JButton btnNewButton_1 = new JButton("Calcular precio medio");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblPrecioMedio.setText("" + 
						ControladorConcierto.getPrecioMedioConciertos());
			}
		});
		GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
		gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_1.gridx = 0;
		gbc_btnNewButton_1.gridy = 2;
		add(btnNewButton_1, gbc_btnNewButton_1);
		
		lblPrecioMedio = new JLabel("New label");
		GridBagConstraints gbc_lblPrecioMedio = new GridBagConstraints();
		gbc_lblPrecioMedio.insets = new Insets(0, 0, 5, 0);
		gbc_lblPrecioMedio.gridx = 1;
		gbc_lblPrecioMedio.gridy = 2;
		add(lblPrecioMedio, gbc_lblPrecioMedio);
		
		JButton btnNewButton = new JButton("Grupo con más conciertos");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblGrupoConMasConciertos.setText(
						ControladorConcierto.getGrupoConMasConciertos());
			}
		});
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton.gridx = 0;
		gbc_btnNewButton.gridy = 3;
		add(btnNewButton, gbc_btnNewButton);
		
		lblGrupoConMasConciertos = new JLabel("New label");
		GridBagConstraints gbc_lblGrupoConMasConciertos = new GridBagConstraints();
		gbc_lblGrupoConMasConciertos.gridx = 1;
		gbc_lblGrupoConMasConciertos.gridy = 3;
		add(lblGrupoConMasConciertos, gbc_lblGrupoConMasConciertos);

	}

	/**
	 * 
	 * @return
	 */
	private Object[][] getMatrizDeDatos() {
//		String matriz[][] = new String[2][2];
//		matriz[0][0] = "Rafa";
//		matriz[0][1] = "Ismael";
//		matriz[1][0] = "Rubén";
//		matriz[1][1] = "Mª Jesús";
		return ControladorConcierto.getTotalesFestivalesPorCiudad();
	}
	
	/**
	 * 
	 * @return
	 */
	private String[] getTitulosMatriz() {
		return new String[] {"Ciudad", "Número de festivales"};
	}
	
}












