<?php /** @var \FiloBlu\Esb\Block\Adminhtml\Input\Ace $block */ ?>

<script>
    require([
        'jquery',
        'filoblu_esb_ace',
        'uiRegistry'
    ], function ($, acex, uiRegistry) {
        "use strict";
        setTimeout(function () {
            $('textarea').each(function() {

                console.log(acex);
                var textarea = $(this);
                var editDiv = $('<div>', {
                    position: 'absolute',
                    width: textarea.width(),
                    'class': textarea.attr('class')
                }).insertBefore(textarea);

                textarea.css('display', 'none');
                var editor = ace.edit(editDiv[0],

                    {
                       // theme: "ace/theme/tomorrow_night_blue",
                        mode: "ace/mode/json",
                        minLines: 35,
                        maxLines: 5000
                    }
                );
              //  editor.setOption('maxLines', 5000);
              //  editor.setOption('minLines', 25);
                var data = JSON.stringify(JSON.parse(textarea.val()), null, 4);
                editor.getSession().setValue(data);
               // editor.getSession().setMode("ace/mode/json");

                editor.getSession().on('change', function() {
                    uiRegistry.get('index = parameters').value(editor.getSession().getValue());

                })
            });
        }, 1000);

    });

</script>