<?php if (!defined('ABSPATH'))
	exit; ?>
<?php

class polylai_Notices
{
	public function check_usage()
	{
		global $wpdb;

		$rating_asked = get_option('polylai_rating_asked');
		if ($rating_asked) {
			return;
		}

		if (isset($_COOKIE['polylai_suspend_notice'])) {
			return;
		}		

		$table_name = $wpdb->prefix . 'polylai_log';
		$query = $wpdb->prepare("SELECT DISTINCT `post_id` FROM %i where operation='translate'", $table_name);
		$results = $wpdb->get_results($query);

		if (count($results) >= 3) {

			$nonce = wp_create_nonce('polylai_rating_asked');

			?>
			<div class="notice notice-success">
				<h3>Thank you for using PolylAI Translator!</h3>
				<p>If you like the plugin, please <a
						href="https://wordpress.org/support/plugin/ai-translator-for-polylang/reviews/#new-post"
						target="_blank">rate it with ⭐⭐⭐⭐⭐</a> on WordPress.org. It will help us to improve the plugin and make it
					better for everyone.</p>
				<p>
				<form method="post" action="">
					<input type="hidden" name="polylai_rating_nonce" value="<?php echo $nonce ?>">
					<button class="button" type="submit" name="polylai_rating_action" value="remind">Remind me later</button>					
					<button class="button" type="submit" name="polylai_rating_action" value="done">Already done</button>
					<a
						class="button"
						href="https://wordpress.org/support/plugin/ai-translator-for-polylang/reviews/#new-post"
						target="_blank">Sure!</a>
				</form>
				</p>
			</div>
			<?php
		}
	}

	public function check_bg_messages()
	{
		$args = array(
			'post_type' => 'post',
			'posts_per_page' => -1,
			'meta_key' => 'polylai_status',
			'meta_value' => 'completed'
		);
	}
}