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

contextBridge.exposeInMainWorld('api', {
  selectFolder:       ()         => ipcRenderer.invoke('select-folder'),
  listImages:         (folder)   => ipcRenderer.invoke('list-images', folder),
  readImage:          (path)     => ipcRenderer.invoke('read-image', path),
  renameFiles:        (args)     => ipcRenderer.invoke('rename-files', args),
  onFullscreenChange: (() => {
    let _cb = null;
    ipcRenderer.on('fullscreen-change', (_e, v) => { if (_cb) _cb(v); });
    return (callback) => { _cb = callback; };
  })(),
  getHomeDir:         ()         => ipcRenderer.invoke('get-home-dir'),
  getLastFolder:      ()         => ipcRenderer.invoke('get-last-folder'),
  setLastFolder:      (p)        => ipcRenderer.invoke('set-last-folder', p),
  listDirectories:    (p)        => ipcRenderer.invoke('list-directories', p),
  revealFolder:       (p)        => ipcRenderer.invoke('reveal-folder', p),
  getPreviewOn:       ()         => ipcRenderer.invoke('get-preview-on'),
  setPreviewOn:       (on)       => ipcRenderer.invoke('set-preview-on', on),
  checkFilesExist:    (folder, names) => ipcRenderer.invoke('check-files-exist', folder, names),
  moveFiles:          (args)     => ipcRenderer.invoke('move-files', args),
});
