<?php

namespace GriffinForms\Admin\Html\FormControls\Field;

class DefaultValue extends \GriffinForms\Admin\Html\FormControls\Field\Format
{   
    protected $choices;
    protected $secure;
    protected $secure_data;
    protected $value_type_options;
    protected $value_type;
    protected $custom_value;
    protected $variable_value_options;
    protected $variable_value;
    protected $get_value;
    protected $get_name;
    
    public function html()
    {
        echo '<div class="row mb-3">';
        echo '<div class="col-md-12 mb-3" id="griffinforms-field-default-value-type-wrap">';
        $this->selectValueType();
        echo '</div>';        
        echo '<div class="griffinforms-field-default-suboption col-md-12 mb-3" id="griffinforms-field-default-value-custom-wrap">';
        $this->customValue();
        echo '</div>';        
        echo '<div class="griffinforms-field-default-suboption col-md-12 mb-3" id="griffinforms-field-default-value-variable-wrap">';
        $this->selectVariableValue();
        echo '</div>';        
        echo '<div class="col-md-12 mb-3" id="griffinforms-field-default-enable-get-wrap">';
        $this->urlGet();
        echo '</div>';
        echo '</div>';
        
    }
    
    protected function setValueTypeOptions()
    {
        $this->value_type_options = $this->choices->getChoices('default_value_type_' . $this->data['field_type']);
    }
    
    protected function setValueType()
    {
        $this->value_type = $this->fixEmptyValue('value_type', '', $this->value_type_options);
    }
    
    protected function setCustomValue()
    {
        $this->custom_value = $this->fixEmptyValue('custom', '');
    }
    
    protected function setVariableValueOptions()
    {
        $this->variable_value_options = $this->choices->getChoices('variable_values_' . $this->data['field_type']);
    }
    
    protected function setVariableValue()
    {
        $this->variable_value = $this->fixEmptyValue('variable', '', $this->variable_value_options);
    }
    
    protected function setGetValue()
    {
        $this->get_value = $this->fixEmptyValue('get_value', 0);
    }
    
    protected function setGetName()
    {
        $this->get_name = $this->fixEmptyValue('get_name', '');
    }
    
    protected function selectValueType()
    {
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('field_default_value', $this->value_type, '');
        $field->selectOptions($this->value_type_options);
        $field->html();
    }    
    
    protected function customValue()
    {
        $method = 'customValue' . $this->data['field_type'];

        if (method_exists($this, $method)) {
            return $this->$method();
        }
    }    
    
    protected function selectVariableValue()
    {
        $method = 'variableValue' . $this->data['field_type'];
        
        if (method_exists($this, $method)) {
            return $this->$method();
        }
    }    
    
    protected function customValueInputText()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('custom_inputtext_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }      
    
    protected function customValueInputNumber()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputNumber('custom_inputnumber_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }      
    
    protected function customValueInputEmail()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('custom_inputemail_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }          
    
    protected function customValueInputPhone()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('custom_inputphone_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }          
    
    protected function customValueInputUrl()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputUrl('custom_inputurl_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }           
    
    protected function customValueInputDate()
    {
        $field = new \GriffinForms\Admin\Html\FormControls\InputDate('custom_inputdate_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }

    protected function customValueInputTime()
    {
        $field = new \GriffinForms\Admin\Html\FormControls\InputTime('custom_inputtime_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }

    protected function customValueSelectField()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('custom_selectfield_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }              
    
    protected function customValueInputRadio()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('custom_inputradio_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }                
    
    protected function customValueInputCheckbox()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\InputText('custom_inputcheckbox_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }    

    protected function customValueTextArea()
    {        
        $field = new \GriffinForms\Admin\Html\FormControls\TextArea('custom_textarea_value', $this->custom_value, '');
        $this->lang->getText('default_value_custom_label');
        $field->html();
    }    
    
    protected function variableValueInputText()
    {   
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('field_inputtext_variable_value', $this->variable_value, '');
        $field->selectOptions($this->variable_value_options);
        $this->lang->getText('default_value_variable_label');
        $field->html();
    }    
    
    protected function variableValueInputNumber()
    {   
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('field_inputnumber_variable_value', $this->variable_value, '');
        $field->selectOptions($this->variable_value_options);
        $this->lang->getText('default_value_variable_label');
        $field->html();
    }    
    
    protected function variableValueInputEmail()
    {   
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('field_inputemail_variable_value', $this->variable_value, '');
        $field->selectOptions($this->variable_value_options);
        $this->lang->getText('default_value_variable_label');
        $field->html();
    }    
    
    protected function variableValueInputPhone()
    {   
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('field_inputphone_variable_value', $this->variable_value, '');
        $field->selectOptions($this->variable_value_options);
        $this->lang->getText('default_value_variable_label');
        $field->html();
    }    
    
    protected function variableValueInputUrl()
    {   
        $field = new \GriffinForms\Admin\Html\FormControls\SelectField('field_inputurl_variable_value', $this->variable_value, '');
        $field->selectOptions($this->variable_value_options);
        $this->lang->getText('default_value_variable_label');
        $field->html();
    }   
    
    protected function variableValueInputDate()
    {   
/*         $data = array('choices' => $this->choices, 'lang' => $this->lang);
        $field = new \GriffinForms\Admin\Html\FormControls\RelativeDate('defaultvalue_variable', $this->variable_value, $data);
        $field->html(); */
    }   
    
    protected function variableValueSelectField()
    {   
    }   
    
    protected function variableValueInputRadio()
    {   
    }   
    
    protected function variableValueInputCheckbox()
    {   
    }
    
    protected function urlGet()
    {
        $data = array('label' => $this->lang->getText('allow_url_get'));
        $checkbox = new \GriffinForms\Admin\Html\FormControls\toggleCheckbox('url_get', $this->get_value, $data);
        $getValue = new \GriffinForms\Admin\Html\FormControls\inputText('get_name', $this->get_name, '');
        echo '<div class="mb-3">';
        $checkbox->html();
        echo '</div>';
        echo '<div id="griffinforms-getvalue-inputtext-wrap">';
        echo '<div>';
        echo esc_html($this->lang->getText('get_value_label'));
        echo '</div>';
        echo '<div>';
        $getValue->html();
        echo '</div>';
        echo '</div>';
    }
}
