/**
     * Show the contents of the panel
     */
    public function render()
    {
        if (!function_exists('ep_get_query_log')) {
            esc_html_e('ElasticPress not activated or not at least version 1.8.', 'debug-bar');
            return;
        }
        $queries = ep_get_query_log();
        $total_query_time = 0;
        foreach ($queries as $query) {
            if (!empty($query['time_start']) && !empty($query['time_finish'])) {
                $total_query_time += $query['time_finish'] - $query['time_start'];
            }
        }
        ?>

		<h2><?php 
        printf(__('<span>Total ElasticPress Queries:</span> %d', 'debug-bar'), count($queries));
        ?>
</h2>
		<h2><?php 
        printf(__('<span>Total Blocking ElasticPress Query Time:</span> %d ms', 'debug-bar'), (int) ($total_query_time * 1000));
        ?>
</h2><?php 
        if (empty($queries)) {
            ?>
<ol class="wpd-queries">
				<li><?php 
            esc_html_e('No queries to show', 'debug-bar');
            ?>
</li>
			</ol><?php 
        } else {
            ?>
<ol class="wpd-queries ep-queries-debug"><?php 
            foreach ($queries as $query) {
                $query_time = !empty($query['time_start']) && !empty($query['time_finish']) ? $query['time_finish'] - $query['time_start'] : false;
                $result = wp_remote_retrieve_body($query['request']);
                $response = wp_remote_retrieve_response_code($query['request']);
                $class = $response < 200 || $response >= 300 ? 'ep-query-failed' : '';
                ?>
<li class="ep-query-debug hide-query-body hide-query-results hide-query-args <?php 
                echo sanitize_html_class($class);
                ?>
">
						<div class="ep-query-host">
							<strong><?php 
                esc_html_e('Host:', 'debug-bar');
                ?>
</strong>
							<?php 
                echo esc_html($query['host']);
                ?>
						</div>

						<div class="ep-query-time"><?php 
                if (!empty($query_time)) {
                    printf(__('<strong>Time Taken:</strong> %d ms', 'debug-bar'), $query_time * 1000);
                } else {
                    _e('<strong>Time Taken:</strong> -', 'debug-bar');
                }
                ?>
</div>

						<div class="ep-query-url">
							<strong><?php 
                esc_html_e('URL:', 'debug-bar');
                ?>
</strong>
							<?php 
                echo esc_url($query['url']);
                ?>
						</div>

						<div class="ep-query-method">
							<strong><?php 
                esc_html_e('Method:', 'debug-bar');
                ?>
</strong>
							<?php 
                echo esc_html($query['args']['method']);
                ?>
						</div>

						<?php 
                if (!empty($query['query_args'])) {
                    ?>
							<div clsas="ep-query-args">
								<strong><?php 
                    esc_html_e('Query Args:', 'debug-bar');
                    ?>
 <div class="query-args-toggle dashicons"></div></strong>
								<pre class="query-args"><?php 
                    echo var_dump($query['query_args']);
                    ?>
</pre>
							</div>
						<?php 
                }
                ?>

						<div clsas="ep-query-body">
							<strong><?php 
                esc_html_e('Query Body:', 'debug-bar');
                ?>
 <div class="query-body-toggle dashicons"></div></strong>
							<pre class="query-body"><?php 
                echo esc_html(stripslashes(json_encode(json_decode($query['args']['body'], true), JSON_PRETTY_PRINT)));
                ?>
</pre>
						</div>

						<div class="ep-query-response-code">
							<?php 
                printf(__('<strong>Query Response Code:</strong> HTTP %d', 'debug-bar'), (int) $response);
                ?>
						</div>

						<div class="ep-query-result">
							<strong><?php 
                esc_html_e('Query Result:', 'debug-bar');
                ?>
 <div class="query-result-toggle dashicons"></div></strong>
							<pre class="query-results"><?php 
                echo esc_html(stripslashes(json_encode(json_decode($result, true), JSON_PRETTY_PRINT)));
                ?>
</pre>
						</div>
					</li><?php 
            }
            ?>
</ol><?php 
        }
    }
    /**
     * Show the contents of the panel
     */
    public function render()
    {
        $queries = ep_get_query_log();
        $total_query_time = 0;
        foreach ($queries as $query) {
            if (!empty($query['time_start']) && !empty($query['time_finish'])) {
                $total_query_time += $query['time_finish'] - $query['time_start'];
            }
        }
        ?>

		<h2><?php 
        printf(__('<span>Total ElasticPress Queries:</span> %d', 'debug-bar'), count($queries));
        ?>
</h2>
		<h2><?php 
        printf(__('<span>Total Blocking ElasticPress Query Time:</span> %d ms', 'debug-bar'), (int) ($total_query_time * 1000));
        ?>
</h2>

		<?php 
        if (empty($queries)) {
            ?>
			<ol class="wpd-queries">
				<li><?php 
            esc_html_e('No queries to show', 'debug-bar');
            ?>
</li>
			</ol>
		<?php 
        } else {
            ?>
			<ol class="wpd-queries">
				<?php 
            foreach ($queries as $query) {
                $query_time = !empty($query['time_start']) && !empty($query['time_finish']) ? $query['time_finish'] - $query['time_start'] : false;
                $response = wp_remote_retrieve_response_code($query['request']);
                if ($response >= 200 && $response < 300) {
                    $result = wp_remote_retrieve_body($query['request']);
                }
                ?>
					<li>
						<strong><?php 
                esc_html_e('Host:', 'debug-bar');
                ?>
</strong> <?php 
                echo esc_html($query['host']);
                ?>
<br>
						<?php 
                if (!empty($query_time)) {
                    ?>
							<?php 
                    printf(__('<strong>Time Taken:</strong> %d ms', 'debug-bar'), $query_time * 1000);
                    ?>
<br>
						<?php 
                } else {
                    ?>
							<?php 
                    _e('<strong>Time Taken:</strong> -', 'debug-bar');
                    ?>
<br>
						<?php 
                }
                ?>
						<strong><?php 
                esc_html_e('URL:', 'debug-bar');
                ?>
</strong> <?php 
                echo esc_url($query['url']);
                ?>
<br>
						<strong><?php 
                esc_html_e('Method:', 'debug-bar');
                ?>
</strong> <?php 
                echo esc_html($query['args']['method']);
                ?>
<br>
						<strong><?php 
                esc_html_e('Query Body:', 'debug-bar');
                ?>
</strong> <pre><?php 
                echo json_encode(json_decode($query['args']['body'], true), JSON_PRETTY_PRINT);
                ?>
</pre><br>
						<?php 
                printf(__('<strong>Query Response Code:</strong> HTTP %d', 'debug-bar'), (int) $response);
                ?>
<br>
						<?php 
                if (200 <= $response && $response < 300) {
                    ?>
							<strong><?php 
                    esc_html_e('Query Result:', 'debug-bar');
                    ?>
</strong> <pre><?php 
                    echo json_encode(json_decode($result, true), JSON_PRETTY_PRINT);
                    ?>
</pre><br>
						<?php 
                }
                ?>

					</li>
				<?php 
            }
            ?>
			</ol>
		<?php 
        }
        ?>

		<?php 
    }