{% extends 'base.html' %}
{% block title %}{% if product %}Edit Product{% else %}Add Product{% endif %}{% endblock %}

{% block content %}
<div class="flex justify-between items-center mb-6">
  <h1 class="text-2xl font-bold">{% if product %}Edit {{ product.name }}{% else %}Add Product{% endif %}</h1>
  <a href="{% url 'inventory:product_list' %}" class="btn btn-ghost btn-sm">← Back</a>
</div>

{% load form_tags %}
<div class="card bg-base-100 shadow max-w-2xl">
  <div class="card-body">
    <form method="post" enctype="multipart/form-data">
      {% csrf_token %}
      {% if form.non_field_errors %}
        <div class="alert alert-error mb-4">
          <span>{{ form.non_field_errors }}</span>
        </div>
      {% endif %}
      <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
        {% for field in form %}
          <div class="form-control {% if field.name == 'name' %}md:col-span-2{% endif %}">
            <label class="label">
              <span class="label-text">{{ field.label }}</span>
            </label>
            {{ field|daisyui }}
            {% if field.help_text %}
              <span class="label-text-alt text-base-content/40 mt-1">{{ field.help_text }}</span>
            {% endif %}
            {% for error in field.errors %}
              <span class="text-error text-sm">{{ error }}</span>
            {% endfor %}
          </div>
        {% endfor %}
      </div>
      <div class="card-actions justify-end mt-6">
        <a href="{% url 'inventory:product_list' %}" class="btn btn-ghost">Cancel</a>
        <button type="submit" class="btn btn-primary">💾 Save Product</button>
      </div>
    </form>
  </div>
</div>
{% endblock %}
