<layout name="layouts/main" />

<div class="demo-container">
    <div class="demo-header">
        <h1>🖼️ LiveComponent Image Gallery Demo</h1>
        <p class="demo-description">
            Real-time image gallery with server-side filtering, sorting, and pagination.
            All state management happens in PHP with automatic updates.
        </p>
    </div>

    <div class="demo-features">
        <div class="feature">
            <strong>🔍 Search</strong> - Real-time search in filenames and alt text
        </div>
        <div class="feature">
            <strong>🎯 Filter</strong> - Filter by image type (JPEG, PNG, GIF, WebP)
        </div>
        <div class="feature">
            <strong>📊 Sort</strong> - Sort by date, name, size, or dimensions
        </div>
        <div class="feature">
            <strong>✅ Select</strong> - Multi-select with bulk delete
        </div>
        <div class="feature">
            <strong>♻️ Real-time</strong> - All actions update instantly
        </div>
        <div class="feature">
            <strong>📄 Pagination</strong> - Load more images on demand
        </div>
    </div>

    <!-- The LiveComponent -->
    <div class="component-wrapper">
        {{image_gallery}}
    </div>

    <div class="demo-info">
        <h3>How It Works</h3>
        <div class="info-grid">
            <div class="info-card">
                <h4>Server-Side State</h4>
                <p>All filtering, sorting, and pagination happens in <code>ImageGalleryState</code> PHP class.</p>
            </div>
            <div class="info-card">
                <h4>LiveComponent Actions</h4>
                <p>Actions like <code>filterByType()</code>, <code>sortBy()</code>, <code>deleteImage()</code> are PHP methods.</p>
            </div>
            <div class="info-card">
                <h4>Data Providers</h4>
                <p>Pluggable data sources: <code>DemoImageGalleryDataProvider</code> or <code>DatabaseImageGalleryDataProvider</code>.</p>
            </div>
            <div class="info-card">
                <h4>No JavaScript Required</h4>
                <p>Gallery functionality works without custom JavaScript. Only upload needs JS.</p>
            </div>
        </div>
    </div>

    <div class="demo-code">
        <h3>Usage Example</h3>
        <pre><code>// Controller
$imageGallery = new ImageGalleryComponent(
    id: ComponentId::fromString('gallery:main'),
    dataProviderResolver: $resolver,
    initialData: ComponentData::fromArray([
        'sort_by' => 'created_at',
        'items_per_page' => 12,
        'data_source' => 'database' // or 'demo'
    ])
);

return new ViewResult('page', data: [
    'gallery' => $imageGallery
]);</code></pre>
    </div>
</div>

<style>
.demo-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

.demo-header {
    text-align: center;
    margin-bottom: 2rem;
}

.demo-header h1 {
    font-size: 2.5rem;
    margin: 0 0 1rem 0;
    color: #333;
}

.demo-description {
    font-size: 1.125rem;
    color: #666;
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.6;
}

.demo-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f9f9f9;
    border-radius: 8px;
}

.feature {
    padding: 1rem;
    background: white;
    border-radius: 6px;
    border-left: 4px solid #2196F3;
    font-size: 0.875rem;
}

.feature strong {
    display: block;
    margin-bottom: 0.25rem;
    color: #2196F3;
}

.component-wrapper {
    margin-bottom: 3rem;
}

.demo-info {
    margin-bottom: 2rem;
}

.demo-info h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #333;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.info-card {
    padding: 1.5rem;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
}

.info-card h4 {
    margin: 0 0 0.5rem 0;
    color: #2196F3;
    font-size: 1.125rem;
}

.info-card p {
    margin: 0;
    color: #666;
    font-size: 0.875rem;
    line-height: 1.6;
}

.info-card code {
    background: #f0f0f0;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-size: 0.8125rem;
}

.demo-code {
    background: #1e1e1e;
    padding: 1.5rem;
    border-radius: 8px;
    color: white;
}

.demo-code h3 {
    margin: 0 0 1rem 0;
    color: white;
    font-size: 1.25rem;
}

.demo-code pre {
    margin: 0;
    overflow-x: auto;
}

.demo-code code {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #d4d4d4;
}

@media (max-width: 768px) {
    .demo-container {
        padding: 1rem;
    }

    .demo-header h1 {
        font-size: 2rem;
    }

    .demo-features {
        grid-template-columns: 1fr;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }
}
</style>
