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

namespace Kufer\Web\KuferTools\Basis\Kursdetails\TnZertifikat;

class TnZertifikatPresenter extends \Kufer\KuferTools\Basis\Presenter\MitRahmenPresenter
{
  
  protected $isFormular;

  public function __construct($useCaseResponse, bool $isFormular = true)
  {
    parent::__construct($useCaseResponse);
    $this->isFormular = $isFormular;
  }

  protected function getContent()
  {
    if (empty($this->useCaseResponse->belegungen)) {
      return $this->getView()->getNoData();
    }

    return parent::getContent();
  }

  protected function getNewViewModel(): TnZertifikatViewModel
  {
    return new TnZertifikatViewModel();
  }

  protected function getViewModel()
  {
    $result = $this->getNewViewModel();
    $result->isFormular = $this->isFormular;
    $result->kurs = $this->useCaseResponse->kurs;
    $result->belegungen = $this->useCaseResponse->belegungen;
    $result->referer = $this->useCaseResponse->referer;
    $result->refererLabel = $this->useCaseResponse->refererLabel;
    $result->toolId = $this->useCaseResponse->toolId;
    $result->status = $this->useCaseResponse->status ?? 0;
    $result->shouldWrite = $this->useCaseResponse->shouldWrite;

    return $result;
  }

  protected function getView()
  {
    return new TnZertifikatView($this->getViewModel());
  }

  protected function getJsFilesSrcAry()
  {
    return array_merge(
      parent::getJsFilesSrcAry(),
      array(
        $this->getJsFileFromSys('tnzertifikat.js')
      )
    );
  }

  protected function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    $result .= 'registerNamespace("KuferTools.Kurs");';
    $result .= \JsOperations::getDeclarationString('KuferTools.Kurs.Beginndatum', $this->useCaseResponse->kurs->beginn_dat);
    $result .= \JsOperations::getDeclarationString('KuferTools.Kurs.Endedatum', $this->useCaseResponse->kurs->ende_dat);

    return $result;
  }
}