<?php

if(!defined('STYLESWISS_ADMIN_MODE')) {
	define('STYLESWISS_ADMIN_MODE', false);
}

if (is_link(dirname($_SERVER['SCRIPT_FILENAME']))) {
	require_once dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))) . '/config/config.inc.php';

} else {
	require_once __DIR__ . '/../../config/config.inc.php';
}

define('STYLESWISS_AJAX_REQUEST', true);

@session_start();
require_once __DIR__ . '/require.php';

use SwissStyle\Route\Controller\Route as RouteController;

// Hack for FullStyler logic
if (!isset($_REQUEST['params']) && !empty($_REQUEST)) {
	$_REQUEST['params'] = [];
	foreach ($_REQUEST as $r_key => $r_val) {
		if (in_array($r_key, ['subject','action'])) { continue; }
		$_REQUEST['params'][$r_key] = $r_val;
	}
} elseif (!isset($_REQUEST['params']) && empty($_REQUEST)) {
	$_REQUEST['params'] = [];
}
// end hack

echo json_encode(RouteController::route($_REQUEST['subject'], $_REQUEST['action'], $_REQUEST['params']));
