package tech.nevets.dlite;

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLightLaf;

import javax.swing.*;
import java.awt.*;

public class Main {
    private static final FlatDarkLaf DARK_LAF = new FlatDarkLaf();
    private static final FlatLightLaf LIGHT_LAF = new FlatLightLaf();
    //private static TrayIcon trayIcon;
    private static JFrame frame;

    public static void main(String[] args) {
        //startTrayService();
        startUI();
    }

    public static void startUI() {
        ChatWindow window = new ChatWindow();
        frame = new JFrame();
        frame.add(window);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setTitle("Discord Lite");
        frame.setIconImage(Toolkit.getDefaultToolkit().createImage(Main.class.getResource("/icon.png")));
        frame.setLocationRelativeTo(null);
        window.requestFocus();
        setDarkMode(true);
        frame.setVisible(true);
    }

    public static JFrame getFrame() {
        return frame;
    }

    public static void setDarkMode(boolean darkMode) {
        try {
            if (darkMode) {
                UIManager.setLookAndFeel(DARK_LAF);
            } else {
                UIManager.setLookAndFeel(LIGHT_LAF);
            }
            SwingUtilities.updateComponentTreeUI(frame);
        } catch (UnsupportedLookAndFeelException e) {
            Notifier.errorPopup("Error Setting Look and Feel", e.getMessage());
        }
    }

//    private static void startTrayService() {
//        SystemTray sysTray = SystemTray.getSystemTray();
//        Image img = Toolkit.getDefaultToolkit().createImage(Main.class.getResource("/icon.png"));
//        trayIcon = new TrayIcon(img, "Discord Lite");
//        trayIcon.setImageAutoSize(true);
//        PopupMenu menu = new PopupMenu("Discord Lite");
//        menu.add("Open Window");
//        menu.add("Exit");
//        menu.addActionListener(al -> {
//            switch (al.getActionCommand().toLowerCase()) {
//                case "open window" -> startUI();
//                case "exit" -> System.exit(0);
//            }
//        });
//        trayIcon.setPopupMenu(menu);
//        try {
//            sysTray.add(trayIcon);
//        } catch (AWTException e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static void sendNotification(String title, String message) {
//        trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO);
//    }
}
