<?php
/**
 * Unblock requests page handler for BotFend Anti-Bot Firewall
 *
 * @package BotFend\Admin\Pages
 * @version 5.0.5
 */

namespace BotFend\Admin\Pages;

use BotFend\Core\Config;
use BotFend\Core\Core;

defined('ABSPATH') || exit;

class Unblock {

    private $core;
    private $config;

    public function __construct(Core $core) {
        $this->core = $core;
        $this->config = Config::get_instance();

        add_action('admin_enqueue_scripts', [$this, 'enqueue_unblock_assets']);
    }

    private function get_database() {
        $components = $this->core->get_components();
        return $components['database'] ?? null;
    }

    /**
     * Enqueue Unblock specific CSS and JavaScript
     *
     * @param string $hook Current admin page
     * @return void
     */
    public function enqueue_unblock_assets(string $hook): void {
        if (strpos($hook, 'botfend-unblock-requests') === false) {
            return;
        }

        wp_enqueue_style(
            'botfend-unblock-css',
            BOTFEND_ASSETS_URL . 'css/botfend-unblock.css',
            ['botfend-admin-css'],
            BOTFEND_VERSION
        );

        wp_enqueue_script(
            'botfend-unblock-js',
            BOTFEND_ASSETS_URL . 'js/unblock.js',
            ['jquery'],
            BOTFEND_VERSION,
            true
        );

        $auto_refresh = $this->get_config_bool('unblock_auto_refresh', false);
        $refresh_interval = $this->get_config_int('unblock_refresh_interval', 30000);

        wp_localize_script('botfend-unblock-js', 'botfendUnblock', [
            'autoRefresh' => $auto_refresh,
            'refreshInterval' => $refresh_interval,
            'i18n' => [
                'approveConfirm' => esc_html__('Are you sure you want to approve the selected requests?', 'botfend-anti-bot-firewall'),
                'rejectConfirm' => esc_html__('Are you sure you want to reject the selected requests?', 'botfend-anti-bot-firewall'),
                'deleteConfirm' => esc_html__('Are you sure you want to delete the selected requests? This action cannot be undone.', 'botfend-anti-bot-firewall'),
                'rejectSingle' => esc_html__('Are you sure you want to reject this request?', 'botfend-anti-bot-firewall'),
                'deleteSingle' => esc_html__('Are you sure you want to delete this request? This action cannot be undone.', 'botfend-anti-bot-firewall'),
                'selectRequest' => esc_html__('Please select at least one request to perform bulk action.', 'botfend-anti-bot-firewall'),
            ],
        ]);
    }

    private function get_config_bool(string $key, bool $default = false): bool {
        return $this->config->get_bool($key, $default);
    }

    private function get_config_int(string $key, int $default = 0): int {
        return $this->config->get_int($key, $default);
    }

    private function get_config_string(string $key, string $default = ''): string {
        return $this->config->get_string($key, $default);
    }

    public function handle_actions() {
        if (!isset($_GET['action_result']) || !isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'botfend_admin_action')) {
            return null;
        }

        $action = sanitize_text_field(wp_unslash($_GET['action_result']));
        $type = isset($_GET['result_type']) ? sanitize_text_field(wp_unslash($_GET['result_type'])) : 'success';
        $processed = isset($_GET['processed']) ? absint($_GET['processed']) : 0;

        $messages = [
            'approved' => ['type' => 'success', 'message' => esc_html__('Request approved and IP unblocked successfully.', 'botfend-anti-bot-firewall')],
            'rejected' => ['type' => 'success', 'message' => esc_html__('Request rejected successfully.', 'botfend-anti-bot-firewall')],
            'deleted' => ['type' => 'success', 'message' => esc_html__('Request deleted successfully.', 'botfend-anti-bot-firewall')],
            'bulk_processed' => ['type' => 'success', 'message' => sprintf(esc_html__('Bulk action completed. %d request(s) processed.', 'botfend-anti-bot-firewall'), $processed)],
            'error' => ['type' => 'error', 'message' => esc_html__('An error occurred. Please try again.', 'botfend-anti-bot-firewall')]
        ];

        return $messages[$action] ?? null;
    }

    private function truncate_text(string $text, int $length = 50): string {
        if (strlen($text) <= $length) {
            return $text;
        }
        return substr($text, 0, $length) . '...';
    }

    private function get_status_label(string $status): string {
        $labels = [
            'pending' => esc_html__('Pending', 'botfend-anti-bot-firewall'),
            'approved' => esc_html__('Approved', 'botfend-anti-bot-firewall'),
            'rejected' => esc_html__('Rejected', 'botfend-anti-bot-firewall')
        ];

        return $labels[$status] ?? ucfirst($status);
    }

    public function render(): void {
        if (!current_user_can('manage_options')) {
            return;
        }

        $database = $this->get_database();
        
        if (!$database) {
            echo '<div class="notice notice-error"><p>' . esc_html__('Database component not available.', 'botfend-anti-bot-firewall') . '</p></div>';
            return;
        }

        $unblock_enabled = $this->get_config_bool('allow_unblock', true);
        if (!$unblock_enabled) {
            echo '<div class="notice notice-warning is-dismissible">';
            echo '<p>' . esc_html__('Unblock requests are currently disabled in plugin settings. Enable "Allow unblock requests" in General Settings to accept new requests.', 'botfend-anti-bot-firewall') . '</p>';
            echo '</div>';
        }

        $items_per_page = $this->get_config_int('unblock_items_per_page', 50);
        $date_format = $this->get_config_string('date_format', get_option('date_format'));
        $time_format = $this->get_config_string('time_format', get_option('time_format'));
        $enable_export = $this->get_config_bool('enable_unblock_export', false);

        $action_result = $this->handle_actions();
        if ($action_result) {
            echo '<div class="notice notice-' . esc_attr($action_result['type']) . ' is-dismissible"><p>' . esc_html($action_result['message']) . '</p></div>';
        }

        $filters = [];
        if (isset($_GET['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'])), 'botfend_admin_action')) {
            $filters['status'] = isset($_GET['status']) ? sanitize_text_field(wp_unslash($_GET['status'])) : 'pending';
            $filters['ip'] = isset($_GET['filter_ip']) ? sanitize_text_field(wp_unslash($_GET['filter_ip'])) : '';
            $filters['email'] = isset($_GET['filter_email']) ? sanitize_text_field(wp_unslash($_GET['filter_email'])) : '';
            if (!empty($_GET['date_from'])) $filters['date_from'] = sanitize_text_field(wp_unslash($_GET['date_from']));
            if (!empty($_GET['date_to'])) $filters['date_to'] = sanitize_text_field(wp_unslash($_GET['date_to']));
        } else {
            $filters['status'] = 'pending';
            $filters['ip'] = '';
            $filters['email'] = '';
        }

        $requests = $database->get_unblock_requests($filters, $items_per_page);
        $pending_count = $database->count_pending_unblock_requests();
        $all_requests = $database->get_unblock_requests([], 1000);
        ?>
        <div class="wrap">
            <h1 class="botfend-page-title">
                <?php esc_html_e('Unblock Request Management', 'botfend-anti-bot-firewall'); ?>
                <?php if (!$unblock_enabled): ?>
                    <span class="botfend-badge botfend-badge-warning"><?php esc_html_e('Disabled', 'botfend-anti-bot-firewall'); ?></span>
                <?php endif; ?>
            </h1>

            <div class="botfend-card botfend-mb-20">
                <details open>
                    <summary class="botfend-section-summary">
                        <span class="dashicons dashicons-chart-pie"></span>
                        <?php esc_html_e('Request Overview', 'botfend-anti-bot-firewall'); ?>
                    </summary>
                    <div class="botfend-section-content">
                        <div class="botfend-stats-grid">
                            <div class="botfend-stat-card" style="--stat-color: #ffb900; --stat-bg: #fff3cd;">
                                <div class="botfend-stat-icon"><span class="dashicons dashicons-clock"></span></div>
                                <div class="botfend-stat-content">
                                    <h3 class="botfend-stat-title"><?php esc_html_e('Pending', 'botfend-anti-bot-firewall'); ?></h3>
                                    <p class="botfend-stat-value"><?php echo esc_html($pending_count); ?></p>
                                </div>
                            </div>

                            <?php
                            $approved_count = 0;
                            $rejected_count = 0;
                            foreach ($all_requests as $request) {
                                if ($request->status === 'approved') $approved_count++;
                                elseif ($request->status === 'rejected') $rejected_count++;
                            }
                            ?>

                            <div class="botfend-stat-card" style="--stat-color: #28a745; --stat-bg: #d4edda;">
                                <div class="botfend-stat-icon"><span class="dashicons dashicons-yes-alt"></span></div>
                                <div class="botfend-stat-content">
                                    <h3 class="botfend-stat-title"><?php esc_html_e('Approved', 'botfend-anti-bot-firewall'); ?></h3>
                                    <p class="botfend-stat-value"><?php echo esc_html($approved_count); ?></p>
                                </div>
                            </div>

                            <div class="botfend-stat-card" style="--stat-color: #dc3545; --stat-bg: #f8d7da;">
                                <div class="botfend-stat-icon"><span class="dashicons dashicons-no-alt"></span></div>
                                <div class="botfend-stat-content">
                                    <h3 class="botfend-stat-title"><?php esc_html_e('Rejected', 'botfend-anti-bot-firewall'); ?></h3>
                                    <p class="botfend-stat-value"><?php echo esc_html($rejected_count); ?></p>
                                </div>
                            </div>

                            <div class="botfend-stat-card" style="--stat-color: #007cba; --stat-bg: #e7f3fe;">
                                <div class="botfend-stat-icon"><span class="dashicons dashicons-chart-bar"></span></div>
                                <div class="botfend-stat-content">
                                    <h3 class="botfend-stat-title"><?php esc_html_e('Total', 'botfend-anti-bot-firewall'); ?></h3>
                                    <p class="botfend-stat-value"><?php echo esc_html(count($all_requests)); ?></p>
                                </div>
                            </div>
                        </div>
                    </div>
                </details>
            </div>

            <div class="botfend-card botfend-mb-20">
                <details>
                    <summary class="botfend-section-summary">
                        <span class="dashicons dashicons-filter"></span>
                        <?php esc_html_e('Filter Requests', 'botfend-anti-bot-firewall'); ?>
                    </summary>
                    <div class="botfend-section-content">
                        <form method="get" class="botfend-filter-form">
                            <input type="hidden" name="page" value="botfend-unblock-requests">
                            <?php wp_nonce_field('botfend_admin_action'); ?>
                            <div class="botfend-filter-grid">
                                <div class="botfend-filter-group">
                                    <label for="filter-status" class="botfend-filter-label"><?php esc_html_e('Status', 'botfend-anti-bot-firewall'); ?></label>
                                    <select id="filter-status" name="status" class="botfend-filter-select">
                                        <option value=""><?php esc_html_e('All Statuses', 'botfend-anti-bot-firewall'); ?></option>
                                        <option value="pending" <?php selected($filters['status'], 'pending'); ?>><?php esc_html_e('Pending', 'botfend-anti-bot-firewall'); ?></option>
                                        <option value="approved" <?php selected($filters['status'], 'approved'); ?>><?php esc_html_e('Approved', 'botfend-anti-bot-firewall'); ?></option>
                                        <option value="rejected" <?php selected($filters['status'], 'rejected'); ?>><?php esc_html_e('Rejected', 'botfend-anti-bot-firewall'); ?></option>
                                    </select>
                                </div>
                                <div class="botfend-filter-group">
                                    <label for="filter-ip" class="botfend-filter-label"><?php esc_html_e('IP Address', 'botfend-anti-bot-firewall'); ?></label>
                                    <input type="text" id="filter-ip" name="filter_ip" class="botfend-filter-input" value="<?php echo esc_attr($filters['ip']); ?>" placeholder="<?php esc_attr_e('e.g., 192.168.1.1', 'botfend-anti-bot-firewall'); ?>">
                                </div>
                                <div class="botfend-filter-group">
                                    <label for="filter-email" class="botfend-filter-label"><?php esc_html_e('Email', 'botfend-anti-bot-firewall'); ?></label>
                                    <input type="text" id="filter-email" name="filter_email" class="botfend-filter-input" value="<?php echo esc_attr($filters['email']); ?>" placeholder="<?php esc_attr_e('user@example.com', 'botfend-anti-bot-firewall'); ?>">
                                </div>
                                <div class="botfend-filter-group">
                                    <label class="botfend-filter-label"><?php esc_html_e('Date Range', 'botfend-anti-bot-firewall'); ?></label>
                                    <div class="botfend-date-range">
                                        <input type="date" name="date_from" class="botfend-filter-input" value="<?php echo esc_attr($filters['date_from'] ?? ''); ?>">
                                        <span class="botfend-date-separator"><?php esc_html_e('to', 'botfend-anti-bot-firewall'); ?></span>
                                        <input type="date" name="date_to" class="botfend-filter-input" value="<?php echo esc_attr($filters['date_to'] ?? ''); ?>">
                                    </div>
                                </div>
                            </div>
                            <div class="botfend-filter-actions">
                                <button type="submit" class="button button-primary"><span class="dashicons dashicons-filter"></span> <?php esc_html_e('Apply Filters', 'botfend-anti-bot-firewall'); ?></button>
                                <a href="<?php echo esc_url(wp_nonce_url(admin_url('admin.php?page=botfend-unblock-requests'), 'botfend_admin_action')); ?>" class="button"><span class="dashicons dashicons-dismiss"></span> <?php esc_html_e('Clear Filters', 'botfend-anti-bot-firewall'); ?></a>
                            </div>
                        </form>
                    </div>
                </details>
            </div>

            <div id="botfend-bulk-bar" class="botfend-bulk-bar" style="display: none;">
                <div class="botfend-bulk-content">
                    <span class="botfend-bulk-count"><span id="selected-count">0</span> <?php esc_html_e('request(s) selected', 'botfend-anti-bot-firewall'); ?></span>
                    <select name="bulk_action" class="botfend-bulk-select" form="botfend-unblock-form">
                        <option value=""><?php esc_html_e('-- Bulk Actions --', 'botfend-anti-bot-firewall'); ?></option>
                        <option value="approve"><?php esc_html_e('Approve Selected', 'botfend-anti-bot-firewall'); ?></option>
                        <option value="reject"><?php esc_html_e('Reject Selected', 'botfend-anti-bot-firewall'); ?></option>
                        <option value="delete"><?php esc_html_e('Delete Selected', 'botfend-anti-bot-firewall'); ?></option>
                    </select>
                    <button type="submit" name="bulk_submit" class="button button-primary" form="botfend-unblock-form"><?php esc_html_e('Apply', 'botfend-anti-bot-firewall'); ?></button>
                    <button type="button" class="button" id="botfend-cancel-bulk"><?php esc_html_e('Clear Selection', 'botfend-anti-bot-firewall'); ?></button>
                </div>
            </div>

            <div class="botfend-card" style="padding: 0;">
                <details open>
                    <summary class="botfend-section-summary">
                        <span class="dashicons dashicons-list-view"></span>
                        <?php esc_html_e('Unblock Requests List', 'botfend-anti-bot-firewall'); ?>
                    </summary>
                    <div class="botfend-section-content" style="padding: 15px;">
                        <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" id="botfend-unblock-form">
                            <?php wp_nonce_field('botfend_bulk_unblock_action'); ?>
                            <input type="hidden" name="action" value="botfend_unblock_action">

                            <?php if (empty($requests)): ?>
                                <div class="notice notice-info botfend-notice"><p><?php esc_html_e('No unblock requests found.', 'botfend-anti-bot-firewall'); ?></p></div>
                            <?php else: ?>
                                <div class="botfend-table-responsive">
                                    <table class="wp-list-table widefat fixed striped botfend-unblock-table">
                                        <thead>
                                            <tr>
                                                <th class="botfend-col-check"><input type="checkbox" id="botfend-select-all"></th>
                                                <th class="botfend-col-id"><?php esc_html_e('ID', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-ip"><?php esc_html_e('IP Address', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-email"><?php esc_html_e('Email', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-reason"><?php esc_html_e('Reason', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-status"><?php esc_html_e('Status', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-date"><?php esc_html_e('Submitted', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-whitelist"><?php esc_html_e('Whitelist Request', 'botfend-anti-bot-firewall'); ?></th>
                                                <th class="botfend-col-actions"><?php esc_html_e('Actions', 'botfend-anti-bot-firewall'); ?></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php foreach ($requests as $request):
                                                $logs_url = admin_url('admin.php?page=botfend-logs&ip=' . urlencode($request->ip));
                                                $blocklist_url = admin_url('admin.php?page=botfend-blocklist&ip=' . urlencode($request->ip));
                                                $whitelist_requested = isset($request->request_whitelist) && $request->request_whitelist;
                                            ?>
                                            <tr class="botfend-request-row botfend-status-<?php echo esc_attr($request->status); ?>">
                                                <td class="botfend-col-check" data-label="<?php esc_attr_e('Select', 'botfend-anti-bot-firewall'); ?>">
                                                    <input type="checkbox" class="botfend-request-checkbox" name="bulk_ids[]" value="<?php echo esc_attr($request->id); ?>">
                                                </td>
                                                <td class="botfend-col-id" data-label="<?php esc_attr_e('ID', 'botfend-anti-bot-firewall'); ?>">
                                                    <code class="botfend-request-id"><?php echo esc_html($request->id); ?></code>
                                                </td>
                                                <td class="botfend-col-ip" data-label="<?php esc_attr_e('IP Address', 'botfend-anti-bot-firewall'); ?>">
                                                    <div class="botfend-ip-cell">
                                                        <strong class="botfend-ip-address"><?php echo esc_html($request->ip); ?></strong>
                                                        <div class="botfend-ip-actions">
                                                            <a href="<?php echo esc_url($logs_url); ?>" class="botfend-action-link" target="_blank"><span class="dashicons dashicons-list-view"></span><?php esc_html_e('Logs', 'botfend-anti-bot-firewall'); ?></a>
                                                            <a href="<?php echo esc_url($blocklist_url); ?>" class="botfend-action-link" target="_blank"><span class="dashicons dashicons-lock"></span><?php esc_html_e('Blocklist', 'botfend-anti-bot-firewall'); ?></a>
                                                        </div>
                                                    </div>
                                                </td>
                                                <td class="botfend-col-email" data-label="<?php esc_attr_e('Email', 'botfend-anti-bot-firewall'); ?>">
                                                    <a href="mailto:<?php echo esc_attr($request->email); ?>" class="botfend-email-link"><?php echo esc_html($request->email); ?></a>
                                                </td>
                                                <td class="botfend-col-reason" data-label="<?php esc_attr_e('Reason', 'botfend-anti-bot-firewall'); ?>">
                                                    <div class="botfend-reason-cell">
                                                        <?php if ($request->reason): ?>
                                                            <div class="botfend-reason-text" title="<?php echo esc_attr($request->reason); ?>"><?php echo esc_html($this->truncate_text($request->reason, 80)); ?></div>
                                                        <?php else: ?>
                                                            <em class="botfend-no-reason"><?php esc_html_e('No reason provided', 'botfend-anti-bot-firewall'); ?></em>
                                                        <?php endif; ?>
                                                    </div>
                                                </td>
                                                <td class="botfend-col-status" data-label="<?php esc_attr_e('Status', 'botfend-anti-bot-firewall'); ?>">
                                                    <span class="botfend-status-badge botfend-status-<?php echo esc_attr($request->status); ?>"><?php echo esc_html($this->get_status_label($request->status)); ?></span>
                                                    <?php if ($request->admin_action_by): ?>
                                                        <div class="botfend-admin-action"><span class="dashicons dashicons-admin-users"></span><?php echo esc_html($request->admin_action_by); ?></div>
                                                    <?php endif; ?>
                                                </td>
                                                <td class="botfend-col-date" data-label="<?php esc_attr_e('Submitted', 'botfend-anti-bot-firewall'); ?>">
                                                    <div class="botfend-date-cell">
                                                        <?php echo esc_html(date_i18n($date_format, strtotime($request->created_at))); ?>
                                                        <div class="botfend-time"><?php echo esc_html(date_i18n($time_format, strtotime($request->created_at))); ?></div>
                                                    </div>
                                                </td>
                                                <td class="botfend-col-whitelist" data-label="<?php esc_attr_e('Whitelist Request', 'botfend-anti-bot-firewall'); ?>">
                                                    <?php if ($whitelist_requested): ?>
                                                        <span class="botfend-status-badge botfend-status-approved" style="background: #d4edda; color: #155724;"><span class="dashicons dashicons-yes"></span><?php esc_html_e('Requested', 'botfend-anti-bot-firewall'); ?></span>
                                                    <?php else: ?>
                                                        <span class="botfend-status-badge botfend-status-pending" style="background: #fff3cd; color: #856404;"><span class="dashicons dashicons-no"></span><?php esc_html_e('Not Requested', 'botfend-anti-bot-firewall'); ?></span>
                                                    <?php endif; ?>
                                                </td>
                                                <td class="botfend-col-actions" data-label="<?php esc_attr_e('Actions', 'botfend-anti-bot-firewall'); ?>">
                                                    <div class="botfend-actions-cell">
                                                        <?php if ($request->status === 'pending'): ?>
                                                            <button type="submit" name="single_action" value="approve_<?php echo esc_attr($request->id); ?>" class="button button-small botfend-action-button botfend-action-approve"><span class="dashicons dashicons-yes"></span><?php esc_html_e('Approve', 'botfend-anti-bot-firewall'); ?></button>
                                                            <button type="submit" name="single_action" value="reject_<?php echo esc_attr($request->id); ?>" class="button button-small botfend-action-button botfend-action-reject" onclick="return confirm('<?php echo esc_js(esc_html__('Are you sure you want to reject this request?', 'botfend-anti-bot-firewall')); ?>');"><span class="dashicons dashicons-no"></span><?php esc_html_e('Reject', 'botfend-anti-bot-firewall'); ?></button>
                                                        <?php endif; ?>
                                                        <button type="submit" name="single_action" value="delete_<?php echo esc_attr($request->id); ?>" class="button button-small botfend-action-button botfend-action-delete" onclick="return confirm('<?php echo esc_js(esc_html__('Are you sure you want to delete this request? This action cannot be undone.', 'botfend-anti-bot-firewall')); ?>');"><span class="dashicons dashicons-trash"></span><?php esc_html_e('Delete', 'botfend-anti-bot-firewall'); ?></button>
                                                    </div>
                                                </td>
                                            </tr>
                                            <?php endforeach; ?>
                                        </tbody>
                                    </table>
                                </div>
                            <?php endif; ?>
                        </form>
                    </div>
                </details>
            </div>

            <div class="botfend-card">
                <details>
                    <summary class="botfend-section-summary">
                        <span class="dashicons dashicons-chart-bar"></span>
                        <?php esc_html_e('Quick Statistics', 'botfend-anti-bot-firewall'); ?>
                    </summary>
                    <div class="botfend-section-content">
                        <div class="botfend-stats-grid compact" style="margin-top: 15px;">
                            <?php
                            $total_processed = $approved_count + $rejected_count;
                            $approval_rate = $total_processed > 0 ? round(($approved_count / $total_processed) * 100, 1) : 0;
                            $oldest_pending = null;
                            foreach ($all_requests as $request) {
                                if ($request->status === 'pending' && (!$oldest_pending || strtotime($request->created_at) < strtotime($oldest_pending->created_at))) {
                                    $oldest_pending = $request;
                                }
                            }
                            $whitelist_count = 0;
                            foreach ($all_requests as $request) {
                                if (isset($request->request_whitelist) && $request->request_whitelist) $whitelist_count++;
                            }
                            ?>
                            <div class="botfend-stat-item"><span class="botfend-stat-item-label"><?php esc_html_e('Total Requests:', 'botfend-anti-bot-firewall'); ?></span><span class="botfend-stat-item-value"><?php echo esc_html(count($all_requests)); ?></span></div>
                            <div class="botfend-stat-item"><span class="botfend-stat-item-label"><?php esc_html_e('Pending Requests:', 'botfend-anti-bot-firewall'); ?></span><span class="botfend-stat-item-value"><?php echo esc_html($pending_count); ?></span></div>
                            <div class="botfend-stat-item"><span class="botfend-stat-item-label"><?php esc_html_e('Approval Rate:', 'botfend-anti-bot-firewall'); ?></span><span class="botfend-stat-item-value"><?php echo esc_html($approval_rate); ?>%</span></div>
                            <div class="botfend-stat-item"><span class="botfend-stat-item-label"><?php esc_html_e('Whitelist Requests:', 'botfend-anti-bot-firewall'); ?></span><span class="botfend-stat-item-value"><?php echo esc_html($whitelist_count); ?></span></div>
                        </div>
                    </div>
                </details>
            </div>
        </div>
        <?php
    }
}