<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      metal:use-macro="here/main_template/macros/master"
      i18n:domain="senaite.core">

  <body tal:define="form_id view/form_id;
                    table_only python:hasattr(view, 'table_only') and view.table_only or view.request.get('table_only','') == form_id;"
        tal:omit-tag="python:table_only">

    <metal:content-title fill-slot="content-title"
                         tal:define="form_id view/form_id;
                                     table_only python:hasattr(view, 'table_only') and view.table_only or view.request.get('table_only','') == form_id;"
                         tal:condition="python:not table_only">
      <h1>
        <img tal:condition="view/icon|nothing" tal:attributes="src view/icon"/>
        <span class="documentFirstHeading" tal:content="view/title"/>
      </h1>
    </metal:content-title>

    <metal:content-description fill-slot="content-description"
                               tal:define="form_id view/form_id;
                                          table_only python:hasattr(view, 'table_only') and view.table_only or view.request.get('table_only','') == form_id;"
                               tal:condition="python:not table_only">
      <div class="documentDescription"
           tal:content="view/description"
           tal:condition="view/description"/>
    </metal:content-description>

    <metal:content-core fill-slot="content-core"
                        tal:define="form_id view/form_id;
                                   table_only python:hasattr(view, 'table_only') and view.table_only or view.request.get('table_only','') == form_id;">

      <tal:searchform condition="python:not table_only">

        <!-- Template -->
        <table>
          <tr>
            <td>
              <form id="applytemplate_form" method="POST">
                <input type="hidden" name="submitted" value="1"/>
                <input tal:replace="structure context/@@authenticator/authenticator"/>
                <label for="getWorksheetTemplate" i18n:translate="">Select template</label>
                <select id="ProfileSelector" name="getWorksheetTemplate"
                        tal:define="ws_templates_list view/getWorksheetTemplates">
                  <option value=""></option>
                  <tal:profile repeat="profile ws_templates_list">
                    <option tal:attributes="value python:profile;
                                            selected python: view.request.get('WorksheetTemplate', '') == profile[0] and 'selected' or ''"
                            tal:content="python:ws_templates_list.getValue(profile)"/>
                  </tal:profile>
                </select>
                <input type="submit"
                       class="applytemplate"
                       value="Apply template"
                       i18n:attributes="value"/>
              </form>
            </td>
          </tr>
        </table>

        <!-- Searchform -->
        <form class="criteria form-inline" name="criteria">
          <h3 i18n:translate="">Filter Analyses</h3>

          <div class="form-group">
            <label tal:attributes="for string:${form_id}_FilterByCategory"
                   i18n:translate="">Category</label>
            <select id="CategorySelector"
                    tal:attributes="name string:${form_id}_FilterByCategory"
                    tal:define="categories_list view/getCategories"
                    class="listing-filter">
              <option value="any" i18n:translate="">Any</option>
              <tal:options repeat="category categories_list">
                <option
                  tal:attributes="value python:category;
                                  selected python: view.request.form.get(form_id+'_getCategoryTitle', '') == category and 'selected' or ''"
                  tal:content="python:categories_list.getValue(category)"/>
              </tal:options>
            </select>
          </div>

          <div class="form-group">
            <label tal:attributes="for string:${form_id}_FilterByService"
                   i18n:translate="">Service</label>
            <select id="ServiceSelector"
                    tal:attributes="name string:${form_id}_FilterByService"
                    tal:define="services_list view/getServices"
                    class="listing-filter">
              <option value="any" i18n:translate="">Any</option>
              <tal:options repeat="service services_list">
                <option
                  tal:attributes="value python:service;
                                  selected python: view.request.form.get(form_id+'_Title', '') == service and 'selected' or ''"
                  tal:content="python:services_list.getValue(service)"/>
              </tal:options>
            </select>
          </div>

          <div class="form-group">
            <label tal:attributes="for string:${form_id}_FilterByClient"
                   i18n:translate="">Client</label>
            <select id="ClientSelector"
                    tal:attributes="name string:${form_id}_FilterByClient"
                    tal:define="clients_list view/getClients"
                    class="listing-filter">
              <option value="any" i18n:translate="">Any</option>
              <tal:options repeat="client clients_list">
                <option
                  tal:attributes="value python:client;
                                  selected python: view.request.form.get(form_id+'_getClientTitle', '') == client and 'selected' or ''"
                  tal:content="python:clients_list.getValue(client)"/>
              </tal:options>
            </select>
          </div>

          <!-- Search Button -->
          <a tal:attributes="href view/view_url"
             class="btn btn-default ws-analyses-search-button"
             i18n:translate="">Search</a>

        </form>
      </tal:searchform>

      <!-- Listing Table -->
      <div id="folderlisting-main-table"
           tal:content="structure view/contents_table"/>

    </metal:content-core>
  </body>
</html>
