<?php
/**
 * Shipments page view.
 *
 * @package DhlPolska\Admin
 *
 * @var \DhlPolska\Admin\Shipments\ShipmentsListTable $table
 * @var array{type: string, message: string}|null    $notice
 * @var string                                      $menu_slug
 */

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


?>
<div class="wrap">
	<h1><?php esc_html_e( 'Przesyłki', 'dhl-polska' ); ?></h1>
	<?php if ( $notice ) : ?>
		<div class="notice notice-<?php echo esc_attr( $notice['type'] ); ?>">
			<p><?php echo esc_html( $notice['message'] ); ?></p>
		</div>
	<?php endif; ?>
	<form method="get">
		<input type="hidden" name="page" value="<?php echo esc_attr( $menu_slug ); ?>" />
		<?php $table->search_box( esc_html__( 'Szukaj przesyłek', 'dhl-polska' ), 'dhl-polska-shipments' ); ?>
		<?php $table->display(); ?>
	</form>
</div>
<script>
	(function () {
		if ( ! window.location.search ) {
			return;
		}

		var url = new URL( window.location.href );
		var keysToRemove = [
			'action',
			'action2',
			'shipment_ids',
			'_wpnonce',
			'_wp_http_referer'
		];

		var changed = false;
		keysToRemove.forEach( function ( key ) {
			if ( url.searchParams.has( key ) ) {
				url.searchParams.delete( key );
				changed = true;
			}
		} );

		if ( changed ) {
			window.history.replaceState( {}, document.title, url.toString() );
		}
	})();
</script>
