<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class Reactify_Text extends Reactify_Field {
     public $type = 'text';
    private $placeholder = '';

    public function setType( $type ) {
        $this->type = $type;
        return $this;
    }

    public function setPlaceholder( $placeholder ) {
        $this->placeholder = $placeholder;
        return $this;
    }

    function build() {
        $type = $this->type;
        $is_disabled = $this->disabled ? 'disabled' : '';

        $out = '';

        // Allow HTML in the label for icons
        if ( $this->type != 'hidden' && $this->label != '' ) {
            $out .= "<label for='{$this->id}'>" . wp_kses_post($this->label) . "</label>";
        }

        $out .= "<input 
                    type='{$type}' 
                    name='{$this->id}' 
                    id='{$this->id}' 
                    placeholder='{$this->placeholder}' 
                    class='form-control' 
                    value=\"" . esc_attr($this->value) . "\" 
                    {$is_disabled}>";

        echo "<div class='" . esc_attr( $this->classes ) . "'>{$out}</div>";
    }
}
