/**
 * Utilities for testing font rendering and loading.
 */
import { loadFontForPdf, registerFontWithJsPdf } from './fontPdfLoader';
import { loadGoogleFonts } from './googleFontsManager';
import { jsPDF } from 'jspdf';

export const testFontLoading = async (fontName) => {
    console.log(`Testing loading for ${fontName}...`);
    try {
        const base64 = await loadFontForPdf(fontName, 'Regular');
        if (base64) {
            console.log(`✅ Successfully loaded ${fontName} (Length: ${base64.length})`);
            return true;
        } else {
            console.error(`❌ Failed to load ${fontName} - returned null`);
            return false;
        }
    } catch (e) {
        console.error(`❌ Exception loading ${fontName}:`, e);
        return false;
    }
};

export const testPdfRendering = async (fontName) => {
    const doc = new jsPDF();
    const base64 = await loadFontForPdf(fontName, 'Regular');
    
    if (base64) {
        registerFontWithJsPdf(doc, fontName, base64, 'normal');
        doc.setFont(fontName, 'normal');
        doc.setFontSize(20);
        doc.text(`Testing ${fontName}`, 10, 20);
        doc.setFontSize(12);
        doc.text("The quick brown fox jumps over the lazy dog.", 10, 30);
        doc.text("1234567890 !@#$%^&*()", 10, 40);
        doc.save(`test_${fontName}.pdf`);
        return true;
    }
    return false;
};

export const testSymbolRendering = (doc) => {
    // Assumes NotoSymbols is registered
    doc.setFont('NotoSymbols', 'normal');
    doc.text("☐ ☑ ☒ ✓ ✔ • ◦ ▪ – —", 10, 50);
};