<?php
/**
 * Submission list for the WordPress.org free build.
 *
 * @package CF7MasterPro\Admin\Templates
 *
 * @var array $submissions
 * @var array $filters
 */
defined( 'ABSPATH' ) || exit;
?>
<div id="cf7mp-admin-root" data-view="submissions">
	<h1 class="cf7mp-admin__title"><?php esc_html_e( 'Submissions', 'frontierline-forms' ); ?></h1>

	<?php
	$cf7mp_total = isset( $total_count ) ? (int) $total_count : 0;
	?>
	<p style="color:#646970;margin-bottom:16px;"><?php echo esc_html( sprintf( __( '%d submissions', 'frontierline-forms' ), $cf7mp_total ) ); ?></p>

	<div class="cf7mp-submission-list">
		<form class="cf7mp-submission-list__filters" method="get">
			<input type="hidden" name="page" value="frontierline-forms-submissions">
			<input type="search" name="s" value="<?php echo esc_attr( $filters['s'] ?? '' ); ?>" placeholder="<?php esc_attr_e( 'Keyword search', 'frontierline-forms' ); ?>" />
			<select name="priority">
				<option value=""><?php esc_html_e( 'Priority: All', 'frontierline-forms' ); ?></option>
				<option value="high" <?php selected( $filters['priority'] ?? '', 'high' ); ?>><?php esc_html_e( 'High', 'frontierline-forms' ); ?></option>
				<option value="medium" <?php selected( $filters['priority'] ?? '', 'medium' ); ?>><?php esc_html_e( 'Medium', 'frontierline-forms' ); ?></option>
				<option value="low" <?php selected( $filters['priority'] ?? '', 'low' ); ?>><?php esc_html_e( 'Low', 'frontierline-forms' ); ?></option>
			</select>
			<button type="submit" class="button"><?php esc_html_e( 'Filter', 'frontierline-forms' ); ?></button>
		</form>
		<?php if ( ! empty( $export_url ) ) : ?>
			<p style="margin:8px 0 16px;">
				<a href="<?php echo esc_url( $export_url ); ?>" class="button button-secondary"><?php esc_html_e( 'Export CSV', 'frontierline-forms' ); ?></a>
			</p>
		<?php endif; ?>

		<table class="cf7mp-submission-list__table">
			<thead>
				<tr>
					<th><?php esc_html_e( 'Date', 'frontierline-forms' ); ?></th>
					<th><?php esc_html_e( 'Form', 'frontierline-forms' ); ?></th>
					<th><?php esc_html_e( 'Sender', 'frontierline-forms' ); ?></th>
					<th><?php esc_html_e( 'Subject', 'frontierline-forms' ); ?></th>
					<th><?php esc_html_e( 'Priority', 'frontierline-forms' ); ?></th>
					<th><?php esc_html_e( 'Category', 'frontierline-forms' ); ?></th>
				</tr>
			</thead>
			<tbody>
				<?php if ( empty( $submissions ) ) : ?>
					<tr>
						<td colspan="6" style="text-align:center;padding:32px;color:#646970;">
							<?php esc_html_e( 'No submissions yet.', 'frontierline-forms' ); ?>
						</td>
					</tr>
				<?php else : ?>
					<?php foreach ( $submissions as $cf7mp_row ) : ?>
						<?php
						$cf7mp_priority   = $cf7mp_row['priority'] ?? 'low';
						$cf7mp_row_cls    = 'cf7mp-submission-list__row';
						$cf7mp_detail_url = admin_url( 'admin.php?page=frontierline-forms-submissions&action=view&id=' . (int) $cf7mp_row['id'] );
						if ( ! empty( $cf7mp_row['is_new'] ) ) {
							$cf7mp_row_cls .= ' cf7mp-submission-list__row--new';
						}
						?>
						<tr class="<?php echo esc_attr( $cf7mp_row_cls ); ?>" data-id="<?php echo esc_attr( $cf7mp_row['id'] ); ?>" data-detail-url="<?php echo esc_url( $cf7mp_detail_url ); ?>">
							<td><a href="<?php echo esc_url( $cf7mp_detail_url ); ?>"><?php echo esc_html( $cf7mp_row['created_at'] ); ?></a></td>
							<td><a href="<?php echo esc_url( $cf7mp_detail_url ); ?>"><?php echo esc_html( $cf7mp_row['form_title'] ); ?></a></td>
							<td><?php echo esc_html( $cf7mp_row['sender'] ); ?></td>
							<td><a href="<?php echo esc_url( $cf7mp_detail_url ); ?>"><?php echo esc_html( $cf7mp_row['subject'] ); ?></a></td>
							<td>
								<span class="cf7mp-submission-list__priority cf7mp-submission-list__priority--<?php echo esc_attr( $cf7mp_priority ); ?>">
									<?php echo esc_html( $cf7mp_row['priority_label'] ?? $cf7mp_priority ); ?>
								</span>
							</td>
							<td><?php echo esc_html( $cf7mp_row['category'] ?? '-' ); ?></td>
						</tr>
					<?php endforeach; ?>
				<?php endif; ?>
			</tbody>
		</table>
	</div>
</div>
