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

contextBridge.exposeInMainWorld('api', {
  selectDirectory: () => ipcRenderer.invoke('select-directory'),
  selectFile: () => ipcRenderer.invoke('select-file'),
  loadProjects: () => ipcRenderer.invoke('load-projects'),
  saveProject: (project) => ipcRenderer.invoke('save-project', project),
  deleteProject: (projectId) => ipcRenderer.invoke('delete-project', projectId),
  scanPhotos: (dirPath) => ipcRenderer.invoke('scan-photos', dirPath),
  reverseGeocode: (lat, lon) => ipcRenderer.invoke('reverse-geocode', lat, lon),
  wikipediaGeosearch: (lat, lon) => ipcRenderer.invoke('wikipedia-geosearch', lat, lon),
  generateWeb: (project, outputDir) => ipcRenderer.invoke('generate-web', project, outputDir),
  openProjectHtml: (exportPath) => ipcRenderer.invoke('open-project-html', exportPath),
  zipAndOpenNetlify: (folderPath) => ipcRenderer.invoke('zip-and-open-netlify', folderPath),
  openNetlify: () => ipcRenderer.invoke('open-netlify'),
  deployToNetlify: (project, token) => ipcRenderer.invoke('deploy-to-netlify', project, token),
  getNetlifyToken: () => ipcRenderer.invoke('get-netlify-token'),
  readHelpFile: () => ipcRenderer.invoke('read-help-file'),
  importMobileZip: () => ipcRenderer.invoke('import-mobile-zip'),
  
  onGenerationProgress: (callback) => {
    const subscription = (event, progress) => callback(progress);
    ipcRenderer.on('generation-progress', subscription);
    return () => {
      ipcRenderer.removeListener('generation-progress', subscription);
    };
  },
  
  onOpenHelpModal: (callback) => {
    const subscription = () => callback();
    ipcRenderer.on('open-help-modal', subscription);
    return () => {
      ipcRenderer.removeListener('open-help-modal', subscription);
    };
  }
});
