{% extends "./add-forge-common.html" %}

{% comment %}
Copyright (C) 2022-2024  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"
           href="{% url login_url %}?next={% url 'forge-add-create' %}">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="row g-3">
          <div class="col-md-5">
            <label for="swh-input-forge-type" class="form-label swh-required-label">Forge type</label>
            <select class="form-select form-control"
                    id="swh-input-forge-type"
                    name="forge_type"
                    autofocus>
              <option hidden disabled selected value></option>
              {% for forge_type in forge_types %}
                <option value={{ forge_type }}>{{ forge_type }}
                </option>
              {% endfor %}
            </select>
            <small class="form-text text-black-50">Supported forge types in software archive.</small>
          </div>
          <div class="col-md-7">
            <label for="swh-input-forge-url" class="form-label swh-required-label">Forge URL</label>
            <input type="text"
                   class="form-control"
                   id="swh-input-forge-url"
                   name="forge_url"
                   oninput="swh.add_forge_now.validateForgeUrl(this)"
                   required />
            <small class="form-text text-black-50">Base URL of the forge.</small>
            <input type="hidden" id="swh-input-forge-validate" value="on" />
          </div>
        </div>
        <div class="row g-3 mt-1">
          <div class="col-md-5">
            <label for="swh-input-forge-contact-name"
                   class="form-label 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-black-50">Name of the forge administrator.</small>
          </div>
          <div class="col-md-7">
            <label for="swh-input-forge-contact-email"
                   class="form-label 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-black-50">
              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="row mt-3">
          <div class="form-check">
            <input class="form-check-input"
                   type="checkbox"
                   id="swh-input-consent-check"
                   name="submitter_forward_username" />
            <label class="form-check-label" for="swh-input-consent-check">
              I consent to add my username in the communication with the forge.
            </label>
          </div>
        </div>
        <div class="row mt-3">
          <div class="col-md-12">
            <label class="form-label" for="swh-input-forge-comment">Comment</label>
            {% spaceless %}
              <textarea class="form-control" id="swh-input-forge-comment" name="forge_contact_comment" rows="3">
              </textarea>
            {% endspaceless %}
            <small class="form-text text-black-50">Optionally, leave a comment to the moderator regarding your request.</small>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <input id="swh-input-form-submit"
                   type="submit"
                   value="Submit Add Request"
                   class="btn btn-secondary float-end" />
          </div>
        </div>
        <div class="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="{% url 'forge-add-list' %}">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 tab_content %}
