const resolveBridge = () => {
    const globalWithBridge = window;
    return (globalWithBridge.electron?.ipcRenderer ??
        globalWithBridge.ipcRenderer ??
        null) ?? {
        invoke: async () => {
            throw new Error('ipcRenderer bridge is not available in the renderer context');
        }
    };
};
export const ipcRenderer = new Proxy({}, {
    get(_target, prop, receiver) {
        const bridge = resolveBridge();
        const value = Reflect.get(bridge, prop, receiver);
        return typeof value === 'function' ? value.bind(bridge) : value;
    },
});
export const contextBridge = {
    exposeInMainWorld: () => {
        throw new Error('contextBridge is not available in the renderer process');
    },
};
const createUnavailableProxy = (name) => {
    const target = (() => {
        throw new Error(`${name} is not available in the renderer process`);
    });
    return new Proxy(target, {
        apply() {
            throw new Error(`${name} is not available in the renderer process`);
        },
        get(_target, prop) {
            if (prop === 'then') {
                return undefined;
            }
            if (prop === Symbol.toStringTag) {
                return 'Function';
            }
            return createUnavailableProxy(`${name}.${String(prop)}`);
        },
    });
};
export const ipcMain = createUnavailableProxy('ipcMain');
export const app = createUnavailableProxy('app');
export const BrowserWindow = createUnavailableProxy('BrowserWindow');
export const nativeImage = createUnavailableProxy('nativeImage');
export const clipboard = createUnavailableProxy('clipboard');
export const Menu = createUnavailableProxy('Menu');
export const MenuItem = createUnavailableProxy('MenuItem');
export const dialog = createUnavailableProxy('dialog');
export const shell = createUnavailableProxy('shell');
export const webContents = createUnavailableProxy('webContents');
const electronModule = {
    ipcRenderer,
    contextBridge,
    ipcMain,
    app,
    BrowserWindow,
    nativeImage,
    clipboard,
    Menu,
    MenuItem,
    dialog,
    shell,
    webContents,
};
export default electronModule;
