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

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

/* @var \Magento\Sales\Model\Order $_order */
$_order = $block->getOrder();
/** @var \Magento\GiftMessage\Helper\Message $giftMessageHelper */
$giftMessageHelper = $block->getData('giftMessageHelper');
?>
<div>
<?= $block->escapeHtml(__('Customer Name: %1', $_order->getCustomerFirstname() ? $_order->getCustomerName() :
    $_order->getBillingAddress()->getName())) ?><br />
<?= $block->escapeHtml(__('Purchased From: %1', $_order->getStore()->getGroup()->getName())) ?><br />
</div>
<table id="order-details" cellpadding="0" border="0" width="100%">
    <thead>
        <tr>
            <th align="left" bgcolor="#d9e5ee">Item</th>
            <th align="center" bgcolor="#d9e5ee">Qty</th>
            <th align="right" bgcolor="#d9e5ee" width="10%">Subtotal</th>
        </tr>
    </thead>

    <tbody>
<?php $i = 0; foreach ($_order->getAllItems() as $_item): $i++ ?>
        <tr id="item-<?= /* @noEscape */ $i ?>" <?= $i%2 ? 'bgcolor="#eeeded"' : '' ?>>
            <td align="left" valign="top"><strong><?= $block->escapeHtml($_item->getName()) ?></strong>
            <?php if ($_item->getGiftMessageId() &&
                $_giftMessage = $giftMessageHelper->getGiftMessage($_item->getGiftMessageId())): ?>
            <br /><strong><?= $block->escapeHtml(__('Gift Message')) ?></strong>
            <br /><?= $block->escapeHtml(__('From:')) ?> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
            <br /><?= $block->escapeHtml(__('To:')) ?> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
            <br /><?= $block->escapeHtml(__('Message:')) ?><br /> <?= $block->escapeHtml($_giftMessage->getMessage()) ?>
            <?php endif; ?>
            </td>
            <td align="center" valign="top"><?= (float) $_item->getQtyOrdered() ?></td>
            <td align="right" valign="top"><?= /* @noEscape */ $_order->formatPrice($_item->getRowTotal()) ?></td>
        </tr>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'tr#item-' . $i
    ) ?>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'tr#item-' . $i . ' td:nth-child(1)'
    ) ?>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'tr#item-' . $i . ' td:nth-child(2)'
    ) ?>
<?php endforeach; ?>
    </tbody>

    <tfoot>
    <?php if ($_order->getGiftMessageId() &&
        $_giftMessage = $giftMessageHelper->getGiftMessage($_order->getGiftMessageId())): ?>
        <tr id="gift-message">
            <td colspan="3" align="left">
            <strong><?= $block->escapeHtml(__('Gift Message')) ?></strong>
            <br /><?= $block->escapeHtml(__('From:')) ?> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
            <br /><?= $block->escapeHtml(__('To:')) ?> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
            <br /><?= $block->escapeHtml(__('Message:')) ?><br /> <?= $block->escapeHtml($_giftMessage->getMessage()) ?>
            </td>
        </tr>
        <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
            'padding:3px 9px',
            'table#order-details tr#gift-message td'
        ) ?>
    <?php endif; ?>
        <tr id="subtotal">
            <td colspan="2" align="right"><?= $block->escapeHtml(__('Subtotal')) ?></td>
            <td align="right"><?= /* @noEscape */ $_order->formatPrice($_order->getSubtotal()) ?></td>
        </tr>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'table#order-details tr#subtotal td:nth-child(0)'
    ) ?>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'table#order-details tr#subtotal td:nth-child(1)'
    ) ?>

        <?php if ($_order->getDiscountAmount() > 0): ?>
            <tr id="discount">
                <td colspan="2" align="right"><?= $block->escapeHtml((($_order->getCouponCode()) ?
                        __('Discount (%1)', $_order->getCouponCode()) : __('Discount'))) ?></td>
                <td align="right"><?= /* @noEscape */ $_order->formatPrice(0.00 - $_order->getDiscountAmount()) ?></td>
            </tr>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                'padding:3px 9px',
                'table#order-details tr#discount td:nth-child(0)'
            ) ?>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                'padding:3px 9px',
                'table#order-details tr#discount td:nth-child(1)'
            ) ?>
        <?php endif; ?>
        <?php if ($_order->getShippingAmount() || $_order->getShippingDescription()): ?>
            <tr id="shipping">
                <td colspan="2" align="right"><?= $block->escapeHtml(__('Shipping &amp; Handling')) ?></td>
                <td align="right"><?= /* @noEscape */ $_order->formatPrice($_order->getShippingAmount()) ?></td>
            </tr>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                'padding:3px 9px',
                'table#order-details tr#shipping td:nth-child(0)'
            ) ?>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                'padding:3px 9px',
                'table#order-details tr#shipping td:nth-child(1)'
            ) ?>
        <?php endif; ?>
        <?php if ($_order->getTaxAmount() > 0): ?>
            <tr id="tax">
                <td colspan="2" align="right"><?= $block->escapeHtml(__('Tax')) ?></td>
                <td align="right"><?= /* @noEscape */ $_order->formatPrice($_order->getTaxAmount()) ?></td>
            </tr>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                'padding:3px 9px',
                'table#order-details tr#tax td:nth-child(0)'
            ) ?>
            <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
                'padding:3px 9px',
                'table#order-details tr#tax td:nth-child(1)'
            ) ?>
        <?php endif; ?>
        <tr id="grand-total" bgcolor="#DEE5E8">
            <td colspan="2" align="right"><strong><?= $block->escapeHtml(__('Grand Total')) ?></strong></td>
            <td align="right"><strong><?= /* @noEscape */ $_order->formatPrice($_order->getGrandTotal())?></strong></td>
        </tr>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'table#order-details tr#grand-total td:nth-child(0)'
    ) ?>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'font-size: larger',
        'table#order-details tr#grand-total td:nth-child(0) strong'
    ) ?>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'padding:3px 9px',
        'table#order-details tr#grand-total td:nth-child(1)'
    ) ?>
    <?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
        'font-size: larger',
        'table#order-details tr#grand-total td:nth-child(1) strong'
    ) ?>
    </tfoot>
</table>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
    "border:1px solid #bebcb7; background:#f8f7f5;",
    'table#order-details'
) ?>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
    'padding:3px 9px',
    'table#order-details thead tr th:nth-child(0)'
) ?>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
    'padding:3px 9px',
    'table#order-details thead tr th:nth-child(1)'
) ?>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
    'padding:3px 9px',
    'table#order-details thead tr th:nth-child(2)'
) ?>
