<style>
  .A4 #titleblock { /* Need to force width on A4 paper */
    width:180mm;
  }

  #titleblock {
    position: absolute;
    bottom: 0;
    right: 0;
  }

  #titleblock table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
  }

  #titleblock tr {
    height: {{ options.titleblock_row_height }}mm;
  }

  #titleblock .name {
    width: 16mm;
  }

  #titleblock .date {
    width: 10mm;
  }

  #titleblock .revno {
    text-align: center;
    width: 6mm;
  }

  #titleblock .changelog {
    width: 22mm;
  }

  #titleblock .process {
    width: 18mm;
  }

  #titleblock .title {
    width: 82mm;
    font-size: {{ options.titleblock_row_height }};
    text-align: center;
    white-space: normal;
    font-weight: 700;
  }

  #titleblock .company {
    font-size: 4mm;
    text-align: center;
    white-space: normal;
  }

  #titleblock .gitstatus {
    text-align: center;
    font-style: italic;
    width: 4mm;
  }

  #titleblock .partno {
    font-size: 4mm;
    text-align: center;
    white-space: normal;
  }

  #titleblock .revision {
    font-size: 3mm;
    text-align: center;
    white-space: normal;
  }

  #titleblock .sheetno {
    width: 12.75mm;
    text-align: center;
  }
</style>

<!-- REVISION GENERATION MACRO --!>
{% macro revision(row) -%}
    {% set index = 8 - row %}
    {% if row == 9 %}
      <td class=rev><b>Rev</td>
      <td class=date><b>Date</td>
      <td class=name><b>Name</td>
      <td class=changelog><b>Changelog</td>
    {% elif metadata.revisions_list|length > index %}
      {% set revision = metadata.revisions_list[index] %}
      <td class=rev> {{ revision.revision }} </td>
      <td class=date> {{ revision.date }} </td>
      <td class=name> {{ revision.name }} </td>
      <td class=changelog> {{ revision.changelog }} </td>
    {% else %}
      <td class=rev> </td>
      <td class=date> </td>
      <td class=name> </td>
      <td class=changelog> </td>
    {% endif %}
{%- endmacro %}

<!-- AUTHOR GENERATION MACRO --!>
{% macro author(row) -%}
  {% set index = row - 2 %}
  {% if row == 1 %}
    <td class="process"></td>
    <td class="date"><b>Date</b></td>
    <td class="name"><b>Name</b></td>
  {% elif metadata.authors_list|length > index %}
    {% set author = metadata.authors_list[index] %}
    <td><b> {{ author.role }} </b></td>
    <td>    {{ author.date }}</td>
    <td>    {{ author.name }}</td>
  {% else %}
    <td></td>
    <td></td>
    <td></td>
  {% endif %}
{%- endmacro %}

<!-- START OF TEMPLATE --!>
<div id="titleblock">
  <table>
    <tr> <!-- ROW 1 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(1) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      {{ author(1) }}
      <!-- HARNESS INFO         Column 8 to 10 --!>
      <td class="company" colspan="4" rowspan="2"><b> {{ metadata.company }}</b></td>
    </tr>

    <tr> <!-- ROW 2 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(2) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      {{ author(2) }}
      <!-- HARNESS INFO         Column 8 to 10 --!>
    </tr>

    <tr> <!-- ROW 3 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(3) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      {{ author(3) }}
      <!-- HARNESS INFO         Column 8 to 10 --!>
      <td class="address" colspan="4" rowspan="2"><small> {{ metadata.address }}</small></td>
    </tr>

    <tr> <!-- ROW 4 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(4) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      {{ author(4) }}
      <!-- HARNESS INFO         Column 8 to 10 --!>
    </tr>

    <tr> <!-- ROW 5 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(5) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      {{ author(5) }}
      <!-- HARNESS INFO         Column 8 to 10 --!>
      <td class="title" colspan="4" rowspan="2">
        {{ metadata.title }}
        {% if metadata.name and metadata.name != metadata.title %}
        <div style="font-size: {{ options.titleblock_row_height * 0.8 }}mm; font-weight: 500;">
          {{ metadata.name }}
        </div>
        {% endif %}
      </td>
    </tr>

    <tr> <!-- ROW 6 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(6) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      <td class="logo" colspan="3" rowspan="4" >
       {% if metadata.logo %}
         <img src={{ metadata.logo }} alt="" style="height:auto; width:150px;display:block;margin-left:auto;margin-right:auto" />
       {% endif %}
      </td>
      <!-- HARNESS INFO         Column 8 to 10 --!>
    </tr>

    <tr> <!-- ROW 7 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(7) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      <!-- HARNESS INFO         Column 8 to 10 --!>
      <td class="partno" colspan="3" rowspan="2"> {{ partno }}</td>
      <td class="revision" colspan="1" rowspan="2"> REV {{ metadata.revision }}</td>
    </tr>

    <tr> <!-- ROW 8 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(8) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      <!-- HARNESS INFO         Column 8 to 10 --!>
    </tr>

    <tr> <!-- ROW 9 --!>
      <!-- REVISIONS            Column 1 to 4 --!>
      {{ revision(9) }}
      <!-- AUTHOR INFO + LOGO   Column 5 to 7 --!>
      <!-- HARNESS INFO         Column 8 to 10 --!>
      <td class="gitstatus" colspan="3" rowspan="1"> {{ metadata.git_status }}</td>
      <td class="sheetno" colspan="1">Sheet {{ metadata.sheet_current }} of {{ metadata.sheet_total }}</td>
    </tr>

  </table>
</div>  <!-- /titleblock --!>
