<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Provide a admin area view for the plugin.
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       https://webequipe.com
 * @since      1.0.0
 *
 * @package    Webequipe_Spin_Win_Wheel
 * @subpackage Webequipe_Spin_Win_Wheel/admin/partials
 */
?>

<div class="wrap wsww-spin-view">
	<div class="wsww-button-inline">
		<h1 class="wp-heading-inline"><?php esc_html_e( 'Winner Detail', 'webequipe-spin-win-wheel' ); ?></h1>
		<a name="submit_spin_settings"
			class="btn wsww-button-color"
			href="<?php echo esc_url( admin_url( 'admin.php?page=wsww-spin-winner' ) ); ?>">
				<?php esc_html_e( 'Back to winner list', 'webequipe-spin-win-wheel' ); ?>
		</a>
	</div>


	<hr class="wp-header-end">

	<?php
	/*
	 * Display success messages passed via query string.
	 * These are non-sensitive, read-only indicators shown after redirect.
	 */
	$webequipe_sww_message_raw = filter_input( INPUT_GET, 'message', FILTER_DEFAULT );
	if ( is_string( $webequipe_sww_message_raw ) && '' !== $webequipe_sww_message_raw ) {
		$webequipe_sww_message = sanitize_text_field( wp_unslash( $webequipe_sww_message_raw ) );
		echo '<div class="updated"><p>' . esc_html( $webequipe_sww_message ) . '</p></div>';
	}
	?>

	<form id="WswwWinnerForm" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post">
		<input type="hidden" name="id" value="<?php echo esc_attr( $winner->id ); ?>">
		<input type="hidden" name="action" value="wsww_claim_update">

		<?php
		/*
		 * Use REQUEST_URI only to redirect back safely.
		 * Check for existence, unslash, and sanitize properly.
		 */
		$webequipe_sww_current_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
		?>
		<input type="hidden" name="redirect_to" value="<?php echo esc_url( $webequipe_sww_current_uri ); ?>">

		<?php wp_nonce_field( 'wsww-claim-update-form' ); ?>

		<div id="poststuff">
			<div id="post-body" class="metabox-holder columns-2">
				<div id="post-body-content">
					<div class="postbox">
						<div class="inside">
							<table class="wsww-spin-winner-table table table-striped">
								<tbody>
									<tr>
										<th><?php esc_html_e( 'ID', 'webequipe-spin-win-wheel' ); ?></th>
										<td><?php echo esc_html( $winner->id ); ?></td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Name', 'webequipe-spin-win-wheel' ); ?></th>
										<td><?php echo esc_html( $winner->name ); ?></td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Email', 'webequipe-spin-win-wheel' ); ?></th>
										<td><?php echo esc_html( $winner->email ); ?></td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Phone', 'webequipe-spin-win-wheel' ); ?></th>
										<td><?php echo esc_html( $winner->phone ); ?></td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Spin Label', 'webequipe-spin-win-wheel' ); ?></th>
										<td><?php echo esc_html( $winner->spin_label ); ?></td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Spin ID', 'webequipe-spin-win-wheel' ); ?></th>
										<td><?php echo esc_html( $winner->spin_id ); ?></td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Page URL', 'webequipe-spin-win-wheel' ); ?></th>
										<td>
											<a href="<?php echo esc_url( $winner->page_url ); ?>" target="_blank" rel="noopener">
												<?php echo esc_html( $winner->page_url ); ?>
											</a>
										</td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Claim', 'webequipe-spin-win-wheel' ); ?></th>
										<td>
											<?php if ( 'no' === $winner->claim ) : ?>
												<button type="submit" id="btn-claim-update" class="button button-primary">
													<?php esc_html_e( 'Claim this prize', 'webequipe-spin-win-wheel' ); ?>
												</button>
											<?php else : ?>
												<span class="claim-yes" title="<?php esc_attr_e( 'Claimed', 'webequipe-spin-win-wheel' ); ?>">
													<?php esc_html_e( 'Yes', 'webequipe-spin-win-wheel' ); ?>
												</span>
											<?php endif; ?>
										</td>
									</tr>

									<tr>
										<th><?php esc_html_e( 'Created Date', 'webequipe-spin-win-wheel' ); ?></th>
										<td>
											<?php
											echo esc_html(
												webequipe_sww_format_mysql_datetime_display(
													isset( $winner->created_at ) ? $winner->created_at : null
												)
											);
											?>
										</td>
									</tr>
								</tbody>
							</table>
						</div><!-- .inside -->
					</div><!-- .postbox -->
				</div><!-- .post-body-content -->

				<div id="postbox-container-1" class="postbox-container">
					<div id="side-sortables" class="meta-box-sortables ui-sortable"></div>
				</div>
			</div><!-- .post-body -->
			<br class="clear" />
		</div><!-- #poststuff -->
	</form>
</div><!-- .wrap -->
