/**
 * Debugging utilities for symbol rendering in PDFs.
 */

import { detectSymbols, splitTextBySymbols } from './symbolRenderer';

export const logFontStatus = (doc) => {
  if (!doc) return;
  const fonts = doc.getFontList();
  console.log('PDF Debug: Registered Fonts:', fonts);
  const hasNoto = Object.keys(fonts).some(f => f.toLowerCase().includes('noto'));
  console.log(`PDF Debug: NotoSymbols available? ${hasNoto ? 'YES' : 'NO'}`);
};

export const verifySymbolRendering = (text) => {
  const hasSymbols = detectSymbols(text);
  console.log(`PDF Debug: Text "${text.substring(0, 20)}..." contains symbols? ${hasSymbols ? 'YES' : 'NO'}`);
  if (hasSymbols) {
    const segments = splitTextBySymbols(text);
    console.log('PDF Debug: Segments:', segments);
  }
  return hasSymbols;
};

export const logSymbolDetection = (text) => {
  if (!text) return;
  const segments = splitTextBySymbols(text);
  const symbolsFound = segments.filter(s => s.isSymbol).map(s => s.text);
  if (symbolsFound.length > 0) {
    console.log('PDF Debug: Symbols detected in text:', symbolsFound);
  }
};

export const testSymbolRendering = (doc, x = 10, y = 10) => {
  console.log('PDF Debug: Running visual symbol test on PDF...');
  try {
    const testStr = "Test Check: ☑ Box: ☐ Bullet: • Dash: —";
    doc.setFontSize(12);
    doc.setTextColor(255, 0, 0);
    
    const segments = splitTextBySymbols(testStr);
    let curX = x;
    
    segments.forEach(seg => {
        if (seg.isSymbol) {
            doc.setFont('NotoSymbols', 'normal');
        } else {
            doc.setFont('Helvetica', 'normal');
        }
        doc.text(seg.text, curX, y);
        curX += doc.getTextWidth(seg.text);
    });
    
    doc.setTextColor(0, 0, 0);
    console.log('PDF Debug: Visual test complete.');
  } catch (e) {
    console.error('PDF Debug: Visual test failed', e);
  }
};
