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

{% set edit = gantry.authorize('outline.assign') %}

{% block gantry %}
    <div id="assignments">
        {% if assignments %}
            <form method="post">
                {% if edit %}
                <span class="float-right">
                    <button type="submit" class="button button-primary button-save" data-save="Assignments">
                        <i class="fa fa-fw fa-check"></i> <span>{{ 'GANTRY5_PLATFORM_SAVE_ASSIGNMENTS'|trans }}</span>
                    </button>
                </span>
                {% endif %}

                <h2 class="page-title">{{ 'GANTRY5_PLATFORM_ASSIGNMENTS'|trans }}</h2>

                <div class="g-filters-bar">
                    <div class="g-panel-filters" data-g-global-filter="">
                        <div class="search settings-block">
                            <input type="text" placeholder="{{ 'GANTRY5_PLATFORM_GLOBAL_FILTER_ELI'|trans }}" aria-label="{{ 'GANTRY5_PLATFORM_GLOBAL_FILTER_ELI'|trans }}" role="search">
                            <i class="fa fa-fw fa-search"></i>
                        </div>
                    </div>
                    <label>
                        <input type="checkbox" data-assignments-enabledonly="" /> {{ 'GANTRY5_PLATFORM_ASSIGNMENTS_HIDE_UNASSIGNED'|trans }}
                    </label>
                    {% if edit %}
                        <a href="#" data-g-assignments-check=""
                           aria-label="{{ 'GANTRY5_PLATFORM_ASSIGNMENTS_SELECT_ALL'|trans }}"
                           data-tip="{{ 'GANTRY5_PLATFORM_ASSIGNMENTS_SELECT_ALL'|trans }}"
                           data-tip-place="top">All
                        </a>
                        <a href="#" data-g-assignments-uncheck=""
                           aria-label="{{ 'GANTRY5_PLATFORM_ASSIGNMENTS_UNSELECT_ALL'|trans }}"
                           data-tip="{{ 'GANTRY5_PLATFORM_ASSIGNMENTS_UNSELECT_ALL'|trans }}"
                           data-tip-place="top">None
                        </a>
                    {% endif %}

                    {% if options %}
                        <div class="pull-right">
                            {% include '@gantry-admin/forms/fields/select/selectize.html.twig' with {'layout': 'input', 'name': 'assignments.assignment', 'field': {'type': 'select.selectize', 'options': options}, 'value': assignment} only %}
                        </div>
                    {% endif %}
                </div>

                <div class="cards-wrapper clearfix">
                    {% for type, types in assignments %}
                        {% for name, list in types %}
                            <div class="card settings-block">
                                <h4>
                                    {{ list.label }}
                                    <div class="g-panel-filters float-right align-right">
                                        <div class="search settings-block">
                                            <input type="text" placeholder="{{ 'GANTRY5_PLATFORM_FILTER_ELI'|trans }}" aria-label="{{ 'GANTRY5_PLATFORM_FILTER_ELI'|trans }}">
                                            <i class="fa fa-fw fa-search"></i>
                                        </div>
                                        {% if edit %}
                                            <a href="#" data-g-assignments-check=""
                                               aria-label="{{ 'GANTRY5_PLATFORM_SELECT_ALL_MENU'|trans ~ ' in ' ~ list.label  }}"
                                               data-tip="{{ 'GANTRY5_PLATFORM_SELECT_ALL_MENU'|trans ~ ' in ' ~ list.label  }}"
                                               data-tip-place="top">All
                                            </a>
                                            <a href="#" data-g-assignments-uncheck=""
                                               aria-label="{{ 'GANTRY5_PLATFORM_UNSELECT_ALL_MENU'|trans ~ ' in ' ~ list.label  }}"
                                               data-tip="{{ 'GANTRY5_PLATFORM_UNSELECT_ALL_MENU'|trans ~ ' in ' ~ list.label  }}"
                                               data-tip-place="top">None
                                            </a>
                                        {% endif %}
                                    </div>
                                </h4>

                                <div class="settings-param-wrapper">
                                    {% for link in list.items %}
                                        {% set path = 'assignments.' ~ type ~ '.' ~ name ~ '.' ~ link.name %}
                                        {% set group = link.section ? 'data-g-assignments-group=' ~ link.name : 'data-g-assignments-parent=' ~ link.taxonomy %}
                                        {% set value = link.value is defined ? link.value : gantry.config.get(path) %}
                                        <label class="settings-param{% if link.section %} settings-param-section{% endif %}"{{ group }}>
                                            {% include 'forms/fields/enable/enable.html.twig' with {
                                            'default': true,
                                            'name': path|fieldName,
                                            'field': link.field,
                                            'value': value,
                                            'disabled': not value,
                                            'turned_off': link.disabled,
                                            'title': "'" ~ link.label ~ "' Menu Item"
                                            } %}
                                            <span class="settings-param-title{% if link.section %} settings-param-section-title{% endif %}">
                                {{- link.label -}}
                            </span>
                                        </label>
                                    {% endfor %}
                                </div>
                            </div>
                        {% endfor %}
                    {% endfor %}
                </div>

                {% if edit %}
                <div class="g-footer-actions">
                    <span class="float-right">
                        <button type="submit" class="button button-primary button-save" data-save="{{ 'GANTRY5_PLATFORM_ASSIGNMENTS'|trans }}">
                            <i class="fa fa-fw fa-check"></i> <span>{{ 'GANTRY5_PLATFORM_SAVE_ASSIGNMENTS'|trans }}</span>
                        </button>
                    </span>
                </div>
                {% endif %}
                <input type="hidden" name="_end" value="1" />
            </form>
        {% else %}
            <h2 class="page-title">{{ 'GANTRY5_PLATFORM_ASSIGNMENTS'|trans }}</h2>
            {% if configuration == 'default' %}
                <p>{{ 'GANTRY5_PLATFORM_ASSIGN_BASE_DESC'|trans }}</p>
            {% else %}
                <p>{{ 'GANTRY5_PLATFORM_NO_ASSIGNMENTS_DESC'|trans }}</p>
            {% endif %}
        {% endif %}
    </div>
{% endblock %}
