<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\KuferTools\Oeffentlich\PasswortAendern\PasswortAendernFormular;

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

class PasswortAendernFormularPresenter extends \Kufer\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()
  {
    $result = parent::getJSDeclarations();
    $result .= \JsOperations::getDeclarationInt('KuferTools.pwMinLength', $this->useCaseResponse->pwAnzahlZeichen);

    return $result;
  }
}