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

/**@var \Magento\Backend\Block\Widget\Form\Renderer\Fieldset $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<?php $_element = $block->getElement() ?>
<?php $_jsObjectName = $block->getFieldSetId() != null ? $block->getFieldSetId() : $_element->getHtmlId() ?>
<div class="rule-tree">
<fieldset id="<?= $block->escapeHtmlAttr($_jsObjectName) ?>" <?= /* @noEscape */ $_element->serialize(['class']) ?>
          class="fieldset">
        <legend class="legend"><span><?= $block->escapeHtml($_element->getLegend()) ?></span></legend>
        <br>
    <?php if ($_element->getComment()): ?>
        <div class="messages">
            <div class="message message-notice"><?= $block->escapeHtml($_element->getComment()) ?></div>
        </div>
    <?php endif; ?>
    <div class="rule-tree-wrapper">
        <?= $_element->getChildrenHtml() ?>
    </div>
    </fieldset>
</div>

<?php $scriptString = <<<script

require([
    'Magento_Rule/rules',
    'prototype'
], function(VarienRulesForm){

script;
$scriptString .= 'window.' . /* @noEscape */ $_jsObjectName . ' = new VarienRulesForm(\'' .
    /* @noEscape */ $_jsObjectName . '\', \'' .  /* @noEscape */ $block->getNewChildUrl() . '\');';
if ($_element->getReadonly()):
    $scriptString .= /* @noEscape */ $_element->getHtmlId() . '.setReadonly(true);' . PHP_EOL;
endif;

$scriptString .= '});' . PHP_EOL;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
