{% load static coderedcms_tags i18n wagtailcore_tags wagtailimages_tags wagtailsettings_tags wagtailuserbar %}
{% get_settings %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% wagtail_site as site %}


<!doctype html>
<html prefix="og: http://ogp.me/ns#" lang="{{ LANGUAGE_CODE }}">
  <head>
        {% block tracking %}
        {% if settings.coderedcms.AnalyticsSettings.ga_tracking_id %}
            <!-- Global site tag (gtag.js) - Google Analytics -->
            <script async src="https://www.googletagmanager.com/gtag/js?id={{settings.coderedcms.AnalyticsSettings.ga_tracking_id}}"></script>
            <script>
              cr_track_clicks = {{settings.coderedcms.AnalyticsSettings.ga_track_button_clicks|yesno:"true,false"}};
              window.dataLayer = window.dataLayer || [];
              function gtag(){dataLayer.push(arguments);}
              gtag('js', new Date());
              gtag('config', '{{settings.coderedcms.AnalyticsSettings.ga_tracking_id}}');
            </script>
        {% endif %}
        {% if settings.coderedcms.AnalyticsSettings.head_scripts %}
            {{settings.coderedcms.AnalyticsSettings.head_scripts|safe}}
        {% endif %}
        {% endblock %}

        {# Pass in CMS variables to JavaScript #}
        <script>
            cr_site_url = "{{site.root_url}}";
            cr_external_new_tab = {{settings.coderedcms.GeneralSettings.external_new_tab|yesno:"true,false"}};
        </script>

        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        {# SEO Metadata #}
        {% include "wagtailseo/meta.html" %}

        {% block frontend_assets %}
            {% if settings.coderedcms.LayoutSettings.frontend_theme %}
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/4.6.0/{{settings.coderedcms.LayoutSettings.frontend_theme}}/bootstrap.min.css" />
            {% else %}
            <link rel="stylesheet" href="{% static 'coderedcms/vendor/bootstrap/dist/css/bootstrap.min.css' %}" />
            {% endif %}
        {% endblock %}

        {% block coderedcms_assets %}
        {% if "DEBUG"|django_settings %}
        <link rel="stylesheet" type="text/css" href="{% static 'coderedcms/css/codered-front.css' %}">
        {% else %}
        <link rel="stylesheet" type="text/css" href="{% static 'coderedcms/css/codered-front.min.css' %}">
        {% endif %}
        {% endblock %}

        {% block custom_assets %}
            <link rel="stylesheet" type="text/css" href="{% static 'css/custom.css' %}">
        {% endblock %}

        {% block favicon %}
            {% if settings.coderedcms.LayoutSettings.favicon %}
                {# See https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/ #}
                {% image settings.coderedcms.LayoutSettings.favicon fill-120x120 format-png as favicon_iphone %}
                {% image settings.coderedcms.LayoutSettings.favicon fill-180x180 format-png as favicon_iphone_plus %}
                {% image settings.coderedcms.LayoutSettings.favicon fill-152x152 format-png as favicon_ipad %}
                {% image settings.coderedcms.LayoutSettings.favicon fill-167x167 format-png as favicon_ipad_pro %}
                <link rel="icon" type="image/png" href="{{ favicon_iphone_plus.url }}" />
                <link rel="apple-touch-icon" href="{{ favicon_iphone_plus.url }}">
                <link rel="apple-touch-icon" sizes="120x120" href="{{ favicon_iphone.url }}">
                <link rel="apple-touch-icon" sizes="180x180" href="{{ favicon_iphone_plus.url }}">
                <link rel="apple-touch-icon" sizes="152x152" href="{{ favicon_ipad.url }}">
                <link rel="apple-touch-icon" sizes="167x167" href="{{ favicon_ipad_pro.url }}">
            {% endif %}
        {% endblock %}

        {% block extra_head %}{% endblock %}
    </head>

    <body class="coderedcms-{{page.content_type.model}} {% if page.get_parent %}parent-page-{{page.get_parent.id}}{% endif %} {% block body_class %}{% endblock %}" id="page-{{page.id}}">

        {% include "coderedcms/includes/codered_banner.html" %}

        {% wagtailuserbar %}

        {% block ada_skip %}
            {% if settings.coderedcms.ADASettings.skip_navigation %}
                <a href='#content' title='Skip Navigation'>Skip Navigation</a>
            {% endif %}
        {% endblock %}

        {% block navbar %}{% endblock %}

        <div id="content">
            {% block content %}
                {% block messages %}
                    {% if messages %}
                        <div class="container">
                        {% for message in messages %}
                            <div class="alert alert-{{ message.tags|map_to_bootstrap_alert }}" role="alert">{{ message }}</div>
                        {% endfor %}
                        </div>
                    {% endif %}
                {% endblock %}
                {% block content_pre_body %}{% endblock %}

                {% block content_body %}
                {% include_block page.body with settings=settings %}
                {% endblock %}

                {% block content_post_body %}{% endblock %}

                {% block index_filters %}
                {% if page.index_show_subpages and page.index_classifiers.exists %}
                    {% include "coderedcms/includes/classifier_dropdowns.html" with formclass="form-inline" %}
                {% endif %}
                {% endblock %}

                {% block index_content %}
                {% if page.index_show_subpages %}
                    <ul>
                    {% for child in index_paginated %}
                        <li><a href="{% pageurl child %}">{{child.title}}</a></li>
                    {% endfor %}
                    </ul>
                    {% include "coderedcms/includes/pagination.html" with items=index_paginated %}
                {% endif %}
                {% endblock %}

            {% endblock %}
        </div>

        <div id="content-walls">
            {% block content_walls %}
                {% for content_wall in content_walls %}
                    {% include_block content_wall with settings=settings %}
                {% endfor %}
            {% endblock %}
        </div>

        {% block footer %}{% endblock %}

        {% block required_scripts %}
        <script src="{% static 'coderedcms/vendor/jquery/jquery-3.5.1.min.js' %}" ></script>
        {% endblock %}

        {% block frontend_scripts %}
        <script src="{% static 'coderedcms/vendor/bootstrap/dist/js/bootstrap.min.js' %}"></script>
        {% endblock %}

        {% block coderedcms_scripts %}
        <script type="text/javascript" src="{% static 'coderedcms/js/codered-front.js' %}"></script>
        {% endblock %}

        {% block custom_scripts %}
        {# Legacy behavior, remove this in the future and leave blank for client sites to implement. #}
        <script type="text/javascript" src="{% static 'js/custom.js' %}"></script>
        {% endblock %}

        {% include "wagtailseo/struct_data.html" %}

        {% block body_tracking_scripts %}
        {% if settings.coderedcms.AnalyticsSettings.body_scripts %}
            {{settings.coderedcms.AnalyticsSettings.body_scripts|safe}}
        {% endif %}
        {% endblock %}
    </body>
</html>
