//
//  Ventry_Upload_WatcherApp.swift
//  Ventry Upload Watcher
//
//  Created by Jan-Marlon Leibl on 18.01.25.
//

import SwiftUI
import AppKit

@main
struct Ventry_Upload_WatcherApp: App {
    // MARK: - Properties
    // MARK: - Scene
    var body: some Scene {
        WindowGroup {
            ContentView()
                .fixedSize()
        }
        .windowResizability(.contentSize)
        
        MenuBarExtra {
            menuContent
        } label: {
            menuIcon
        }
    }
    
    // MARK: - Menu Components
    @ViewBuilder
    private var menuContent: some View {
        Button("Show Window") {
            NSApp.activate(ignoringOtherApps: true)
            NSApp.windows.first?.makeKeyAndOrderFront(nil)
        }
        
        Divider()
        
        Button("Quit") {
            NSApplication.shared.terminate(nil)
        }
        .keyboardShortcut("q")
    }
    
    @ViewBuilder
    private var menuIcon: some View {
        if let nsImage = NSImage(named: "ventry-logo-white") {
            Image(nsImage: nsImage)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 16, height: 16)
        }
    }
}
