<?php

namespace Encore\Admin\Form\Field;

class Number extends Text
{

    public function render()
    {

        $this->initPlainInput();

        $this->prepend('<i class="fa fa-fw">N</i>')
            ->defaultAttribute('type', 'number')
            ->defaultAttribute('step', '0.1')
            ->defaultAttribute('id', $this->id)
            ->defaultAttribute('name', $this->elementName ?: $this->formatName($this->column))
            ->defaultAttribute('value', old($this->column, $this->value()))
            ->defaultAttribute('class', 'form-control '.$this->getElementClassString())
            ->defaultAttribute('style', 'width:150px')
            ->defaultAttribute('placeholder', $this->getPlaceholder());

        $this->addVariables([
            'prepend' => $this->prepend,
            'append'  => $this->append,
        ]);

        return parent::render();
    }

    /**
     * Set min value of number field.
     *
     * @param int $value
     *
     * @return $this
     */
    public function min($value)
    {
        $this->attribute('min', $value);

        return $this;
    }

    /**
     * Set max value of number field.
     *
     * @param int $value
     *
     * @return $this
     */
    public function max($value)
    {
        $this->attribute('max', $value);

        return $this;
    }

    /**
     * Set step value of number field.
     *
     * @param int $value
     *
     * @return $this
     */
    public function step($value)
    {
        $this->attribute('step', $value);

        return $this;
    }
}