<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();

if (isset($arParams["TEMPLATE_THEME"]) && !empty($arParams["TEMPLATE_THEME"]))
{
	$arAvailableThemes = array();
	$dir = trim(preg_replace("'[\\\\/]+'", "/", __DIR__."/themes/"));
	if (is_dir($dir) && $directory = opendir($dir))
	{
		while (($file = readdir($directory)) !== false)
		{
			if ($file != "." && $file != ".." && is_dir($dir.$file))
				$arAvailableThemes[] = $file;
		}
		closedir($directory);
	}

	if ($arParams["TEMPLATE_THEME"] == "site")
	{
		$solution = COption::GetOptionString("main", "wizard_solution", "", SITE_ID);
		if ($solution == "eshop")
		{
			$templateId = COption::GetOptionString("main", "wizard_template_id", "eshop_bootstrap", SITE_ID);
			$templateId = (preg_match("/^eshop_adapt/", $templateId)) ? "eshop_adapt" : $templateId;
			$theme = COption::GetOptionString("main", "wizard_".$templateId."_theme_id", "blue", SITE_ID);
			$arParams["TEMPLATE_THEME"] = (in_array($theme, $arAvailableThemes)) ? $theme : "blue";
		}
	}
	else
	{
		$arParams["TEMPLATE_THEME"] = (in_array($arParams["TEMPLATE_THEME"], $arAvailableThemes)) ? $arParams["TEMPLATE_THEME"] : "blue";
	}
}
else
{
	$arParams["TEMPLATE_THEME"] = "blue";
}

$arParams["FILTER_VIEW_MODE"] = (isset($arParams["FILTER_VIEW_MODE"]) && mb_strtoupper($arParams["FILTER_VIEW_MODE"]) == "HORIZONTAL") ? "HORIZONTAL" : "VERTICAL";
$arParams["POPUP_POSITION"] = (isset($arParams["POPUP_POSITION"]) && in_array($arParams["POPUP_POSITION"], array("left", "right"))) ? $arParams["POPUP_POSITION"] : "left";

//$itemsNew =["NAME"=>"Каталог","CODE"=>"TESTT", "DISPLAY_TYPE"=>"F","DISPLAY_EXPANDED"=>"Y", "VALUES"=>[]];
//$arFilter = array('IBLOCK_ID' => $arParams['IBLOCK_ID']);
//$rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'),$arFilter, true);
//
//while ($arSect = $rsSect->GetNext())
//{
//    // вывод содержимого для распределения по вложенности
//    $itemsNew["VALUES"][]=["CONTROL_NAME"=>"sect[]","HTML_VALUE"=>$arSect["ID"], "CONTROL_ID"=>"sectid".$arSect["ID"],"VALUE"=>$arSect["NAME"]]; // задаем новые значения в разделе "Разделы"
//}
//
//
//array_unshift($arResult["ITEMS"], $itemsNew); //добавляем раздел "Разделы в самое начало блоков"
