## The contents of this file are subject to the Common Public Attribution
## License Version 1.0. (the "License"); you may not use this file except in
## compliance with the License. You may obtain a copy of the License at
## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
## License Version 1.1, but Sections 14 and 15 have been added to cover use of
## software over a computer network and provide for limited attribution for the
## Original Developer. In addition, Exhibit A has been modified to be
## consistent with Exhibit B.
##
## Software distributed under the License is distributed on an "AS IS" basis,
## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
## the specific language governing rights and limitations under the License.
##
## The Original Code is reddit.
##
## The Original Developer is the Initial Developer.  The Initial Developer of
## the Original Code is reddit Inc.
##
## All portions of the code written by reddit are Copyright (c) 2006-2012
## reddit Inc. All Rights Reserved.
###############################################################################

<%!
    from r2.lib.pages import WrappedUser 
    from r2.lib.filters import edit_comment_filter, safemarkdown
%>
<%namespace file="printable.html" import="arrow, score"/>
<%namespace file="utils.html" import="plain_link" />
<%namespace file="utils.compact" import="icon_button" />
<%namespace file="printablebuttons.html" import="simple_button"/>

<div class="thing message id-${thing._fullname} ${'unread' if thing.new else ''}">
  <p class="subject">
    %if getattr(thing, "is_parent", False):
       %if thing.sr_id:
         <span class="correspondent reddit rounded">
           <a href="${thing.subreddit.path}message/moderator/inbox.compact">
             /r/${thing.subreddit.name}
           </a>
         </span>
       %else:
         <span class="correspondent rounded">
           <%
              corr = thing.author if thing.recipient else thing.to
            %>
           ${WrappedUser(corr)}
         </span>
       %endif
    %endif
    ${thing.subject}
  %if thing.was_comment:
   <a href="${thing.link_permalink}.compact" class="title">${thing.link_title}</a>
  %endif
 </p>

  <div class="entry">
  <%
   author = WrappedUser(thing.author, thing.attribs, thing).render()
   if thing.sr_id:
     subreddit = '&nbsp;<a href="%s.compact">%s</a>&nbsp;' % \
                   (thing.subreddit.path, thing.subreddit.path)
     if not thing.dest:
       thing.dest = subreddit
     author = thing.updated_author % dict(author=author, subreddit=subreddit)
   
   taglinetext = thing.taglinetext.replace(' ', '&nbsp;')
   taglinetext = taglinetext % dict(when=thing.timesince,
                                    author=u"<b>%s</b>" % author,
                                    dest=u"<b>%s</b>" % thing.dest)
  %>
    <div class="tagline">
      ${unsafe(taglinetext)}
    </div>
    <a href="javascript:void(0)" class="options_link"></a>
    ${unsafe(safemarkdown(thing.body))}
    <div class="clear options_expando hidden">
        <%
            is_author = (c.user_is_loggedin and thing.author and c.user._fullname == thing.author._fullname)
        %>
        %if c.user_is_loggedin:
            ${icon_button("Reply", "reply-icon", outer_class="reply-button", onclick="return reply(this)")}
        %endif
        ${icon_button("Permalink", "permalink-icon", thing.permalink + ".compact")}
        %if thing.was_comment:
            ${icon_button("Context", "context-icon", thing.permalink + ".compact?context=3")}
        %endif
        ${icon_button("Unread", "unread-icon", onclick="change_state(this, 'unread_message', unread_thing, true)" )}
       </div>
  </div>
  <div style="clear: both;"></div>
  <div class="child">
    ${thing.childlisting}
  </div>
</div>


