<%! from django.utils.translation import ugettext as _ %>
<%! from django.core.urlresolvers import reverse %>

<%
def url_for_thread(discussion_id, thread_id):
  return reverse('django_comment_client.forum.views.single_thread', args=[course.id, discussion_id, thread_id])
%>

<%
def url_for_comment(discussion_id, thread_id, comment_id):
  return url_for_thread(discussion_id, thread_id) + "#" + comment_id
%>

<%
def url_for_discussion(discussion_id):
  return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course.id, discussion_id])
%>

<%
def discussion_title(discussion_id):
  return get_discussion_title(discussion_id=discussion_id)
%>

<%
def url_for_user(user_id): #TODO
  return "javascript:void(0)"
%>


<div class="notifications">
  % for notification in notifications:
    ${render_notification(notification)}
  % endfor
</div>

<%def name="render_user_link(notification)">
  <% info = notification['info'] %>
  % if notification.get('actor_id', None):
    <a href="${url_for_user(notification['actor_id'])}">${info['actor_username']}</a>
  % else:
    ${_("Anonymous")}
  % endif
</%def>

<%def name="render_thread_link(notification)">
  <% info = notification['info'] %>
  <a href="${url_for_thread(info['commentable_id'], info['thread_id'])}">${info['thread_title']}</a>
</%def>

<%def name="render_comment_link(notification)">
  <% info = notification['info'] %>
  <a href="${url_for_comment(info['commentable_id'], info['thread_id'], info['comment_id'])}">${_("comment")}</a>
</%def>

<%def name="render_discussion_link(notification)">
  <% info = notification['info'] %>
  <a href="${url_for_discussion(info['commentable_id'])}">${discussion_title(info['commentable_id'])}</a>
</%def>

<%def name="render_notification(notification)">
  <div class="notification">
    % if notification['notification_type'] == 'post_reply':
    ${_("{user} posted a {comment} to the thread {thread} in discussion {discussion}").format(
      user=render_user_link(notification),
      comment=render_comment_link(notification),
      thread=render_thread_link(notification),
      discussion=render_discussion_link(notification),
    )}
    % elif notification['notification_type'] == 'post_topic':
    ${_("{user} posted a new thread {thread} in discussion {discussion}").format(
      user=render_user_link(notification),
      thread=render_thread_link(notification),
      discussion=render_discussion_link(notification),
    )}
    % elif notification['notification_type'] == 'at_user':
      % if notification['info']['content_type'] == 'thread':
        ${_("{user} mentioned you in the thread {thread} in disucssion {discussion}").format(
          user=render_user(info),
          thread=render_thread_link(notification),
          discussion=render_discussion_link(notification),
        )}
      % else:
        ${_("{user} mentioned you in {comment} to the thread {thread} in discussion {discussion}").format(
          user=render_user(info),
          comment=render_comment_link(notification),
          thread=render_thread_link(notification),
          discussion=render_discussion_link(notification),
        )}
      % endif
    % endif
  </div>

</%def>
