<?php
// @codingStandardsIgnoreFile

/** @var  $block \Magento\Shipping\Block\Items */ 

$order = $block->getOrder();
?>

<div class="cs-info-block | cs-dashboard__block">
    <div class="cs-info-block__buttons cs-info-block__buttons--space">
        <div class="cs-info-block__button">
            <?php if ($order->getTracksCollection()->count()) : ?>
                <?php echo $block->getChildHtml('track-all-link') ?>
            <?php endif; ?>
        </div>
        <div class="cs-info-block__button">
            <a
                href="<?php /* @escapeNotVerified */ echo $block->getPrintAllShipmentsUrl($order) ?>"
                onclick="this.target='_blank'"
                class="cs-button cs-button--size_300 cs-button--look_default"
            >
                <span class="cs-button__span"> <?php /* @escapeNotVerified */ echo __('Print All Shipments') ?></span>
                <svg class="cs-button__icon">
                    <use xlink:href="#arrow_next"></use>
                </svg>
            </a>
        </div>

    </div>
    <?php foreach ($order->getShipmentsCollection() as $shipment): ?>
        <div class="cs-info-block__title cs-info-block__title--space-top | cs-title-block cs-title-block--bordered">
            <div class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light">
                <?php /* @escapeNotVerified */ echo __('Shipment #') ?><?php /* @escapeNotVerified */ echo $shipment->getIncrementId(); ?>
            </div>
            <span class="cs-t-headline__span">
                <a 
                    href="<?php /* @escapeNotVerified */ echo $block->getPrintShipmentUrl($shipment) ?>"
                    onclick="this.target='_blank'"
                    class="cs-link"
                >
                    <?php /* @escapeNotVerified */ echo __('Print Shipment') ?>
                </a>
            </span>
            <span class="cs-t-headline__span">
               <a 
                   href="#"
                   data-mage-init='{"popupWindow": {"windowURL":"<?php /* @escapeNotVerified */ echo $this->helper('Magento\Shipping\Helper\Data')->getTrackingPopupUrlBySalesModel($shipment) ?>","windowName":"trackshipment","width":800,"height":600,"top":0,"left":0,"resizable":1,"scrollbars":1}}'
                   title="<?php /* @escapeNotVerified */ echo __('Track this shipment') ?>"
                   class="cs-link"
               >
                   <?php /* @escapeNotVerified */ echo __('Track this shipment') ?>
               </a>
            </span>

        </div>
        <?php $tracks = $shipment->getTracksCollection(); ?>
        <?php  if ($tracks->count()): ?>
            <dl class="order-tracking" id="my-tracking-table-<?php /* @escapeNotVerified */ echo $shipment->getId(); ?>">
                <dt class="tracking-title">
                    <?php /* @escapeNotVerified */ echo __('Tracking Number(s):') ?>
                </dt>
                <dd class="tracking-content">
                    <?php
                    $i = 1;
                    $size = $tracks->count();
                    foreach ($tracks as $track): ?>
                        <?php if ($track->isCustom()): ?>
                            <?php echo $block->escapeHtml($track->getNumber()) ?>
                        <?php else: ?>
                        <a
                            href="#"
                            data-mage-init='{"popupWindow": {"windowURL":"<?php /* @escapeNotVerified */ echo $this->helper('Magento\Shipping\Helper\Data')->getTrackingPopupUrlBySalesModel($track) ?>","windowName":"trackorder","width":800,"height":600,"left":0,"top":0,"resizable":1,"scrollbars":1}}'
                            class="action track"
                        >
                            <span><?php echo $block->escapeHtml($track->getNumber()) ?></span>
                        </a>
                        <?php endif; ?>

                        <?php if ($i != $size): ?>
                            ,
                        <?php endif; ?>

                        <?php $i++;
                    endforeach; ?>
                </dd>
            </dl>
        <?php  endif; ?>
        <div class="cs-table | order-items-shipment">
            <table class="cs-table__body | shipment" id="my-shipment-table-<?php /* @escapeNotVerified */ echo $shipment->getId(); ?>">
                <caption class="cs-visually-hidden"><?php /* @escapeNotVerified */ echo __('Items Shipped') ?></caption>
                <thead class="cs-table__head">
                <tr>
                    <th class="cs-table__col-head | name"><?php /* @escapeNotVerified */ echo __('Product Name') ?></th>
                    <th class="cs-table__col-head | sku"><?php /* @escapeNotVerified */ echo __('SKU') ?></th>
                    <th class="cs-table__col-head | qty"><?php /* @escapeNotVerified */ echo __('Qty Shipped') ?></th>
                </tr>
                </thead>
                <?php $items = $shipment->getAllItems(); ?>
                <?php $count = count($items) ?>
                <?php foreach ($items as $item): ?>
                    <?php if ($item->getOrderItem()->getParentItem()) {
                        continue;
                    } ?>
                    <tbody>
                    <?php echo $block->getItemHtml($item) ?>
                    </tbody>
                <?php endforeach; ?>
            </table>
        </div>
        <?php echo $block->getCommentsHtml($shipment)?>
    <?php endforeach; ?>

</div>

