<?php

declare(strict_types=1);

use Akeneo\Connector\Block\Adminhtml\System\Config\ExportPdf;

/** @var ExportPdf $block */
?>
<button id="config_export_pdf" title="<?= $block->escapeHtml(__('Export PDF')) ?>" type="button"
        class="action-default scalable">
    <?= $block->escapeHtml(__('Export PDF')) ?>
</button>

<script>
{
    requirejs([
        'jquery',
        'domReady!'
    ], function($) {
        $(document).on('click', '#config_export_pdf', function() {
            /** unfold all sections */
            $('.section-config').each(function (el) {
                if (!$(this).hasClass('active')) {
                    $(this).find('a').click();
                }
            });
            /** resize all multiselect to display all options */
            $('.multiselect').each(function (el) {
                let currentEl = $(this);
                let newHeight = currentEl.children().length * 29;
                currentEl.height(newHeight).parent().parent().height(newHeight);

                let options = currentEl.find(':selected');
                for (let i = 0; i < options.length; i++) {
                    $(options[i]).attr('selected', 'selected');
                }
            });

            window.print();
        });
    });
}
</script>
