<?php

namespace GriffinForms\Admin\Html\FormControls;

class InputRadio extends \GriffinForms\Admin\Html\FormControls\Format
{
    protected $options;

    protected function setCssClass()
    {
        if (!empty($this->data['app_context'])) {
            $this->css_class = 'class="form-check-input gf-app-control-radio griffinforms-' . $this->purgeString($this->name) . ' griffinforms-' . strtolower($this->meta) . ' griffinforms-formcontrol';
        } else {
            $this->css_class = '';
        }
    }
    
    public function radioOptions($options)
    {
        if (is_array($options)) {
            $this->options = $options;
        } else {
            $this->options = array();
        }
    }
    
    public function html()
    {
        echo '';
        $checked = '';
        foreach($this->options as $value => $text) {
            
            if ($this->value == $value) {
                $checked = ' checked="checked"';
            } else {
                $checked = '';
            }
            
            $id = 'griffinforms-' . $this->purgeString($value) . '-' . strtolower($this->meta);
            echo '<div id="' . esc_attr($id) . '-wrap' . '">';
            echo '<input type="radio" id="' . esc_attr($id) . '"' . wp_kses_post($this->attr_name) . wp_kses_post($this->css_class) . '" value="' . esc_attr($value) . '"' . esc_attr($checked) . '>';
            echo ' <label for="' . esc_attr($id) . '">' . esc_html($text) . '</label></div>';
        }
        echo '</select>';
        
    }
}
