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

// @codingStandardsIgnoreFile

/* @var \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart $block */
?>
<?php if ($block->getCartHeader()): ?>
<div class="content-header skip-header">
    <table>
        <tr>
            <td style="width:50%;"><h4><?php echo $block->escapeHtml($block->getCartHeader()); ?></h4></td>
        </tr>
    </table>
</div>
<?php endif ?>
<?php echo $block->getGridParentHtml() ?>
<?php if ($block->canDisplayContainer()) : ?>
<?php
    $listType = $block->getJsObjectName();
?>
<script>
require([
    "Magento_Ui/js/modal/alert",
    "Magento_Ui/js/modal/confirm",
    "Magento_Catalog/catalog/product/composite/configure"
], function(alert, confirm){

<?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>cartControl = {
    reload: function (params) {
        if (!params) {
            params = {};
        }
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.reloadParams = params;
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.reload();
        <?php /* @escapeNotVerified */ echo $block->getJsObjectName() ?>.reloadParams = {};
    },

    configureItem: function (itemId) {
        productConfigure.setOnLoadIFrameCallback('<?php /* @escapeNotVerified */ echo $listType ?>', this.cbOnLoadIframe.bind(this));
        productConfigure.showItemConfiguration('<?php /* @escapeNotVerified */ echo $listType ?>', itemId);
        return false;
    },

    cbOnLoadIframe: function (response) {
        if (!response.ok) {
            return;
        }
        this.reload();
    },

    removeItem: function (itemId) {
        var self = this;

        if (!itemId) {
            alert({
                content: '<?php /* @escapeNotVerified */ echo $block->escapeJsQuote(__('No item specified.')) ?>'
            });

            return false;
        }

        confirm({
            content: '<?php /* @escapeNotVerified */ echo $block->escapeJsQuote(__('Are you sure you want to remove this item?')) ?>',
            actions: {
                confirm: function(){
                    self.reload({'delete':itemId});
                }
            }
        });
    }
};

<?php
$params = [
    'customer_id' => $block->getCustomerId(),
    'website_id' => $block->getWebsiteId(),
];
?>
productConfigure.addListType(
    '<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeJs($listType) ?>',
    {
        urlFetch: '<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeJs($block->escapeUrl($block->getUrl('customer/cart_product_composite_cart/configure', $params))) ?>',
        urlConfirm: '<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeJs($block->escapeUrl($block->getUrl('customer/cart_product_composite_cart/update', $params))) ?>'
    }
);

});
</script>
<?php endif ?>
<br />
