{% extends "admin/base.html" %}

{% block title %}Admin Dashboard{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">Dashboard</h1>
</div>

<div class="row mb-4">
    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-orange shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-orange text-uppercase mb-1">Total Products</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ total_products }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-box fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-success shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Total Orders</div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">{{ total_orders }}</div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-shopping-cart fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-lg-6">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-orange">Quick Actions</h6>
            </div>
            <div class="card-body">
                <a href="{{ url_for('admin_add_product') }}" class="btn btn-orange mb-2 w-100">
                    <i class="fas fa-plus me-2"></i>Add New Product
                </a>
                <a href="{{ url_for('admin_products') }}" class="btn btn-outline-orange mb-2 w-100">
                    <i class="fas fa-list me-2"></i>Manage Products
                </a>
                <a href="{{ url_for('init_data') }}" class="btn btn-outline-secondary w-100">
                    <i class="fas fa-database me-2"></i>Initialize Categories
                </a>
            </div>
        </div>
    </div>
    
    <div class="col-lg-6">
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-orange">Recent Orders</h6>
            </div>
            <div class="card-body">
                {% if recent_orders %}
                    {% for order in recent_orders %}
                    <div class="d-flex justify-content-between align-items-center mb-2">
                        <div>
                            <strong>{{ order.customer_name }}</strong>
                            <br>
                            <small class="text-muted">{{ order.created_at.strftime('%Y-%m-%d %H:%M') }}</small>
                        </div>
                        <span class="badge bg-success">KES {{ "%.2f"|format(order.total_amount) }}</span>
                    </div>
                    {% endfor %}
                {% else %}
                    <p class="text-muted">No orders yet.</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
