<script type="text/javascript">
	$(document).ready(function() {
		$(".cart-remove").click(function() {
			var input = $(".amount" + $(this).attr('product')).val(0);
			$("#form").submit();
		});
	});
</script>

<div class="container cart">
	<{include file="add_financial_products.html"}>
</div>

<form action="" method="post" id="form">

	<div class="container cart checkoutStep" data-step="Basket">
		<{if $get.s == "NaN"}>
			<div class="alert alert-danger">En eller flere varer er ikke på lager</div>
		<{/if}>

		<div class="row cart-header">
			<div class="col-md-2 d-none d-md-block">Vare</div>
			<div class="col-md-3 d-none d-md-block">Navn</div>
			<div class="col-md-2 d-none d-md-block">Pris</div>
			<div class="col-md-2 d-none d-md-block">Antal</div>
			<div class="col-md-2 d-none d-md-block">Total</div>
			<div class="col-md-1 d-none d-md-block"></div>
		</div>

		<{section name="i" loop=$basket}>
			<{assign var="attributes" value=$basket[i].attributes}>
			<{assign var="product" value=$basket[i].product}>

			<{if $attributes.0.value_id}>
				<{assign var="image" value=$product->getImage($attributes.0.value_id)}>
			<{else}>
				<{assign var="image" value=$product->getImage()}>
			<{/if}>

			<div class="row">
				<div class="col-4 col-md-2 p-4">
					<a href="<{$product->getRemoteUrl()|escape}>">
						<{if $image}>
							<img src="<{$image->getSrc(80, 80, 'box')}>">
						<{else}>
							<img src="images/small_product_list_08.jpg" alt=""/>
						<{/if}>
					</a>
				</div>
				<div class="col-8 col-md-3 p-4"
					class="productEntity"
						data-product_name="<{$product->getName()}>"
						data-product_id="<{$product->getProductId()}>"
						data-product_price="<{$product->getRealPrice()}>"
						<{if $product->getBrand()}>
							data-product_brand="<{$product->getBrandName()}>"
						<{/if}>
						<{if $product->getMainCategory()}>
							data-product_category="<{$product->getMainCategoryName()}>"
						<{elseif $product->getCategory()}>
							data-product_category="<{$product->getCategoryName()}>"
						<{/if}>
						data-productlist_position="<{$smarty.section.products.iteration}>"
						data-productlist_name="cart"
						<{if $product->hasVariant()}>
							<{assign var="variant" value=$product->getVariant()}>
							data-product_variant="<{$variant->getName()}>"
						<{/if}>
						>
					<a href="<{$product->getRemoteUrl()|escape}>"><{$product->getName()|escape}></a>

					<{if $attributes}>
						<dl>
							<{foreach from=$attributes item=a}>
								<dd><{$a.name|escape}>: <{$a.value|escape}></d>
							<{/foreach}>
						</dl>
					<{/if}>

					<{if $campaign_matches && in_array($product->getProductId(), $campaign_matches)}>
						<dl>
							<small>Kampagnerabat</small>
						</dl>
					<{/if}>

					<{if $products_matches && in_array($product->getProductId(), $products_matches)}>
						<dl>
							<small>Rabat</small>
						</dl>
					<{/if}>

					<{if $product->hasBundleProducts()}>
						<{assign var="bundle" value=$product->getBundleProducts()}>
						<{if $bundle}>
							<dl>
								<{section name="j" loop=$bundle}>
									<{assign var="b_product" value=$bundle[j]}>
									<{assign var="id" value=$b_product->getProductId()}>
									<dd>
										<{$b_product->getName()|escape}>
										<{if $basket[i].bundle.$id}>
											(<{$basket[i].bundle.$id.val}>)
										<{/if}>
									</dd>
								<{/section}>
							</dl>
						<{/if}>
					<{/if}>
				</div>

				<div class="col-4 col-md-2 p-4">
					<div class="d-block d-md-none"><strong>Stykpris:</strong></div>
					<{if $product->getBulkDiscountOver() && $basket[i].amount > $product->getBulkDiscountOver()}>
						<{$product->getBulkDiscountPrice()|number_format:2:",":"."}> <{$webshop->getCurrency()}>
					<{else}>
						<{$product->getRealPrice(1, $basket[i].attributes)|number_format:2:",":"."}> <{$webshop->getCurrency()}>
					<{/if}>
				</div>
				<div class="col-4 col-md-2 p-4">
					<div class="d-block d-md-none"><strong>Antal:</strong></div>

					<{if !$basket[i].in_stock && !$product->getAllowNegativeStock()}>
						<div class="alert alert-danger">
							Ikke nok på lager
							<{if $product->getDeliveryTimeNotInStock()}>
								<div>Leveringstid: <{$product->getDeliveryTimeNotInStock()|escape}></div>
							<{/if}>
						</div>
					<{/if}>

					<input type='number' <{if $product->getPackage()}>step="<{$product->getPackage()}>"<{/if}> min="0" id="amount<{$basket[i].id}>" name="amount[<{$basket[i].id}>]" value="<{$basket[i].amount}>" class="amount<{$basket[i].id}> qty-number" style="box-sizing: content-box !important" />
				</div>
				<div class="col-4 col-md-2 p-4">
					<div class="d-block d-md-none"><strong>Total:</strong></div>
					<{$product->getRealPrice($basket[i].amount, $basket[i].attributes)|number_format:2:",":"."}> <{$webshop->getCurrency()}>
				</div>
				<div class="col-6 col-md-1 p-4 d-none d-md-block">
					<a href="#" product="<{$basket[i].id}>" class="cart-remove"></a>
				</div>
			</div>

		<{/section}>

		<{if $webshop->hasLoyaltyProgram() && $customer}>
			<div class="row cart-header">
				<{if $customer->getActivePoints()}>
					<h3>Betal med point</h3>
					<div class="col-12 col-md-12 apply-coupon">
						<p>
							Du har optjent <{$customer->getActivePoints()|number_format:0:",":"."}> point.
							<{if $customer->getPointsAvailable()}>
								Du kan bruge <{$customer->getPointsAvailable()|number_format:0:",":"."}> point på denne ordre.
								<a style="float:none; display:inline" href="#" onclick="$('#use_points').val(<{$customer->getPointsAvailable()}>); return false;">Brug alle.</a>
							<{else}>
								Du har ingen optjente point du kan bruge på denne ordre.
							<{/if}>
						</p>

						<input type="number" placeholder="Hvor mange point vil du bruge?" name="use_points" id="use_points" value="<{$use_points}>" min="0" max="<{$customer->getPointsAvailable()}>"/>

						<br style="clear:both;"><br>

						<p><small style="font-weight:normal;">
							Du optjener <{$webshop->getLoyaltyProgramBasePoints()|number_format:0:",":"."}> point hver gang du køber for 1 <{$webshop->getCurrency()}>.
							Når du betaler med point svarer <{$webshop->getLoyaltyProgramBaseCost()|number_format:0:",":"."}> point til 1 <{$webshop->getCurrency()}>.
						</small></p>

						<p><small style="font-weight:normal;">
							Du optjener <{$earns|number_format:0:",":"."}> point på denne ordre.
						</small></p>

					</div>
				<{else}>

					<p><small style="font-weight:normal;">
						Du optjener <{$earns|number_format:0:",":"."}> point på denne ordre.
					</small></p>

				<{/if}>

			</div>

			<br>
		<{/if}>

		<div class="row cart-header">
			<div class="col-12 col-md-8 apply-coupon">
				<{if $get.wrong_voucher}>
					<div class="alert alert-danger">Ugyldig rabatkort</div>
				<{/if}>
				<input type="text" placeholder="Evt. rabatkode" name="voucher" value="<{$voucher|escape}>"/>
			</div>
			<div class="col-12 col-md-4 text-center">
				<input class="btn btn-secondary gray button" type="submit" name="opdate" value="Opdater"/>
				<input class="btn btn-primary button color proceed checkoutStepProceed" type="submit" name="next" value="Fortsæt"/>
				<{include file="mobilepay_checkout.html" show="button"}>
			</div>
		</div>

		<div class="margin-top-40 col-4">
			<{include file="paypal_checkout.html"}>
		</div>

		<div class="margin-top-40">

		<{assign var="countries" value=$webshop->getCountries()}>
		<{if $countries}>
			<div class="my-2"></div>
			<section class="variables">
				<div class="form-group">
					<h3 class="headline">Leveres til:</h3>
					<span class="line"></span>
					<div class="clearfix"></div>
					<div class="row">
						<div class="col">
							<select class="form-control" name="del_country_id" onchange="$('#form').submit();">
								<{section name="i" loop=$countries}>
									<option value="<{$countries[i]->getCountryId()}>" <{if $session_del.country_id == $countries[i]->getCountryId()}>selected="selected"<{/if}>><{$countries[i]->getName()|escape}></option>
								<{/section}>
							</select>
						</div>
						<div class="col col-4 col-lg-4 text-right">
							<input class="btn btn-secondary gray button" type="submit" name="opdate" value="Opdater"/>
						</div>
					</div>
				</div>
			</section>
		<{/if}>

		<h3 class="headline">Samlede pris</h3>
		<span class="line"></span>
		<div class="clearfix"></div>

		<table class="cart-table margin-top-5">
			<tr>
				<th>Subtotal</th>
				<td><strong><{$price|number_format:2:",":"."}> <{$webshop->getCurrency()}></strong></td>
			</tr>

			<{if $voucher}>
				<tr>
					<th>Rabat</th>
					<td>
						<{if $voucher->getPercentDiscount()}>
							<div><{$voucher->getPercentDiscount()}> %</div>
						<{/if}>

						<{if $voucher->getPriceDiscount()}>
							<div><{$voucher->getPriceDiscount()}> <{$webshop->getCurrency()}></div>
						<{/if}>

						<{if $voucher->getFreeShipping()}>
							<div>Gratis fragt.</div>
						<{/if}>

						<{if $voucher_discount && !$voucher->getPriceDiscount()}>
							<div>Du sparer <{$voucher_discount|number_format:2:",":"."}> <{$webshop->getCurrency()}>.</div>
						<{/if}>

					</td>
				</tr>
			<{/if}>

			<{if $campaign_ids && $campaign_discount}>
				<tr>
					<th>Kampagnerabat</th>
					<td>
						<{$campaign_discount|number_format:2:",":"."}> <{$webshop->getCurrency()}>
					</td>
				</tr>
			<{/if}>

			<tr>
				<th>Levering</th>
				<td><{$shipping_price|number_format:2:",":"."}> <{$webshop->getCurrency()}></td>
			</tr>

			<{if $point_discount}>
				<tr>
					<th>Brug af point</th>
					<td>-<{$point_discount|number_format:2:",":"."}> <{$webshop->getCurrency()}> (<{$use_points|number_format:0:",":"."}> point)</td>
				</tr>
			<{/if}>

			<tr>
				<th>Total</th>
				<td><strong><{$total_price|number_format:2:",":"."}> <{$webshop->getCurrency()}></strong></td>
			</tr>

			<tr>
				<th>Heraf moms</th>
				<td><{$vat|number_format:2:",":"."}> <{$webshop->getCurrency()}></td>
			</tr>
		</table>
	</div>

	<div class="margin-top-40"></div>

	<div class="notification notice">
	  <div class="row text-center">
		<div class="col-12 col-md-6 col-lg-4 col py-4">
			Din kurv (<{$total_amount}> vare<{if $total_amount != 1}>r<{/if}>):
			<span class="highlight color">
				<{$total_price|number_format:2:",":"."}> <{$webshop->getCurrency()}>
			</span>
		</div>
		<div class="col-12 col-md-6 col-lg-2 py-1 align-self-end text-center">
			<form action="" method="post">
				<input class="button rounded huge color proceed checkoutStepProceed" type="submit" name="next" value="Fortsæt"/>
			</form>
		</div>
	</div>

	<{include file="mobilepay_checkout.html" show="form"}>

	<div class="margin-top-40"></div>

</form>

<{include file="klaviyo_add_to_cart.html" product=$product type="basket"}>