<?php

namespace GriffinForms\Admin\Html\FormControls;

class ToggleCheckBox extends \GriffinForms\Admin\Html\FormControls\Format
{    
    protected function isChecked()
    {
        if ($this->value == 1) {
            return 'checked="checked"';
        } else {
            return '';
        }
    }
    
    protected function checkBoxLabel()
    {
        if(isset($this->data['label']) and $this->data['label'] != '') {
            echo '<label class="me-2" for="griffinforms-' . esc_attr($this->purgeString($this->name) . '-' . strtolower($this->meta)) . '">' . esc_html($this->data['label']) . '</label>';
            
        } else {
            return;
        }
    }
    
    public function html()
    {
        $class = !empty($this->data['app_context'])
            ? 'form-check-input gf-app-control-checkbox me-2'
            : 'me-2';

        echo '';
        echo '<input type="checkbox" class="' . esc_attr($class) . '" ' . wp_kses_post($this->css_id . ' ' . $this->attr_name) . ' ' . esc_attr($this->isChecked()) . '>';
        $this->checkBoxLabel();
        
    }
}
