<?php

namespace GriffinForms\Admin\Html\FormControls\Field\ValidationTraits;

trait InputText
{
    protected $min_chars;
    protected $max_chars;
    protected $allow_numbers;
    protected $allow_spaces;
    protected $allow_splchars;
    protected $exclude;

    protected function setMinChars()
    {
        $this->min_chars = $this->fixEmptyValue('min', '');
    }
    
    protected function setMaxChars()
    {
        $this->max_chars = $this->fixEmptyValue('max', '');
    }

    protected function setAllowNumbers()
    {
        $this->allow_numbers = $this->fixEmptyValue('allow_numbers', 1);
    }
    
    protected function setAllowSpaces()
    {
        $this->allow_spaces = $this->fixEmptyValue('allow_spaces', 1);
    }
    
    protected function setAllowSplChars()
    {
        $this->allow_splchars = $this->fixEmptyValue('allow_splchars', 1);
    }
    
    protected function setExclude()
    {
        $this->exclude = $this->fixEmptyValue('exclude', '');
    }

    protected function validationOptionsInputText()
    {
        echo '<div class="row">';
        echo '<div class="col-md-12 mb-3 gf-validation-options" id="gf-pattern-wrap">';
        $this->patternField();
        echo '</div>';
        echo '<div class="col-md-12 gf-validation-options" id="gf-custom-parameters-wrap">';
        echo '<div class="mb-3">';
        $this->minCharsInputText();
        echo '</div>';
        echo '<div class="mb-3">';
        $this->maxCharsInputText();
        echo '</div>';
        echo '<div class="mb-3">';
        $this->allowNumbers();
        $this->allowSpaces();
        $this->allowSplChars();
        echo '</div>';
        echo '<div>';
        $this->excludeChars();
        echo '</div>';
        echo '</div>';
        echo '<div class="col-md-12 gf-validation-options" id="gf-db-validate-wrap">';
        $this->tableSelect();
        $this->columnSelect();
        $this->matchType();
        echo '</div>';
        echo '</div>';
    }

    protected function minCharsInputText()
    {
        $field = new \GriffinForms\Admin\Html\FormControls\InputNumber('min_chars', $this->min_chars, '');
        $field->setAttr('min', 1);
        echo '<span class="me-2">' . esc_html($this->lang->getText('inputtext_minchars_label')) . '</span>';
        echo '<span class="me-3">';
        $field->html();
        echo '</span>'; 
    }    
    
    protected function maxCharsInputText()
    {
        $field = new \GriffinForms\Admin\Html\FormControls\InputNumber('max_chars', $this->max_chars, '');
        $field->setAttr('min', 1);
        echo '<span class="me-2">' . esc_html($this->lang->getText('inputtext_maxchars_label')) . '</span>';
        echo '<span class="me-3">';
        $field->html();
        echo '</span>'; 
    }
    
    protected function allowNumbers()
    {   
        $data = array('label' => $this->lang->getText('allow_numbers'));
        $field = new \GriffinForms\Admin\Html\FormControls\toggleCheckbox('allow_numbers', $this->allow_numbers, $data);
        echo '<span class="me-3">';
        $field->html();
        echo '</span>'; 
    } 
    
    protected function allowSpaces()
    {
        $data = array('label' => $this->lang->getText('allow_spaces'));
        $field = new \GriffinForms\Admin\Html\FormCOntrols\toggleCheckbox('allow_spaces', $this->allow_spaces, $data);
        echo '<span class="me-3">';
        $field->html();
        echo '</span>'; 
        
    }    
    
    protected function allowSplChars()
    {   
        $data = array('label' => $this->lang->getText('allow_spl_chars'));
        $field = new \GriffinForms\Admin\Html\FormControls\toggleCheckbox('allow_spl_chars', $this->allow_splchars, $data);
        echo '<span class="me-3">';
        $field->html();
        echo '</span>'; 
        
    }
    
    protected function excludeChars()
    {   
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('exclude_chars', $this->exclude, '');
        echo '<span class="me-2">' . esc_html($this->lang->getText('exclude_chars_label')) . '</span>';
        echo '<span class="me-3">';
        $field->html();
        echo '</span>'; 
        
    }

}