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

// phpcs:disable Magento2.Templates.ThisInTemplate
// @codingStandardsIgnoreFile

/** @var \Magetop\Advancepreview\Block\ReWrites\HistoryCustom $block */
?>
<?php $_orders = $block->getOrders(); ?>
<?= $block->getChildHtml('info') ?>
<span>	&nbsp;</span>
<?php if ($_orders && count($_orders)) : ?>
    <div class="table-wrapper orders-history">
        <table class="data table table-order-items history" id="my-orders-table">
            <caption class="table-caption"><?= $block->escapeHtml(__('Orders')) ?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?= $block->escapeHtml(__('Order #')) ?></th>
                    <th scope="col" class="col date"><?= $block->escapeHtml(__('Date')) ?></th>
                    <?= $block->getChildHtml('extra.column.header') ?>
                    <th scope="col" class="col total"><?= $block->escapeHtml(__('Order total')) ?></th>
                    <th scope="col" class="col status"><?= $block->escapeHtml(__('Status')) ?></th>
                    <th scope="col" class="col status"><?= $block->escapeHtml(__('Project number and name')) ?></th>
                    <th scope="col" class="col status"><?= $block->escapeHtml(__('Delivery time')) ?></th>
                    <th scope="col" class="col actions"><?= $block->escapeHtml(__('Action')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($_orders as $_order) : ?>
                    <?php // $customPrice = $block->getCustomOrderTotal($_order); ?>
                    <?php
                        $customItemData = $block->getCustomProjectNameInOrder($_order);
                        $projectNames = $customItemData['project_name'];
                        $shippingDailies = $customItemData['shipping_daily'];
                        $customPrice = $customItemData['price_item'];
                        $statusItems = $customItemData['status'];
                    ?>

                    <tr>
                        <td data-th="<?= $block->escapeHtml(__('Order #')) ?>" class="col id"><?= $block->escapeHtml($_order->getRealOrderId()) ?></td>
                        <td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date"><?= /* @noEscape */ date('m/d/Y',strtotime($_order->getCreatedAt())) ?></td>
                        <?php $extra = $block->getChildBlock('extra.container'); ?>
                        <?php if ($extra) : ?>
                            <?php $extra->setOrder($_order); ?>
                            <?= $extra->getChildHtml() ?>
                        <?php endif; ?>
                        <td data-th="<?= $block->escapeHtml(__('Order Total')) ?>" class="col total"><?= /* @noEscape */ $_order->formatPrice($customPrice) ?></td>
                        <td data-th="<?= $block->escapeHtml(__('Status')) ?>" class="col status">
                            <?php if(count($statusItems)) : ?>
                                <?php foreach ($statusItems as $statusItem) : ?>
                                <span>
                                    <?php echo $statusItem['name'] ?> - <b><?php echo __($statusItem['status']) ?></b>
                                </span>
                                <br/>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </td>
                        <td data-th="<?= $block->escapeHtml(__('Project Names')) ?>" class="col status">
                            <?php if(count($projectNames)) : ?>
                                <?php foreach ($projectNames as $key => $projectName) : ?>
                                    <?php echo $projectName ?> <br/>
                                <?php endforeach ?>
                            <?php endif ?>

                        </td>
                        <td data-th="<?= $block->escapeHtml(__('Delivery time')) ?>" class="col status">
                        <?php if(count($shippingDailies)) : ?>
                            <?php foreach ($shippingDailies as $key => $shippingDaily) : ?>
                                <?php echo __('Delivery time:') ?> <?php echo $shippingDaily ?>  <?php echo __('days plus shipping') ?> <br/>
                            <?php endforeach ?>
                        <?php endif ?>
                        </td>
                        <td data-th="<?= $block->escapeHtml(__('Actions')) ?>" class="col actions">
                            <a href="<?= $block->escapeUrl($block->getViewUrl($_order)) ?>" class="action view">
                                <span><?= $block->escapeHtml(__('View Order')) ?></span>
                            </a>
							<div style="display: none;">
								<?php if ($this->helper(\Magento\Sales\Helper\Reorder::class)->canReorder($_order->getEntityId())) : ?>
									<a href="#" data-post='<?= /* @noEscape */
									$this->helper(\Magento\Framework\Data\Helper\PostHelper::class)
										->getPostData($block->getReorderUrl($_order))
									?>' class="action order">
										<span><?= $block->escapeHtml(__('Reorder')) ?></span>
									</a>
								<?php endif ?>
							</div>

                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getPagerHtml()) : ?>
        <div class="order-products-toolbar toolbar bottom"><?= $block->getPagerHtml() ?></div>
    <?php endif ?>
<?php else : ?>
    <div class="message info empty"><span><?= $block->escapeHtml($block->getEmptyOrdersMessage()) ?></span></div>
<?php endif ?>
