<?php
/**
 * Buttons list tab.
 *
 * @package Rsmspark_Content_Widgets
 *
 * @var Rsmspark_Buttons_List_Table $table
 */

defined( 'ABSPATH' ) || exit;

// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin notice flag; no state change.
$import_notice = isset( $_GET['imported'] ) ? sanitize_text_field( wp_unslash( (string) $_GET['imported'] ) ) : '';
$import_message = '';
if ( isset( $_GET['message'] ) ) {
	$import_message = sanitize_text_field( wp_unslash( (string) $_GET['message'] ) );
	$import_message = rawurldecode( $import_message );
}
$import_count = isset( $_GET['count'] ) ? absint( wp_unslash( $_GET['count'] ) ) : 0;
// phpcs:enable WordPress.Security.NonceVerification.Recommended
?>
<p class="rsm-buttons-tab-actions">
	<a href="<?php echo esc_url( Rsmspark_Buttons_Admin::edit_url() ); ?>" class="button button-primary"><?php esc_html_e( 'Add New Button', 'rsm-content-widgets' ); ?></a>
</p>

<?php if ( 'success' === $import_notice ) : ?>
	<?php
	rsmspark_suite_render_admin_notice(
		sprintf(
			/* translators: %d: number of buttons */
			__( 'Import complete. %d button(s) processed.', 'rsm-content-widgets' ),
			$import_count
		)
	);
	?>
<?php elseif ( 'error' === $import_notice && $import_message ) : ?>
	<?php rsmspark_suite_render_admin_notice( $import_message ); ?>
<?php endif; ?>

<form method="get">
	<input type="hidden" name="page" value="<?php echo esc_attr( Rsmspark_Buttons_Admin::PAGE_SLUG ); ?>" />
	<input type="hidden" name="tab" value="buttons" />
	<?php $table->search_box( __( 'Search Buttons', 'rsm-content-widgets' ), 'rsm-buttons' ); ?>
</form>

<form method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=' . Rsmspark_Buttons_Admin::PAGE_SLUG . '&tab=buttons' ) ); ?>" id="rsm-buttons-list-form">
	<input type="hidden" name="page" value="<?php echo esc_attr( Rsmspark_Buttons_Admin::PAGE_SLUG ); ?>" />
	<input type="hidden" name="tab" value="buttons" />
	<?php
	wp_nonce_field( 'bulk-rsm_buttons' );
	$table->display();
	?>
</form>
