<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
?>
<?php
/**
 * @var $block \Magento\Downloadable\Block\Customer\Products\ListProducts
 */
?>
<?php $_items = $block->getItems(); ?>
<?php if (count($_items)) : ?>
    <div class="table-wrapper downloadable-products">
        <table id="my-downloadable-products-table" class="data table table-downloadable-products">
            <caption class="table-caption"><?= $block->escapeHtml(__('Downloadable Products')) ?></caption>
            <thead>
                <tr>
                    <th scope="col" class="col id"><?= $block->escapeHtml(__('Order #')) ?></th>
                    <th scope="col" class="col date"><?= $block->escapeHtml(__('Date')) ?></th>
                    <th scope="col" class="col title"><?= $block->escapeHtml(__('Title')) ?></th>
                    <th scope="col" class="col status"><?= $block->escapeHtml(__('Status')) ?></th>
                    <th scope="col" class="col remaining"><?= $block->escapeHtml(__('Remaining Downloads')) ?></th>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($_items as $_item) : ?>
                <tr>
                    <td data-th="<?= $block->escapeHtmlAttr(__('Order #')) ?>" class="col id">
                        <a href="<?= $block->escapeUrl($block->getOrderViewUrl($_item->getPurchased()->getOrderId())) ?>"
                            title="<?= $block->escapeHtmlAttr(__('View Order')) ?>">
                            <?= $block->escapeHtml($_item->getPurchased()->getOrderIncrementId()) ?>
                        </a>
                    </td>
                    <td data-th="<?= $block->escapeHtmlAttr(__('Date')) ?>" class="col date"><?= $block->escapeHtml($block->formatDate($_item->getPurchased()->getCreatedAt())) ?></td>
                    <td data-th="<?= $block->escapeHtmlAttr(__('Title')) ?>" class="col title">
                        <strong class="product-name"><?= $block->escapeHtml($_item->getPurchased()->getProductName()) ?></strong>
                        <?php if ($_item->getStatus() == \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE) : ?>
                        <a href="<?= $block->escapeUrl($block->getDownloadUrl($_item)) ?>" title="<?= $block->escapeHtmlAttr(__('Start Download')) ?>" class="action download" <?= /* @noEscape */ $block->getIsOpenInNewWindow() ? 'onclick="this.target=\'_blank\'"' : '' ?>><?= $block->escapeHtml($_item->getLinkTitle()) ?></a>
                        <?php endif; ?>
                    </td>
                    <td data-th="<?= $block->escapeHtmlAttr(__('Status')) ?>" class="col status"><?= $block->escapeHtml(__(ucfirst($_item->getStatus()))) ?></td>
                    <td data-th="<?= $block->escapeHtmlAttr(__('Remaining Downloads')) ?>" class="col remaining"><?= $block->escapeHtml($block->getRemainingDownloads($_item)) ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php if ($block->getChildHtml('pager')) : ?>
        <div class="toolbar downloadable-products-toolbar bottom">
            <?= $block->getChildHtml('pager') ?>
        </div>
    <?php endif; ?>
<?php else : ?>
    <div class="message info empty"><span><?= $block->escapeHtml(__('You have not purchased any downloadable products yet.')) ?></span></div>
<?php endif; ?>

<div class="actions-toolbar">
    <div class="secondary">
        <a href="<?= $block->escapeUrl($block->getBackUrl()) ?>" class="action back">
            <span><?= $block->escapeHtml(__('Back')) ?></span>
        </a>
    </div>
</div>
