<?php
if (!class_exists('WPGSV_Field')) {
    class WPGSV_Field {

        public static function add($type = "", $name = "", $placeholder = "", $class = "", $value = "", $callback = "" ) 
        {
            global $wpgsv;
            $wpgsv__options = $wpgsv->wpgsv__options();

            if ($type == "text") {
                
                if( isset($wpgsv__options[$name]) && !empty($wpgsv__options[$name]) ) {
                    $value = $wpgsv__options[$name];
                }
                
                echo "<input type='" . esc_attr($type) . "' id='wpgsv-" . esc_attr($name) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' class='" . esc_attr($class) . "' placeholder='" . esc_attr($placeholder) . "' " . $callback . " />";
            }

            if ($type == 'checkbox') {

                echo "<label class='toggle'><input type='" . esc_attr($type) . "' name='" . esc_attr($name) . "' ";

                if ( isset($wpgsv__options[$name]) && !empty($wpgsv__options[$name] ) ) echo "checked";
                
                echo " /><span class='toggle-slider toggle-round'></span></label>";
                
            }

            if ($type == "textarea") {

                if( isset($wpgsv__options[$name]) && !empty($wpgsv__options[$name]) ) {
                    $value = $wpgsv__options[$name];
                }
                
                echo "<textarea id='wpgsv-" . esc_attr($name) . "' name='" . esc_attr($name) . "' placeholder='" . esc_attr($placeholder) . "' class='" . esc_attr($class) . "' />" . esc_textarea($value) . "</textarea>";
            }

            if ($type == "hidden") {
                
                if( isset($wpgsv__options[$name]) && !empty($wpgsv__options[$name]) ) {
                    $value = $wpgsv__options[$name];
                }
                
                echo "<input type='" . esc_attr($type) . "' id='wpgsv-" . esc_attr($name) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' " . $callback . " />";
            }
        }

        public static function select($type = "", $name = "", $class = "", $value = array() ) 
        {
            global $wpgsv;
            $wpgsv__options = $wpgsv->wpgsv__options();
            
            echo "<select name='" . esc_attr($name) . "' class='" . esc_attr($class) . "'>";
                
                foreach( $value as $key => $val) {
                    echo "<option value='" . esc_attr($key) . "'";
                    
                    if ( isset($wpgsv__options[$name]) && $wpgsv__options[$name] == $key) echo " selected";
                    
                    echo ">" . esc_html($val) . "</option>";
                }
                
                echo "</select>";
        }
    }
}