## 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, safemarkdown
   from r2.lib.template_helpers import static, format_number, display_comment_karma, display_link_karma
 %>
<%namespace file="utils.html" import="submit_form, plain_link, thing_timestamp"/>
<%namespace file="printablebuttons.html" import="toggle_button"/>

<div class="titlebox">
  <h1>${thing.user.name}</h1>

  %if c.user_is_loggedin and not thing.viewing_self:
    <div>
    ${toggle_button("fancy-toggle-button", _("+ friends"), _("- friends"),
         "friend('%s', '%s', 'friend')" % (thing.user.name, c.user._fullname),
         "unfriend('%s', '%s', 'friend')" % (thing.user.name, c.user._fullname),
         css_class = "add", alt_css_class = "remove",
         reverse = thing.is_friend, login_required=True)}
    </div>
  %endif

  <span class="karma">${format_number(display_link_karma(thing.user.link_karma))}</span>
  &#32;
  ${_("link karma")}

  <br/>
  <span class="karma comment-karma">${format_number(display_comment_karma(thing.user.comment_karma))}</span>
  &#32;
  ${_("comment karma")}

  %if thing.show_private_info:
    <table id="per-sr-karma"${" class='more-karmas'" if not c.user_is_admin else ""}>
     <thead>
        <tr>
          <th id="sr-karma-header">subreddit</th>
          <th>link</th>
          <th>comment</th>
        </tr>
     </thead>
     <tbody>
     %for i, (sr_name, (link_karma, comment_karma)) in enumerate(thing.all_karmas.iteritems()):
       %if c.user_is_admin and i >= 5:
         <tr class="more-karmas">
       %else:
         <tr>
       %endif

        % if sr_name == "ancient history":
          <th class="helpful" title="${_('really obscure karma from before it was cool to track per-subreddit')}"><span>${_(sr_name)}</span></th>
        % else:
          <th>${sr_name}</th>
        % endif

          <td>${display_link_karma(link_karma)}</td>
          <td>${display_comment_karma(comment_karma)}</td>
        </tr>
     %endfor
     </tbody>
    </table>
    % if not c.user_is_admin or len(thing.all_karmas) > 5:
    <div class="karma-breakdown">
      <a href="javascript:void(0)"
         onclick="$('.more-karmas').show();$(this).hide();return false">
         show karma breakdown by subreddit
      </a>
    </div>
    % endif
  %endif

  %if thing.show_private_info and (thing.user.gold or thing.user.gold_creddits > 0):
    <div class="rounded gold-accent gold-expiration-info">
      %if hasattr(thing, "gold_remaining"):
        <div class="gold-remaining" title="${thing.user.gold_expiration.strftime('%Y-%m-%d')}">
          <span class="karma">
            ${thing.gold_remaining}
          </span>
          <br>
          ${_("of reddit gold remaining")}
          <br>
          <a href="/gold/about">${_("view gold features/benefits")}</a>
        </div>
        %if hasattr(thing, "paypal_subscr_id"):
          <%  
            paypal_link = ("https://www.paypal.com/cgi-bin/webscr?cmd=_subscr-find&alias=%s" % g.goldthanks_email)
           %>
           <div>
            <a href=${paypal_link}>
              ${_("Recurring Paypal subscription")}
            </a>
            &#32;
            ${thing.paypal_subscr_id}
          </div>
        %endif

        %if hasattr(thing, "stripe_customer_id"):
           <div>
            <a href="/gold/subscription">
              ${_("manage recurring subscription")}
            </a>
          </div>
        %endif
      %endif
      %if hasattr(thing, "gold_creddit_message"):
        <div class="gold-creddits-remaining">
          ${plain_link(thing.gold_creddit_message, "/gold?goldtype=gift")}
        </div>
      %endif
    </div>
  %endif

%if hasattr(thing, "goldlink"):
  <div class="giftgold">
    <a href="${thing.goldlink}">
      ${thing.giftmsg}
    </a>
  </div>
%endif

  <div class="bottom">
    %if not thing.viewing_self:
      <img src="${static('mailgray.png')}"/>
      &#32;
      ${plain_link(_("send message"), "/message/compose/?to=%s" % thing.user.name)}
    %endif

    <span class="age">
      ${_("redditor for")}&#32;${thing_timestamp(thing.user)}
    </span>
  </div>

  <div class="clear"> </div>

</div>
