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

/**
 * @var \Magento\Sales\Block\Adminhtml\Order\View\Info $block
 */

// @codingStandardsIgnoreFile

$order = $block->getOrder();

$orderAdminDate = $block->formatDate(
    $block->getOrderAdminDate($order->getCreatedAt()),
    \IntlDateFormatter::MEDIUM,
    true
);

$orderStoreDate = $block->formatDate(
    $order->getCreatedAt(),
    \IntlDateFormatter::MEDIUM,
    true,
    $block->getTimezoneForStore($order->getStore())
);
?>

<section class="admin__page-section order-view-account-information">
    <div class="admin__page-section-title">
        <span class="title"><?php echo $block->escapeHtml(__('Order & Account Information')) ?></span>
    </div>
    <div class="admin__page-section-content">
        <div class="admin__page-section-item order-information">
            <?php /* Order Information */ ?>
            <?php $confirmationEmailStatusMessage = $order->getEmailSent() ? __('The order confirmation email was sent') : __('The order confirmation email is not sent'); ?>
            <div class="admin__page-section-item-title">
                <span class="title">
                    <?php if ($block->getNoUseOrderLink()): ?>
                        <?php echo $block->escapeHtml(__('Order # %1', $order->getRealOrderId())) ?> (<span><?php echo $block->escapeHtml($confirmationEmailStatusMessage) ?></span>)
                    <?php else: ?>
                        <a href="<?php echo $block->escapeHtml($block->getViewUrl($order->getId())) ?>"><?php echo $block->escapeHtml(__('Order # %1', $order->getRealOrderId())) ?></a>
                        <span>(<?php echo $block->escapeHtml($confirmationEmailStatusMessage) ?>)</span>
                    <?php endif; ?>
                </span>
            </div>
            <div class="admin__page-section-item-content">
                <table class="admin__table-secondary order-information-table">
                <tr>
                    <th><?php echo $block->escapeHtml(__('Order Date')) ?></th>
                    <td><?php echo $block->escapeHtml($orderAdminDate) ?></td>
                </tr>
                <?php if ($orderAdminDate != $orderStoreDate):?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Order Date (%1)', $block->getTimezoneForStore($order->getStore()))) ?></th>
                        <td><?php echo $block->escapeHtml($orderStoreDate) ?></td>
                    </tr>
                <?php endif;?>
                <tr>
                    <th><?php echo $block->escapeHtml(__('Order Status')) ?></th>
                    <td><span id="order_status"><?php echo $block->escapeHtml($order->getStatusLabel()) ?></span></td>
                </tr>
                <?php echo $block->getChildHtml(); ?>
                <?php if ($block->isSingleStoreMode() == false):?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Purchased From')) ?></th>
                        <td><?php echo $block->escapeHtml($block->getOrderStoreName(), ['br']) ?></td>
                    </tr>
                <?php endif; ?>
                    <?php if ($order->getRelationChildId()): ?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Link to the New Order')) ?></th>
                        <td>
                            <a href="<?php echo $block->escapeHtml($block->getViewUrl($order->getRelationChildId())) ?>">
                                <?php echo $block->escapeHtml($order->getRelationChildRealId()) ?>
                            </a>
                        </td>
                    </tr>
                <?php endif; ?>
                <?php if ($order->getRelationParentId()): ?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Link to the Previous Order')) ?></th>
                        <td>
                            <a href="<?php echo $block->escapeHtml($block->getViewUrl($order->getRelationParentId())) ?>">
                                <?php echo $block->escapeHtml($order->getRelationParentRealId()) ?>
                            </a>
                        </td>
                    </tr>
                <?php endif; ?>
                <?php if ($order->getRemoteIp() && $block->shouldDisplayCustomerIp()): ?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Placed from IP')) ?></th>
                        <td><?php echo $block->escapeHtml($order->getRemoteIp()); echo $order->getXForwardedFor() ? ' (' . $block->escapeHtml($order->getXForwardedFor()) . ')' : ''; ?></td>
                    </tr>
                <?php endif; ?>
                <?php if ($order->getGlobalCurrencyCode() != $order->getBaseCurrencyCode()): ?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('%1 / %2 rate:', $order->getGlobalCurrencyCode(), $order->getBaseCurrencyCode())) ?></th>
                        <td><?php echo $block->escapeHtml($order->getBaseToGlobalRate()) ?></td>
                    </tr>
                <?php endif; ?>
                <?php if ($order->getBaseCurrencyCode() != $order->getOrderCurrencyCode()): ?>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('%1 / %2 rate:', $order->getOrderCurrencyCode(), $order->getBaseCurrencyCode())) ?></th>
                        <th><?php echo $block->escapeHtml($order->getBaseToOrderRate()) ?></th>
                    </tr>
                <?php endif; ?>
            </table>
            </div>
        </div>

        <div class="admin__page-section-item order-account-information">
            <?php /* Account Information */ ?>
            <div class="admin__page-section-item-title">
                <span class="title"><?php echo $block->escapeHtml(__('Account Information')) ?></span>
                <div class="actions">
                    <?php if ($customerUrl = $block->getCustomerViewUrl()) : ?>
                    <a href="<?php /* @noEscape */ echo $block->getCustomerViewUrl() ?>" target="_blank">
                        <?php echo $block->escapeHtml(__('Edit Customer')) ?>
                    </a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="admin__page-section-item-content">
                <table class="admin__table-secondary order-account-information-table">
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Customer Name')) ?></th>
                        <td>
                            <?php if ($customerUrl = $block->getCustomerViewUrl()) : ?>
                                <a href="<?php echo $block->escapeUrl($customerUrl) ?>" target="_blank">
                                    <span><?php echo $block->escapeHtml($order->getCustomerName()) ?></span>
                                </a>
                            <?php else: ?>
                                <?php echo $block->escapeHtml($order->getCustomerName()) ?>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <tr>
                        <th><?php echo $block->escapeHtml(__('Email')) ?></th>
                        <td><a href="mailto:<?php echo $block->escapeHtml($order->getCustomerEmail()) ?>"><?php echo $block->escapeHtml($order->getCustomerEmail()) ?></a></td>
                    </tr>
                    <?php if ($groupName = $block->getCustomerGroupName()) : ?>
                        <tr>
                            <th><?php echo $block->escapeHtml(__('Customer Group')) ?></th>
                            <td><?php echo $block->escapeHtml($groupName) ?></td>
                        </tr>
                    <?php endif; ?>
                    <?php foreach ($block->getCustomerAccountData() as $data):?>
                        <tr>
                            <th><?php echo $block->escapeHtml($data['label']) ?></th>
                            <td><?php echo $block->escapeHtml($data['value'], ['br']) ?></td>
                        </tr>
                    <?php endforeach;?>
                </table>
            </div>
        </div>
    </div>
</section>

<section class="admin__page-section order-addresses">
    <div class="admin__page-section-title">
        <span class="title"><?php echo $block->escapeHtml(__('Address Information')) ?></span>
    </div>
    <div class="admin__page-section-content">
        <div class="admin__page-section-item order-billing-address">
            <?php /* Billing Address */ ?>
            <div class="admin__page-section-item-title">
                <span class="title"><?php echo $block->escapeHtml(__('Billing Address')) ?></span>
                <div class="actions"><?php /* @noEscape */ echo $block->getAddressEditLink($order->getBillingAddress()); ?></div>
            </div>
            <address class="admin__page-section-item-content"><?php /* @noEscape */ echo $block->getFormattedAddress($order->getBillingAddress()); ?></address>
        </div>
        <?php if (!$block->getOrder()->getIsVirtual()): ?>
            <div class="admin__page-section-item order-shipping-address">
                <?php /* Shipping Address */ ?>
                <div class="admin__page-section-item-title">
                    <span class="title"><?php echo $block->escapeHtml(__('Shipping Address')) ?></span>
                    <div class="actions"><?php /* @noEscape */ echo $block->getAddressEditLink($order->getShippingAddress()); ?></div>
                </div>
                <address class="admin__page-section-item-content"><?php /* @noEscape */ echo $block->getFormattedAddress($order->getShippingAddress()); ?></address>
            </div>
        <?php endif; ?>
    </div>
</section>
