<?php
/**
 * Basic Forms - Admin Entries View
 *
 * @package BasicForms
 * @since 1.0.0
 */

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

use WP_PowerSuite\Admin\PageHero;

$list_table = new BasicForms\EntriesListTable();
$list_table->prepare_items();
$filter_form = isset( $_GET['form_filter'] ) ? (int) $_GET['form_filter'] : 0;
$filter_status = isset( $_GET['status_filter'] ) ? sanitize_text_field( wp_unslash( $_GET['status_filter'] ) ) : '';

$meta_html = sprintf(
	'<a href="%s" class="button">%s</a>',
	esc_url( admin_url( 'admin.php?page=powersuite-basic-forms' ) ),
	esc_html__( 'Back to Forms', 'wp-powersuite' )
);
?>
<div class="wrap wpps-bf-wrap">
	<hr class="wp-header-end" style="margin:0;padding:0;border:none;height:0;overflow:hidden;">

	<?php
	if ( $entries_updated !== '' ) {
		$parts = explode( '_', $entries_updated, 2 );
		$count = isset( $parts[0] ) ? (int) $parts[0] : 0;
		$action = isset( $parts[1] ) ? $parts[1] : '';
		if ( $count > 0 && $action ) {
			/* translators: 1: number, 2: number, 3: number, 4: number, 5: number, 6: number. */
			$msg = $action === 'delete' ? _n( '%d entry deleted.', '%d entries deleted.', $count, 'wp-powersuite' ) : ( $action === 'mark_read' ? _n( '%d entry marked as read.', '%d entries marked as read.', $count, 'wp-powersuite' ) : _n( '%d entry marked as unread.', '%d entries marked as unread.', $count, 'wp-powersuite' ) );
			echo '<div class="notice notice-success is-dismissible"><p>' . esc_html( sprintf( $msg, $count ) ) . '</p></div>';
		}
	}
	?>

	<?php
	PageHero::render_for_module(
		[
			'icon'      => 'dashicons-list-view',
			'title'     => __( 'Form Entries', 'wp-powersuite' ),
			'tagline'   => __( 'View, export, and manage all form submissions.', 'wp-powersuite' ),
			'meta_html' => $meta_html,
		]
	);
	?>

	<div class="wpps-bf-panel wpps-bf-list-panel">
		<div class="wpps-bf-panel-body">
			<?php $list_table->views(); ?>
			<form method="get" id="entries-filter">
				<input type="hidden" name="page" value="powersuite-basic-forms">
				<input type="hidden" name="view" value="entries">
				<?php $list_table->search_box( __( 'Search entries', 'wp-powersuite' ), 'entry' ); ?>
				<?php $list_table->display(); ?>
			</form>
		</div>
	</div>
</div>

<div id="wpps-bf-entry-modal" class="wpps-bf-modal-overlay" role="dialog" aria-modal="true" aria-labelledby="wpps-bf-entry-modal-title" aria-hidden="true">
	<div class="wpps-bf-modal-container">
		<div class="wpps-bf-modal-header">
			<h2 id="wpps-bf-entry-modal-title"><?php esc_html_e( 'Entry Details', 'wp-powersuite' ); ?></h2>
			<button type="button" class="wpps-bf-modal-close" aria-label="<?php esc_attr_e( 'Close', 'wp-powersuite' ); ?>">&times;</button>
		</div>
		<div class="wpps-bf-modal-content" id="wpps-bf-entry-modal-content">
			<div class="wpps-bf-loading"><?php esc_html_e( 'Loading...', 'wp-powersuite' ); ?></div>
		</div>
	</div>
</div>

