{% extends "base.html" %}
{% block title %}Produit générique{% endblock %}
{% block content %}
<div class="container">
  <h1>{{ 'Modifier' if product else 'Nouveau' }} produit générique</h1>
  <form method="post">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    <div class="mb-3"><label class="form-label" for="name">Nom générique</label><input id="name" class="form-control" required name="name" value="{{ product.name if product else '' }}"></div>
    <div class="mb-3"><label class="form-label" for="description">Description</label><textarea id="description" class="form-control" name="description">{{ product.description if product else '' }}</textarea></div>
    <div class="row">
      <div class="col-md-4"><label class="form-label" for="category_id">Catégorie</label><select id="category_id" class="form-select" name="category_id"><option value="">—</option>{% for c in categories %}<option value="{{ c.id }}" {% if product and product.category_id==c.id %}selected{% endif %}>{{ c.name }}</option>{% endfor %}</select></div>
      <div class="col-md-4"><label class="form-label" for="reference_unit">Unité de référence</label><input id="reference_unit" class="form-control" name="reference_unit" value="{{ product.reference_unit if product else 'unité' }}"></div>
      <div class="col-md-4"><label class="form-label" for="product_type">Type</label><select id="product_type" class="form-select" name="product_type"><option>consommable</option><option>liquide</option><option>matériel</option></select></div>
    </div>
    <div class="row mt-3">
      <div class="col-md-4"><label for="stock_minimum">Stock minimum</label><input id="stock_minimum" class="form-control" type="number" step="0.000001" name="stock_minimum" value="{{ product.stock_minimum if product else 0 }}"></div>
      <div class="col-md-4"><label for="stock_security">Stock de sécurité</label><input id="stock_security" class="form-control" type="number" step="0.000001" name="stock_security" value="{{ product.stock_security if product else 0 }}"></div>
      <div class="col-md-4"><label for="forecast_daily_quantity">Consommation prévue/jour</label><input id="forecast_daily_quantity" class="form-control" type="number" step="0.000001" name="forecast_daily_quantity" value="{{ product.forecast_daily_quantity if product else 0 }}"></div>
    </div>
    <div class="form-check mt-3"><input id="request_enabled" class="form-check-input" type="checkbox" name="request_enabled" {% if not product or product.request_enabled %}checked{% endif %}><label class="form-check-label" for="request_enabled">Proposer sur les fiches papier de demande</label></div>
    {% if product %}<div class="form-check mt-2"><input id="is_active" class="form-check-input" type="checkbox" name="is_active" {% if product.is_active %}checked{% endif %}><label class="form-check-label" for="is_active">Produit actif</label></div>{% endif %}
    <button class="btn btn-primary mt-3">Enregistrer</button>
  </form>
</div>
{% endblock %}
