{% extends "cranefly/layout.html" %}
{% import "cranefly/macros.html" as macros with context %}

{% block title %}{% if user.alerts -%}
{{ macros.page_title(title=get_title(),parent=_('Your Notifications')) }}
{%- else -%}
{{ macros.page_title(title=get_title()) }}
{%- endif %}{% endblock %}

{% block container %}
<div class="page-header header-primary">
  <div class="container">
    {{ messages_list(messages) }}
    <h1>{% if user.alerts %}{{ get_title() }} <small>{% trans %}Your Notifications{% endtrans %}</small>
      {%- else -%}
      {% trans %}Your Notifications{% endtrans %}{% endif %}</h1>
  </div>
</div>

<div class="container container-primary">
  {% if alerts %}
  <div class="user-alerts">
    {% if alerts.today %}{{ alerts_list(lang_today(), alerts.today) }}{% endif %}
    {% if alerts.yesterday %}{{ alerts_list(lang_yesterday(), alerts.yesterday) }}{% endif %}
    {% if alerts.week %}{{ alerts_list(lang_week(), alerts.week) }}{% endif %}
    {% if alerts.month %}{{ alerts_list(lang_month(), alerts.month) }}{% endif %}
    {% if alerts.older %}{{ alerts_list(lang_older(), alerts.older) }}{% endif %}
  </div>
  {% else %}
  <p class="lead">{% trans %}Looks like you don't have any notifications... yet.{% endtrans %}</p>
  {% endif %}
</div>
{% endblock %}

{% macro get_title() -%}
{% if new_alerts -%}
{% trans alerts=new_alerts -%}
You have one new alert
{%- pluralize -%}
You have {{ alerts }} new alerts
{%- endtrans %}
{%- else -%}
{% trans %}Your Notifications{% endtrans %}
{%- endif %}
{%- endmacro %}

{% macro alerts_list(title, alerts) %}
  <table class="table table-striped">
    <thead>
      <tr>
        <th style="width: 1%;">&nbsp;</th>
        <th colspan="2">{{ title }}</th>
      </tr>
    </thead>
    <tbody>
      {% for alert in alerts %}
      <tr>
        <td class="alert-icon"><span class="label {% if alert.new %} label-warning{% endif %} tooltip-top" title="{% if alert.new %}{% trans %}New notification{% endtrans %}{% else %}{% trans %}Old notification{% endtrans %}{% endif %}"><i class="icon-fire"></i></label></td>
        <td class="alert-message">{{ (_(alert.message) % alert.vars())|safe }}</td>
        <td class="alert-date">{{ alert.date|reltimesince }}</td>
      </tr>
      {% endfor %}
    </tbody>
  </table>
{% endmacro %}

{# Language strings macros #}
{% macro lang_today() -%}{% trans %}Today Notifications{% endtrans %}{%- endmacro %}
{% macro lang_yesterday() -%}{% trans %}Yesterday Notifications{% endtrans %}{%- endmacro %}
{% macro lang_week() -%}{% trans %}This Week{% endtrans %}{%- endmacro %}
{% macro lang_month() -%}{% trans %}This Month{% endtrans %}{%- endmacro %}
{% macro lang_older() -%}{% trans %}Older Notifications{% endtrans %}{%- endmacro %}