<div class="page-renders"
     id="document-previews"
     tal:define="
       is_slow here/@@proto/is_slow;
       force request/force|nothing;
       autoload python: force or not is_slow;
       dummy context/@@http-cache-headers;
       successfully_converted view/successfully_converted;
     "
     i18n:domain="ploneintranet"
>
  <div class="page-renders pat-gallery pat-push"
       data-pat-gallery="item-selector: a.gallery-item"
  >

    <tal:show_previews condition="view/show_previews">

      <tal:not_successfully_converted condition="not:successfully_converted">
        <tal:converting condition="view/converting">
          <div class="message no-preview">
            <p class="title">${context/Title}</p>
            <p class="byline">${view/preview_info}</p>
          </div>
          <p hidden>
            <a class="pat-inject"
               href="${here/absolute_url}/@@previews"
               data-pat-inject="source: #document-previews; target: #document-previews; trigger: autoload; delay: 5s"
            >Load page renders.</a>
          </p>
        </tal:converting>
        <tal:not_converting condition="not:view/converting">
          <a class="message no-preview error"
             href="${context/absolute_url}/download"
          >
            <p class="title">${context/Title}</p>
            <p class="byline">${view/preview_info}</p>
            <p class="download-line"
               i18n:translate=""
            >Download this document.</p>
          </a>
        </tal:not_converting>
      </tal:not_successfully_converted>

      <tal:successfully_converted condition="successfully_converted">

        <a class="message max-preview"
           href="${context/absolute_url}/download"
           tal:define="
                  num_pages view/num_preview_pages;
                  page_limit view/num_preview_limit;
                  "
           tal:condition="python:num_pages and num_pages &gt; page_limit and autoload"
        >
          <strong class="title">${context/id}</strong>
          <p class="byline"
             i18n:translate=""
          >Page views are limited to a maximum of
            <tal:name i18n:name="page_limit">${page_limit}</tal:name>
            pages.
          </p>
          <p class="download-line"
             i18n:translate=""
          >Download the full
            <tal:name i18n:name="num_pages">${page_limit}+</tal:name>
            page document.
          </p>
        </a>

        <p class="message max-preview"
           tal:condition="not:autoload"
        >
          <a class="pat-inject"
             href="${here/absolute_url}/@@previews?force=1"
             data-pat-inject="source: #document-previews; target: #document-previews;"
             i18n:translate=""
          >Load previews &hellip;</a>
        </p>

        <tal:loader repeat="preview view/previews"
                    condition="autoload">
          <figure class="page-compound"
                  id="page-${pagenumber}-page-compound"
                  tal:define="
                    pagenumber repeat/preview/number;
                  "
                  tal:condition="python: pagenumber <=2"
          >
            <a class="gallery-item"
               href="${preview}"
            >
              <img class="page"
                   alt="Page ${pagenumber}"
                   src="${preview}"
                   tal:attributes="style python:view.aspect_ratio_style(pagenumber)"
              />
            </a>
          </figure>
          <figure class="page-compound"
                  id="page-${pagenumber}-page-compound"
                  tal:define="pagenumber repeat/preview/number;"
                  tal:condition="python: pagenumber > 2"
          >
            <a class="pat-inject image-loader"
               href="${context/absolute_url}/@@previews-page-compound-rendered?page=${pagenumber}"
               data-pat-inject="
                   source: #page-${pagenumber}-page-compound-rendered;
                   target: #page-${pagenumber}-page-compound;
                   trigger: autoload-visible;
                      "
               i18n:translate="label_loading_ellipsis"
            >Loading&hellip;</a>
            <a class="gallery-item"
               href="${preview}"
               tal:define="aspect_ratio python:view.aspect_ratio(pagenumber) or 210/297"
               style="aspect-ratio ${aspect_ratio}"
            >
            </a>
          </figure>
        </tal:loader>

      </tal:successfully_converted>


    </tal:show_previews>

    <tal:if condition="python:not view.show_previews and (view.is_audiotype or view.is_videotype)">
      <tal:def define="
                 content_type context/file/contentType|nothing;
                 download_url string:${context/absolute_url}/@@download/file/${context/file/filename};
               ">
        <tal:if condition="view/is_audiotype">
          <audio controls="controls">
            <source src="${download_url}"
                    type="${content_type}"
            />
          </audio>
        </tal:if>

        <tal:if condition="view/is_videotype">
          <video controls="controls"
                 poster="${poster}"
                 preload="${preload}"
                 tal:define="
                   poster_view nocall:here/@@poster.jpg|nothing;
                   has_poster poster_view/image|nothing;
                   poster python: '{}/@@poster.jpg'.format(here.absolute_url()) if has_poster else None;
                   preload python: 'none' if has_poster else 'metadata';
                 "
          >
            <source src="${download_url}"
                    type="${content_type}"
            />
          </video>
        </tal:if>

      </tal:def>
    </tal:if>

  </div>
</div>
