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

/*
 * HTML template for å vise Country Rules siden.
 * 
 * Forventer å motta følgende variabler:
 * 
 * $msg = Eventuell success/error melding som skal settes inn på toppen av siden.
 * $countryList = HTML som settes inn i select feltet i Add Country Rule boksen. Lister alle land bruker kan velge.
 * $countryRuleList = HTML som settes inn for å vise alle eksisterende firewall regler for land.
 */
?>
<div class="wrap wtb-firewall-admin">
    <h1 class="wp-heading-inline">Add Country Rule</h1>
    <?php echo wp_kses_post($msg); ?>    

    <div class="card">
        <h2>Add Country Rule</h2>

        <p>Select a country and choose whether to block or allow it.</p>

        <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>">
            <input type="hidden" name="action" value="wtb_firewall_add_country_rule" />
            <?php wp_nonce_field('wtb_firewall_add_country_rule', 'wtb_firewall_nonce'); ?>

            <table class="form-table" role="presentation">
                <tbody>
                    <tr>
                        <th>
                            Country
                        </th>
                        <td>
                            <select name="country" required>
                                <?php //echo $countryList; ?>                                        
                                <?php
                                echo wp_kses(
                                        $countryList,
                                        [
                                            'option' => [
                                                'value' => true,                                                
                                            ],
                                        ]
                                );
                                ?>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <th>Action</th>
                        <td>
                            <fieldset>                            
                                <input type="radio" name="rule_action" value="block" checked>
                                Block
                                &nbsp;&nbsp;                               
                                <input type="radio" name="rule_action" value="allow">
                                Allow                               
                            </fieldset>
                        </td>
                    </tr>
                </tbody>
            </table>

            <p>
                <button type="submit" class="button button-primary">
                    Add Country Rule
                </button>
            </p>

        </form>        
    </div>


    <h1>Country Rules</h1>         
    <table class="wp-list-table widefat fixed striped">
        <thead>
            <tr>                    
                <th scope="col" class="manage-column column-primary column-country">Country</th>
                <th scope="col" class="manage-column column-action">Action</th>
                <th scope="col" class="manage-column column-status">Status</th>
                <th scope="col" class="manage-column column-blocked_connections">Blocked connections</th>
                <th scope="col" class="manage-column column-last_blocked">Last blocked</th>
                <th scope="col" class="manage-column column-row_actions">Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php echo wp_kses_post($countryRuleList); ?>                
        </tbody>
    </table>          
</div>
