{% 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="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="{{ 'GANTRY5_PLATFORM_SETTINGS'|trans }}">
                    <i class="fa fa-fw fa-check"></i> <span>{{ 'GANTRY5_PLATFORM_SAVE_SETTINGS'|trans }}</span></button>
                </span>
                {% for group, list in particles %}
                    <h2 class="page-title">
                        <span class="title">{{ group|capitalize }} {{ 'GANTRY5_PLATFORM_SETTINGS'|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 }}...">
                                <i class="fa fa-fw fa-search"></i>
                            </div>
                            <div class="button" data-g-collapse-all="true"><i class="fa fa-fw fa-toggle-up"></i> {{ 'GANTRY5_PLATFORM_COLLAPSE_ALL'|trans }}</div>
                            <div class="button" data-g-collapse-all="false"><i class="fa fa-fw fa-toggle-down"></i> {{ 'GANTRY5_PLATFORM_EXPAND_ALL'|trans }}</div>
                        </div>
                    </div>

                    <div class="cards-wrapper g-grid">
                        {% for id, particle in list %}
                            {% if not particle.hidden %}
                                {% set prefix = 'particles.' ~ 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' : '' }}">
                                    <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 }}">
                                        <span class="g-collapse g-tooltip" data-title="{{ collapsed ? labels.expand : labels.collapse }}"><i class="fa fa-fw  fa-caret-up"></i></span>
                                        <span class="g-title">{{ particle.name }}</span>
                                        <input type="hidden" name="particles[{{ id }}]"/>
                                        {% 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': gantry.config.get(prefix ~ 'enabled')} %}
                                        {% endif %}
                                    </h4>

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

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