<?php

declare(strict_types=1);

spl_autoload_register(static function (string $class): void {
    $baseDir = __DIR__ . DIRECTORY_SEPARATOR;

    $candidates = [
        $baseDir . 'components' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'components' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'components' . DIRECTORY_SEPARATOR . 'staff' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'components' . DIRECTORY_SEPARATOR . 'customer' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'pages' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'services' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'context' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'utils' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . 'hooks' . DIRECTORY_SEPARATOR . $class . '.php',
        $baseDir . $class . '.php',
    ];

    foreach ($candidates as $file) {
        if (is_file($file)) {
            require_once $file;
            return;
        }
    }
});
