{% load timepiece_tags %}
{% load url from future %}

<div class="navbar navbar-fixed-top navbar-inverse">
    <div class="navbar-inner">
        <div class="container-fluid visible-desktop">
            {% block navbar-left %}
                <ul class="nav pull-left">
                <li class="active"><a class="brand" href="/">Timepiece</a></li>
                {% block quick-clock-in %}
                    {% if perms.timepiece.can_clock_in %}
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-time icon-white"> </i><b class="caret"></b> </a>
                            <ul class="dropdown-menu">
                                <li><a href="{% url 'timepiece-clock-in' %}">Clock in...</a></li>
                                <li class="divider"></li>
                                {% for project in work_projects %}
                                    <li><a href="{% url 'timepiece-clock-in' %}?project={{ project.id }}">{{ project.name }}</a></li>
                                {% endfor %}
                                <li class="divider"></li>
                                {% for project in leave_projects %}
                                    <li><a href="{% url 'timepiece-clock-in' %}?project={{ project.id }}">{{ project.name }}</a></li>
                                {% endfor %}
                            </ul>
                        {% endif %}
                {% endblock %}

                    {% if perms.timepiece.add_entry %}
                        <li><a href="{% url 'view_person_time_sheet' request.user.pk %}">Time Sheet</a></li>
                    {% endif %}
                    {% if perms.timepiece.view_project or perms.auth.view_user or perms.timepiece.view_business or persm.timepiece.add_project_contract %}
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">CRM <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                {% if perms.timepiece.view_project %}
                                    <li><a href="{% url 'list_projects' %}">Projects</a></li>
                                {% endif %}
                                {% if perms.auth.view_user %}
                                    <li><a href="{% url 'list_people' %}">People</a></li>
                                {% endif %}
                                {% if perms.timepiece.view_business %}
                                    <li><a href="{% url 'list_businesses' %}">Businesses</a></li>
                                {% endif %}
                                {% if perms.timepiece.add_project_contract %}
                                    <li><a href="{% url 'list_contracts' %}">Contracts</a></li>
                                {% endif %}
                            </ul>
                        </li>
                    {% endif %}
                    {% if perms.timepiece.can_clock_in or perms.timepiece.view_entry_summary or perms.timepiece.view_payroll_summary or perms.timepiece.change_entrygroup or user.is_staff %}
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Management <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                {% if perms.timepiece.view_entry_summary %}
                                    <li><a href="{% url 'billable_hours' %}">Billable Hours</a></li>
                                    <li><a href="{% url 'timepiece-summary' %}">General Ledger</a></li>
                                    <li><a href="{% url 'hourly_report' %}">Hourly</a></li>
                                {% endif %}
                                {% if perms.timepiece.view_payroll_summary %}
                                    <li><a href="{% url 'payroll_summary' %}">Payroll Summary</a></li>
                                    <li><a href="{% url 'productivity_report' %}">Productivity</a></li>
                                {% endif %}
                                {% if perms.timepiece.view_payroll_summary %}
                                    {% if user.is_staff or perms.timepiece.change_entrygroup or perms.timepiece.can_clock_in %}
                                        <li class="divider"></li>
                                    {% endif %}
                                {% endif %}
                                {% if user.is_staff %}
                                    <li><a href="{% url 'admin:index' %}">Admin</a></li>
                                {% endif %}
                                {% if perms.timepiece.change_entrygroup %}
                                    <li><a href="{% url 'invoice_projects' %}">Invoices</a></li>
                                {% endif %}
                                {% if perms.timepiece.can_clock_in %}
                                    <li><a href="{% url 'project_hours' %}">Weekly Schedule</a></li>
                                {% endif %}
                            </ul>
                        </li>
                    {% endif %}

                    {% for name, links in timepiece_extra_nav.items %}
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ name }} <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                {% for url_name, link_text in links %}
                                    <li><a href="{% url url_name %}">{{ link_text }}</a></li>
                                {% endfor %}
                            </ul>
                        </li>
                    {% endfor %}

                </ul>
            {% endblock %}

            {% block navbar-right %}
                {% if user.is_authenticated %}
                    <ul class="nav pull-right">
                        <li class="dropdown">
                            <a href="" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i> {{ user.first_name }} <b class="caret"></b></a>
                            <ul class="dropdown-menu">
                                <li><a href="{% url 'edit_settings' %}">Settings</a></li>
                                <li><a href="{% url 'change_password' %}">Change Password</a></li>
                                <li class="divider"></li>
                                <li><a href="{% url 'auth_logout' %}">Logout</a></li>
                            </ul>
                        </li>
                    </ul>
                {% else %}
                    <a class="btn btn-primary pull-right" href="{% url 'auth_login' %}">Login</a>
                {% endif %}

                {% block quick-search %}
                    {% if perms.timepiece.view_business %}
                        <form class="navbar-search pull-right" action="{% url 'quick_search' %}" method="get" accept-charset="utf-8">
                            {{ quick_search_form.quick_search }}
                        </form>
                    {% endif %}
                {% endblock %}
            {% endblock %}
        </div>

        <div class="container-fluid hidden-desktop">
            <a class="brand" href="/">Timepiece</a>

            {% if user.is_authenticated %}
                <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </a>
            {% endif %}

            <div class="nav-collapse">
                <ul class="nav">
                    {% if perms.timepiece.add_entry %}
                        <li><a href="{% url 'dashboard' %}">Dashboard</a></li>
                        <li><a href="{% url 'view_person_time_sheet' request.user.pk %}">My Ledger</a></li>
                        <li><a href="{% url 'timepiece-add' %}">Add Entry</a></li>
                        <li><a href="{% url 'auth_logout' %}">Logout</a></li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </div>
</div>
