<?php

declare (strict_types=1);
namespace Worldline\Vendor\Worldline\WorldlineForWoocommerce\Documentation;

use Worldline\Vendor\Worldline\Modularity\Module\ExecutableModule;
use Worldline\Vendor\Worldline\Modularity\Module\ModuleClassNameIdTrait;
use Worldline\Vendor\Worldline\Modularity\Module\ServiceModule;
use Worldline\Vendor\Worldline\WorldlineForWoocommerce\Documentation\Renderer\LinksRenderer;
use Worldline\Vendor\Worldline\WorldlineForWoocommerce\WorldlinePaymentGateway\GatewayIds;
use Worldline\Vendor\Psr\Container\ContainerExceptionInterface;
use Worldline\Vendor\Psr\Container\ContainerInterface;
class DocumentationModule implements ExecutableModule, ServiceModule
{
    use ModuleClassNameIdTrait;
    /**
     * @param ContainerInterface $container
     * @return bool
     * @throws ContainerExceptionInterface
     */
    public function run(ContainerInterface $container) : bool
    {
        \add_action(
            'woocommerce_sections_checkout',
            // phpcs:disable Worldline.CodeQuality.VariablesName.SnakeCaseVar
            static function () use($container) : void {
                global $current_section;
                if (GatewayIds::HOSTED_CHECKOUT !== $current_section) {
                    return;
                }
                $documentationLinksRenderer = $container->get('documentation.links_renderer');
                \assert($documentationLinksRenderer instanceof LinksRenderer);
                // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                echo $documentationLinksRenderer->render();
            }
        );
        return \true;
    }
    public function services() : array
    {
        static $services;
        if ($services === null) {
            $services = (require_once \dirname(__DIR__) . '/inc/services.php');
        }
        return $services();
    }
}
