<?php
/**
 * Relocates other plugins' admin notices into a collapsible tray on Speedlyst
 * screens. Nothing is removed; every notice stays visible and dismissible.
 *
 * @package MarketingConsole
 */

namespace MarketingConsole\Admin;

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

final class NoticeIsolation {
	public function register(): void {
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
	}

	public function enqueue_assets( string $hook ): void {
		if ( false === strpos( $hook, 'speedlyst' ) ) {
			return;
		}

		$asset_path  = dirname( MARKETING_CONSOLE_FILE ) . '/assets/js/notice-tray.js';
		$asset_mtime = is_file( $asset_path ) ? filemtime( $asset_path ) : false;
		$version     = false === $asset_mtime ? MARKETING_CONSOLE_VERSION : (string) $asset_mtime;

		wp_enqueue_script(
			'speedlyst-notice-tray',
			plugin_dir_url( MARKETING_CONSOLE_FILE ) . 'assets/js/notice-tray.js',
			array( 'jquery', 'common' ),
			$version,
			true
		);

		wp_localize_script(
			'speedlyst-notice-tray',
			'speedlystNoticeTray',
			array(
				'heading' => __( 'Notices from other plugins', 'speedlyst' ),
			)
		);
	}
}
