{% extends "base.html" %}

{% from "components/alert.html" import Alert %}
{% from "components/modal.html" import Modal %}
{% from "components/empty_state.html" import EmptyState %}

{% block content %}

  {% call Modal(name='pendingFinancialVerification', dismissable=True) %}
    <h1>Request submitted!</h1>

    {% include 'fragments/pending_financial_verification.html' %}

    <div class='action-group'>
      <a v-on:click="closeModal('pendingFinancialVerification')" class='action-group__action usa-button'>Close</a>
    </div>
  {% endcall %}

  {% call Modal(name='pendingCCPOApproval', dismissable=True) %}

    {% include 'fragments/pending_ccpo_approval_modal.html' %}

    <div class='action-group'>
      <a v-on:click="closeModal('pendingCCPOApproval')" class='action-group__action usa-button'>Close</a>
    </div>
  {% endcall %}

{% if not requests %}

  {{ EmptyState(
    'There are currently no active requests for you to see.',
    actionLabel='Create a new JEDI Cloud Request',
    actionHref=url_for('requests.requests_form_new', screen=1),
    icon='document'
  ) }}

{% else %}

  {% if pending_financial_verification %}

    {{ Alert('Pending Financial Verification', fragment="fragments/pending_financial_verification.html") }}

  {% endif %}

  {% if pending_ccpo_approval %}

    {{ Alert('Request submitted. Approval pending.', fragment="fragments/pending_ccpo_approval_alert.html") }}

  {% endif %}

  {% if extended_view %}
    <div class="row kpi">
      <div class="kpi__item col col--grow">
        <div class="kpi__item__value">{{ kpi_inprogress }}</div>
        <div class="kpi__item__description">In Progress</div>
      </div>
      <div class="kpi__item col col--grow">
        <div class="kpi__item__value">{{ kpi_pending }}</div>
        <div class="kpi__item__description">Pending CCPO Action</div>
      </div>
      <div class="kpi__item col col--grow">
        <div class="kpi__item__value">{{ kpi_completed }}</div>
        <div class="kpi__item__description">Completed (Overall)</div>
      </div>
    </div>
  {% endif %}

  <div class="col col--grow">

    {% if extended_view %}
      <form class='search-bar'>
        <div class='usa-input search-input'>
          <label for='requests-search'>Search requests by Order ID</label>
          <input type='search' id='requests-search' name='requests-search' placeholder="Search by Order ID"/>
          <button type="submit">
            <span class="hide">Search</span>
          </button>
        </div>

        <div class='usa-input'>
          <label for='filter-status'>Filter requests by status</label>
          <select id="filter-status" name="filter-status">
            <option value="" selected disabled>Filter by status</option>
            <option value="">Active</option>
            <option value="">Pending</option>
            <option value="">Denied</option>
          </select>
        </div>
      </form>
    {% endif %}

    <div class='responsive-table-wrapper'>
      <table>
        <thead>
          <tr>
            <th scope="col">JEDI Cloud Request ID</th>
            <th scope="col">Date Request Initiated / Created</th>
            {% if extended_view %}
              <th scope="col">Requester</th>
              <th scope="col">Reason Flagged</th>
            {% endif %}
            <th scope="col">Projected Annual Usage ($)</th>
            <th scope="col">Request Status</th>
          </tr>
        </thead>
        <tbody>
          {% for r in requests %}
          <tr>
            <th scope="row">
              <a class='icon-link icon-link--large' href="{{ r['edit_link'] }}">{{ r['order_id'] }}</a>
              {% if r['is_new'] %}<span class="usa-label">New</span>
            </th>
            {% endif %}
            <td>{{ r['date'] }}</td>
            {% if extended_view %}
              <td>{{ r['full_name'] }}</td>
              <td></td>
            {% endif %}
            <td>${{ r['annual_usage'] }}</td>
            <td>{{ r['status'] }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>

{% endif %}

{% endblock %}

