{% extends "layout.html" %}

{% comment %}
Copyright (C) 2022-2026  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 %}

{% load render_bundle from webpack_loader %}
{% load static %}
{% load swh_templatetags %}

{% block header %}
  {% render_bundle 'add_forge_now' %}
{% endblock header %}

{% block page_title %}
  {{ heading }}
{% endblock page_title %}

{% block navbar-content %}
  <h4>Add forge now request dashboard</h4>
{% endblock navbar-content %}

{% block content %}
  <div class="container">
    <div id="fetchError" class="row d-none">
      <h3>Error fetching information about the request</h3>
    </div>
    <div class="row" id="requestDetails">
      <div id="ForgeRequestActions" class="col-md-8 request-actions">
        <div>
          <div class="accordion" id="requestHistory"></div>
        </div>
        <div>
          <form method="POST"
                action="{% url 'api-1-add-forge-request-update' request_id %}"
                style="padding-top: 5px"
                id="updateRequestForm">
            {% csrf_token %}
            <div class="row">
              <div class="col-md-6">
                <label for="decisionOptions" class="form-label swh-required-label">Choose your decision</label>
                <select class="form-control form-select"
                        id="decisionOptions"
                        name="new_status"></select>
              </div>
            </div>
            <div class="row mt-3">
              <div class="col-md-12">
                <label for="swh-input-forge-comment" class="form-label swh-required-label">Comment</label>
                <textarea class="form-control" id="updateComment" name="text" rows="3" required></textarea>
                <small class="form-text text-black-50">Enter a comment related to your decision.</small>
              </div>
            </div>
            <div class="row mt-3">
              <div class="col-md-6">
                <button id="update-request-submit"
                        type="submit"
                        class="btn btn-secondary mb-2">Submit</button>
              </div>
            </div>
            <div class="row">
              <div class="col-md-12">
                <h3 class="text-center">
                  <span id="userMessage" class="badge"></span>
                </h3>
              </div>
            </div>
          </form>
        </div>
      </div>
      <div id="ForgeRequestDetails" class="col-md-4">
        <div>
          <strong>Request status</strong>
        </div>
        <small class="details-text" id="requestStatus"></small>
        <hr />
        <div>
          <strong>Forge type</strong>
        </div>
        <small class="details-text" id="requestType"></small>
        <hr />
        <div>
          <strong>Forge URL</strong>
        </div>
        <small class="details-text" id="requestURL"></small>
        <hr />
        <div>
          <strong>Contact name</strong>
        </div>
        <small class="details-text" id="requestContactName"></small>
        <hr />
        <div>
          <strong>Consent to use name</strong>
        </div>
        <small class="details-text" id="requestContactConsent"></small>
        <hr />
        <div>
          <strong>Contact email</strong>
        </div>
        <small class="details-text" id="requestContactEmail"></small>
        <hr />
        <div>
          <strong>Message</strong>
        </div>
        <p>
          <small id="submitterMessage" class="details-text"></small>
        </p>
        <hr />
        <div>
          <a class="btn btn-secondary me-3"
             type="button"
             id="contactForgeAdmin"
             emailSubject=""
             emailTo=""
             emailCc="">
            <i class="mdi mdi-email-outline mdi-fw"></i>Send message to the forge
          </a>
          {% if request_edit_url %}
            <a class="btn btn-secondary"
               id="editRequestDetails"
               type="button"
               href="{{ request_edit_url }}">
              <i class="mdi mdi-database-edit-outline mdi-fw"></i>Edit request details
            </a>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
  {{ next_statuses_for|swh_json_script:"next_statuses_for" }}
  <script>
    swh.webapp.initPage('add-forge-now-moderation');
    swh.add_forge_now.onRequestDashboardLoad(
      "{{ request_id }}", swh.webapp.parseJsonScript('next_statuses_for')
    );
  </script>
{% endblock content %}
