<?php
/**
 * Country routing list view template.
 *
 * Variables in scope (passed by Admin_Settings::render_routing_list_view()):
 *
 * @var string                                                             $add_url
 * @var \DonationRouter\Country_Routing_List_Table      $list_table
 *
 * @since   1.0.0
 * @package DonationRouter
 */

declare( strict_types=1 );

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

?>
<div class="ador-list-header">
	<a href="<?php echo esc_url( $add_url ); ?>" class="page-title-action">
		<?php esc_html_e( 'Add New Routing Rule', 'alamin-donation-router' ); ?>
	</a>

	<?php
	/*
	 * The donor-facing shortcode, where it is needed.
	 *
	 * Routing is where somebody is already thinking about which countries a
	 * donor can pick from, which is the moment they need the shortcode that
	 * renders that choice. Same copy affordance as the webhook URL.
	 */
	?>
	<span class="ador-shortcode-chip">
		<span class="ador-shortcode-chip__label"><?php esc_html_e( 'Donor selector:', 'alamin-donation-router' ); ?></span>
		<code id="ador-selector-shortcode">[<?php echo esc_html( \DonationRouter\Country_Selector::SHORTCODE ); ?>]</code>
		<button type="button" class="ador-copy-btn" data-target="#ador-selector-shortcode">
			<?php echo ador_icon( 'copy' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			<?php esc_html_e( 'Copy', 'alamin-donation-router' ); ?>
		</button>
	</span>
</div>

<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
	<?php wp_nonce_field( 'ador_bulk_deactivate_routings', 'ador_bulk_nonce' ); ?>
	<?php $list_table->display(); ?>
	<?php
	/*
	 * Printed AFTER the table on purpose: WP_List_Table::display() emits its own
	 * bulk <select name="action">, and admin-post.php dispatches on
	 * $_REQUEST['action'] (last duplicate key wins). See the accounts list template
	 * for the full rationale.
	 */
	?>
	<input type="hidden" name="action" value="ador_bulk_deactivate_routings" />
</form>
