<?php

namespace YOOtheme;

$root = __DIR__;

// In Bedrock/composer projects, the project autoloader is already loaded
// and handles all PSR-4/classmap autoloading for YOOtheme's packages.
// The bundled vendor/autoload.php has been removed to avoid duplicate
// class loading conflicts with CiviCRM and wp-cli dependencies.
//
// The stock vendor autoloader also loads these function files via
// autoload_files.php — we must require them explicitly since we
// removed the bundled autoloader.
require_once "{$root}/packages/application/functions.php";
require_once "{$root}/packages/translation/functions.php";

Path::setAlias('~theme', $root);
Path::setAlias('~yootheme', "{$root}/packages");
Path::setAlias('~assets/leaflet', "{$root}/vendor/assets/leaflet");
Path::setAlias('~assets/uikit', "{$root}/vendor/assets/uikit");

// Redirect generated assets (compiled CSS, fonts, cache) to the uploads
// directory so they live outside Composer-managed theme source code.
// This survives composer install and supports S3/DAM serving.
$generatedDir = dirname($root, 3) . '/uploads/yootheme';
foreach (['css', 'fonts', 'cache'] as $dir) {
    $target = "{$generatedDir}/{$dir}";
    if (!is_dir($target)) {
        @mkdir($target, 0755, true);
    }
    Path::setAlias("~theme/{$dir}", $target);
}

$app = Application::getInstance("{$generatedDir}/cache");
$app->load('~theme/packages/{application,encryption,image,translation,http{-message,-server},view{,-metadata}}/bootstrap.php');

return $app;
