<?php

if (
!defined(
'BASE_PATH'
)
) {

define(
'BASE_PATH',
dirname(__DIR__)
);

}
require_once BASE_PATH . '/app/helpers/helpers.php';
require_once BASE_PATH . '/app/helpers/rbac.php';
require_once BASE_PATH . '/app/helpers/view_compat.php';
require_once BASE_PATH . '/app/helpers/i18n.php';
require_once BASE_PATH . '/app/helpers/easychair_translate.php';
require_once BASE_PATH . '/app/helpers/permissions.php';
require_once BASE_PATH . '/app/helpers/conference_scope.php';
require_once BASE_PATH . '/app/helpers/access_scope.php';
require_once
BASE_PATH
. '/app/helpers/permission_guard.php';


if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

require BASE_PATH . '/app/helpers/tenant.php';
require BASE_PATH . '/app/helpers/conference_permissions.php';

spl_autoload_register(function ($class) {

    $prefix = 'App\\';
    $base_dir = BASE_PATH . '/app/';

    if (strncmp($prefix, $class, strlen($prefix)) !== 0) {
        return;
    }

    $relative_class = substr($class, strlen($prefix));
    $relative_class = str_replace('\\', '/', $relative_class);

    $parts = explode('/', $relative_class);
    $parts[0] = strtolower($parts[0]);
    $relative_class = implode('/', $parts);

    $file = $base_dir . $relative_class . '.php';
    
    error_log(
    "AUTOLOAD: {$class} => {$file} => " .
    (file_exists($file) ? 'FOUND' : 'MISSING')
);

    if (file_exists($file)) {
        require $file;
    }
});

require BASE_PATH . '/config/routes.php';

require_once BASE_PATH . '/app/helpers/toast.php';
