const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('electronAPI', {
    copyToClipboard: (text) => ipcRenderer.invoke('clipboard-write', text),
    getConfig: () => ipcRenderer.invoke('get-config'),
    storageGet: (key) => ipcRenderer.invoke('storage-get', key),
    storageSet: (key, value) => ipcRenderer.invoke('storage-set', key, value),
    storageRemove: (key) => ipcRenderer.invoke('storage-remove', key),
    getUpdateState: () => ipcRenderer.invoke('get-update-state'),
    checkForUpdatesNow: () => ipcRenderer.invoke('check-for-updates-now'),
    checkForUpdates: () => ipcRenderer.send('check-for-updates'),
    downloadUpdate: () => ipcRenderer.send('download-update'),
    quitAndInstall: () => ipcRenderer.send('quit-and-install'),
    onUpdateState: (callback) => ipcRenderer.on('update-state', (event, state) => callback(state)),
    onUpdateAvailable: (callback) => ipcRenderer.on('update-available', (event, info) => callback(info)),
    onUpdateDownloaded: (callback) => ipcRenderer.on('update-downloaded', (event, info) => callback(info)),
    onUpdateError: (callback) => ipcRenderer.on('update-error', (event, error) => callback(error))
});
