/**
 * Layout metrics for 58mm (32 chars) vs 80mm (42 chars) thermal paper.
 */
function getPaperMetrics(paperWidth) {
  const raw = Math.max(24, parseInt(String(paperWidth || 32), 10) || 32);
  const isWide = raw >= 40;
  /** 58mm = 32 cols; 80mm ESC/POS Font A = 48 cols (designer option 42 maps to 48). */
  const chars = isWide ? 48 : 32;
  const qtyPrefixCols = 4;
  const moneyCols = isWide ? 11 : 10;
  const itemNameCols = Math.max(8, chars - qtyPrefixCols - moneyCols);

  return {
    chars,
    isWide,
    qtyPrefixCols,
    itemNameCols,
    moneyCols,
    /** Max logo raster width in pixels */
    logoMaxPx: isWide ? 320 : 200,
    /** QR code raster size in pixels */
    qrMaxPx: isWide ? 220 : 160,
    /** Monospace preview font size (px) */
    previewFontPx: isWide ? 13 : 11,
    /** Receipt paper preview max width */
    previewPaperPx: isWide ? 420 : 300,
    /** Header title uses double width on 80mm only */
    titleDoubleWidth: isWide,
  };
}

module.exports = { getPaperMetrics };
