{% extends 'partials/base.html.twig' %}

{% macro spanToggle(input, length) %}
    {{ (repeat('  ', (length - input|length) / 2) ~ input ~ repeat('  ', (length - input|length) / 2))|raw }}
{% endmacro %}

{% macro loop(page, depth, twig_vars) %}
    {% import _self as self %}

    {% set config = twig_vars['config'] %}
    {% set separator = config.system.param_sep %}
    {% set display_field = config.plugins.admin.pages_list_display_field %} {# DEPRECATED #}
    {% set base_url_relative_frontend = twig_vars['base_url_relative_frontend'] %}
    {% set admin = twig_vars['admin'] %}
    {% set warn = twig_vars['warn'] %}
    {% set uri = twig_vars['uri'] %}

    {% if page.header.admin.children_display_order == 'collection' and page.header.content.order.by %}
        {% if page.header.content.order.custom %}
            {% set pcol = page.children().order(page.header.content.order.by, page.header.content.order.dir|default('asc'), page.header.content.order.custom) %}
        {% else %}
            {% set pcol = page.children().order(page.header.content.order.by, page.header.content.order.dir|default('asc')) %}
        {% endif %}
    {% else %}
        {% set pcol = page.children() %}
    {% endif %}

    {% for p in pcol %}
        {% set description = (not p.page ? "PLUGIN_ADMIN.FOLDER"|t ~ ' • ' : "PLUGIN_ADMIN.PAGE"|t ~ ' • ') ~
            (p.isModule ? "PLUGIN_ADMIN.MODULE"|t ~ ' • ' : '') ~
            (p.routable ? "PLUGIN_ADMIN.ROUTABLE"|t ~ ' • ' : "PLUGIN_ADMIN.NON_ROUTABLE"|t ~ ' • ') ~
            (p.visible ? "PLUGIN_ADMIN.VISIBLE"|t ~ ' • ' : "PLUGIN_ADMIN.NON_VISIBLE"|t ~ ' • ') ~
            (p.published ? "PLUGIN_ADMIN.PUBLISHED"|t ~ ' • ' : "PLUGIN_ADMIN.NON_PUBLISHED"|t ~ ' • ') %}

        {% set page_url = getPageUrl(p) %}

        <li class="page-item" data-nav-id="{{ p.route }}">
            <div class="row page-item__row">
                <span class="page-item__toggle" {{ p.children(0).count > 0 ? 'data-toggle="children"' : ''}}>
                    <i class="page-icon fa fa-fw fa-circle-o {{ p.children(0).count > 0 ? 'children-closed' : ''}} {{ p.isModule ? 'modular' : (not p.routable ? 'not-routable' : (not p.visible ? 'not-visible' : (not p.page ? 'folder' :  ''))) }}"></i>
                </span>
                <div class="page-item__content">
                    <div class="page-item__content-name">
                        <span data-hint="{{ description|trim(' &bull; ')|raw }}" class="hint--top page-item__content-hint">
                            {% set page_label = attribute(p.header, display_field)|defined(attribute(p, display_field))|defined(p.title)|default(p.slug|titleize) %}
                            <a href="{{ page_url }}" class="page-edit">{{ page_label }}</a>
                        </span>
                        {% if p.language %}
                            <span class="badge lang {% if p.language == admin.language %}info{% endif %}">{{p.language}}</span>
                        {% endif %}
                        {% if p.home %}
                            <span class="page-home"><i class="fa fa-home"></i></span>
                        {% endif %}
                    </div>
                    <p class="page-route">{{ p.header.routes.default ?: p.route }} <span class="spacer"><i class="fa fa-long-arrow-right"></i></span> {{ p.template() }}</p>
                </div>
                <span class="page-item__tools">
                    {% if config.plugins.admin.frontend_preview_target != 'inline' %}
                        {% set preview_target = config.plugins.admin.frontend_preview_target %}
                        {% set preview_route = (base_url_relative_frontend|rtrim('/') ~ (p.home ? '' : p.route)) ?: '/' %}
                        {% set preview_link = p.routable ? '<a class="page-view" target="' ~ preview_target ~ '" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|t ~ '"> <i class="fa fa-fw fa-eye"></i></a>' : '' %}
                    {% else %}
                        {% set preview_route = admin_route('/preview' ~ (p.home ? '' : p.route)) %}
                        {% set preview_link = p.routable ? '<a class="page-view" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|t ~ '"> <i class="fa fa-fw fa-eye"></i></a>' : '' %}
                    {% endif %}
                    {{ preview_link|raw }}
                    {% if warn %}
                        <a href="#delete" data-remodal-target="delete" data-delete-url="{{ uri.addNonce(page_url ~ '/task' ~ separator ~ 'delete', 'admin-form', 'admin-nonce') }}" class="page-delete" ><i class="fa fa-trash-o"></i></a>
                    {% else %}
                        <a href="{{ uri.addNonce(page_url ~ '/task' ~ separator ~ 'delete', 'admin-form', 'admin-nonce') }}" class="page-delete" ><i class="fa fa-trash-o"></i></a>
                    {% endif %}
                </span>
            </div>
            {% if p.children().count > 0 %}
                <ul class="depth-{{ depth + 1 }}" style="display:none;">
                    {{ self.loop(p, depth + 1, twig_vars) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}

{% import _self as macro %}

{% if admin.route %}
    {% set context = admin.page(true) %}
    {#
    {% if admin.language != admin.session.admin_lang %}
        {% do admin.setMessage('Session language does not match') %}
    {% endif %}
    #}
{% elseif grav.language.enabled and admin.language != admin.session.admin_lang %}
    {# Redirect to last set language #}
    {% do admin.redirect(admin.adminRoute('/pages', admin.session.admin_lang)) %}
{% endif %}

{% if uri.param('new') %}
    {% set mode = 'new' %}
{%  elseif context %}
    {% set mode = 'edit' %}
    {% if context.exists %}
        {% set page_url = admin_route('/pages' ~ (context.header.routes.default ?: context.rawRoute)) %}
        {% set exists = true %}
        {% set title = (context.exists ? "PLUGIN_ADMIN.EDIT"|t : "PLUGIN_ADMIN.CREATE"|t ) ~ " " ~ (context.header.title ?: context.title) %}
    {% else %}
        {% set title = "PLUGIN_ADMIN.ADD_PAGE"|t %}
    {% endif %}
{% else %}
    {% set mode = 'list' %}
    {% set title = "PLUGIN_ADMIN.PAGES"|t %}
{% endif %}

{% set modular = context.isModule ? 'modular_' : '' %}
{% set warn = config.plugins.admin.warnings.delete_page %}
{% set secure_delete = config.plugins.admin.warnings.secure_delete %}
{% set page_lang = context.language %}
{% set type = 'page' %}

{% block stylesheets %}
    {% if mode == 'edit' %}
        {% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %}
    {% endif %}
    {{ parent() }}
{% endblock %}

{% block javascripts %}
    {{ parent() }}
{% endblock %}

{% if config.plugins.admin.frontend_preview_target != 'inline' %}
    {% set preview_route = (base_url_relative_frontend|rtrim('/') ~ (context.home ? '' : context.route)) ?: '/' %}
    {% set preview_target = config.plugins.admin.frontend_preview_target %}
    {% set preview_link = context.routable ? '<a class="button" target="' ~ preview_target ~ '" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|t ~ '"> <i class="fa fa-fw fa-eye" style="font-size:18px;margin-right:0;"></i></a>' : '' %}
{% else %}
    {% set preview_route = admin_route('/preview' ~ (context.home ? '' : context.route)) %}
    {% set preview_link = context.routable ? '<a class="button" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|t ~ '"> <i class="fa fa-fw fa-eye" style="font-size:18px;margin-right:0;"></i></a>' : '' %}
{% endif %}

{% block titlebar %}

    <div class="button-bar">
        {% if mode == 'list' %}
            <a class="button" href="{{ admin_route('/') }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|t }}</a>

            {% for key, add_modal in config.plugins.admin.add_modals %}
                {% if add_modal.show_in|defined('bar') == 'bar' %}
                    <a class="button {{ add_modal.link_classes }}" href="#modal-add_modal-{{ key }}" data-remodal-target="modal-add_modal-{{ key }}"><i class="fa fa-plus"></i> {{ add_modal.label|t }}</a>
                {% endif %}
            {% endfor %}

            <div class="button-group">
                <button type="button" class="button disabled" href="#modal" data-remodal-target="modal">
                    <i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.ADD"|t }}
                </button>
                <button type="button" class="button dropdown-toggle" data-toggle="dropdown">
                    <i class="fa fa-caret-down"></i>
                </button>
                <ul class="dropdown-menu">
                    <li><a class="button" href="#modal" data-remodal-target="modal">{{ "PLUGIN_ADMIN.ADD_PAGE"|t }}</a></li>
                    <li><a class="button" href="#modal-folder" data-remodal-target="modal-folder">{{ "PLUGIN_ADMIN.ADD_FOLDER"|t }}</a></li>
                    {% if admin.modularTypes is not empty %}
                        <li><a class="button" href="#module" data-remodal-target="module">{{ "PLUGIN_ADMIN.ADD_MODULE"|t }}</a></li>
                    {% endif %}
                    {% for key, add_modal in config.plugins.admin.add_modals %}
                        {% if add_modal.show_in|defined('bar') == 'dropdown' %}
                            <li><a class="button {{ add_modal.link_classes }}" href="#modal-add_modal-{{ key }}" data-remodal-target="modal-add_modal-{{ key }}">{{ add_modal.label|t }}</a></li>
                        {% endif %}
                    {% endfor %}
                </ul>
            </div>

            {% if admin.multilang %}
                <div class="button-group">
                    <button type="button" class="button disabled">
                        <i class="fa fa-flag-o"></i>
                        {% set langName = admin.siteLanguages[admin.language] %}
                        {{ langName[:1]|upper ~ langName[1:] }}
                    </button>
                    {%  if admin.languages_enabled|length > 1 %}
                    <button type="button" class="button dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-caret-down"></i>
                    </button>
                    <ul class="dropdown-menu language-switcher">
                        {% for langCode in admin.languages_enabled %}
                            {% set langName = admin.siteLanguages[langCode] %}
                            {% if langCode != admin.language %}
                                <li><a href="{{ uri.addNonce(base_url_relative ~ theme.slug ~ '/pages/task' ~ config.system.param_sep ~ 'switchlanguage/lang' ~ config.system.param_sep ~ langCode, 'admin-form', 'admin-nonce') }}">{{ langName[:1]|upper ~ langName[1:] }}</a></li>
                            {% endif %}
                        {% endfor %}
                    </ul>
                    {% endif %}
                </div>
            {% endif %}

        {% elseif mode == 'edit' %}

            {{ preview_link|raw }}

            <a class="button" href="{{ admin_route('/pages') }}" title="{{ "PLUGIN_ADMIN.BACK"|t }}"><i class="fa fa-reply"></i></a>

            {% if exists %}
                {% set siblings = context.parent().children() %}

                {% if not siblings.isFirst(context.path) %}
                    {% set sib = siblings.nextSibling(context.path) %}
                    {% set sib_url = admin_route('/pages' ~ (sib.header.routes.default ?: sib.rawRoute)) %}
                    <a class="button hidden-mobile" href="{{ sib_url }}" title="{{ "PLUGIN_ADMIN.PREVIOUS"|t }}"><i class="fa fa-chevron-left"></i></a>
                {% endif %}

                {% if not siblings.isLast(context.path) %}
                    {% set sib = siblings.prevSibling(context.path) %}
                    {% set sib_url = admin_route('/pages' ~ (sib.header.routes.default ?: sib.rawRoute)) %}
                    <a class="button hidden-mobile" href="{{ sib_url }}" title="{{ "PLUGIN_ADMIN.NEXT"|t }}"><i class="fa fa-chevron-right"></i></a>
                {% endif %}

                {% if warn %}
                    <a class="button" href="#delete" data-remodal-target="delete" data-delete-url="{{ uri.addNonce(page_url ~ '/task' ~ config.system.param_sep ~ 'delete', 'admin-form', 'admin-nonce') }}"><i class="fa fa-trash-o"></i> {{ "PLUGIN_ADMIN.DELETE"|t }}</a>
                {% else %}
                    <a class="button disable-after-click" href="{{ uri.addNonce(uri.route(true) ~ '/task' ~ config.system.param_sep ~ 'delete', 'admin-form', 'admin-nonce') }}" class="page-delete" ><i class="fa fa-trash-o"></i></a>
                {% endif %}

                <div class="button-group">
                    <button type="button" class="button disabled" href="#modal" data-remodal-target="modal">
                        <i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.ADD"|t }}
                    </button>
                    <button type="button" class="button dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-caret-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a class="button" href="#modal" data-remodal-target="modal">{{ "PLUGIN_ADMIN.ADD_PAGE"|t }}</a></li>
                        <li><a class="button" href="#modal-folder" data-remodal-target="modal-folder">{{ "PLUGIN_ADMIN.ADD_FOLDER"|t }}</a></li>
                        {% if admin.modularTypes is not empty %}
                            <li><a class="button" href="#module" data-remodal-target="module">{{ "PLUGIN_ADMIN.ADD_MODULE"|t }}</a></li>
                        {% endif %}
                    </ul>
                </div>

                <a class="button disable-after-click" href="{{ uri.addNonce(page_url ~ '/task' ~ config.system.param_sep ~ 'copy', 'admin-form', 'admin-nonce') }}" class="page-copy" ><i class="fa fa-copy"></i> {{ "PLUGIN_ADMIN.COPY"|t }}</a>
                <a class="button" href="#" data-remodal-target="move" data-parents="data[route]"><i class="fa fa-arrows"></i> {{ "PLUGIN_ADMIN.MOVE"|t }}</a>
                {% if config.plugins['admin-pro'].enabled %}
                    <a class="button" href="#" data-remodal-target="revisions"><i class="fa fa-history"></i> {{ "PLUGIN_ADMIN_PRO.REVISIONS"|t }}</a>
                {% endif %}

            {% endif %}

            <div class="button-group">
                <button class="button success" name="task" value="save" form="blueprints" type="submit"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|t }}</button>
                {% if exists and admin.multilang %}
                    {%  set untranslated = context.untranslatedLanguages(true) %}
                    {% if untranslated %}
                        <button type="button" class="button success dropdown-toggle" data-toggle="dropdown">
                            <i class="fa fa-caret-down"></i>
                        </button>
                        <ul class="dropdown-menu lang-switcher">
                            {% for langCode in untranslated %}
                                {% set langName = admin.siteLanguages[langCode] %}
                                {% if langCode != page_lang %}
                                    <li><button class="button success task" name="task" value="saveas" lang="{{langCode}}" form="blueprints" type="submit">{{ "PLUGIN_ADMIN.SAVE_AS"|t }} {{ langName[:1]|upper ~ langName[1:] }}</button></li>
                                {% endif %}
                            {% endfor %}
                        </ul>
                    {% endif %}
                {% endif %}
            </div>


        {% endif %}
    </div>
    {% if mode == 'new' %}
        <h1><i class="fa fa-fw fa-file-text-o"></i> {{ "PLUGIN_ADMIN.ADD_PAGE"|t }}</h1>
    {% elseif mode == 'edit' %}
        <h1><i class="fa fa-fw fa-file-text-o"></i>
            {{ context.title }}
        </h1>
    {% else %}
        <h1><i class="fa fa-fw fa-file-text-o"></i> {{ "PLUGIN_ADMIN.MANAGE_PAGES"|t }}</h1>
    {% endif %}
{% endblock %}

{% block content %}
    <div class="clear admin-pages">
    {% if mode == 'new' %}
        {% include 'partials/blueprints-new.html.twig' with { blueprints: admin.blueprints('pages/page'), data: context } %}
    {% elseif mode == 'edit' %}
        <div class="admin-form-wrapper">
            <div id="admin-topbar">

                {% if admin.multilang %}
                    {% set translated = context.translatedLanguages(false) %}
                    <div id="admin-lang-toggle" class="button-group">
                        <button type="button" class="button disabled">
                            {% if exists %}
                                {{ page_lang ?? "PLUGIN_ADMIN.DEFAULT"|t }}
                            {% else %}
                                {{ admin.language }}
                            {% endif %}
                        </button>

                        {% if exists and translated|length > 1 - (exists and not page_lang)|int %}
                            <button type="button" class="button dropdown-toggle" data-toggle="dropdown">
                                <i class="fa fa-caret-down"></i>
                            </button>
                            <ul class="dropdown-menu language-switcher">
                                {% for language, route in translated %}
                                    {% if language != page_lang ?? grav.language.default %}
                                    <li><button class="task" name="task" value="switchlanguage" lang="{{language}}" redirect="{{context.rawRoute|trim('/')}}" form="blueprints">{{ language }}</button></li>
                                    {% endif %}
                                {% endfor %}
                                {% if translated|length > 1  %}
                                    <li><button class="task" name="task" value="switchlanguage" lang="{{ grav.language.default }}" redirect="{{context.rawRoute|trim('/')}}" form="blueprints">Default</button></li>
                                {% endif %}
                            </ul>
                        {% endif %}
                    </div>
                {% endif %}

                {% if context.blueprints.fields and user.authorize('admin.super') %}
                {% set normalText = "PLUGIN_ADMIN.NORMAL"|t %}
                {% set expertText = "PLUGIN_ADMIN.EXPERT"|t %}
                {% set maxLen = max([normalText|length, expertText|length]) %}
                {% set normalText = macro.spanToggle(normalText, maxLen) %}
                {% set expertText = macro.spanToggle(expertText, maxLen) %}
                <form id="admin-mode-toggle">
                    <div class="switch-toggle switch-grav">
                        <input type="radio" value="normal" data-leave-url="{{ admin_route('/pages/' ~ admin.route|trim('/') ~ '/mode' ~ config.system.param_sep ~ 'normal') }}" id="normal" name="mode-switch" class="highlight" {% if admin.session.expert == '0' %} checked="checked"{% endif %}>
                        <label for="normal">{{ normalText|raw }}</label>
                        <input type="radio" value="expert" data-leave-url="{{ admin_route('/pages/' ~ admin.route|trim('/') ~ '/mode' ~ config.system.param_sep ~ 'expert') }}" id="expert" name="mode-switch" class="highlight" {% if admin.session.expert == '1' %} checked="checked"{% endif %}>
                        <label for="expert">{{ expertText|raw }}</label>
                        <a></a>
                    </div>
                </form>
                {% endif %}

            </div>

            {# Set current form data back into page content #}
            {% if current_form_data %}
                {% do context.header(current_form_data.header) %}
                {% do context.content(current_form_data.content) %}
            {% endif %}
            {% if (context.blueprints.fields and admin.session.expert == '0') or not user.authorize('admin.super') %}
                {% include 'partials/blueprints.html.twig' with { blueprints: context.blueprints, data: context } %}
            {% else %}
                {% include 'partials/blueprints-raw.html.twig' with { blueprints: admin.blueprints('admin/pages/'~modular~'raw'), data: context } %}
            {% endif %}
        </div>
    {% else %}
        <form id="page-filtering">
            <div class="page-filters">
                <input type="text" data-filter-labels="{{ [{'id': 'mode', 'name': 'PLUGIN_ADMIN.PAGE_MODES'|t}, {'id': 'type', 'name': 'PLUGIN_ADMIN.PAGE_TYPES'|t}, {'id': 'access', 'name': 'PLUGIN_ADMIN.ACCESS_LEVELS'|t}] |json_encode|e('html_attr')}}" data-filter-types="{{ admin.types|merge(admin.modularTypes)|json_encode|e('html_attr') }}" data-filter-access-levels="{{ admin.accessLevels|json_encode|e('html_attr') }}" placeholder="{{ "PLUGIN_ADMIN.ADD_FILTERS"|t }}" class="page-filter" name="page-filter" />
            </div>
            <div class="page-search">
                <input type="text" placeholder="{{ "PLUGIN_ADMIN.SEARCH_PAGES"|t }}" name="page-search" />
            </div>
            <div class="page-shortcuts">
                <span class="button button-x-small" data-page-toggleall="expand"><i class="fa fa-fw fa-plus-circle"></i> {{ "PLUGIN_ADMIN.EXPAND_ALL"|t }}</span>
                <span class="button button-x-small" data-page-toggleall="collapse"><i class="fa fa-fw fa-minus-circle"></i> {{ "PLUGIN_ADMIN.COLLAPSE_ALL"|t }}</span>
            </div>
        </form>
        <div class="pages-list">
            <ul class="depth-0">
                {{ macro.loop(pages, 0, _context) }}
            </ul>
            {% include 'partials/page-legend.html.twig' %}
        </div>
    {% endif %}
    </div>

    {% if context %}
        {% set obj_data = clone(context) %}

        {% if mode == 'edit' %}
            {% do obj_data.folder('') %}
        {% endif %}
    {% endif %}

    {% if mode == 'list' or mode == 'edit' %}
    <div class="remodal" data-remodal-id="modal" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
        {% include 'partials/blueprints-new.html.twig' with { blueprints: admin.blueprints('admin/pages/new'), data: obj_data, form_id:'new-page' } %}
    </div>

    <div class="remodal" data-remodal-id="modal-folder" data-remodal-options="hashTracking: false">
        {% include 'partials/blueprints-new-folder.html.twig' with { blueprints: admin.blueprints('admin/pages/new_folder'), data: obj_data, form_id:'new-folder' } %}
    </div>

    <div class="remodal" data-remodal-id="module" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
        {% include 'partials/blueprints-new.html.twig' with { blueprints: admin.blueprints('admin/pages/modular_new'), data: obj_data, form_id:'new-modular' } %}
    </div>

    {% for key, add_modal in config.plugins.admin.add_modals %}
        <div class="remodal {{ add_modal.modal_classes|defined('') }}" data-remodal-id="modal-add_modal-{{ key }}" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
            {% include add_modal.template|defined('partials/blueprints-new.html.twig') with { blueprints: admin.blueprints(add_modal.blueprint), data: context, form_id:'add-modal' }|merge(add_modal.with|defined({})) %}
        </div>
    {% endfor %}
    {% endif %}

    <div class="remodal parents-container" data-remodal-id="parents" data-remodal-options="hashTracking: false, stack: true">
        <form>
            <h1>Parents</h1>
            <div class="grav-loading"><div class="grav-loader">Loading...</div></div>
            <div class="parents-content"></div>
            <div class="button-bar">
                <a class="button secondary remodal-cancel" data-remodal-action="cancel" href="#"><i class="fa fa-fw fa-close"></i> {{ "PLUGIN_ADMIN.CANCEL"|t }}</a>
                <a class="button" data-parents-select href="#"><i class="fa fa-fw fa-check"></i> {{ "PLUGIN_ADMIN.CONTINUE"|t }}</a>
            </div>
        </form>
    </div>
    {% if mode == 'edit' %}
    <div class="remodal parents-container" data-remodal-id="move" data-remodal-options="hashTracking: false">
        {% include 'partials/page-move.html.twig' with { blueprints: admin.blueprints('admin/pages/move'), data: context } %}
    </div>
    <div class="remodal" data-remodal-id="revisions" data-remodal-options="hashTracking: false">
        {% include ['partials/page-revisions.html.twig', 'empty.html.twig'] ignore missing with { data: context } %}
    </div>
    {% endif %}

    {% include 'partials/modal-changes-detected.html.twig' %}

    <div class="remodal" data-remodal-id="delete" data-remodal-optF#ions="hashTracking: false">
        <form>
            <h1>{{ "PLUGIN_ADMIN.MODAL_DELETE_PAGE_CONFIRMATION_REQUIRED_TITLE"|t }}</h1>
            <p class="bigger">
                {% if context %}
                    <strong>{{ "PLUGIN_ADMIN.PAGE"|t }}: {{ context.title }}</strong>
                {% endif %}
            </p>
            <p class="bigger">
              {{ "PLUGIN_ADMIN.MODAL_DELETE_PAGE_CONFIRMATION_REQUIRED_DESC"|t }}
            </p>
            {% if secure_delete %}
                <p class="form-secure-delete">
                    <input id="secure-delete-field" autofocus type="text" placeholder="{{ "PLUGIN_ADMIN.SECURE_DELETE_DESC"|t }}" />
                </p>
            {% endif %}
            <br>
            <div class="button-bar">
            <button data-remodal-action="cancel" class="button secondary remodal-cancel"><i class="fa fa-fw fa-close"></i> {{ "PLUGIN_ADMIN.CANCEL"|t }}</button>
            {% if secure_delete %}
                <button id="secure-delete-btn" disabled="true" class="button danger disable-after-click" data-delete-action><i class="fa fa-fw fa-check"></i> {{ "PLUGIN_ADMIN.CONFIRM"|t }}</button>
            {% else %}
                <a class="button danger disable-after-click" data-delete-action href="#"><i class="fa fa-fw fa-check"></i> {{ "PLUGIN_ADMIN.CONTINUE"|t }}</a>
            {% endif %}
            </div>
        </form>
    </div>

    {% include 'partials/admin-pro-pages-addons.html.twig' ignore missing %}

{% endblock %}

{% block bottom %}
    {{ parent() }}
    <script>
        $('.admin-pages .form-tabs .tabs-nav').css('margin-right', ($('#admin-topbar').width() + 20) + 'px');
        {% if secure_delete %}
        $('#secure-delete-field').keyup(function () {
            var inputValue = $(this).val();
            if (inputValue == 'DELETE') {
                $('#secure-delete-btn').attr('disabled', false);
            }else{
                $('#secure-delete-btn').attr('disabled', true);
            }
        });
        $(document).on('closing', '.remodal', function () {
            $('#secure-delete-field').val('');
        });
        {% endif %}
    </script>
{% endblock %}