<?php
/**
 * Better Badge Review Notice
 * add review notice in admin dashboard
 * @package   Better Badge
 * @author    InnoCodia <innocodia@gmail.com>
 * @sicne     1.1.6
 */

namespace CPBW\Notices;

class ReviewNotice {
	public function __construct() {
		// add_action( 'admin_notices', [ $this, 'display_review_notice' ] );
	}

    /**
     * Display the review notice if it hasn't been dismissed.
     * @throws \Exception
     *
     * @return void
     */
    public function display_review_notice() {
        $dismiss_type = sanitize_text_field( get_user_meta( get_current_user_id(), 'cpbw_review_dismissed', true ) );

        // If no dismissal record, show the notice after 7 days of plugin activation
        if ( empty( $dismiss_type ) ) {
            $activation_time = get_option( 'cpbw_install_time' );
            if ( $activation_time && ( time() < ( $activation_time + ( 7 * DAY_IN_SECONDS ) ) ) ) {
                return;
            }
        }

        // If 'never', don't show the notice
        if ( $dismiss_type === 'never' ) {
            return;
        }

        // If it's a timestamp, check if the snooze period has expired
        if ( is_numeric( $dismiss_type ) && $dismiss_type > time() ) {
            return;
        }

        ?>
        <div class="notice notice-success is-dismissible cpbw-review-notice">
            <div class="cpbw-notice-icon-container">
                <img class="cpbw-notice-icon" src="<?php echo esc_url( plugins_url( 'custom-product-badge-for-woocommerce/assets/image/cpbw-logo.gif' ) ); ?>" alt="Better badge Logo">
            </div>
            <div>
                <h2 class="cpbw-review-title">⭐ Better Badge is working for you?</h2>
                <p class="cpbw-review-subtitle">If the plugin helps you create better product badges and manage them more efficiently, please consider leaving a ⭐⭐⭐⭐⭐ review on WordPress.org—your feedback truly helps us improve and add better features.</p>
                <div class="cpbw-review-buttons">
                    <div class="cpbw-review-buttons-left">
                        <a href="https://wordpress.org/support/plugin/custom-product-badge-for-woocommerce/reviews/#new-post" target="_blank" class="review-btn">⭐ Leave a Review</a>
                        <a href="#" class="later-btn cpbw-dismiss-review" data-dismiss="later">Remind me later</a>
                    </div>
                    <div class="cpbw-review-buttons-right">
                        <a href="#" id="cpbw-review-never" class="cpbw-dismiss-review" data-dismiss="never">Dismiss</a>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
}