<?php
// @codingStandardsIgnoreFile

?>
<div class="cs-info-block | cs-dashboard__block | block-dashboard-orders">
    <?php $orders = $block->getOrders(); ?>

    <div class="cs-info-block__title cs-info-block__title--up | cs-title-block cs-title-block--bordered">
        <h2 class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light">
            <?php /* @escapeNotVerified */ echo __('Recent Orders') ?>
        </h2>
        <span class="cs-title-block__span">
            <?php if (sizeof($orders->getItems()) > 0): ?>
                <a class="cs-link" href="<?php /* @escapeNotVerified */ echo $block->getUrl('sales/order/history') ?>">
                    <span><?php /* @escapeNotVerified */ echo __('View All') ?></span>
                </a>
            <?php endif; ?>
        </span>
    </div>

    <div class="cs-info-block__content cs-info-block__content--up">
        <?php echo $block->getChildHtml()?>
        <?php if (sizeof($orders->getItems()) > 0): ?>
            <div class="cs-table cs-table--tablet-small">
                <table class="cs-table__body" id="my-orders-table">
                    <caption class="cs-visually-hidden"><?php /* @escapeNotVerified */ echo __('Recent Orders') ?></caption>
                    <thead class="cs-table__head">
                        <tr>
                            <th scope="col" class="cs-table__col-head id">
                                <?php /* @escapeNotVerified */ echo __('Order #') ?>
                            </th>
                            <th scope="col" class="cs-table__col-head date">
                                <?php /* @escapeNotVerified */ echo __('Date') ?>
                            </th>
                            <th scope="col" class="cs-table__col-head shipping">
                                <?php /* @escapeNotVerified */ echo __('Ship To') ?>
                            </th>
                            <th scope="col" class="cs-table__col-head total">
                                <?php /* @escapeNotVerified */ echo __('Order Total') ?>
                            </th>
                            <th scope="col" class="cs-table__col-head status">
                                <?php /* @escapeNotVerified */ echo __('Status') ?>
                            </th>
                            <th scope="col" class="cs-table__col-head actions">
                                <?php /* @escapeNotVerified */ echo __('Action') ?>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($orders as $order): ?>
                        <?php $shippingAddress = $order->getShippingAddress()  ?>
                        <tr>
                            <td data-th="<?php echo $block->escapeHtml(__('Order #')) ?>" class="cs-table__col id">
                                <?php /* @escapeNotVerified */ echo $order->getRealOrderId() ?>
                            </td>
                            <td data-th="<?php echo $block->escapeHtml(__('Date')) ?>" class="cs-table__col date">
                                <?php /* @escapeNotVerified */ echo $block->formatDate($order->getCreatedAt()) ?>
                            </td>
                            <td data-th="<?php echo $block->escapeHtml(__('Ship To')) ?>" class="cs-table__col shipping">
                                <?php echo $shippingAddress ? $block->escapeHtml($shippingAddress->getName()) : '&nbsp;' ?>
                            </td>
                            <td data-th="<?php echo $block->escapeHtml(__('Order Total')) ?>" class="cs-table__col total">
                                <?php /* @escapeNotVerified */ echo $order->formatPrice($order->getGrandTotal()) ?>
                            </td>
                            <td data-th="<?php echo $block->escapeHtml(__('Status')) ?>" class="cs-table__col status">
                                <?php /* @escapeNotVerified */ echo $order->getStatusLabel() ?>
                            </td>
                            <td data-th="<?php echo $block->escapeHtml(__('Actions')) ?>" class="cs-table__col cs-table__col--actions actions">
                                <a href="<?php /* @escapeNotVerified */ echo $block->getViewUrl($order) ?>" class="cs-link cs-link--separator">
                                    <?php /* @escapeNotVerified */ echo __('View Order') ?>
                                </a>
                                <?php if ($this->helper('Magento\Sales\Helper\Reorder')->canReorder($order->getEntityId())) : ?>
                                    <a href="<?php /* @escapeNotVerified */ echo $block->getReorderUrl($order) ?>" class="cs-link">
                                        <?php /* @escapeNotVerified */ echo __('Reorder') ?>
                                    </a>
                                <?php endif ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php else: ?>
            <div class="cs-info-block__line | cs-t-text cs-t-text--look_light">
                <?php /* @escapeNotVerified */ echo __('You have placed no orders.'); ?>
            </div>
        <?php endif; ?>
    </div>
</div>
