<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * My account mystery boxes wins template
 *
 * @link       https://wpgenie.org
 * @since      1.0.0
 *
 * @package    Mysterx
 * @subpackage Mysterx/admin
 */

?>
<header class="woocommerce-products-header mysterx">
	<h4 class="woocommerce-products-header__title page-title wins"><a href="<?php echo esc_html( wc_get_account_endpoint_url( 'mysterx' ) ); ?>"><?php esc_html_e( 'Boxes', 'mysterx-mystery-boxes-for-woocommerce' ); ?></a></h4>
	<h4 class="woocommerce-products-header__title page-title wins active"><?php esc_html_e( 'Wins', 'mysterx-mystery-boxes-for-woocommerce' ); ?></h4>
</header>

<?php

if ( $boxes ) {
	?>

	<ul class="products columns-<?php echo esc_attr( wc_get_loop_prop( 'columns' ) ); ?>">

	<?php
	foreach ( $boxes as $value ) {

		global $product, $post;

		$current_post = get_post( $value['reward_id'] );

		if ( $current_post ) {
			setup_postdata( $current_post );
		}
		$product = wc_get_product( $value['reward_id'] );
		wc_get_template( 'mysterx/mysterx-win.php', array( 'opened_at' => $value['opened_at'] ) );

	}
		wp_reset_postdata();
	?>
	</ul>

	<?php if ( 1 < $max_num_pages ) : ?>

		<div class="woocommerce-pagination woocommerce-pagination--without-numbers woocommerce-Pagination">
				<?php if ( 1 !== $current_page ) : ?>
				<a class="woocommerce-button woocommerce-button--previous woocommerce-Button woocommerce-Button--previous button<?php echo esc_attr( $wp_button_class ); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'mysterx-wins', $current_page - 1 ) ); ?>"><?php esc_html_e( 'Previous', 'mysterx-mystery-boxes-for-woocommerce' ); ?></a>
			<?php endif; ?>

				<?php if ( intval( $max_num_pages ) !== $current_page ) : ?>
				<a class="woocommerce-button woocommerce-button--next woocommerce-Button woocommerce-Button--next button<?php echo esc_attr( $wp_button_class ); ?>" href="<?php echo esc_url( wc_get_endpoint_url( 'mysterx-wins', $current_page + 1 ) ); ?>"><?php esc_html_e( 'Next', 'mysterx-mystery-boxes-for-woocommerce' ); ?></a>
			<?php endif; ?>
		</div>
	<?php endif; ?>


	<?php

} else {
	?>

	<div class="woocommerce-message woocommerce-message--info woocommerce-Message woocommerce-Message--info woocommerce-info">
		<?php esc_html_e( 'No boxes found.', 'mysterx-mystery-boxes-for-woocommerce' ); ?>
	</div>

	<?php
}
