<%# The data lab and the grand mapping, as two panels of the Infrasys page (tabs "lab" and "mapping"). Needs: can, apiUrl, route. %>
<% if (can.lab) { %>
<section class="is-panel" id="tab-lab" data-upload="<%= can.labUpload ? 1 : 0 %>" data-download="<%= can.labDownload ? 1 : 0 %>"<%- route === 'tools' ? '' : ' hidden' %>>
  <p class="is-note">Keep every report the POS gives us, not only the three the pipeline converts, so the whole data can be studied. Combine rules and the WebPR format are not touched.</p>
  <% if (can.labUpload) { %>
    <div class="is-lab-drop is-card" id="labDrop" tabindex="0" role="button" aria-label="Choose or drop files">
      <b>Drop any file here</b> or click to choose
      <div class="is-muted is-small">CSV, Excel, JSON, text. Up to 100 files, 60 MB each. Files named SITE_REPORT_yyyymmdd.csv go to the pipeline inbox, everything else is kept in the lab.</div>
      <input type="file" id="labFile" multiple hidden>
    </div>
  <% } else { %>
    <p class="is-note">Your role may browse the lab but not upload files.</p>
  <% } %>
  <div id="labUploadOut"></div>
  <p class="is-note is-small" id="labCatalogSub">Loading the catalog...</p>

  <h2 class="is-h">Reports</h2>
  <div id="labReports"><p class="is-note is-loading">Loading...</p></div>

  <h2 class="is-h">Files</h2>
  <div class="filter-bar is-mon-filters">
    <div class="filter-left">
      <select class="admin-select" id="labReport" aria-label="Report"><option value="">All reports</option></select>
      <select class="admin-select" id="labSource" aria-label="Source">
        <option value="">All sources</option><option value="inbox">SFTP / Mail inbox</option><option value="archive">Extension archive</option><option value="lab">Data lab (other files)</option>
      </select>
      <button type="button" class="btn btn-secondary btn-sm" id="labRefresh">Refresh</button>
    </div>
  </div>
  <div id="labFiles"></div>
  <div id="labProfile"></div>
</section>
<% } %>

<% if (can.mapping) { %>
<section class="is-panel" id="tab-mapping" data-edit="<%= can.mappingEdit ? 1 : 0 %>" data-switch="<%= can.mappingSwitch ? 1 : 0 %>" hidden>
  <p class="is-note">The food sold at Modern Haus (MH) is a Bouchon item, the food sold at The Cocktail Club (TCC) is a Pierre item (for example "African Chicken MH" is a Bouchon item). Give each POS food item its partner item code; the pipeline then swaps the item on those lines. Waiting for the business to confirm: it stays off until switched on, and the money of a day never changes.</p>
  <div class="table-card is-card" id="mapSettings"><p class="is-note is-loading">Loading...</p></div>
  <div id="mapPipe"></div>

  <h2 class="is-h">POS food items</h2>
  <div class="filter-bar is-mon-filters">
    <div class="filter-left">
      <select class="admin-select" id="mapOutlet" aria-label="Outlet"><option value="">All outlets</option></select>
      <select class="admin-select" id="mapState" aria-label="Status">
        <option value="">Any status</option><option value="none">Not mapped</option><option value="draft">Draft</option><option value="confirmed">Confirmed</option>
      </select>
      <button type="button" class="btn btn-secondary btn-sm" id="mapRefresh">Refresh</button>
    </div>
    <% if (can.mappingEdit) { %>
      <div class="is-row is-wrap">
        <button type="button" class="btn btn-secondary btn-sm" id="mapSeed" title="Add every POS food item that has no entry yet, as a draft with an empty partner code">Draft all not mapped</button>
        <button type="button" class="btn btn-secondary btn-sm" id="mapSheetBtn">Upload sheet</button>
        <input type="file" id="mapSheet" accept=".csv,.txt,.xlsx,.xls" multiple hidden>
      </div>
    <% } %>
    <a class="btn btn-secondary btn-sm" href="<%= apiUrl %>?r=mapping_export">Download mapping (CSV)</a>
  </div>
  <p class="is-note is-small">Items are read from the sales files already received (SFTP / Mail bill lines and the extension's Menu Item Sales). Fill in the partner code and name, tick Confirm and Save. A sheet with the columns outlet, posCode, posName, targetCode, targetName, status (confirmed) can be uploaded instead.</p>
  <div id="mapList"><p class="is-note is-loading">Loading...</p></div>
</section>
<% } %>
