<?php
/**
 * Admin update notification popup for Pixelio Cart Abandon Recovery More plugin.
 *
 * This file checks if an update is available for the plugin and, if so, displays
 * a popup in the WordPress admin area to notify the user. It provides a direct
 * link to the plugins page for updating, and optionally allows dismissing the popup
 * if the update is not forced.
 *
 * PHP version 8.0+
 *
 * @package PixelioCartAbandonRecoveryMore
 */

use PixelioCartAbandonRecoveryMore\Includes\Utils\Pixelio_Cart_Abandon_Recovery_More_Util;

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

if ( Pixelio_Cart_Abandon_Recovery_More_Util::$update_available ) {
	?>
	<div class="<?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-container" id="pixelio-cart-abandon-recovery-more-update-popup-container">
		<div
			class="<?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-background-grey"></div>
		<div class=" <?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup ">
			<div
				class=" <?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-header pixelio-cart-abandon-recovery-more-gradient">
				<img class="pixelio-cart-abandon-recovery-more-update-popup-header-img"
					src="<?php echo esc_attr( plugins_url( '../../assets/img/pixelio-cart-abandon-recovery-more-rocket.png', __FILE__) ); ?>"
					alt="<?php esc_html_e( 'rocket to explain there is an update', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>"/>
			</div>

			<div
				class=" <?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-body">
				<h3 class="pixelio-cart-abandon-recovery-more-update-popup-body-title">
					<?php esc_html_e(
						'A new version of Rivio is available',
						'rivio-ai-cart-recovery-marketing-email-automation'
					); ?>
				</h3>

				<p class="pixelio-cart-abandon-recovery-more-update-popup-body-description">
					<?php esc_html_e(
						'Update now to benefit from the latest features, performance improvements, security enhancements, and bug fixes.',
						'rivio-ai-cart-recovery-marketing-email-automation'
					); ?>
				</p>

				<?php
				$changelog = trim( (string) Pixelio_Cart_Abandon_Recovery_More_Util::$changelog );

				if ( $changelog !== '' ) :
					?>
					<p class="pixelio-cart-abandon-recovery-more-update-popup-changelog-title">
						<?php esc_html_e(
							"What's new in this version",
							'rivio-ai-cart-recovery-marketing-email-automation'
						); ?>
					</p>

					<p class="pixelio-cart-abandon-recovery-more-update-popup-body-subtitle">
						<?php echo esc_html( $changelog ); ?>
					</p>
				<?php endif; ?>
			</div>

			<div
				class=" <?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-footer">
				<a href="<?php echo esc_attr( admin_url( 'plugins.php' ) ); ?>"
					class="<?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-footer-update-button pixelio-cart-abandon-recovery-more-gradient pixelio-cart-abandon-recovery-more-pixelio-style-button ">
					Update
				</a>

				<?php
				if (!Pixelio_Cart_Abandon_Recovery_More_Util::$force_update) { ?>
					<a href="#"
					   data-force-update="<?php echo esc_attr( Pixelio_Cart_Abandon_Recovery_More_Util::$force_update ); ?>"
						class="<?php esc_attr_e( 'pixelio-cart-abandon-recovery-more', 'rivio-ai-cart-recovery-marketing-email-automation' ); ?>-update-popup-footer-not-now pixelio-cart-abandon-recovery-more-close-update-popup">
						Maybe After</a>
				<?php } ?>
			</div>
		</div>
	</div>
	<?php
}
