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

<head>
</head>

<body>

    <metal:main fill-slot="main"
                tal:define="obj python: view.getVersion(request.form.get('version', 'current'));
                            modified obj/ModificationDate;
                            version_id python: request.form.get('version', '1');
                            utils context/@@castle-utils">
      <h1 class="documentFirstHeading">History View</h1>

      <div class="history-info-container">
        <form>
          <div class="form-group">
            <label>Select version</label>
            <select name="version" class="form-control version-selector">
              <tal:version tal:repeat="version view/versions">
                <option value="${version/version_id}"
                        tal:attributes="selected python: str(version_id) == str(version['version_id']) and 'true'">
                  <span tal:replace="python: here.toLocalizedTime(version['dt'],long_format=True)" />
                  <span tal:condition="version/comments" tal:omit-tag="">- ${version/comments}</span>
                </option>
              </tal:version>
            </select>
          </div>
        </form>


        <h4>Showing edit from
          <span tal:content="modified"
                class="pat-moment" data-pat-moment="format:relative;"/></h4>
        <p tal:condition="view/version_info/comments|nothing">
          <strong>Comments</strong>: ${view/version_info/comments|nothing}</p>

        <form method="post" action="${context/absolute_url}/revertversion">
          <input type="hidden" name="version_id" value=""
                 tal:attributes="value version_id" />
          <input type="submit" class="plone-btn plone-btn-danger"
                 value="Revert to this version" />
        </form>

      </div>
      <hr />
      <div class="history-content-wrapping">
        <div tal:replace="structure python: view.getContent(obj)" />

        <hr />
        <h3>Lead image</h3>
        <div class="history-lead-image"
             tal:define="referenced python: view.get_referenced_image(obj)">
          <div class="history-has-lead-image" tal:condition="python: obj.image is not None">
            <p class="discreet">
              This version has a lead image assigned to it.
            </p>
            <img src="${obj/absolute_url}/@@images/image/mini" />
            <p tal:condition="python: referenced is None">
              Filename: ${python: obj.image.filename}
            </p>
            <p tal:condition="python: referenced is not None">
              Referenced image:
              <a href="${python: referenced.absolute_url()}/view">
                ${python: utils.get_path(referenced)}
              </a>
            </p>
          </div>
          <div class="history-no-lead-image" tal:condition="python: obj.image is None">
            <p class="discreet">
              No lead image assigned to this version.
            </p>
          </div>
        </div>
      </div>

    </metal:main>

</body>
</html>
