<?php

/**
 * Admin Notice Handler
 *
 * @package Licenzo\Hooks\Handler\Admin
 */

namespace Licenzo\Hooks\Handler\Admin;

use Licenzo\Hooks\Handler\BaseHandler;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Handles admin notices and cleanup
 */
class NoticeHandler extends BaseHandler
{
    /**
     * Handle admin notices display
     */
    public function handle(...$args)
    {
        // No admin notices for SPA - all notifications handled by Vue
    }

    /**
     * Handle hiding admin notices on our pages
     */
    public function handleHideNotices(...$args)
    {
        $screen = get_current_screen();

        // Only apply on our admin pages
        if (!$screen || strpos($screen->id, 'licenzo') === false) {
            return;
        }

        $this->hideWordPressNotices();
    }

    /**
     * Hide all WordPress admin notices on our pages
     */
    private function hideWordPressNotices()
    {
        // Register a dummy style handle for inline CSS
        wp_register_style('licenzo-admin-notices', false, [], LICENZO_VERSION);
        wp_enqueue_style('licenzo-admin-notices');

        // Add inline CSS using WordPress function
        // CSS approach hides notices visually while preserving hook integrity
        $css = '
            .notice, .error, .updated, .update-nag {
                display: none !important;
            }

            /* Also hide notices that might be added dynamically */
            #wpbody-content > .notice,
            #wpbody-content > .error,
            #wpbody-content > .updated,
            #wpbody-content > .update-nag,
            .wrap > .notice,
            .wrap > .error,
            .wrap > .updated,
            .wrap > .update-nag {
                display: none !important;
            }
        ';

        wp_add_inline_style('licenzo-admin-notices', $css);
    }
}
