<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php /* @var $block \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\AbstractSidebar */ ?>
<div class="create-order-sidebar-block" id="sidebar_data_<?= $block->escapeHtmlAttr($block->getDataId()) ?>">
    <div class="head sidebar-title-block">
        <a href="#" class="action-refresh"
           title="<?= $block->escapeHtml(__('Refresh')) ?>"
           onclick="order.loadArea('sidebar_<?= $block->escapeJs($block->getDataId()) ?>', 'sidebar_data_<?= $block->escapeJs($block->getDataId()) ?>');return false;">
            <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>
    <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>
                        <td class="col-item"><?= $block->escapeHtml($_item->getName()) ?></td>

                        <?php if ($block->canDisplayItemQty()) : ?>
                            <td class="col-qty">
                                <?= (int) $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($block->getDataId()) ?>"
                                           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()) && $block->getDataId() == 'wishlist') : ?>
                                    <a href="#"
                                       class="icon icon-configure"
                                       title="<?= $block->escapeHtml(__('Configure and Add to Order')) ?>"
                                       onclick="order.sidebarConfigureProduct('sidebar_wishlist', <?= (int) $block->getProductId($_item) ?>, <?= (int) $block->getItemId($_item) ?>); return false;">
                                        <span><?= $block->escapeHtml(__('Configure and Add to Order')) ?></span>
                                    </a>
                                <?php elseif ($block->isConfigurationRequired($_item->getTypeId())) : ?>
                                    <a href="#"
                                       class="icon icon-configure"
                                       title="<?= $block->escapeHtml(__('Configure and Add to Order')) ?>"
                                       onclick="order.sidebarConfigureProduct('sidebar', <?= (int) $block->getProductId($_item) ?>); return false;">
                                        <span><?= $block->escapeHtml(__('Configure and Add to Order')) ?></span>
                                    </a>
                                <?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() ? (int) $_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>
