{% extends 'formie/_layouts/settings' %}

{% block actionButton %}
    <a href="{{ url('formie/settings/pdf-templates/new') }}" class="btn submit add icon">{{ 'New Template' | t('formie') }}</a>
{% endblock %}

{% block content %}
    <div id="pdf-templates-vue-admin-table"></div>
{% endblock %}

{% set tableData = [] %}
{% for template in pdfTemplates %}
    {% set tableData = tableData | merge([{
        id: template.id,
        labelHtml: {
            url: template.getCpEditUrl(),
            html: template.name,
        },
        title: template.name | t('formie'),
        url: template.getCpEditUrl(),
        handle: template.handle | e,
        _showDelete: template.canDelete(),
    }]) %}
{% endfor %}

{% js %}
    var columns = [
        {
            name: 'labelHtml',
            title: Craft.t('app', 'Name'),
            callback: function(value) {
                return '<a class="cell-bold" href="' + value.url + '">' + value.html + '</a>';
            }
        },
        { name: '__slot:handle', title: Craft.t('app', 'Handle') }
    ];

    new Craft.VueAdminTable({
        columns: columns,
        container: '#pdf-templates-vue-admin-table',
        deleteAction: 'formie/pdf-templates/delete',
        reorderAction: 'formie/pdf-templates/reorder',
        reorderSuccessMessage: Craft.t('formie', 'Templates reordered.'),
        reorderFailMessage: Craft.t('formie', 'Couldn’t reorder templates.'),
        tableData: {{ tableData | json_encode | raw }},
    });
{% endjs %}

