{% extends "base.html" %}
{% comment %}
# SPDX-License-Identifier: AGPL-3.0-or-later
{% endcomment %}

{% load bootstrap %}
{% load i18n %}
{% load static %}
{% load extras %}

{% block page_js %}
  <script src="{% static 'backups/backups_add_remote_repository.js' %}"
          defer></script>
{% endblock %}

{% block content %}

  <h3>{{ title }}</h3>

  <form class="form form-add-remote-repository" method="post">
    {% if form.non_field_errors %}
        <div class="alert alert-danger">
            <a class="close" data-dismiss="alert">&times;</a>
            {% for non_field_error in form.non_field_errors %}
                {{ non_field_error }}
            {% endfor %}
        </div>
    {% endif %}

    {% csrf_token %}

    <div class="form-group{% if form.repository.errors %}
                has-error{% endif %}">
      <label class="control-label fs-4 fw-medium" for="id_repository">
        {{ form.repository.label }}
      </label>
      <div>
        <input type="text" name="repository" class="form-control"
               required id="id_repository">
        {% for error in form.repository.errors %}
            <span class="help-block {{ form.error_css_class }}">{{ error }}</span>
        {% endfor %}
        <p class="help-block">
          {{ form.repository.help_text|safe }}
        </p>
      </div>
    </div>

    <div class="form-group{% if form.ssh_auth_type.errors %}
                has-error{% endif %}">
      <label class="control-label fs-4 fw-medium">
        {{ form.ssh_auth_type.label }}
      </label>
      <p class="help-block">
        {{ form.ssh_auth_type.help_text|safe }}
      </p>
      {% for error in form.ssh_auth_type.errors %}
        <span class="help-block {{ form.error_css_class }}">{{ error }}</span>
      {% endfor %}

      <div class="radio">
        <label>
          {{ form.ssh_auth_type.0.tag }}
          {{ form.ssh_auth_type.0.choice_label }}
        </label>
      </div>

      <div>
        <p>
          {% blocktrans trimmed %}
            The following SSH client public key must be added to the
            authorized keys list on the remote machine for {{ box_name }} to
            be able to connect to the remote machine:
          {% endblocktrans %}
        </p>
        <pre>{{ ssh_client_public_key }}</pre>
      </div>

      <div class="radio">
        <label>
          {{ form.ssh_auth_type.1.tag }}
          {{ form.ssh_auth_type.1.choice_label }}
        </label>
      </div>

      <p>
        {% blocktrans trimmed %}
          {{ box_name }} service will attempt to connect using the provided
          password. If successful, then the public key will be automatically
          added to the authorized keys list, so that future connections do
          not need the password.
        {% endblocktrans %}
      </p>

      {% with _=form.ssh_password|add_input_classes %}
        {% include "bootstrapform/field.html" with field=form.ssh_password %}
      {% endwith %}
    </div>

    <div class="form-group">
      <div class="form-group{% if form.encryption.errors %}
                  has-error{% endif %}">
        <label class="control-label fs-4 fw-medium" for="id_encryption">
          {{ form.encryption.label }}
        </label>
        <div>
          <select name="encryption" class="form-control" id="id_encryption">
            <option value="repokey">{{ form.encryption.0.choice_label }}</option>
            <option value="none">{{ form.encryption.1.choice_label }}</option>
          </select>
          {% for error in form.encryption.errors %}
            <span class="help-block {{ form.error_css_class }}">{{ error }}</span>
          {% endfor %}
          <p class="help-block">
            {{ form.encryption.help_text|safe }}
          </p>
        </div>
      </div>

      {% with _=form.encryption_passphrase|add_input_classes %}
        {% include "bootstrapform/field.html" with field=form.encryption_passphrase %}
      {% endwith %}

      {% with _=form.confirm_encryption_passphrase|add_input_classes %}
        {% include "bootstrapform/field.html" with field=form.confirm_encryption_passphrase %}
      {% endwith %}
    </div>

    <div class="alert alert-warning d-flex align-items-center" role="alert">
      <div class="me-2">
        {% icon 'exclamation-triangle' %}
        <span class="visually-hidden">{% trans "Caution:" %}</span>
      </div>
      <div>
        {% blocktrans trimmed %}
          The credentials for this repository are stored on your {{ box_name }}.
          <br />
          To restore a backup on a new {{ box_name }} you need the SSH
          credentials and, if chosen, the encryption passphrase.
        {% endblocktrans %}
      </div>
    </div>

    <input type="submit" class="btn btn-primary"
           value="{% trans "Create Location" %}"/>
  </form>

{% endblock %}
