{% extends "layouts/base.html" %}
{% load i18n %}
{% load static %}

{% block title %}Social Media Monitoring - PX360{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="mb-1">
                <i class="bi bi-chat-dots text-purple me-2"></i>
                Social Media Monitoring
            </h2>
            <p class="text-muted mb-0">Track social media mentions and sentiment</p>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card border-left-primary">
                <div class="card-body">
                    <h6 class="text-muted mb-1">{% trans "Total Mentions" %}</h6>
                    <h3 class="mb-0">{{ stats.total }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card border-left-success">
                <div class="card-body">
                    <h6 class="text-muted mb-1">{% trans "Positive" %}</h6>
                    <h3 class="mb-0 text-success">{{ stats.positive }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card border-left-warning">
                <div class="card-body">
                    <h6 class="text-muted mb-1">{% trans "Neutral" %}</h6>
                    <h3 class="mb-0">{{ stats.neutral }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card border-left-danger">
                <div class="card-body">
                    <h6 class="text-muted mb-1">{% trans "Negative" %}</h6>
                    <h3 class="mb-0 text-danger">{{ stats.negative }}</h3>
                </div>
            </div>
        </div>
    </div>

    <!-- Mentions Feed -->
    <div class="row">
        {% for mention in mentions %}
        <div class="col-md-6 mb-3">
            <div class="card h-100">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-start mb-2">
                        <div>
                            <span class="badge bg-primary">{{ mention.get_platform_display }}</span>
                            {% if mention.sentiment == 'positive' %}
                            <span class="badge bg-success">Positive</span>
                            {% elif mention.sentiment == 'negative' %}
                            <span class="badge bg-danger">Negative</span>
                            {% else %}
                            <span class="badge bg-secondary">Neutral</span>
                            {% endif %}
                        </div>
                        <small class="text-muted">{{ mention.posted_at|date:"M d, Y" }}</small>
                    </div>
                    
                    <p class="mb-2"><strong>@{{ mention.author_username }}</strong></p>
                    <p class="mb-3">{{ mention.content|truncatewords:30 }}</p>
                    
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <small class="text-muted me-3">
                                <i class="bi bi-heart"></i> {{ mention.likes_count }}
                            </small>
                            <small class="text-muted me-3">
                                <i class="bi bi-share"></i> {{ mention.shares_count }}
                            </small>
                            <small class="text-muted">
                                <i class="bi bi-chat"></i> {{ mention.comments_count }}
                            </small>
                        </div>
                        <a href="{% url 'social:mention_detail' mention.id %}" class="btn btn-sm btn-outline-primary">
                            View
                        </a>
                    </div>
                </div>
            </div>
        </div>
        {% empty %}
        <div class="col-12">
            <div class="text-center py-5">
                <i class="bi bi-chat-dots" style="font-size: 3rem; color: #ccc;"></i>
                <p class="text-muted mt-3">No mentions found</p>
            </div>
        </div>
        {% endfor %}
    </div>

    <!-- Pagination -->
    {% if page_obj.has_other_pages %}
    <nav aria-label="Mentions pagination" class="mt-4">
        <ul class="pagination justify-content-center">
            {% if page_obj.has_previous %}
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.previous_page_number }}{% for key, value in filters.items %}&{{ key }}={{ value }}{% endfor %}">
                    <i class="bi bi-chevron-left"></i>
                </a>
            </li>
            {% endif %}
            
            {% for num in page_obj.paginator.page_range %}
                {% if page_obj.number == num %}
                <li class="page-item active"><span class="page-link">{{ num }}</span></li>
                {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
                <li class="page-item">
                    <a class="page-link" href="?page={{ num }}{% for key, value in filters.items %}&{{ key }}={{ value }}{% endfor %}">
                        {{ num }}
                    </a>
                </li>
                {% endif %}
            {% endfor %}
            
            {% if page_obj.has_next %}
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.next_page_number }}{% for key, value in filters.items %}&{{ key }}={{ value }}{% endfor %}">
                    <i class="bi bi-chevron-right"></i>
                </a>
            </li>
            {% endif %}
        </ul>
    </nav>
    {% endif %}
</div>
{% endblock %}
