package tech.nevets.jaml.gui;

import tech.nevets.jaml.gui.panels.HomePanel;
import tech.nevets.jaml.gui.panels.ProfilePanel;
import tech.nevets.jaml.gui.panels.UsersPanel;
import tech.nevets.jaml.listeners.RightClickListener;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class HomeGui extends JFrame {

    private JTabbedPane tabPanel;
    private HomePanel homePanel;
    private ProfilePanel profilePanel;
    private UsersPanel userPanel;


    public HomeGui() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize((int) (GuiHandler.SCREEN_WIDTH / 1.5), (int) (GuiHandler.SCREEN_HEIGHT / 1.5));
        SpringLayout springLayout = new SpringLayout();
        getContentPane().setLayout(springLayout);
        addMouseListener(new RightClickListener());
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                removeFromArray();
            }
        });

        tabPanel = new JTabbedPane();
        springLayout.putConstraint(SpringLayout.NORTH, tabPanel, 0, SpringLayout.NORTH, getContentPane());
        springLayout.putConstraint(SpringLayout.WEST, tabPanel, 0, SpringLayout.WEST, getContentPane());
        springLayout.putConstraint(SpringLayout.SOUTH, tabPanel, 720, SpringLayout.NORTH, getContentPane());
        springLayout.putConstraint(SpringLayout.EAST, tabPanel, 1280, SpringLayout.WEST, getContentPane());
        tabPanel.setBorder(new EmptyBorder(5, 5, 5, 5));


        homePanel = new HomePanel();
        tabPanel.add("Home", homePanel);

        profilePanel = new ProfilePanel();
        tabPanel.add("Profiles", profilePanel);

        userPanel = new UsersPanel();
        tabPanel.add("Users", userPanel);

        getContentPane().add(tabPanel);

        tabPanel.addMouseListener(new RightClickListener());

    }

    private void removeFromArray() {
        GuiHandler.removeFromFramesArray(this);
    }
}
