<!--
    Worksheet AR-by-column Template

    All data is available using the worksheet dictionary.
    Example for accessing and displaying data:

    <p tal:content="python:worksheet['laboratory']['title']"></p>
    or
    <p tal:content="worksheet/laboratory/title"></p>

    See README.txt for further details about the dict structure

-->
<tal:print
  i18n:domain="senaite.core"
  tal:define="worksheet       python:view.getWorksheet();
              laboratory      worksheet/laboratory;
              portal          worksheet/portal;
              ars             worksheet/ars;
              anstitles       worksheet/analyses_titles;">

  <div id="header">
    <div class='barcode-container'>
      <div class='barcode'
           data-code='code128'
           data-showHRI='false'
           data-barHeight='15'
           data-addQuietZone='true'
           tal:attributes="data-id worksheet/id">
      </div>
    </div>
    <div class='lab-logo'>
      <a tal:attributes="href laboratory/url">
        <img tal:attributes="src laboratory/logo"/>
      </a>
    </div>
    <h1>
      <a tal:attributes="href worksheet/url"
         tal:content="worksheet/id"></a>
    </h1>
  </div>
  <div class="subheader">
    <div>
      <span i18n:translate="">Created on</span>&nbsp;
      <span tal:content="worksheet/date_created"></span>&nbsp;
      <span i18n:translate="">by</span>&nbsp;
      <a tal:attributes="href python:('mailto:%s' % worksheet['createdby']['email'])"
         tal:content="worksheet/createdby/fullname"></a>
    </div>
    <div>
      <span i18n:translate="">Printed on</span>&nbsp;
      <span tal:content="worksheet/date_printed"></span>&nbsp;
      <span i18n:translate="">by</span>&nbsp;
      <a tal:attributes="href python:('mailto:%s' % worksheet['printedby']['email'])"
         tal:content="worksheet/printedby/fullname"></a>
    </div>
    <div>
      <span i18n:translate="">Analysed by</span>:&nbsp;
      <a tal:attributes="href python:('mailto:%s' % worksheet['analyst']['email'])"
         tal:content="worksheet/analyst/fullname"></a>
    </div>
  </div>

  <!-- Repeat the table every 4 ARs -->
  <div class="content" tal:repeat="ars python:view.splitList(ars,view.getNumColumns())">
    <table>
      <thead>
        <tr>
          <th i18n:translate="" class="requestid">Request ID</th>
          <th tal:repeat="ar ars">
            <div class='barcode'
                 data-code='code128'
                 data-showHRI='false'
                 data-barHeight='15'
                 data-addQuietZone='true'
                 tal:attributes="data-id ar/id"></div>
          </th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th i18n:translate="">Client</th>
          <td tal:repeat="ar ars">
            <a tal:attributes="href ar/client/url"
               tal:content="ar/client/name"></a>
          </td>
        </tr>
        <tr>
          <th i18n:translate="">Sample Type</th>
          <td tal:repeat="ar ars">
            <a tal:attributes="href ar/sample/sample_type/url"
               tal:content="ar/sample/sample_type/title"
               tal:condition="ar/sample/sample_type"></a>
          </td>
        </tr>
        <tr>
          <th i18n:translate="">Sample</th>
          <td tal:repeat="ar ars">
            <a tal:attributes="href ar/sample/url"
               tal:content="ar/sample/id"></a>
          </td>
        </tr>
        <tr>
          <th i18n:translate="">Sampling Date</th>
          <td tal:repeat="ar ars"
              tal:content="ar/sample/date_sampled">
          </td>
        </tr>
        <tr>
          <th i18n:translate="">Date received</th>
          <td tal:repeat="ar ars"
              tal:content="ar/date_received">
          </td>
        </tr>
        <tr>
          <th tal:attributes="colspan python:len(ars)+1"
              i18n:translate=""
              class="analyses">Analyses</th>
        </tr>
        <tr tal:repeat="antitle anstitles">
          <th tal:content="antitle"></th>
          <!-- (Partial) Result -->
          <tal:results tal:repeat="ar ars">
            <tal:analysis define="analysis python:view.get_analysis_data_by_title(ar, antitle)">
              <td tal:condition="analysis"
                  tal:attributes="class string:${analysis/review_state} result">
                <tal:result condition="analysis/formatted_result">
                  <span tal:content="string:${analysis/formatted_result}">100</span>
                  <span tal:content="string:${analysis/unit}">ml</span>
                </tal:result>
              </td>
              <td tal:condition="not:analysis" class='no-result'>
                <div>&nbsp;</div>
              </td>
            </tal:analysis>
          </tal:results>
        </tr>
      </tbody>
    </table>
    <div id="footer">
      <div class="" i18n:translate="">
        Legend: Results in <em>italic</em> font are pending, results in <strong>bold</strong> font are verified.
      </div>
    </div>
  </div>
</tal:print>
