<?php

namespace GriffinForms\Admin\Html\FormControls\Form;

class UserAction extends \GriffinForms\Admin\Html\FormControls\Form\Format
{    
    public function html()
    {
        echo '<div class="row"' . wp_kses_post($this->css_id) . '>';
        echo '<div class="col-md-12 mb-3" id="griffinforms-toggleredirection-wrap">';
        $this->actionType();
        echo '</div>';        
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-successmessage-wrap">';
        echo '<div>';
        echo esc_html($this->lang->getText('success_message_label'));
        echo '</div>';
        echo '<div>';
        $this->successMessage();
        echo '</div>';        
        echo '</div>';        
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-redirectionurl-wrap">';
        echo '<div>';
        echo esc_html($this->lang->getText('redirection_url_label'));
        echo '</div>';
        echo '<div>';
        $this->redirectionUrl();
        echo '</div>';
        echo '</div>';
        echo '</div>';
        
    }
    
    protected function actionType()
    {
        $options = $this->choices->getChoices('user_action_type');
        $value = isset($this->value['type']) ? $this->value['type'] : array_key_first($options);
        $field = new \GriffinForms\Admin\Html\FormControls\InputRadio('action_type', $value, $this->getControlData());
        $field->radioOptions($options);
        $field->html();
    }
    
    protected function successMessage()
    {
        $value = isset($this->value['message']) ? $this->value['message'] : '';
        $field = new \GriffinForms\Admin\Html\FormControls\TextArea('success_message', $value, $this->getControlData());
        $field->html();
    }
    
    protected function redirectionUrl()
    {
        $value = isset($this->value['url']) ? $this->value['url'] : '';
        $field = new \GriffinForms\Admin\Html\FormControls\InputUrl('redirection_url', $value, $this->getControlData());
        $field->html();
    }
    
    protected function entryAlertsEmails()
    {
        $data = array();
        $data['max'] = 10;
        $field = new \GriffinForms\Admin\Html\FormControls\MultiInput('entry_alerts_emails', $this->value, $this->getControlData($data));
        $field->html();
    }
}
