import {app, BrowserWindow} from 'electron';
import path from 'path';
import {ProdressConnection} from './pdr2com/connection.js';

const APPLICATION_PATH = path.join(app.getAppPath(), '/dist-svelte/index.html');

app.on('ready', async () => {
  const mainWindow = new BrowserWindow({}); //@todo
  if (process.env.NODE_ENV === 'development') {
    mainWindow.loadURL('http://localhost:5123/');
  } else {
    mainWindow.loadFile(APPLICATION_PATH);
  }

  const req = new ProdressConnection(
    {
      port: 4788,
      host: 'localhost',
      database: 'test',
      handler: 'Shopify',
      action: 'artikelSync',
    },
    [['string', 'HalloWelt']],
    [
      ['line1', 'string'],
      ['line2', 'string'],
    ],
  );
  const res = await req.handleRequest();
  console.log(res);
  // try {
  //   const socket = new Socket();
  //   socket.connect(4788, 'localhost');
  //
  //   const test = new ProdressRequest('db', 'handler', 'aktion');
  //   test.schreibeText('HalloWelt 2355435');
  //   socket.on('connect', () => {
  //     console.log('verbunden');
  //     test.sende(socket);
  //   });
  //   const r2reader = new RequestLeser();
  //   socket.on('data', (data: Buffer) => {
  //     r2reader.verarbeiteDaten(data);
  //   });
  //   const r2request = await r2reader.leseRequest();
  //   console.log(r2request.nächsterText());
  // } catch (error) {
  //   console.error(error);
  // }
});
