<?php

namespace PixelioCartAbandonRecoveryMore\Admin\Services;



use PixelioCartAbandonRecoveryMore\Admin\Wrapper\Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper;

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


class Pixelio_Cart_Abandon_Recovery_More_Notice_Service
{
	/**
	 * WordPress abstraction layer (POST, sanitize, esc_html, etc).
	 *
	 * @var Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper
	 */
	private Pixelio_Cart_Abandon_Recovery_More_Wordpress_Wrapper $pixelio_wordpress_wrapper;


	public function __construct($wordpress_wrapper)
	{
		$this->pixelio_wordpress_wrapper = $wordpress_wrapper;
		$this->pixelio_cart_abandon_recovery_more_init();
	}


	public function pixelio_cart_abandon_recovery_more_init(): void
	{
		$this->pixelio_remove_admin_notices();

	}



	private function pixelio_remove_admin_notices(): void
	{
		$this->pixelio_cart_abandon_recovery_more_remove_all_actions('admin_notices');
		$this->pixelio_cart_abandon_recovery_more_remove_all_actions('all_admin_notices');
	}

	/**
	 * Removes all actions attached to a specific hook in the admin context.
	 *
	 * This method unsets the global $wp_filter for the given hook name,
	 * but only if the current admin page contains "pixelio" in its slug.
	 * This is used to prevent default WordPress admin notices or other actions
	 * from interfering with the plugin's admin pages.
	 *
	 * @param string $hook_name The name of the hook from which to remove all actions.
	 * @return void
	 */
	public function pixelio_cart_abandon_recovery_more_remove_all_actions($hook_name): void
	{
		$wp_filter = $this->pixelio_wordpress_wrapper->pixelio_get_filter();
		// We are in a WP admin submenu, no nonce is required here.
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		if (isset($wp_filter[$hook_name]) && isset($_GET) && array_key_exists('page', $_GET)) {
			// phpcs:ignore WordPress.Security.NonceVerification.Recommended
			$page = $this->pixelio_wordpress_wrapper->pixelio_sanitize_text_field($this->pixelio_wordpress_wrapper->pixelio_wp_unslash($_GET['page']));
			if (str_contains($page, 'rivio')) {
				unset($wp_filter[$hook_name]);
			}
		}
	}

}
