<?php
namespace Engine\Theme;

abstract class ThemeAbstract
{
	protected $listing = null;
	protected $popup = null;
	protected $path = null;
	protected $appLayoutPath = null;
	protected $url = null;

	public function __construct()
	{
		$this->path = APP_REAL_PATH."_themes/".THEME."/";
		$this->appLayoutPath = APP_REAL_PATH."_layout/".THEME."/";
		$this->url = APP_URL."_themes/".THEME."/";

		$this->defineSmartyPaths();
	}

	public function defineSmartyPaths()
	{
		$paths = $this->composeSmartyPaths([]);
		foreach ($paths as $k=>$v) {
			define($k, $v);
		}
	}

	public function composeSmartyPaths($paths)
	{
		return $paths;
	}

	public function getName()
	{
		return get_class($this);
	}

	public function getPath()
	{
		return $this->path;
	}

	public function getUrl()
	{
		return $this->url;
	}

	public function listing()
	{
		if ($this->listing===null) {
			$this->listing = $this->createListing();
		}

		return $this->listing;
	}

	abstract protected function createListing();

	public function popup()
	{
		if ($this->popup===null) {
			$this->popup = $this->createPopup();
		}

		return $this->popup;
	}

	abstract protected function createPopup();

	public function createMenu()
	{
		// the default handler doesn't create any menu
		return null;
	}


	public function generalSmartyAssign($smarty)
	{
	}

	public function getFlashMessageTemplate($templateClass)
	{
		return null;
	}

	public function stdModuleSmartyAssign(\App\Mvc\ViewAbstract $view)
	{
	}

	public function compatibilityWithTina2()
	{
		return null;
	}

	public function getResourceLoaderCfg()
	{
		/** config used by JSLoader to determine how file groups are configured **/
		// base
		$cfg['groups']['base']['js'] = [
			APP_REAL_PATH."_3parties/prototype/prototype.js",
			APP_REAL_PATH."_3parties/scriptaculous/scriptaculous.js",
			APP_REAL_PATH."_3parties/scriptaculous/effects.js",
			APP_REAL_PATH."_js/engine/dcsEngine.js",
			APP_REAL_PATH."_js/engine/utils.js",
			APP_REAL_PATH."_js/engine/mvc.js",

			APP_REAL_PATH."_3parties/overlib/overlib.js",
			APP_REAL_PATH."_js/engine/dcsOverlib.js",	// overlibAjax

			APP_REAL_PATH."_js/engine/dcsUI-mask.js",
			APP_REAL_PATH."_js/engine/dcsUI-loadingMask.js",

			APP_REAL_PATH."_js/engine/dcsUI-window.js",
			APP_REAL_PATH."_js/engine/dcsUI-messageBox.js",

			APP_REAL_PATH."_js/engine/tooltips/tooltip.js",
			APP_REAL_PATH."_js/engine/tooltips/tooltipsHandler.js",

			APP_REAL_PATH."_js/application/multiUsePopups.js",

			APP_REAL_PATH."_js/engine/alert/alert.js",
			APP_REAL_PATH."_js/engine/alert/alertConfirm.js",
			APP_REAL_PATH."_js/engine/alert/alertSimple.js",
			APP_REAL_PATH."_js/engine/alert/alertIframe.js",
		];

		if (SHOW_DEBUGS) {
			$cfg['groups']['base']['js'][] = APP_REAL_PATH."_js/engine/debug/designer.js";
		}

		$cfg['groups']['base']['calls'] = [
			"JSLoader_export_dateTimeFormat",
			"JSLoader_export_dcsValidatorTranslations",
			"JSLoader_export_dateTimeTranslations",

			"JSLoader_export_CFG",
			"JSLoader_export_nonMVC",
			"JSLoader_export_LANG",
		];
		$cfg['groups']['base']['css'] = [
			"_themes/".THEME."/group.base.css",
			"_css/index.css",
		];

		$cfg['groups']['auth']['js'] = [];
		$cfg['groups']['auth']['css'] = [];
		$cfg['groups']['auth']['calls'] = [];

		// listing
		$cfg['groups']['listing']['js'] = [
			APP_REAL_PATH."_js/engine/menu.js",
			APP_REAL_PATH."_js/engine/messageDiv.js",

			APP_REAL_PATH."_js/engine/listing/loadingMask.js",
			APP_REAL_PATH."_js/engine/listing/listing.js",
			APP_REAL_PATH."_js/engine/listing/selection.js",
			APP_REAL_PATH."_js/engine/listing/pagination.js",
			APP_REAL_PATH."_js/engine/listing/filters.js",

			APP_REAL_PATH."_js/engine/popups.js",

			APP_REAL_PATH."_js/engine/dcs-browserCache.js",
			APP_REAL_PATH."_3parties/date-functions/date-functions.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator.settings.js",	// remoteLoad depends on inputValidator.settings
		];
		$cfg['groups']['listing']['calls'] = [
			"JSLoader_export_listing",
		];
		$cfg['groups']['listing']['css'] = [
			"_themes/".THEME."/group.listing.css",
		];


		//
		$cfg['groups']['popup']['js'] = [
			APP_REAL_PATH."_js/engine/autoButtons.js",

			APP_REAL_PATH."_js/engine/popups.js",
			APP_REAL_PATH."_js/engine/popups2.js",
			APP_REAL_PATH."_js/engine/mvcPopup.js",
		];

		$cfg['groups']['remoteLoad']['js'] = [
			APP_REAL_PATH."_js/engine/remoteLoad/remoteLoad.js",
		];
		$cfg['groups']['remoteLoad']['css'] = [
			"_themes/".THEME."/group.remoteLoad.css",
			"_themes/".THEME."/group.optionsBox.icons.css",
		];

		$cfg['groups']['popup']['css'] = [
			"_themes/".THEME."/group.popup.css"
		];


		// effects
		$cfg['groups']['effects']['js'] = [
			APP_REAL_PATH."_3parties/scriptaculous/scriptaculous.js",
			APP_REAL_PATH."_3parties/scriptaculous/effects.js",
			APP_REAL_PATH."_3parties/scriptaculous/builder.js",
			APP_REAL_PATH."_3parties/scriptaculous/dragdrop.js",

			APP_REAL_PATH."_3parties/scriptaculous/controls.js",
			APP_REAL_PATH."_3parties/scriptaculous/slider.js",
		];


		// inputs
		$cfg['groups']['inputs']['js'] = [
			APP_REAL_PATH."_js/engine/dateTime.js",
			APP_REAL_PATH."_js/engine/dateValidation.js",
			APP_REAL_PATH."_js/engine/dcsValidator.js",
			APP_REAL_PATH."_js/engine/input.textareaExpander.js",
			APP_REAL_PATH."_js/application/forms.js",

			APP_REAL_PATH."_3parties/coolestCalendar/calendar.js",
			APP_REAL_PATH."_3parties/coolestCalendar/calendar-setup.js",
			APP_REAL_PATH."_3parties/coolestCalendar/calendar-en.js",

			//"_js/engine/formField/general.js",
			"__general.js__",
			APP_REAL_PATH."_js/engine/formField/generalClone.js",
			APP_REAL_PATH."_js/engine/formField/matrix.js",
			APP_REAL_PATH."_3parties/date-functions/date-functions.js",
			APP_REAL_PATH."_3parties/xregexp/xregexp.js",
			APP_REAL_PATH."_3parties/xregexp/xregexp-unicode-base.js",
			APP_REAL_PATH."_3parties/xregexp/xregexp-unicode-categories.js",

			APP_REAL_PATH."_js/engine/dcs-browserCache.js",
			#APP_REAL_PATH."_js/engine/inputAutocomplete.js",

			APP_REAL_PATH."_js/application/cloneFactory.js",
			APP_REAL_PATH."_js/engine/inputValidator/events.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator.settings.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator_messageAbstract.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator_messageCite.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator_messageCite_unified.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator_messageTooltip.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator-validators.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator-types.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator-validator-dateInterval.js",
			APP_REAL_PATH."_js/engine/inputValidator/inputValidator-validator-AJAX.js",
			APP_REAL_PATH."_js/application/inputValidator/inputValidator-validators.js",
			APP_REAL_PATH."_js/application/table-formNavigator.js",

			APP_REAL_PATH."_js/engine/formField-tree.js",
		];
		$cfg['groups']['inputs']['calls'] = [
			"JSLoader_export_autocomplete",
			"JSLoader_export_calendar",
			"JSLoader_export_validator",
		];

		$cfg['groups']['inputs']['css'] = [
			"_themes/".THEME."/group.inputs.css"
		];

		// fieldset
		$cfg['groups']['fieldset']['js'] = [
		];
		$cfg['groups']['fieldset']['css'] = [
			"_themes/".THEME."/styles/inputs/container-fieldset/fieldset.css"
		];


		// Menu
		$cfg['groups']['menu']['js'] = [
		];
		$cfg['groups']['menu']['css'] = [
			"_themes/".THEME."/group.menu.css"
		];


		// Filemanager
		$cfg['groups']['filemanager']['js'] = [
		];
		$cfg['groups']['filemanager']['css'] = [
			"_themes/".THEME."/group.filemanager.css"
		];


		// PluginReports
		$cfg['groups']['PluginReports']['js'] = [
			APP_REAL_PATH."_js/engine/pluginReports/reports.js",
		];
		$cfg['groups']['PluginReports']['css'] = [
			"_themes/".THEME."/group.PluginReports.css",
		];
		$cfg['groups']['PluginReportsConfig']['js'] = [
		];
		$cfg['groups']['PluginReportsConfig']['css'] = [
				"_themes/".THEME."/group.PluginReportsConfig.css",
		];

		// remoteHtmlView
		$cfg['groups']['remoteHtmlView']['js'] = [
			APP_REAL_PATH.'_js/engine/remoteHtmlView/RemoteHtmlView.js',
			APP_REAL_PATH.'_js/engine/remoteHtmlView/remoteHtmlViewHandler.js',
		];
		$cfg['groups']['remoteHtmlView']['calls'] = [];
		$cfg['groups']['remoteHtmlView']['css'] = [
			"_themes/".THEME."/group.remoteHtmlView.css",
		];

		// window
		$cfg['groups']['window']['js'] = [
			APP_REAL_PATH."_js/engine/listing/currentDatetime.js",
			APP_REAL_PATH."_js/engine/popups2.js",
		];
		$cfg['groups']['window']['calls'] = [];
		$cfg['groups']['window']['css'] = [
			"_themes/".THEME."/group.window.css",
			"_layout/".THEME."/group.window.css",
		];

		// window.form
		$cfg['groups']['window.form']['js'] = [];
		$cfg['groups']['window.form']['calls'] = [];
		$cfg['groups']['window.form']['css'] = [
			"_themes/".THEME."/group.window.form.css",
		];

		// popup.listing
		$cfg['groups']['popup.listing']['js'] = [];
		$cfg['groups']['popup.listingform']['calls'] = [];
		$cfg['groups']['popup.listing']['css'] = [
			"_themes/".THEME."/group.popup.listing.css",
		];

		// optionsBox.icons
		$cfg['groups']['optionsBox.icons']['js'] = [];
		$cfg['groups']['optionsBox.icons']['calls'] = [];
		$cfg['groups']['optionsBox.icons']['css'] = [
			"_themes/".THEME."/group.optionsBox.icons.css",
		];


		// iframe filtering
		$cfg['groups']['iframe.listing']['js'] = [
			APP_REAL_PATH."_js/engine/listing/filtersIframe.js",
		];
		$cfg['groups']['iframe.listing']['css'] = [
			"_themes/".THEME."/group.iframe.listing.css",
		];

		// formatters
		$cfg['groups']['formattersForDebugging']['js'] = [
			APP_REAL_PATH."_3parties/vkbeautify/vkbeautify.js",
		];
		$cfg['groups']['formattersForDebugging']['css'] = [
		];

		return $cfg;
	}
}