{% 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">

    <!-- Page Header -->
    <div class="sp-page-header">
        <div>
            <h1 class="sp-page-title"><i class="fas fa-chart-bar"></i>Feature Usage Analytics</h1>
            <p class="sp-page-subtitle">Superadmin view: per-company usage and activity stats.</p>
        </div>
    </div>
    <div class="card">
        <div class="card-body p-0">
            <div class="sp-table-container">
                <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 %}
