<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">

  <metal:view_macro define-macro="view">
    <span metal:define-macro="textarea-field-view"
          tal:define="uid context/UID|nothing;
                      portal_state context/@@plone_portal_state;
                      portal portal_state/portal;
                      history accessor"
          tal:condition="history"
          tal:attributes="id string:parent-fieldname-$fieldName-$uid"
          class="remarks_history">
      <tal:static define="static_path string:${portal/absolute_url}/bika_widgets">
        <link rel="stylesheet" type="text/css" media="all" href=""
              tal:attributes="href string:${static_path}/remarkswidget.css"/>
      </tal:static>
      <div class="remarks_history">
        <tal:record repeat="record history">
          <div class="record" tal:attributes="id record/id;">
            <div class="record-header" tal:condition="record/user_id">
              <span class="record-user" tal:content="record/user_id"/>
              <span class="record-username" tal:content="record/user_name"/>
              <span class="record-date" tal:content="record/created_ulocalized"/>
            </div>
            <div class="record-content"
                tal:content="structure record/html_content"></div>
          </div>
        </tal:record>
      </div>
    </span>
  </metal:view_macro>

  <metal:remarks_edit define-macro="remarks_edit">
    <tal:static define="static_path string:${portal/absolute_url}/bika_widgets">
      <script type="text/javascript"
              tal:attributes="src string:${static_path}/remarkswidget.js"></script>
      <link rel="stylesheet" type="text/css" media="all" href=""
            tal:attributes="href string:${static_path}/remarkswidget.css"/>
    </tal:static>
    <textarea class="form-control" tal:attributes="name fieldName; id fieldName;"></textarea>
    <div tal:condition="python: 'portal_factory' not in context.absolute_url()">
      <input class="saveRemarks allowMultiSubmit btn btn-primary btn-sm input-sm"
             type="submit"
             value="Add remarks"
             disabled="disabled"
             i18n:attributes="value"
             i18n:domain="senaite.core"/>
    </div>
  </metal:remarks_edit>

  <metal:remarks_history define-macro="remarks_history">
    <div class="remarks_history">
      <tal:record repeat="record python:field.get_history(context)">
        <div class="record" tal:attributes="id record/id;">
          <div class="record-header" tal:condition="record/user_id">
            <span class="record-user" tal:content="record/user_id"/>
            <span class="record-username" tal:content="record/user_name"/>
            <span class="record-date" tal:content="record/created_ulocalized"/>
          </div>
          <div class="record-content"
               tal:content="structure record/html_content"></div>
        </div>
      </tal:record>
    </div>
  </metal:remarks_history>

  <metal:edit define-macro="edit">
    <metal:use use-macro="field_macro | context/widgets/field/macros/edit">
      <metal:fill fill-slot="widget_body">
        <metal:block use-macro="context/bika_widgets/remarkswidget/macros/remarks_history"/>
        <metal:block use-macro="context/bika_widgets/remarkswidget/macros/remarks_edit"/>
      </metal:fill>
    </metal:use>
  </metal:edit>

  <metal:search define-macro="search">
    <metal:use use-macro="context/widgets/field/macros/edit">
      <metal:fill fill-slot="widget_body">
        <metal:block use-macro="context/widgets/remarkswidget/macros/remarks_edit"/>
      </metal:fill>
    </metal:use>
  </metal:search>

</html>
