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

namespace Kufer\Web\KuferTools\Basis\Kursdetails\Detailsreiter\Teilnehmer\BelegungDialog;

abstract class BelegungBearbeitenDialogPresenter extends \Kufer\Web\KuferTools\Basis\Presenter\JsonPresenter
{
  public function present()
  {
    $view = $this->getView();

    return \JsonOperations::encode4Ajax($this->getAjaxObject($view));
  }

  
  protected function getAjaxObject($pView): \stdClass
  {
    $result = new \stdClass();
    $result->inhalt = $pView->show(); 
    $result->title = $this->getAjaxDialogTitle();
    
    $result->jsdeclarations = $this->getJSDeclarations();

    return $result;
  }

  protected function getViewModel()
  {
    $viewModel = new BelegungBearbeitenDialogViewModel();
    $viewModel->toolSection = $this->useCaseResponse->toolSection;
    $viewModel->toolSettings = $this->useCaseResponse->toolSettings;
    $viewModel->columns = $this->useCaseResponse->columns;
    $viewModel->belegung = $this->useCaseResponse->belegung;

    return $viewModel;
  }

  protected function getAjaxDialogTitle(): string
  {
    return 'Belegungsdaten bearbeiten';
  }

  protected function getJSDeclarations(): string
  {
    return 'registerNamespace("KuferTools.BelegungBearbeiten");' . "\n"
              . \JsOperations::getDeclarationString('KuferTools.BelegungBearbeiten.Anmeldedatum', \StringOperations::htmlentities($this->useCaseResponse->belegung->anm_datum, ENT_QUOTES))
              . \JsOperations::getDeclarationString('KuferTools.BelegungBearbeiten.Anmeldestatus', \StringOperations::htmlentities($this->useCaseResponse->belegung->status, ENT_QUOTES));
  }
}