{% extends "./common.html" %}

{% comment %}
Copyright (C) 2022  The Software Heritage developers
See the AUTHORS file at the top-level directory of this distribution
License: GNU Affero General Public License version 3, or any later version
See top-level LICENSE file for more information
{% endcomment %}

{% block tab_content %}
  <div id="swh-add-forge-submit-request" class="tab-pane active mt-3">
    {% if not user.is_authenticated %}
      <p class="text-primary">
        You must be logged in to submit an add forge request. Please
        <a id="loginLink" class="link-primary"
        {% if oidc_enabled and 'remote_user' in request.GET %}
          href="{% url 'oidc-login' %}?next={% url 'forge-add-create' %}"
        {% else %}
          href="{% url 'login' %}?next={% url 'forge-add-create' %}"
        {% endif %}>log in</a>
      </p>
    {% else %}

      <form method="POST" action="{% url 'api-1-add-forge-request-create' %}"
            id="requestCreateForm" class="collapse show">
        {% csrf_token %}
        <div class="form-row">
          <div class="form-group col-md-5">
            <label for="swh-input-forge-type" class="swh-required-label">
              Forge type
            </label>
            <select class="form-control" id="swh-input-forge-type"
                    name="forge_type" autofocus>
              {% for forge_type in forge_types %}
              <option value={{ forge_type }}>{{ forge_type}}</option>
              {% endfor %}
            </select>
            <small class="form-text text-muted">
              Supported forge types in software archive.
            </small>
          </div>

          <div class="form-group col-md-7">
            <label for="swh-input-forge-url" class="swh-required-label">
              Forge URL
            </label>
            <input type="text" class="form-control" id="swh-input-forge-url"
                   name="forge_url" required>
            <small class="form-text text-muted">
              Remote URL of the forge.
            </small>
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-md-5">
            <label for="swh-input-forge-contact-name" class="swh-required-label">
              Forge contact name
            </label>
            <input type="text" class="form-control" name="forge_contact_name"
                   id="swh-input-forge-contact-name" required>
            <small class="form-text text-muted">
              Name of the forge administrator.
            </small>
          </div>

          <div class="form-group col-md-7">
            <label for="swh-input-forge-contact-email" class="swh-required-label">
              Forge contact email
            </label>
            <input type="email" class="form-control" name="forge_contact_email"
                   id="swh-input-forge-contact-email" required>
            <small class="form-text text-muted">
              Email of the forge administrator. The given email address will not be used
              for any purpose outside the “add forge now” process.
            </small>
          </div>
        </div>

        <div class="form-row">
          <div class="form-group form-check">
            <input class="form-check-input" type="checkbox"
                  id="swh-input-consent-check" name="submitter_forward_username">
            <label for="swh-input-consent-check">
              I consent to add my username in the communication with the forge.
            </label>
          </div>
        </div>

        <div class="form-row">
          <div class="form-group col-md-12">
            <label for="swh-input-forge-comment">Comment</label>
            <textarea class="form-control" id="swh-input-forge-comment"
                      name="forge_contact_comment" rows="3">
            </textarea>
            <small class="form-text text-muted">
              Optionally, leave a comment to the moderator regarding your request.
            </small>
          </div>
        </div>

        <div class="form-row">
          <div class="col-md-12">
            <input id="swh-input-form-submit" type="submit" value="Submit Add Request"
                   class="btn btn-default float-right">
          </div>
        </div>

        <div class="form-row">
          <div class="col-md-12">
            <h3 class="text-center">
              <span id="userMessage" class="badge"></span>
            </h3>
            <p class="text-center">
              <span id="userMessageDetail"></span>
            </p>
          </div>
        </div>
      </form>
      <p>
        Once an add-forge-request is submitted, its status can be viewed in
        the <a id="swh-show-forge-add-requests-list" href="#browse-requests">
        submitted requests list</a>. This process involves a moderator approval and
        might take a few days to handle (it primarily depends on the response
        time from the forge).
      </p>
    {% endif %}
  </div>
{% endblock %}
