<?php

declare(strict_types=1);

namespace Apexl\Io\User\Display\Controllers;

use Apexl\Io\Display\Components\BasicLink;
use Apexl\Io\Display\Components\ContentTitle;
use Apexl\Io\Display\Controllers\DisplayController;
use Apexl\Io\Services\RouteUrls;
use Apexl\Io\Services\VariableManager;
use JsonException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final readonly class ForgotPasswordCheckEmailDisplayController extends DisplayController
{

    /**
     * @throws JsonException
     */
    public function __invoke(
        ServerRequestInterface $request,
        ResponseInterface $response,
        RouteUrls $routeUrls,
        VariableManager $variableManager,
    ): ResponseInterface {
        $this->render->setActive("noUI");
        $this->render->setPageTitle("Check Email");

        $this->output->addResponse($request, $this->render->build([
            $this->component(ContentTitle::class)
                ->addContent(
                    "If an account exists for that email address, we've sent password reset instructions to it. The email may take upto a few minutes to arrive."
                )
                ->addClass('col-md-12'),

            $this->component(BasicLink::class)
                ->addClass('forgottenPasswordLink')
                ->addRoute($routeUrls->url('user.display.login'))
                ->addText($variableManager->get('user_login_return_login_text') ?? 'Return to login'),
        ]));

        return $this->json($response);
    }
}


