<?php

namespace Plainwork\Ui\Component\Form;

use Plainwork\Http\Request;
use Plainwork\Ui\Component\Form\AbstractInput;

class DateInput extends AbstractInput
{
    private ?\DateTimeInterface $value = null;

    public function grab(Request $request): ?\DateTimeInterface
    {
        $ret = $request->getPostParam($this->getName());
        $ret = (null !== $ret) ? new \DateTimeImmutable($ret) : null;

        return $ret;
    }

    public function setValue(?\DateTimeInterface $v): self
    {
        $this->value = $v;

        return $this;
    }

    public function getValue(): ?\DateTimeInterface
    {
        return $this->value;
    }
}
