{% load template_tags %}
<!DOCTYPE html>
<html lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Application Area</title>
      {% include 'html_export/milligram.htm' %}
      {% include 'html_export/custom_style.htm' %}
   </head>
   <body>
      <header>
         {% include 'html_export/custom_header.htm' %}
         <h1>Application Area</h1>
      </header>
      <main>
         {% for resource in resources %}
         {% with resource_data=resource.resource %}
         <section class="section-title">
            <blockquote>
               <h2>{{ resource.displayname }}</h2>
            </blockquote>
         </section>

         {# System Ref #}
         {% if resource_data|has_key:"System Reference Numbers" %}
         <section>
            <div class="container">
               <div class="row">
                  <div class="column">
                     <div>
                        <h3>System Reference Numbers</h3>
                        <p>
                           <strong>Primary Reference Number: </strong>{{ resource_data|val_from_key:"System Reference Numbers"|val_from_key:"PrimaryReferenceNumber"|val_from_key:"Primary Reference Number"|val_from_key:"@display_value" }}<br>
                           <strong>Legacy ID: </strong>{{ resource_data|val_from_key:"System Reference Numbers"|val_from_key:"LegacyID"|val_from_key:"Legacy ID"|val_from_key:"@display_value" }}
                        </p>
                     </div>
                  </div>
               </div>
            </div>
         </section>
         <hr/>
         {% endif %}


         {# References #}
         {% if resource_data|has_key:"References" %}
         <section>
            <div class="container">
               <h3>References</h3>
               <div class="row">
                  <div class="column">
                     <div class="keeptogether">
                        <div class="rtable">
                           <div class="rrow rheader">
                              <div class="rcell">Reference Number</div>
                              <div class="rcell">Reference Number Type</div>
                           </div>
                           {% for ref in resource_data|val_from_key:"References" %}
                           <div class="rrow">
                              <div class="rcell" data-title="Reference Number">
                                 {{ ref|val_from_key:"Reference Number"|val_from_key:"@display_value" }}
                              </div>

                              <div class="rcell" data-title="Reference Number Type">
                                 {{ ref|val_from_key:"Reference Number Type"|val_from_key:"@display_value" }}
                              </div>
                           </div>
                           {% endfor %}
                        </div>
                     </div>
                  </div>
               </div>
            </div>
         </section>
         <hr/>
         {% endif %}


         {# Application Area Names #}
         {% if resource_data|has_key:"Application Area Names" %}
         <section>
            <div class="container">
               <div class="row">
                  <div class="column">
                     <div>
                        <h3>Application Area Name</h3>
                        <p>
                           <strong>Name: </strong>{{ resource_data|val_from_key:"Application Area Names"|val_from_key:"Application Area Name"|val_from_key:"@display_value"}}<br>
                           <strong>Name Type: </strong>{{ resource_data|val_from_key:"Application Area Names"|val_from_key:"Application Area Name Type"|val_from_key:"@display_value" }}
                        </p>
                     </div>
                  </div>
               </div>
            </div>
        </section>
         <hr/>
         {% endif %}


         {# Location Data #}
         {% if resource_data|has_key:"Localities/Administrative Areas" or "Addresses" %}
         <section>
            <div class="container location-details">
               <h3>Location Information</h3>
               <div class="row">
                  <div class="column">
                     <div class="keeptogether">
                        <div class="row">
                            <div class="column">
                                <h4>Localities/Administrative Areas</h4>
                                <p>
                                    {% if resource_data|has_key:"Localities/Administrative Areas" %}
                                    {% for area in resource_data|val_from_key:"Localities/Administrative Areas" %}

                                    {# there is a bug that passes a dict if there are no addresses in this branch... let's check for a key to stop this from causing odd artifacts #}
                                    {% if area|val_from_key:"Area Type"|has_key:"@display_value" %}
                                       <strong>{{ area|val_from_key:"Area Type"|val_from_key:"@display_value" }}:</strong> {{ area|val_from_key:"Area Names"|val_from_key:"Area Name"|val_from_key:"@display_value" }}</br/>
                                    {% else %}
                                       {{ area|val_from_key:"Area Names"|val_from_key:"Area Name"|val_from_key:"@display_value" }}</br/>
                                    {% endif %}

                                    {% endfor %}
                                    {% endif %}
                                </p>
                            </div>
                            <div class="column">
                                {# there is a bug that passes a dict if there are no addresses in this branch... let's check for a key to stop this from causing odd artifacts #}
                                {% with address_check=resource_data|val_from_key:"Addresses" %}
                                {% if address_check.0|has_key:"Full Address" %}
                                <div class="keeptogether">
                                    <h4>Addresses</h4>
                                    <div class="rtable">
                                    <div class="rrow rheader">
                                        <div class="rcell">Full Address</div>
                                        <div class="rcell">Locality</div>
                                    </div>
                                    {% for address in resource_data|val_from_key:"Addresses" %}

                                    <div class="rrow">
                                        <div class="rcell" data-title="Full Address">
                                                {{ address|val_from_key:"Full Address"|val_from_key:"@display_value" }}
                                        </div>
                                        <div class="rcell" data-title="Locality">
                                            {{ address|val_from_key:"Locality"|val_from_key:"Locality Value"|val_from_key:"@display_value" }}
                                        </div>
                                    </div>
                                    {% endfor %}
                                    </div>
                                </div>
                                {% endif %}
                                {% endwith %}
                            </div>
                        </div>
                    </div>
               </div>
            </div>
        </section>
        <hr/>
        {% endif %}

        {# Designation and Protection Assignment #}
        {% if resource_data|has_key:"Designation and Protection Assignment" %}
        <section>
           <div class="container">
              <h3>Designation and Protection Assignment</h3>
              <div class="row">
                 <div class="column">
                    <div class="keeptogether">
                       <div class="rtable">
                          <div class="rrow rheader">
                             <div class="rcell">Designation Name</div>
                             <div class="rcell">Designation or Protection Type</div>
                             <div class="rcell">Grade</div>
                          </div>
                          {% for desig in resource_data|val_from_key:"Designation and Protection Assignment" %}
                          <div class="rrow">
                             <div class="rcell" data-title="Designation Name">
                                {{ desig|val_from_key:"Designation Names"|val_from_key:"Designation Name"|val_from_key:"@display_value" }}
                             </div>
                             <div class="rcell" data-title="Designation or Protection Type">
                                {{ desig|val_from_key:"Designation or Protection Type"|val_from_key:"@display_value" }}
                             </div>
                             <div class="rcell" data-title="Grade">
                                {{ desig|val_from_key:"Grade"|val_from_key:"@display_value" }}
                             </div>
                          </div>
                          {% endfor %}
                       </div>
                    </div>
                 </div>
              </div>
           </div>
        </section>
        <hr/>
        {% endif %}


        {# Associated Application Areas #}
        {% if resource_data|has_key:"Associated Application Area" %}
        <section>
           <div class="container">
              <h3>Associated Application Areas</h3>
              <div class="row">
                 <div class="column">
                    <div class="keeptogether">
                       {{ resource_data|val_from_key:"Associated Application Area" |val_from_key:"@display_value" }}
                    </div>
                 </div>
              </div>
           </div>
        </section>
        <hr/>
        {% endif %}

        {# Associated Consultations #}
        {% if resource_data|has_key:"Associated Consultations" %}
        <section>
           <div class="container">
              <h3>Associated Consultations</h3>
              <div class="row">
                 <div class="column">
                    <div class="keeptogether">
                       {{ resource_data|val_from_key:"Associated Consultations"|val_from_key:"@display_value" }}
                    </div>
                 </div>
              </div>
           </div>
        </section>
        <hr/>
        {% endif %}

        {# Associated Monuments/Areas/Artefacts/Maritime Vessels/Historic Aircraft #}
        {% if resource_data|has_key:"Associated Monuments, Areas and Artefacts" %}
        <section>
           <div class="container">
              <h3>Associated Monuments, Areas and Artefacts</h3>
              <div class="row">
                 <div class="column">
                    <div class="keeptogether">
                        {{ resource_data|val_from_key:"Associated Monuments, Areas and Artefacts"|val_from_key:"@display_value" }}
                    </div>
                 </div>
              </div>
           </div>
        </section>
        <hr/>
        {% endif %}

        {# Associated Activities #}
        {% if resource_data|has_key:"Associated Activities" %}
        <section>
           <div class="container">
              <h3>Associated Activities</h3>
              <div class="row">
                 <div class="column">
                    <div class="keeptogether">
                       {{ resource_data|val_from_key:"Associated Activities"|val_from_key:"@display_value" }}
                    </div>
                 </div>
              </div>
           </div>
        </section>
        <hr/>
        {% endif %}


         {% endwith%}
         {% endfor %}
        </main>
    </body>
 </html>