{% extends "core/base.jinja" %}

{% block content %}
  {% if object %}
    <h2>{% trans name=object %}Edit product {{ name }}{% endtrans %}</h2>
  {% else %}
    <h2>{% trans %}Product creation{% endtrans %}</h2>
  {% endif %}
  <form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.as_p() }}

    <br />

    <h3>{% trans %}Automatic actions{% endtrans %}</h3>

    <p class="margin-bottom">
      <em>
        {%- trans trimmed -%}
          Automatic actions allows to schedule product changes
          ahead of time.
        {%- endtrans -%}
      </em>
    </p>

    {{ form.action_formset.management_form }}
    {%- for action_form in form.action_formset.forms -%}
      <fieldset x-data="{action: '{{ action_form.task.initial }}'}">
        {{ action_form.non_field_errors() }}
        <div class="row gap-2x margin-bottom">
          <div>
            {{ action_form.task.errors }}
            {{ action_form.task.label_tag() }}
            {{ action_form.task|add_attr("x-model=action") }}
          </div>
          <div>{{ action_form.trigger_at.as_field_group() }}</div>
        </div>
        <div x-show="action==='counter.tasks.change_counters'" class="margin-bottom">
          {{ action_form.counters.as_field_group() }}
        </div>
        {%- if action_form.DELETE -%}
          <div class="row gap">
            {{ action_form.DELETE.as_field_group() }}
          </div>
        {%- endif -%}
        {%- for field in action_form.hidden_fields() -%}
          {{ field }}
        {%- endfor -%}
      </fieldset>
      {%- if not loop.last -%}
        <hr class="margin-bottom">
      {%- endif -%}
    {%- endfor -%}
    <p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
  </form>
{% endblock %}