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

namespace Kufer\KuferTools\Teilnehmer\BayerischerApothekertagStudenten\AnmeldeFormular;

class AnmeldeFormularPresenter extends \Kufer\KuferTools\Basis\Presenter\MitRahmenPresenter
{
  protected function getView()
  {
    return new AnmeldeFormularView($this->getViewModel());
  }

  protected function getViewModel()
  {
    $viewModel = new AnmeldeFormularViewModel();
    $viewModel->person = $this->useCaseResponse->person;
    $viewModel->columns = $this->useCaseResponse->columns;
    $viewModel->messageErfolg = $this->getMessageStringSuccess();
    $viewModel->messageInfo = $this->getMessageStringInfo();
    $viewModel->messageFehler = $this->getMessageStringError();
    $viewModel->freeField = nl2br($this->useCaseResponse->freeField);
    $viewModel->bearbeitbar = $this->useCaseResponse->bearbeitbar;

    return $viewModel;
  }

  private function getMessageStringSuccess()
  {
    
    return '';
  }

  private function getMessageStringInfo()
  {
    return '';
  }

  private function getMessageStringError()
  {
    return '';
    
  }

  public function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    $teilnehmer = $this->useCaseResponse->person;

    $result .= 'registerNamespace("KuferTools.UserInfo"); ';
    $tnrKonto = $teilnehmer->konto;
    $tnrIban = $teilnehmer->iban;
    if (!\SessionOperations::isReplikat()) {
      $tnrKonto = \SecurityOperations::anonymizeString($tnrKonto);
      $tnrIban = \SecurityOperations::anonymizeString($tnrIban);
    }
    $anmZf = $this->useCaseResponse->toolTnAnmeldSettings->anm_zahlverfahren;
    if ($anmZf == ANM_ZAHLVERFAHREN_SEPA_KTO || $anmZf == ANM_ZAHLVERFAHREN_NUR_KTO) {
      $result .= \JsOperations::getDeclarationString('KuferTools.UserInfo.CurrentUserKonto', \StringOperations::htmlentities($tnrKonto, ENT_QUOTES));
      $result .= \JsOperations::getDeclarationBoolean('KuferTools.UserInfo.UseKto', false);
    }
    if ($anmZf == ANM_ZAHLVERFAHREN_SEPA_KTO || $anmZf == ANM_ZAHLVERFAHREN_NUR_SEPA) {
      $result .= \JsOperations::getDeclarationString('KuferTools.UserInfo.CurrentUserIban', \StringOperations::htmlentities($tnrIban, ENT_QUOTES));
      $result .= \JsOperations::getDeclarationBoolean('KuferTools.UserInfo.UseSepa', true);
    }

    $result .= \JsOperations::getDeclarationString('KuferTools.UserInfo.NewsletterErlaubt', $teilnehmer->newsl_erlaubt);

    
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.NewsletterAnmeldung_erlaubt', $this->useCaseResponse->toolTnAnmeldSettings->newsletterAnmeldung_erlaubt);
    $result .= \JsOperations::getDeclarationJsonBase64('KuferTools.ErlaubteZahlarten', $this->useCaseResponse->toolTnAnmeldSettings->getErlaubteZahlArten());
    
    $result .= \JsOperations::getDeclarationString('KuferTools.SepaTextOhneMandat', \StringOperations::convertLinebreaks2HTML($this->useCaseResponse->toolTnAnmeldSettings->sepaTextOhneMandat));
    $result .= \JsOperations::getDeclarationString('KuferTools.SepaTextMitMandat', \StringOperations::convertLinebreaks2HTML($this->useCaseResponse->toolTnAnmeldSettings->sepaTextMitMandat));
    $result .= \JsOperations::getDeclarationString('KuferTools.SepaTextDruckLink', $this->useCaseResponse->toolTnAnmeldSettings->sepaTextDruckLink);

    
    $result .= \JsOperations::getDeclarationString('KuferTools.AnmZusatzText', \StringOperations::convertLinebreaks2HTML($this->useCaseResponse->toolTnAnmeldSettings->anm_zusatzText));
    $result .= \JsOperations::getDeclarationString('KuferTools.AnmZusatzAufforderung', \StringOperations::convertLinebreaks2HTML($this->useCaseResponse->toolTnAnmeldSettings->anm_zusatzAufforderung));
    $result .= \JsOperations::getDeclarationJson('KuferTools.KursData', (object)$this->useCaseResponse->kursdata4Js);

    return $result;
  }

  protected function getJsFilesSrcAryWeitere()
  {
    $js = parent::getJsFilesSrcAryWeitere();
    $js[] = $this->getJsFileFromSys('anmelden.js');

    return $js;
  }
}