<?php
/**
 * Code Snippet List Table
 *
 * Standard WordPress list table for code snippets (like Posts/Pages).
 *
 * @package CodeSnippet
 * @since 1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'WP_List_Table' ) ) {
	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}

/**
 * Class Code_Snippet_List_Table
 */
class Code_Snippet_List_Table extends WP_List_Table {

	/**
	 * Module instance.
	 *
	 * @var \CodeSnippet\Module
	 */
	private $module;

	/**
	 * Status filter: all, active, inactive.
	 *
	 * @var string
	 */
	private $status_filter;

	/**
	 * Search query.
	 *
	 * @var string
	 */
	private $search_query;

	/**
	 * Code type filter: html, css, js, php, or empty.
	 *
	 * @var string
	 */
	private $type_filter;

	/**
	 * Location slug filter, or empty.
	 *
	 * @var string
	 */
	private $location_filter;

	/**
	 * Device filter: all, desktop, mobile, tablet, or empty.
	 *
	 * @var string
	 */
	private $device_filter;

	/**
	 * Constructor.
	 *
	 * @param \CodeSnippet\Module     $module  Module instance.
	 * @param string                  $status  Status filter (all, active, inactive).
	 * @param string                  $search  Search query.
	 * @param array<string, string>   $filters Optional type/location/device filters.
	 */
	public function __construct( $module, $status = 'all', $search = '', array $filters = [] ) {
		$this->module          = $module;
		$this->status_filter   = $status;
		$this->search_query    = $search;
		$this->type_filter     = isset( $filters['type'] ) ? sanitize_key( (string) $filters['type'] ) : '';
		$this->location_filter = isset( $filters['location'] ) ? sanitize_key( (string) $filters['location'] ) : '';
		$this->device_filter   = isset( $filters['device'] ) ? sanitize_key( (string) $filters['device'] ) : '';
		parent::__construct(
			[
				'singular' => 'snippet',
				'plural'   => 'snippets',
				'ajax'     => false,
			]
		);
	}

	/**
	 * Read a scalar request value. Arrays are rejected.
	 */
	private static function requestScalar( string $key ): string {
		if ( ! isset( $_REQUEST[ $key ] ) || is_array( $_REQUEST[ $key ] ) ) {
			return '';
		}
		return (string) wp_unslash( $_REQUEST[ $key ] );
	}

	/**
	 * Sanitize list filters from the current request.
	 *
	 * @return array{status: string, search: string, type: string, location: string, device: string, orderby: string, order: string, paged: int}
	 */
	public static function filtersFromRequest(): array {
		$status = sanitize_key( self::requestScalar( 'status' ) );
		if ( ! in_array( $status, [ 'all', 'active', 'inactive' ], true ) ) {
			$status = 'all';
		}
		$search = sanitize_text_field( self::requestScalar( 's' ) );
		if ( strlen( $search ) > 200 ) {
			$search = function_exists( 'mb_substr' ) ? mb_substr( $search, 0, 200 ) : substr( $search, 0, 200 );
		}
		$type = sanitize_key( self::requestScalar( 'snippet_type' ) );
		if ( ! in_array( $type, [ 'html', 'css', 'js', 'php' ], true ) ) {
			$type = '';
		}
		$location = sanitize_key( self::requestScalar( 'snippet_location' ) );
		if ( $location !== '' && ! in_array( $location, \CodeSnippet\Module::getAllLocationSlugs(), true ) ) {
			$location = '';
		}
		$device = sanitize_key( self::requestScalar( 'snippet_device' ) );
		if ( ! in_array( $device, [ 'all', 'desktop', 'mobile', 'tablet' ], true ) ) {
			$device = '';
		}
		$orderby = sanitize_key( self::requestScalar( 'orderby' ) );
		if ( ! in_array( $orderby, [ 'title', 'ID', 'author', 'date', 'modified', 'priority' ], true ) ) {
			$orderby = '';
		}
		$order = strtolower( sanitize_text_field( self::requestScalar( 'order' ) ) );
		if ( ! in_array( $order, [ 'asc', 'desc' ], true ) ) {
			$order = '';
		}
		$paged = absint( self::requestScalar( 'paged' ) );
		if ( $paged > 10000 ) {
			$paged = 10000;
		}
		return [
			'status'   => $status,
			'search'   => $search,
			'type'     => $type,
			'location' => $location,
			'device'   => $device,
			'orderby'  => $orderby,
			'order'    => $order,
			'paged'    => $paged,
		];
	}

	/**
	 * @param array{status: string, search: string, type: string, location: string, device: string, orderby?: string, order?: string, paged?: int} $filters
	 */
	public static function urlFromFilters( array $filters ): string {
		$args = [ 'page' => 'powersuite-code-snippet' ];
		if ( ( $filters['status'] ?? 'all' ) !== 'all' ) {
			$args['status'] = $filters['status'];
		}
		if ( ( $filters['search'] ?? '' ) !== '' ) {
			$args['s'] = $filters['search'];
		}
		if ( ( $filters['type'] ?? '' ) !== '' ) {
			$args['snippet_type'] = $filters['type'];
		}
		if ( ( $filters['location'] ?? '' ) !== '' ) {
			$args['snippet_location'] = $filters['location'];
		}
		if ( ( $filters['device'] ?? '' ) !== '' ) {
			$args['snippet_device'] = $filters['device'];
		}
		if ( ( $filters['orderby'] ?? '' ) !== '' ) {
			$args['orderby'] = $filters['orderby'];
		}
		if ( ( $filters['order'] ?? '' ) !== '' ) {
			$args['order'] = $filters['order'];
		}
		if ( ! empty( $filters['paged'] ) && (int) $filters['paged'] > 1 ) {
			$args['paged'] = (int) $filters['paged'];
		}
		return add_query_arg( $args, admin_url( 'admin.php' ) );
	}

	/**
	 * Render list markup with REQUEST_URI pointing at the admin list URL
	 * so pagination, sort links, and the bulk-action referer stay valid.
	 *
	 * @param \CodeSnippet\Module $module Module instance.
	 * @param array<string, mixed>|null $filters Optional pre-parsed filters.
	 */
	public static function renderAppInnerToString( $module, ?array $filters = null ): string {
		$filters = is_array( $filters ) ? $filters : self::filtersFromRequest();
		$backup  = isset( $_SERVER['REQUEST_URI'] ) ? (string) $_SERVER['REQUEST_URI'] : '';
		$list    = self::urlFromFilters( $filters );
		$path    = wp_parse_url( $list, PHP_URL_PATH );
		$query   = wp_parse_url( $list, PHP_URL_QUERY );
		$_SERVER['REQUEST_URI'] = ( is_string( $path ) ? $path : '/wp-admin/admin.php' ) . ( is_string( $query ) && $query !== '' ? '?' . $query : '' );
		ob_start();
		try {
			self::renderAppInner( $module, $filters );
			$html = (string) ob_get_clean();
		} catch ( \Throwable $e ) {
			ob_end_clean();
			$_SERVER['REQUEST_URI'] = $backup;
			throw $e;
		}
		$_SERVER['REQUEST_URI'] = $backup;
		return $html;
	}

	/**
	 * Views + table (or empty state) used by the list page and AJAX refresh.
	 *
	 * @param \CodeSnippet\Module $module Module instance.
	 * @param array<string, string>|null $filters Optional pre-parsed filters.
	 */
	public static function renderAppInner( $module, ?array $filters = null ): void {
		$filters = is_array( $filters ) ? $filters : self::filtersFromRequest();
		$table   = new self(
			$module,
			$filters['status'],
			$filters['search'],
			[
				'type'     => $filters['type'],
				'location' => $filters['location'],
				'device'   => $filters['device'],
			]
		);
		$table->prepare_items();
		if ( (int) $module->getSnippetCounts()['all'] === 0 ) {
			?>
			<div class="wpps-cs-empty-state">
				<div class="wpps-cs-empty-icon">
					<span class="dashicons dashicons-editor-code"></span>
				</div>
				<h3 class="wpps-cs-empty-title"><?php esc_html_e( 'No code snippets yet', 'wppowersuite-lite' ); ?></h3>
				<p class="wpps-cs-empty-desc"><?php esc_html_e( 'Create your first snippet to add custom code to your site\'s header, footer, or anywhere via shortcode.', 'wppowersuite-lite' ); ?></p>
				<div class="wpps-cs-empty-actions">
					<a href="<?php echo esc_url( admin_url( 'admin.php?page=powersuite-code-snippet&action=add' ) ); ?>" class="wpps-cs-empty-btn">
						<span class="dashicons dashicons-plus-alt"></span>
						<?php esc_html_e( 'Add Snippet', 'wppowersuite-lite' ); ?>
					</a>
					<button type="button" class="button button-secondary wpps-cs-import-toggle">
						<?php esc_html_e( 'Import JSON', 'wppowersuite-lite' ); ?>
					</button>
				</div>
			</div>
			<?php
			return;
		}
		$table->views();
		?>
		<form method="get" action="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>" id="wpps-cs-list-form">
			<?php wp_nonce_field( 'bulk-snippets' ); ?>
			<input type="hidden" name="page" value="powersuite-code-snippet" />
			<input type="hidden" name="status" value="<?php echo esc_attr( $filters['status'] ); ?>" />
			<?php $table->search_box( __( 'Search snippets', 'wppowersuite-lite' ), 'snippet' ); ?>
			<?php $table->display(); ?>
		</form>
		<?php
	}

	/**
	 * Get table columns.
	 *
	 * @return array
	 */
	public function get_columns() {
		return [
			'cb'       => '<input type="checkbox" />',
			'title'    => __( 'Title', 'wppowersuite-lite' ),
			'author'   => __( 'Author', 'wppowersuite-lite' ),
			'id'       => __( 'ID', 'wppowersuite-lite' ),
			'type'     => __( 'Type', 'wppowersuite-lite' ),
			'location' => __( 'Location', 'wppowersuite-lite' ),
			'priority' => __( 'Priority', 'wppowersuite-lite' ),
			'created'  => __( 'Created', 'wppowersuite-lite' ),
			'status'   => __( 'Status', 'wppowersuite-lite' ),
		];
	}

	/**
	 * Get sortable columns.
	 *
	 * @return array
	 */
	protected function get_sortable_columns() {
		return [
			'title'    => [ 'title', false ],
			'author'   => [ 'author', false ],
			'id'       => [ 'ID', false ],
			'priority' => [ 'priority', false ],
			'created'  => [ 'date', false ],
		];
	}

	/**
	 * Get bulk actions.
	 *
	 * @return array
	 */
	protected function get_bulk_actions() {
		return [
			'activate'   => __( 'Activate', 'wppowersuite-lite' ),
			'deactivate' => __( 'Deactivate', 'wppowersuite-lite' ),
			'export'     => __( 'Export', 'wppowersuite-lite' ),
			'delete'     => __( 'Delete', 'wppowersuite-lite' ),
		];
	}

	/**
	 * Prepare items for display.
	 */
	public function prepare_items() {
		$args = [
			'orderby' => 'modified',
			'order'   => 'DESC',
		];
		if ( isset( $_REQUEST['orderby'] ) ) {
			$ob = sanitize_key( wp_unslash( $_REQUEST['orderby'] ) );
			if ( in_array( $ob, [ 'title', 'ID', 'author', 'date', 'modified', 'priority' ], true ) ) {
				$args['orderby'] = $ob;
			}
		}
		if ( isset( $_REQUEST['order'] ) && strtolower( wp_unslash( $_REQUEST['order'] ) ) === 'asc' ) {
			$args['order'] = 'ASC';
		}
		if ( $this->status_filter === 'active' ) {
			$args['post_status'] = 'publish';
		} elseif ( $this->status_filter === 'inactive' ) {
			$args['post_status'] = 'draft';
		} else {
			$args['post_status'] = 'any';
		}
		if ( $this->search_query !== '' ) {
			$args['s'] = $this->search_query;
		}
		$meta_query = [];
		if ( $this->type_filter !== '' ) {
			$meta_query[] = [
				'key'   => '_wpps_code_type',
				'value' => $this->type_filter,
			];
		}
		if ( $this->location_filter !== '' ) {
			$meta_query[] = [
				'key'   => '_wpps_location',
				'value' => $this->location_filter,
			];
		}
		if ( $this->device_filter !== '' ) {
			$meta_query[] = [
				'key'   => '_wpps_device_type',
				'value' => $this->device_filter,
			];
		}
		if ( $meta_query !== [] ) {
			if ( count( $meta_query ) > 1 ) {
				$meta_query['relation'] = 'AND';
			}
			// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- admin list filters by snippet meta.
			$args['meta_query'] = $meta_query;
		}
		$this->items = $this->module->getAllSnippets( $args );
		$this->_column_headers = [
			$this->get_columns(),
			[],
			$this->get_sortable_columns(),
			'title',
		];
	}

	/**
	 * Default column output.
	 *
	 * @param \WP_Post $item        Snippet post.
	 * @param string   $column_name Column name.
	 * @return string
	 */
	protected function column_default( $item, $column_name ) {
		return '';
	}

	/**
	 * Checkbox column.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_cb( $item ) {
		return sprintf(
			'<input type="checkbox" name="snippet[]" value="%d" />',
			(int) $item->ID
		);
	}

	/**
	 * Title column with row actions.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_title( $item ) {
		$edit_url = admin_url( 'admin.php?page=powersuite-code-snippet&action=edit&id=' . $item->ID );
		$title    = $item->post_title ?: __( '(no title)', 'wppowersuite-lite' );
		$actions  = [
			'edit' => sprintf(
				'<a href="%s">%s</a>',
				esc_url( $edit_url ),
				__( 'Edit', 'wppowersuite-lite' )
			),
		];
		$active = $item->post_status === 'publish';
		if ( $active ) {
			$actions['deactivate'] = sprintf(
				'<a href="%s" class="submitdelete">%s</a>',
				esc_url( wp_nonce_url( admin_url( 'admin.php?page=powersuite-code-snippet&action=deactivate&id=' . $item->ID ), 'deactivate-snippet_' . $item->ID ) ),
				__( 'Deactivate', 'wppowersuite-lite' )
			);
		} else {
			$actions['activate'] = sprintf(
				'<a href="%s">%s</a>',
				esc_url( wp_nonce_url( admin_url( 'admin.php?page=powersuite-code-snippet&action=activate&id=' . $item->ID ), 'activate-snippet_' . $item->ID ) ),
				__( 'Activate', 'wppowersuite-lite' )
			);
		}
		$actions['export'] = sprintf(
			'<a href="%s">%s</a>',
			esc_url( \CodeSnippet\ImportExport::exportUrl( (int) $item->ID ) ),
			__( 'Export', 'wppowersuite-lite' )
		);
		$actions['delete'] = sprintf(
			'<a href="#" class="submitdelete wpps-cs-delete-link" data-id="%d">%s</a>',
			(int) $item->ID,
			__( 'Delete', 'wppowersuite-lite' )
		);
		$row_actions = $this->row_actions( $actions );
		$html        = '<strong><a href="' . esc_url( $edit_url ) . '" class="row-title">' . esc_html( $title ) . '</a></strong>' . $row_actions;
		$raw_err     = get_post_meta( $item->ID, '_wpps_last_php_error', true );
		$err         = is_string( $raw_err ) ? json_decode( $raw_err, true ) : null;
		if ( is_array( $err ) && ! empty( $err['message'] ) ) {
			$html .= '<div class="wpps-cs-row-php-error">' . esc_html( (string) $err['message'] ) . '</div>';
		}
		return $html;
	}

	/**
	 * Author column.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_author( $item ) {
		$author = get_userdata( $item->post_author );
		return $author ? esc_html( $author->display_name ?: $author->user_login ) : '—';
	}

	/**
	 * ID column.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_id( $item ) {
		$shortcode = sprintf( '[wpps_code id="%d"]', $item->ID );
		return '<code title="' . esc_attr( $shortcode ) . '">' . (int) $item->ID . '</code>';
	}

	/**
	 * Type column with colored badges.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_type( $item ) {
		$types = [
			'html' => __( 'HTML', 'wppowersuite-lite' ),
			'css'  => __( 'CSS', 'wppowersuite-lite' ),
			'js'   => __( 'JavaScript', 'wppowersuite-lite' ),
			'php'  => __( 'PHP', 'wppowersuite-lite' ),
		];
		$type = get_post_meta( $item->ID, '_wpps_code_type', true ) ?: 'html';
		$label = $types[ $type ] ?? $type;
		return '<span class="wpps-cs-type-badge wpps-cs-type-' . esc_attr( $type ) . '">' . esc_html( $label ) . '</span>';
	}

	/**
	 * Location column.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_location( $item ) {
		$loc = get_post_meta( $item->ID, '_wpps_location', true ) ?: 'footer';
		$locations = \CodeSnippet\Module::getLocations();
		$label = $loc === 'shortcode' ? __( 'Shortcode', 'wppowersuite-lite' ) : ( $locations[ $loc ] ?? $loc );
		return esc_html( $label );
	}

	/**
	 * Priority column.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_priority( $item ) {
		$prio = (int) ( get_post_meta( $item->ID, '_wpps_priority', true ) ?: 10 );
		return (string) $prio;
	}

	/**
	 * Created column.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_created( $item ) {
		return esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $item->post_date ) ) );
	}

	/**
	 * Status column with toggle.
	 *
	 * @param \WP_Post $item Snippet post.
	 * @return string
	 */
	protected function column_status( $item ) {
		$active = $item->post_status === 'publish';
		$id     = (int) $item->ID;
		$label  = $active ? __( 'Active', 'wppowersuite-lite' ) : __( 'Inactive', 'wppowersuite-lite' );
		return sprintf(
			'<label class="wpps-cs-status-toggle" title="%s">
				<input type="checkbox" class="wpps-cs-status-switch" data-id="%d" %s>
				<span class="wpps-cs-status-slider"></span>
				<span class="wpps-cs-status-label">%s</span>
			</label>',
			esc_attr( $active ? __( 'Deactivate', 'wppowersuite-lite' ) : __( 'Activate', 'wppowersuite-lite' ) ),
			$id,
			$active ? 'checked' : '',
			esc_html( $label )
		);
	}

	/**
	 * Message when no items.
	 */
	public function no_items() {
		esc_html_e( 'No code snippets found.', 'wppowersuite-lite' );
	}

	/**
	 * Query args for the active type/location/device filters.
	 *
	 * @return array<string, string>
	 */
	private function getActiveFilterArgs(): array {
		$args = [];
		if ( $this->type_filter !== '' ) {
			$args['snippet_type'] = $this->type_filter;
		}
		if ( $this->location_filter !== '' ) {
			$args['snippet_location'] = $this->location_filter;
		}
		if ( $this->device_filter !== '' ) {
			$args['snippet_device'] = $this->device_filter;
		}
		if ( $this->search_query !== '' ) {
			$args['s'] = $this->search_query;
		}
		return $args;
	}

	/**
	 * Type, location, and device filters above the table.
	 *
	 * @param string $which Top or bottom.
	 */
	protected function extra_tablenav( $which ) {
		if ( $which !== 'top' ) {
			return;
		}
		$types = [
			'html' => __( 'HTML', 'wppowersuite-lite' ),
			'css'  => __( 'CSS', 'wppowersuite-lite' ),
			'js'   => __( 'JavaScript', 'wppowersuite-lite' ),
			'php'  => __( 'PHP', 'wppowersuite-lite' ),
		];
		$devices = [
			'all'     => __( 'All devices', 'wppowersuite-lite' ),
			'desktop' => __( 'Desktop', 'wppowersuite-lite' ),
			'mobile'  => __( 'Mobile', 'wppowersuite-lite' ),
			'tablet'  => __( 'Tablet', 'wppowersuite-lite' ),
		];
		?>
		<div class="alignleft actions wpps-cs-filters">
			<label for="wpps-cs-filter-type" class="screen-reader-text"><?php esc_html_e( 'Filter by type', 'wppowersuite-lite' ); ?></label>
			<select name="snippet_type" id="wpps-cs-filter-type">
				<option value=""><?php esc_html_e( 'All types', 'wppowersuite-lite' ); ?></option>
				<?php foreach ( $types as $value => $label ) : ?>
					<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $this->type_filter, $value ); ?>><?php echo esc_html( $label ); ?></option>
				<?php endforeach; ?>
			</select>
			<label for="wpps-cs-filter-location" class="screen-reader-text"><?php esc_html_e( 'Filter by location', 'wppowersuite-lite' ); ?></label>
			<select name="snippet_location" id="wpps-cs-filter-location">
				<option value=""><?php esc_html_e( 'All locations', 'wppowersuite-lite' ); ?></option>
				<option value="shortcode" <?php selected( $this->location_filter, 'shortcode' ); ?>><?php esc_html_e( 'Shortcode only', 'wppowersuite-lite' ); ?></option>
				<?php foreach ( \CodeSnippet\Module::getLocationsForUI() as $category ) : ?>
					<?php
					$cat_label = isset( $category['label'] ) ? (string) $category['label'] : '';
					if ( $cat_label === '' || empty( $category['sections'] ) || ! is_array( $category['sections'] ) ) {
						continue;
					}
					?>
					<optgroup label="<?php echo esc_attr( $cat_label ); ?>">
						<?php foreach ( $category['sections'] as $section ) : ?>
							<?php
							if ( empty( $section['locations'] ) || ! is_array( $section['locations'] ) ) {
								continue;
							}
							foreach ( $section['locations'] as $loc ) {
								if ( empty( $loc['value'] ) ) {
									continue;
								}
								$loc_value = (string) $loc['value'];
								$loc_label = isset( $loc['label'] ) ? (string) $loc['label'] : $loc_value;
								echo '<option value="' . esc_attr( $loc_value ) . '" ' . selected( $this->location_filter, $loc_value, false ) . '>' . esc_html( $loc_label ) . '</option>';
							}
							?>
						<?php endforeach; ?>
					</optgroup>
				<?php endforeach; ?>
			</select>
			<label for="wpps-cs-filter-device" class="screen-reader-text"><?php esc_html_e( 'Filter by device', 'wppowersuite-lite' ); ?></label>
			<select name="snippet_device" id="wpps-cs-filter-device">
				<option value=""><?php esc_html_e( 'Any device', 'wppowersuite-lite' ); ?></option>
				<?php foreach ( $devices as $value => $label ) : ?>
					<option value="<?php echo esc_attr( $value ); ?>" <?php selected( $this->device_filter, $value ); ?>><?php echo esc_html( $label ); ?></option>
				<?php endforeach; ?>
			</select>
			<?php submit_button( __( 'Filter', 'wppowersuite-lite' ), '', 'filter_action', false, [ 'id' => 'wpps-cs-filter-submit' ] ); ?>
		</div>
		<?php
	}

	/**
	 * Get views for the list table (All, Active, Inactive).
	 *
	 * @return array
	 */
	protected function get_views() {
		$base_args = array_merge(
			[ 'page' => 'powersuite-code-snippet' ],
			$this->getActiveFilterArgs()
		);
		$counts         = $this->module->getSnippetCounts();
		$count_all      = $counts['all'];
		$count_active   = $counts['active'];
		$count_inactive = $counts['inactive'];
		$views          = [
			'all'      => sprintf(
				'<a href="%s" class="%s">%s <span class="count">(%d)</span></a>',
				esc_url( add_query_arg( array_merge( $base_args, [ 'status' => 'all' ] ), admin_url( 'admin.php' ) ) ),
				$this->status_filter === 'all' ? 'current' : '',
				__( 'All', 'wppowersuite-lite' ),
				$count_all
			),
			'active'   => sprintf(
				'<a href="%s" class="%s">%s <span class="count">(%d)</span></a>',
				esc_url( add_query_arg( array_merge( $base_args, [ 'status' => 'active' ] ), admin_url( 'admin.php' ) ) ),
				$this->status_filter === 'active' ? 'current' : '',
				__( 'Active', 'wppowersuite-lite' ),
				$count_active
			),
			'inactive' => sprintf(
				'<a href="%s" class="%s">%s <span class="count">(%d)</span></a>',
				esc_url( add_query_arg( array_merge( $base_args, [ 'status' => 'inactive' ] ), admin_url( 'admin.php' ) ) ),
				$this->status_filter === 'inactive' ? 'current' : '',
				__( 'Inactive', 'wppowersuite-lite' ),
				$count_inactive
			),
		];
		return $views;
	}
}
