/**
 * View Malicious File - Syntax Highlighting and Auto-scroll
 * 
 * @package VMPFence
 * @since 1.0.0
 */

// Add some basic syntax highlighting for PHP
document.addEventListener('DOMContentLoaded', function() {
    const codeContent = document.querySelector('.code-content');
    
    // Check if file is PHP (data attribute set by PHP)
    const isPhpFile = document.body.dataset.isPhp === 'true';
    
    if (codeContent && isPhpFile) {
        // Apply syntax highlighting to non-highlighted lines only
        const codeLines = codeContent.querySelectorAll('.code-line:not(.highlighted)');
        codeLines.forEach(function(line) {
            let html = line.innerHTML;
            // Basic PHP syntax highlighting
            html = html.replace(/(&lt;\?php|\?&gt;)/g, '<span style="color: #0000BB; font-weight: bold;">$1</span>');
            html = html.replace(/(\$[a-zA-Z_][a-zA-Z0-9_]*)/g, '<span style="color: #FF8000;">$1</span>');
            html = html.replace(/(function|class|if|else|foreach|for|while|return|echo|print|include|require)/g, '<span style="color: #007700; font-weight: bold;">$1</span>');
            html = html.replace(/(&quot;[^&]*&quot;|&#039;[^&]*&#039;)/g, '<span style="color: #DD0000;">$1</span>');
            line.innerHTML = html;
        });
    }
    
    // Auto-scroll to highlighted line if it exists
    const highlightedLineId = document.body.dataset.highlightedLine;
    if (highlightedLineId && parseInt(highlightedLineId) > 0) {
        const highlightedLine = document.getElementById('code-line-' + highlightedLineId);
        if (highlightedLine) {
            setTimeout(function() {
                highlightedLine.scrollIntoView({ 
                    behavior: 'smooth', 
                    block: 'center' 
                });
                
                // Add a subtle pulsing animation to draw attention
                highlightedLine.style.animation = 'pulse 2s ease-in-out 3';
            }, 500);
        }
    }
});

// Add pulse animation
const style = document.createElement('style');
style.textContent = `
    @keyframes pulse {
        0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7); }
        50% { box-shadow: 0 0 0 10px rgba(255, 107, 107, 0.3); }
        100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
    }
`;
document.head.appendChild(style);
