{% extends '@MapbenderManager/layouts/tabbed.html.twig' %}
{%- set title = 'mb.manager.source.sources' | trans -%}
{%- import '@MapbenderManager/macros/tabs.html.twig' as tab_macros -%}

{% block js %}
  {{parent()}}
  <script type="text/javascript" src="{{ asset('bundles/mapbendermanager/js/service-list.js') }}"></script>
{% endblock %}

{% block tab_headers %}
  {{- tab_macros.tab_header('Sources', 'mb.manager.source.sources', 'active') -}}
  {{- tab_macros.tab_header('SharedInstances', 'mb.terms.sourceinstance.reusable.plural') -}}
{% endblock tab_headers %}

{% block tab_containers %}
    <div{{ tab_macros.tab_content_attributes('Sources', 'active', false) }}>
        {%- set items = sources -%}
        {%- set list_id = 'listFilterServices' -%}
        <div class="list-head">
            <div class="row">
                <div class="col-sm-5 col-xs-12 col-12">
                    {%- if grants.create -%}
                        <div class="dropdown">
                            <button class="btn btn-outline-primary dropdown-toggle content-box content-box-md" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fas fa-plus fa-lg"></i>
                                <span>{{ 'mb.manager.source.add' | trans }}</span>
                            </button>
                            <ul class="dropdown-menu">
                                {% for source, label in datasources %}
                                    <li><a class="dropdown-item" href="{{ path('mapbender_manager_repository_new', parameters = {sourceType: source}) }}">{{ label }}</a></li>
                                {% endfor %}
                            </ul>
                        </div>
                    {%- endif -%}
                </div>
                {%- if items -%}
                    <div class="col-sm-7 col-xs-12 col-12">
                    {% include "@MapbenderManager/fragments/filter-container.html.twig" with {filterTargetId: list_id} only %}
                    </div>
                {%- endif -%}
            </div>
        </div>

        {% embed '@MapbenderManager/fragments/blocklist.html.twig' %}
            {%- block boxlist_item_content -%}
                {%- set source = item -%}
                {{- parent() -}}
            {%- endblock -%}

            {%- block item_content_main -%}
                {%- import '@MapbenderManager/macros/source.html.twig' as source_macros -%}
                {{- source_macros.source_meta(item) -}}
            {%- endblock -%}

            {%- block item_interactions -%}
                            <a class="btn btn-light" href="{{ path("mapbender_manager_repository_view",{"sourceId":item.id}) }}" title="{{ 'mb.manager.source.show_metadata' | trans }}"><i class="fas fa-display"></i></a>
                            {%- if grants.refresh -%}
                              <a class="btn btn-light" href="{{ path("mapbender_manager_repository_updateform",{"sourceId":item.id}) }}"
                                 title="{{ 'mb.manager.source.update' | trans }} {{ item.title }}"
                                 data-test="mb-update-source-{{item.title}}"><i class="fas fa-rotate"></i></a>
                            {% endif %}
                            {%- if grants.delete -%}
                              <a href="#" class="btn btn-light -fn-delete"
                                          title="{{"mb.manager.source.delete"|trans}} {{ item.title }}"
                                          data-url="{{ path("mapbender_manager_repository_delete",{"sourceId":item.id}) }}"
                                          data-test="mb-delete-source-{{item.title}}"
                                          data-id="{{ item.id }}"><i class="far fa-trash-can"></i></a>
                            {% endif %}
            {%- endblock -%}

            {%- block item_title -%}
              <a href="{{ path("mapbender_manager_repository_view",{"sourceId":item.id}) }}">{{ item.title }}</a> <sup>{{ item.alias }}&nbsp;#{{ item.id }}</sup>
            {%- endblock -%}

            {%- block boxlist_placeholder_content -%}
            {{- 'mb.manager.source.no_source' | trans -}}
            {%- endblock -%}
        {% endembed %}


    </div>
    <div{{ tab_macros.tab_content_attributes('SharedInstances', '', false) }}>
        {%- set list_id = 'listFilterSharedInstances' -%}
        {%- set list_class = '-fn-instance-list' -%}
        {%- set items = shared_instances -%}
        <div class="list-head">
            <div class="row">
                <div class="col-sm-5 col-xs-12 col-12">
                    {%- block list_actions -%}{%- endblock -%}
                </div>
                {%- if items -%}
                    <div class="col-sm-7 col-xs-12 col-12">
                    {% include "@MapbenderManager/fragments/filter-container.html.twig" with {filterTargetId: list_id} only %}
                    </div>
                {%- endif -%}
            </div>
        </div>
        {% embed '@MapbenderManager/fragments/blocklist.html.twig' %}
            {%- block item_interactions -%}
                {%- if grants.delete -%}
                  <a class="btn btn-light" href="{{ path('mapbender_manager_repository_unowned_instance', {'instanceId': item.id}) }}"
                    ><i class="fas fa-pencil"></i>
                  </a>
                {%- endif -%}
                <a class="btn btn-light" href="{{ path("mapbender_manager_repository_view",{"sourceId":item.source.id}) }}" title="{{ 'mb.manager.source.show_metadata' | trans }}"
                  ><i class="fas fa-display"></i></a>
                {%- if grants.delete -%}
                          <a class="btn btn-light -fn-delete" href="#"
                              data-url="{{ path('mapbender_manager_sourceinstance_delete', {'instance': item}) }}"
                              title="{{"mb.actions.delete"|trans}}"
                              ><i class="far fa-trash-can"></i></a>
                {%- endif -%}
            {%- endblock -%}

            {%- block boxlist_item_content -%}
                {%- set source = item.source -%}
                {{- parent() -}}
            {%- endblock -%}

            {%- block item_content_main -%}
                {%- import '@MapbenderManager/macros/source.html.twig' as source_macros -%}
                {{- source_macros.source_meta(item.source) -}}
            {%- endblock -%}

            {%- block item_title -%}
              <a href="{{ path("mapbender_manager_repository_view",{"sourceId":item.source.id}) }}">{{ item.title | default(item.source.title) }}</a>&nbsp;<sup>#{{ item.id }}</sup>
            {%- endblock -%}

            {%- block boxlist_placeholder_content -%}
            {{- 'mb.manager.source.no_source' | trans -}}
            {%- endblock -%}
        {% endembed %}
    </div>
{% endblock tab_containers %}
