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

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

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

{% set tableData = [] %}
{% for stencil in stencils %}
	{% set tableData = tableData | merge([{
        id: stencil.id,
        labelHtml: {
            url: stencil.getCpEditUrl(),
            html: stencil.name | raw
        },
        title: stencil.name | t('formie'),
        url: stencil.getCpEditUrl(),
        handle: stencil.handle | e,
    }]) %}
{% 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: '#stencils-vue-admin-table',
        deleteAction: 'formie/stencils/delete',
        tableData: {{ tableData | json_encode | raw }},
    });
{% endjs %}
