<?php
/**
 * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
 */
?>
<?php
    /** @var \Magento\Backend\Block\Template $block */
    /** @var \Temando\Shipping\ViewModel\Shipment\ShipmentDetails $viewModel */
    $viewModel = $block->getData('viewModel');
    /** @var \Temando\Shipping\Model\DocumentationInterface[] $documents */
    $documents = $viewModel->getDocumentation();
?>

<section class="admin__page-section">
    <div class="admin__page-section-title">
        <span class="title"><?= $block->escapeHtml(__('Documentation')) ?></span>
    </div>

    <div class="admin__table-wrapper shipment-documentation">
        <?php if (!empty($documents)) : ?>
            <?php if ($viewModel->isShipmentPaperless()) : ?>
                <div class="paperless">
                    <span class="tooltip"><span class="help"><span></span></span></span>
                    <span class="paperless-info">
                        <?php // @codingStandardsIgnoreLine ?>
                        <?= $block->escapeHtml(__('Paperless Shipment - Customs documentation has been submitted electronically and is not required to be physically attached to the shipment.')); ?>
                    </span>
                </div>
            <?php endif; ?>
            <table class="data-table admin__table-primary">
                <thead>
                    <tr class="headings">
                        <th class="col-name"><span><?= $block->escapeHtml(__('Document Name')); ?></span></th>
                        <th class="col-size"><span><?= $block->escapeHtml(__('Size')); ?></span></th>
                        <th class="col-file-type"><span><?= $block->escapeHtml(__('File Type')); ?></span></th>
                        <th class="col-action last"><span><?= $block->escapeHtml(__('Action')); ?></span></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($documents as $document) : ?>
                        <?php $documentName = $viewModel->getDocumentationDisplayName($document->getType()); ?>
                        <tr>
                            <td><?= $block->escapeHtml($documentName); ?></td>
                            <td><?= $block->escapeHtml($document->getSize()); ?></td>
                            <td><?= $block->escapeHtml($document->getMimeType()); ?></td>
                            <td>
                                <a href="<?= $block->escapeUrl($document->getUrl()); ?>" rel="noopener noreferrer"
                                   target="_blank"><?= $block->escapeHtml(__('Download')); ?></a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else : ?>
            <?= $block->escapeHtml(__('Documentation is not available.')) ?>
        <?php endif; ?>
    </div>
</section>
