<?php
/**
 * Displays affiliate notices.
 *
 * @package SWPTLS
 */

// If direct access than exit the file.
defined( 'ABSPATH' ) || exit;

$pink_diamond = ECRE_ASSETS . '/icons/pink-diamond.svg';
?>
<div class="ecre-upgrade-banner">
	<span class="ecre-upgrade-close"></span>
	<div class="banner-content">
		<div class="ecre-upgrade-image">
			<img class="ecre-image-icon" src="<?php echo esc_url( $pink_diamond ); ?>" alt="">
		</div>
		
		<div class="content">
			<h3><?php esc_html_e( 'Advance coupon use cases and many more premium features are available in the ', 'echo-rewards' ); ?> <span><?php esc_html_e( 'EchoRewards', 'echo-rewards' ); ?></span> <?php esc_html_e( 'plugin 😍', 'echo-rewards' ); ?></h3>

			<div class="upgrade-btn-wrapper">
				<a href="<?php echo esc_url( 'https://cutt.ly/3ewdS5Go' ); ?>" target="_blank" class="upgrade-button"><?php esc_html_e( 'Upgrade Now', 'echo-rewards' ); ?> <span></span></a>
			</div>

		</div>
		
	</div>
	
</div>

<script>
jQuery(document).ready(function($) {
	$(document).on('click', '.ecre-upgrade-close', (e) => {
		console.log("Click")
		e.preventDefault();

		let target = $(e.currentTarget);
		let dataValue = 'hide_notice';

		$.ajax({
			type: "POST",
			url: "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>", // phpcs:ignore
			data: {
				action: 'ecre_notice_action',
				nonce: '<?php echo esc_attr( wp_create_nonce( 'ecre_notices_nonce' ) ); ?>',
				info: {
					type: 'hide_notice',
					value: dataValue
				},
				actionType: 'upgrade_notice'
			},
			success: response => {
				if (response.data.response_type === 'success') {
					$('.ecre-upgrade-banner').slideUp();
				}
			}
		});
	})
});
</script>
