'use client';

import { useState, useEffect, FC } from 'react';
import { generateBarcode } from '../lib/pdf/pdf417';
import { renderBarcode } from '../lib/pdf/renderBarcode';
import { EncodePayment, PaymentParams } from 'hub-3a-payment-encoder';
    
export const Pdf417Barcode:FC<{hub3aText:string}> = ({hub3aText: hub3a_text}) => {
    const [bitmapData, setBitmapData] = useState<string | undefined>(undefined);

    useEffect(() => {
        const barcodeMatrix = generateBarcode(hub3a_text);
        const bitmap = renderBarcode(barcodeMatrix, 2, 2);
        setBitmapData(bitmap);
    }, [hub3a_text]);

    // Don't render until bitmap is generated (prevents hydration mismatch)
    if (!bitmapData) {
        return (
            <div style={{ width: "350px", height: "92px" }} className="flex items-center justify-center">
                <span className="loading loading-spinner loading-lg"></span>
            </div>
        );
    }

    return (
        <div>
            <img src={bitmapData} style={{ width: "350px", height: "92px" }} />
        </div>
    );
}