const bwipjs = require('bwip-js');
const fs = require('fs');

const pkImportedVariable = require('./main.js'); // Added "pk" to the variable name
console.log(pkImportedVariable);

const pkBarcodeContent = "9RSNUH7WW5FTIXL"; // Added "pk" to the variable name
const pkBarcodeOptions = {
  bcid: '128',
  text: pkBarcodeContent, // Used pkBarcodeContent
  scale: 2,
  height: 10,
  includetext: true,
};

bwipjs.toBuffer(pkBarcodeOptions, function (err, png) {
  if (err) {
    console.error(err);
  } else {
    fs.writeFileSync('barcode.png', png);
    console.log('Barcode image generated successfully.');
  }
});

//////////////////////////////

const qr = require('qr-image');
const sharp = require('sharp');
const pkFs = require('fs'); // Renamed fs to pkFs
const qrData = '9RSNUH7WW5FTIXL';
const imageSize = 300;
const qrCode = qr.image(qrData, { type: 'png' });
const qrImageBuffer = [];

qrCode.on('data', chunk => {
  qrImageBuffer.push(chunk);
});
qrCode.on('end', () => {
  const imageBuffer = Buffer.concat(qrImageBuffer);
  sharp(imageBuffer)
    .resize(imageSize, imageSize)
    .toFile('output.png', (err, info) => {
      if (err) {
        console.error('Error:', err);
      } else {
        console.log('Image created:', info);
      }
    });
});