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

{% block title %}{{ post.title }} - Blog ECOLUX BTP{% endblock %}
{% block description %}{{ post.excerpt|truncatewords:25 }}{% endblock %}


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

<!-- Header avec image de fond -->
{% include 'partials/page_header.html' with page_title=post.title page_description=post.excerpt badge_text=post.category.name header_image=post.featured_image.url breadcrumb=breadcrumb_items image_absolute=True %}

<!-- Contenu principal -->
<section class="section"  >
    <div class="container">
        <div class="article-container">
            <!-- Article principal -->
            <article class="article-main">
                <div class="article-header">
                    <div class="article-meta">
                        <span class="article-date">{{ post.created_at|date:"d F Y" }}</span>
                        {% comment %} <span class="article-author">Par {{ post.author.get_full_name|default:post.author.username }}</span> {% endcomment %}
                        {% if post.category %}
                        <span class="tag">{{ post.category.name }}</span>
                        {% endif %}
                        <span class="article-views">{{ post.views }} vue{{ post.views|pluralize }}</span>
                    </div>
                </div>

                {% if post.featured_image %}
                <div class="article-featured-image">
                    <img src="{{ post.featured_image.url }}" alt="{{ post.title }}" loading="lazy">
                </div>
                {% endif %}

                <div class="article-content">
                    {{ post.content|safe }}
                </div>

                {% if post.tags %}
                <div class="article-tags">
                    <h4>Tags :</h4>
                    <div class="tags-list">
                        {% for tag in post.tags_list %}
                        <span class="tag">{{ tag }}</span>
                        {% endfor %}
                    </div>
                </div>
                {% endif %}

                <!-- Partage social -->
                {% comment %} <div class="article-share">
                    <h4>Partager cet article :</h4>
                    <div class="share-buttons">
                        <a href="#" class="share-btn facebook" onclick="shareOnFacebook('{{ request.build_absolute_uri }}', '{{ post.title }}')">
                            <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
                            </svg>
                            Facebook
                        </a>
                        <a href="#" class="share-btn twitter" onclick="shareOnTwitter('{{ request.build_absolute_uri }}', '{{ post.title }}')">
                            <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                <path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/>
                            </svg>
                            Twitter
                        </a>
                        <a href="#" class="share-btn linkedin" onclick="shareOnLinkedIn('{{ request.build_absolute_uri }}', '{{ post.title }}')">
                            <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
                                <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 01-2.063-2.065 2.064 2.064 0 112.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
                            </svg>
                            LinkedIn
                        </a>
                        <a href="#" class="share-btn whatsapp" onclick="shareOnWhatsApp('{{ request.build_absolute_uri }}', '{{ post.title }}')">
                            <svg width="20" height="20" 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.413"/>
                            </svg>
                            WhatsApp
                        </a>
                    </div>
                </div> {% endcomment %}
            </article>

            <!-- Sidebar -->
            <aside class="article-sidebar">
                <!-- Articles récents -->
                <div class="sidebar-widget">
                    <h3>Articles Récents</h3>
                    <div class="recent-posts">
                        {% for recent_post in recent_posts %}
                        <div class="recent-post">
                            <div class="recent-post-image">
                                <img src="{% if recent_post.featured_image %}{{ recent_post.featured_image.url }}{% else %}{% static 'assets/img/blog-default.jpg' %}{% endif %}" alt="{{ recent_post.title }}">
                            </div>
                            <div class="recent-post-content">
                                <h4><a href="{% url 'app:blog_detail' recent_post.slug %}">{{ recent_post.title|truncatewords:5 }}</a></h4>
                                <span class="recent-post-date">{{ recent_post.created_at|date:"d M Y" }}</span>
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                </div>

                <!-- Catégories -->
                <div class="sidebar-widget">
                    <h3>Catégories</h3>
                    <ul class="categories-list">
                        {% for category in categories %}
                        <li>
                            <a href="{% url 'app:blog_list' %}?category={{ category.slug }}">
                                {{ category.name }}
                                <span class="category-count">({{ category.posts_count }})</span>
                            </a>
                        </li>
                        {% endfor %}
                    </ul>
                </div>

                {% comment %} <!-- Newsletter -->
                <div class="sidebar-widget newsletter-widget">
                    <h3>Newsletter</h3>
                    <p>Recevez nos derniers articles et conseils BTP</p>
                    <form class="newsletter-form">
                        <input type="email" placeholder="Votre email" required>
                        <button type="submit" class="btn-primary">S'abonner</button>
                    </form>
                </div> {% endcomment %}
            </aside>
        </div>
    </div>
</section>

<!-- Articles similaires -->
<section class="section bg-muted">
    <div class="container">
        <div class="section-header" style="background-image: url('{% if post.featured_image %}{{ post.featured_image.url }}{% else %}{% static 'assets/img/blog-default.jpg' %}{% endif %}'); background-blend-mode: multiply; background-size: cover; background-position: center;background-color: rgba(75, 47, 10, 0.8);">
            <h2>Articles Similaires</h2>
            <p>Découvrez d'autres contenus qui pourraient vous intéresser</p>
        </div>

        <div class="related-articles">
            {% for related_post in related_posts %}
            <article class="blog-card">
                <div class="blog-image" 
                     style="background-image: url('{% if related_post.featured_image %}{{ related_post.featured_image.url }}{% else %}{% static 'assets/img/blog-default.jpg' %}{% endif %}');">
                </div>
                <div class="blog-content">
                    <div class="blog-meta">
                        <span class="blog-date">{{ related_post.created_at|date:"d F Y" }}</span>
                        {% if related_post.category %}
                        <span class="tag">{{ related_post.category.name }}</span>
                        {% endif %}
                    </div>
                    <h3>
                        <a href="{% url 'app:blog_detail' related_post.slug %}">{{ related_post.title }}</a>
                    </h3>
                    <p class="blog-excerpt">{{ related_post.excerpt|truncatewords:15 }}</p>
                    <a href="{% url 'app:blog_detail' related_post.slug %}" class="read-more">
                        Lire la suite
                        <svg width="16" height="16" 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>
                    </a>
                </div>
            </article>
            {% endfor %}
        </div>
    </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>

<style>
/* Styles spécifiques au détail d'article */
.article-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 3rem;
    max-width: 1200px;
    margin: 0 auto;
}

.article-main {
    background: var(--card);
    border-radius: 1.5rem;
    padding: 3rem;
    box-shadow: var(--shadow);
}

.article-header {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.article-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
}

.article-date,
.article-author,
.article-views {
    color: rgba(30, 24, 16, 0.6);
}

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

.article-featured-image {
    margin-bottom: 2rem;
    border-radius: 1rem;
    overflow: hidden;
}

.article-featured-image img {
    width: 100%;
    height: 300px;
    object-fit: cover;
}

.article-content {
    line-height: 1.8;
    font-size: 1.125rem;
    color: var(--foreground);
}

.article-content h2,
.article-content h3,
.article-content h4 {
    margin: 2rem 0 1rem;
    color: var(--primary);
}

.article-content p {
    margin-bottom: 1.5rem;
}

.article-content img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1.5rem 0;
}

.article-tags {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.article-tags h4 {
    margin-bottom: 1rem;
    color: var(--primary);
}

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.article-share {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.article-share h4 {
    margin-bottom: 1rem;
    color: var(--primary);
}

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

.share-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
    font-size: 0.875rem;
}

.share-btn.facebook {
    background: #1877f2;
    color: white;
}

.share-btn.twitter {
    background: #1da1f2;
    color: white;
}

.share-btn.linkedin {
    background: #0077b5;
    color: white;
}

.share-btn.whatsapp {
    background: #25d366;
    color: white;
}

.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

/* Sidebar */
.article-sidebar {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.sidebar-widget {
    background: var(--card);
    padding: 2rem;
    border-radius: 1.5rem;
    box-shadow: var(--shadow);
}

.sidebar-widget h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--primary);
}

.recent-posts {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.recent-post {
    display: flex;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.recent-post:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.recent-post-image {
    width: 80px;
    height: 60px;
    border-radius: 0.5rem;
    overflow: hidden;
    flex-shrink: 0;
}

.recent-post-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recent-post-content h4 {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.recent-post-content h4 a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

.recent-post-content h4 a:hover {
    color: var(--secondary);
}

.recent-post-date {
    font-size: 0.75rem;
    color: rgba(30, 24, 16, 0.6);
}

.categories-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.categories-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--muted);
    border-radius: 0.5rem;
    color: var(--foreground);
    text-decoration: none;
    transition: var(--transition);
}

.categories-list a:hover {
    background: var(--secondary);
    color: var(--primary);
}

.category-count {
    font-size: 0.875rem;
    color: rgba(30, 24, 16, 0.6);
}

.newsletter-widget {
    background: linear-gradient(135deg, var(--secondary), var(--accent));
    color: var(--primary);
}

.newsletter-widget h3,
.newsletter-widget p {
    color: var(--primary);
}

.newsletter-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.newsletter-form input {
    padding: 0.875rem;
    border: none;
    border-radius: 0.75rem;
    font-size: 1rem;
}

.newsletter-form input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(30, 24, 16, 0.2);
}

/* Articles similaires */
.related-articles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

/* Responsive */
@media (max-width: 968px) {
    .article-container {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .article-main {
        padding: 2rem;
    }
    
    .share-buttons {
        justify-content: center;
    }
}

@media (max-width: 568px) {
    .article-main {
        padding: 1.5rem;
    }
    
    .article-content {
        font-size: 1rem;
    }
    
    .share-buttons {
        flex-direction: column;
    }
    
    .share-btn {
        justify-content: center;
    }
}
</style>
{% endblock %}

{% block extra_js %}
{% include 'ecolux_scripts.html' %}
<script>
// Fonctions de partage social
function shareOnFacebook(url, title) {
    window.open(`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`, '_blank', 'width=600,height=400');
}

function shareOnTwitter(url, title) {
    window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(url)}&text=${encodeURIComponent(title)}`, '_blank', 'width=600,height=400');
}

function shareOnLinkedIn(url, title) {
    window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`, '_blank', 'width=600,height=400');
}

function shareOnWhatsApp(url, title) {
    window.open(`https://wa.me/?text=${encodeURIComponent(title + ' ' + url)}`, '_blank');
}
</script>
{% endblock %}
