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

// @codingStandardsIgnoreFile

?>
<?php /* @var $block \Magento\Customer\Block\Adminhtml\Edit\Tab\Cart */ ?>
<?php if ($block->getCartHeader()): ?>
<div class="content-header skip-header">
    <table>
        <tr>
            <td style="width:50%;"><h4><?php /* @escapeNotVerified */ echo $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 /* @escapeNotVerified */ echo $listType ?>',
    {
        urlFetch: '<?php /* @escapeNotVerified */ echo $block->getUrl('customer/cart_product_composite_cart/configure', $params) ?>',
        urlConfirm: '<?php /* @escapeNotVerified */ echo $block->getUrl('customer/cart_product_composite_cart/update', $params) ?>'
    }
);

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