<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ $errorClass }}: {{ $errorMessage }}</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background: #1a202c;
            color: #e2e8f0;
            line-height: 1.6;
            padding: 20px;
        }

        .debug-container {
            max-width: 1400px;
            margin: 0 auto;
        }

        .error-header {
            background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
            border-radius: 12px;
            padding: 32px;
            margin-bottom: 24px;
            box-shadow: 0 4px 20px rgba(220, 38, 38, 0.3);
            position: relative;
            overflow: hidden;
        }

        .error-header::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
            pointer-events: none;
        }

        .error-class {
            font-size: 28px;
            font-weight: 700;
            color: white;
            margin-bottom: 12px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
            position: relative;
        }

        .error-message {
            font-size: 18px;
            color: #fef3c7;
            margin-bottom: 16px;
            font-weight: 500;
            position: relative;
        }

        .error-location {
            font-family: 'Fira Code', 'Courier New', Courier, monospace;
            font-size: 14px;
            color: #fecaca;
            background: rgba(0, 0, 0, 0.3);
            padding: 12px 16px;
            border-radius: 8px;
            border-left: 4px solid #fbbf24;
            position: relative;
        }

        .error-location strong {
            color: #fbbf24;
            font-weight: 600;
        }

        .section {
            background: #2d3748;
            border-radius: 12px;
            padding: 24px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        }

        .section-title {
            font-size: 18px;
            font-weight: 600;
            color: #f7fafc;
            margin-bottom: 16px;
            padding-bottom: 12px;
            border-bottom: 2px solid #4a5568;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .section-title.collapsible {
            cursor: pointer;
            user-select: none;
        }

        .section-title.collapsible:hover {
            color: #667eea;
        }

        .collapse-icon {
            font-size: 20px;
            transition: transform 0.3s;
            color: #a0aec0;
        }

        .section-title.collapsed .collapse-icon {
            transform: rotate(-90deg);
        }

        .section-content {
            max-height: 2000px;
            overflow: hidden;
            transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
            opacity: 1;
        }

        .section-content.collapsed {
            max-height: 0;
            opacity: 0;
        }

        .meta-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 16px;
        }

        .meta-item {
            background: #1a202c;
            padding: 12px;
            border-radius: 6px;
            border-left: 3px solid #667eea;
        }

        .meta-label {
            font-size: 12px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: #a0aec0;
            margin-bottom: 4px;
        }

        .meta-value {
            font-family: 'Courier New', Courier, monospace;
            color: #e2e8f0;
            font-size: 14px;
            word-break: break-all;
        }

        .code-preview {
            position: relative;
            margin-bottom: 20px;
        }

        /* Stelle sicher, dass Highlighter-Output nicht überschrieben wird */
        .code-preview > * {
            margin: 0;
        }

        /* Fallback für Code-Darstellung wenn Highlighter fehlt */
        .code-preview pre {
            background: #2b2b2b;
            color: #a9b7c6;
            padding: 16px;
            border-radius: 8px;
            overflow-x: auto;
            font-family: 'Fira Code', 'Consolas', monospace;
            font-size: 14px;
            line-height: 1.5;
            white-space: pre;
            tab-size: 4;
        }

        .code-preview code {
            font-family: 'Fira Code', 'Consolas', monospace;
            white-space: pre;
        }

        /* Copy Button für Code */
        .copy-button {
            position: absolute;
            top: 12px;
            right: 12px;
            background: #4a5568;
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 6px;
            font-size: 12px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            z-index: 10;
        }

        .copy-button:hover {
            background: #667eea;
            transform: translateY(-2px);
        }

        .copy-button:active {
            transform: translateY(0);
        }

        .copy-button.copied {
            background: #48bb78;
        }

        .copy-button.copied::after {
            content: ' ✓';
        }

        .trace-item {
            background: #1a202c;
            padding: 16px;
            margin-bottom: 8px;
            border-radius: 6px;
            border-left: 3px solid #4a5568;
            transition: all 0.2s;
        }

        .trace-item:hover {
            background: #283141;
            border-left-color: #667eea;
        }

        .trace-item.origin {
            border-left-color: #dc2626;
            border-left-width: 4px;
            background: linear-gradient(90deg, rgba(220, 38, 38, 0.15) 0%, #2d1f1f 100%);
            box-shadow: 0 0 20px rgba(220, 38, 38, 0.2);
        }

        .trace-item.origin::before {
            content: '⚠️';
            position: absolute;
            left: -12px;
            top: 50%;
            transform: translateY(-50%);
            font-size: 20px;
        }

        .trace-index {
            display: inline-block;
            background: #4a5568;
            color: white;
            padding: 4px 10px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 600;
            margin-right: 8px;
        }

        .trace-item.origin .trace-index {
            background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
            box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
        }

        .trace-function {
            font-family: 'Courier New', Courier, monospace;
            color: #9ae6b4;
            font-size: 14px;
            margin-bottom: 4px;
        }

        .trace-location {
            font-family: 'Courier New', Courier, monospace;
            color: #90cdf4;
            font-size: 13px;
        }

        .trace-filter {
            margin-bottom: 16px;
            display: flex;
            gap: 12px;
            align-items: center;
        }

        .trace-filter input {
            flex: 1;
            background: #1a202c;
            border: 2px solid #4a5568;
            color: #e2e8f0;
            padding: 10px 16px;
            border-radius: 8px;
            font-size: 14px;
            font-family: 'Courier New', Courier, monospace;
            transition: border-color 0.2s;
        }

        .trace-filter input:focus {
            outline: none;
            border-color: #667eea;
        }

        .trace-filter-label {
            color: #a0aec0;
            font-size: 14px;
            font-weight: 500;
        }

        .trace-stats {
            color: #a0aec0;
            font-size: 13px;
            padding: 8px 12px;
            background: #1a202c;
            border-radius: 6px;
        }

        .dependency-info {
            background: #78350f;
            border: 2px solid #fbbf24;
            border-radius: 8px;
            padding: 16px;
            margin-bottom: 20px;
        }

        .dependency-info h3 {
            color: #fbbf24;
            margin-bottom: 8px;
        }

        @media (max-width: 768px) {
            .meta-grid {
                grid-template-columns: 1fr;
            }

            .error-header {
                padding: 20px;
            }

            .section {
                padding: 16px;
            }
        }
    </style>
</head>
<body>
    <div class="debug-container">
        <!-- Error Header -->
        <div class="error-header">
            <div class="error-class">⚠️ {{ $errorClass }}</div>
            <div class="error-message">{{ $errorMessage }}</div>
            <div class="error-location">
                <strong>📁 File:</strong> {{ $errorFile }}<br>
                <strong>📍 Line:</strong> {{ $errorLine }}
            </div>
        </div>

        <!-- Dependency Info (if available) -->
        <div if="{{ $dependencyInfo }}">
            {{ $dependencyInfo }}
        </div>

        <!-- Request Information -->
        <div class="section">
            <h2 class="section-title collapsible collapsed" onclick="toggleSection('request-info')">
                <span>📋 Request Information</span>
                <span class="collapse-icon">▼</span>
            </h2>
            <div class="section-content collapsed" id="request-info-content">
                <div class="meta-grid">
                <div class="meta-item">
                    <div class="meta-label">Request ID</div>
                    <div class="meta-value">{{ $requestId }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">HTTP Status</div>
                    <div class="meta-value">{{ $httpStatus }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Method</div>
                    <div class="meta-value">{{ $requestMethod }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">URI</div>
                    <div class="meta-value">{{ $requestUri }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Client IP</div>
                    <div class="meta-value">{{ $clientIp }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Timestamp</div>
                    <div class="meta-value">{{ $timestamp }}</div>
                </div>
            </div>
            </div>
        </div>

        <!-- Code Preview -->
        <div class="section">
            <h2 class="section-title">💻 Code Context</h2>
            <div class="code-preview" id="code-container">
                <button class="copy-button" onclick="copyCode()" id="copy-code-btn">Copy Code</button>
                {{ $code }}
            </div>
        </div>

        <!-- Stack Trace -->
        <div class="section" if="{{ $traceCount > 0 }}">
            <h2 class="section-title collapsible" onclick="toggleSection('stack-trace')">
                <span>📚 Stack Trace (<span id="trace-count">{{ $traceCount }}</span> frames)</span>
                <span class="collapse-icon">▼</span>
            </h2>
            <div class="section-content" id="stack-trace-content">
                <div class="trace-filter">
                    <span class="trace-filter-label">🔍 Filter:</span>
                    <input
                        type="text"
                        id="trace-filter"
                        placeholder="Search by class, method, or file path..."
                        oninput="filterStackTrace()"
                    >
                    <button class="copy-button" onclick="copyStackTrace()" id="copy-trace-btn" style="position: static; margin: 0;">
                        Copy Trace
                    </button>
                </div>
                <div foreach="$trace as $item">
                    <div class="trace-item" if="{{ $item->isOrigin }}">
                        <span class="trace-index">#{{ $item->index }}</span>
                        <div class="trace-function">🎯 {{ $item->function }}</div>
                        <div class="trace-location">{{ $item->file }}:{{ $item->line }}</div>
                    </div>
                    <div class="trace-item" if="!{{ $item->isOrigin }}">
                        <span class="trace-index">#{{ $item->index }}</span>
                        <div class="trace-function">{{ $item->function }}</div>
                        <div class="trace-location">{{ $item->file }}:{{ $item->line }}</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- System Information -->
        <div class="section">
            <h2 class="section-title collapsible collapsed" onclick="toggleSection('system-info')">
                <span>⚙️ System Information</span>
                <span class="collapse-icon">▼</span>
            </h2>
            <div class="section-content collapsed" id="system-info-content">
                <div class="meta-grid">
                <div class="meta-item">
                    <div class="meta-label">Environment</div>
                    <div class="meta-value">{{ $environment }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Debug Mode</div>
                    <div class="meta-value">{{ $debugMode }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">PHP Version</div>
                    <div class="meta-value">{{ $phpVersion }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Memory Usage</div>
                    <div class="meta-value">{{ $memory }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Execution Time</div>
                    <div class="meta-value">{{ $executionTime }}</div>
                </div>
                <div class="meta-item">
                    <div class="meta-label">Memory Limit</div>
                    <div class="meta-value">{{ $memoryLimit }}</div>
                </div>
            </div>
            </div>
        </div>
    </div>

    <script>
        // Toggle collapsible sections
        function toggleSection(sectionId) {
            const content = document.getElementById(sectionId + '-content');
            const title = content.previousElementSibling;

            content.classList.toggle('collapsed');
            title.classList.toggle('collapsed');
        }

        // Copy code to clipboard
        function copyCode() {
            const codeContainer = document.getElementById('code-container');
            const codeElement = codeContainer.querySelector('pre') || codeContainer.querySelector('code');

            if (!codeElement) {
                return;
            }

            const text = codeElement.textContent || codeElement.innerText;

            navigator.clipboard.writeText(text).then(() => {
                const button = document.getElementById('copy-code-btn');
                button.classList.add('copied');
                button.textContent = 'Copied!';

                setTimeout(() => {
                    button.classList.remove('copied');
                    button.textContent = 'Copy Code';
                }, 2000);
            }).catch(err => {
                console.error('Failed to copy:', err);
            });
        }

        // Copy stack trace
        function copyStackTrace() {
            const traceContainer = document.getElementById('stack-trace-content');
            const traceItems = traceContainer.querySelectorAll('.trace-item');

            let text = 'Stack Trace:\n\n';
            traceItems.forEach(item => {
                const func = item.querySelector('.trace-function').textContent;
                const location = item.querySelector('.trace-location').textContent;
                text += `${func}\n  at ${location}\n\n`;
            });

            navigator.clipboard.writeText(text).then(() => {
                const button = document.getElementById('copy-trace-btn');
                button.classList.add('copied');
                button.textContent = 'Copied!';

                setTimeout(() => {
                    button.classList.remove('copied');
                    button.textContent = 'Copy Trace';
                }, 2000);
            }).catch(err => {
                console.error('Failed to copy:', err);
            });
        }

        // Filter stack trace
        function filterStackTrace() {
            const input = document.getElementById('trace-filter');
            const filter = input.value.toLowerCase();
            const items = document.querySelectorAll('.trace-item');
            let visibleCount = 0;

            items.forEach(item => {
                const text = item.textContent.toLowerCase();
                if (text.includes(filter)) {
                    item.style.display = '';
                    visibleCount++;
                } else {
                    item.style.display = 'none';
                }
            });

            // Update trace count
            const traceCount = document.getElementById('trace-count');
            if (traceCount) {
                if (filter) {
                    traceCount.textContent = `${visibleCount}/${items.length}`;
                } else {
                    traceCount.textContent = items.length;
                }
            }
        }
    </script>
</body>
</html>
