{% extends 'generic/object_edit.html' %}
{% load i18n %}

{% block content %}
  {% include 'users/inc/v1_token_warning.html' %}
  {{ block.super }}
{% endblock %}

{% block javascript %}
{{ block.super }}
<script>
  (function () {
    const versionField = document.getElementById('id_version');
    const v1Warning = document.getElementById('v1-deprecation-warning');
    if (versionField && v1Warning) {
      function updateV1Warning() {
        v1Warning.style.display = versionField.value === '1' ? '' : 'none';
      }
      versionField.addEventListener('change', updateV1Warning);
      updateV1Warning();
    }
  })();
</script>
{% endblock javascript %}

{% block buttons %}
  {# Omit the "Create & Add Another" button: that flow would redirect away from the detail page before the #}
  {# one-time plaintext can be displayed, leaving the new token unrecoverable. #}
  <a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a>
  {% if object.pk %}
    <button type="submit" name="_update" class="btn btn-primary">{% trans "Save" %}</button>
  {% else %}
    <button type="submit" name="_create" class="btn btn-primary">{% trans "Create" %}</button>
  {% endif %}
{% endblock buttons %}
