<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      >
<body>

  <tal:comment condition="nothing">
    <!-- ploneintranet.prototype/_includes/post.html -->
  </tal:comment>
<div class="tile">
  <div i18n:domain="ploneintranet"
       tal:define="
         thread_id context/getId;
         portal_url view/portal_url;
         is_slow here/@@proto/is_slow;
       "
       class="post item"
       tal:attributes="id python: thread_id and ('post-%s' % thread_id) or None">
    <div class="post-header">
      <a href="${portal_url}/author/${here/userid}">
          <img tal:replace="structure view/avatar">
          <h4 class="name">${view/fullname}</h4>
      </a>
      <p class="byline">
        <em class="action" i18n:translate=""
            tal:content="context/action_verb">posted</em>
        <time class="pat-display-time"
              data-pat-display-time="from-now: true; locale: ${view/portal/plone_portal_state/language}"
              datetime="${context/date/ISO}"
            >${context/date/ISO}</time>
        <tal:location condition="context/microblog_context/Title|nothing" define="token context/@@authenticator/token">
          in <a href="${context/microblog_context/absolute_url}?_authenticator=${token}">${context/microblog_context/Title}</a>
        </tal:location>

        <tal:comment condition="nothing">
        <!-- XXX: This is not yet implemented -->
        <!--label class="visibility pat-select bare">
        |
          <select>
            <optgroup>
              <option>
                Everyone
              </option>
              <option>
                Trusted users
              </option>
            </optgroup>
            <optgroup>
              <option>
                Workspace so and so
              </option>
              <option>
                Baggage handling regulations
              </option>
              <option>
                Human resources
              </option>
            </optgroup>
          </select>
         </label-->
        </tal:comment>
        <br/>
        <a tal:condition="view/actions"
           href="${view/traverse}/post-menu.html#content"
           class="iconified icon-cog pat-tooltip"
           data-pat-tooltip="source: ajax">Options</a>
      </p>
    </div>

    <section class="post-content">
      <p>
        <span tal:replace="structure view/decorated_text">Comment text</span>
        <a tal:condition="context/original_text"
           class="edited-toggle"
           id="edited-toggle-${context/id}">
          (<span tal:omit-tag="" i18n:translate="">Edited</span>
          <time class="pat-display-time"
                data-pat-display-time="from-now: true; locale: ${view/portal/plone_portal_state/language}"
                datetime="${context/edited/ISO}"
                >${context/edited/ISO}</time>
          )</a>
      </p>

      <section tal:condition="context/original_text"
               class="original-text pat-collapsible closed"
               data-pat-collapsible="trigger: #edited-toggle-${context/id}">
        <p>
          <strong i18n:translate="">Original text:</strong>
          ${context/original_text}
        </p>
      </section>

    </section>


    <tal:comment condition="nothing">
    prototype distinguishes:
    - content shares (link, download, view) versus status attachments (download)
    - files (with title, description) versus images (fullwidth)
    - has preview  versus no preview versus preview in progress

    Please study prototype/./_includes/post.html when making changes here.

    NB the prototype assumes that multiple attachments are either all images
    or else are all files. Implementation will need to split that into
    a multi-file + multi-image renderer.

    Structure
    ---------

    Explanation see https://github.com/quaive/ploneintranet/issues/1

    The below is broken into 2x2 blocks wrapped in conditionals:

    1. streamonly       = post with attachment, without reference to content object
     a. stream_document = file attachment
     b. stream_image    = image attachment

    2. content          = post with content object reference
     a. content_default = reference to file or document, anything but an image
     b. content_image   = reference to an image

    The prototype does not have a distinction between 1. and 2. that way,
    but we need it for the implementation since the API is very different,
    and the markup is subtly different on top of that.

    TODO:
    - "converting" state not yet supported in markup
      relates to https://github.com/quaive/ploneintranet/issues/44
    - multi-attachments and multi-page previews
    - zip downloads

    </tal:comment>

    <tal:streamonly condition="not:view/is_content_update">

    <tal:attachments repeat="attachment view/attachments">
      <tal:def define="is_image attachment/is_image;
                       has_preview attachment/img_src|nothing">

        <tal:comment condition="nothing">
  ----------------------------------------------------------------
      1.a. STREAM DOCUMENT
  ----------------------------------------------------------------
        </tal:comment>

        <tal:stream_document condition="not:is_image">
          <section class="document document document-preview ${python: 'not-possible' if (is_slow or not has_preview) else ''}">
            <figure>
              <a href="${attachment/link}"
                 title="Download this file"
                 i18n:attributes="title"
              >
                <img alt="${attachment/title}"
                     title="${attachment/title}"
                     src="${attachment/img_src}"
                     tal:condition="python:not is_slow and has_preview"
                />
              </a>
              <figcaption>
                <strong class="title">
                  <a href="#"
                     i18n:attributes="title"
                     title="Download this file"
                     tal:attributes="href attachment/link">
                    <tal:r replace="attachment/title">Projection Material</tal:r>
                  </a>
                  <tal:comment condition="nothing">
                  <!-- This needs exposure of all generated thumbs. We can do that and have them accessible, it is just not added here yet. -->
                  <!--span class="page-counter icon-docs">3x</span-->
                  </tal:comment>
                  <span class="functions">
                    <a href="#" class="icon iconified icon-download" i18n:attributes="title" title="Download this file" tal:attributes="href attachment/link">Download</a>
                    <tal:comment condition="nothing">
                    <!-- XXX gallery not implemented yet -- >
                    </tal:comment>

                    </span>
                </strong>
                <tal:comment condition="nothing">
                  <!-- no description byline for status attachments -->
                </tal:comment>

              </figcaption>
            </figure>
          </section>
        </tal:stream_document>

        <tal:comment condition="nothing">
  ----------------------------------------------------------------
      1.b. STREAM IMAGE
  ----------------------------------------------------------------
        </tal:comment>

        <tal:stream_image condition="is_image">
  	<section class="image document-preview"
                   tal:condition="has_preview">
  	  <figure >
              <a href="${attachment/img_src}">
                <img src="${attachment/img_src}/large"
                     alt=""
                     tal:condition="not:is_slow"
                     />
                <tal:title condition="is_slow">${attachment/title}</tal:title>
              </a>
  	  </figure>
  	  <p class="${python: not is_slow and 'overlay' or None}">
              <tal:comment condition="nothing">
              <!-- XXX images gallery view not implemented yet -->
              <!-- XXX images zip download not implemented yet -->
              </tal:comment>
              <a href="${attachment/img_src}"
                 class="icon iconified icon-download"
                 i18n:attributes="title"
                 title="Download this image">Download</a>
  	  </p>
  	</section>
        </tal:stream_image>


      </tal:def>
    </tal:attachments>
    </tal:streamonly>

    <tal:content condition="view/is_content_update">

      <tal:comment condition="nothing">
  ----------------------------------------------------------------
      2.a. CONTENT DEFAULT
  ----------------------------------------------------------------
      </tal:comment>

      <tal:content_default condition="not:view/is_content_image_update">
      <section class="${view/content_preview_status_css} ${python:is_slow and 'not-possible'}"
               tal:define="content_context nocall:context/content_context;"
      >
        <figure>
          <a tal:condition="view/content_has_previews"
             tal:define="preview_src python:view.content_preview_urls()[0]"
             tal:attributes="href view/content_url;
                             alt content_context/Title">
            <img src="${preview_src}"
                 tal:condition="python:not is_slow"
                 alt=""
            />
  	      </a>
          <a tal:condition="view/content_has_leadimage"
             tal:attributes="href view/content_url;
                             alt content_context/Title">
          <img alt=""
               src="${content_context/absolute_url}/@@images/image/preview"
               tal:condition="python:not is_slow and content_context.image"
          />
  	</a>
  	<figcaption>
  	  <strong class="title">
  	    <a href="${view/content_url}" alt="${content_context/Title}"><span tal:replace="content_context/Title">title</span>
                <!-- This needs exposure of all generated thumbs. We can do that and have them accessible, it is just not added here yet. -->
                <!--span class="page-counter icon-docs">3x</span-->
  	    </a>
  	    <span class="functions">
  	      <a tal:condition="view/is_content_downloadable"
                   href="${content_context/absolute_url}"
                   class="icon iconified icon-download"
                   i18n:attributes="title"
                   title="Download this file">Download</a>
                <tal:comment condition="nothing">
                <!-- XXX images gallery view not implemented yet -->
                <!-- instead, for now a single view link -->
                </tal:comment>
                <a href="${view/content_url}"
                   class="icon iconified icon-eye"
                   i18n:attributes="title"
                   title="View">View</a>

  	    </span>
  	  </strong>
  	  <a href="${view/content_url}" alt="${content_context/Title}">
  	    <em class="byline" tal:content="content_context/Description">Description goes here</em>
  	  </a>
  	</figcaption>
        </figure>
        <tal:comment condition="nothing">
        <!-- 			<p class="overlay">
  				<a href="#" class="iconified icon-download">Download</a>
  				<a href="#" class="iconified icon-preview">Preview</a>
        </p> -->
        </tal:comment>
      </section>
      </tal:content_default>

      <tal:comment condition="nothing">
  ----------------------------------------------------------------
     2.b. CONTENT IMAGE
  ----------------------------------------------------------------
      </tal:comment>

      <tal:content_image condition="view/is_content_image_update">
        <section class="image document-preview"
                 tal:define="content_context nocall:context/content_context;">
  	<figure>
            <a href="${view/content_url}"
               alt="${content_context/Title}"
            >
              <img src="${content_context/absolute_url}/@@images/image/large"
                   alt="${content_context/Title}"
                   tal:condition="not:is_slow"
              />
              <tal:title condition="is_slow">${content_context/Title}</tal:title>
            </a>
  	</figure>
  	<p class="${python: not is_slow and 'overlay' or None}">
            <tal:comment condition="nothing">
            <!-- XXX images gallery view not implemented yet -->
            <!-- XXX images zip download not implemented yet -->
            </tal:comment>
            <a href="${view/content_url}"
               i18n:attributes="title"
               title="View this image">
  	    <span class="icon iconified icon-eye">View</span>
  	  </a>
            <a href="${content_context/absolute_url}"
               i18n:attributes="title"
               title="Download this image">
  	    <span class="icon iconified icon-download">Download</span>
  	  </a>
  	</p>
        </section>
        </tal:content_image>

    </tal:content>


    <div class="functions">
      <tal:comment condition="nothing">
      <!-- XXX: This is not yet implemented -->
      <!--a href="#" class="share pat-modal">Share <sup class="counter">(8)</sup></a-->
      </tal:comment>
      <form tal:replace="structure view/toggle_like" />
    </div>

    <tal:comment condition="nothing">
  ----------------------------------------------------------------
     *** comments ***
  ----------------------------------------------------------------
    </tal:comment>

    <div class="comments"
         id="${string:comments-${thread_id}}">
      <div id="comment-trail-${thread_id}"
           tal:define="
             replies view/replies;
             comment_views view/comment_views;
           "
      >
        <p class="older-comments"
           id="older-comments"
           tal:condition="view/has_older_replies"
        >
          <tal:old_replies_link tal:define="
            total_replies python: len(replies);
            older_replies python: total_replies  - view.fresh_reply_limit;
            plural python:older_replies > 1;
          ">
            <a href="${portal_url}/@@activitystream.tile?post_id=${thread_id}&amp;all_comments=1#comment-trail-${thread_id}"
               class="pat-inject"
               data-pat-inject="source: #comment-trail-${thread_id}::element; target: #comment-trail-${thread_id}::element"
               i18n:translate=""
            >
              <tal:singular condition="not:plural"
                            i18n:translate=""
              >Show <tal:n i18n:name="count">${older_replies}</tal:n> older comment</tal:singular>
              <tal:plural condition="plural"
                          i18n:translate=""
              >Show <tal:n i18n:name="count">${older_replies}</tal:n> older comments</tal:plural>
            </a>
            <span class="counter">${view/fresh_reply_limit} of ${total_replies}</span>
          </tal:old_replies_link>
        </p>
        <tal:loop
            tal:repeat="comment python:comment_views"
            tal:content="structure comment"
        />
      </div>
      <tal:commentable condition="view/commentable">
        <div id="${string:new-comment-${thread_id}}"></div>
        <div tal:replace="structure context/@@update-social.html" />
      </tal:commentable>
    </div>

  </div>
</div>
</body>
</html>
