<?php

namespace Plainwork\Ui\Component\Form;

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

class CheckboxInput extends AbstractInput
{
    private bool $value = false;
    private string $htmlValue = '1';
    private $label = null;
    private bool $on = false;

    public function setOn(bool $v): self
    {
        $this->on = $v;
        return $this;
    }

    public function isOn(): bool
    {
        return $this->on ? true : false;
    }

    public function grab(Request $request): bool
    {
        $postedValue = $request->getPostParam($this->getName());
        $ret = (null === $postedValue) ? false : true;

        return $ret;
    }

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

        return $this;
    }

    public function getValue(): bool
    {
        return $this->value;
        // return $this->value ? $this->htmlValue : null;
    }

    public function setHtmlValue(string $v): self
    {
        $this->htmlValue = $v;

        return $this;
    }

    public function getHtmlValue(): string
    {
        return $this->htmlValue;
    }

    public function setLabel($v): self
    {
        $this->label = $v;

        return $this;
    }

    public function getLabel()
    {
        return $this->label;
    }
}
