// generateBarcode.jsx
import bwipjs from 'bwip-js';

export const generateBarcode = (canvasRef, barcodeValue) => {
    if (!canvasRef.current) {
        console.error('Canvas reference is not valid');
        return;
    }

    try {
        bwipjs.toCanvas(canvasRef.current, {
            bcid: 'code128',       // Barcode type
            text: barcodeValue,    // Text to encode
            scale: 3,              // 3x scaling factor
            height: 10,            // Bar height, in millimeters
            includetext: true,     // Show human-readable text
            textxalign: 'center',  // Always good to set this
        });
    } catch (err) {
        console.error('Error generating barcode:', err);
    }
};
