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

namespace Kufer\Web\KuferTools\utils\wssfield\basis;

use Kufer\Web\KuferTools\Basis\UseCaseBuilder\ToolSection;
use Kufer\Web\KuferTools\Utils\WssField\WssField;

class WssFieldDatumKomplettKurzJahrKurz extends WssField
{
  
  private $field;

  public function __construct(ToolSection $toolSection, \ToolSettings $toolSettings, $datamodulColumn, string $field)
  {
    parent::__construct($toolSection, $toolSettings, $datamodulColumn);
    $this->field = $field;
  }

  public function getValue($datamodulWert, $isFormular = false)
  {
    $date = $datamodulWert->getVarValueEx($this->field, $this->datamodulColumn->datamodul);
    if (\DateTimeOperations::isEmptyOrDefault($date)) {
      return '';
    }

    $weekdayLong = \CleanOperations::cleanStringForHtml(\DateTimeOperations::getWeekDay($date));
    $weekdayShort = \CleanOperations::cleanStringForHtml(\DateTimeOperations::getWeekDayShort($date));
    $dateEscaped = \CleanOperations::cleanStringForHtml(
      \DateTimeOperations::getShortForm4DateStr($date)
    );

    return "<abbr title=\"$weekdayLong\">$weekdayShort</abbr>, $dateEscaped";
  }

  protected function encodeValue($value)
  {
    return $value;
  }
}