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

try {
    contextBridge.exposeInMainWorld("explorer", {
        onFileDrop: (file) => webUtils.getPathForFile(file)
    })
    contextBridge.exposeInMainWorld("submit", {
        submit: (meeting_specifications) => { ipcRenderer.send("file_submit", meeting_specifications) }
    })
    contextBridge.exposeInMainWorld("electronAPI", {
        getFilePath: (file) => { return webUtils.getPathForFile(file) }
    })

    contextBridge.exposeInMainWorld("onStartup", {
        getModuleNames: () => ipcRenderer.invoke('get-module-names')
    })

    contextBridge.exposeInMainWorld('electron', {
        progress: (callback) => ipcRenderer.on('progress', callback)
    })

    contextBridge.exposeInMainWorld('audios', {
        speakerAudios: (callback) => ipcRenderer.on('speakerAudios', callback)
    })
    contextBridge.exposeInMainWorld("submitSpeaker", {
        speaker_submit: (speaker_names) => { ipcRenderer.send("speaker_submit", speaker_names) }
    })

    contextBridge.exposeInMainWorld("download", {
        file_download: () => { ipcRenderer.send("file_download") }
    })
    
    //documenttypes 
    contextBridge.exposeInMainWorld('api', {
        getTxtFiles: () => ipcRenderer.invoke('get-txt-files'),
        saveTxtFile: (name, content) =>
            ipcRenderer.invoke('save-txt-file', name, content),
        readTxtFile: (fileName) =>
            ipcRenderer.invoke('read-txt-file', fileName),
        deleteTxtFile: (fileName) =>
            ipcRenderer.invoke('delete-txt-file', fileName)
    });


    ipcRenderer.on("error", (event, err) => { alert(err) })
} catch (error) {
    console.log("Error in preload.js");
}
