{% macro RequiredLabel() -%}
  <span class='label label--error'>Response Required</span>
{%- endmacro %}

{% macro DefinitionReviewField(title, section, item_name, filter=None, filter_args=[]) -%}
  <div>
    <dt>{{ title | safe }}</dt>
    <dd>
      {% set value = data.get(section, {}).get(item_name) %}
      {% if value is not none %}
        {{ value | findFilter(filter, filter_args) }}
      {% else %}
        {{ RequiredLabel() }}
      {% endif %}
    </dd>
  </div>
{% endmacro %}

{% macro EditLink(screen) %}
  {% if request_id %}
    {{ url_for('requests.requests_form_update', screen=screen, request_id=request_id)}}
  {% else %}
    {{ url_for('requests.requests_form_update', screen=screen, request_id=None) }}
  {% endif %}
{% endmacro %}

<h2>
  Details of Use
  {% if editable %}
  <a href="{{ EditLink(1) }}" class="icon-link">
    {{ Icon('edit') }}
    <span>Edit this section</span>
  </a>
  {% endif %}
</h2>

<dl>

  {{ DefinitionReviewField("DoD Component", "details_of_use", "dod_component", filter="getOptionLabel", filter_args=[service_branches]) }}

  {{ DefinitionReviewField("JEDI Cloud Usage", "details_of_use", "jedi_usage") }}

  {{ DefinitionReviewField("Number of software systems", "details_of_use", "num_software_systems", filter="readableInteger") }}

  {{ DefinitionReviewField("JEDI Cloud Migration", "details_of_use", "jedi_migration") }}

  {% if data['details_of_use']['jedi_migration'] == 'yes' %}
    {{ DefinitionReviewField("Rationalization of Software Systems", "details_of_use", "rationalization_software_systems") }}

    {{ DefinitionReviewField("Technical Support Team", "details_of_use", "technical_support_team") }}

    {% if data['details_of_use']['technical_support_team'] == 'yes' %}
      {{ DefinitionReviewField("Organization Providing Assistance", "details_of_use", "organization_providing_assistance", filter="getOptionLabel", filter_args=[assistance_org_types]) }}
    {% endif %}

    {{ DefinitionReviewField("Engineering Assessment", "details_of_use", "engineering_assessment") }}

    {{ DefinitionReviewField("Data Transfers", "details_of_use", "data_transfers", filter="getOptionLabel", filter_args=[data_transfer_amounts]) }}

    {{ DefinitionReviewField("Expected Completion Date", "details_of_use", "expected_completion_date", filter="getOptionLabel", filter_args=[completion_date_ranges]) }}

  {% else %}

    {{ DefinitionReviewField("Cloud Native", "details_of_use", "cloud_native") }}

  {% endif %}

  {{ DefinitionReviewField("Estimated Monthly Spend", "details_of_use", "estimated_monthly_spend", filter="dollars") }}

  {% if jedi_request and jedi_request.annual_spend > annual_spend_threshold %}

    {{ DefinitionReviewField("Number of User Sessions", "details_of_use", "number_user_sessions", filter="readableInteger") }}

    {{ DefinitionReviewField("Average Daily Traffic (Number of Requests)", "details_of_use", "average_daily_traffic", filter="readableInteger") }}

    {{ DefinitionReviewField("Average Daily Traffic (GB)", "details_of_use", "average_daily_traffic_gb", filter="readableInteger") }}

  {% endif %}

  {{ DefinitionReviewField("Total Spend", "details_of_use", "dollar_value", filter="dollars") }}

  {{ DefinitionReviewField("Start Date", "details_of_use", "start_date") }}

  {{ DefinitionReviewField("Request Name", "details_of_use", "name") }}
</dl>

<hr>
<h2>
  Information About You
  {% if editable %}
  <a href="{{ EditLink(2) }}" class="icon-link">
    {{ Icon('edit') }}
    <span>Edit this section</span>
  </a>
  {% endif %}
</h2>

<dl>
  {{ DefinitionReviewField("First Name", "information_about_you", "fname_request") }}

  {{ DefinitionReviewField("Last Name", "information_about_you", "lname_request") }}

  {{ DefinitionReviewField("Email Address", "information_about_you", "email_request") }}

  {{ DefinitionReviewField("Phone Number", "information_about_you", "phone_number", filter="usPhone") }}

  {{ DefinitionReviewField("Service Branch or Agency", "information_about_you", "service_branch", filter="getOptionLabel", filter_args=[service_branches]) }}

  {{ DefinitionReviewField("Citizenship", "information_about_you", "citizenship") }}

  {{ DefinitionReviewField("Designation of Person", "information_about_you", "designation", filter="capitalize") }}

  {{ DefinitionReviewField("Latest Information Assurance (IA) Training completion date", "information_about_you", "date_latest_training") }}
</dl>

<hr>
<h2>
  Workspace Owner
  {% if editable %}
  <a href="{{ EditLink(3) }}" class="icon-link">
    {{ Icon('edit') }}
    <span>Edit this section</span>
  </a>
  {% endif %}
</h2>

<dl>
  {{ DefinitionReviewField("POC First Name", "primary_poc", "fname_poc") }}

  {{ DefinitionReviewField("POC Last Name", "primary_poc", "lname_poc") }}

  {{ DefinitionReviewField("POC Email Address", "primary_poc", "email_poc") }}

  {{ DefinitionReviewField("DoD ID", "primary_poc", "dodid_poc") }}
</dl>

{% if jedi_request.has_financial_data %}
  <hr>
  <h2>
    Financial Verification
  </h2>

  <div>
    {% if jedi_request.task_order.pdf %}
        <a href="{{ url_for("requests.task_order_pdf_download", request_id=request_id)}}" download>
          Download the Task Order PDF
        </a>
    {% else %}
      <p>No Task Order PDF attached.</p>
    {% endif %}
  </div>

  <dl>
    {{ DefinitionReviewField("Task Order Information Source", "task_order", "source", filter="getOptionLabel", filter_args=[task_order_sources]) }}

    {{ DefinitionReviewField("Task Order Number", "task_order", "number") }}

    {{ DefinitionReviewField("What is the source of funding?", "task_order", "funding_type", filter="getOptionLabel", filter_args=[funding_types]) }}

    {% if data["task_order"] and data["task_order"]["funding_type"].value == "OTHER" %}
      {{ DefinitionReviewField("If other, please specify", "task_order", "funding_type_other") }}
    {% endif %}

    {{ DefinitionReviewField("Task Order Expiration Date", "task_order", "expiration_date") }}

    {{ DefinitionReviewField("<dl><dt>CLIN 0001</dt> - <dd>Unclassified IaaS and PaaS Amount</dd></dl>", "task_order", "clin_0001", filter="dollars") }}

    {{ DefinitionReviewField("<dl><dt>CLIN 0003</dt> - <dd>Unclassified Cloud Support Package</dd></dl>", "task_order", "clin_0003", filter="dollars") }}

    {{ DefinitionReviewField("<dl><dt>CLIN 1001</dt> - <dd>Unclassified IaaS and PaaS Amount <br> OPTION PERIOD 1</dd></dl>", "task_order", "clin_1001", filter="dollars") }}

    {{ DefinitionReviewField("<dl><dt>CLIN 1003</dt> - <dd>Unclassified Cloud Support Package <br> OPTION PERIOD 1</dd></dl>", "task_order", "clin_1003", filter="dollars") }}

    {{ DefinitionReviewField("<dl><dt>CLIN 2001</dt> - <dd>Unclassified IaaS and PaaS Amount <br> OPTION PERIOD 2</dd></dl>", "task_order", "clin_2001", filter="dollars") }}

    {{ DefinitionReviewField("<dl><dt>CLIN 2003</dt> - <dd>Unclassified Cloud Support Package <br> OPTION PERIOD 2</dd></dl>", "task_order", "clin_2003", filter="dollars") }}

    {{ DefinitionReviewField("Unique Item Identifier (UII)s related to your application(s) if you already have them", "financial_verification", "uii_ids", filter="renderList") }}

    {{ DefinitionReviewField("Program Element (PE) Number related to your request", "financial_verification", "pe_id") }}

    {{ DefinitionReviewField("Program Treasury Code", "financial_verification", "treasury_code") }}

    {{ DefinitionReviewField("Program Budget Activity (BA) Code", "financial_verification", "ba_code") }}

    {{ DefinitionReviewField("Contracting Officer First Name", "financial_verification", "fname_co") }}

    {{ DefinitionReviewField("Contracting Officer Last Name", "financial_verification", "lname_co") }}

    {{ DefinitionReviewField("Contracting Officer Email", "financial_verification", "email_co") }}

    {{ DefinitionReviewField("Contracting Officer Office", "financial_verification", "office_co") }}

    {{ DefinitionReviewField("Contracting Officer Representative (COR) First Name", "financial_verification", "fname_cor") }}

    {{ DefinitionReviewField("Contracting Officer Representative (COR) Last Name", "financial_verification", "lname_cor") }}

    {{ DefinitionReviewField("Contracting Officer Representative (COR) Email", "financial_verification", "email_cor") }}

    {{ DefinitionReviewField("Contracting Officer Representative (COR) Office", "financial_verification", "office_cor") }}
  </dl>
{% endif %}
