<?php

if (!defined('ABSPATH')) {
    exit;
}

$calio_root_path = plugin_dir_path(__FILE__);
$calio_composer_autoload = $calio_root_path . 'vendor/autoload.php';
if (is_readable($calio_composer_autoload)) {
    require_once $calio_composer_autoload;
}

spl_autoload_register(static function (string $class): void {
    $prefix = 'Calio\\';
    if (strpos($class, $prefix) !== 0) {
        return;
    }

    $relative = substr($class, strlen($prefix));
    $relativePath = str_replace('\\', DIRECTORY_SEPARATOR, $relative) . '.php';
    $file = plugin_dir_path(__FILE__) . 'src/' . $relativePath;

    if (is_readable($file)) {
        require_once $file;
    }
});
