<?php

namespace GriffinForms\Admin\Html\FormControls\Field;

use GriffinForms\Admin\Html\FormControls\Field\FieldOptionsTraits\SelectField;
use GriffinForms\Admin\Html\FormControls\Field\FieldOptionsTraits\InputRadio;
use GriffinForms\Admin\Html\FormControls\Field\FieldOptionsTraits\InputCheckbox;
use GriffinForms\Admin\Html\FormControls\Field\FieldOptionsTraits\Payment;

class FieldOptions extends \GriffinForms\Admin\Html\FormControls\Field\Format
{   
    use SelectField;
    use InputRadio;
    use InputCheckbox;
    use Payment;
    
    public function html()
    {
        $html_method = $this->data['field_type'] . 'Html';
        $this->$html_method();
    }
    
    protected function setValue()
    {
        if (!is_array($this->value) or empty($this->value)) {
            $this->value = array(
                $this->lang->getText('options_group_name') => array(
                    $this->lang->getText('option_text') . ' 1' => '',
                    $this->lang->getText('option_text') . ' 2' => '',
                    $this->lang->getText('option_text') . ' 3'=> ''
                )
            );
        }
    }
    
    public function fieldJs()
    {
        $js_method = $this->data['field_type'] . 'Js';
    
        ob_start();
        ?>
        jQuery(document).ready(function($) {
            <?php
            $this->commonJs();
    
            if (method_exists($this, $js_method)) {
                $this->$js_method();
            }
            ?>
        });
        <?php
    
        $js = ob_get_clean();
    
        wp_add_inline_script('griffinforms-global-js', $js);
    }
    
    private function commonJs()
    {
        echo '';
    }
}
