import {app, BrowserWindow} from 'electron';
import {getPreloadPath, getUIPath, inDevelopment} from './utils.js';
import {ipcMain} from 'electron/main';
import {ProdressConnection} from './pdr2com/connection.js';

app.on('ready', async () => {
  const mainWindow = new BrowserWindow({
    webPreferences: {
      preload: getPreloadPath(),
    },
  }); //@todo
  if (inDevelopment()) {
    mainWindow.loadURL('http://localhost:5123/');
  } else {
    mainWindow.loadFile(getUIPath());
  }

  ipcMain.handle('ping', () => {
    const req = new ProdressConnection(
      {
        port: 4788,
        host: 'localhost',
        database: 'test',
        handler: 'Shopify',
        action: 'artikelSync',
      },
      [['string', 'HalloWelt']],
      [
        ['line1', 'string'],
        ['line2', 'string'],
      ],
    );
    return req.handleRequest();
  });
});
