<?php

namespace GriffinForms\Admin\Html\FormControls\Form;

class LimitEntries extends \GriffinForms\Admin\Html\FormControls\Form\Format
{    
    public function html()
    {
        echo '<div class="row">';
        echo '<div class="col-md-12 mb-3" id="griffinforms-togglelimitentries-wrap">';
        $this->toggleLimitEntries();
        echo '</div>';
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-limitentriescount-wrap">';
        $this->limitEntriesCount();
        echo '</div>';
        echo '<div class="griffinforms-hidden-option col-md-12 mb-3" id="griffinforms-limitentriesmessage-wrap">';
        $this->limitEntriesMessage();
        echo '</div>';
        echo '</div>';
        
    }
    
    protected function toggleLimitEntries()
    {
        $value = isset($this->value['toggle']) ? $this->value['toggle'] : false;
        $data = $this->getControlData(array('label' => $this->lang->getText('toggle_limit_entries_label')));
        $field = new \GriffinForms\Admin\Html\FormControls\ToggleCheckbox('toggle_limit_entries', $value, $data);
        $field->html();
    }
    
    protected function limitEntriesCount()
    {
        $value = isset($this->value['limit']) ? $this->value['limit'] : '';
        $field = new \GriffinForms\Admin\Html\FormControls\InputNumber('limit_entries_count', $value, $this->getControlData());
        $field->setAttr('min', 100);
        $field->setAttr('step', 100);
        echo '<div>';
        echo esc_html($this->lang->getText('limit_entries_count_label'));
        echo '</div>';
        echo '<div>';
        $field->html();
        echo '</div>';
        
    }    
    
    protected function limitEntriesMessage()
    {
        $value = isset($this->value['message']) ? $this->value['message'] : '';
        $field = new \GriffinForms\Admin\Html\FormControls\TextArea('limit_entries_message', $value, $this->getControlData());
        echo '<div>';
        echo esc_html($this->lang->getText('limit_entries_message_label'));
        echo '</div>';
        echo '<div>';
        $field->html();
        echo '</div>';
        
    }
}
