{% extends 'core/base.html' %}
{% load static %}

{% block title %}Restock Product - SwiftPOS{% endblock %}

{% block topbar_title %}
Restock Product
{% endblock %}

{% block content %}
<div class="container-fluid px-0">

    <!-- Toast Messages -->
    <div class="swiftpos-toast-container">
        {% if messages %}
            {% for message in messages %}
                <div class="swiftpos-toast swiftpos-toast-{{ message.tags }}">
                    <div class="toast-icon">
                        {% if message.tags == 'success' %}
                            <i class="fas fa-check-circle"></i>
                        {% elif message.tags == 'error' or message.tags == 'danger' %}
                            <i class="fas fa-exclamation-circle"></i>
                        {% elif message.tags == 'warning' %}
                            <i class="fas fa-exclamation-triangle"></i>
                        {% else %}
                            <i class="fas fa-info-circle"></i>
                        {% endif %}
                    </div>
                    <div class="toast-text">
                        {{ message }}
                    </div>
                </div>
            {% endfor %}
        {% endif %}
    </div>

    <div class="d-flex flex-wrap justify-content-between align-items-center mb-3 gap-2">
        <div>
            <h5 class="mb-0">Restock Product</h5>
            <div class="text-muted small">
                {{ product.name }} (SKU: {{ product.sku }})
            </div>
        </div>
        <a href="{% url 'inventory:product_detail' product.id %}"
           class="btn btn-outline-secondary btn-sm d-flex align-items-center gap-2">
            <i class="fas fa-arrow-left"></i> Back to product
        </a>
    </div>

    <div class="row g-3">
        <div class="col-lg-4">
            <div class="card mb-3">
                <div class="card-body">
                    <div class="fw-semibold small mb-2">Current stock</div>
                    <div class="h4 mb-0">{{ product.stock_quantity }}</div>
                    <div class="text-muted small">
                        Minimum: {{ product.minimum_stock }}
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-8">
            <div class="card">
                <div class="card-header">
                    <h6 class="card-title mb-0 d-flex align-items-center gap-2">
                        <i class="fas fa-plus-circle"></i> Restock details
                    </h6>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}

                        <div class="row g-3">
                            <div class="col-md-6">
                                <label for="quantity" class="form-label small fw-semibold">
                                    Quantity to Add
                                </label>
                                <input type="number"
                                       name="quantity"
                                       id="quantity"
                                       class="form-control"
                                       placeholder="Enter quantity"
                                       min="1"
                                       required>
                            </div>
                            <div class="col-md-6">
                                <label for="reference_number" class="form-label small fw-semibold">
                                    Reference Number (optional)
                                </label>
                                <input type="text"
                                       name="reference_number"
                                       id="reference_number"
                                       class="form-control"
                                       placeholder="Invoice or reference number">
                            </div>
                        </div>

                        <div class="mt-3">
                            <label for="reason" class="form-label small fw-semibold">
                                Note / Reason (optional)
                            </label>
                            <textarea name="reason"
                                      id="reason"
                                      rows="3"
                                      class="form-control"
                                      placeholder="Short note for this restock (supplier, reason, etc.)"></textarea>
                        </div>

                        <div class="mt-4 d-flex justify-content-end gap-2">
                            <a href="{% url 'inventory:product_detail' product.id %}"
                               class="btn btn-outline-secondary btn-sm">
                                Cancel
                            </a>
                            <button type="submit"
                                    class="btn btn-primary btn-sm d-flex align-items-center gap-2">
                                <i class="fas fa-check-circle"></i> Confirm restock
                            </button>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}