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

namespace Kufer\Web\Classes\Pdf\Helper;

use Kufer\Web\Classes\Pdf\ExtFPDITcPDF;

class TextInput extends RenderObject
{
  
  private $name;

  
  private $value;

  
  private $defaultValue;

  public function __construct(ExtFPDITcPDF $fpdf, string $name, ?string $value = null, ?string $defaultValue = null)
  {
    parent::__construct($fpdf);
    $this->name = $name;
    $this->value = $value;
    $this->defaultValue = $defaultValue;
  }

  public function render(): void
  {
    $this->context(function() {
      $props = array_filter(array(
        'value' => $this->value,
        'defaultValue' => $this->defaultValue,
        'editable' => true
      ), \FunctionOperations::not('is_null'));

      $w = $this->getComputedWidth();
      $h = $this->getComputedHeight();
      assert(!is_null($w));
      assert(!is_null($h));
      $this->fpdf->TextField($this->name, $w, $h, $props);
    });
  }
}