`);
printWindow.document.close(); // Close the document to allow rendering
printWindow.focus(); // Focus on the new window
printWindow.print(); // Trigger the print
printWindow.close(); // Close the print window after printing
});
// Download button functionality using html2canvas
const downloadButton = document.getElementById('pos-download-button');
downloadButton.addEventListener('click', function() {
// Ensure SVG is properly handled by html2canvas
const svgElement = document.querySelector('.pos-logo');
if (svgElement) {
svgElement.setAttribute("width", "150px");
svgElement.setAttribute("height", "auto");
svgElement.setAttribute("fill", "currentColor");
}
html2canvas(document.getElementById('pos-product-details')).then(canvas => {
const skuElement = document.getElementById('pos-product-sku');
const sku = skuElement && skuElement.textContent ? skuElement.textContent.replace('SKU: ', '').trim() : 'product-details';
const link = document.createElement('a');
link.href = canvas.toDataURL('image/jpeg', 1.0);
link.download = `${sku}.jpg`;
link.click();
});
});