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

/** @var \Magento\Sales\Block\Adminhtml\Order\Create\Data $block */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<div class="page-create-order">
    <?php $scriptString = <<<script
    require(["Magento_Sales/order/create/form"], function(){
        order.setCurrencySymbol('{$block->escapeJs($block->getCurrencySymbol($block->getCurrentCurrencyCode()))}')
    });
script;
    ?>
    <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
    <div class="order-details<?php if ($block->getCustomerId()): ?> order-details-existing-customer<?php endif; ?>">

        <div id="order-additional_area" class="admin__page-section order-additional-area">
            <?= $block->getChildHtml('additional_area') ?>
        </div>
        <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
            'display:none',
            'div#order-additional_area'
        ) ?>

        <div id="order-search" class="admin__page-section order-search-items no-display">
            <?= $block->getChildHtml('search') ?>
        </div>
        <?= /* @noEscape */ $secureRenderer->renderTag(
            'script',
            [],
            "var elemOrderSearch = document.querySelector('div#order-search');
            if (elemOrderSearch) {
                elemOrderSearch.style.display = 'none';
                elemOrderSearch.classList.remove('no-display');
            }",
            false
        ) ?>

        <section id="order-items" class="admin__page-section order-items" data-mage-init='{"loader": {}}'>
            <?= $block->getChildHtml('items') ?>
        </section>

        <div id="order-errors" class="order-errors"><?= $block->getChildHtml('errors') ?></div>

        <section id="order-form_account" class="admin__page-section order-account-information">
            <?= $block->getChildHtml('form_account') ?>
        </section>

        <section id="order-addresses" class="admin__page-section order-addresses">
            <div class="admin__page-section-title">
                <span class="title"><?= $block->escapeHtml(__('Address Information')) ?></span>
            </div>
            <div class="admin__page-section-content">
                <div id="order-billing_address" class="admin__page-section-item order-billing-address">
                    <?= $block->getChildHtml('billing_address') ?>
                </div>
                <div id="order-shipping_address" class="admin__page-section-item order-shipping-address">
                    <?= $block->getChildHtml('shipping_address') ?>
                </div>
            </div>
        </section>

        <section id="order-methods" class="admin__page-section order-methods">
            <div class="admin__page-section-title">
                <span class="title"><?= $block->escapeHtml(__('Payment &amp; Shipping Information')) ?></span>
            </div>
            <div class="admin__page-section-content">
                <div id="order-billing_method" class="admin__page-section-item order-billing-method">
                    <?= $block->getChildHtml('billing_method') ?>
                </div>
                <div id="order-shipping_method" class="admin__page-section-item order-shipping-method">
                    <?= $block->getChildHtml('shipping_method') ?>
                </div>
            </div>
        </section>

        <?php if ($block->getChildBlock('card_validation')): ?>
        <section id="order-card_validation" class="admin__page-section order-card-validation">
            <?= $block->getChildHtml('card_validation') ?>
        </section>
        <?php endif; ?>

        <?= $block->getChildHtml('gift_options') ?>

        <section class="admin__page-section order-summary">
            <div class="admin__page-section-title">
                <span class="title"><?= $block->escapeHtml(__('Order Total')) ?></span>
            </div>
            <div class="admin__page-section-content">
                <fieldset class="admin__fieldset order-history" id="order-comment">
                    <legend class="admin__legend"><span><?= $block->escapeHtml(__('Order History')) ?></span></legend>
                    <br>
                    <?= $block->getChildHtml('comment') ?>
                </fieldset>
                <fieldset id="order-totals" class="admin__fieldset order-totals">
                    <?= $block->getChildHtml('totals') ?>
                </fieldset>
            </div>
        </section>
    </div>

    <?php if ($block->getCustomerId()): ?>
        <div class="order-sidebar">
            <div class="store-switcher order-currency">
                <label class="admin__field-label" for="currency_switcher">
                    <?= $block->escapeHtml(__('Order Currency:')) ?>
                </label>
                <select id="currency_switcher"
                        class="admin__control-select"
                        name="order[currency]">
                    <?php foreach ($block->getAvailableCurrencies() as $_code): ?>
                        <option value="<?= $block->escapeHtmlAttr($_code) ?>"
                            <?php if ($_code == $block->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?>
                                symbol="<?= $block->escapeHtmlAttr($block->getCurrencySymbol($_code)) ?>">
                            <?= $block->escapeHtml($block->getCurrencyName($_code)) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
                <?= /* @noEscape */ $secureRenderer->renderEventListenerAsTag(
                    'onchange',
                    "order.setCurrencyId(this.value);
                     order.setCurrencySymbol(this.options[this.selectedIndex].getAttribute('symbol'));",
                    'select#currency_switcher'
                ) ?>

            </div>
            <div class="customer-current-activity" id="order-sidebar">
                <?= $block->getChildHtml('sidebar') ?>
            </div>
        </div>
    <?php endif; ?>
</div>
