{% load i18n %}
{% load static %}

{% load compress %}

{% load common_tags %}
{% load navigation_tags %}

{% spaceless %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="Content-Language" content="{{ LANGUAGE_CODE }}" />
        <title>
            {% block base_title %}
                {% block title %}{% endblock %} :: {% block project_name %}{% project_name %}{% endblock %}
            {% endblock base_title %}
        </title>

        {% compress css %}
            <link href="{% static 'appearance/packages/font-awesome-4.7.0/css/font-awesome.min.css' %}" media="screen" rel="stylesheet" type="text/css" />
            {# Disable base Bootstrap CSS, Flatly seems to include it already #}
            {#<link href="{% static 'appearance/packages/bootstrap-3.3.4-dist/css/bootstrap.min.css' %}" media="screen" rel="stylesheet" type="text/css"  />#}
            <link href="{% static 'appearance/packages/bootswatch.com/flatly/bootstrap.css' %}" media="screen" rel="stylesheet" type="text/css" />
            <link href="{% static 'appearance/packages/animate/animate.css' %}" media="screen" rel="stylesheet" type="text/css" />
            <link href="{% static 'appearance/packages/fancyBox-master/source/jquery.fancybox.css' %}" media="screen" rel="stylesheet" type="text/css" />
            <link href="{% static 'appearance/packages/select2-4.0.3/dist/css/select2.min.css' %}" media="screen" rel="stylesheet" type="text/css" />
            <link href="{% static 'appearance/packages/toastr-master-998959b0/build/toastr.min.css' %}" media="screen" rel="stylesheet" type="text/css" />
            <link href="{% static 'appearance/css/base.css' %}" media="screen" rel="stylesheet" type="text/css" />
            {% block stylesheets %}{% endblock %}
        {% endcompress %}
        <script>
            function waitForJQuery(func) {
                if (window.jQuery) {
                    func();
                } else {
                    setTimeout(function() {
                        waitForJQuery(func)
                    }, 50);
                }
            }
        </script>
    </head>
    <body>
        {% if appearance_type == 'plain' %}
            {% block content_plain %}{% endblock %}
        {% else %}
            <nav class="navbar navbar-default navbar-fixed-top">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                            <span class="sr-only">{% trans 'Toggle navigation' %}</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        {# TODO: don't use hardcoded main:home use settings.LOGIN_REDIRECT_URL #}
                        <a class="navbar-brand" href="{% url 'common:home' %}">{% project_name %}</a>
                    </div>
                    <div id="navbar" class="navbar-collapse collapse">
                        <ul class="nav navbar-nav">
                            {% get_menu_links 'main menu' as menu_links %}
                            {% for link_set in menu_links %}
                                {% for link in link_set %}
                                    {% with 'true' as as_li %}
                                    {% with 'true' as hide_active_anchor %}
                                    {% with 'active' as li_class_active %}
                                    {% with 'first' as li_class_first %}
                                    {% with ' ' as link_classes %}
                                        {% include 'navigation/generic_subnavigation.html' %}
                                    {% endwith %}
                                    {% endwith %}
                                    {% endwith %}
                                    {% endwith %}
                                    {% endwith %}
                                {% endfor %}
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </nav>

            <div class="container-fluid">
                <div class="row">
                    <div class="col-xs-12">
                        {% block messages %}{% endblock %}
                    </div>
                </div>

                {% get_menus_links names='object menu,sidebar menu,secondary menu' as links %}
                {% get_menu_links 'object facet' as form_navigation_links %}

                <div class="row">
                    {% if links or form_navigation_links %}
                        <div class="col-xs-12 col-sm-9 col-md-10 col-lg-10">
                    {% else %}
                        <div class="col-xs-12">
                    {% endif %}
                        {% block content %}{% endblock %}
                        {% block footer %}{% endblock %}
                    </div>

                    {% if links or form_navigation_links %}
                        <div class="col-xs-12 col-sm-3 col-md-2 col-lg-2">
                    {% endif %}

                    {% if links %}
                        <div class="pull-right btn-group" style="margin-bottom: 10px;">
                            <button aria-expanded="true" type="button" class="btn btn-danger btn-sm dropdown-toggle" data-toggle="dropdown">
                                {% trans 'Actions' %}
                                <span class="caret"></span>
                                <span class="sr-only">{% trans 'Toggle Dropdown' %}</span>
                            </button>
                            <ul class="dropdown-menu" role="menu">
                                {% for links_set in links %}
                                    {% for entry in links_set %}
                                        <li><a class="btn-sm" href="{{ entry.url }}">{{ entry.text }}</a></li>
                                    {% endfor %}

                                    {% if not forloop.last and links_set %}
                                        <li class="divider"></li>
                                    {% endif %}
                                {% endfor %}
                            </ul>
                        </div>
                         <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
                    {% endif %}

                    {% if form_navigation_links %}
                        <div class="pull-right list-group">
                            {% if form_navigation_links %}
                                {% for object_navigation_links in form_navigation_links %}
                                    {% with 'true' as hide_active_anchor %}
                                    {% with 'active' as link_class_active %}
                                    {% with 'list-group-item btn-sm' as link_classes %}
                                        {% include 'navigation/generic_navigation.html' %}
                                    {% endwith %}
                                    {% endwith %}
                                    {% endwith %}
                                {% endfor %}
                            {% endif %}
                        </div>
                    {% endif %}

                    {% if links or form_navigation_links %}
                        </div>
                    {% endif %}
                </div>
            </div>
        {% endif %}

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

        {% compress js %}
        <script type="text/javascript" src="{% static 'appearance/packages/jquery-2.1.4.min.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/bootstrap-3.3.4-dist/js/bootstrap.min.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/jquery.scrollview.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/jquery_lazyload-master/jquery.lazyload.min.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/fancyBox-master/source/jquery.fancybox.pack.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/fancyBox-master/lib/jquery.mousewheel.pack.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/select2-4.0.3/dist/js/select2.min.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/toastr-master-998959b0/build/toastr.min.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/packages/jquery.matchHeight-min.js' %}"></script>
        <script type="text/javascript" src="{% static 'appearance/js/base.js' %}"></script>
        {% endcompress %}

        <script>
        var DjangoMessages = [
            {% for message in messages %}
                {
                    tags: '{{ message.tags }}',
                    message: '{{ message.message }}'
                },
            {% endfor %}
        ];
        </script>
        {% block javascript %}{% endblock %}
    </body>
</html>
{% endspaceless %}
