<?php
/**
 * Renders the Purchase Rules list page.
 *
 * Override this template in your own theme by creating a file at:
 *
 *     [your-theme]/tribe/tickets-plus/purchase-rules/admin/list.php
 *
 * @link https://evnt.is/1amp See more documentation about our views templating system.
 *
 * @since 6.9.0
 *
 * @version 6.9.0
 *
 * @var Template   $this  The Purchase Rules template instance.
 * @var List_Table $table The Purchase Rules table instance.
 */

use TEC\Tickets_Plus\Commerce\Purchase_Rules\Admin\Page;
use TEC\Tickets_Plus\Commerce\Purchase_Rules\Admin\List_Table;
use TEC\Tickets_Plus\Commerce\Purchase_Rules\Template;

defined( 'ABSPATH' ) || exit;
?>
<div class="wrap">
	<h1 class="wp-heading-inline">
		<?php echo esc_html__( 'Purchase Rules', 'event-tickets-plus' ); ?>
	</h1>
	<a href="<?php echo esc_url( tribe( Page::class )->get_url( [ 'rule_id' => 0 ] ) ); ?>" class="page-title-action"><?php echo esc_html__( 'Add New Rule', 'event-tickets-plus' ); ?></a>

	<?php if ( tec_get_request_var( 's', '' ) ) : ?>
		<span class="subtitle">
		<?php
		// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped, StellarWP.XSS.EscapeOutput.OutputNotEscaped
		/* translators: %s: Search query. */
		printf( __( 'Search results for: %s', 'event-tickets-plus' ), '<strong>' . esc_html( tec_get_request_var( 's' ) ) . '</strong>' );
		// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped, StellarWP.XSS.EscapeOutput.OutputNotEscaped
		?>
		</span>
	<?php endif; ?>

	<hr class="wp-header-end">

	<?php
	$deleted_count = (int) tec_get_request_var_raw( 'deleted', 0 );
	if ( $deleted_count ) {
		wp_admin_notice(
			// Translators: %s is the number of purchase rules that were deleted.
			sprintf( _n( '%s purchase rule permanently deleted.', '%s purchase rules permanently deleted.', $deleted_count, 'event-tickets-plus' ), $deleted_count ),
			[
				'id'                 => 'message',
				'additional_classes' => [ 'updated' ],
				'dismissible'        => true,
			]
		);
	}
	$updated_count = (int) tec_get_request_var_raw( 'updated', 0 );
	if ( $updated_count ) {
		wp_admin_notice(
			// Translators: %s is the number of purchase rules that were updated.
			sprintf( _n( '%s purchase rule was updated.', '%s purchase rules were updated.', $updated_count, 'event-tickets-plus' ), $updated_count ),
			[
				'id'                 => 'message',
				'additional_classes' => [ 'updated' ],
				'dismissible'        => true,
			]
		);
	}
	?>

	<?php $table->views(); ?>

	<form id="posts-filter" method="get">
		<?php
		if ( ! $table->is_empty() ) {
			$table->search_box( esc_html__( 'Search Rules', 'event-tickets-plus' ), 'purchase_rules' );
		}
		$table->display();
		?>
	</form>

	<?php
	if ( $table->has_items() ) {
		$table->inline_edit();
	}
	?>

	<div class="clear"></div>
</div>
<?php
