{% extends 'base.html' %}
{% load static %}

{% block title %}Nos Réalisations - ECOLUX BTP{% endblock %}

{% block content %}
<!-- Navigation -->
{% include "ecolux_styles.html" %}
<!-- Navigation -->
{% include "nav.html" %}

<!-- Header avec image de fond -->
{% include 'partials/page_header.html' with page_title="Nos Réalisations" page_description="Découvrez nos projets BTP d'exception, témoins de notre savoir-faire et de notre engagement qualité" badge_text="Portfolio & Références" header_image="assets/img/bg2.jpg" breadcrumb=breadcrumb_items %}

<!-- Contenu principal -->
<section class="section">
    <div class="container">
        <!-- Filtres de catégories -->
        <div class="filters-container">
            <div class="filters-wrapper">
                <button class="filter-btn active" data-filter="all">
                    Tous les projets
                </button>
                {% for category in categories %}
                <button class="filter-btn" data-filter="{{ category.slug }}">
                    {{ category.name }}
                </button>
                {% endfor %}
            </div>
        </div>
        
        <!-- Projets -->
        <div class="projects-grid" style="
            display: grid !important; 
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)) !important; 
            gap: 2rem !important; 
            margin-top: 2rem !important;
            visibility: visible !important;
            opacity: 1 !important;
        ">
            
            {% for project in projects %}
            <article class="project-card animate-on-scroll" data-category="{{ project.category.slug|default:'general' }}" style="background: white; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); border: 1px solid #e5e7eb; margin-bottom: 2rem; opacity: 1; transform: none;">
                <div class="project-image-container" style="position: relative; height: 250px; overflow: hidden;">
                    <div class="project-image" style="width: 100%; height: 100%; background-size: cover; background-position: center; background-image: url('{% if project.main_image %}{{ project.main_image.url }}{% else %}{% static 'assets/img/bg2.jpg' %}{% endif %}');">
                    </div>
                    <div class="project-overlay">
                        <div class="project-badges">
                            {% if project.category %}
                            <span class="project-badge">{{ project.category.name }}</span>
                            {% endif %}
                            {% if project.featured %}
                            <span class="project-badge featured">Projet Phare</span>
                            {% endif %}
                        </div>
                        <div class="project-actions">
                            <a href="{% url 'app:project_detail' project.slug %}" class="project-btn">
                                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>
                                </svg>
                                Voir détails
                            </a>
                            {% if project.images.count > 1 %}
                            <button class="project-btn gallery-btn" data-project="{{ project.id }}">
                                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                    <path d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/>
                                </svg>
                                Galerie ({{ project.images.count }})
                            </button>
                            {% endif %}
                        </div>
                    </div>
                </div>
                <div class="project-content" style="padding: 1.5rem; background: white;">
                    <div class="project-meta">
                        <span class="project-date">{{ project.completed_date|date:"Y"|default:"En cours" }}</span>
                        <span class="project-location">{{ project.location }}</span>
                    </div>
                    <h3>
                        <a href="{% url 'app:project_detail' project.slug %}">{{ project.title }}</a>
                    </h3>
                    <p class="project-description">{{ project.short_description|default:project.description|striptags|truncatewords:15 }}</p>
                    <div class="project-specs">
                        {% if project.budget %}
                        <div class="spec-item">
                            <span class="spec-label">Budget:</span>
                            <span class="spec-value">{{ project.budget|floatformat:0 }} FCFA</span>
                        </div>
                        {% endif %}
                        {% if project.surface_built %}
                        <div class="spec-item">
                            <span class="spec-label">Surface:</span>
                            <span class="spec-value">{{ project.surface_built }} m²</span>
                        </div>
                        {% endif %}
                    </div>
                </div>
            </article>
            {% empty %}
            <div class="empty-state" style="text-align: center; padding: 80px 20px; background: #f8f9fa; border-radius: 12px; border: 2px dashed #dee2e6;">
                <div class="empty-icon" style="font-size: 4rem; margin-bottom: 20px;">🏗️</div>
                <h3 style="color: #495057; margin-bottom: 15px; font-size: 1.5rem;">Aucune réalisation disponible</h3>
                <p style="color: #6c757d; margin-bottom: 25px; font-size: 1.1rem;">
                    Nos équipes travaillent sur de nouveaux projets exceptionnels.<br>
                    Revenez bientôt pour découvrir nos dernières réalisations !
                </p>
                <div style="background: #e9ecef; padding: 15px; border-radius: 8px; display: inline-block;">
                    <p style="margin: 0; color: #495057; font-size: 0.9rem;">
                        <strong>💡 Conseil :</strong> Consultez notre section 
                        <a href="{% url 'app:home' %}" style="color: #d4af37; text-decoration: none;">services</a> 
                        pour voir ce que nous pouvons réaliser pour vous.
                    </p>
                </div>
            </div>
            {% endfor %}
        </div>

        <!-- Bouton Voir Plus -->
        {% if projects|length >= 6 %}
        <div class="load-more-container">
            <button class="btn-outline btn-lg load-more-btn">
                Voir plus de projets
                <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                    <path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6-1.41-1.41z"/>
                </svg>
            </button>
        </div>
        {% endif %}
    </div>
</section>



<!-- Footer -->
{% include 'partials/footer.html' %}

<!-- WhatsApp Button -->
<button class="whatsapp-btn" onclick="window.open(`https://wa.me/221779962626?text=${encodeURIComponent('Bonjour ECOLUX BTP, je souhaite obtenir une consultation gratuite pour mon projet de construction.')}`, '_blank');" title="Contactez-nous sur WhatsApp">
    <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">
        <path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/>
    </svg>
</button>


<!-- Modal Galerie -->
<div id="gallery-modal" class="modal">
    <div class="modal-content">
        <button class="modal-close">&times;</button>
        <div class="gallery-container">
            <div class="gallery-main">
                <img id="gallery-main-image" src="" alt="">
                <button class="gallery-nav gallery-prev">
                    <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
                    </svg>
                </button>
                <button class="gallery-nav gallery-next">
                    <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z"/>
                    </svg>
                </button>
            </div>
            <div class="gallery-thumbnails" id="gallery-thumbnails">
                <!-- Thumbnails will be populated by JavaScript -->
            </div>
        </div>
    </div>
</div>

<style>
/* Styles spécifiques aux réalisations */
.stats-container {
    margin-bottom: 4rem;
}

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

.stat-card {
    text-align: center;
    padding: 2rem;
    background: var(--card);
    border-radius: 1rem;
    border: 1px solid var(--border);
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(30, 24, 16, 0.08);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow);
    border-color: var(--secondary);
}

.stat-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary);
    margin-bottom: 0.5rem;
}

.stat-label {
    color: rgba(30, 24, 16, 0.7);
    font-weight: 600;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.project-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    overflow: hidden;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(30, 24, 16, 0.08);
}

.project-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    border-color: var(--secondary);
}

.project-image-container {
    position: relative;
    height: 250px;
    overflow: hidden;
}

.project-image {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: var(--transition);
}

.project-card:hover .project-image {
    transform: scale(1.05);
}

.project-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, 
        rgba(30, 24, 16, 0.7), 
        rgba(212, 175, 55, 0.3)
    );
    opacity: 0;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.5rem;
}

.project-card:hover .project-overlay {
    opacity: 1;
}

.project-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.project-badge {
    padding: 0.375rem 0.75rem;
    background: rgba(212, 175, 55, 0.9);
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 9999px;
    backdrop-filter: blur(10px);
}

.project-badge.featured {
    background: rgba(239, 68, 68, 0.9);
    color: white;
}

.project-actions {
    display: flex;
    gap: 0.75rem;
}

.project-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary);
    text-decoration: none;
    border: none;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.project-btn:hover {
    background: var(--secondary);
    color: var(--primary);
    transform: translateY(-2px);
}

.project-content {
    padding: 2rem;
}

.project-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: rgba(30, 24, 16, 0.6);
}

.project-date {
    font-weight: 600;
    color: var(--secondary);
}

.project-content h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--primary);
    line-height: 1.4;
}

.project-content h3 a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}

.project-content h3 a:hover {
    color: var(--secondary);
}

.project-description {
    color: rgba(30, 24, 16, 0.7);
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.project-specs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.spec-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
}

.spec-label {
    font-weight: 600;
    color: rgba(30, 24, 16, 0.7);
}

.spec-value {
    font-weight: 700;
    color: var(--secondary);
}

.load-more-container {
    text-align: center;
    margin-top: 3rem;
}

.cta-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: center;
    padding: 4rem;
    background: var(--card);
    border-radius: 1.5rem;
    box-shadow: var(--shadow);
}

.cta-content h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.cta-content p {
    font-size: 1.125rem;
    color: rgba(30, 24, 16, 0.7);
    margin-bottom: 2rem;
    line-height: 1.6;
}

.cta-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.cta-image img {
    width: 100%;
    height: 300px;
    object-fit: cover;
    border-radius: 1rem;
}

/* Modal Galerie */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    padding: 2rem;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    background: var(--card);
    border-radius: 1rem;
    overflow: hidden;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 3rem;
    height: 3rem;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    transition: var(--transition);
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.gallery-container {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.gallery-main {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.gallery-main img {
    max-width: 100%;
    max-height: 60vh;
    object-fit: contain;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 3rem;
    height: 3rem;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-prev {
    left: 1rem;
}

.gallery-next {
    right: 1rem;
}

.gallery-nav:hover {
    background: var(--secondary);
    color: var(--primary);
}

.gallery-thumbnails {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--muted);
    overflow-x: auto;
}

.gallery-thumbnail {
    width: 80px;
    height: 60px;
    background-size: cover;
    background-position: center;
    border-radius: 0.5rem;
    cursor: pointer;
    opacity: 0.6;
    transition: var(--transition);
    flex-shrink: 0;
}

.gallery-thumbnail.active,
.gallery-thumbnail:hover {
    opacity: 1;
    border: 2px solid var(--secondary);
}

@media (max-width: 968px) {
    .cta-container {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .cta-buttons {
        justify-content: center;
    }
}

@media (max-width: 568px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .projects-grid {
        grid-template-columns: 1fr;
    }
    
    .cta-buttons {
        flex-direction: column;
        align-items: center;
    }
}
</style>
{% endblock %}

{% block extra_js %}
{% include 'ecolux_scripts.html' %}
<script>
// Filtrage des projets
document.addEventListener('DOMContentLoaded', function() {
    const filterBtns = document.querySelectorAll('.filter-btn');
    const projectCards = document.querySelectorAll('.project-card');
    
    filterBtns.forEach(btn => {
        btn.addEventListener('click', () => {
            // Mettre à jour les boutons actifs
            filterBtns.forEach(b => b.classList.remove('active'));
            btn.classList.add('active');
            
            const filter = btn.dataset.filter;
            
            // Filtrer les projets
            projectCards.forEach(card => {
                if (filter === 'all' || card.dataset.category === filter) {
                    card.style.display = 'block';
                    setTimeout(() => {
                        card.style.opacity = '1';
                        card.style.transform = 'translateY(0)';
                    }, 100);
                } else {
                    card.style.opacity = '0';
                    card.style.transform = 'translateY(20px)';
                    setTimeout(() => {
                        card.style.display = 'none';
                    }, 300);
                }
            });
        });
    });
    
    // Gestionnaire de galerie
    const galleryBtns = document.querySelectorAll('.gallery-btn');
    const modal = document.getElementById('gallery-modal');
    const modalClose = document.querySelector('.modal-close');
    const mainImage = document.getElementById('gallery-main-image');
    const thumbnailsContainer = document.getElementById('gallery-thumbnails');
    const prevBtn = document.querySelector('.gallery-prev');
    const nextBtn = document.querySelector('.gallery-next');
    
    let currentImages = [];
    let currentIndex = 0;
    
    galleryBtns.forEach(btn => {
        btn.addEventListener('click', () => {
            const projectId = btn.dataset.project;
            // Ici, vous devriez charger les images du projet depuis votre API
            // Pour la démo, on utilise des images factices
            currentImages = [
                '{% static "assets/img/project1.jpg" %}',
                '{% static "assets/img/project2.jpg" %}',
                '{% static "assets/img/project3.jpg" %}'
            ];
            currentIndex = 0;
            openGallery();
        });
    });
    
    function openGallery() {
        modal.classList.add('active');
        updateGallery();
        createThumbnails();
    }
    
    function closeGallery() {
        modal.classList.remove('active');
    }
    
    function updateGallery() {
        mainImage.src = currentImages[currentIndex];
        updateThumbnails();
    }
    
    function createThumbnails() {
        thumbnailsContainer.innerHTML = '';
        currentImages.forEach((img, index) => {
            const thumb = document.createElement('div');
            thumb.className = 'gallery-thumbnail';
            thumb.style.backgroundImage = `url(${img})`;
            thumb.addEventListener('click', () => {
                currentIndex = index;
                updateGallery();
            });
            thumbnailsContainer.appendChild(thumb);
        });
    }
    
    function updateThumbnails() {
        const thumbnails = document.querySelectorAll('.gallery-thumbnail');
        thumbnails.forEach((thumb, index) => {
            thumb.classList.toggle('active', index === currentIndex);
        });
    }
    
    // Event listeners pour la galerie
    modalClose.addEventListener('click', closeGallery);
    modal.addEventListener('click', (e) => {
        if (e.target === modal) closeGallery();
    });
    
    prevBtn.addEventListener('click', () => {
        currentIndex = (currentIndex - 1 + currentImages.length) % currentImages.length;
        updateGallery();
    });
    
    nextBtn.addEventListener('click', () => {
        currentIndex = (currentIndex + 1) % currentImages.length;
        updateGallery();
    });
    
    // Navigation au clavier
    document.addEventListener('keydown', (e) => {
        if (!modal.classList.contains('active')) return;
        
        switch(e.key) {
            case 'Escape':
                closeGallery();
                break;
            case 'ArrowLeft':
                prevBtn.click();
                break;
            case 'ArrowRight':
                nextBtn.click();
                break;
        }
    });
    
    // DIAGNOSTIC SIMPLE - Forcer l'affichage des projets
    setTimeout(() => {
        const animatedElements = document.querySelectorAll('.animate-on-scroll');
        animatedElements.forEach(element => {
            element.style.opacity = '1';
            element.style.transform = 'translateY(0)';
        });
        console.log(`✅ ${animatedElements.length} éléments rendus visibles`);
    }, 100);
});
</script>
{% endblock %}
