{% extends "base.html" %}

{% block title %}Stock Dashboard{% endblock %}

{% block content %}
<div class="container mt-4">
    <h2>Stock Dashboard</h2>
    
    <div class="row">
        <!-- Low Stock Alerts -->
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header bg-warning">
                    <h5 class="mb-0">Low Stock Alerts</h5>
                </div>
                <div class="card-body">
                    {% if low_stock %}
                    <div class="table-responsive">
                        <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th>Product</th>
                                    <th>Current Stock</th>
                                    <th>Min Level</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for product in low_stock %}
                                <tr>
                                    <td>{{ product.name }}</td>
                                    <td>{{ product.current_stock|default:0 }}</td>
                                    <td>{{ product.min_stock_level }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <div class="alert alert-success">
                        No low stock items!
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
        
        <!-- Recent Movements -->
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="mb-0">Recent Stock Movements</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Product</th>
                                    <th>Type</th>
                                    <th>Qty</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for movement in recent_movements %}
                                <tr>
                                    <td>{{ movement.date|date:"SHORT_DATETIME_FORMAT" }}</td>
                                    <td>{{ movement.product.name }}</td>
                                    <td>{{ movement.get_movement_type_display }}</td>
                                    <td>{{ movement.quantity }}</td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="4" class="text-center">No recent movements</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}