<?php
/**
 * WAF Optimization Modal
 * 
 * Modal for WAF optimization wizard
 * 
 * @package VMPFence
 * @since 2.2.4
 */

if (!defined('ABSPATH')) {
    exit;
}
?>

<!-- WAF Optimization Modal -->
<div id="vmpfence-waf-optimization-modal" class="vmpfence-waf-modal" style="display: none;">
    <div class="vmpfence-waf-modal-overlay"></div>
    <div class="vmpfence-waf-modal-container">
        <div class="vmpfence-waf-modal-content">
            
            <!-- Step 1: Configuration Screen -->
            <div class="vmpfence-waf-modal-screen" id="vmpfence-waf-config-screen">
                <div class="vmpfence-waf-modal-header">
                    <h2>Optimize VMP Security Firewall</h2>
                    <button type="button" class="vmpfence-waf-modal-close" onclick="vmpfenceCloseOptimizationModal()">&times;</button>
                </div>
                
                <div class="vmpfence-waf-modal-body">
                    
                    <div class="vmpfence-waf-info-notice">
                        <p>Extended Protection Mode of the VMP Security Web Application Firewall uses the PHP ini setting called <code>auto_prepend_file</code> in order to ensure it runs before any potentially vulnerable code runs. This PHP setting will be configured to point to the VMP Security file at:</p>
                    </div>
                    
                    <div class="vmpfence-waf-file-path-box">
                        <code id="vmpfence-waf-file-path-display-opt">Loading...</code>
                    </div>
                    
                    <div class="vmpfence-waf-info-box">
                        <p>To enable Extended Protection, the <code>auto_prepend_file</code> setting will be configured in your server's configuration file.</p>
                    </div>

                    <div class="vmpfence-waf-server-config-box">
                        <p>We've preselected your server configuration based on our tests, but if you know your web server's configuration, please select it now.</p>
                        <select id="vmpfence-waf-server-config-select-opt" class="vmpfene-waf-select">
                            <option value="apache">Apache</option>
                            <!-- <option value="apache_suphp">Apache + suPHP</option> -->
                            <!-- <option value="apache_cgi">Apache + CGI/FastCGI</option> -->
                            <option value="litespeed">LiteSpeed</option>
                            <!-- <option value="nginx">NGINX</option> -->
                            <!-- <option value="iis">Windows (IIS)</option> -->
                        </select>
                    </div>
                    
                    <!-- Warning for non-Apache servers -->
                    <div class="vmpfence-waf-warning-box" id="vmpfence-waf-server-warning" style="display: none;">
                        <strong>⚠️ Warning:</strong>
                        <p id="vmpfence-waf-server-warning-text"></p>
                    </div>
                    
                    <!-- Warning for subdirectory installation -->
                    <div class="vmpfence-waf-warning-box" id="vmpfence-waf-subdirectory-warning" style="display: none;">
                        <strong>⚠️ Notice:</strong>
                        <p>WordPress is installed in a subdirectory. Please verify the file paths after optimization.</p>
                    </div>
                    
                    <!-- Warning for multisite subsite -->
                    <div class="vmpfence-waf-error-box" id="vmpfence-waf-multisite-warning" style="display: none;">
                        <strong>❌ Error:</strong>
                        <p>WAF optimization can only be configured on the main site of a multisite network.</p>
                    </div>

                    <div class="vmpfence-waf-instruction-box">
                        <p>Please download a backup of the following files before we make the necessary changes:</p>
                        <button type="button" class="vmpfence-waf-btn vmpfence-waf-btn-default" onclick="vmpfenceDownloadHtaccess()">
                            DOWNLOAD .HTACCESS BACKUP
                        </button>
                    </div>
                    
                    <!-- Error display -->
                    <div class="vmpfence-waf-error-box" id="vmpfence-waf-error-display" style="display: none;">
                        <strong>Error:</strong>
                        <p id="vmpfence-waf-error-message"></p>
                    </div>
                </div>
                
                <div class="vmpfence-waf-modal-footer">
                    <p>Once you have downloaded the files, click Continue to complete the setup.</p>
                    <button type="button" class="vmpfence-waf-btn vmpfence-waf-btn-danger" id="vmpfence-waf-continue-btn" onclick="vmpfenceStartOptimization()" disabled>
                        CONTINUE
                    </button>
                </div>
            </div>
            
            <!-- Step 2: Processing Screen -->
            <div class="vmpfence-waf-modal-screen" id="vmpfence-waf-processing-screen" style="display: none;">
                <div class="vmpfence-waf-modal-header">
                    <h2>Waiting for Changes</h2>
                </div>
                
                <div class="vmpfence-waf-modal-body">
                    <div class="vmpfence-waf-waiting-box">
                        <p>The <code>auto_prepend_file</code> setting has been successfully added to <code>.htaccess</code> and <code>.user.ini</code>. Once this change takes effect, Extended Protection Mode will be enabled.</p>
                        <div class="vmpfence-waf-spinner-container">
                            <div class="vmpfence-waf-spinner"></div>
                            <p class="vmpfence-waf-waiting-text">Waiting for it to take effect. This may take up to 30 seconds.</p>
                        </div>
                    </div>
                </div>
                
                <div class="vmpfence-waf-modal-footer">
                    <button type="button" class="vmpfence-waf-btn vmpfence-waf-btn-primary" onclick="vmpfenceCloseOptimizationModal()">
                        CLOSE
                    </button>
                </div>
            </div>
            
            <!-- Step 3: Success Screen -->
            <div class="vmpfence-waf-modal-screen" id="vmpfence-waf-success-screen" style="display: none;">
                <div class="vmpfence-waf-modal-header">
                    <h2>Installation Complete</h2>
                    <button type="button" class="vmpfence-waf-modal-close" onclick="vmpfenceCloseOptimizationModal()">&times;</button>
                </div>
                
                <div class="vmpfence-waf-modal-body">
                    <div class="vmpfence-waf-simple-success-box">
                        <p>Installation was successful!</p>
                    </div>
                </div>
                
                <div class="vmpfence-waf-modal-footer">
                    <button type="button" class="vmpfence-waf-btn vmpfence-waf-btn-primary" onclick="vmpfenceCloseOptimizationModal()">
                        CLOSE
                    </button>
                </div>
            </div>
            
        </div>
    </div>
</div>
