{% extends "base.html" %}
{% block toplink %}{% if delivery.id %}<a href="{{ url_for('show_delivery', id=delivery.id) }}">↶ Retourner à la distribution</a>{% endif %}{% endblock %}
{% block body %}
<div class="header">
{% if delivery.id %}
    <h1>Modifier la distribution</h1>
    <div class="pure-menu pure-menu-horizontal">
        <ul class="pure-menu-list">
            <li class="pure-menu-item">
                <a class="pure-menu-link" href="{{ url_for('list_products', id=delivery.id) }}"><i class="icon-pencil"></i> Gérer les produits / product⋅eur⋅rice⋅s</a>
            </li>
        </ul>
    </div>
{% else %}
    <h1>Nouvelle distribution</h1>
{% endif %}

</div>
<form method="post">
    <label>
        <p>Nom de la distribution</p>
        <input type="text" name="name" value="{{ delivery.name or '' }}">
    </label>
    <label>
        <p>Référent⋅e</p>
        <input type="email" name="contact" value="{{ delivery.contact or request.user.email }}" required>
    </label>
    <label>
        <p>Téléphone référent⋅e</p>
        <input id="contact_phone" onInput="prettifyPhoneNumber('contact_phone')" type="phone" name="contact_phone" value="{{ delivery.contact_phone }}" required>
    </label>
    
    <label>
        <p>Lieu</p>
        <input type="text" name="where" value="{{ delivery.where or '' }}" required>
    </label>
    <label>
        <p>Date de distribution</p>
        <input type="date" name="date" value="{{ delivery.from_date.date() if delivery.from_date else '' }}" required> de <input type="time" name="from_time" value="{{ delivery.from_date.time() if delivery.from_date else '' }}" required> à <input type="time" name="to_time" value="{{ delivery.to_date.time() if delivery.to_date else '' }}" required>
    </label>
    <label>
        <p>Date de limite de commande</p>
        <input type="date" name="order_before" value="{{ delivery.order_before.date() if delivery.order_before else '' }}" required>
    </label>
    <label>
        <p>Instructions particulières</p>
        <input type="text" name="instructions" value="{{ delivery.instructions or '' }}">
    </label>
    <div>
        <input type="submit" name="submit" value="Valider" class="primary">
    </div>
</form>
<hr>
{% endblock body %}
