<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"
  i18n:domain="senaite.core">

  <head tal:define="portal context/@@plone_portal_state/portal;">
      <script type="text/javascript"
          tal:attributes="src python:portal.absolute_url() + '/bika_widgets/datetimewidget.js'"></script>
      <script type="text/javascript"
          tal:attributes="src python:portal.absolute_url() + '/bika_widgets/referencewidget.js'"></script>
      <script type="text/javascript"
          tal:attributes="src python:portal.absolute_url() + '/bika_widgets/rejectionwidget.js'"></script>
  </head>

  <body
    tal:define="portal context/@@plone_portal_state/portal;
                checkPermission python:context.portal_membership.checkPermission;
                dummy python:view.sublists();
                prominent python:dummy[0];
                sublists python:dummy[1];
                errors view/errors"
    tal:condition="sublists">
    <form method="post" name="header_form">
      <input type="hidden" name="header_table_submitted" value="1" />

      <table class="header_table table table-condensed table-bordered table-sm">

        <tr tal:repeat="action prominent">
          <tal:def define="mode python:action['mode'];
                           fieldName python:action['fieldName'];
                           field python:context.Schema()[fieldName];
                           field_macro here/widgets/field/macros/edit;
                           widget python:field.widget;
                           accessor python:field.getAccessor(context);
                           errors python:{};">
            <td class="active">
              <span tal:replace="python:widget.label"/>
              <span class="fieldRequired"
                    tal:condition="python:field.required and mode == 'edit'"
                    title="Required"
                    i18n:attributes="title title_required;"> </span>
            </td>
            <td colspan="5">
              <tal:x condition="python:mode!='structure'">
                <metal:field use-macro="python:context.widget(fieldName, mode=mode)"/>
              </tal:x>
              <span
                tal:condition="python:mode=='structure' and action['html']"
                tal:content="structure action/html"/>
            </td>
          </tal:def>
        </tr>

        <tr tal:repeat="row_nr python:range(len(sublists[0]))">
          <tal:repeat repeat="col_nr python:range(3)">
            <tal:print_blanks condition="python:len(sublists[col_nr]) <= row_nr">
              <td tal:attributes="class python:row_nr%2 and 'key odd' or 'key even'"></td>
              <td tal:attributes="class python:row_nr%2 and 'value odd' or 'value even'"></td>
            </tal:print_blanks>
            <tal:skip_blanks condition="python:len(sublists[col_nr]) > row_nr">
              <tal:def define="action python:sublists[col_nr][row_nr];
                               mode python:action['mode'];
                               fieldName python:action['fieldName'];
                               field python:context.Schema()[fieldName];
                               field_macro here/widgets/field/macros/edit;
                               widget python:field.widget;
                               accessor python:field.getAccessor(context);
                               errors python:{};">
                <td tal:attributes="class python:row_nr%2 and 'key odd active' or 'key even active'">
                  <span tal:replace="python:widget.label"/>
                  <span class="fieldRequired"
                        tal:condition="python:field.required and mode == 'edit'"
                        title="Required"
                        i18n:attributes="title title_required;"> </span>
                </td>
                <td tal:attributes="class python:row_nr%2 and 'value odd' or 'value even'">
                  <tal:x condition="python:mode!='structure'">
                    <metal:field
                      use-macro="python:context.widget(fieldName, mode=mode)"/>
                  </tal:x>
                  <span
                    tal:condition="python:mode=='structure' and action['html']"
                    tal:content="structure action/html"/>
                </td>
              </tal:def>
            </tal:skip_blanks>
          </tal:repeat>
        </tr>
      </table>
      <input class="context btn btn-sm btn-primary"
             type="submit"
             name="form.button.save"
             value="Save"
             i18n:domain="plone"
             i18n:attributes="value label_save;"
             />
    </form>
  </body>
</html>
