<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * @methods
 *  getTitle() - string
 *  getSaveUrl() - string
 *  getSections() - array
 *  getForm() - html
 */
?>
<div data-mage-init='{"floatingHeader": {}}' class="page-actions"><?= $block->getSaveButtonHtml() ?></div>
<form action="<?= /* @escapeNotVerified */ $block->getSaveUrl() ?>" method="post" id="config-edit-form" enctype="multipart/form-data">
    <?= $block->getBlockHtml('formkey') ?>

    <script>
    window.setCacheAction = function(id, button) {
        document.getElementById(id).value = button.id;

        configForm.submit();
    }
    </script>

    <input type="hidden" id="catalog_action" name="catalog_action" value="" />
    <input type="hidden" id="jscss_action" name="jscss_action" value="" />

    <?= $block->getChildHtml('form') ?>
    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?= /* @escapeNotVerified */ __('Catalog') ?></h4>
        </div>
        <fieldset id="catalog">
            <table class="form-list">
                <tbody>
                    <?php foreach ($block->getCatalogData() as $_item): ?>
                    <?php /* disable reindex buttons. functionality moved to index management*/?>
                    <?php if ($_item['buttons'][0]['name'] != 'clear_images_cache') {
    continue;
}?>
                    <tr>
                        <td class="label"><label><?= /* @escapeNotVerified */ $_item['label'] ?></label></td>
                        <td class="value">
                            <?php foreach ($_item['buttons'] as $_button): ?>
                                <?php $clickAction = "setCacheAction('catalog_action',this)"; ?>
                                <?php if (isset($_button['warning']) && $_button['warning']): ?>
                                    <?php $clickAction = "if (confirm('" . addslashes($_button['warning']) . "')) {{$clickAction}}"; ?>
                                <?php endif; ?>
                                <button <?php if (!isset($_button['disabled']) || !$_button['disabled']):?>onclick="<?= /* @escapeNotVerified */ $clickAction ?>"<?php endif; ?> id="<?= /* @escapeNotVerified */ $_button['name'] ?>" type="button" class="scalable <?php if (isset($_button['disabled']) && $_button['disabled']):?>disabled<?php endif; ?>" style=""><span><span><span><?= /* @escapeNotVerified */ $_button['action'] ?></span></span></span></button>
                                <?php if (isset($_button['comment'])): ?> <br /> <small><?= /* @escapeNotVerified */ $_button['comment'] ?></small> <?php endif; ?>
                            <?php endforeach; ?>
                        </td>
                        <td><small>&nbsp;</small></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </fieldset>
    </div>

    <div class="entry-edit">
        <div class="entry-edit-head">
            <h4 class="icon-head head-edit-form fieldset-legend"><?= /* @escapeNotVerified */ __('JavaScript/CSS') ?></h4>
        </div>

        <fieldset id="jscss">
            <table class="form-list">
                <tbody>
                    <tr>
                        <td class="label"><label><?= /* @escapeNotVerified */ __('JavaScript/CSS Cache') ?></label></td>
                        <td class="value">
                            <button onclick="setCacheAction('jscss_action', this)" id='jscss_action' type="button" class="scalable"><span><span><span><?= /* @escapeNotVerified */ __('Clear') ?></span></span></span></button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </div>
</form>
<script>
    require(["jquery","mage/mage"],function($){
       $('#config-edit-form').mage('form').mage('validation');
    });
</script>
