<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Oeffentlich\PasswortAendern\PasswortAendernFormular;

use Kufer\Web\KuferTools\Oeffentlich\PasswortAnfordern\Utils\HandlePasswortAnfordernEingaben as HandlePasswortAnfordern;

class PasswortAendernFormularPresenter extends \Kufer\Web\KuferTools\Basis\Presenter\MitRahmenPresenter
{
  protected function getContent()
  {
    $view = $this->getView();

    return \is_null($this->useCaseResponse->key) ? $view->getNoColumn() : $view->getFooter();
  }

  protected function getView()
  {
    return new PasswortAendernFormularView($this->getViewModel());
  }

  protected function getViewModel()
  {
    $viewModel = new PasswortAendernFormularViewModel();
    $viewModel->pwAnzahlZeichen = $this->useCaseResponse->pwAnzahlZeichen;
    $viewModel->pwZahlErforderlich = $this->useCaseResponse->pwZahlErforderlich;
    $viewModel->pwGrossKleinBuchstabenErforderlich = $this->useCaseResponse->pwGrossKleinBuchstabenErforderlich;
    $viewModel->pwSonderzeichenErforderlich = $this->useCaseResponse->pwSonderzeichenErforderlich;
    $viewModel->https = $this->useCaseResponse->https;
    $viewModel->passwort = $this->useCaseResponse->password;
    $viewModel->login = $this->useCaseResponse->login;
    $viewModel->key = $this->useCaseResponse->key;
    $viewModel->errormsg = \array_map(function($pStatus): string {
      return HandlePasswortAnfordern::getMessageString($pStatus);
    }, HandlePasswortAnfordern::filterError($this->useCaseResponse->errormsg));

    return $viewModel;
  }

  protected function getJSDeclarations(): string
  {
    $result = parent::getJSDeclarations();
    $result .= \JsOperations::getDeclarationInt('KuferTools.pwMinLength', $this->useCaseResponse->pwAnzahlZeichen);

    return $result;
  }

  protected function getSeitenTitel(): string
  {
    return 'Passwort ändern';
  }
}