{% extends ajax-suffix ? "@gantry-admin/partials/ajax.html.twig" : "@gantry-admin/partials/base.html.twig" %}

{% block gantry %}
    {% set stored_data = get_cookie('g5-collapsed')|default('{}')|json_decode %}
    <div id="page-settings">
        <form method="post">
            <div data-set-page="{{ page_id }}" data-set-root="">
                <span class="float-right">
                    <button type="submit" class="button button-primary button-save" data-save="Page Settings">
                        <i class="fa fa-fw fa-check" aria-hidden="true"></i> <span>{{ 'GANTRY5_PLATFORM_SAVE_PAGESETTINGS'|trans }}</span></button>
                </span>
                {% for group, list in page %}
                    {% if group != 'hidden' %}
                        <h2 class="page-title">
                            <span class="title">{{ group|capitalize }} {{ 'GANTRY5_PLATFORM_PAGESETTINGS'|trans }}</span>
                        </h2>

                        <div class="g-filter-actions">
                            <div class="g-panel-filters" data-g-global-filter="">
                                <div class="search settings-block">
                                    <input type="text" data-g-collapse-filter="" placeholder="{{ 'GANTRY5_PLATFORM_FILTER'|trans }} {{ group|capitalize }}..." aria-label="{{ 'GANTRY5_PLATFORM_FILTER'|trans }} {{ group|capitalize }}..." role="search" />
                                    <i class="fa fa-fw fa-search" aria-hidden="true"></i>
                                </div>
                                <button class="button" type="button" data-g-collapse-all="true"><i class="far fa-fw fa-caret-square-up" aria-hidden="true"></i> {{ 'GANTRY5_PLATFORM_COLLAPSE_ALL'|trans }}</button>
                                <button class="button" type="button" data-g-collapse-all="false"><i class="far fa-fw fa-caret-square-down" aria-hidden="true"></i> {{ 'GANTRY5_PLATFORM_EXPAND_ALL'|trans }}</button>
                            </div>
                        </div>

                        <div class="cards-wrapper g-grid">
                            {% for id, particle in list %}
                                {% if not particle.hidden %}
                                    {% set particle = gantry.page.getBlueprintForm(id) %}
                                    {% set prefix = 'page.' ~ id ~ '.' %}
                                    {% set collapsed = particle.form.collapsed or attribute(stored_data, prefix) %}
                                    {% set labels = {collapse: 'GANTRY5_PLATFORM_COLLAPSE'|trans, expand: 'GANTRY5_PLATFORM_EXPAND'|trans} %}
                                    <div class="card settings-block{{ collapsed ? ' g-collapsed' : '' }}">
                                        <input type="hidden" name="page[{{ id }}]"/>
                                        <h4 data-g-collapse="{{ labels|merge({collapsed: collapsed ? true : false, id: prefix, target: '~ .inner-params' })|json_encode|e('html_attr') }}"
                                            data-g-collapse-id="{{ prefix }}"
                                            {{ overrideable ? ' class="card-overrideable"' : '' }}
                                        >
                                            <span class="g-collapse" data-title="{{ collapsed ? labels.expand : labels.collapse }}" data-tip="{{ collapsed ? labels.expand : labels.collapse }}" data-tip-place="top-right"><i class="fa fa-fw fa-caret-up" aria-hidden="true"></i></span>
                                            <span class="g-title">{{ particle.name }}</span>
                                            {% if particle.form.fields.enabled %}
                                                {% include 'forms/fields/enable/enable.html.twig' with {'default': true, 'scope': prefix, 'name': 'enabled', 'field': particle.form.fields.enabled, 'value': data.get(prefix ~ 'enabled')} %}

                                                {% if overrideable %}
                                                    {% include 'forms/override.html.twig' with {'scope': prefix, 'name': 'enabled', 'field': {'label': 'Enabled of the ' ~ particle.name ~ ' Particle' }} %}
                                                {% endif %}
                                            {% endif %}
                                        </h4>

                                        <div class="inner-params">
                                            {% include 'forms/fields.html.twig' with {'ignore_not_overrideable': true, 'overrideable': overrideable, 'blueprints': particle.form, skip: ['enabled'], "prefix": prefix} %}
                                        </div>
                                    </div>
                                {% endif %}
                            {% endfor %}
                        </div>
                    {% endif %}
                {% endfor %}

                {% include '@gantry-admin/pages/configurations/page/atoms.html.twig' %}

                <div class="g-footer-actions">
                    <span class="float-right">
                        <button type="submit" class="button button-primary button-save" data-save="Page Settings">
                            <i class="fa fa-fw fa-check" aria-hidden="true"></i> <span>{{ 'GANTRY5_PLATFORM_SAVE_PAGESETTINGS'|trans }}</span></button>
                    </span>
                </div>
            </div>
        </form>
    </div>
{% endblock %}
