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

{% block content %}
<div class="container mt-4">
    <h2>Edit Product</h2>
    <form method="post" class="row g-3">
        {% csrf_token %}
        <div class="col-md-6">
            <label for="category" class="form-label">Category</label>
            <select name="category" id="category" class="form-select">
                <option value="">---------</option>
                {% for cat in categories %}
                    <option value="{{ cat.id }}" {% if product.category and cat.id == product.category.id %}selected{% endif %}>{{ cat.name|default:cat.id }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="col-md-6">
            <label for="product_name" class="form-label">Product Name</label>
            <input type="text" class="form-control" id="product_name" name="product_name" value="{{ product.product_name }}" required>
        </div>
        <div class="col-md-4">
            <label for="price" class="form-label">Price</label>
            <input type="number" step="0.01" class="form-control" id="price" name="price" value="{{ product.price }}">
        </div>
        <div class="col-md-4">
            <label for="unit" class="form-label">Unit</label>
            <input type="text" class="form-control" id="unit" name="unit" value="{{ product.unit }}">
        </div>
        <div class="col-12">
            <label for="description" class="form-label">Description</label>
            <textarea class="form-control" id="description" name="description" rows="3">{{ product.description|safe }}</textarea>
        </div>
        <div class="col-12">
            <div class="form-check">
                <input class="form-check-input" type="checkbox" id="trash" name="trash" {% if product.trash %}checked{% endif %}>
                <label class="form-check-label" for="trash">Trash</label>
            </div>
        </div>
        <div class="col-12">
            <button type="submit" class="btn btn-primary">Update Product</button>
            <a href="{% url 'product-management' %}" class="btn btn-secondary">Back</a>
        </div>
    </form>
</div>
{% endblock %}
