<?php if ($this->textOnly): ?>
<?php ### THIS IS FOR TEXT ONLY EMAILS ### ?>
<?php foreach ($this->items as $item ): ?>
<?= $item['name'] ?><?php if (!empty($item['attributes'])): ?> (<?php $i=0; foreach ($item['attributes'] as $name => $value): ?><?= ($i++==0 ? '' : ', ').$this->attributeLabel($name) ?>: <?= $this->attributeValue($name, $value) ?><?php endforeach; ?>)<?php endif; ?>: <?= $item['quantity'] ?> x <?= $item['price'] ?> = <?= $item['total'] ?>

<?php endforeach; ?>
--------------------
<?= $GLOBALS['TL_LANG']['MSC']['subTotalLabel'] ?>: <?= $this->subtotal ?>

<?php foreach ($this->surcharges as $surcharge): ?>
<?= $surcharge['label'] ?>: <?= $surcharge['price'] ?> = <?= $surcharge['total_price'] ?>

<?php endforeach; ?>
<?= $GLOBALS['TL_LANG']['MSC']['grandTotalLabel'] ?>: <?= $this->total ?>
<?php else: ?>
<?php ### THIS IS HTML EMAILS AND EVERYTHING ELSE ### ?>
<?php if(!empty($this->actions)): ?>
<form id="<?= $this->formId ?>" method="post">
<div class="formbody">
<input type="hidden" name="FORM_SUBMIT" value="<?= $this->formSubmit ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
<?php endif; ?>

<?php if ($this->collection->hasErrors()): ?>
<p class="error"><?= implode('</p><p class="error">', $this->collection->getErrors()) ?></p>
<?php endif; ?>

<table class="productTable">
<tbody>
<?php foreach($this->items as $item): $i=0; ?>
    <tr class="<?= $item['rowClass'] ?>"><?php if(!$this->isNotification): ?>
        <td class="col_<?= $i++ ?> col_first image"><?= $this->getGallery('images', $item['item'])->generateMainImage() ?></td><?php endif; ?>
        <td class="col_<?= $i++ ?><?php if($this->isNotification) echo ' col_first'; ?> name">
            <?php if($this->linkProducts && $item['href']): ?>
            <a href="<?php echo $item['href']; ?>">
            <?php endif; ?>

                <strong>
                    <?php echo $item['name']; ?>
                    <?= ($item['product']->zusatz ? '{{iso_custom_product::zusatz:'.$item['product']->id.'}}' : '') ?>
                    <?= ($item['product']->jahrgang ? $item['product']->jahrgang : '') ?>
                </strong>

            <?php if($this->linkProducts && $item['href']): ?>
            </a>
            <?php endif; ?>

            <?php if ($item['product']->qualitaet || $item['product']->geschmack || $item['product']->flascheninhalt): ?>
            <br />
            <?= ($item['product']->qualitaet ? '{{iso_custom_product::qualitaet:'.$item['product']->id.'}}' : '') ?>
            <?= ($item['product']->geschmack ? '{{iso_custom_product::geschmack:'.$item['product']->id.'}}' : '') ?>
            <?= rtrim(rtrim(\System::getFormattedNumber($item['product']->flascheninhalt,3),'0'),',') ?> l
            <?php endif; ?>
            <?php if ($item['product']->weinlinie): ?>
                <br /><span class="small">{{isolabel::attr_weinlinie}}: {{iso_custom_product::weinlinie:<?= $item['product']->id ?>}}</span>
            <?php endif; ?>
            <?php if ($item['sku']): ?><br /><span class="small" itemprop="sku"><span class="label">{{isolabel::attr_sku}}:</span> <?php echo $item['sku']; ?></span><?php endif; ?>
            <ul>
              <?php if(!empty($item['attributes'])): ?>
                <?php foreach($item['attributes'] as $name => $value): ?>
                <li><strong><?= $this->attributeLabel($name) ?>:</strong> <?= $this->attributeValue($name, $value, ['html'=>true, 'item'=>$item['item']]) ?></li>
                <?php endforeach; ?>
              <?php endif; ?>
            </ul>
        </td>
        <td class="col_<?= $i++ ?> quantity">
        <?php if($this->isEditable): ?>
            <input name="quantity[<?= $item['id'] ?>]" type="text" class="text" value="<?= $item['quantity'] ?>" maxlength="10">
        <?php else: ?>
            <?= $item['quantity'] ?> x
        <?php endif; ?>
        </td>
        <td class="col_<?= $i++ ?> price"><?= $item['price'] ?></td>
        <td class="col_<?= $i++; if(!$this->isEditable && $this->total_tax_ids < 2) echo ' col_last' ?> price total"><?= $item['total'] ?></td><?php if ($this->total_tax_ids > 1): ?>
        <td class="col_<?= $i++; if(!$this->isEditable) echo ' col_last' ?> tax"><?= $item['tax_id'] ?></td><?php endif; if($this->isEditable): ?>
        <td class="col_<?= $i++ ?> col_last actions">
            <?php if ($item['edit_href'] ?? null): ?><a href="<?= $item['edit_href'] ?>" class="edit" title="<?= $item['edit_title'] ?>"><?= $item['edit_link'] ?></a><?php endif; ?>
            <a href="<?= $item['remove_href'] ?>" class="remove" title="<?= $item['remove_title'] ?>"><?= $item['remove_link'] ?></a>
        </td><?php endif; ?>
    </tr><?php if($item['item']->hasErrors()): ?>
    <tr class="<?= $item['rowClass'] ?>">
        <td colspan="<?= $i ?>"><p class="error"><?= implode('</p><p class="error">', $item['item']->getErrors()) ?></p></td>
    </tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
<?php
// we know this is invalid markup but nor Outlook nor TCPDF support putting <thead> or <tfoot> in front of <tbody>
// you're free to adjust the template to your needs
?>
<tfoot>
    <tr class="foot_0 foot_first subtotal">
        <?php $i=0; if(!$this->isNotification): ?>
        <td class="col_<?= $i++ ?> col_first">&nbsp;</td><?php endif; ?>
        <td class="col_<?= $i++; $i++ ?><?php if($this->isNotification) echo ' col_first'; ?> name" colspan="2"><?= $GLOBALS['TL_LANG']['MSC']['subTotalLabel'] ?></td>
        <td class="col_<?= $i++ ?> price">&nbsp;</td>
        <td class="col_<?= $i++; if(!$this->isEditable && $this->total_tax_ids < 2) echo ' col_last' ?> price total"><?= $this->subtotal ?></td><?php if ($this->total_tax_ids > 1): ?>
        <td class="col_<?= $i++; if(!$this->isEditable) echo ' col_last' ?> tax">&nbsp;</td><?php endif; if($this->isEditable): ?>
        <td class="col_<?= $i++ ?> col_last remove">&nbsp;</td><?php endif; ?>
    </tr>
    <?php foreach ($this->surcharges as $surcharge): $i=0; ?>
    <tr class="<?= $surcharge['rowClass'] ?>">
        <?php if(!$this->isNotification): ?>
        <td class="col_<?= $i++ ?> col_first">&nbsp;</td><?php endif; ?>
        <td class="col_<?= $i++; $i++ ?><?php if($this->isNotification) echo ' col_first'; ?> name" colspan="2"><?= $surcharge['label'] ?></td>
        <td class="col_<?= $i++ ?> price"><?= $surcharge['price'] ?></td>
        <td class="col_<?= $i++; if(!$this->isEditable && $this->total_tax_ids < 2) echo ' col_last' ?> price total"><?= $surcharge['total_price'] ?></td><?php if ($this->total_tax_ids > 1): ?>
        <td class="col_<?= $i++; if(!$this->isEditable) echo ' col_last' ?> tax"><?= $surcharge['tax_id'] ?></td><?php endif; if($this->isEditable): ?>
        <td class="col_<?= $i++ ?> col_last remove">&nbsp;</td><?php endif; ?>
    </tr>
    <?php endforeach; ?>
    <tr class="foot_<?= count($this->surcharges)+1 ?> foot_last total">
        <?php $i=0; if(!$this->isNotification): ?>
        <td class="col_<?= $i++ ?> col_first">&nbsp;</td><?php endif; ?>
        <td class="col_<?= $i++; $i++ ?><?php if($this->isNotification) echo ' col_first' ?> name" colspan="2"><?= $GLOBALS['TL_LANG']['MSC']['grandTotalLabel'] ?></td>
        <td class="col_<?= $i++ ?> price">&nbsp;</td>
        <td class="col_<?= $i++; if(!$this->isEditable && $this->total_tax_ids < 2) echo ' col_last' ?> price total"><?= $this->total ?></td><?php if ($this->total_tax_ids > 1): ?>
        <td class="col_<?= $i++; if(!$this->isEditable) echo ' col_last' ?> tax">&nbsp;</td><?php endif; if($this->isEditable): ?>
        <td class="col_<?= $i++ ?> col_last remove">&nbsp;</td><?php endif; ?>
    </tr>
</tfoot>
</table>

<?php if(!empty($this->actions)): ?>
</div>
<div class="submit_container">
<?php foreach($this->actions as $action) echo $action->generate($this->collection) . ' iso_collection_table.html5'; ?>
</div>
</form>
<?php endif; ?>

<?php if (!$this->isEditable && !empty($this->downloads) && \is_array($this->downloads)): ?>
<div class="downloads">
<h2><?= $GLOBALS['TL_LANG']['MSC']['downloadsLabel'] ?></h2>
<ul>
<?php foreach ($this->downloads as $download): ?>
<li class="<?= $download['downloadable'] ? 'available' : 'unavailable' ?>"><?php if ($download['downloadable'] && $download['href']): ?><a href="<?= $download['href'] ?>"><?php endif; echo $download['title']; if ($download['downloadable'] && $download['href']): ?></a><?php endif; echo $download['remaining']; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>

<?php endif; ?>