[av_codeblock wrapper_element='html' wrapper_element_attributes='' codeblock_type='' alb_description='' id='' custom_class='' template_class='' av_uid='av-mbfkqpwv' sc_version='1.0']
<!-- Tailwind CSS --><!-- PDF.js library -->

<style>
        body {<br />            font-family: 'Inter', sans-serif;<br />        }<br />        canvas {<br />            display: block;<br />        }<br />        .pdf-link {<br />            text-decoration: none;<br />            display: block;<br />        }<br />    </style>

&nbsp;

<header class="mb-8 text-center">
<h1 class="text-3xl font-bold text-gray-800">Important Facts About Fentanyl and Analogs</h1>
<p class="text-gray-600">Minor changes to the chemical structure can have major effects on how it interacts with your body</p>

</header><!-- Top Two PDF Items -->
<div class="flex justify-center mb-4 md:mb-6"><!-- Outer centering container -->
<!-- Container for the two PDF items in the top row -->
<div id="top-pdf-row-container" class="flex flex-col sm:flex-row gap-4 w-full sm:w-full lg:w-1/2">
<div id="top-pdf-item-slot-1" class="w-full sm:w-1/2"><!-- JS will inject PDF 1 here --></div>
<div id="top-pdf-item-slot-2" class="w-full sm:w-1/2"><!-- JS will inject PDF 2 here --></div>
</div>
</div>
<!-- PDF Grid Container -->
<div id="pdf-grid" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 md:gap-6"><!-- PDF items for the main grid will be populated here by JavaScript --></div>
<script>
        pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.worker.min.js';

        // URLs for the two top PDFs
        const topPdfUrls = [
            'https://sanguen.com/wp-content/uploads/2025/06/Acetylfentanyl-Drug-Information-Sheet.pdf', 
            'https://sanguen.com/wp-content/uploads/2025/06/Fentanyl-Infographic.pdf' 
        ];

        // Array of PDF URLs for the main grid (ensure no overlap with topPdfUrls if desired, or use different ones)
        const gridPdfUrls = [

'https://sanguen.com/wp-content/uploads/2025/06/Methylfentanyl-Infographic.pdf',

'https://sanguen.com/wp-content/uploads/2025/06/Furanylfentanyl-Infographic.pdf',
'https://sanguen.com/wp-content/uploads/2025/06/Butyrfentanyl-Infographic.pdf',
'https://sanguen.com/wp-content/uploads/2025/06/Parafluorofentanyl-Infographic.pdf',

'https://sanguen.com/wp-content/uploads/2025/06/Acrylfentanyl-Infographic.pdf',
'https://sanguen.com/wp-content/uploads/2025/06/Acetylfentanyl-Infographic.pdf',
'https://sanguen.com/wp-content/uploads/2025/06/Cyclopropylfentanyl-Infographic.pdf',
'https://sanguen.com/wp-content/uploads/2025/06/Beta-hydroxythiofentanyl-Infographic.pdf',
        ];

        const topPdfSlot1 = document.getElementById('top-pdf-item-slot-1');
        const topPdfSlot2 = document.getElementById('top-pdf-item-slot-2');
        const pdfGrid = document.getElementById('pdf-grid');

        async function renderPdfPage(pdfUrl, canvasElement, loadingOverlayElement) {
            try {
                loadingOverlayElement.textContent = 'Loading PDF...';
                loadingOverlayElement.classList.remove('hidden');

                const pdf = await pdfjsLib.getDocument(pdfUrl).promise;
                const page = await pdf.getPage(1); 
                const context = canvasElement.getContext('2d');
                
                canvasElement.width = canvasElement.clientWidth;
                canvasElement.height = canvasElement.clientHeight;

                const viewportBase = page.getViewport({ scale: 1 });
                const scaleToFitWidth = canvasElement.width / viewportBase.width;
                const scaleToFitHeight = canvasElement.height / viewportBase.height;
                const scale = Math.min(scaleToFitWidth, scaleToFitHeight);
                const viewport = page.getViewport({ scale: scale });

                const offsetX = (canvasElement.width - viewport.width) / 2;
                const offsetY = (canvasElement.height - viewport.height) / 2;

                context.clearRect(0, 0, canvasElement.width, canvasElement.height);
                context.save();
                context.translate(offsetX, offsetY);

                const renderContext = {
                    canvasContext: context,
                    viewport: viewport
                };
                await page.render(renderContext).promise;
                context.restore();
                loadingOverlayElement.classList.add('hidden');

            } catch (error) {
                console.error(`Error loading PDF ${pdfUrl}:`, error);
                loadingOverlayElement.textContent = 'Error loading PDF';
                loadingOverlayElement.classList.remove('hidden');
                
                const context = canvasElement.getContext('2d');
                context.clearRect(0, 0, canvasElement.width, canvasElement.height);
                context.fillStyle = 'rgb(100,100,100)';
                context.textAlign = 'center';
                context.textBaseline = 'middle';
                let fontSize = Math.min(16, canvasElement.height / 6, canvasElement.width / 10);
                context.font = `${fontSize}px Inter, sans-serif`;
                const shortFileName = pdfUrl.substring(pdfUrl.lastIndexOf('/') + 1);
                const lines = [`Failed to load:`, `${shortFileName.substring(0,20)}${shortFileName.length > 20 ? '...' : ''}`];
                lines.forEach((line, index) => {
                    context.fillText(line, canvasElement.width / 2, canvasElement.height / 2 + (index * (fontSize + 5)) - (lines.length-1)*(fontSize+5)/2);
                });
            }
        }

        function setupPdfItem(pdfUrl, parentElement, uniqueIdSuffix) {
            const anchorLink = document.createElement('a');
            anchorLink.href = pdfUrl;
            anchorLink.target = '_blank'; 
            anchorLink.className = 'pdf-link block'; 
            anchorLink.setAttribute('aria-label', `Open PDF: ${pdfUrl.substring(pdfUrl.lastIndexOf('/') + 1)}`);

            const itemContainer = document.createElement('div');
            itemContainer.className = 'pdf-item-container bg-white rounded-lg shadow-lg overflow-hidden aspect-[8.5/11] relative w-full cursor-pointer hover:shadow-xl transition-shadow duration-200'; 

            const canvas = document.createElement('canvas');
            canvas.className = 'w-full h-full'; 
            canvas.id = `pdf-canvas-${uniqueIdSuffix}`;

            const loadingOverlay = document.createElement('div');
            loadingOverlay.className = 'loading-overlay absolute inset-0 flex items-center justify-center bg-gray-50 bg-opacity-80 text-gray-700 p-2 text-center text-sm';
            loadingOverlay.textContent = 'Initializing...';
            
            itemContainer.appendChild(canvas);
            itemContainer.appendChild(loadingOverlay);
            anchorLink.appendChild(itemContainer);
            parentElement.appendChild(anchorLink); 

            setTimeout(() => {
                if (typeof renderPdfPage === 'function') {
                    renderPdfPage(pdfUrl, canvas, loadingOverlay);
                } else {
                    console.error('renderPdfPage function is not defined when trying to render', pdfUrl);
                    loadingOverlay.textContent = 'Setup Error';
                    loadingOverlay.classList.remove('hidden');
                }
            }, 0);
        }

        // Setup the top PDF items
        if (topPdfSlot1 && topPdfUrls[0]) {
            setupPdfItem(topPdfUrls[0], topPdfSlot1, 'top-1');
        } else {
            console.error('Element with ID "top-pdf-item-slot-1" not found or URL missing.');
        }
        if (topPdfSlot2 && topPdfUrls[1]) {
            setupPdfItem(topPdfUrls[1], topPdfSlot2, 'top-2');
        } else {
            console.error('Element with ID "top-pdf-item-slot-2" not found or URL missing.');
        }


        // Setup PDF items for the grid
        if (pdfGrid) {
            gridPdfUrls.forEach((url, index) => {
                setupPdfItem(url, pdfGrid, `grid-${index + 1}`);
            });
        } else {
            console.error('Element with ID "pdf-grid" not found.');
        }

        // Optional: Re-render PDFs on window resize (commented out, needs adjustment for two top items)
        /*
        let resizeTimeout;
        window.addEventListener('resize', () => {
            clearTimeout(resizeTimeout);
            resizeTimeout = setTimeout(() => {
                // Re-render top PDFs
                [topPdfSlot1, topPdfSlot2].forEach((slot, i) => {
                    if (slot && slot.firstChild && slot.firstChild.firstChild && topPdfUrls[i]) { 
                        const canvas = slot.firstChild.firstChild.querySelector('canvas');
                        const loadingOverlay = slot.firstChild.firstChild.querySelector('.loading-overlay');
                        if(canvas && loadingOverlay) {
                            loadingOverlay.textContent = 'Resizing...';
                            loadingOverlay.classList.remove('hidden');
                            setTimeout(() => renderPdfPage(topPdfUrls[i], canvas, loadingOverlay), 0);
                        }
                    }
                });
                
                // Re-render grid PDFs
                document.querySelectorAll('#pdf-grid .pdf-link').forEach((anchor, index) => { 
                    if (anchor.firstChild) { 
                        const canvas = anchor.firstChild.querySelector('canvas');
                        const loadingOverlay = anchor.firstChild.querySelector('.loading-overlay');
                        if (canvas && gridPdfUrls[index]) {
                            loadingOverlay.textContent = 'Resizing...';
                            loadingOverlay.classList.remove('hidden');
                            setTimeout(() => renderPdfPage(gridPdfUrls[index], canvas, loadingOverlay), 0);
                        }
                    }
                });
            }, 250); 
        });
        */
    </script>

[/av_codeblock]