{% extends "base.html" %}
{% load accounting_tags %}
{% block title %}Edit Product{% endblock %}

{% block content %}
<div class="container">
    <div class="card shadow">
        
            <h2 class="my-4">Edit Product</h2>
       
        <div class="card-body">
            <form method="POST" enctype="multipart/form-data" novalidate>
                {% csrf_token %}

                {% for field in form %}
                    <div class="mb-3">
                        <label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
                        {{ field|add_class:"form-control" }}
                        {% if field.errors %}
                            <div class="text-danger small">
                                {{ field.errors|join:", " }}
                            </div>
                        {% endif %}
                    </div>
                {% endfor %}

                {% if product.attachments %}
                    <div class="mb-3">
                        <label class="form-label">Current Attachment:</label><br>
                        <a href="{{ product.attachments.url }}" target="_blank">{{ product.attachments.name }}</a>
                    </div>
                {% endif %}

                <div class="d-flex justify-content-between">
                    <a href="{% url 'product_list' %}" class="btn btn-secondary">Cancel</a>
                    <button type="submit" class="btn btn-success">Update Product</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}
