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


namespace Kufer\Web\KuferTools\Mitarbeiter\KursUebersicht\Detailsreiter\Downloads\BearbeiteDoku;

use Kufer\Web\KuferTools\Utils\Download\DokuHelper as DokuHelper;

class BearbeiteDokuFormularPresenter 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->jsdeclarations = $this->getJSDeclarations();

    return $result;
  }

  
  protected function getJSDeclarations(): string
  {
    
    $dokuHelper = new DokuHelper();

    return $dokuHelper->getJSDeclarations($this->useCaseResponse->dokument);
  }

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

  protected function getViewModel()
  {
    $viewModel = new BearbeiteDokuFormularViewModel();
    $viewModel->toolId = $this->useCaseResponse->toolId;
    $viewModel->download = $this->useCaseResponse->dokument;
    $viewModel->freigabeNoetig = $this->useCaseResponse->freigabeNoetig;
    $viewModel->freigabeVon = $this->useCaseResponse->freigabeVon;
    $viewModel->freigabeAm = $this->useCaseResponse->freigabeAm;

    
    $viewModel->freigabeUserKuerzel = '';
    if ($viewModel->freigabeAm !== '') {
      $viewModel->freigabeUserKuerzel = \SessionOperations::getCurrentWebToolsUserKennung();
    }

    $viewModel->dokuOrigName = $this->useCaseResponse->dokuOrigName;
    
    $viewModel->downloadTn = $this->useCaseResponse->downloadTn;

    return $viewModel;
  }
}