## 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-2015
## reddit Inc. All Rights Reserved.
###############################################################################

<%!
   from r2.lib.filters import unsafe
   from r2.lib.pages.things import CommentButtons
   from r2.lib.pages import WrappedUser
%>

<%namespace file="utils.html" import="plain_link, thing_timestamp, edited" />
<%inherit file="comment_skeleton.html"/>

#####################
### specific fill-in functions for comment
##################

<%def name="midcol(display=True, cls = '')">
${parent.midcol(cls = cls)}
</%def>

<%def name="ParentDiv()">
  ${parent.ParentDiv()}
  %if not thing.deleted:
    <a name="${thing._id36}"></a>
  %endif
  %if c.profilepage:
    %if thing.link: 
      %if thing.link.title:
        <a href="${thing.link.url}" class="title"
           %if thing.nofollow:
             rel="nofollow"
           %endif
           >
          ${thing.link.title}
        </a>
      %else:
          ${thing.link.url}
      %endif
    %endif
    &#32;
    ${_("by")}
    &#32;
    ${thing.link_author}
    ${_("in")}
    &#32;
    ${plain_link(thing.subreddit.name, thing.subreddit_path, sr_path = False,
                 cname = False, _class = "subreddit hover")}
  %endif
</%def>

<%def name="tagline()">
  <%
     if c.user_is_admin:
       show = True
     else:
       show = not thing.deleted
  %>

  <a href="javascript:void(0)" class="expand" onclick="return togglecomment(this)">
    ${"[%s]" % ("+" if thing.collapsed else "–")}
  </a>

  %if show:
     %if thing.deleted:
       <em>${_("deleted comment from")}</em>&#32;
     %endif
     ${WrappedUser(thing.author, thing.attribs, thing)}
     &#32;
  %else:
     <em>${_("[deleted]")}</em>&#32;
  %endif

  %if thing.collapsed and show:
    <span class="collapsed-reason">${thing.collapsed_reason}</span>
  %endif

  %if show and thing.score_hidden:
    <span title="${_('this subreddit hides comment scores for %d minutes') % thing.subreddit.comment_score_hide_mins}">
      [${_("score hidden")}]
    </span>&#32;
  %elif show and not thing.score_hidden:
    ${unsafe(self.score(thing, likes = thing.likes))}&#32;
  %endif

  ${thing_timestamp(thing, thing.timesince, live=True, include_tense=True)}
  ${edited(thing, thing.lastedited)}
  ${self.gildings()}

  &nbsp;
  <a href="javascript:void(0)" class="numchildren" onclick="return togglecomment(this)">
    (${thing.numchildren_text})
  </a>

  ${self.approval_checkmark()}
  %if getattr(thing, 'savedcategory', None) is not None:
    ${plain_link(_('category: %s') % thing.savedcategory,
                 '/user/%s/saved/%s' % (c.user.name, thing.savedcategory),
                 _class='save-category' + ('' if thing.savedcategory else ' hidden')
                )}
  %endif
</%def>

<%def name="Child()">
%if not c.profilepage and thing.link.contest_mode and hasattr(thing, "child") and not thing.parent_id:
  <a href="#" class="showreplies"
     onclick="$(this).hide();$(this).parent().find('.noncollapsed').show();return false;">
    [${_("show replies")}]
  </a>
  <div class="child noncollapsed" style="display:none">
%else:
  <div class="child">
%endif
  %if thing.childlisting:
    ${thing.childlisting}
  %endif
  </div>
</%def>

<%def name="commentBody()">
  ${parent.commentBody()}
</%def>

<%def name="arrows()">
  ${parent.midcol()}
</%def>

<%def name="buttons()">
  ${CommentButtons(thing)}
  ${self.admintagline()}
</%def>
