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

namespace Kufer\Web\KuferTools\Teilnehmer\BayerischerApothekertagEhrengaeste\AnmeldeFormular;

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

  protected function getViewModel()
  {
    $viewModel = new AnmeldeFormularViewModel();
    $viewModel->toolSection = $this->useCaseResponse->toolSection;
    $viewModel->toolSettings = $this->useCaseResponse->toolSettings;
    $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(): string
  {
    $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(): array
  {
    $js = parent::getJsFilesSrcAryWeitere();
    $js[] = $this->getJsFileFromSys('anmelden.js');

    return $js;
  }
}