{% extends "base.html" %}
{% load static %}

{% block title %}
    Inventory Dashboard
{% endblock title %}

{% block content %}
<main>
    <div class="background-shapes">
        <div class="shape shape-1"></div>
        <div class="shape shape-2"></div>
        <div class="shape shape-3"></div>
        <div class="shape shape-4"></div>
    </div>
    <section class="hero text-center mb-5">
        <div class="container">
            <h1 class="display-4 fw-bold">!!!Inventory Dashboard!!!</h1>
            <p class="lead col-lg-8 mx-auto">
                A modern dashboard to monitor products, stock levels, and adjustments.
            </p>
        </div>
    </section>

    <div class="container">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2 class="h4">All Products</h2>
            <div>
                <a href="{% url 'add_product' %}" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>Add Product
                </a>
                <a href="#" class="btn btn-secondary disabled" role="button" aria-disabled="true">
                    <i class="fas fa-file-csv me-2"></i>Export CSV
                </a>
            </div>
        </div>

        <div class="product-grid">
            {% for product in products %}
            <div class="product-card">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-start">
                        <div>
                            <h5 class="card-title">{{ product.name }}</h5>
                            <h6 class="card-subtitle mb-2 text-muted">{{ product.sku }}</h6>
                        </div>
                        {% if product.is_low_stock %}
                            <span class="badge status-badge badge-danger">
                                <i class="fas fa-exclamation-triangle me-1"></i>Low Stock
                            </span>
                        {% else %}
                            <span class="badge status-badge badge-success">
                                <i class="fas fa-check-circle me-1"></i>In Stock
                            </span>
                        {% endif %}
                    </div>
                    <div class="stock-info mt-4">
                        <div class="stock-level">
                            <span class="stock-value">{{ product.stock_level }}</span>
                            <span class="stock-label">Units</span>
                        </div>
                        <div class="stock-bar-container">
                            <div class="stock-bar" style="width: {% widthratio product.stock_level 1000 100 %}%"></div>
                        </div>
                    </div>
                </div>
                <div class="card-footer d-flex justify-content-between align-items-center">
                    <small class="text-muted">Last updated: {{ product.updated_at|date:"M d, Y" }}</small>
                    <a href="{% url 'edit_product' product.id %}" class="btn btn-sm btn-outline-secondary">Edit</a>
                </div>
            </div>
            {% empty %}
            <div class="col-12">
                <div class="card text-center p-5">
                    <h4>No products found.</h4>
                    <p>Add your first product to see it here.</p>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
</main>
{% endblock content %}
