import { useEffect, useState } from "react";

interface WindowState {
    isMinimized: boolean;
    isMaximized: boolean;
    isFullScreen: boolean;
    isVisible: boolean;
    isFocused: boolean;
    isResizable: boolean;
    isClosable: boolean;
    isDestroyed: boolean;
    bounds: any;
}

export function useWindowState() : WindowState {
    const [windowState, setWindowState] = useState<WindowState>({
        isMinimized: false,
        isMaximized: false,
        isFullScreen: false,
        isVisible: false,
        isFocused: false,
        isResizable: false,
        isClosable: false,
        isDestroyed: false,
        bounds: {}
    });
    useEffect(() => {
        window.electron.ipcRenderer.on('window-state-changed', () => {
            window.electron.ipcRenderer.invoke('window-state').then((state) => {
                setWindowState(state);
            });
        });
        window.electron.ipcRenderer.invoke('window-state').then((state) => {
            setWindowState(state);
        });
    }, []);
    
    return windowState;
}