<?php

/**
 * @package     Dotclear
 *
 * @copyright   Olivier Meunier & Association Dotclear
 * @copyright   AGPL-3.0
 */
declare(strict_types=1);

namespace Dotclear\Theme\customCSS;

use Dotclear\App;
use Dotclear\Helper\Process\TraitProcess;

/**
 * @brief   The module frontend process.
 * @ingroup customCSS
 */
class Frontend
{
    use TraitProcess;

    public static function init(): bool
    {
        return self::status(My::checkContext(My::FRONTEND));
    }

    public static function process(): bool
    {
        if (self::status()) {
            App::behavior()->addBehavior('publicHeadContent', function (): void {
                if (App::blog()->settings()->system->theme === My::id()) {
                    $p_url = is_string($p_url = App::blog()->settings()->system->public_url) ? $p_url : '';

                    echo
                    '<link rel="stylesheet" type="text/css" href="' .
                    $p_url . DIRECTORY_SEPARATOR . My::id() . '.css' .
                    '" media="screen">' . "\n";
                }
            });
        }

        return self::status();
    }
}
