import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.*;

public class MainMenuView extends JPanel {

    private JLabel titelLabel = new JLabel("Studium versenken");
    private JButton lokalButton = new JButton("Lokal");
    private JButton multiButton = new JButton("Multiplayer");
    private JButton soundButton;

    Font robotoFont = new Font("Roboto", Font.BOLD, 45);
    private ImageIcon soundIcon = new ImageIcon("graphics/sound button.png");
    private ImageIcon muteIcon = new ImageIcon("graphics/sound button muted.png");

    public MainMenuView(MainFrame frame) {
        setLayout(null);
        buildPanel(frame);
    }

    private void buildPanel(MainFrame frame) {
        lokalButton.setBounds(200, 200, 500, 500);
        multiButton.setBounds(800, 200, 500, 500);
        titelLabel.setBounds(550, 10, 700, 100);
        soundButton = new JButton(soundIcon);
        soundButton.setBounds(20, 20, 128, 128);

        titelLabel.setFont(robotoFont);
        lokalButton.setFont(robotoFont.deriveFont(50f));
        multiButton.setFont(robotoFont.deriveFont(50f));

        add(titelLabel);
        add(lokalButton);
        add(multiButton);
        add(soundButton);

        // Event Listener für Buttons
        lokalButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Lokales Spiel ausgewählt.");
                frame.showPanel("LocalGame"); // Panel wechseln
            }
        });

        multiButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Multiplayer-Spiel ausgewählt.");
                frame.showPanel("MultiplayerGame"); // Panel wechseln
            }
        });

        soundButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Soundbutton geklickt.");
                toggleMute();
            }
        });
    }

    private void toggleMute() {
        if (soundButton.getIcon() == soundIcon) {
            soundButton.setIcon(muteIcon);
        } else {
            soundButton.setIcon(soundIcon);
        }
    }
}