{% extends "@MauticCore/Theme/index.html.twig" %}

{% block mainContent %}

    {% if items|length %}
        <div class="table-responsive">
            <table class="table table-hover table-striped table-bordered theme-list" id="themeTable">
                <thead>
                    <tr>   
                        {{ include('@MauticCore/Helper/tableheader.html.twig', {
                            'checkall': 'true',
                            'target'  : '#themeTable',
                            'langVar' : 'core.theme',
                            'routeBase': 'themes',
                            'templateButtons': {
                                'delete': permissions['core:themes:delete'],
                            },
                        })}}

                        {{ include('@MauticCore/Helper/tableheader.html.twig', {
                            'text': 'mautic.core.title',
                        })}}

                        {{ include('@MauticCore/Helper/tableheader.html.twig', {
                            'text': 'mautic.core.author',
                        })}}

                        {{ include('@MauticCore/Helper/tableheader.html.twig', {
                            'text': 'mautic.core.features',
                        })}}

                    </tr>
                </thead>
                <tbody>
                    {% for k, item in items %}
                        {% set thumbnailUrl = asset('themes/' ~ k ~ '/thumbnail.png') %}
                        {% set hasThumbnail =  (item['dir'] ~ '/thumbnail.png') is file  %}
                        <tr>
                            <td>
                                {% set item = item|merge({id: item.key}) %}
                                {% set previewButtonSettings = {
                                    'attr': {
                                        'data-toggle': 'modal',
                                        'data-target': '#theme-' ~ k,   
                                    },
                                    'btnText': 'mautic.asset.asset.preview'|trans,
                                    'iconClass': 'fa fa-image',
                                    } %}
                                {% set previewButton = hasThumbnail ? previewButtonSettings : [] %}
                                {% set deleteButton = {
                                    'delete': permissions['core:themes:delete']
                                } %}
                                {% set templateButtons = (k not in defaultThemes) ? deleteButton : {} %}

                                {{ include ('@MauticCore/Helper/list_actions.html.twig',
                                    {
                                        'item': item,
                                        'templateButtons': templateButtons,
                                        'routeBase': 'themes',
                                        'langVar': 'core.theme',
                                        'customButtons': [
                                            {
                                                'attr': {
                                                    'href': path('mautic_themes_action', { 
                                                        objectAction: 'download',
                                                        objectId: k
                                                    }),
                                                    'data-toggle': '0',
                                                },
                                                'btnText': 'mautic.core.download'|trans,
                                                'iconClass': 'fa fa-download',
                                            },
                                            previewButton,
                                        ],
                                    }
                                ) }}

                                {% if hasThumbnail %}
                                <!-- Modal -->
                                <div class="modal fade" id="theme-{{ k }}" tabindex="-1" role="dialog" aria-labelledby="{{ k }}">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title" id="{{ k }}">{{ item['name']|e }}</h4>
                                            </div>
                                            <div class="modal-body">
                                                <div style="background-image: url({{ thumbnailUrl }});background-repeat:no-repeat;background-size:contain; background-position:center; width: 100%; height: 600px"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {% endif %}
                            </td>
                            <td>
                                <div>
                                    {{ item['name']|e }} ({{ item['key']|e }})
                                </div>
                            </td>
                            <td>
                                <div>
                                    {% if item['config']['authorUrl'] is defined and item['config']['authorUrl'] is not empty and item['config']['author'] is defined %}
                                        <a href="{{ inputUrl(item['config']['authorUrl']) }}" target="_blank">
                                            {{ item['config']['author']|e }}
                                        </a>
                                    {% elseif item['config']['author'] is defined and item['config']['author'] is not empty %}
                                        {{ item['config']['author']|e }}
                                    {% endif %}
                                </div>
                            </td>
                            <td class="visible-md visible-lg">
                                    {% for builder in item['config']['builder'] %}
                                    <span style="white-space: nowrap;">
                                        <span class="label label-primary pa-4">{{ builder }}</span>
                                    </span>
                                {% endfor %}
                                {% if item['config']['features'] is defined and item['config']['features'] is not empty %}
                                    {% for feature in item['config']['features'] %}
                                        <span style="white-space: nowrap;">
                                            <span class="label label-default pa-4">
                                                {{ ('mautic.core.theme.feature.' ~ feature|e)|trans }}
                                            </span>
                                        </span>
                                    {% endfor %}
                                {% endif %}
                            </td>
                        <tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% else %}
    {{ include('@MauticCore/Helper/noresults.html.twig', {
                'tip': 'mautic.theme.noresults.tip'
            })
        }}
    {% endif %}
{% endblock %}
