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

namespace Kufer\Web\KuferTools\Teilnehmer\KursUebersicht\Detailsreiter\InfoAnDoz;

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

  protected function getViewModel()
  {
    $viewModel = new SendInfoAnDozViewModel();
    $viewModel->kurs = $this->useCaseResponse->kurs;
    
    $viewModel->kurs->toolId = $this->useCaseResponse->toolId;
    $viewModel->kurs->belegId = $this->useCaseResponse->belegId;
    $viewModel->dozenten = $this->getDozentenMitEMailStatus();
    $viewModel->doppeltVersandt = $this->useCaseResponse->doppeltVersandt;
    $viewModel->kurs->titleSingular = $this->useCaseResponse->sprachSettings->Dozent['Singular_mit_Artikel']['Akkusativ'];
    $viewModel->kurs->titlePlural = $this->useCaseResponse->sprachSettings->Dozent['Plural_mit_Artikel']['Nominativ'];
    $viewModel->kurs->kursArtikel = $this->useCaseResponse->sprachSettings->Kurs['Singular_mit_Artikel']['Nominativ'];
    $viewModel->kurs->countDozenten = $this->useCaseResponse->countDozenten;

    return $viewModel;
  }

  
  private function getDozentenMitEMailStatus()
  {
    $result = array();
    foreach ($this->useCaseResponse->dozenten as $key => $doz) {
      if (!isset($this->useCaseResponse->emailStatus->getRecipients()[$key])) {
        continue;
      }

      $recipientStatus = $this->useCaseResponse->emailStatus->getRecipients()[$key];
      if ($recipientStatus->isSuccess()) {
        $doz->email_status = 0; 
      } elseif ($recipientStatus->isWarning()) {
        $doz->email_status = 1; 
      } else {
        $doz->email_status = 2; 
      }

      $doz->email_status_message = $recipientStatus->getReadableMessageWithRecipientName();
      $result[] = $doz;
    }

    return $result;
  }

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

  protected function getSeitenTitel(): string
  {
    return 'Information an den/die Dozenten/in ';
  }
}