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

/* @var $block \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */

$blockDataId = $block->getDataId();
$jsEscapedBlockDataId = $block->escapeJs($blockDataId);
?>
<div class="create-order-sidebar-block" id="sidebar_data_<?= $block->escapeHtmlAttr($blockDataId) ?>">
    <div class="head sidebar-title-block">
        <a href="#" class="action-refresh" title="<?= $block->escapeHtml(__('Refresh')) ?>">
            <span><?= $block->escapeHtml(__('Refresh')) ?></span>
        </a>
        <h5 class="create-order-sidebar-label">
            <?= $block->escapeHtml($block->getHeaderText()) ?>
            <span class="normal">(<?= $block->escapeHtml($block->getItemCount()) ?>)</span>
        </h5>
    </div>
    <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
        'onclick',
        "order.loadArea(
            'sidebar_" . $jsEscapedBlockDataId ."',
            'sidebar_data_" . $jsEscapedBlockDataId . "'
        );
        event.preventDefault();",
        'div#sidebar_data_'. $jsEscapedBlockDataId . ' a.action-refresh'
    ) ?>
    <div class="content">
        <div class="auto-scroll">
        <?php if ($block->getItemCount()): ?>
        <table class="admin__table-primary">
            <thead>
                <tr>
                    <th class="col-item"><?= $block->escapeHtml(__('Item')) ?></th>

                    <?php if ($block->canDisplayItemQty()): ?>
                        <th class="col-qty"><?= $block->escapeHtml(__('Qty')) ?></th>
                    <?php endif; ?>

                    <?php if ($block->canDisplayPrice()): ?>
                        <th class="col-price"><?= $block->escapeHtml(__('Price')) ?></th>
                    <?php endif; ?>

                    <?php if ($block->canRemoveItems()): ?>
                        <th class="col-remove">
                            <span title="<?= $block->escapeHtml(__('Remove')) ?>"
                                  class="icon icon-remove">
                                <span><?= $block->escapeHtml(__('Remove')) ?></span>
                            </span>
                        </th>
                    <?php endif; ?>

                    <th class="col-add">
                        <span title="<?= $block->escapeHtml(__('Add To Order')) ?>"
                              class="icon icon-add">
                            <span><?= $block->escapeHtml(__('Add To Order')) ?></span>
                        </span>
                    </th>
                </tr>
            </thead>

            <tbody>
                <?php foreach ($block->getItems() as $_item): ?>
                    <tr id="product-id-<?= (int) $block->getProductId($_item) ?>">
                        <td class="col-item"><?= $block->escapeHtml($_item->getName()) ?></td>

                        <?php if ($block->canDisplayItemQty()): ?>
                            <td class="col-qty">
                                <?= (float) $block->getItemQty($_item) ?>
                            </td>
                        <?php endif; ?>

                        <?php if ($block->canDisplayPrice()): ?>
                            <td class="col-price">
                                <?= /* @noEscape */ $block->getItemPrice($block->getProduct($_item)) ?>
                            </td>
                        <?php endif; ?>

                        <?php if ($block->canRemoveItems()): ?>
                            <td class="col-remove">
                                <div class="admin__field-option">
                                    <input id="sidebar-remove-<?=
                                    $block->escapeHtmlAttr($block->getSidebarStorageAction())
                                    ?>-<?= (int) $block->getItemId($_item) ?>"
                                           type="checkbox"
                                           class="admin__control-checkbox"
                                           name="sidebar[remove][<?= (int) $block->getItemId($_item) ?>]"
                                           value="<?= $block->escapeHtmlAttr($blockDataId) ?>"
                                           title="<?= $block->escapeHtml(__('Remove')) ?>" />
                                    <label class="admin__field-label"
                                           for="sidebar-remove-<?=
                                            $block->escapeHtmlAttr($block->getSidebarStorageAction())
                                            ?>-<?= (int) $block->getItemId($_item) ?>">
                                    </label>
                                </div>
                            </td>
                        <?php endif; ?>

                        <td class="col-add">
                            <div class="admin__field-option">
                                <?php if ($block->isConfigurationRequired($_item->getTypeId()) &&
                                    $blockDataId == 'wishlist'): ?>
                                    <a href="#"
                                       class="icon icon-configure"
                                       title="<?= $block->escapeHtml(__('Configure and Add to Order')) ?>">
                                        <span><?= $block->escapeHtml(__('Configure and Add to Order')) ?></span>
                                    </a>
                                    <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
                                        'onclick',
                                        "order.sidebarConfigureProduct('sidebar_wishlist', " .
                                        (int) $block->getProductId($_item) . ", " . (int) $block->getItemId($_item) .
                                        ");event.preventDefault();",
                                        'tr#product-id-' . (int) $block->getProductId($_item) .' a.icon.icon-configure'
                                    ) ?>
                                <?php elseif ($block->isConfigurationRequired($_item->getTypeId())): ?>
                                    <a href="#"
                                       class="icon icon-configure"
                                       title="<?= $block->escapeHtml(__('Configure and Add to Order')) ?>">
                                        <span><?= $block->escapeHtml(__('Configure and Add to Order')) ?></span>
                                    </a>
                                    <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
                                        'onclick',
                                        "order.sidebarConfigureProduct('sidebar', " .
                                        (int) $block->getProductId($_item) . ");event.preventDefault();",
                                        'tr#product-id-' . (int) $block->getProductId($_item) . ' a.icon.icon-configure'
                                    ) ?>
                                <?php else: ?>
                                    <input id="sidebar-<?= $block->escapeHtmlAttr($block->getSidebarStorageAction())
                                    ?>-<?= (int) $block->getIdentifierId($_item) ?>"
                                           type="checkbox"
                                           class="admin__control-checkbox"
                                           name="sidebar[<?= $block->escapeHtmlAttr($block->getSidebarStorageAction())
                                            ?>][<?= (int) $block->getIdentifierId($_item) ?>]"
                                           value="<?= $block->canDisplayItemQty() ? (float) $_item->getQty() : 1 ?>"
                                           title="<?= $block->escapeHtml(__('Add To Order')) ?>"/>
                                    <label class="admin__field-label"
                                           for="sidebar-<?= $block->escapeHtmlAttr($block->getSidebarStorageAction())
                                            ?>-<?= (int) $block->getIdentifierId($_item) ?>">
                                    </label>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <?php else: ?>
            <span class="no-items"><?= $block->escapeHtml(__('No items')) ?></span>
        <?php endif ?>
        </div>
        <?php if ($block->getItemCount() && $block->canRemoveItems()): ?>
            <?= $block->getChildHtml('empty_customer_cart_button') ?>
        <?php endif; ?>
    </div>
</div>
