
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
if ( ! class_exists('WP_List_Table')) {
    require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}

use GigaAI\Core\Logger as Logger;

/**
 * Create a new table class that will extend the WP_List_Table
 */
class Logger_List_Table extends \WP_List_Table
{
    public $items = [];
    
    public $per_page = 20;
    
    public $total = 0;
    
    /**
     * Prepare the items for the table to process
     *
     * @return Void
     */
    public function prepare_items()
    {
        $columns = $this->get_columns();
        $hidden = $this->get_hidden_columns();
        $sortable = $this->get_sortable_columns();
        
        $this->_column_headers = [$columns, $hidden, $sortable];
        
        $this->items = Logger::get();
        
        if ( ! empty($this->items)) {
            rsort($this->items);
        }
    }
    
    /**
     * Override the parent columns method. Defines the columns to use in your listing table
     *
     * @return array
     */
    public function get_columns()
    {
        return [
            'timestamp' => __('Timestamp', 'giga-messenger-bots'),
            'incoming'  => __('Server Received', 'giga-messenger-bots'),
            'outcoming' => __('Send Back', 'giga-messenger-bots'),
            'response'  => __('Result', 'giga-messenger-bots'),
        ];
    }
    
    /**
     * Define which columns are hidden
     *
     * @return array
     */
    public function get_hidden_columns()
    {
        return [];
    }
    
    /**
     * Define what data to show on each column of the table
     *
     * @param  array  $item        Data
     * @param  String $column_name - Current column name
     *
     * @return Mixed
     */
    public function column_default($item, $column_name)
    {
        if ( ! isset($item[$column_name])) {
            return '';
        }
        
        if ( ! is_string($item[$column_name])) {
            $item[$column_name] = '<div class="debug-col"><pre>' . var_export($item[$column_name], true) . '</pre></div>';
        }
        
        return $item[$column_name];
    }
}