<!DOCTYPE html>
<html>
<!-- kate: space-indent on; indent-width 2; -->
<head>
    <title>{{DglProjectId}} Line Log Report – {%if Sequences.length > 1 %}Multiple sequences{% else %}Sequence {{Sequences[0].SequenceNumber}}{% endif %}</title>
    <style>

@media print {
  body, html, table {
    font-size: 10px !important;
  }

  a {
    text-decoration: none;
  }

  tr.aside {
    font-size: 8px !important;
  }
}

html {
  font-size: 16px;
  text-rendering: optimizeLegibility;
  background: #FFFFFF;
  color: rgba(0, 0, 0, 0.87);
}

body {
  max-width: 100vw;
  margin: 0;
}

table {
  border-collapse: collapse;
}

table th,
table td {
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
}

table > tbody > tr:not(:last-child) > td,
table > tbody > tr:not(:last-child) > th {
  border-bottom: thin solid rgba(0, 0, 0, 0.12);
}

header {
  display: flex;
  align-items: center;
  height: 50px;
  padding: 8px;
}

header img#logo {
  height: 50px;
  flex: 0 1 auto;
}

header h1 {
  flex: 1 1 auto;
  text-align: center;
}

main {
  min-height: calc(100vh - 116px );
  padding: 8px;
  margin-bottom: 25px;
}

table.summary td:nth-of-type(1) {
  text-align: right;
  padding-inline-start: 1em;
}

table.summary td:nth-of-type(2) {
  font-size: smaller;
  vertical-align: middle;
  text-align: right;
}

.comments {
  margin-top: 1em;
  margin-bottom: 1em;
}

div.sequence:not(:nth-of-type(1)) {
  break-before: page;
}

.comment {
  margin: 0.5em 2em;
  border: thin solid lightgray;
  padding: 1em;
  border-radius: 4px;
}

.nocomment {
  margin: 0.5em 2em;
  color: gray;
  font-style: italic;
}

table.events th,
table.events td {
  padding: 4pt 8pt;
}

table.events tr > td:nth-of-type(1) {
  text-align: right;
}

table.events tr > td:nth-of-type(3) {
  min-width: 20ex;
}

/*
 * In this section we deal with equipment
 */


div.equipment-details {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  column-gap: 2em;
  row-gap: 2em;
}

/* Bug in Firefox: causes the content to overlap

div.equipment-details table {
  break-inside: avoid;
}
*/
/* So we try this instead */
div.equipment {
  break-inside: avoid;
}

table.equipment {
  margin-bottom: 2em;
  font-size: 80%;
}

table.equipment thead {
  border-bottom: 1px solid darkgray;
}

table.equipment tbody + tbody::before {
  content: "";
  display: table-row;
  height: 1.2em;
}

table.equipment tr.aside {
  font-size: small;
  color: gray;
}

/*
  Get rid of Markdown-induced paragraph spacing
  while respecting inter-paragraph margins.
*/
table.equipment p:nth-of-type(1) {
  margin-top: 0;
}
table.equipment p:nth-last-of-type(1) {
  margin-bottom: 0;
}

footer {
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0.5em;
  width: 100%;
  font-size: smaller;
  border-top: thin solid;
  min-height: 25px;

  position: fixed;
  bottom: 0;
  background: white;
}
    </style>
</head>
<body>

<header>
  <img id="logo" src="data:image/png;base64,[encoded data, 22896 characters]">
  <h1>{{DglProjectId}} – Line log</h1>
</header>

<main>
{% for Sequence in Sequences %}
{% set Begin = Sequence.Entries | find("EntryTypeId", 3000) %}
{% set End   = Sequence.Entries | find("EntryTypeId", 3007) %}
<div class="sequence" id="sequence-{{ Sequence.SequenceNumber |padStart(3, "0") }}">
<h2>Sequence {{ Sequence.SequenceNumber |padStart(3, "0") }} ({{Begin.LineType}}{% if End.IsNTBP %} – NTBP{% endif %})</h2>

<table class="summary">
  <tr>
    <th>Line</th>
    <td>{{Sequence.DglSailline}}</td>
    <td></td>
  </tr>
  <tr>
    <th>Start</th>
    <td>{{Begin.ShotPointId}}</td>
    <td>@ {{Begin.Time |timestamp}}</td>
  </tr>
  <tr>
    <th>End</th>
    <td>{{End.ShotPointId}}</td>
    <td>@ {{End.Time |timestamp}}</td>
  </tr>
  <tr>
    <th>Duration</th>
    <td>
      {{Sequence.DglDuration.hours |default(0)|padStart(2, "0")}}:{{Sequence.DglDuration.minutes |default(0)|padStart(2, "0")}}:{{Sequence.DglDuration.seconds |default(0)|padStart(2, "0")}}
    </td>
    <td style="color:gray;">(hh:mm:ss)</td>
  </tr>
  <tr>
    <th>No. Shots</th>
    <td>{{Sequence.DglNumPoints}}</td>
    <td>{{Sequence.DglNumMissing}} missing</td>
  </tr>
  <tr>
    <th>Azimuth</th>
    <td>{{Sequence.DglAzimuth |round |padStart(3, "0")}}°</td>
    <td></td>
  </tr>
  <tr>
    <th>Length</th>
    <td>
      {{Sequence.DglLength |round}} m
    </td>
    <td></td>
  </tr>
</table>

  {% if Begin.Reshoot %}Reshoot{% endif -%}

<div class="comments">

  {% if Sequence.DglSequenceComments %}
  {% if Sequence.DglSequenceComments[0] %}
  <h3>Acquisition Comments</h3>
  <div class="comment">
    {{ Sequence.DglSequenceComments[0] | markdown }}
  </div>
  {% endif %}
  {% if Sequence.DglSequenceComments[1] %}
  <h3>Processing Comments</h3>
  <div class="comment">
    {{ Sequence.DglSequenceComments[1] | markdown }}
  </div>
  {% endif %}
  {% else %}
  <h3>Sequence comments</h3>
  <div class="nocomment">(Nil)</div>
  {% endif %}
</div>

<div class="events">
<h3>Events</h3>

<table class="events">
  <thead>
    <tr>
      <th>Shotpoint</th>
      <th>Timestamp</th>
      <th>Event</th>
      <th>Comment</th>
    </tr>
  </thead>
  <tbody>
  {% for Entry in Sequence.Entries | collect("ShotPointId", ["EntryType", "Comment"]) %}
    <tr>
      <td>{{ Entry.ShotPointId }}</td>
      <td>{{Entry.Time |timestamp}}</td>
      <td>{{Entry.EntryType |join("<br/>")}}</td>
      <td>{{Entry.Comment |unique |join("<br/>")}}</td>
    </tr>
  {% endfor %}
  </tbody>
</table>
</div> <!-- events -->

{% if Sequence.DglEquipmentInfo.length %}
<div class="equipment">
<h3>Equipment Info</h3>

<div class="equipment-details">
{% for kind, items in Sequence.DglEquipmentInfo |sort(false, false, "kind") | groupby("kind") %}
<div> <!-- Needed because flex -->
<table class="equipment">
  <thead>
    <tr>
      <th colspan="2">{{kind}}</th>
    </tr>
  </thead>
  {% for item in items |sort(true, false, "tstamp") %}
  <tbody>
    {% if item.description %}
    <tr>
      <td colspan="2">{{item.description |markdown}}</td>
    </tr>
    {% endif %}
    {% for attr in item.attributes %}
    <tr>
      <th>{{attr.key}}</th>
      <td>{{attr.value |markdownInline}}</td>
    </tr>
    {% endfor %}
    <tr class="aside">
      <td>Last update:</td>
      <td>{{item.tstamp.substring(0,10)}}</td>
    </tr>
  </tbody>
  {% endfor %}
</table>
</div> <!-- Needed because flex -->
{% endfor %}
</div> <!-- equipment-details -->

</div> <!-- equipment -->
{% endif %}

</div> <!-- sequence -->
{% endfor %}

</main>

<footer>
<span>✉ <a href="mailto:hc.om@magseisfairfield.com">hc.om@magseisfairfield.com</a></span>
<span>Created on {{DglCreatedOn |timestamp}}.</span>
</footer>
</body>
</html>
