<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 *
 * Modifications by Hyvä Themes (https://hyva.io) under the terms of the AFL 3.0.
 */

use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Helper\SecureHtmlRenderer;
use Magento\Shipping\Block\Tracking\Popup;

/** @var Escaper $escaper */
/** @var Popup $block */
/** @var SecureHtmlRenderer $secureRenderer */

$results = $block->getTrackingInfo();
?>
<div class="page tracking container">
    <?php if (!empty($results)): ?>
        <?php foreach ($results as $shipId => $result): ?>
            <?php if ($shipId): ?>
                <div class="order subtitle caption">
                    <?= /* @noEscape */ $escaper->escapeHtml(__('Shipment #')) . $shipId ?>
                </div>
            <?php endif; ?>
            <?php if (!empty($result)): ?>
                <?php foreach ($result as $counter => $track): ?>
                    <div class="table-wrapper">
                        <?php
                            $shipmentBlockIdentifier = $shipId . '.' . $counter;
                            $block->addChild('shipping.tracking.details.' . $shipmentBlockIdentifier, Template::class, [
                                'track' => $track,
                                'template' => 'Magento_Shipping::tracking/details.phtml',
                                'storeSupportEmail' => $block->getStoreSupportEmail()
                            ]);
                        ?>
                        <?= /* @noEscape */ $block->getChildHtml('shipping.tracking.details.' .
                            $shipmentBlockIdentifier) ?>
                    </div>
                    <?php if (is_object($track) && !empty($track->getProgressdetail())): ?>
                        <?php
                            $block->addChild(
                                'shipping.tracking.progress.' . $shipmentBlockIdentifier,
                                Template::class,
                                ['track' => $track, 'template' => 'Magento_Shipping::tracking/progress.phtml']
                            );
                        ?>
                        <?= /* @noEscape */ $block->getChildHtml('shipping.tracking.progress.' .
                            $shipmentBlockIdentifier) ?>
                    <?php endif; ?>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="message info empty">
                    <div><?= $escaper->escapeHtml(__('There is no tracking available for this shipment.')) ?></div>
                </div>
            <?php endif; ?>
        <?php endforeach; ?>
    <?php else: ?>
        <div class="message info empty">
            <div><?= $escaper->escapeHtml(__('There is no tracking available.')) ?></div>
        </div>
    <?php endif; ?>
</div>