<?php $this->extend('block_searchable'); ?>

<?php $this->block('content'); ?>

<?php if ($this->noVoucher): ?>
<div class="box icon_left">
	{{icon::fe:error:circle left error}}
	<div>
		<?= $this->noVoucher ?>
	</div>
</div>
<?php else: ?>
<?php if ($this->messages): ?>
<div class="box messages">
	<?= $this->messages ?>
</div>
<?php endif; ?>
<div class="eq cf">
	<div class="details">
		<div class="box">
			<h2><?= $this->titleDetails ?></h2>
			<ul>
				<li><span class="label"><?= $this->lblVoucherNo ?>:</span><?= $this->voucherNo ?></li>
				<li><span class="label"><?= $this->lblRemainingVal ?>:</span><span class="highlight<?php if (!$this->isValid): ?> invalid<?php endif; ?>"><?= $this->fRemainingVal ?> &euro;</span></li>
				<li><span class="label"><?= $this->lblSerieNo ?>:</span><?= $this->serieNo ?></li>
				<li><span class="label"><?= $this->lblSerieDiscount ?>:</span><?= $this->serieDiscount ?> &euro;</li>
				<li><span class="label"><?= $this->lblValidFrom ?>:</span><?= $this->validFrom ?></li>
				<li><span class="label"><?= $this->lblValidTil ?>:</span><?= $this->validTil ?></li>
			</ul>
		</div>
	</div>

	<div class="deduct">
		<div class="box">
			<h2><?= $this->titleDeduct ?></h2>
			<?php if (!$this->isValid): ?>
				<?= $this->invalid ?>
			<?php else: ?>
			<form id="form_oxVoucherDetails_<?= $this->id ?>"<?php if ($this->action): ?> action="<?= $this->action ?>"<?php endif; ?> method="post">
				<div class="formbody">
					<input type="hidden" name="FORM_SUBMIT" value="eSM_oxVoucher_details">
					<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
					<input type="hidden" name="OXID" value="<?= $this->voucherOxid ?>">

					<div class="widget widget-text w20">
						<label for="voucher_deductValue_<?= $this->id ?>"><?= $this->valueLabel ?></label>
						<input type="number" name="voucher_deductValue" id="voucher_deductValue_<?= $this->id ?>" min="0.00" step="0.01" max="<?= $this->remainingVal ?>" value="0"/>
					</div>

					<div class="widget widget-checkbox w100 clr">
						<input type="checkbox" name="voucher_deductAll" id="voucher_deductAll_<?= $this->id ?>" value="1"/>
						<label for="voucher_deductAll_<?= $this->id ?>"><?= $this->maxValueLabel ?></label>
					</div>

					<div class="submit_container widget lblp button_block">
						<button type="submit" class="submit"><?= $this->submitLabel ?></button>
					</div>
				</div>
			</form>
			<?php endif; ?>
		</div>
	</div>
</div>
<script>
	$(document).ready(function(){
		$('#voucher_deductAll_<?= $this->id ?>').click(function(e) {
			if ($(this).is(':checked'))
			{
				$('#voucher_deductValue_<?= $this->id ?>').val('<?= $this->remainingVal ?>').attr('disabled',true);
			} else {
				$('#voucher_deductValue_<?= $this->id ?>').attr('disabled',false);
			}
		});
	});
</script>
<?php endif; ?>

<?php $this->endblock(); ?>