{% extends "core/base.html" %}
{% load static %}
{% block title %}Feature Usage Analytics - SwiftPOS{% endblock %}
{% block topbar_title %}Feature Usage Analytics{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h5 class="mb-0 fw-bold">📊 Feature Usage Analytics</h5>
            <p class="text-muted small mb-0">Superadmin view: per-company usage and activity stats.</p>
        </div>
    </div>
11  
    <div class="card border-0 shadow-sm">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-dark">
                        <tr>
                            <th>Company</th>
                            <th>Plan</th>
                            <th class="text-center">Orders (30d)</th>
                            <th class="text-center">Products</th>
                            <th class="text-center">Active Users</th>
                            <th>Last Activity</th>
                            <th class="text-center">Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for row in data %}
                        <tr>
                            <td>
                                <div class="fw-bold">{{ row.company.name }}</div>
                                <small class="text-muted">{{ row.company.slug }}</small>
                            </td>
                            <td>{{ row.company.plan.name|default:"No Plan" }}</td>
                            <td class="text-center fw-semibold">{{ row.orders_30 }}</td>
                            <td class="text-center">{{ row.products }}</td>
                            <td class="text-center">{{ row.active_users }}</td>
                            <td>
                                {% if row.last_activity %}
                                    {{ row.last_activity|timesince }} ago
                                {% else %}
                                    <span class="text-muted">No orders</span>
                                {% endif %}
                            </td>
                            <td class="text-center">
                                {% if row.company.is_active %}
                                    <span class="badge bg-success">Active</span>
                                {% else %}
                                    <span class="badge bg-danger">Suspended</span>
                                {% endif %}
                                {% if row.orders_30 == 0 %}
                                    <span class="badge bg-warning text-dark ms-1">Inactive</span>
                                {% endif %}
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="7" class="text-center py-5 text-muted">No companies found.</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
