{#
    MetaTagCollection form view. Should be included in conjunction with the
    MetaTagCollectionType.

    @author Elze Kool <info@visualmedia.nl>
#}
{% import 'VisualMTagManagerBundle:ManageMetaTag:form.html.twig' as _meta_tag_form %}

<!-- Container where tags are added -->
<div class="js-meta-tag-container" data-form-name="{{ form.metaTags.vars.full_name }}">

    {# First collect sets that are available #}
    {% set meta_tag_sets = [] %}
    {% for meta_tag_form in form.metaTags %}
        {% if meta_tag_form.vars.value.metaTagPreset.metaTagSet not in meta_tag_sets %}
            {% set meta_tag_sets = meta_tag_sets|merge([ meta_tag_form.vars.value.metaTagPreset.metaTagSet ]) %}
        {% endif %}
    {% endfor %}

    {# Now we collected the sets go trough them #}
    {% for meta_tag_set in meta_tag_sets %}
        <div class="meta-tag-set max-width" data-meta-tag-set-id="{{ meta_tag_set.id }}">

            <fieldset>

                <legend>
                    <button data-confirm="{{ 'meta_tag_collection.meta_tag_set_verwijder.confirm'|trans({}, 'forms') }}" type="button" class="btn btn-link pull-right js-meta-tag-set-del"><i class="icon-trash"></i></button>
                    {{ meta_tag_set.naam }}                    
                </legend>

                {% for meta_tag_form in form.metaTags %}
                    {% if meta_tag_form.vars.value.metaTagPreset.metaTagSet.id == meta_tag_set.id %}
                        {{ _meta_tag_form.meta_tag_widget(meta_tag_form) }}
                        {{ form_errors(meta_tag_form) }}
                    {% endif %}
                {% endfor %}

            </fieldset>

        </div>
    {% endfor %}

    {{ form_errors(form.metaTags) }}
    {% do form.metaTags.setRendered %}

</div>



<!-- Add new set button -->
<div class="max-width">
    <hr />

    <div class="row">
        <div class="col-sm-7">
            {{ render(url('manage_meta_tag_available_sets')) }}
        </div>

        <div class="col-sm-3">
            <button type="button" class="btn btn-link js-meta-tag-addset"><i class="glyphicon glyphicon-plus-sign"></i> Set toevoegen</button>
        </div>
    </div>
</div>

{% stylesheets
    'bundles/visualmtagmanager/codemirror-4.5/lib/codemirror.css'
    'bundles/visualmtagmanager/codemirror-4.5/theme/monokai.css'
    'bundles/visualmtagmanager/css/meta_tag_collection/form.css'
%}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

{% set js %}
    {% javascripts
        'bundles/visualmtagmanager/codemirror-4.5/lib/codemirror.js'
        'bundles/visualmtagmanager/codemirror-4.5/mode/javascript/javascript.js'
        'bundles/visualmtagmanager/js/meta_tag_collection/form.js'
    %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endset %}
{{ append_javascript(js, 'meta_tag_collection_form') }}
