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

namespace Kufer\Web\KuferTools\Ausgaben\Feedback;

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

  protected function getNewViewModel()
  {
    return new FeedbackFormularViewModel();
  }

  protected function getViewModel()
  {
    $viewModel = $this->getNewViewModel();
    $viewModel->kurs = $this->useCaseResponse->kurs;
    $viewModel->kurs->name = $this->useCaseResponse->user->getVarValue('name');
    $viewModel->kurs->vorname = $this->useCaseResponse->user->getVarValue('vorname');
    $viewModel->betreff = isset($this->useCaseResponse->betreff) ? $this->useCaseResponse->betreff : '';
    $viewModel->toolId = $this->useCaseResponse->toolId;
    $viewModel->action = $this->useCaseResponse->action;
    $viewModel->ktId = isset($this->useCaseResponse->ktId) ? $this->useCaseResponse->ktId : '';
    $viewModel->requestId = $this->useCaseResponse->requestId ?? $viewModel->ktId;
    $viewModel->kurs->belegId = isset($this->useCaseResponse->belegId) ? $this->useCaseResponse->belegId : '';

    $viewModel->sendEMailToVerwMitarbeiter = $this->useCaseResponse->sendEMailToVerwMitarbeiter ?? false;
    $viewModel->sendEMailToPlanendMitarbeiter = $this->useCaseResponse->sendEMailToPlanendMitarbeiter ?? false;
    $viewModel->sendEMailToVerantwortendenMitarbeiter = $this->useCaseResponse->sendEMailToVerantwortendenMitarbeiter ?? false;
    $viewModel->sendEMailToEinrichtung = $this->useCaseResponse->sendEMailToEinrichtung ?? true;
    $viewModel->sendEMailToDozent = $this->useCaseResponse->sendEMailToDozent ?? false;

    $viewModel->maxGroesseProDatei = isset($this->useCaseResponse->maxGroesseProDatei) ? $this->useCaseResponse->maxGroesseProDatei : '';
    $viewModel->maxGroesseAllerDateien = isset($this->useCaseResponse->maxGroesseAllerDateien) ? $this->useCaseResponse->maxGroesseAllerDateien : '';

    $viewModel->vhsname = $this->useCaseResponse->vhsname ?? 'Einrichtung';

    return $viewModel;
  }

  protected function getJSDeclarations(): string
  {
    $result = parent::getJSDeclarations();

    $tool0Settings = \ToolSettingsAPI::getToolSettings(0);
    if ($tool0Settings->dokuUploadAllowByExclude) {
      
      $fileExtStr = $tool0Settings->uploadBlacklist4Ext;
      $useBlacklist = true;
    } else {
      
      $fileExtStr = $tool0Settings->uploadWhitelist4Ext;
      $useBlacklist = false;
    }
    $statusMessageStr4FileExt = \DokuUploadUserAPI::getStatusMessagePart4FileExt($tool0Settings);

    $result .= \JsOperations::getDeclarationBoolean('KuferTools.Kontakt.AllowUploadByExclude', $useBlacklist);
    $result .= \JsOperations::getDeclarationString('KuferTools.Kontakt.FileExtStr', $fileExtStr);
    $result .= \JsOperations::getDeclarationString('KuferTools.Kontakt.FileExtMessagePart', $statusMessageStr4FileExt);
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.Kontakt.UseAllowedExt4Attach', $tool0Settings->useAllowedExt4Attach);
    $result .= \JsOperations::getDeclarationInt('KuferTools.Kontakt.MaxGroesseProUploadDateien', \ConstantOperations::getMaxFileSize4Upload(($tool0Settings->uploadmaxsize)));
    $result .= \JsOperations::getDeclarationInt('KuferTools.Kontakt.MaxGesamtGroesseAllerUploadDateien', \ConstantOperations::getMaxFileSize4Upload(5 * ($tool0Settings->uploadmaxsize)));

    return $result;
  }

  protected function getJsFilesSrcAryWeitere(): array
  {
    return array(
      $this->getJsFileFromSys('kontaktformular.js'),
      $this->getJsFileFromOldTools('Formulare/kontakte.js')
    );
  }

  protected function getSeitenTitel(): string
  {
    return 'Feedback zum Kurs ' . $this->useCaseResponse->kurs->id;
  }
}