<?php
ob_start();
error_reporting(E_ALL);
require_once(__DIR__ . '/php/vendor/autoload.php');

if (!class_exists('Console', false)) {
    class_alias('Xberg\Debug\Console', 'Console');
}

if (!class_exists('Profiler', false)) {
	class_alias('Xberg\Debug\Profiler', 'Profiler');
}

$ds = DIRECTORY_SEPARATOR;

$root = __DIR__; //realpath(dirname($_SERVER['SCRIPT_FILENAME']));
$baseUrl = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] : '') .
	(isset($_SERVER['DOCUMENT_ROOT']) ? str_replace($ds, '/', substr($root, strlen(rtrim($_SERVER['DOCUMENT_ROOT'], $ds)))) : '')
;

// \Console::log('root', $root);
// \Console::log('baseUrl', $baseUrl);

$options = [];
$srcPath = realpath(__DIR__ . '/../src/bin');
$options['roots'] = [
	'index'=> $root,
];
$options['urls'] = [
	'index' => $baseUrl,
];
if ($srcPath !== FALSE && file_exists($srcPath)) {
	// we are on a dev environment, we use different dirs for accounts and sessions
	// that are not going to be copied on the server
	$options['roots'] = array_merge($options['roots'], [
		'accounts' => $root . $ds . 'kirby-dev-accounts',
		'sessions' => $root . $ds . 'kirby-dev-sessions'
	]);
}

// $options['site'] = new \Cdlx\Kirby\Site();

$kirby = new Cdlx\Kirby\Kirby($options);

echo $kirby->render();
