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

use Magento\CatalogWidget\Block\Product\Widget\Conditions;
use Magento\Framework\View\Helper\SecureHtmlRenderer;
use Magento\Framework\Escaper;

/** @var Conditions $block */
/** @var SecureHtmlRenderer $secureRenderer */
/** @var Escaper $escaper */

// phpcs:disable Generic.Files.LineLength.TooLong
?>
<?php
$element = $block->getElement();
$fieldId = $element->getHtmlContainerId() ?
    ' id="' . $escaper->escapeHtmlAttr($element->getHtmlContainerId()) . '"' : '';
$fieldClass = 'field admin__field field-' . $escaper->escapeHtmlAttr((string)$element->getId()) . ' '
    . $escaper->escapeHtmlAttr($element->getCssClass());
$fieldClass .= $element->getRequired() ? ' required' : '';
$fieldAttributes = $fieldId . ' class="' . $fieldClass . '" '
    . $block->getUiId('form-field', $escaper->escapeHtmlAttr((string)$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.{$escaper->escapeJs($block->getHtmlId())} = new VarienRulesForm(
        '{$escaper->escapeJs($block->getHtmlId())}',
         '{$escaper->escapeUrl($block->getNewChildUrl())}');
    });
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
