<?php
// Prevent direct access.
if (!defined('ABSPATH')) {
    exit;
}


/**
 * HTML template for å vise Traffic Log siden.
 *
 * Forventer å motta følgende variabler:
 *
 * $msg = Eventuell success/error melding som skal settes inn på toppen av siden.  
 * $trafficLog = Tilsvarende $trafficLog array fra FirewallConfig.
 */
?>

<div class="wrap wtb-firewall-admin">
    <h1>Traffic Log</h1>
    <?php echo wp_kses_post($msg); ?>

    <p>
        Monitor requests to your website with the Traffic Log. Choose what activity to record, review recent visits, and use the collected data to identify suspicious traffic, errors, and unusual request patterns.
    </p>

    <div class="card">
        <h2>View Traffic Log</h2>       
        <p>
            Review recorded requests and visitor activity to see how traffic is reaching and interacting with your site.
        </p>

        <p>
            <a href="<?php echo esc_url(admin_url('admin.php?page=')); ?>" class="button button-secondary">
                View traffic log</a>
        </p>

        <p><b>LEGG INN PHP KODE HER SENERE FOR Å VISE RETT MELDING.</b><br>
            Traffic logging is currently disabled. Enable it below to begin recording requests.<br>
            or:<br>
            Traffic logging is enabled. The log contains 1,248 recorded requests.
        </p>
    </div>


    <form method="POST" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
        <input type="hidden" name="action" value="wtb_traffic_log" />        
        <?php wp_nonce_field('wtb_firewall_traffic_log', 'wtb_firewall_nonce'); ?>
        <div class="card">
            <h2>Traffic Log Configuration</h2>            
            <p>
                Enable or disable traffic logging and choose which requests and visitor activity should be recorded.
            </p>

            <table class="form-table" role="presentation">
                <tbody>
                    <tr>
                        <th>Enable traffic log</th>
                        <td>
                            <input type="checkbox" name="traffic_log_enabled" <?php checked($trafficLog['enabled'], true); ?> value="1" />
                            Enable the traffic log to record visits and requests.
                        </td>
                    </tr>
                    
                    <tr>
                        <th>Ignore signed in users</th>
                        <td>
                            <input type="checkbox" name="ignore_users" <?php checked($trafficLog['ignoreUsers'], true); ?> value="1" />
                            Signed in users will not be logged in the frontend.
                        </td>
                    </tr>
                    
                    <tr>
                        <th>Ignore signed in users in Wordpress dashboard</th>
                        <td>
                            <input type="checkbox" name="ignore_dashboard" <?php checked($trafficLog['ignoreDashboard'], true); ?> value="1" />
                            Signed in users will not be logged in the wordpress dashboard.
                        </td>
                    </tr>
                    
                    <tr>
                        <th>Clear log after</th>
                        <td>
                            <input type="number" class="small-text" name="log_days" min="1" step="1" value="<?php echo esc_html($trafficLog['logDays']); ?>" />
                            days.
                            <p>
                                Log entries older than this will be automatically deleted from the log.
                            </p>
                        </td>
                    </tr>

                </tbody>
            </table>

            <p class="submit">
                <button type="submit" class="button button-primary">Save settings</button>
            </p>

        </div>
    </form>


</div>