<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{meta.title}}</title>
    <link rel="stylesheet" href="/assets/css/admin.css">
    <style>
        .component-library-layout {
            display: grid;
            grid-template-columns: 250px 1fr;
            min-height: 100vh;
            background-color: #f8fafc;
        }
        
        .component-sidebar {
            background: white;
            border-right: 1px solid #e2e8f0;
            padding: 1.5rem;
            overflow-y: auto;
        }
        
        .component-main {
            padding: 2rem;
            overflow-y: auto;
        }
        
        .search-box {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #e2e8f0;
            border-radius: 6px;
            margin-bottom: 1.5rem;
            font-size: 0.875rem;
        }
        
        .category-filter {
            margin-bottom: 2rem;
        }
        
        .category-filter h3 {
            font-size: 0.875rem;
            font-weight: 600;
            color: #374151;
            margin-bottom: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        
        .category-list {
            space-y: 0.25rem;
        }
        
        .category-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0.5rem 0.75rem;
            border-radius: 6px;
            font-size: 0.875rem;
            color: #6b7280;
            text-decoration: none;
            transition: all 0.2s;
        }
        
        .category-item:hover,
        .category-item.active {
            background-color: #f3f4f6;
            color: #374151;
        }
        
        .category-count {
            font-size: 0.75rem;
            background: #e5e7eb;
            color: #6b7280;
            padding: 0.125rem 0.375rem;
            border-radius: 9999px;
        }
        
        .components-header {
            display: flex;
            align-items: center;
            justify-content: between;
            margin-bottom: 2rem;
        }
        
        .components-stats {
            display: flex;
            gap: 2rem;
            margin-bottom: 2rem;
            padding: 1.5rem;
            background: white;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
        }
        
        .stat-item {
            text-align: center;
        }
        
        .stat-value {
            font-size: 1.5rem;
            font-weight: 700;
            color: #1f2937;
        }
        
        .stat-label {
            font-size: 0.75rem;
            color: #6b7280;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        
        .components-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 1.5rem;
        }
        
        .component-card {
            background: white;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
            overflow: hidden;
            transition: all 0.2s;
        }
        
        .component-card:hover {
            border-color: #d1d5db;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        
        .component-preview {
            padding: 2rem;
            background: #f9fafb;
            border-bottom: 1px solid #e2e8f0;
            min-height: 120px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .component-info {
            padding: 1rem 1.5rem;
        }
        
        .component-name {
            font-weight: 600;
            color: #1f2937;
            margin-bottom: 0.5rem;
        }
        
        .component-meta {
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.75rem;
            color: #6b7280;
        }
        
        .component-category {
            background: #dbeafe;
            color: #1d4ed8;
            padding: 0.125rem 0.375rem;
            border-radius: 9999px;
        }
        
        .component-pattern {
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        
        .empty-state {
            text-align: center;
            padding: 4rem 2rem;
            color: #6b7280;
        }
        
        .empty-state-icon {
            font-size: 3rem;
            margin-bottom: 1rem;
        }
        
        /* Component Preview Styling */
        .component-preview .btn {
            background: #3b82f6;
            color: white;
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 6px;
            cursor: pointer;
        }
        
        .component-preview .btn-secondary {
            background: #6b7280;
        }
        
        .component-preview .btn-success {
            background: #10b981;
        }
        
        .component-preview .btn-danger {
            background: #ef4444;
        }
        
        .component-preview .btn-warning {
            background: #f59e0b;
        }
        
        .component-preview .card {
            background: white;
            padding: 1rem;
            border-radius: 6px;
            border: 1px solid #e2e8f0;
            min-width: 200px;
        }
        
        .component-preview .alert {
            padding: 0.75rem 1rem;
            border-radius: 6px;
            min-width: 250px;
            font-size: 0.875rem;
        }
        
        .component-preview .alert-success {
            background: #dcfce7;
            color: #166534;
            border: 1px solid #bbf7d0;
        }
        
        .component-preview .alert-error {
            background: #fef2f2;
            color: #dc2626;
            border: 1px solid #fecaca;
        }
        
        .component-preview .alert-warning {
            background: #fef3c7;
            color: #d97706;
            border: 1px solid #fed7aa;
        }
        
        .component-preview .alert-info {
            background: #dbeafe;
            color: #1d4ed8;
            border: 1px solid #bfdbfe;
        }
    </style>
</head>
<body>
    <div class="component-library-layout">
        <!-- Sidebar -->
        <aside class="component-sidebar">
            <div class="mb-4">
                <a href="/design-system" class="text-sm text-gray-500 hover:text-gray-700">← Design System</a>
                <h1 class="text-lg font-semibold text-gray-900 mt-2">Component Library</h1>
            </div>
            
            <!-- Search -->
            <input type="text" class="search-box" placeholder="Search components..." value="{{searchQuery}}" id="search-input">
            
            <!-- Category Filter -->
            <div class="category-filter">
                <h3>Categories</h3>
                <div class="category-list">
                    <a href="/design-system/components" class="category-item">
                        <span>🌟 All Components</span>
                        <span class="category-count">{{totalComponents}}</span>
                    </a>
                    
                    <a href="/design-system/components?category=button" class="category-item">
                        <span>🔘 Buttons</span>
                        <span class="category-count">{{ count(groupedComponents.button ?? []) }}</span>
                    </a>
                    
                    <a href="/design-system/components?category=navigation" class="category-item">
                        <span>🧭 Navigation</span>
                        <span class="category-count">{{ count(groupedComponents.navigation ?? []) }}</span>
                    </a>
                    
                    <a href="/design-system/components?category=form" class="category-item">
                        <span>📝 Form Elements</span>
                        <span class="category-count">{{ count(groupedComponents.form ?? []) }}</span>
                    </a>
                    
                    <a href="/design-system/components?category=card" class="category-item">
                        <span>🃏 Cards & Panels</span>
                        <span class="category-count">{{ count(groupedComponents.card ?? []) }}</span>
                    </a>
                    
                    <a href="/design-system/components?category=feedback" class="category-item">
                        <span>💬 Alerts & Messages</span>
                        <span class="category-count">{{ count(groupedComponents.feedback ?? []) }}</span>
                    </a>
                    
                    <a href="/design-system/components?category=layout" class="category-item">
                        <span>📐 Layout</span>
                        <span class="category-count">{{ count(groupedComponents.layout ?? []) }}</span>
                    </a>
                    
                    <a href="/design-system/components?category=typography" class="category-item">
                        <span>📖 Typography</span>
                        <span class="category-count">{{ count(groupedComponents.typography ?? []) }}</span>
                    </a>
                </div>
            </div>
        </aside>
        
        <!-- Main Content -->
        <main class="component-main">
            <!-- Header -->
            <div class="components-header">
                <div>
                    <h1 class="text-2xl font-bold text-gray-900">Component Library</h1>
                    <p class="text-gray-600 mt-1">Interactive component documentation with live previews</p>
                </div>
            </div>
            
            <!-- Stats -->
            <div class="components-stats">
                <div class="stat-item">
                    <div class="stat-value">{{totalComponents}}</div>
                    <div class="stat-label">Total Components</div>
                </div>
                <div class="stat-item">
                    <div class="stat-value">{{ count(categoryCounts) }}</div>
                    <div class="stat-label">Categories</div>
                </div>
                <div class="stat-item">
                    <div class="stat-value">{{ count(patternCounts) }}</div>
                    <div class="stat-label">Patterns</div>
                </div>
            </div>
            
            <!-- Components Grid -->
            <div class="components-grid">
                <!-- Dynamic Components Loop -->
                <for var="component" in="components">
                    <a href="/design-system/components/{{{$component.name}}}" class="component-card" style="text-decoration: none; color: inherit;">
                        <div class="component-preview">
                            {{{$component.previewHtml}}}
                        </div>
                        <div class="component-info">
                            <div class="component-name">{{{$component.displayName}}}</div>
                            <div class="component-meta">
                                <span class="component-category">{{{$component.category}}}</span>
                                <span class="component-pattern">{{{$component.pattern}}}</span>
                            </div>
                        </div>
                    </a>
                </for>
                
                <!-- Static examples showing found components -->
                <a href="/design-system/components/card" class="component-card" style="text-decoration: none; color: inherit;">
                    <div class="component-preview">
                        <div class="card">
                            <h3 style="margin: 0 0 0.5rem 0;">Card Title</h3>
                            <p style="margin: 0; color: #6b7280;">Card content goes here...</p>
                        </div>
                    </div>
                    <div class="component-info">
                        <div class="component-name">Card</div>
                        <div class="component-meta">
                            <span class="component-category">card</span>
                            <span class="component-pattern">BEM</span>
                        </div>
                    </div>
                </a>
                
                <a href="/design-system/components/button" class="component-card" style="text-decoration: none; color: inherit;">
                    <div class="component-preview">
                        <button class="btn">Button</button>
                    </div>
                    <div class="component-info">
                        <div class="component-name">Button</div>
                        <div class="component-meta">
                            <span class="component-category">button</span>
                            <span class="component-pattern">TRADITIONAL</span>
                        </div>
                    </div>
                </a>
                
                <a href="/design-system/components/btn-primary" class="component-card" style="text-decoration: none; color: inherit;">
                    <div class="component-preview">
                        <button class="btn btn-primary">Primary Button</button>
                    </div>
                    <div class="component-info">
                        <div class="component-name">Btn Primary</div>
                        <div class="component-meta">
                            <span class="component-category">button</span>
                            <span class="component-pattern">TRADITIONAL</span>
                        </div>
                    </div>
                </a>
                
                <a href="/design-system/components/csrf-protection" class="component-card" style="text-decoration: none; color: inherit;">
                    <div class="component-preview">
                        <div class="csrf-status csrf-valid">
                            <span class="csrf-indicator">✓</span>
                            <span class="csrf-label">CSRF Protected</span>
                        </div>
                    </div>
                    <div class="component-info">
                        <div class="component-name">CSRF Protection</div>
                        <div class="component-meta">
                            <span class="component-category">form</span>
                            <span class="component-pattern">BEM</span>
                        </div>
                    </div>
                </a>
                
                <a href="/design-system/components/sidebar" class="component-card" style="text-decoration: none; color: inherit;">
                    <div class="component-preview">
                        <div class="sidebar-preview" style="background: #2c1c59; color: white; padding: 1rem; border-radius: 4px; min-width: 150px;">
                            <div>Sidebar Navigation</div>
                        </div>
                    </div>
                    <div class="component-info">
                        <div class="component-name">Sidebar</div>
                        <div class="component-meta">
                            <span class="component-category">navigation</span>
                            <span class="component-pattern">BEM</span>
                        </div>
                    </div>
                </a>
                
                <a href="/design-system/components/lightbox" class="component-card" style="text-decoration: none; color: inherit;">
                    <div class="component-preview">
                        <div class="lightbox-preview" style="border: 2px solid #ddd; padding: 1rem; border-radius: 4px; text-align: center;">
                            <span>🖼️ Lightbox</span>
                        </div>
                    </div>
                    <div class="component-info">
                        <div class="component-name">Lightbox</div>
                        <div class="component-meta">
                            <span class="component-category">layout</span>
                            <span class="component-pattern">BEM</span>
                        </div>
                    </div>
                </a>
            </div>
            
            <!-- Empty State -->
            <div class="empty-state" if="count(components) === 0">
                <div class="empty-state-icon">🔍</div>
                <h3>No Components Found</h3>
                <p>Try adjusting your search or filter criteria.</p>
            </div>
        </main>
    </div>
    
    <script>
        // Search functionality
        const searchInput = document.getElementById('search-input');
        searchInput.addEventListener('input', function(e) {
            const query = e.target.value;
            const url = new URL(window.location);
            if (query) {
                url.searchParams.set('search', query);
            } else {
                url.searchParams.delete('search');
            }
            window.location.href = url.toString();
        });
    </script>
</body>
</html>