<?php
use Magento\Framework\Json\Helper\Data;
?>
<?php /** @var Blackbird\MenuManager\Block\Adminhtml\NodeType\Subcategory $block */?>

<div class="admin__field field field-title" data-mage-init='{"menuManagerSubcategory":{"type":"subcategory"}}'>
    <div class="admin__field field field-subcategory" data-ui-id="subcategory-chooser">
        <label class="label admin__field-label" for="subcategory_id_chooser">Category with Subcategory </label>
        <div class="admin__field-control control">
            <input class="input-text admin__control-text" id="subcategory_id_chooser" type="text" name="subcategory-chooser-field" data-mage-init='{"menuManagerEditorRename":{"type":"entity_id"}}'/>
            <?= $block->getOpenChooserButtonHtml() ?>
            <?= $block->getApplyButtonHtml() ?>
        </div>
    </div>
</div>
<script>
    require([
        "jquery",
        "Blackbird_MenuManager/js/content"
    ], function(jQuery){
        jQuery(function ($) {
            var contentSet = $('[data-ui-id=subcategory-chooser]');
            contentSet.contentEdit(<?= $this->helper(Data::class)->jsonEncode(
                [
                    'formKey' => $block->getFormKey(),
                    'fieldId' => 'subcategory_id_chooser',
                    'fieldName' => 'subcategory-chooser-field',
                    'fieldType' => 'subcategory',
                    'urlSource' => $block->getUrlSource(),
                ]
            )?>);
        });
    });
</script>
<script>
    require([
        "Blackbird_MenuManager/js/chooser",
        "prototype"
    ], function(RelationChooserForm){
        window.subcategory_id_chooser = new RelationChooserForm('subcategory_id_chooser');
    });
</script>
