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

/** @var \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar $block */
?>
<div class="customer-current-activity-inner">
    <h4 class="customer-activity-title"><?= $block->escapeHtml(__('Customer\'s Activities')) ?></h4>
    <div class="create-order-sidebar-container">
    <?= $block->getChildHtml('top_button') ?>
    <?php foreach ($block->getLayout()->getChildBlocks($block->getNameInLayout()) as $_alias => $_child) : ?>
        <?php if ($_alias != 'top_button' && $_alias != 'bottom_button') : ?>
            <?php if ($block->canDisplay($_child)) : ?>
                <div class="order-sidebar-block" id="order-sidebar_<?= $block->escapeHtmlAttr($_alias) ?>">
                    <?= $block->getChildHtml($_alias) ?>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    <?php endforeach; ?>
    <?= $block->getChildHtml('bottom_button') ?>
    </div>
</div>
<script>
require([
    "prototype",
    "Magento_Catalog/catalog/product/composite/configure"
], function(){

    function addSidebarCompositeListType() {
        productConfigure.addListType('sidebar', {
            urlFetch: '<?= $block->escapeJs($block->escapeUrl($block->getUrl('sales/order_create/configureProductToAdd'))) ?>',
            urlConfirm: '<?= $block->escapeJs($block->escapeUrl($block->getUrl('sales/order_create/addConfigured'))) ?>'
        });
        productConfigure.addListType('sidebar_wishlist', {
            urlFetch: '<?= $block->escapeJs($block->escapeUrl($block->getUrl('customer/wishlist_product_composite_wishlist/configure'))) ?>',
            urlConfirm: '<?= $block->escapeJs($block->escapeUrl($block->getUrl('sales/order_create/addConfigured'))) ?>'
        });
    }

    if (typeof(sidebarListTypeWorkedOn) == 'undefined') {
        sidebarListTypeWorkedOn = false;
    }
    if (!sidebarListTypeWorkedOn) {
        if (typeof(productConfigure) == 'undefined') {
            Event.observe(window, 'load',  function(){
                setTimeout(addSidebarCompositeListType, 10);
            })
        } else {
            addSidebarCompositeListType();
        }
        sidebarListTypeWorkedOn = true;
    }

    window.addSidebarCompositeListType = addSidebarCompositeListType;
});
</script>
