<?php

/**
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
 * @copyright Aimeos (aimeos.org), 2019
 */

$enc = $this->encoder();

$detailTarget = $this->config( 'client/html/catalog/detail/url/target' );
$detailController = $this->config( 'client/html/catalog/detail/url/controller', 'catalog' );
$detailAction = $this->config( 'client/html/catalog/detail/url/action', 'detail' );
$detailConfig = $this->config( 'client/html/catalog/detail/url/config', ['absoluteUri' => 1] );

$pricetype = 'price:default';
$pricefmt = $this->translate( 'controller/jobs', $pricetype );
/// Price format with price value (%1$s) and currency (%2$s)
$priceFormat = $pricefmt !== 'price:default' ? $pricefmt : $this->translate( 'controller/jobs', '%1$s %2$s' );

?>
<mjml>
	<mj-head>
		<mj-title><?= $enc->html( $this->translate( 'controller/jobs', 'Your watched products' ), $enc::TRUST ) ?></mj-title>
		<mj-style>
			<?= $this->get( 'css' ) ?>
		</mj-style>
	</mj-head>
	<mj-body css-class="aimeos">
		<mj-section>
			<mj-column>
				<mj-image css-class="logo" src="<?= $this->get( 'logo' ) ?>" align="center"/>
			</mj-column>
		</mj-section>
		<mj-section>
			<mj-column>
				<mj-text css-class="email-common-salutation">
					<?= $enc->html( $this->get( 'emailIntro' ) ) ?>
				</mj-text>
				<mj-text css-class="email-common-intro">
					<?= $enc->html( nl2br( $this->translate( 'controller/jobs', 'One or more products you are watching have been updated.' ) ), $enc::TRUST ) ?>
				</mj-text>
			</mj-column>
		</mj-section>
		<mj-section css-class="common-summary-detail common-summary">
			<mj-column>
				<mj-table css-class="basket">
					<thead>
						<th css-class="header" colspan="3"><?= $enc->html( $this->translate( 'controller/jobs', 'Details' ), $enc::TRUST ) ?></th>
					</thead>
					<tbody class="details">
						<?php foreach( $this->get( 'products' ) as $product ) : $price = $product->get( 'price' ) ?>
							<tr class="product">
								<td class="image">
									<?php $media = $product->getRefItems( 'media', 'default', 'default' ) ?>
									<?php if( ( $image = $media->first() ) !== null && ( $url = $image->getPreview() ) != '' ) : ?>
										<img class="product-image" src="<?= $enc->attr( $this->content( $url ) ) ?>" height="150" />
									<?php endif ?>
								</td>
								<td class="name">
									<?php $params = array_merge( $this->get( 'urlparams' ), ['currency' => $price->getCurrencyId(), 'd_name' => $product->getName( 'url' ), 'd_prodid' => $product->getId(), 'd_pos' => ''] ) ?>
									<a class="product-name" href="<?= $enc->attr( $this->url( ( $product->getTarget() ?: $detailTarget ), $detailController, $detailAction, $params, [], $detailConfig ) ) ?>">
										<?= $enc->html( $product->getName(), $enc::TRUST ) ?>
									</a>
								</td>
								<td class="price">
									<?= sprintf( $priceFormat, $this->number( $price->getValue(), $price->getPrecision() ), $this->translate( 'currency', $price->getCurrencyId() ) ) ?>
								</td>
							</tr>
						<?php endforeach ?>
					</tbody>
				</mj-table>
			</mj-column>
		</mj-section>
		<mj-section css-class="email-common-outro">
			<mj-column>
				<mj-text>
					<?= $enc->html( nl2br( $this->translate( 'controller/jobs', 'If you have any questions, please reply to this e-mail' ) ), $enc::TRUST ) ?>
				</mj-text>
			</mj-column>
		</mj-section>
	</mj-body>
</mjml>
