<?php

namespace GriffinForms\Admin\Html\FormControls\Submissions;

class FormFilter extends \GriffinForms\Admin\Html\FormControls\Submissions\Format
{    
    public function html()
    {
        $forms = $this->sql->getItems('form', array('name', 'id'));
        echo '<select name="form_id">';
        echo '<option value="-1">' . esc_html($this->lang->getText('all_forms', 'form_filter')) . '</option>';
        
        $form_id_from_get = isset($_GET['form_id']) && is_numeric($_GET['form_id']) ? intval($_GET['form_id']) : null;
        $selected_value = $form_id_from_get ?? $this->value;

        foreach ($forms as $form) {
            $selected = '';
            $disabled = '';
            if ($form->id == $selected_value) {
                $selected = ' selected';
            }

            echo '<option value="' . absint($form->id) . '"' . esc_attr($selected) . esc_attr($disabled) . '>';
            echo esc_html($form->name);
            echo '</option>';
        }
        
        echo '</select>';
    }
}