package tech.nevets.jaml.gui.panels;

import tech.nevets.jaml.JAML;
import tech.nevets.jaml.Launcher;
import tech.nevets.jaml.util.ImageUtils;
import tech.nevets.jaml.util.ProfileUtils;

import javax.swing.*;

public class HomePanel extends JPanel {
    public HomePanel() {
        JButton newProfileButton = new JButton("Create New Profile");
        newProfileButton.setBounds(920, 601, 134, 36);
        newProfileButton.addActionListener(al -> {
            JAML.guiHandler.startNewProfileGui();
        });
        add(newProfileButton);

        JButton launchButton = new JButton("Launch");
        launchButton.setBounds(512, 619, 196, 51);
        launchButton.addActionListener(al -> {
            Launcher launch = new Launcher();
            launch.setJdkVersion(17);
            launch.setMemoryAmount(6144);
            launch.setGarbageCollection("zgc");
            launch.setPrintConsole(true);
            launch.launch();
        });
        add(launchButton);

        JComboBox<String> activeProfileDropdown = new JComboBox<>(ProfileUtils.profileList);
        activeProfileDropdown.setBounds(858, 648, 196, 22);
        add(activeProfileDropdown);

        JButton reloadProfileButton = new JButton("Reload Profiles");
        reloadProfileButton.setBounds(800, 608, 106, 23);
        reloadProfileButton.addActionListener(al -> {
            ProfileUtils.getProfileList();
            activeProfileDropdown.removeAllItems();
            for (int i = 0; i < ProfileUtils.profileList.length; i++) {
                activeProfileDropdown.addItem(ProfileUtils.profileList[i]);
            }
        });
        add(reloadProfileButton);

        JLabel backgroundIcon = new JLabel("");
        backgroundIcon.setBounds(0, 25, 1264, 542);
        ImageIcon backgroundImg = new ImageIcon(getClass().getClassLoader().getResource("assets/background.png"));
        backgroundImg = ImageUtils.resizeIcon(backgroundImg, backgroundIcon.getWidth(), backgroundIcon.getHeight());
        backgroundIcon.setIcon(backgroundImg);
        add(backgroundIcon);
    }
}
