'payment',
            'plural' => 'payments',
            'ajax'   => false
        ));
    }
    function extra_tablenav($which) {
        if ($which == "top") {
            $hidden_fields = wp_nonce_field() . wp_referer_field();
            $tab_info = array(
                'all' => array(),
                'pending' => array(),
                'paid' => array(),
                'confirmed' => array(),
                'expired' => array(),
            );
            foreach($tab_info as $type=>&$info) {
                $info['active'] = '';
                $info['count'] = $this->get_item_count($type);
            }
            if(isset($_GET['type'])) {
                switch($_GET['type']) {
                case 'all':
                    $tab_info['all']['active'] = 'class="current" aria-current="page"';
                    break;
                case 'pending':
                    $tab_info['pending']['active'] = 'class="current" aria-current="page"';
                    break;
                case 'paid':
                    $tab_info['paid']['active'] = 'class="current" aria-current="page"';
                    break;
                case 'confirmed':
                    $tab_info['confirmed']['active'] = 'class="current" aria-current="page"';
                    break;
                case 'expired':
                    $tab_info['expired']['active'] = 'class="current" aria-current="page"';
                    break;
                }
            } else {
                $tab_info['all']['active'] = 'class="current" aria-current="page"';
            }
            if(Monero_Gateway::get_confirm_type() == 'monero-wallet-rpc') {
                $balance = Monero_Gateway::admin_balance_info();
                $balance_info = <<
    Wallet height: {$balance['height']}
    Your balance is: {$balance['balance']}
    Unlocked balance: {$balance['unlocked_balance']}
HTML;
            } else {
                $balance_info = '';
            }
            echo <<
                
Monero Payments
                $balance_info
                
                
                
                Monero Payments List
                
                
HTML;
        } else if ($which == "bottom") {
            echo '
';
        }
    }
    /**
     * Get column value.
     *
     * @param mixed  $item Item being displayed.
     * @param string $column_name Column name.
     */
    public function column_default($item, $column_name) {
        switch($column_name) {
        case 'col_order_id':
            echo $this->get_order_link($item->order_id);
            break;
        case 'col_payment_id':
            echo $item->payment_id;
            break;
        case 'col_txid':
            $url = MONERO_GATEWAY_EXPLORER_URL.'/tx/'.$item->txid;
            echo ''.$item->txid.'';
            break;
        case 'col_height':
            echo $item->height;
            break;
        case 'col_amount':
            echo Monero_Gateway::format_monero($item->amount).' Monero';
            break;
        }
    }
    protected function get_order_link($order_id) {
        $order = new WC_Order($order_id);
        $buyer = '';
        if($order->get_billing_first_name() || $order->get_billing_last_name()) {
            $buyer = trim(sprintf(_x('%1$s %2$s', 'full name', 'woocommerce'), $order->get_billing_first_name(), $order->get_billing_last_name()));
        } else if ($order->get_billing_company()) {
            $buyer = trim($order->get_billing_company());
        } else if ($order->get_customer_id()) {
            $user = get_user_by('id', $order->get_customer_id());
            $buyer = ucwords($user->display_name);
        }
        return '#' . esc_attr( $order->get_order_number() ) . ' ' . esc_html( $buyer ) . '';
    }
    function get_columns() {
        return $columns= array(
            'col_order_id' => __('Order'),
            'col_payment_id' => __('Payment ID'),
            'col_txid' => __('Txid'),
            'col_height' => __('Height'),
            'col_amount' => __('Amount'),
        );
    }
    public function get_sortable_columns() {
        return array();
        return $sortable = array(
            'col_order_id' => 'col_order_id',
            'col_payment_id' => 'payment_id',
            'col_txid' => 'txid',
            'col_height' => 'height',
            'col_amount' => 'amount',
        );
    }
    function prepare_items() {
        $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns());
        $current_page = absint($this->get_pagenum());
        $per_page = 25;
        $this->get_items($current_page, $per_page);
    }
    public function no_items() {
        esc_html_e('No Monero payments found', 'monero_gateway');
    }
    protected function get_filter_vars() {
        $type = isset($_GET['type']) ? $_GET['type'] : null;
        return (object) array(
            'type' => $type,
        );
    }
    protected function get_item_count($type) {
        global $wpdb;
        $table_name_1 = $wpdb->prefix.'monero_gateway_quotes';
        $table_name_2 = $wpdb->prefix.'monero_gateway_quotes_txids';
        $query_where = ' WHERE 1=1 '.$this->get_clause_type($type);
        $query = "SELECT COUNT(*) AS count FROM {$table_name_2} t2 LEFT JOIN $table_name_1 t1 ON t2.payment_id = t1.payment_id {$query_where}";
        $item_count = $wpdb->get_var($query);
        if(is_null($item_count)) $item_count = 0;
        return $item_count;
    }
    protected function get_clause_type($type) {
        global $wpdb;
        switch($type) {
        case 'pending':
            $query_where = $wpdb->prepare(' AND pending = 1 AND paid = 0 ', array());
            break;
        case 'paid':
            $query_where = $wpdb->prepare(' AND paid = 1 AND confirmed = 0 ', array());
            break;
        case 'confirmed':
            $query_where = $wpdb->prepare(' AND confirmed = 1 ', array());
            break;
        case 'expired':
            $query_where = $wpdb->prepare(' AND paid = 0 AND pending = 0 ', array());
            break;
        case 'all':
        default:
            $query_where = ' ';
        }
        return $query_where;
    }
    public function get_items($current_page, $per_page) {
        global $wpdb;
        $this->items = array();
        $filters = $this->get_filter_vars();
        $table_name_1 = $wpdb->prefix.'monero_gateway_quotes';
        $table_name_2 = $wpdb->prefix.'monero_gateway_quotes_txids';
        $query_where = ' WHERE 1=1 ';
        $query_where .= $this->get_clause_type($filters->type);
        $query_order = $wpdb->prepare('ORDER BY id DESC LIMIT %d, %d;', ($current_page-1)*$per_page, $per_page);
        $query = "SELECT t1.order_id, t1.confirmed, t1.paid, t1.pending, t2.* FROM {$table_name_2} t2 LEFT JOIN $table_name_1 t1 ON t2.payment_id = t1.payment_id {$query_where} {$query_order}";
        $this->items = $wpdb->get_results($query);
        $max_items = $this->get_item_count($filters->type);
        $this->set_pagination_args(
            array(
                'total_items' => $max_items,
                'per_page'    => $per_page,
                'total_pages' => ceil($max_items/$per_page),
            )
        );
    }
}