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

/** @var \Magento\CatalogWidget\Block\Product\Widget\Conditions $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */

$element = $block->getElement();
$fieldId = $element->getHtmlContainerId() ? ' id="' . $block->escapeHtmlAttr($element->getHtmlContainerId()) . '"' : '';
$fieldClass = 'field admin__field field-' . $block->escapeHtmlAttr($element->getId()) . ' '
    . $block->escapeHtmlAttr($element->getCssClass());
$fieldClass .= $element->getRequired() ? ' required' : '';
$fieldAttributes = $fieldId . ' class="' . $fieldClass . '" '
    . $block->getUiId('form-field', $block->escapeHtmlAttr($element->getId()));
?>
<div<?= /* @noEscape */ $fieldAttributes ?>>
    <?= $element->getLabelHtml() ?>
    <div class="control admin__field-control">
        <div class="rule-tree">
            <div class="rule-tree-wrapper">
                <?= $block->getInputHtml() ?>
            </div>
        </div>
    </div>
</div>

<?php $scriptString = <<<script
    require([
        "Magento_Rule/rules",
        "prototype"
    ], function(VarienRulesForm){
        window.{$block->escapeJs($block->getHtmlId())} = new VarienRulesForm('{$block->escapeJs($block->getHtmlId())}',
         '{$block->escapeUrl($block->getNewChildUrl())}');
    });
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
