<?php

namespace GriffinForms\Admin\Html\FormControls\Form;

class AccessLevel extends \GriffinForms\Admin\Html\FormControls\Form\Format
{    
    public function html()
    {
        echo '<div class="row">';
        echo '<div class="col-md-12 mb-3" id="griffinforms-togglepublicaccess-wrap">';
        $this->togglePublicAccess();
        echo '</div>';        
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-toggleroleaccess-wrap">';
        $this->toggleRoleAccess();
        echo '</div>';        
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-selectuserroles-wrap">';
        echo '<div>' . esc_html($this->lang->getText('select_user_roles_label')) . '</div>';
        $this->selectUserRoles();
        echo '</div>';
        echo '</div>';
        
    }
    
    protected function togglePublicAccess()
    {
        $choices = $this->choices->getChoices('toggle_public_access');
        $value = isset($this->value['access']) ? $this->value['access'] : array_key_first($choices);
        $field = new \GriffinForms\Admin\Html\FormControls\InputRadio('toggle_public_access', $value, $this->getControlData());
        $field->radioOptions($choices);
        $field->html();
    }
    
    protected function toggleRoleAccess()
    {
        $data = $this->getControlData(array('label' => $this->lang->getText('toggle_role_access_label')));
        $value = isset($this->value['role_access']) ? $this->value['role_access'] : false;
        $field = new \GriffinForms\Admin\Html\FormControls\ToggleCheckbox('toggle_role_access', $value, $data);
        $field->html();
    }
    
    protected function selectUserRoles()
    {
        $options = $this->choices->getUserRoles();
        $value = isset($this->value['roles']) ? $this->value['roles'] : '';
        $field = new \GriffinForms\Admin\Html\FormControls\MultiSelect('select_user_roles', $value, $this->getControlData());
        $field->selectOptions($options);
        $field->html();
    }
    
    public function fieldJs()
    {
    }
}
