<?php


namespace Opentalent\OtTemplating\ViewHelpers;

use Closure;
use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

/**
 * Returns true if a login attempt just failed
 *
 *     {namespace ot=Opentalent\OtTemplating\ViewHelpers}
 *
 *     {ot:loginFailed()}
 *
 * @package Opentalent\OtTemplating\ViewHelpers
 */
class LoginFailedViewHelper extends OtAbstractViewHelper
{

    /**
     * -- This method is expected by Fluid --
     * Renders the content as html
     *
     * @param array $arguments
     * @param Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     * @return int|null
     */
    public static function renderStatic(
        array $arguments,
        Closure $renderChildrenClosure,
        RenderingContextInterface $renderingContext
    ) {
        $loginFailure = $_SESSION['login_failed'] ?? false;
        if ($loginFailure) {
            return 1;
        }
        return 0;
    }

}
