{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_POPUP}

{block name="body-declaration-class"}popup{/block}

{block name="template-head" append}
	{$JS->loadGroup("popup")}
	{$CSS->loadGroup("popup")}

	{$JS->loadGroup("inputs")}
	{$CSS->loadGroup("inputs")}

	{$JS->loadGroup("optionsBox.icons")}
	{$CSS->loadGroup("optionsBox.icons")}

	{$CSS->load("{asset path="_css/orderDetails.css"}")}

	{$objectExplorer->preloadJs($JS)}
	{$optionsView->preloadCss($CSS)}
	{$optionsView->preloadJs($JS)}
{/block}


{block name="operations"}
	<div class="optionsBox sectionInputs">{$optionsView->renderHtml()}</div>
{/block}

{block name="content"}
	{$objectExplorer->renderHtml()}

	<button type="button" class="back" onclick="window.location = MVC.appUrl('Orders/ImportedOrders/ServicesList','viewOrder', { 'idOrder': {$idOrder} })">{$_LANG['back']}</button>

	{if $orderHasCcNumbers and $userHasAccessToCcNumbers}
		{if !$revealCcNumbers}
			<button type="button" class="ccDetails" onclick="window.location = MVC.appUrl('Orders/ImportedOrders/ServicesList','orderDetails', { 'idOrder': {$idOrder}, 'revealCcNumbers': 1 })">{$_LANG['Orders']['ImportedOrders']['ServicesList']['orderDetails']['buttons']['revealCc']}</button>
		{else}
			<button type="button" class="ccDetails" onclick="window.location = MVC.appUrl('Orders/ImportedOrders/ServicesList','orderDetails', { 'idOrder': {$idOrder} })">{$_LANG['Orders']['ImportedOrders']['ServicesList']['orderDetails']['buttons']['hideCc']}</button>
		{/if}

	{/if}

{/block}

{block name="css"}
	<style>
		{$objectExplorer->preloadCss($CSS)}
		button.back {
			float:left;
		}
		button.ccDetails {
			float:right;
		}
	</style>
{/block}

{block name="js"}
	<script type='text/javascript'>
		{$objectExplorer->renderJs($JS)}
		{$optionsView->renderJs($JS)}

		(new _optionsBox({})).attach($$('.optionsBox.sectionInputs').first());


		function toggleCollapsedClass(fields, doCollapse)
		{

			$$(fields.map((c) => ".container-"+c).join(", ")).forEach((elm, i) => {
				if (doCollapse) {
					$(elm).addClassName('collapsed');
				}
				else {
					$(elm).removeClassName('collapsed');
				}
			});
		}

		function hideItinerary(doHide)
		{
			toggleCollapsedClass(['itinerary', 'departureDateTime', 'destinationDateTime', 'departurePlace', 'destinationPlace', 'supplier',], doHide);
		}

		function hidePassengers(doHide)
		{
			toggleCollapsedClass(['passengers', 'ticketNumbers', 'creditCard', 'ownerPassenger', ], doHide);
		}

		function hideOffers(doHide)
		{
			toggleCollapsedClass(['offers', 'taxCodes', ], doHide);
		}

		function hideLinkedServices(doHide)
		{
			toggleCollapsedClass(['linkedToService', ], doHide);
		}


		function highlightPrices(doHighlight)
		{
			let fields = [
				'servicePriceTotal', 'servicePriceVat',
				'taxTotal', 'taxVat',
				'commissionTotal',
				'discountTotal',
				'serviceFeeTotal',
			];

			$$(fields.map((c) => ".container-"+c).join(", ")).forEach((elm, i) => {
				if (doHighlight) {
					$(elm).addClassName('highlight-0');
				}
				else {
					$(elm).removeClassName('highlight-0');
				}
			});
		}


	</script>
{/block}
