{% extends 'base.html.twig' %}
{% import "user/actions.html.twig" as actions %}

{% block page_title %}{% if not user.alias is empty %}{{ user.alias }}{% else %}{{ user.username }}{% endif %}{% endblock %}
{% block page_subtitle %}{% if not user.alias is empty %}{{ user.username }}{% endif %}{% endblock %}
{% block page_actions %}{{ actions.user(user, tab) }}{% endblock %}

{% block main %}
    <div class="row">
        <div class="col-md-8">
            {% block profile_content %}{% endblock %}
        </div>

        <div class="col-md-4">

            {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
                {% import "macros/widgets.html.twig" as widgets %}
                {% block box_body_class %}box-profile{% endblock %}
                {% block box_body %}
                    <div class="text-center">
                        {{ widgets.user_avatar(user) }}
                        <h3 class="profile-username">{{ widgets.username(user) }}</h3>
                        <p class="text-muted">{{ user.title }}</p>
                    </div>
                    {% set seeOwnRate = is_granted('view_rate_own_timesheet') %}

                    <table class="table">
                        <tr>
                            <th>{{ 'stats.durationMonth'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ stats.durationThisMonth|duration }}</td>
                        </tr>
                        {% if seeOwnRate %}
                        <tr>
                            <th>{{ 'stats.amountMonth'|trans }}</th>
                            {# TODO which currency shall we use here? #}
                            <td class="text-nowrap pull-right">{{ stats.amountThisMonth|money }}</td>
                        </tr>
                        {% endif %}
                        <tr>
                            <th>{{ 'stats.durationTotal'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ stats.durationTotal|duration }}</td>
                        </tr>
                        {% if seeOwnRate %}
                        <tr>
                            <th>{{ 'stats.amountTotal'|trans }}</th>
                            {# TODO which currency shall we use here? #}
                            <td class="text-nowrap pull-right">{{ stats.amountTotal|money }}</td>
                        </tr>
                        {% endif %}
                    </table>
                {% endblock %}
            {% endembed %}

            {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
                {% block box_title %}{{ 'profile.about_me'|trans }}{% endblock %}
                {% block box_body %}
                    {# colors = purple, blue, aqua, red, green #}
                    <table class="table no-border">
                        <tr>
                            <th>{{ 'label.id'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ user.id }}</td>
                        </tr>
                        <tr>
                            <th>{{ 'label.username'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ user.username }}</td>
                        </tr>
                        <tr>
                            <th>{{ 'profile.first_entry'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ stats.firstEntry|date_short }}</td>
                        </tr>
                        <tr>
                            <th>{{ 'profile.registration_date'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ user.registeredAt|date_short }}</td>
                        </tr>
                        {% if is_granted('hourly-rate', user) %}
                        <tr>
                            <th>{{ 'label.hourlyRate'|trans }}</th>
                            <td class="text-nowrap pull-right">{{ user.preferenceValue('hourly_rate') }}</td>
                        </tr>
                        {% endif %}
                    </table>
                {% endblock %}
            {% endembed %}

            {% if user.teams is not empty and (is_granted('teams', user) or (app.user == user and is_granted('view_team_member'))) %}
                {% embed '@AdminLTE/Widgets/box-widget.html.twig' %}
                    {% import "macros/widgets.html.twig" as widgets %}
                    {% block box_title %}{{ 'label.my_teams'|trans }}{% endblock %}
                    {% block box_tools %}
                        {% if is_granted('roles', user) %}
                            <a class="btn-box-tool" href="{{ path('user_profile_teams', {'username': user.username}) }}"><i class="{{ 'edit'|icon }}"></i></a>
                        {% endif %}    
                    {% endblock %}
                    {% block box_body %}
                        {{ widgets.team_list(user.teams) }}
                    {% endblock %}
                {% endembed %}
            {% endif %}

        </div>
    </div>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    <script type="text/javascript">
        document.addEventListener('kimai.initialized', function() {
            KimaiReloadPageWidget.create('kimai.teamUpdate', true);
        });
    </script>
{% endblock %}
