{%- do gantry.theme.setLayout() -%}

{%- set content %}
    {% block content %}
    {% endblock %}
{% endset -%}

{%- set offcanvas = null -%}
{%- for segment in gantry.theme.segments if segment.type == 'offcanvas' %}
    {%- set offcanvas = segment -%}
{% endfor -%}

{%- set page_offcanvas %}
    {% block page_offcanvas %}
        {% if offcanvas %}
            {% include '@nucleus/layout/' ~ offcanvas.type ~ '.html.twig' with { 'segment': offcanvas } -%}
        {% endif %}
    {% endblock %}
{% endset %}

{%- set page_offcanvas = page_offcanvas|trim ?: '' %}
{%- set offcanvas_position = page_offcanvas ? offcanvas.attributes.position|default('g-offcanvas-left') : '' -%}

{%- set page_layout %}
    {% block page_layout %}
    {% for segment in gantry.theme.segments if segment.type != 'offcanvas' %}
        {% include '@nucleus/layout/' ~ segment.type ~ '.html.twig' with { 'segments': segment.children } %}
    {% endfor %}
    {% endblock %}
{% endset -%}

{%- set page_top %}
    {% block page_top %}
    {% endblock %}
{% endset -%}

{%- set page_bottom %}
    {% block page_bottom %}
        {{ gantry.scripts('footer')|join("\n    ")|raw }}
    {% endblock %}
{% endset -%}

{%- block page -%}
<!DOCTYPE {{ gantry.page.doctype|default('html')|raw }}>
<html{{ gantry.page.htmlAttributes|raw }}>
    {% block page_head -%}
        {% include 'partials/page_head.html.twig' %}
    {%- endblock %}
    {% block page_body -%}
    <body{{ gantry.page.bodyAttributes({'class': [offcanvas_position, 'g-style-' ~ gantry.theme.preset]})|raw }}>
        {{ page_offcanvas|raw }}
        <div id="g-page-surround">
            {% if page_offcanvas|trim %}
            <div class="g-offcanvas-hide g-offcanvas-toggle" data-offcanvas-toggle><i class="fa fa-fw fa-bars"></i></div>
            {% endif %}
            {{ page_top|raw }}
            {{ page_layout|raw }}
            {{ page_bottom|raw }}
        </div>
        <script type="text/javascript" src="{{ url('gantry-assets://js/main.js') }}"></script>
    </body>
    {%- endblock %}

</html>
{% endblock -%}
{% do gantry.platform.finalize() -%}
