<?php
 
 /**
 * =============================================================================
 * @package			    Blue Raven (Free Version)
 * @Plugin URI			https://enterrahost.com/plugins/blue-raven
 * 
 * @Author			    EnterraHost
 * @Author URI			https://enterrahost.com
 * @License		    	GPL-2.0-or-later
 *  
 * @Copyright			(c) 2025 EnterraHost
 * @File Description	Setting Page
 * 
 * =============================================================================
 * 
 * || INDEX:
 * ||   - BLUE RAVEN ADMIN SETTINGS
 * || 
 * =============================================================================
 */

if ( ! defined( 'ABSPATH' ) ) exit; 

/*
============================================================
    BLUE RAVEN ADMIN SETTINGS
============================================================
*/

class BlueRaven_Admin_Settings {
    
    /**
     * Renders the admin settings interface.
     *
     * This is the main entry point that outputs the plugin's settings panel
     * by calling the internal static method that builds the settings HTML.
     *
     * @access public
     * @static
     * @return void
     */
    public static function render() {
        self::output_settings();
    }
        
    /**
     * Outputs the settings section for the Blue Raven plugin.
     *
     * This function renders a UI block in the admin panel that allows users
     * to enable or disable hard error logging. It includes a labeled toggle switch
     * and a brief description, using WordPress-compliant escaping and translation functions.
     *
     * @access private
     * @static
     * @return void
     */
    private static function output_settings() {
        
        global $wpdb;
        $table_name = $wpdb->prefix . 'BlueRavenConfig';
        $eTypeDebugging = $wpdb->get_var( $wpdb->prepare( "SELECT value FROM $table_name WHERE setting = %s", 'eType_debugging'));
        $uninstaller = get_option('blue_raven_remove_all_data', false);
        
        ?>

        <div class='parent-container'>
            <h2><?php esc_html_e('SETTINGS', 'blue-raven'); ?></h2>
            <div id='settings-body' style='margin-top: 5rem;'>
                <div class='block-wrap-bottom-border'>
                    <h3><?php esc_html_e('Uninstaller', 'blue-raven'); ?></h3>
                    <div style="margin: 20px 0;" id='uninstaller-setting' class='flex-sb'>
                        <h4 class='no-margin-padding spacing-right text-center'>
                            <?php esc_html_e('Remove all data when uninstalling', 'blue-raven'); ?>
                        </h4>
                        <label class="switch">
                            <input type="checkbox" id="enable-full-uninstaller" name="enable-full-uninstaller" value="1" 
                                <?php checked($uninstaller); ?>>
                            <span class="slider"></span>
                        </label>
                    </div>
                    <p class='enterra-highlight indent-one'>
                        <?php esc_html_e('When you uninstall Blue Raven with this enabled, it will remove all the data in the plugin.', 'blue-raven'); ?>
                    </p>
                </div>
                <div class=''>
                    <h3><?php esc_html_e('Debugging', 'blue-raven'); ?><h3>
                    <div style="margin: 20px 0;" id='error-logging' class='flex-sb'>
                        <h4 class='no-margin-padding spacing-right text-center'>
                            <?php esc_html_e('Switch On Hard Error Logging', 'blue-raven'); ?>
                        </h4>
                        <label class="switch" for='enable-etype-debuging'>
                            <input type="checkbox" id="enable-etype-debuging" name="enable-etype-debuging" value="1" 
                                <?php checked(isset($eTypeDebugging) && filter_var($eTypeDebugging, FILTER_VALIDATE_BOOLEAN)); ?>>
                            <span class="slider"></span>
                        </label>
                    </div>
                    <p class='enterra-highlight indent-one'>
                        <?php esc_html_e('You are enabling error logging, which can help us learn more about bugs and crashes.', 'blue-raven'); ?>
                    </p>
                    <button class='enterra-button' id='download-logs' style='font-size: 1rem !important; margin-top: 1rem;'><?php esc_html_e('Download Logs', 'blue-raven'); ?></button>
                </div>
            </div>
        </div>
        <?php
    }
}

