<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
/**
 * API permissions tab template for integration activation dialog.
 */

/** @var \Magento\Integration\Block\Adminhtml\Integration\Activate\Permissions\Tab\Webapi $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<fieldset class="admin__fieldset form-inline entry-edit">
    <?php if ($block->isTreeEmpty()): ?>
        <p class="empty"><?= $block->escapeHtml(__('No permissions requested')) ?></p>
    <?php else: ?>
        <div class="field" data-role="tree-resources-container">
            <div class="control">
                <div id="resource-tree" class="tree x-tree" data-role="resource-tree"></div>
            </div>
        </div>
    <?php endif ?>
</fieldset>
<?php
if (!$block->isTreeEmpty()):
    $treeJson = /* @noEscape */ $block->getResourcesTreeJson();
    $selectedJson = /* @noEscape */ $block->getSelectedResourcesJson();
    $scriptString = <<<script
        require(["jquery", "Magento_User/js/roles-tree"], function($){
            $('[data-role="resource-tree"]').rolesTree({
                'treeInitData': {$treeJson},
                'checkboxVisible': false
            });
        });
script;
    ?>
    <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
<?php endif ?>
