package tech.nevets.tvpn.ui;

import tech.nevets.tvpn.LogOutputStream;

import javax.swing.*;

public class UIManager {
    private final JFrame frame;
    private final JTabbedPane tabPane;

    private JFrame loginFrame;
    private final HomePanel homePanel;

    public UIManager(LogOutputStream logOut) {
        frame = new JFrame();
        tabPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);

        homePanel = new HomePanel();
        tabPane.addTab("Home", homePanel);
        tabPane.addTab("Logs", new LogsPanel(logOut));

        frame.add(tabPane);
        frame.pack();
        frame.setSize(720, 480);
        frame.setTitle("TVPN");
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        SwingUtilities.updateComponentTreeUI(frame);
        frame.setVisible(true);
    }

    public void startLoginFrame() {
        loginFrame = new JFrame();
        JPanel p = new LoginPanel(this);
        loginFrame.add(p);
        loginFrame.pack();
        loginFrame.setTitle("Login");
        loginFrame.setSize(340, 170);
        loginFrame.setResizable(false);
        loginFrame.setLocationRelativeTo(null);
        loginFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        loginFrame.setVisible(true);
    }

    protected void disposeLoginFrame() {
        loginFrame.dispose();
    }

    protected HomePanel getUIPanel() {
        return homePanel;
    }

}
