<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$this->setFrameMode(true);
?>
<script>
	$(function()
	{
		calculator(<?= CUtil::PhpToJSObject(array_merge(gettype($arParams) === "array" ? $arParams : [], gettype($arResult['CALCULATION']) === "array" ? $arResult['CALCULATION'] : [] )); ?>);
		<? if($arResult['PROPERTIES']['LEASING_AVAILABLE']['VALUE_XML_ID'] !== "YES"): ?>
			$("#FORM_FIELD_IS_IZT").val("Да");
		<? endif; ?>
	});
</script>
<style>
	main {overflow-x: unset;}
</style>
<section data-page="position">
<input type="hidden" id="FORM_FIELD_BRAND" value="<?= $arResult['PROPERTIES']['BRAND']['RELATED']['NAME']; ?>"/>
<input type="hidden" id="FORM_FIELD_MODEL" value="<?= $arResult['PROPERTIES']['MODEL']['RELATED']['NAME']; ?>"/>
<input type="hidden" id="FORM_FIELD_MODIFICATION" value="<?= $arResult['PROPERTIES']['MODIFICATION']['RELATED']['PROPERTIES']['TITLE']['VALUE']; ?>"/>
<input type="hidden" id="FORM_FIELD_PRICE" value=""/>
<input type="hidden" id="FORM_FIELD_PREPAID" value=""/>
<input type="hidden" id="FORM_FIELD_TERM" value=""/>
<input type="hidden" id="FORM_FIELD_REDEMPTION" value=""/>
	<div class="container">
		<ul class="breadcrumbs">
			<li></li>
		</ul>
		<div id="izt_<?= $arResult['ID']; ?>">
			<h1 class="car_position_title"><em><?= $arResult['PROPERTIES']['BRAND']['RELATED']['NAME']; ?> <?= $arResult['PROPERTIES']['MODEL']['RELATED']['NAME']; ?></em><br> <?= $arResult['PROPERTIES']['MODIFICATION']['VALUE']; ?> с пробегом<?= $arResult['PROPERTIES']['LEASING_AVAILABLE']['VALUE_XML_ID'] === "YES" ? " в лизинг " : " "; ?></h1>
			<div class="used_item_tags">
				<? if($arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 0): ?>
					<div class="used_item_tag used_item_discount">Скидка</div>
				<? endif; ?>
				<? if($arResult['PROPERTIES']['SPECIAL_OFFER']['VALUE_XML_ID'] === "YES"): ?>
					<div class="used_item_tag used_item_special_offer">Спецпредложение</div>
				<? endif; ?>
				<? if(!empty($arResult['PROPERTIES']['RESERVE_DATE']['VALUE'])): ?>
					<? if(strtotime($arParams['PROPERTIES']['RESERVE_DATE']['VALUE']) > time()): ?>
						<div class="used_item_tag used_item_reserve">Резерв до <?= date("d.m.Y", strtotime($arResult['PROPERTIES']['RESERVE_DATE']['VALUE'])); ?></div>
					<? endif; ?>
				<? endif; ?>
				<? if($arResult['PROPERTIES']['LEASING_AVAILABLE']['VALUE_XML_ID'] === "YES"): ?>
					<div class="used_item_tag used_item_leasing">Доступно в лизинг</div>
				<? endif; ?>
				<? if($arResult['PROPERTIES']['AFTER_ACCIDENT']['VALUE_XML_ID'] === "YES"): ?>
					<div class="used_item_tag used_item_accident">После ДТП</div>
				<? endif; ?>
			</div>
			<div class="model_container car_container_used">
				<div class="col">
					<input type="hidden" id="photos" value='<?= json_encode([
						"120" => $arResult['PHOTOS_120'], 
						"480" => $arResult['PHOTOS_480'], 
						"1080" => $arResult['PHOTOS_1080'], 
					]); ?>'/>
					<input type="hidden" id="contract" value="<?= $arResult['CODE']; ?>"/>
					<div id="photo_480_wrapper">
						<? if(count($arResult['PHOTOS_480']) > 0): ?>
							<img id="photo_480" data-p1080="<?= !empty($arResult['PHOTOS_1080'][0]) ? $arResult['PHOTOS_1080'][0] : ""; ?>" src="<?= !empty($arResult['PHOTOS_480'][0]) ? $arResult['PHOTOS_480'][0] : "/images/no_image_650.png"; ?>" alt="<?= $arResult['NAME']; ?>" width="100%" height="auto" style="opacity:0.0; display: block;">
							<? if(count($arResult['PHOTOS_480']) > 0): ?>
								<? foreach($arResult['PHOTOS_480'] AS $k => $photo_480): ?>
									<img 
										class="photo_480 photo_480_<?= $k; ?>" 
										data-p1080="<?= !empty($arResult['PHOTOS_1080'][$k]) ? $arResult['PHOTOS_1080'][$k] : ""; ?>" 
										src="<?= $photo_480; ?>" 
										alt="<?= $arResult['NAME']; ?>" 
										width="100%" height="auto" 
										style="<?= $k === 0 ? "opacity: 1.0;" : "opacity: 0.0;"; ?>
									">
								<? endforeach; ?>
								<? if(!isset($_GET['advertise']) && $arResult['PROPERTIES']['ADVERTISING_ERIR']['VALUE']): ?>
									<div class="advwrapper" style="position: absolute; right: 0px; top: 0px;">
										<div class="advblock adv_button_news">Реклама
											<div class="adv_content">ООО "ЛК Эволюция"</div>
											<div class="adv_content">ИНН 9724016636</div>
											<div class="adv_content">erid: <?= $arResult['PROPERTIES']['ADVERTISING_ERIR']['VALUE']; ?></div>
										</div>
									</div>
								<? endif; ?>
							<? endif; ?>
						<? else: ?>
							<img id="photo_480" src="/images/no_image_650.png" alt="<?= $arResult['NAME']; ?>" width="100%" height="auto">
						<? endif; ?>
					</div>
					<?/* style="display:none;" */?>
					<div class="scroll_images_wrapper">
						<div class="scroll_images_button scroll_images_button_left"></div>
						<div class="scroll_images" data-custom-scroll="true">
							<? foreach($arResult['PHOTOS_120'] AS $k => $thumb): ?>
								<div class="thumb" data-p480="<?= $arResult['PHOTOS_480'][$k]; ?>" data-p1080="<?= $arResult['PHOTOS_1080'][$k]; ?>" data-index="<?= $k; ?>">
									<img class="thumb_image" src="<?= $thumb; ?>" alt="<?= $arResult['NAME']; ?>">
								</div>
							<? endforeach; ?>
						</div>
						<div class="scroll_images_button scroll_images_button_right"></div>
					</div>
				</div>
				<div class="col">
					<div class="model_desc">
						<p><b>Артикул: <?= $arResult['CODE']; ?></b></p>
						<? if(!empty($arResult['PROPERTIES']['VIN']['VALUE'])): ?>
							<p><b>VIN: <?= str_repeat("*", 12).substr($arResult['PROPERTIES']['VIN']['VALUE'], 12, 5); ?></b></p>
						<? endif; ?>
						<p><b>Ключевые характеристики</b></p>
						<ul class="list-column">
							<li>Год выпуска: <?= $arResult['PROPERTIES']['YEAR']['VALUE']; ?></li>
							<? if(!empty($arResult['PROPERTIES']['MILEAGE']['VALUE'])): ?>
								<li>Пробег: <?= $arResult['PROPERTIES']['MILEAGE']['VALUE']; ?> км.</li>
							<? endif; ?>
							<? if(!empty($arResult['PROPERTIES']['ENGINE_HOURS']['VALUE'])): ?>
								<li>Моточасы: <?= $arResult['PROPERTIES']['ENGINE_HOURS']['VALUE']; ?></li>
							<? endif; ?>
							<? if(!empty($arResult['PROPERTIES']['ENGINE_POWER']['VALUE'])): ?>
								<li>Л.с.: <?= $arResult['PROPERTIES']['ENGINE_POWER']['VALUE']; ?></li>
							<? endif; ?>
							<li>Объем: <?= $arResult['PROPERTIES']['ENGINE_VOLUME']['VALUE']; ?></li>
							<li>Топливо: <?= $arResult['PROPERTIES']['ENGINE_FUEL']['VALUE']; ?></li>
							<? if(!empty($arResult['PROPERTIES']['PARKING_REGION']['VALUE'])): ?>
								<li>Регион размещения: <?= $arResult['PROPERTIES']['PARKING_REGION']['VALUE']; ?></li>
							<? endif; ?>
							<? if(!empty($arResult['PROPERTIES']['PARKING_CITY']['VALUE'])): ?>
								<li>Город размещения: <?= $arResult['PROPERTIES']['PARKING_CITY']['VALUE']; ?></li>
							<? endif; ?>
						</ul>
						<? if($arResult['ACTIVE'] == "Y"): ?>
							<div id="pdf_download">
								<div id="pdf_icon"></div>
								<p>Скачать PDF с коммерческим предложением</p>
							</div>
						<? endif; ?>
					</div>
					<div class="fixed_col" style="z-index: 10;">
						<div class="model_price">
							<? if($arResult['ACTIVE'] == "Y"): ?>
								<h2 style="margin:0; font-size:inherit; margin-bottom: 45px; line-height: 20px;">Приобретите <?= $arResult['PROPERTIES']['BRAND']['RELATED']['NAME']; ?> <?= $arResult['PROPERTIES']['MODEL']['RELATED']['NAME']; ?> на выгодных условиях</h2>
								<p style="<?= $arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 0 ? "margin-bottom: 20px;" : ""; ?>">
									Стоимость авто
									<span style="<?= $arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 0 ? "text-decoration: line-through;" : ""; ?> font-size: <?= ($arResult['PROPERTIES']['PRICE']['VALUE'] > 9999999) ? "30px" : "34px"; ?>"><?= number_format($arResult['PROPERTIES']['PRICE']['VALUE'], 0, ".", " "); ?> ₽</span>
								</p>
								<? if($arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 0): ?>
									<p>
										Стоимость авто со скидкой
										<span style="font-size: <?= ($arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 9999999) ? "30px" : "34px"; ?>"><?= number_format($arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'], 0, ".", " "); ?> ₽</span>
									</p>
								<? endif; ?>
								<button class="button button-blue" id="to_form_button">Купить</button>
								<? if($arResult['PROPERTIES']['LEASING_AVAILABLE']['VALUE_XML_ID'] === 'YES'): ?>
									<button class="button" id="to_calculator_button">Оформить в лизинг</button>
								<? endif; ?>
							<? else: ?>
								<p style="margin: 0; font-size: 24px; margin-bottom: 45px; line-height: 24px; color: #B7391A;">Автомобиль продан</p>
								<p style="font-weight: normal;">
									Посмотрите другие автомобили с пробегом в нашем каталоге
								</p>
								<button class="button" id="to_used_catalog_button">Посмотреть каталог</button>
							<? endif; ?>
						</div>
					</div>
				</div>
				<div class="aside_container">
					<aside>
						<ul class="aside_nav">
							<li>
								<a href="#" data-id="1" class="car_details_menu active"><h2 style="margin:0; font-size:inherit; font-weight:inherit;">Комплектация</h2></a>
							</li>
						</ul>
					</aside>
					<article>
						<div class=" active">
						</div>
						<div class="tab_content info_block info_column active" id="info_block_1">
							<?= $arResult['DETAIL_TEXT']; ?>
							<br/>
						</div>
					</article>
				</div>

				<div class="izt_calculator">
					<? if($arResult['ACTIVE'] == "Y" && $arResult['PROPERTIES']['LEASING_AVAILABLE']['VALUE_XML_ID'] === 'YES'): ?>
						<div id="calc">
							<div class="calc_body">
								<h2 class="section_title">Калькулятор расчета лизинга</h2>
								<div class="calc_settings">
									<div class="settings_box">
										<p>Стоимость авто</p>
										<p>
											<span id="calculator_car_price_value">
												<?= number_format($arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 0 ? $arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] : $arResult['PROPERTIES']['PRICE']['VALUE'], 0, ".", " "); ?> ₽
											</span>
											<output hidden></output>
										</p>
										<div class="price_custom" id="calculator_car_price_editor" style="display:none;">
											<input id="calculator_car_price_input" type="number" value="500000" min="500000" max="20000000" />
											<button id="calculator_car_price_save">Сохранить</button>
										</div>
										<div class="line">
											<input id="calculation_car_price" data-slider-name="car_price" type="range" min="<?= $arParams['CAR_PRICE_MIN']; ?>" max="<?= $arParams['CAR_PRICE_MAX']; ?>" step="100000" data-rangeslider value="<?= $arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] > 0 ? $arResult['PROPERTIES']['PRICE_WITH_DISCOUNT']['VALUE'] : $arResult['PROPERTIES']['PRICE']['VALUE']; ?>" />
										</div>
										<p class="min"><?= $arParams['CAR_PRICE_MIN'] / 1000000; ?> млн</p>
										<p class="max"><?= $arParams['CAR_PRICE_MAX'] / 1000000; ?> млн</p>
									</div>
									<div class="settings_box">
										<p>Первоначальный взнос</p>
										<p><output></output> %</p>
										<div class="line">
											<input id="calculation_initial_payment" data-slider-name="initial_payment" type="range" min="<?= $arParams['INITIAL_PAYMENT_MIN'];?>" max="<?= $arParams['INITIAL_PAYMENT_MAX'];?>" data-rangeslider value="<?= $arParams['initial_payment']; ?>" />
										</div>
										<p class="min"><?= $arParams['INITIAL_PAYMENT_MIN'];?>%</p>
										<p class="max"><?= $arParams['INITIAL_PAYMENT_MAX'];?>%</p>
									</div>
									<div class="settings_box">
										<p>Срок договора</p>
										<p><output></output> мес.</p>
										<div class="line">
											<input id="calculation_lease_period" data-slider-name="lease_period" type="range" min="<?= $arParams['LEASE_PERIOD_MIN']; ?>" max="<?= $arParams['LEASE_PERIOD_MAX']; ?>" data-rangeslider value="<?= $arParams['lease_period']; ?>" />
										</div>
										<p class="min"><?= $arParams['LEASE_PERIOD_MIN']; ?> мес.</p>
										<p class="max"><?= $arParams['LEASE_PERIOD_MAX']; ?> мес.</p>
									</div>
									<div class="settings_box">
										<p>Выкупной платеж</p>
										<p><output></output> %</p>
										<div class="line">
											<input id="calculation_redemption_payment" data-slider-name="redemption_payment" type="range" min="<?= $arParams['REDEMPTION_PAYMENT_MIN']; ?>" max="<?= $arParams['REDEMPTION_PAYMENT_MAX']; ?>" data-rangeslider value="<?= $arParams['redemption_payment']; ?>" />
										</div>
										<p class="min"><?= $arParams['REDEMPTION_PAYMENT_MIN']; ?>%</p>
										<p class="max"><?= $arParams['REDEMPTION_PAYMENT_MAX']; ?>%</p>
									</div>
								</div>
								<div class="calc_result">
									<div class="result_box bolder">
										<p>Ежемесячный платеж</p>
										<p><span id="calculator_monthly_payment_value"><?= number_format($arResult['CALCULATION']['monthly_payment'], 0, '.', ' '); ?></span> ₽</p>
									</div>
									<div class="result_box">
										<p>Экономия по налогу на прибыль (до)</p>
										<p><span id="calculator_tax_savings_value"><?= number_format($arResult['CALCULATION']['tax_savings'], 0, '.', ' '); ?></span> ₽</p>
									</div>			
									<div class="result_box">
										<p>НДС к возмещению из бюджета (до)</p>
										<p><span id="calculator_vat_reimbursement_value"><?= number_format($arResult['CALCULATION']['vat_reimbursement'], 0, '.', ' '); ?></span> ₽</p>
									</div>
									<div class="calc_footer">
										<a href="#order" class="button button-blue">Отправить заявку</a>
										<button class="button button-blue" id="calculation_reset">Сбросить к базовым значениям</button>
									</div>
								</div>
							</div>
						</div>
					<? endif; ?>
				</div>
				<? $APPLICATION->IncludeComponent(
					"evolution:catalog.other.positions",
					"",
					Array(
						"EXCEPT" => $arResult['ID'], 
						"BRAND_ID" => $arResult['PROPERTIES']['BRAND']['RELATED']['ID'], 
						"BRAND_CODE" => $arResult['PROPERTIES']['BRAND']['RELATED']['CODE'], 
						"BRAND_NAME" => $arResult['PROPERTIES']['BRAND']['RELATED']['NAME'], 
						"MODEL_ID" => $arResult['PROPERTIES']['MODEL']['RELATED']['ID'], 
						"MODEL_CODE" => $arResult['PROPERTIES']['MODEL']['RELATED']['CODE'], 
						"MODEL_NAME" => $arResult['PROPERTIES']['MODEL']['RELATED']['NAME'], 
					)
				); ?>
			</div>
		</div>
	</div>
	<div id="fullscreen">
		<div id="overlay"></div>
		<img id="overlay_image"/>
		<div id="overlay_left">
			<div id="overlay_left_icon"></div>
		</div>
		<div id="overlay_right">
			<div id="overlay_right_icon"></div>
		</div>
		<div id="overlay_close">
			<div id="overlay_close_icon"></div>
		</div>
	</div>
</section>