<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Manage Static Pages - Admin - LocalLendables</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/main.css">
    
    <style>
        .admin-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem 0;
            margin-bottom: 2rem;
        }
        .page-card {
            border: none;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin-bottom: 1rem;
            transition: all 0.3s ease;
        }
        .page-card:hover {
            box-shadow: 0 4px 8px rgba(0,0,0,0.15);
            transform: translateY(-2px);
        }
        .page-status {
            display: inline-block;
            padding: 0.25rem 0.75rem;
            border-radius: 1rem;
            font-size: 0.875rem;
            font-weight: 500;
        }
        .status-active {
            background-color: #d4edda;
            color: #155724;
        }
        .status-inactive {
            background-color: #f8d7da;
            color: #721c24;
        }
        .btn-edit {
            background: linear-gradient(45deg, #28a745, #20c997);
            border: none;
            color: white;
        }
        .btn-edit:hover {
            background: linear-gradient(45deg, #218838, #1ea085);
            color: white;
        }
        .variable-preview {
            background: #f8f9fa;
            border-left: 4px solid #007bff;
            padding: 0.5rem;
            margin: 0.5rem 0;
            font-family: 'Courier New', monospace;
            font-size: 0.9rem;
        }
        .breadcrumb {
            background: transparent;
            padding: 0;
        }
    </style>
</head>
<body>
    {% include 'common-header.html.twig' %}
    
    <div class="admin-header">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h1><i class="fas fa-file-alt"></i> Static Page Management</h1>
                    <p class="mb-0">Create and edit static pages with dynamic variables</p>
                </div>
                <div class="col-md-4 text-md-end">
                    <a href="/admin/static-pages/new" class="btn btn-light btn-lg">
                        <i class="fas fa-plus"></i> Create New Page
                    </a>
                </div>
            </div>
        </div>
    </div>

    <div class="container">


        <!-- Available Variables Helper -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card border-info">
                    <div class="card-header bg-info text-white">
                        <h5 class="mb-0"><i class="fas fa-info-circle"></i> Available Dynamic Variables</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <h6>Site Variables:</h6>
                                <div class="variable-preview">{{site_name}} - Site name</div>
                                <div class="variable-preview">{{total_members}} - Total member count</div>
                                <div class="variable-preview">{{total_items}} - Total items available</div>
                                <div class="variable-preview">{{active_loans}} - Current active loans</div>
                            </div>
                            <div class="col-md-6">
                                <h6>Manager/Contact Variables:</h6>
                                <div class="variable-preview">{{manager_name}} - Community manager name</div>
                                <div class="variable-preview">{{manager_email}} - Manager contact email</div>
                                <div class="variable-preview">{{community_phone}} - Community phone number</div>
                                <div class="variable-preview">{{last_updated}} - Page last updated date</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Pages List -->
        <div class="row">
            {% for page in staticPages %}
            <div class="col-md-6 col-lg-4">
                <div class="card page-card">
                    <div class="card-body">
                        <div class="d-flex justify-content-between align-items-start mb-2">
                            <h5 class="card-title">{{ page.title }}</h5>
                            <span class="page-status {{ page.isActive ? 'status-active' : 'status-inactive' }}">
                                {{ page.isActive ? 'Active' : 'Inactive' }}
                            </span>
                        </div>
                        
                        <p class="card-text text-muted">
                            <small><i class="fas fa-link"></i> /{{ page.slug }}</small>
                        </p>
                        
                        <p class="card-text">
                            {{ page.content | length > 100 ? (page.content | slice(0, 100) ~ '...') : page.content | striptags }}
                        </p>
                        
                        <div class="d-flex justify-content-between align-items-center">
                            <small class="text-muted">
                                Updated {{ page.updatedAt | date('M j, Y') }}
                            </small>
                            <div class="btn-group" role="group">
                                <a href="/{{ page.slug }}" class="btn btn-outline-primary btn-sm" target="_blank">
                                    <i class="fas fa-eye"></i> View
                                </a>
                                <a href="/admin/static-pages/{{ page.slug }}/edit" class="btn btn-edit btn-sm">
                                    <i class="fas fa-edit"></i> Edit
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {% else %}
            <div class="col-12">
                <div class="text-center py-5">
                    <i class="fas fa-file-alt text-muted" style="font-size: 4rem;"></i>
                    <h3 class="text-muted mt-3">No Static Pages Yet</h3>
                    <p class="text-muted">Create your first static page to get started.</p>
                    <a href="/admin/static-pages/new" class="btn btn-primary btn-lg">
                        <i class="fas fa-plus"></i> Create First Page
                    </a>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>

    {% include 'common-footer.html.twig' %}

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>