// Helper to manage dynamic print styles
window.setupPrintConfig = (type, labelCount) => {
    // Remove existing print style if any
    const existing = document.getElementById('dynamic-print-style');
    if (existing) existing.remove();

    const style = document.createElement('style');
    style.id = 'dynamic-print-style';
    style.type = 'text/css';

    let css = '';
    
    switch (type) {
        case 'label':
            // 58mm x 40mm Label
            css = `
                @page { 
                    size: 58mm 40mm !important; 
                    margin: 0 !important; 
                }
                html, body { 
                    width: 58mm !important;
                    margin: 0 !important;
                    padding: 0 !important;
                    height: auto !important;
                    min-height: 0 !important;
                    overflow: visible !important;
                    background: white !important;
                }
                /* Hide everything except print-area */
                body > *:not(#print-area) {
                    display: none !important;
                }
                #print-area {
                    display: block !important;
                    visibility: visible !important;
                    position: static !important;
                    width: 58mm !important;
                    height: auto !important;
                    margin: 0 !important;
                    padding: 0 !important;
                }
                #print-area * {
                    visibility: visible !important;
                }
            `;
            break;
            
        case 'receipt':
            // 80mm Receipt (Continuous)
            css = `
                @page { 
                    size: 80mm auto !important; 
                    margin: 0 !important; 
                }
                html, body { 
                    width: 80mm !important; 
                    margin: 0 !important;
                    padding: 0 !important;
                    background: white !important;
                    height: auto !important;
                }
                /* Hide everything except receipt-print-area */
                body > *:not(#receipt-print-area) {
                    display: none !important;
                }
                #receipt-print-area {
                    display: block !important;
                    visibility: visible !important;
                    position: static !important;
                    width: 100% !important;
                    margin: 0 !important;
                    padding: 0 !important;
                }
                #receipt-print-area * {
                    visibility: visible !important;
                }
            `;
            break;
            
        case 'a4':
            css = `
                @page { size: A4; margin: 10mm; }
                body { width: 100%; }
            `;
            break;
    }

    style.innerHTML = `@media print { ${css} }`;
    document.head.appendChild(style);
};